tclserv

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

p10.disabled (12112B)


      1 
      2 namespace eval p10 {
      3 set sid [string repeat "A" [expr {2-[string length [b64e $::numeric]]}]]
      4 append sid [b64e $::numeric]
      5 
      6 proc ::p10::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)/$::netname($sck)/$::netname($sck)/${sid}${sendnn}" $uid
     15 	puts $sck $sl
     16 }
     17 
     18 proc ::p10::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 ::p10::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 ::p10::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 ::p10::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 ::p10::notice {sck uid targ 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 O %s :%s" $sid $sendnn $targ $msg]
     54 }
     55 
     56 proc ::p10::setacct {sck targ msg} {
     57 	global sid
     58 	puts $sck [format "%s AC %s R %s" $sid $targ $msg]
     59 	tnda set "login/$::netname($sck)/$::netname($sck)/$::netname($sck)/$targ" $msg
     60 }
     61 
     62 proc ::p10::bind {sock type client comd script} {
     63 	set moretodo 1
     64 	while {0!=$moretodo} {
     65 		set bindnum [rand 1 10000000]
     66 		if {[tnda get "binds/$sock/$type/$client/$comd/$bindnum"]!=""} {} {set moretodo 0}
     67 	}
     68 	tnda set "binds/$sock/$type/$client/$comd/$::netname($sck)/$::netname($sck)/$bindnum" $script
     69 	puts stdout "binds/$sock/$type/$client/$comd/$bindnum [tnda get "binds/$sock/$type/$client/$comd"]"
     70 	return $bindnum
     71 }
     72 
     73 proc ::p10::unbind {sock type client comd id} {
     74 	tnda set "binds/$sock/$type/$client/$comd/$::netname($sck)/$::netname($sck)/$id" ""
     75 }
     76 
     77 proc ::p10::putmode {sck uid targ mode parm ts} {
     78 	global sid
     79 	set sendid [b64e $uid]
     80 	set sendnn [string repeat "A" [expr {3-[string length $sendid]}]]
     81 	append sendnn $sendid
     82 	puts $sck [format "%s%s M %s %s %s" $sid $sendnn $targ $mode $parm $ts]
     83 }
     84 
     85 proc ::p10::putjoin {sck uid targ ts} {
     86 	global sid
     87 	set sendid [b64e $uid]
     88 	set sendnn [string repeat "A" [expr {3-[string length $sendid]}]]
     89 	append sendnn $sendid
     90 	puts $sck [format "%s B %s %s %s%s:o" $sid $targ $ts $sid $sendnn]
     91 	puts stdout [format "%s B %s %s %s%s:o" $sid $targ $ts $sid $sendnn]
     92 
     93 }
     94 
     95 proc ::p10::callbind {sock type client comd args} {
     96 	puts stdout "[tnda get "binds/$sock/$type/$client/$comd"]"
     97 	if {""!=[tnda get "binds/$sock/$type/$client/$comd"]} {
     98 		foreach {id script} [tnda get "binds/$sock/$type/$client/$comd"] {
     99 			$script [lindex $args 0] [lrange $args 1 end]
    100 		};return
    101 	}
    102 	#if {""!=[tnda get "binds/$type/-/$comd"]} {foreach {id script} [tnda get "binds/$type/-/$comd"] {$script [lindex $args 0] [lrange $args 1 end]};return}
    103 }
    104 
    105 proc ::p10::irc-main {sck} {
    106 	global sid sock
    107 	if {[eof $sck]} {puts stderr "duckfuck.";exit}
    108 	gets $sck line
    109 	set line [string trim $line "\r\n"]
    110 	set gotsplitwhere [string first " :" $line]
    111 	if {$gotsplitwhere==-1} {set comd [split $line " "]} {set comd [split [string range $line 0 [expr {$gotsplitwhere - 1}]] " "]}
    112 	set payload [split [string range $line [expr {$gotsplitwhere + 2}] end] " "]
    113 	puts stdout [join $comd " "]
    114 	switch -nocase -- [lindex $comd 1] {
    115 		"P" {
    116 			if {[string index [lindex $comd 2] 0] == "#"} {
    117 				set client chan
    118 				callbind $sck pub "-" [string tolower [lindex $payload 0]] [lindex $comd 2] [lindex $comd 0] [lrange $payload 1 end] p10
    119 				callbind $sck evnt "-" "chanmsg" [lindex $comd 0] [lindex $comd 2] [lrange $payload 0 end] p10
    120 			} {
    121 				set client [tnda get "intclient/$::netname($sck)/[lindex $comd 2]"]
    122 				callbind $sck msg $client [string tolower [lindex $payload 0]] [lindex $comd 0] [lrange $payload 1 end] p10
    123 				callbind $sck "evnt" "-" "privmsg" [lindex $comd 0] [lindex $comd 2] [lrange $payload 0 end] p10
    124 			}
    125 		}
    126 
    127 		"O" {
    128 			if {[string index [lindex $comd 2] 0] == "#"} {
    129 				set client chan
    130 				callbind $sck pubnotc "-" [string tolower [lindex $payload 0]] [lindex $comd 2] [lindex $comd 0] [lrange $payload 1 end] p10
    131 				callbind $sck pubnotc-m "-" [string tolower [lindex $payload 0]] [lindex $comd 2] [lindex $comd 0] [lrange $payload 1 end] p10
    132 				callbind $sck "evnt" "-" "channotc" [lindex $comd 0] [lindex $comd 2] [lrange $payload 0 end] p10
    133 			} {
    134 				set client [tnda get "intclient/$::netname($sck)/[lindex $comd 2]"]
    135 				callbind $sck notc $client [string tolower [lindex $payload 0]] [lindex $comd 0] [lrange $payload 1 end]
    136 				callbind $sck "evnt" "-" "privnotc" [lindex $comd 0] [lindex $comd 2] [lrange $payload 0 end] p10
    137 			}
    138 		}
    139 
    140 		"M" {
    141 			if {[string index [lindex $comd 2] 0] != "#"} {if {[lindex $comd 2] == [tnda get "nick/$::netname($sck)/[lindex $comd 0]"]} {
    142 				foreach {c} [split [lindex $comd 3] {}] {
    143 					switch -- $c {
    144 						"+" {set state 1}
    145 						"-" {set state 0}
    146 						"o" {tnda set "oper/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd 0]" $state}
    147 					}
    148 				}
    149 			} } {
    150 				set ctr 3
    151 				foreach {c} [split [lindex $comd 3] {}] {
    152 					switch -regexp -- $c {
    153 						"\\\+" {set state 1}
    154 						"-" {set state 0}
    155 						"[aCcDdiMmNnOpQRrSsTtZz]" {callbind $sck mode "-" [expr {$state ? "+" : "-"}] $c [lindex $comd 0] [lindex $comd 2] $::netname($sck)}
    156 						"[belLkohv]" {callbind $sck mode "-" [expr {$state ? "+" : "-"}] $c [lindex $comd 0] [lindex $comd 2] [lindex $comd [incr ctr]] $::netname($sck)}
    157 					}
    158 				}
    159 			}
    160 		}
    161 
    162 		"C" {
    163 			callbind $sck create "-" "-" [lindex $comd 2] [lindex $comd 0] $::netname($sck)
    164 			callbind $sck join "-" "-" [lindex $comd 2] [lindex $comd 0] $::netname($sck)
    165 			set chan [string map {/ [} [::base64::encode [string tolower [lindex $comd 2]]]]
    166 			tnda set "channels/$::netname($sck)/$chan/$::netname($sck)/$::netname($sck)/$::netname($sck)/ts" [lindex $comd 3]
    167 		}
    168 
    169 		"T" {
    170 			callbind $sck topic "-" "-" [lindex $comd 2] [join $payload " "]
    171 		}
    172 
    173 		"OM" {
    174 			set ctr 3
    175 			foreach {c} [split [lindex $comd 3] {}] {
    176 				switch -regexp -- $c {
    177 					"\\\+" {set state 1}
    178 					"\\\-" {set state 0}
    179 					"[aCcDdiMmNnOpQRrSsTtZz]" {callbind $sck mode "-" [expr {$state ? "+" : "-"}] $c [lindex $comd 0] [lindex $comd 2]}
    180 					"[belLkohv]" {callbind $sck mode "-" [expr {$state ? "+" : "-"}] $c [lindex $comd 0] [lindex $comd 2] [lindex $comd [incr ctr]]}
    181 				}
    182 			}
    183 		}
    184 
    185 		"B" {
    186 			puts $sck "$sid EB"
    187 			set chan [string map {/ [} [::base64::encode [string tolower [lindex $comd 2]]]]
    188 			puts stdout "$chan"
    189 			if {[string index [lindex $comd 4] 0] == "+"} {
    190 				set four 5
    191 				if {[string match "*l*" [lindex $comd 4]]} {incr four}
    192 				if {[string match "*L*" [lindex $comd 4]]} {incr four}
    193 				if {[string match "*k*" [lindex $comd 4]]} {incr four}
    194 			} {
    195 				set four 4
    196 			}
    197 			tnda set "channels/$::netname($sck)/$chan/$::netname($sck)/$::netname($sck)/$::netname($sck)/ts" [lindex $comd 3]
    198 			foreach {nick} [split [lindex $comd $four] ","] {
    199 				set n [split $nick ":"]
    200 				set un [lindex $n 0]
    201 				set uo [lindex $n 1]
    202 				if {""!=$uo} {tnda set "channels/$::netname($sck)/$chan/modes/$::netname($sck)/$::netname($sck)/$::netname($sck)/$un" $uo}
    203 				callbind $sck join "-" "-" [lindex $comd 2] $un
    204 			}
    205 
    206 		}
    207 
    208 		"J" {
    209 			callbind $sck join "-" "-" [lindex $comd 2] [lindex $comd 0]
    210 		}
    211 
    212 		"L" {
    213 			callbind $sck part "-" "-" [lindex $comd 2] [lindex $comd 0]
    214 		}
    215 
    216 		"K" {
    217 			callbind $sck part "-" "-" [lindex $comd 2] [lindex $comd 3]
    218 		}
    219 
    220 		"EB" {
    221 			puts $sck "$sid EA"
    222 		}
    223 
    224 		"N" {
    225 			if {[llength $comd] >= 5} {
    226 				set num 8
    227 				set ctr 1
    228 				set oper 0
    229 				set loggedin ""
    230 				set fakehost ""
    231 				set modes ""
    232 				if {[string index [lindex $comd 7] 0] == "+"} {set modes [string range [lindex $comd 7] 1 end]; incr num}
    233 				foreach {c} [split $modes {}] {
    234 					puts stdout "$ctr $comd"
    235 					switch -exact -- $c {
    236 						"o" {set oper 1}
    237 						"r" {incr ctr;incr num; set loggedin [lindex $comd [expr {$ctr+6}]]}
    238 						"C" {incr ctr;incr num; set fakehost [lindex $comd [expr {$ctr+6}]]}
    239 						"c" {incr ctr;incr num; set fakehost [lindex $comd [expr {$ctr+6}]]}
    240 						"f" {incr ctr;incr num; set fakehost [lindex $comd [expr {$ctr+6}]]}
    241 						"h" {incr ctr;incr num; set fakehost [lindex [split [lindex $comd [expr {$ctr+7}]] "@"] 1]}
    242 					}
    243 				}
    244 
    245 				if {""!=$loggedin} {
    246 					tnda set "login/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd $num]" $loggedin
    247 				}
    248 
    249 				if {""!=$fakehost} {
    250 					tnda set "vhost/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd $num]" $fakehost
    251 				}
    252 
    253 				tnda set "nick/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd $num]" [lindex $comd 2]
    254 				tnda set "oper/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd $num]" $oper
    255 				tnda set "ident/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd $num]" [lindex $comd 5]
    256 				tnda set "rhost/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd $num]" [lindex $comd 6]
    257 				callbind $sck conn "-" "-" [lindex $comd $num]
    258 			} {
    259 				callbind $sck nch "-" "-" [lindex $comd 0] [tnda get "nick/$::netname($sck)/[lindex $comd 0]"] [lindex $comd 2]
    260 				tnda set "nick/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd 0]" [lindex $comd 2]
    261 			}
    262 		}
    263 
    264 		"Q" {
    265 			tnda set "login/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd 0]" ""
    266 			tnda set "nick/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd 0]" ""
    267 			tnda set "oper/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd 0]" 0
    268 			tnda set "ident/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd 0]" ""
    269 			tnda set "rhost/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd 0]" ""
    270 			tnda set "vhost/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd 0]" ""
    271 		}
    272 
    273 		"D" {
    274 			tnda set "login/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd 2]" ""
    275 			tnda set "nick/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd 2]" ""
    276 			tnda set "oper/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd 2]" 0
    277 			tnda set "ident/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd 2]" ""
    278 			tnda set "rhost/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd 2]" ""
    279 			tnda set "vhost/$::netname($sck)/$::netname($sck)/$::netname($sck)/[lindex $comd 2]" ""
    280 		}
    281 
    282 		"G" {
    283 			puts $sck "$sid Z [lindex $comd 3] [lindex $comd 2] [lindex $comd 4]"
    284 		}
    285 	}
    286 }
    287 
    288 proc ::p10::login {sck} {
    289 	global servername sid password
    290 	tnda set "pfx/owner" o
    291 	tnda set "pfx/protect" o
    292 	tnda set "pfx/halfop" h
    293 	set sid [string repeat "A" [expr {2-[b64e $::numeric]}]]
    294 	append sid [b64e $::numeric]
    295 	puts $sck "PASS :$password"
    296 	puts $sck "SERVER $servername 0 [clock format [clock seconds] -format %s] [clock format [clock seconds] -format %s] J10 $sid\]\]\] 0 :Services for IRC Networks ($::netname($sck))"
    297 	puts stdout "PASS :$password"
    298 	puts stdout "SERVER $servername 0 [clock format [clock seconds] -format %s] [clock format [clock seconds] -format %s] J10 $sid\]\]\] 0 :Services for IRC Networks"
    299 }
    300 
    301 
    302 #source services.conf
    303 namespace export *
    304 namespace ensemble create
    305 }
    306 
    307 #p10 login $::sock