p10n.disabled (12653B)
1 2 namespace eval p10n { 3 set sid [string repeat "A" [expr {2-[string length [b64e $::numeric]]}]] 4 append sid [b64e $::numeric] 5 6 proc ::p10n::sendUid {sck nick ident host dhost uid {realname "* Unknown *"} {modes "+oik"} {server ""}} { 7 if {""==$server} {set server $::numeric} 8 set sid [string repeat "A" [expr {2-[string length [b64e $server]]}]] 9 append sid [b64e $server] 10 set sendid [b64e $uid] 11 set sendnn [string repeat "A" [expr {3-[string length $sendid]}]] 12 append sendnn $sendid 13 set sl [format "%s N %s 1 %s %s %s %s AAAAAA %s%s :%s" $sid $nick [clock format [clock seconds] -format %s] $ident $host $modes $sid $sendnn $realname] 14 tnda set "intclient/$::netname($sck)/${sid}${sendnn}" $uid 15 puts $sck $sl 16 } 17 18 proc ::p10n::sendSid {sck sname sid {realname "In use by Services"}} { 19 set sl [format "%s S %s 2 %s %s P10 %s]]] 0 :%s" [b64e $::sid] $sname [clock format [clock seconds] -format %s] [clock format [clock seconds] -format %s] [b64e $sid] $realname] 20 puts $sck $sl 21 } 22 23 proc ::p10n::topic {sck uid targ topic} { 24 set sid [string repeat "A" [expr {2-[string length [b64e $::numeric]]}]] 25 append sid [b64e $::numeric] 26 set sendid [b64e $uid] 27 set sendnn [string repeat "A" [expr {3-[string length $sendid]}]] 28 append sendnn $sendid 29 puts $sck [format "%s%s T %s :%s" $sid $sendnn $targ $topic] 30 } 31 32 proc ::p10n::privmsg {sck uid targ msg} { 33 global sid 34 set sendid [b64e $uid] 35 set sendnn [string repeat "A" [expr {3-[string length $sendid]}]] 36 append sendnn $sendid 37 puts $sck [format "%s%s P %s :%s" $sid $sendnn $targ $msg] 38 } 39 40 proc ::p10n::kick {sck uid targ tn msg} { 41 global sid 42 set sendid [b64e $uid] 43 set sendnn [string repeat "A" [expr {3-[string length $sendid]}]] 44 append sendnn $sendid 45 puts $sck [format "%s%s K %s %s :%s" $sid $sendnn $targ $tn $msg] 46 } 47 48 proc ::p10n::kill {sck uid tn msg} { 49 global sid 50 set sendid [b64e $uid] 51 set sendnn [string repeat "A" [expr {3-[string length $sendid]}]] 52 append sendnn $sendid 53 puts $sck [format "%s%s D %s :%s" $sid $sendnn $tn $msg] 54 } 55 56 proc ::p10n::notice {sck uid targ msg} { 57 global sid 58 set sendid [b64e $uid] 59 set sendnn [string repeat "A" [expr {3-[string length $sendid]}]] 60 append sendnn $sendid 61 puts $sck [format "%s%s O %s :%s" $sid $sendnn $targ $msg] 62 } 63 64 proc ::p10n::setacct {sck targ msg} { 65 global sid 66 puts $sck [format "%s AC %s R %s" $sid $targ $msg] 67 tnda set "login/$::netname($sck)/$targ" $msg 68 } 69 70 proc ::p10n::putwallop {sck msg} { 71 global sid 72 puts $sck [format "%s WA :%s" $sid $msg] 73 } 74 75 proc ::p10n::sethost {sck uid targ msg} { 76 global sid 77 set sendid [b64e $uid] 78 set sendnn [string repeat "A" [expr {3-[string length $sendid]}]] 79 append sendnn $sendid 80 puts $sck [format "%s%s SH %s %s %s" $sid $sendnn $targ [tnda get "ident/$::netname($sck)/$targ"] $msg] 81 puts $sck [format "%s FA %s %s" $sid $targ $msg] 82 puts stdout [format "%s SH %s %s %s" $sid $targ [tnda get "ident/$::netname($sck)/$targ"] $msg] 83 tnda set "vhost/$::netname($sck)/$targ" $msg 84 } 85 86 proc ::p10n::bind {sock type client comd script} { 87 set moretodo 1 88 while {0!=$moretodo} { 89 set bindnum [rand 1 10000000] 90 if {[tnda get "binds/$sock/$type/$client/$comd/$bindnum"]!=""} {} {set moretodo 0} 91 } 92 tnda set "binds/$sock/$type/$client/$comd/$bindnum" $script 93 puts stdout "binds/$sock/$type/$client/$comd/$bindnum [tnda get "binds/$sock/$type/$client/$comd"]" 94 return $bindnum 95 } 96 97 proc ::p10n::unbind {sock type client comd id} { 98 tnda set "binds/$sock/$type/$client/$comd/$id" "" 99 } 100 101 proc ::p10n::putmode {sck uid targ mode parm ts} { 102 global sid 103 set sendid [b64e $uid] 104 set sendnn [string repeat "A" [expr {3-[string length $sendid]}]] 105 append sendnn $sendid 106 puts $sck [format "%s%s M %s %s %s" $sid $sendnn $targ $mode $parm $ts] 107 } 108 109 proc ::p10n::putmotd {sck targ line} { 110 global sid 111 puts $sck [format "%s 372 %s :- %s" $sid $targ $line] 112 } 113 114 proc ::p10n::mark {sck targ type line} { 115 global sid 116 puts $sck [format "%s MK %s %s :%s" $sid $targ $type $line] 117 puts stdout [format "%s MK %s %s :%s" $sid $targ $type $line] 118 } 119 120 proc ::p10n::putmotdend {sck targ} { 121 global sid 122 puts $sck [format "%s 376 %s :End of global MOTD." $sid $targ] 123 } 124 125 proc ::p10n::putjoin {sck uid targ ts} { 126 global sid 127 set sendid [b64e $uid] 128 set sendnn [string repeat "A" [expr {3-[string length $sendid]}]] 129 append sendnn $sendid 130 puts $sck [format "%s B %s %s %s%s:o" $sid $targ $ts $sid $sendnn] 131 puts stdout [format "%s B %s %s %s%s:o" $sid $targ $ts $sid $sendnn] 132 133 } 134 135 proc ::p10n::callbind {sock type client comd args} { 136 puts stdout "[tnda get "binds/$sock/$type/$client/$comd"]" 137 if {""!=[tnda get "binds/$sock/$type/$client/$comd"]} { 138 foreach {id script} [tnda get "binds/$sock/$type/$client/$comd"] { 139 $script [lindex $args 0] [lrange $args 1 end] 140 };return 141 } 142 #if {""!=[tnda get "binds/$type/-/$comd"]} {foreach {id script} [tnda get "binds/$type/-/$comd"] {$script [lindex $args 0] [lrange $args 1 end]};return} 143 } 144 145 proc ::p10n::irc-main {sck} { 146 global sid sock 147 if {[eof $sck]} {puts stderr "duckfuck.";exit} 148 gets $sck line 149 set line [string trim $line "\r\n"] 150 set gotsplitwhere [string first " :" $line] 151 if {$gotsplitwhere==-1} {set comd [split $line " "]} {set comd [split [string range $line 0 [expr {$gotsplitwhere - 1}]] " "]} 152 set payload [split [string range $line [expr {$gotsplitwhere + 2}] end] " "] 153 switch -nocase -- [lindex $comd 1] { 154 "P" { 155 if {[string index [lindex $comd 2] 0] == "#"} { 156 set client chan 157 callbind $sck pub "-" [string tolower [lindex $payload 0]] [lindex $comd 2] [lindex $comd 0] [lrange $payload 1 end] p10 158 callbind $sck evnt "-" "chanmsg" [lindex $comd 0] [lindex $comd 2] [lrange $payload 0 end] p10 159 } { 160 set client [tnda get "intclient/$::netname($sck)/[lindex $comd 2]"] 161 callbind $sck msg $client [string tolower [lindex $payload 0]] [lindex $comd 0] [lrange $payload 1 end] p10 162 callbind $sck "evnt" "-" "privmsg" [lindex $comd 0] [lindex $comd 2] [lrange $payload 0 end] p10 163 } 164 } 165 166 "O" { 167 if {[string index [lindex $comd 2] 0] == "#"} { 168 set client chan 169 callbind $sck pubnotc "-" [string tolower [lindex $payload 0]] [lindex $comd 2] [lindex $comd 0] [lrange $payload 1 end] p10 170 callbind $sck pubnotc-m "-" [string tolower [lindex $payload 0]] [lindex $comd 2] [lindex $comd 0] [lrange $payload 1 end] p10 171 callbind $sck "evnt" "-" "channotc" [lindex $comd 0] [lindex $comd 2] [lrange $payload 0 end] p10 172 } { 173 set client [tnda get "intclient/$::netname($sck)/[lindex $comd 2]"] 174 callbind $sck notc $client [string tolower [lindex $payload 0]] [lindex $comd 0] [lrange $payload 1 end] 175 callbind $sck "evnt" "-" "privnotc" [lindex $comd 0] [lindex $comd 2] [lrange $payload 0 end] p10 176 } 177 } 178 179 "M" { 180 puts stdout [join [list {*}$comd {*}$payload] " "] 181 if {[string index [lindex $comd 2] 0] != "#"} {if {[lindex $comd 2] == [tnda get "nick/$::netname($sck)/[lindex $comd 0]"]} { 182 foreach {c} [split [lindex $comd 3] {}] { 183 switch -- $c { 184 "+" {set state 1} 185 "-" {set state 0} 186 "o" {tnda set "oper/$::netname($sck)/[lindex $comd 0]" $state} 187 } 188 } 189 } } { 190 set ctr 3 191 foreach {c} [split [lindex $comd 3] {}] { 192 switch -regexp -- $c { 193 "\\\+" {set state 1} 194 "-" {set state 0} 195 "[aCcDdiMmNnOpQRrSsTtZz]" {callbind $sck mode "-" [expr {$state ? "+" : "-"}] $c [lindex $comd 0] [lindex $comd 2] $::netname($sck)} 196 "[belLkohv]" {callbind $sck mode "-" [expr {$state ? "+" : "-"}] $c [lindex $comd 0] [lindex $comd 2] [lindex $comd [incr ctr]] $::netname($sck)} 197 } 198 } 199 } 200 } 201 202 "C" { 203 callbind $sck create "-" "-" [lindex $comd 2] [lindex $comd 0] $::netname($sck) 204 callbind $sck join "-" "-" [lindex $comd 2] [lindex $comd 0] $::netname($sck) 205 set chan [string map {/ [} [::base64::encode [string tolower [lindex $comd 2]]]] 206 tnda set "channels/$::netname($sck)/$chan/$::netname($sck)/ts" [lindex $comd 3] 207 } 208 209 "T" { 210 callbind $sck topic "-" "-" [lindex $comd 2] [join $payload " "] 211 } 212 213 "OM" { 214 set ctr 3 215 foreach {c} [split [lindex $comd 3] {}] { 216 switch -regexp -- $c { 217 "\\\+" {set state 1} 218 "\\\-" {set state 0} 219 "[aCcDdiMmNnOpQRrSsTtZz]" {callbind $sck mode "-" [expr {$state ? "+" : "-"}] $c [lindex $comd 0] [lindex $comd 2]} 220 "[belLkohv]" {callbind $sck mode "-" [expr {$state ? "+" : "-"}] $c [lindex $comd 0] [lindex $comd 2] [lindex $comd [incr ctr]]} 221 } 222 } 223 } 224 225 "B" { 226 set chan [string map {/ [} [::base64::encode [string tolower [lindex $comd 2]]]] 227 puts stdout "$chan" 228 if {[string index [lindex $comd 4] 0] == "+"} { 229 set four 5 230 if {[string match "*l*" [lindex $comd 4]]} {incr four} 231 if {[string match "*L*" [lindex $comd 4]]} {incr four} 232 if {[string match "*k*" [lindex $comd 4]]} {incr four} 233 } { 234 set four 4 235 } 236 tnda set "channels/$::netname($sck)/$chan/$::netname($sck)/ts" [lindex $comd 3] 237 foreach {nick} [split [lindex $comd $four] ","] { 238 set n [split $nick ":"] 239 set un [lindex $n 0] 240 set uo [lindex $n 1] 241 if {""!=$uo} {tnda set "channels/$::netname($sck)/$chan/modes/$::netname($sck)/$un" $uo} 242 callbind $sck join "-" "-" [lindex $comd 2] $un 243 } 244 245 } 246 247 "J" { 248 callbind $sck join "-" "-" [lindex $comd 2] [lindex $comd 0] 249 } 250 251 "MO" { 252 callbind $sck motd "-" "-" [lindex $comd 0] 253 } 254 255 "L" { 256 callbind $sck part "-" "-" [lindex $comd 2] [lindex $comd 0] 257 } 258 259 "AC" { 260 tnda set "login/$::netname($sck)/[lindex $comd 2]" [lindex $comd 3] 261 callbind $sck account "-" "-" [lindex $comd 2] [lindex $comd 3] 262 } 263 264 "K" { 265 callbind $sck part "-" "-" [lindex $comd 2] [lindex $comd 3] 266 } 267 268 "EB" { 269 puts $sck "$sid EA" 270 } 271 272 "N" { 273 if {[llength $comd] >= 5} { 274 set num 8 275 set ctr 1 276 set oper 0 277 set loggedin "" 278 set fakehost "" 279 set modes "" 280 if {[string index [lindex $comd 7] 0] == "+"} {set modes [string range [lindex $comd 7] 1 end]; incr num} 281 foreach {c} [split $modes {}] { 282 puts stdout "$ctr $comd" 283 switch -exact -- $c { 284 "o" {set oper 1} 285 "r" {incr ctr;incr num; set loggedin [lindex $comd [expr {$ctr+6}]]} 286 "C" {incr ctr;incr num; set fakehost [lindex $comd [expr {$ctr+6}]]} 287 "c" {incr ctr;incr num; set fakehost [lindex $comd [expr {$ctr+6}]]} 288 "f" {incr ctr;incr num; set fakehost [lindex $comd [expr {$ctr+6}]]} 289 "h" {incr ctr;incr num; set fakehost [lindex [split [lindex $comd [expr {$ctr+7}]] "@"] 1]} 290 } 291 } 292 293 if {""!=$loggedin} { 294 tnda set "login/$::netname($sck)/[lindex $comd $num]" $loggedin 295 } 296 297 if {""!=$fakehost} { 298 tnda set "vhost/$::netname($sck)/[lindex $comd $num]" $fakehost 299 } 300 301 tnda set "nick/$::netname($sck)/[lindex $comd $num]" [lindex $comd 2] 302 tnda set "oper/$::netname($sck)/[lindex $comd $num]" $oper 303 tnda set "ident/$::netname($sck)/[lindex $comd $num]" [lindex $comd 5] 304 tnda set "rhost/$::netname($sck)/[lindex $comd $num]" [lindex $comd 6] 305 callbind $sck conn "-" "-" [lindex $comd $num] 306 } { 307 callbind $sck nch "-" "-" [lindex $comd 0] [tnda get "nick/$::netname($sck)/[lindex $comd 0]"] [lindex $comd 2] 308 tnda set "nick/$::netname($sck)/[lindex $comd 0]" [lindex $comd 2] 309 } 310 } 311 312 "Q" { 313 tnda set "login/$::netname($sck)/[lindex $comd 0]" "" 314 tnda set "nick/$::netname($sck)/[lindex $comd 0]" "" 315 tnda set "oper/$::netname($sck)/[lindex $comd 0]" 0 316 tnda set "ident/$::netname($sck)/[lindex $comd 0]" "" 317 tnda set "rhost/$::netname($sck)/[lindex $comd 0]" "" 318 tnda set "vhost/$::netname($sck)/[lindex $comd 0]" "" 319 } 320 321 "D" { 322 tnda set "login/$::netname($sck)/[lindex $comd 2]" "" 323 tnda set "nick/$::netname($sck)/[lindex $comd 2]" "" 324 tnda set "oper/$::netname($sck)/[lindex $comd 2]" 0 325 tnda set "ident/$::netname($sck)/[lindex $comd 2]" "" 326 tnda set "rhost/$::netname($sck)/[lindex $comd 2]" "" 327 tnda set "vhost/$::netname($sck)/[lindex $comd 2]" "" 328 } 329 330 "G" { 331 puts $sck "$sid Z [lindex $comd 3] [lindex $comd 2] [lindex $comd 4]" 332 } 333 } 334 } 335 336 proc ::p10n::login {sck} { 337 global servername sid password 338 tnda set "pfx/owner" o 339 tnda set "pfx/protect" o 340 tnda set "pfx/halfop" h 341 set sid [string repeat "A" [expr {2-[string length [b64e $::numeric]]}]] 342 append sid [b64e $::numeric] 343 puts $sck "PASS :$password" 344 puts $sck "SERVER $servername 1 [clock format [clock seconds] -format %s] [clock format [clock seconds] -format %s] J10 $sid\]\]\] +s6h :Services for IRC Networks ($::netname($sck))" 345 puts $sck "$sid EB" 346 puts stdout "PASS :$password" 347 puts stdout "SERVER $servername 1 [clock format [clock seconds] -format %s] [clock format [clock seconds] -format %s] J10 $sid\]\]\] 0 :Services for IRC Networks" 348 } 349 350 351 #source services.conf 352 namespace export * 353 namespace ensemble create 354 } 355 356 #p10 login $::sock