tclserv

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

ts6.disabled (13266B)


      1 # Because TS6 ircds are highly configurable, we start in Charybdis mode without
      2 # an idea what modes are permissible. This is to aid ChanServ.
      3 namespace eval ts6 {
      4 
      5 proc ::ts6::sendUid {sck nick ident host dhost uid {realname "* Unknown *"} {modes "+oiS"} {server ""}} {
      6 	if {""==$server} {set server $::numeric}
      7 	set sid [string repeat "0" [expr {3-[string length [::ts6::b64e $server]]}]]
      8 	append sid [::ts6::b64e $server]
      9 	set sendid [::ts6::b64e $uid]
     10 	set sendnn [string repeat "A" [expr {6-[string length $sendid]}]]
     11 	append sendnn $sendid
     12 	if {!$::ts6(euid)} {
     13 		set sl [format ":%s UID %s 1 %s %s %s %s 0 %s%s :%s" $sid $nick [clock format [clock seconds] -format %s] $modes $ident $host $sid $sendnn $realname]
     14 	} {
     15 		set sl [format ":%s EUID %s 1 %s %s %s %s 0 %s%s * * :%s" $sid $nick [clock format [clock seconds] -format %s] $modes $ident $host $sid $sendnn $realname]
     16 	}
     17 	tnda set "intclient/$::netname($sck)/${sid}${sendnn}" $uid
     18 	puts $sck $sl
     19 	puts stdout $sl
     20 }
     21 
     22 proc ::ts6::topic {sck uid targ topic} {
     23 	set sid [string repeat "0" [expr {3-[string length [::ts6::b64e $::numeric]]}]]
     24 	append sid [::ts6::b64e $::numeric]
     25 	set sendid [::ts6::b64e $uid]
     26 	set sendnn [string repeat "A" [expr {6-[string length $sendid]}]]
     27 	append sendnn $sendid
     28 	puts $sck [format ":%s%s TOPIC %s :%s" $sid $sendnn $targ $topic]
     29 }
     30 
     31 proc ::ts6::sendSid {sck sname sid {realname "In use by Services"}} {
     32 set sid [string repeat "0" [expr {3-[string length [::ts6::b64e $::numeric]]}]]
     33 append sid [::ts6::b64e $::numeric]
     34 	set sl [format ":%s SID %s 1 %s :%s" [::ts6::b64e $sid] $sname [::ts6::b64e $sid] $realname]
     35 	puts $sck $sl
     36 }
     37 
     38 proc ::ts6::privmsg {sck uid targ msg} {
     39 set sid [string repeat "0" [expr {3-[string length [::ts6::b64e $::numeric]]}]]
     40 append sid [::ts6::b64e $::numeric]
     41 	set sendid [::ts6::b64e $uid]
     42 	set sendnn [string repeat "A" [expr {6-[string length $sendid]}]]
     43 	append sendnn $sendid
     44 	puts $sck [format ":%s%s PRIVMSG %s :%s" $sid $sendnn $targ $msg]
     45 }
     46 
     47 proc ::ts6::kick {sck uid targ tn msg} {
     48 set sid [string repeat "0" [expr {3-[string length [::ts6::b64e $::numeric]]}]]
     49 append sid [::ts6::b64e $::numeric]
     50 	set sendid [::ts6::b64e $uid]
     51 	set sendnn [string repeat "A" [expr {6-[string length $sendid]}]]
     52 	append sendnn $sendid
     53 	puts $sck [format ":%s%s KICK %s %s :%s" $sid $sendnn $targ $tn $msg]
     54 }
     55 
     56 proc ::ts6::notice {sck uid targ msg} {
     57 	set sid [string repeat "0" [expr {3-[string length [::ts6::b64e $::numeric]]}]];append sid [::ts6::b64e $::numeric]
     58 	set sendid [::ts6::b64e $uid]
     59 	set sendnn [string repeat "A" [expr {6-[string length $sendid]}]]
     60 	append sendnn $sendid
     61 	puts $sck [format ":%s%s NOTICE %s :%s" $sid $sendnn $targ $msg]
     62 }
     63 
     64 proc ::ts6::setacct {sck targ msg} {
     65 	set sid [string repeat "0" [expr {3-[string length [::ts6::b64e $::numeric]]}]];append sid [::ts6::b64e $::numeric]
     66 	puts $sck [format ":%s ENCAP * SU %s %s" $sid $targ $msg]
     67 	tnda set "login/$::netname($sck)/$targ" $msg
     68 }
     69 
     70 proc ::ts6::bind {type client comd script} {
     71 	set moretodo 1
     72 	while {0!=$moretodo} {
     73 		set bindnum [rand 1 10000000]
     74 		if {[tnda get "binds/$type/$client/$comd/$bindnum"]!=""} {} {set moretodo 0}
     75 	}
     76 	tnda set "binds/$type/$client/$comd/$::netname($sck)/$bindnum" $script
     77 	return $bindnum
     78 }
     79 
     80 proc ::ts6::unbind {type client comd id} {
     81 	tnda set "binds/$type/$client/$comd/$::netname($sck)/$id" ""
     82 }
     83 
     84 proc ::ts6::putmode {sck uid targ mode parm ts} {
     85 	set sid [string repeat "0" [expr {3-[string length [::ts6::b64e $::numeric]]}]];append sid [::ts6::b64e $::numeric]
     86 	set sendid [::ts6::b64e $uid]
     87 	set sendnn [string repeat "A" [expr {6-[string length $sendid]}]]
     88 	append sendnn $sendid
     89 	puts $sck [format ":%s%s TMODE %s %s %s %s" $sid $sendnn $ts $targ $mode $parm]
     90 	puts stdout [format ":%s%s TMODE %s %s %s %s" $sid $sendnn $ts $targ $mode $parm]
     91 }
     92 
     93 proc ::ts6::putjoin {sck uid targ ts} {
     94 	set sid [string repeat "0" [expr {3-[string length [::ts6::b64e $::numeric]]}]];append sid [::ts6::b64e $::numeric]
     95 	set sendid [::ts6::b64e $uid]
     96 	set sendnn [string repeat "A" [expr {6-[string length $sendid]}]]
     97 	append sendnn $sendid
     98 	puts $sck [format ":%s SJOIN %s %s + :@%s%s" $sid $ts $targ $sid $sendnn]
     99 	puts stdout [format ":%s SJOIN %s %s + :@%s%s" $sid $ts $targ $sid $sendnn]
    100 }
    101 
    102 proc ::ts6::callbind {sock type client comd args} {
    103 	puts stdout [tnda get "binds/mode"]
    104 	if {""!=[tnda get "binds/$sock/$type/$client/$comd"]} {
    105 		foreach {id script} [tnda get "binds/$sock/$type/$client/$comd"] {
    106 			$script [lindex $args 0] [lrange $args 1 end]
    107 		};return
    108 	}
    109 	#if {""!=[tnda get "binds/$type/-/$comd"]} {foreach {id script} [tnda get "binds/$type/-/$comd"] {$script [lindex $args 0] [lrange $args 1 end]};return}
    110 }
    111 
    112 proc ::ts6::irc-main {sck} {
    113 	global sid sock
    114 	if {[eof $sck]} {close $sck}
    115 	gets $sck line
    116 	set line [string trim $line "\r\n"]
    117 	set one [string match ":*" $line]
    118 	set line [string trimleft $line ":"]
    119 	set gotsplitwhere [string first " :" $line]
    120 	if {$gotsplitwhere==-1} {set comd [split $line " "]} {set comd [split [string range $line 0 [expr {$gotsplitwhere - 1}]] " "]}
    121 	set payload [split [string range $line [expr {$gotsplitwhere + 2}] end] " "]
    122 	puts stdout [join $comd " "]
    123 	if {[lindex $comd 0] == "PING"} {puts $sck "PONG $::servername :$payload"}
    124 	if {[lindex $comd 0] == "SERVER"} {puts $sck "VERSION"}
    125 	switch -nocase -- [lindex $comd $one] {
    126 		"479" {puts stdout $payload}
    127 
    128 		"005" {
    129 			foreach {tok} [lrange $comd 3 end] {
    130 				foreach {key val} [split $tok "="] {
    131 					if {$key == "PREFIX"} {
    132 						# We're in luck! Server advertises its PREFIX in VERSION reply to servers.
    133 						set v [string range $val 1 end]
    134 						set mod [split $v ")"]
    135 						set modechar [split [lindex $mod 1] {}]
    136 						set modepref [split [lindex $mod 0] {}]
    137 						puts stdout "$key $val $modechar $modepref"
    138 						foreach {c} $modechar {x} $modepref {
    139 							tnda set "ts6/prefix/$c" $x
    140 						}
    141 						puts stdout [tnda get "ts6/prefix"]
    142 					}
    143 				}
    144 			}
    145 		}
    146 
    147 		"105" {
    148 			foreach {tok} [lrange $comd [expr {$comd+1}] end] {
    149 				foreach {key val} [split $tok "="] {
    150 					if {$key == "PREFIX"} {
    151 						# We're in luck! Server advertises its PREFIX in VERSION reply to servers.
    152 						set v [string range $val 1 end]
    153 						set mod [split $v ")"]
    154 						set modechar [split [lindex $mod 1] {}]
    155 						set modepref [split [lindex $mod 0] {}]
    156 						foreach {c} $modechar {x} $modepref {
    157 							tnda set "ts6/$::netname($sck)/prefix/$modepref" $modechar
    158 						}
    159 					}
    160 				}
    161 			}
    162 		}
    163 
    164 		"PRIVMSG" {
    165 			if {[string index [lindex $comd 2] 0] == "#"} {
    166 				set client chan
    167 				callbind $sck pub "-" [string tolower [lindex $payload 0]] [lindex $comd 2] [lindex $comd 0] [lrange $payload 1 end]
    168 				callbind $sck evnt "-" "chanmsg" [lindex $comd 0] [lindex $comd 2] [lrange $payload 0 end] ts6
    169 			} {
    170 				set client [tnda get "intclient/$::netname($sck)/[lindex $comd 2]"]
    171 				callbind $sck msg $client [string tolower [lindex $payload 0]] [lindex $comd 0] [lrange $payload 1 end]
    172 				callbind $sck "evnt" "-" "privmsg" [lindex $comd 0] [lindex $comd 2] [lrange $payload 0 end] ts6
    173 			}
    174 		}
    175 
    176 		"NOTICE" {
    177 			if {[string index [lindex $comd 2] 0] == "#"} {
    178 				set client chan
    179 				callbind $sck pubnotc "-" [string tolower [lindex $payload 0]] [lindex $comd 2] [lindex $comd 0] [lrange $payload 1 end]
    180 				callbind $sck pubnotc-m "-" [string tolower [lindex $payload 0]] [lindex $comd 2] [lindex $comd 0] [lrange $payload 1 end]
    181 				callbind $sck "evnt" "-" "channotc" [lindex $comd 0] [lindex $comd 2] [lrange $payload 0 end] ts6
    182 			} {
    183 				set client [tnda get "intclient/$::netname($sck)/[lindex $comd 2]"]
    184 				callbind $sck notc $client [string tolower [lindex $payload 0]] [lindex $comd 0] [lrange $payload 1 end]
    185 				callbind $sck "evnt" "-" "privnotc" [lindex $comd 0] [lindex $comd 2] [lrange $payload 0 end] ts6
    186 			}
    187 		}
    188 
    189 		"MODE" {
    190 			if {[lindex $comd 3] == [tnda get "nick/$::netname($sck)/[lindex $comd 0]"]} {
    191 				foreach {c} [split [lindex $comd 4] {}] {
    192 					switch -- $c {
    193 						"+" {set state 1}
    194 						"-" {set state 0}
    195 						"o" {tnda set "oper/$::netname($sck)/[lindex $comd 0]" $state}
    196 					}
    197 				}
    198 			}
    199 		}
    200 
    201 		"JOIN" {
    202 			set chan [string map {/ [} [::base64::encode [string tolower [lindex $comd 3]]]]
    203 			if {""==[tnda get "channels/$::netname($sck)/$chan/ts"]} {callbind $sck create "-" "-" [lindex $comd 3] [lindex $comd 0]}
    204 			callbind $sck join "-" "-" [lindex $comd 3] [lindex $comd 0]
    205 			tnda set "channels/$::netname($sck)/$chan/ts" [lindex $comd 2]
    206 			tnda set "userchan/[lindex $comd 0]/$chan" 1
    207 		}
    208 
    209 		"TMODE" {
    210 			set ctr 3
    211 			set state 1
    212 			foreach {c} [split [lindex $comd 3] {}] {
    213 				switch -regexp -- $c {
    214 					"\\\+" {set state 1}
    215 					"-" {set state 0}
    216 					"[ABCcDdiMmNnOpPQRrSsTtZz]" {callbind $sck mode "-" [expr {$state ? "+" : "-"}] $c [lindex $comd 0] [lindex $comd 2] $::netname($sck)}
    217 					"[beljfqIaykohv]" {callbind $sck mode "-" [expr {$state ? "+" : "-"}] $c [lindex $comd 0] [lindex $comd 2] [lindex $comd [incr ctr]] $::netname($sck)}
    218 				}
    219 			}
    220 		}
    221 
    222 		"SJOIN" {
    223 			set chan [string map {/ [} [::base64::encode [string tolower [lindex $comd 3]]]]
    224 			if {[string index [lindex $comd 4] 0] == "+"} {
    225 				set four 5
    226 				if {[string match "*l*" [lindex $comd 4]]} {incr four}
    227 				if {[string match "*f*" [lindex $comd 4]]} {incr four}
    228 				if {[string match "*j*" [lindex $comd 4]]} {incr four}
    229 				if {[string match "*k*" [lindex $comd 4]]} {incr four}
    230 			} {
    231 				set four 4
    232 			}
    233 			tnda set "channels/$::netname($sck)/$chan/ts" [lindex $comd 2]
    234 			foreach {nick} $payload {
    235 				set un ""
    236 				set uo ""
    237 				set state uo
    238 				foreach {c} [split $nick {}] {
    239 					if {[string is integer $c]} {set state un}
    240 					puts stdout "$c $nick"
    241 					if {$state == "uo" && [info exists ::pfx($c)]} {set c $::pfx($c) ; }
    242 					if {"un"==$state} {append un $c}
    243 					if {"uo"==$state} {append uo $c}
    244 				}
    245 				puts stdout "$uo $un"
    246 				if {""!=$uo} {tnda set "channels/$::netname($sck)/$chan/modes/$un" $uo}
    247 				callbind $sck join "-" "-" [lindex $comd 3] $un
    248 			}
    249 
    250 		}
    251 
    252 		"PART" {
    253 			callbind $sck part "-" "-" [lindex $comd 2] [lindex $comd 0]
    254 			set chan [string map {/ [} [::base64::encode [string tolower [lindex $comd 2]]]]
    255 			tnda set "userchan/[lindex $comd 0]/$chan" 0
    256 		}
    257 
    258 		"KICK" {
    259 			callbind $sck part "-" "-" [lindex $comd 2] [lindex $comd 3]
    260 		}
    261 
    262 		"EUID" {
    263 			set num 9
    264 			set ctr 1
    265 			set oper 0
    266 			set loggedin [lindex $comd 11]
    267 			set realhost [lindex $comd 10]
    268 			set modes [lindex $comd 4]
    269 			if {[string match "*o*" $modes]} {set oper 1}
    270 			if {"*"!=$loggedin} {
    271 				tnda set "login/$::netname($sck)/[lindex $comd $num]" $loggedin
    272 			}
    273 			if {"*"!=$realhost} {
    274 				tnda set "rhost/$::netname($sck)/[lindex $comd $num]" $realhost
    275 			} {
    276 				tnda set "rhost/$::netname($sck)/[lindex $comd $num]" [lindex $comd 6]
    277 			}
    278 			tnda set "nick/$::netname($sck)/[lindex $comd $num]" [lindex $comd 2]
    279 			tnda set "oper/$::netname($sck)/[lindex $comd $num]" $oper
    280 			tnda set "ident/$::netname($sck)/[lindex $comd $num]" [lindex $comd 6]
    281 			tnda set "vhost/$::netname($sck)/[lindex $comd $num]" [lindex $comd 7]
    282 			callbind $sck conn "-" "-" [lindex $comd $num]
    283 		}
    284 
    285 		"ENCAP" {
    286 			switch -nocase -- [lindex $comd 3] {
    287 				"SASL" {
    288 					#don't bother
    289 				}
    290 			}
    291 		}
    292 
    293 		"TOPIC" {
    294 			callbind $sck topic "-" "-" [lindex $comd 2] [join $payload " "]
    295 		}
    296 		"QUIT" {
    297 			tnda set "login/$::netname($sck)/[lindex $comd 0]" ""
    298 			tnda set "nick/$::netname($sck)/[lindex $comd 0]" ""
    299 			tnda set "oper/$::netname($sck)/[lindex $comd 0]" 0
    300 			tnda set "ident/$::netname($sck)/[lindex $comd 0]" ""
    301 			tnda set "rhost/$::netname($sck)/[lindex $comd 0]" ""
    302 			tnda set "vhost/$::netname($sck)/[lindex $comd 0]" ""
    303 			foreach {chan _} [tnda get "userchan/[lindex $comd 0]"] {
    304 				callbind $sck part "-" "-" [ndadec $chan] [lindex $comd 0]
    305 				tnda set "userchan/[lindex $comd 0]/$chan" 0
    306 			}
    307 		}
    308 
    309 		"KILL" {
    310 			tnda set "login/$::netname($sck)/[lindex $comd 2]" ""
    311 			tnda set "nick/$::netname($sck)/[lindex $comd 2]" ""
    312 			tnda set "oper/$::netname($sck)/[lindex $comd 2]" 0
    313 			tnda set "ident/$::netname($sck)/[lindex $comd 2]" ""
    314 			tnda set "rhost/$::netname($sck)/[lindex $comd 2]" ""
    315 			tnda set "vhost/$::netname($sck)/[lindex $comd 2]" ""
    316 		}
    317 
    318 		"PING" {
    319 			set num [string repeat "0" [expr {3-[string length [::ts6::b64e $::numeric]]}]]
    320 			append num [::ts6::b64e $::numeric]
    321 			if {[lindex $comd 3]==""} {set pong [lindex $comd 0]} {set pong [lindex $comd 3]}
    322 			puts $sck ":$num PONG $pong [lindex $comd 2]"
    323 		}
    324 	}
    325 }
    326 
    327 proc ::ts6::login {sck {sid $::numeric} {password $::password}} {
    328 	set num [string repeat "0" [expr {3-[string length [::ts6::b64e $::numeric]]}]]
    329 	append num [::ts6::b64e $::numeric]
    330 	if {![info exists ::ts6(halfops)]} {tnda set "pfx/halfop" v} {tnda set "pfx/halfop" $::ts6(halfops)}
    331 	if {![info exists ::ts6(ownermode)]} {tnda set "pfx/owner" o} {tnda set "pfx/owner" $::ts6(ownermode)}
    332 	if {![info exists ::ts6(protectmode)]} {tnda set "pfx/protect" o} {tnda set "pfx/protect" $::ts6(protectmode)}
    333 	if {![info exists ::ts6(euid)]} {set ::ts6(euid) 1}
    334 	puts $sck "PASS $::password TS 6 :$num"
    335 	puts $sck "CAPAB EUID"
    336 	puts $sck "SERVER $::servername 1 :Services for IRC Networks"
    337 	puts $sck "SVINFO 6 6 0 :[clock format [clock seconds] -format %s]"
    338 	puts $sck ":$sid VERSION"
    339 }
    340 
    341 
    342 #source services.conf
    343 namespace export *
    344 namespace ensemble create
    345 }
    346 
    347 #ts6 login $::sock