0002-statemachine.tcl (3179B)
1 2 proc nick2uid {nick} { 3 set sck [curctx sock] 4 foreach {u n} [tnda get "nick/[curctx net]"] { 5 if {[string tolower $n] == [string tolower $nick]} {return $u} 6 } 7 return "" 8 } 9 proc intclient2uid {nick} { 10 set sck [curctx sock] 11 foreach {u n} [tnda get "intclient/[curctx net]"] { 12 if {[string tolower $n] == [string tolower $nick]} {return $u} 13 } 14 return "" 15 } 16 proc intclient2nick {nick} { 17 set sck [curctx sock] 18 foreach {u n} [tnda get "intclient/[curctx net]"] { 19 if {[string tolower $n] == [string tolower $nick]} {return [uid2nick $u]} 20 } 21 return "" 22 } 23 proc uid2nick {u} { 24 set sck [curctx sock] 25 return [tnda get "nick/[curctx net]/$u"] 26 } 27 proc uid2rhost {u} { 28 set sck [curctx sock] 29 return [tnda get "rhost/[curctx net]/$u"] 30 } 31 proc uid2host {u} { 32 set sck [curctx sock] 33 return [tnda get "vhost/[curctx net]/$u"] 34 } 35 proc uid2ident {u} { 36 set sck [curctx sock] 37 return [tnda get "ident/[curctx net]/$u"] 38 } 39 proc nick2host {nick} { 40 set sck [curctx sock] 41 return [tnda get "vhost/[curctx net]/[nick2uid $netname $nick]"] 42 } 43 proc nick2ident {nick} { 44 set sck [curctx sock] 45 return [tnda get "ident/[curctx net]/[nick2uid $netname $nick]"] 46 } 47 proc nick2rhost {nick} { 48 set sck [curctx sock] 49 return [tnda get "rhost/[curctx net]/[nick2uid $netname $nick]"] 50 } 51 proc nick2ipaddr {nick} { 52 set sck [curctx sock] 53 return [tnda get "ipaddr/[curctx net]/[nick2uid $netname $nick]"] 54 } 55 proc getts {chan} { 56 set sck [curctx sock] 57 return [tnda get "channels/[curctx net]/[ndaenc $chan]/ts"] 58 } 59 proc getpfx {chan nick} { 60 set sck [curctx sock] 61 return [tnda get "channels/[curctx net]/[ndaenc $chan]/modes/[nick2uid $netname $nick]"] 62 } 63 proc getupfx {chan u} { 64 return [tnda get "channels/[curctx net]/[ndaenc $chan]/modes/$u"] 65 set sck [curctx sock] 66 } 67 proc getpfxchars {modes} { 68 set sck [curctx sock] 69 set o "" 70 foreach {c} [split $modes {}] { 71 append o [nda get "netinfo/[curctx net]/prefix/$c"] 72 } 73 return $o 74 } 75 proc getmetadata {nick metadatum} { 76 set sck [curctx sock] 77 return [tnda get "metadata/[curctx net]/[nick2uid $netname $nick]/[ndcenc $metadatum]"] 78 } 79 proc getcertfp {nick} { 80 set sck [curctx sock] 81 return [tnda get "certfps/[curctx net]/[nick2uid $netname $nick]"] 82 } 83 84 proc checkop {mc s c p n} { 85 set f $s 86 set t $c 87 if {[tnda get "netinfo/$n/pfxchar/$mc"]==""} {return} 88 putcmdlog "up $mc $f $t $p $n" 89 set chan [string map {/ [} [::base64::encode [string tolower $t]]] 90 tnda set "channels/$n/$chan/modes/$p" [format {%s%s} [string map [list $mc ""] [tnda get "channels/$n/$chan/modes/$p"]] $mc] 91 } 92 93 proc checkdeop {mc s c p n} { 94 set f $s 95 set t $c 96 if {[tnda get "netinfo/$n/pfxchar/$mc"]==""} {return} 97 putcmdlog "down $mc $f $t $p $n" 98 set chan [string map {/ [} [::base64::encode [string tolower $t]]] 99 tnda set "channels/$n/$chan/modes/$p" [string map [list $mc ""] [tnda get "channels/$n/$chan/modes/$p"]] 100 } 101 102 proc uid2intclient {u} { 103 set sck [curctx sock] 104 return [tnda get "intclient/[curctx net]/$u"] 105 } 106 107 proc getfreeuid {} { 108 set sck [curctx sock] 109 set work 1 110 set cns [list] 111 foreach {_ cnum} [tnda get "intclient/[curctx net]"] {lappend cns $cnum} 112 while {0!=$work} {set num [expr {[rand 30000]+10000}];if {[lsearch -exact $cns $num]==-1} {set work 0}} 113 return $num 114 }