5 if {![info exists nick
]} { set nick Blight
}
6 if {![info exists ownfullname
]} { set ownfullname
"here to Help" }
7 set ownmailaddr blight
@chiark.greenend.org.uk
9 set musthaveping_ms
10000
13 set out_lag_very
25000
15 proc manyset
{list args
} {
16 foreach val
$list var
$args {
22 proc try_except_finally
{try except finally
} {
23 global errorInfo errorCode
24 set er
[catch { uplevel 1 $try } emsg
]
28 if {[catch { uplevel 1 $except } emsg3
]} {
29 append ei
"\nALSO ERROR HANDLING ERROR:\n$emsg3"
32 set er2
[catch { uplevel 1 $finally } emsg2
]
35 append ei
"\nALSO ERROR CLEANING UP:\n$emsg2"
37 return -code $er -errorinfo $ei -errorcode $ec $emsg
39 return -code $er2 -errorinfo $errorInfo -errorcode $errorCode $emsg2
47 global out_queue out_creditms out_creditat out_interval out_maxburst
48 global out_lag_lag out_lag_very
49 #set pr [lindex [info level 0] 0]
50 #puts $pr>[clock seconds]|$out_creditat|$out_creditms|[llength $out_queue]<
56 if {[llength $out_queue]*$out_interval > $out_lag_very} {
58 } elseif
{[llength $out_queue]*$out_interval > $out_lag_lag} {
68 set now
[clock seconds
]
69 incr out_creditms
[expr {($now - $out_creditat) * 1000}]
71 if {$out_creditms > $out_maxburst*$out_interval} {
72 set out_creditms
[expr {$out_maxburst*$out_interval}]
77 proc out_runqueue
{now
} {
81 while {[llength $out_queue] && $out_creditms >= $out_interval} {
82 #puts rq>$now|$out_creditat|$out_creditms|[llength $out_queue]<
83 manyset
[lindex $out_queue 0] orgwhen msg
84 set out_queue
[lrange $out_queue 1 end
]
85 if {[llength $out_queue]} {
86 append orgwhen
"+[expr {$now - $orgwhen}]"
87 append orgwhen
([llength $out_queue])"
89 puts "$orgwhen -> $msg"
91 incr out_creditms -$out_interval
93 if {[llength $out_queue]} {
94 after $out_interval out_nextmessage
98 proc out_nextmessage {} {
100 set now [clock seconds]
101 incr out_creditms $out_interval
102 set out_creditat $now
106 proc sendout_priority {priority command args} {
107 global sock out_queue
108 if {[llength $args]} {
109 set la [lindex $args end]
110 set args [lreplace $args end end]
112 if {[regexp {[: ]} $i]} {
113 error "bad argument in output
$i ($command $args)"
118 set args [lreplace $args 0 -1 $command]
119 set string [join $args { }]
120 set now [clock seconds]
121 set newe [list $now $string]
123 set out_queue [concat [list $newe] $out_queue]
125 lappend out_queue $newe
127 if {[llength $out_queue] == 1} {
132 proc sendout {command args} { eval sendout_priority [list 0 $command] $args }
138 proc logerror {data} {
143 global saveei saveec errorInfo errorCode
145 set saveei $errorInfo
146 set saveec $errorCode
148 puts ">$saveec|
$saveei<"
158 global sock nick calling_nick errorInfo errorCode
160 if {[gets $sock line] == -1} { fail "EOF
/error on input
" }
161 regsub -all "\[^
-\176\240-\376\]" $line ? line
166 catch { unset calling_nick }
170 if {[regexp -nocase {^:([^ ]+) (.*)} $line dummy prefix remain]} {
172 if {[regexp {^([^!]+)!} $prefix dummy maybenick]} {
173 set calling_nick $maybenick
174 if {"[irctolower
$maybenick]" == "[irctolower
$nick]"} return
179 if {![string length $line]} { return }
180 if {![regexp -nocase {^([0-9a-z]+) *(.*)} $line dummy command line]} {
181 log "bad command
: $org"
184 set command [string toupper $command]
186 while {[regexp {^([^ :]+) *(.*)} $line dummy thisword line]} {
187 lappend params $thisword
189 if {[regexp {^:(.*)} $line dummy thisword]} {
190 lappend params $thisword
191 } elseif {[string length $line]} {
192 log "junk at end
: $org"
195 if {"$command" == "PRIVMSG
" &&
196 [regexp {^[&#+!]} [lindex $params 0]] &&
197 ![regexp {^!} [lindex $params 1]]} {
198 # on-channel message, ignore
200 recordlastseen_p $prefix "talking on
[lindex $params 0]" 1
204 log "[clock seconds
] <- $org"
205 set procname msg_$command
206 if {[catch { info body $procname }]} { return }
208 eval [list $procname $prefix $command] $params
210 logerror "error: $emsg ($prefix $command $params)"
215 proc sendprivmsg {dest l} {
216 foreach v [split $l "\n"] {
217 sendout [expr {[ischan $dest] ? "PRIVMSG
" : "NOTICE
"}] $dest $v
220 proc sendaction_priority {priority dest what} {
221 sendout_priority $priority PRIVMSG $dest "\001ACTION
$what\001"
223 proc msendprivmsg {dest ll} { foreach l $ll { sendprivmsg $dest $l } }
224 proc msendprivmsg_delayed {delay dest ll} { after $delay [list msendprivmsg $dest $ll] }
226 proc prefix_none {} {
228 if {[string length $p]} { error "prefix specified
" }
231 proc msg_PING {p c s1} {
232 global musthaveping_after
235 if {[info exists musthaveping_after]} { after cancel $musthaveping_after] }
238 proc check_nick {n} {
239 if {[regexp -nocase {[^][\\`_^{|}a-z0-9-]} $n]} { error "bad char in nick
" }
240 if {[regexp {^[-0-9]} $n]} { error "bad nick start
" }
244 return [regexp {^[&#+!]} $dest]
247 proc irctolower {v} {
248 foreach {from to} [list "\\\[" "{" \
252 regsub -all $from $v $to v
254 return [string tolower $v]
257 proc prefix_nick {} {
261 if {![regexp {^([^!]+)!} $p dummy n]} { error "not from nick
" }
263 if {"[irctolower
$n]" == "[irctolower
$nick]"} {
264 error "from myself
" {} {}
268 proc showintervalsecs {howlong} {
269 return [showintervalsecs/[opt timeformat] $howlong]
272 proc showintervalsecs/ks {howlong} {
273 if {$howlong < 1000} {
276 if {$howlong < 1000000} {
283 set value [expr "$howlong.0 / $scale"]
284 foreach {min format} {100 %.0f 10 %.1f 1 %.2f} {
285 if {$value < $min} continue
286 return [format "$format${pfx
}s
" $value]
291 proc format_qty {qty unit} {
295 if {$qty != 1} { append o s }
299 proc showintervalsecs/hms {qty} {
300 set ul {second 60 minute 60 hour 24 day 7 week}
302 while {[llength $ul] > 1 && $qty >= [set uv [lindex $ul 1]]} {
303 set remainu [lindex $ul 0]
304 set remainv [expr {$qty % $uv}]
305 set qty [expr {($qty-$remainv)/$uv}]
306 set ul [lreplace $ul 0 1]
308 set o [format_qty $qty [lindex $ul 0]]
311 append o [format_qty $remainv $remainu]
316 proc showinterval {howlong} {
320 return "[showintervalsecs
$howlong] ago
"
324 proc showtime {when} {
325 return [showinterval [expr {[clock seconds] - $when}]]
328 proc def_msgproc {name argl body} {
329 proc msg_$name "varbase
$argl" "\
330 upvar #0 msg/\$varbase/dest d\n\
331 upvar #0 msg/\$varbase/str s\n\
332 upvar #0 msg/\$varbase/accum a\n\
336 def_msgproc begin {dest str} {
342 def_msgproc append {str} {
344 if {[string length $s] && [string length $ns] > 65} {
345 msg__sendout $varbase
346 set s " [string trimleft
$str]"
352 def_msgproc finish {} {
353 msg__sendout $varbase
359 def_msgproc _sendout {} {
360 lappend a [string trimright $s]
364 proc looking_whenwhere {when where} {
365 set str [showtime [expr {$when-1}]]
366 if {[string length $where]} { append str " on
$where" }
370 proc recordlastseen_n {n how here} {
371 global lastseen lookedfor
372 set lastseen([irctolower $n]) [list $n [clock seconds] $how]
374 upvar #0 lookedfor([irctolower $n]) lf
375 if {[info exists lf]} {
376 switch -exact [llength $lf] {
381 manyset [lindex $lf 0] when who where
383 "FYI
, $who was looking
for you
[looking_whenwhere
$when $where].
"]
386 msg_begin tosend $n "FYI
, people have been looking
for you
:"
392 msg_append tosend " "
393 } elseif {$i == [llength $lf]} {
394 msg_append tosend " and
"
397 msg_append tosend ", "
399 manyset $e when who where
401 "$who ([looking_whenwhere
$when $where])$fin"
403 set ml [msg_finish tosend]
407 msendprivmsg_delayed 1000 $n $ml
411 proc recordlastseen_p {p how here} {
413 recordlastseen_n $n $how $here
416 proc chanmode_arg {} {
418 set rv [lindex $cm_args 0]
419 set cm_args [lreplace cm_args 0 0]
423 proc chanmode_o1 {m g p chan} {
424 global nick chan_initialop
426 set who [chanmode_arg]
427 recordlastseen_n $n "being nice to
$who" 1
428 if {"[irctolower
$who]" == "[irctolower
$nick]"} {
429 set nl [irctolower $n]
430 upvar #0 nick_unique($n) u
431 if {[chandb_exists $chan]} {
432 sendprivmsg $n Thanks.
433 } elseif {![info exists u]} {
434 sendprivmsg $n {Op me while not on the channel, why don't you ?}
436 set chan_initialop([irctolower $chan]) $u
438 "Thanks. You can use `channel manager ...' to register this channel.
"
439 if {![nickdb_exists $n] || ![string length [nickdb_get $n username]]} {
441 "(But to do that you must register your nick securely first.
)"
447 proc chanmode_o0 {m g p chan} {
450 set who [chanmode_arg]
451 recordlastseen_p $p "being mean to
$who" 1
452 if {"[irctolower
$who]" == "[irctolower
$nick]"} {
453 set chandeop($chan) [list [clock seconds] $p]
457 proc msg_MODE {p c dest modelist args} {
458 if {![ischan $dest]} return
459 if {[regexp {^\-(.+)$} $modelist dummy modelist]} {
461 } elseif {[regexp {^\+(.+)$} $modelist dummy modelist]} {
464 error "invalid modelist
"
466 foreach m [split $modelist] {
467 set procname chanmode_$m$give
468 if {[catch { info body $procname }]} {
469 recordlastseen_p $p "fiddling with
$dest" 1
471 $procname $m $give $p $dest
476 proc channel_noone_seen {chan} {
478 foreach n [array names nick_onchans] {
479 upvar #0 nick_onchans($n) oc
480 set oc [grep tc {"$tc" != "$chan"} $oc]
484 proc process_kickpart {chan user} {
487 if {![ischan $chan]} { error "not a channel
" }
488 if {"[irctolower
$user]" == "[irctolower
$nick]"} {
489 channel_noone_seen $chan
491 upvar #0 nick_onchans($user) oc
492 set lc [irctolower $chan]
493 set oc [grep tc {"$tc" != "$lc"} $oc]
494 if {![llength $oc]} { nick_forget $user }
498 proc msg_KICK {p c chans users comment} {
499 set chans [split $chans ,]
500 set users [split $users ,]
501 if {[llength $chans] > 1} {
502 foreach chan $chans user $users { process_kickpart $chan $user }
504 foreach user $users { process_kickpart [lindex $chans 0] $user }
508 proc msg_KILL {p c user why} {
513 set nick_arys {onchans username unique}
515 proc nick_forget {n} {
517 foreach ary $nick_arys {
518 upvar #0 nick_${ary}($n) av
526 set nick_case([irctolower $n]) $n
529 proc msg_NICK {p c newnick} {
530 global nick_arys nick_case
532 recordlastseen_n $n "changing nicks to
$newnick" 0
533 recordlastseen_n $newnick "changing nicks from
$n" 1
534 foreach ary $nick_arys {
535 upvar #0 nick_${ary}($n) old
536 upvar #0 nick_${ary}($newnick) new
537 if {[info exists new]} { error "nick collision ?
! $ary $n $newnick" }
538 if {[info exists old]} { set new $old; unset old }
543 proc nick_ishere {n} {
545 upvar #0 nick_unique($n) u
546 if {![info exists u]} { set u [incr nick_counter].$n.[clock seconds] }
550 proc msg_JOIN {p c chan} {
552 recordlastseen_n $n "joining
$chan" 1
553 upvar #0 nick_onchans($n) oc
554 lappend oc [irctolower $chan]
557 proc msg_PART {p c chan} {
559 recordlastseen_n $n "leaving
$chan" 1
560 process_kickpart $chan $n
562 proc msg_QUIT {p c why} {
564 recordlastseen_n $n "leaving
($why)" 0
568 proc msg_PRIVMSG {p c dest text} {
570 if {[ischan $dest]} {
571 recordlastseen_n $n "invoking me in
$dest" 1
574 recordlastseen_n $n "talking to me
" 1
580 regsub {^! *} $text {} text
582 set procname ucmd/[string tolower $ucmd]
583 if {[catch { info body $procname }]} {
584 error "unknown command
; try help
for help
"
588 sendprivmsg $n "error: $rv"
590 manyset $rv priv_msgs pub_msgs priv_acts pub_acts
591 foreach {td val} [list $n $priv_acts $output $pub_acts] {
592 foreach l [split $val "\n"] {
593 sendaction_priority 0 $td $l
596 foreach {td val} [list $n $priv_msgs $output $pub_msgs] {
597 foreach l [split $val "\n"] {
604 proc msg_INVITE {p c n chan} {
605 after 1000 [list sendout JOIN $chan]
608 proc grep {var predicate list} {
612 if {[uplevel 1 [list expr $predicate]]} { lappend o $v }
617 proc msg_353 {p c dest type chan nicklist} {
618 global names_chans nick_onchans
619 if {![info exists names_chans]} { set names_chans {} }
620 set chan [irctolower $chan]
621 lappend names_chans $chan
622 channel_noone_seen $chan
623 foreach n [split $nicklist { }] {
624 regsub {^[@+]} $n {} n
625 if {![string length $n]} continue
627 upvar #0 nick_onchans($n) oc
633 proc msg_366 {p c args} {
634 global names_chans nick_onchans
635 if {[llength names_chans] > 1} {
636 foreach n [array names nick_onchans] {
637 upvar #0 nick_onchans($n) oc
638 set oc [grep tc {[lsearch -exact $tc $names_chans] >= 0} $oc]
639 if {![llength $oc]} { nick_forget $n }
647 return [expr {!![string length $text]}]
652 if {[string length $text]} { error "too many parameters
" }
657 if {![regexp {^([^ ]+) *(.*)} $text dummy firstword text]} {
658 error "too few parameters
"
670 proc def_ucmd {cmdname body} {
671 proc ucmd/$cmdname {p dest} " upvar 1 text text\n$body"
674 proc ucmdr {priv pub args} {
675 return -code return [concat [list $priv $pub] $args]
681 catch { unset help_topics }
682 set f [open helpinfos r]
685 while {[gets $f l] >= 0} {
687 if {[regexp {^#.*} $l]} {
688 } elseif {[regexp {^ *$} $l]} {
689 if {[info exists topic]} {
690 set help_topics($topic) [join $lines "\n"]
694 } elseif {[regexp {^!([-+._0-9a-z]*)$} $l dummy newtopic]} {
695 if {[info exists topic]} {
696 error "help
$newtopic while in
$topic"
700 } elseif {[regexp {^[^!#]} $l]} {
702 lappend lines [string trimright $l]
704 error "eh ?
$lno: $l"
707 if {[info exists topic]} { error "unfinished topic
$topic" }
714 if {[set lag [out_lagged]]} {
715 if {[ischan $dest]} { set replyto $dest } else { set replyto $n }
717 sendaction_priority 1 $replyto \
718 "is very lagged. Please ask
for help again later.
"
721 sendaction_priority 1 $replyto \
722 "is lagged. Your help will arrive shortly ...
"
726 upvar #0 help_topics([irctolower [string trim $text]]) info
727 if {![info exists info]} { ucmdr "No help on
$text, sorry.
" {} }
733 ucmdr $help_topics() {}
736 proc check_username {target} {
738 [string length $target] > 8 ||
739 [regexp {[^-0-9a-z]} $target] ||
740 ![regexp {^[a-z]} $target]
741 } { error "invalid username
" }
744 proc somedb__head {} {
746 set idl [irctolower $id]
747 upvar #0 ${nickchan}db($idl) ndbe
748 binary scan $idl H* idh
749 set idfn $fprefix$idh
750 if {![info exists iddbe] && [file exists $idfn]} {
752 try_except_finally { set newval [read $f] } {} { close $f }
753 if {[llength $newval] % 2} { error "invalid length
" }
759 proc def_somedb {name arglist body} {
760 foreach {nickchan fprefix} {nick users/n chan chans/c} {
761 proc ${nickchan}db_$name $arglist \
762 "set nickchan
$nickchan; set fprefix
$fprefix; somedb__head
; $body"
766 def_somedb exists {id} {
767 return [info exists iddbe]
770 def_somedb delete {id} {
771 catch { unset iddbe }
775 set default_settings_nick {timeformat ks}
776 set default_settings_chan {autojoin 1}
778 def_somedb set {id args} {
779 upvar #0 default_settings_$nickchan def
780 if {![info exists iddbe]} { set iddbe $def }
781 foreach {key value} [concat $iddbe $args] { set a($key) $value }
783 foreach {key value} [array get a] { lappend newval $key $value }
784 set f [open $idfn.new w]
788 file rename -force $idfn.new $idfn
796 def_somedb get {id key} {
797 upvar #0 default_settings_$nickchan def
798 if {[info exists iddbe]} {
803 foreach {tkey value} $l {
804 if {"$tkey" == "$key"} { return $value }
806 error "unset setting
$key"
811 if {[info exists calling_nick]} { set n $calling_nick } { set n {} }
812 return [nickdb_get $n $key]
815 proc check_notonchan {} {
817 if {[ischan $dest]} { error "that command must be sent privately
" }
820 proc nick_securitycheck {strict} {
822 if {![nickdb_exists $n]} { error "you are
unknown to me
, use `register'.
" }
823 set wantu [nickdb_get $n username]
824 if {![string length $wantu]} {
826 error "that feature is only available to secure users
, sorry.
"
831 upvar #0 nick_username($n) nu
832 if {![info exists nu]} {
833 error "nick
$n is secure
, you must identify yourself first.
"
835 if {"$wantu" != "$nu"} {
836 error "you are the wrong user
- the nick
$n belongs to
$wantu, not
$nu"
840 proc channel_securitycheck {channel n} {
841 # You must also call `nick_securitycheck 1'
842 set mgrs [chandb_get $channel managers]
843 if {[lsearch -exact [irctolower $mgrs] [irctolower $n]] < 0} {
844 error "you are not a manager of
$channel"
848 proc def_chancmd {name body} {
849 proc channel/$name {} \
850 " upvar 1 target chan
; upvar 1 n n
; upvar 1 text text; $body"
853 def_chancmd manager {
855 switch -exact _$opcode {
858 if {[chandb_exists $chan]} {
859 set ml [chandb_get $chan managers]
861 set ml [list [irctolower $n]]
865 error "`channel manager' opcode must be one of
+ - ="
868 foreach nn [split $text " "] {
869 if {![string length $nn]} continue
871 set nn [irctolower $nn]
872 if {"$opcode" != "-"} {
875 set ml [grep nq {"$nq" != "$nn"} $ml]
879 chandb_set $chan managers $ml
880 ucmdr "Managers of
$chan: $ml" {}
883 ucmdr {} {} "forgets about managing
$chan.
" {}
887 def_chancmd autojoin {
889 switch -exact [string tolower $yesno] {
892 default { error "channel autojoin must be `yes' or `no'
}
894 chandb_set
$chan autojoin
$nv
898 if {[chandb_exists
$chan]} {
899 set l
"Settings for $chan: autojoin "
900 append l
[lindex {no yes
} [chandb_get
$chan autojoin
]]
901 append l
"\nManagers: "
902 append l
[join [chandb_get
$chan managers
] " "]
905 ucmdr
{} "The channel $chan is not managed."
910 if {[ischan
$dest]} { set target
$dest }
911 if {[ta_anymore
]} { set target
[ta_word
] }
913 if {![info exists target
]} { error "you must specify, or !... on, the channel" }
914 if {![ischan
$target]} { error "not a valid channel" }
915 if {![chandb_exists
$target]} { error "$target is not a managed channel." }
918 channel_securitycheck
$target $n
919 sendout MODE
$target +o
$n
923 if {[ischan
$dest]} { set target
$dest }
929 if {[ischan
$subcmd]} {
937 if {![info exists target
]} { error "privately, you must specify a channel" }
938 set procname channel
/$subcmd
939 if {"$subcmd" != "show"} {
940 if {[catch { info body
$procname }]} { error "unknown channel setting $subcmd" }
943 if {[chandb_exists
$target]} {
944 channel_securitycheck
$target $n
946 upvar #0 chan_initialop([irctolower $target]) io
947 upvar #0 nick_unique($n) u
948 if {![info exists io
]} { error "$target is not a managed channel" }
949 if {"$io" != "$u"} { error "you are not the interim manager of $target" }
950 if {"$subcmd" != "manager"} { error "use `channel manager' first" }
958 set target
[ta_word
]; ta_nomore
963 set myself
[expr {"$target" != "$n"}]
965 upvar #0 nick_case([irctolower $target]) nc
967 if {[info exists nc
]} {
968 upvar #0 nick_onchans($nc) oc
969 upvar #0 nick_username($nc) nu
970 if {[info exists oc
]} { set nshow
$nc }
972 if {![nickdb_exists
$target]} {
973 set ol
"$nshow is not a registered nick."
974 } elseif
{[string length
[set username
[nickdb_get
$target username
]]]} {
975 set ol
"The nick $nshow belongs to the user $username."
977 set ol
"The nick $nshow is registered (but not to a username)."
979 if {![info exists nc
] ||
![info exists oc
]} {
981 append ol
"\nI can't see $nshow on anywhere."
983 append ol
"\nYou aren't on any channels with me."
985 } elseif
{![info exists nu
]} {
986 append ol
"\n$nshow has not identified themselves."
987 } elseif
{![info exists username
]} {
988 append ol
"\n$nshow has identified themselves as the user $nu."
989 } elseif
{"$nu" != "$username"} {
990 append ol
"\nHowever, $nshow is being used by the user $nu."
992 append ol
"\n$nshow has identified themselves to me."
1000 set old
[nickdb_exists
$n]
1001 if {$old} { nick_securitycheck
0 }
1002 switch -exact [string tolower
[string trim
$text]] {
1004 upvar #0 nick_username($n) nu
1005 if {![info exists nu
]} {
1007 "You must identify yourself before using `register'. See `help identify', or use `register insecure'."
1009 nickdb_set
$n username
$nu
1010 ucmdr
{} {} "makes a note of your username." {}
1014 ucmdr
{} {} "forgets your nickname." {}
1017 nickdb_set
$n username
{}
1019 ucmdr
{} "Security is now disabled for your nickname !"
1021 ucmdr
{} "This is fine, but bear in mind that people will be able to mess with your settings. Channel management features need a secure registration." "makes an insecure registration for your nick."
1027 proc timeformat_desc
{tf
} {
1029 ks
{ return "Times will be displayed in seconds or kiloseconds." }
1030 hms
{ return "Times will be displayed in hours, minutes, etc." }
1031 default { error "invalid timeformat: $v" }
1035 proc def_setting
{opt show_body set_body
} {
1036 proc set_show
/$opt {} "
1040 if {![string length
$set_body]} return
1041 proc set_set
/$opt {} "
1048 def_setting timeformat
{
1049 set tf
[nickdb_get
$n timeformat
]
1050 return "$tf: [timeformat_desc $tf]"
1052 set tf
[string tolower
[ta_word
]]
1054 set desc
[timeformat_desc
$tf]
1055 nickdb_set
$n timeformat
$tf
1059 def_setting security
{
1060 set s
[nickdb_get
$n username
]
1061 if {[string length
$s]} {
1062 return "Your nick, $n, is controlled by the user $s."
1064 return "Your nick, $n, is not secure."
1071 if {![nickdb_exists
$n]} {
1072 ucmdr
{} "You are unknown to me and so have no settings. (Use `register'.)"
1074 if {![ta_anymore
]} {
1076 foreach proc [lsort [info procs
]] {
1077 if {![regexp {^set_show
/(.
*)$} $proc dummy opt
]} continue
1078 lappend ol
[format "%-10s %s" $opt [set_show
/$opt]]
1080 ucmdr
{} [join $ol "\n"]
1083 if {[catch { info body set_show
/$opt }]} {
1084 error "no setting $opt"
1086 if {![ta_anymore
]} {
1087 ucmdr
{} "$opt [set_show/$opt]"
1089 nick_securitycheck
0
1090 if {[catch { info body set_set
/$opt }]} {
1091 error "setting $opt cannot be set with `set'"
1098 def_ucmd identpass
{
1099 set username
[ta_word
]
1100 set passmd5
[md5sum
"[ta_word]\n"]
1104 upvar #0 nick_onchans($n) onchans
1105 if {![info exists onchans
] ||
![llength $onchans]} {
1106 ucmdr
"You must be on a channel with me to identify yourself." {}
1108 check_username
$username
1109 exec userv
--timeout 3 $username << "$passmd5\n" > /dev
/null
\
1111 upvar #0 nick_username($n) rec_username
1112 set rec_username
$username
1113 ucmdr
"Pleased to see you, $username." {}
1117 set target
[ta_word
]
1119 check_username
$target
1122 upvar #0 lastsummon($target) ls
1123 set now
[clock seconds
]
1124 if {[info exists ls
]} {
1125 set interval
[expr {$now - $ls}]
1126 if {$interval < 30} {
1128 "Please be patient; $target was summoned only [showinterval $interval]."
1131 regsub {^
[^
!]*!} $p {} path
1133 exec userv
--timeout 3 $target irc-summon
$n $path \
1134 [expr {[ischan
$dest] ?
"$dest" : ""}] \
1137 regsub -all "\n" $rv { / } rv
1140 if {[regexp {^problem
(.
*)} $rv dummy problem
]} {
1141 ucmdr
{} "The user `$target' $problem."
1142 } elseif
{[regexp {^ok
([^
]+) ([0-9]+)$} $rv dummy tty idlesince
]} {
1143 set idletime
[expr {$now - $idlesince}]
1145 ucmdr
{} {} {} "invites $target ($tty[expr {
1146 $idletime > 10 ? ", idle
for [showintervalsecs
$idletime]" : ""
1148 [ischan $dest] ? "join us here
" : "talk to you
"
1151 error "unexpected response from userv service: $rv"
1155 proc md5sum
{value
} { exec md5sum
<< $value }
1158 global lastseen nick
1161 set nlower
[irctolower
$ncase]
1163 set now
[clock seconds
]
1164 if {"$nlower" == "[irctolower $nick]"} {
1165 error "I am not self-aware."
1166 } elseif
{![info exists lastseen
($nlower)]} {
1167 set rstr
"I've never seen $ncase."
1169 manyset
$lastseen($nlower) realnick
time what
1170 set howlong
[expr {$now - $time}]
1171 set string [showinterval
$howlong]
1172 set rstr
"I last saw $realnick $string, $what."
1174 if {[ischan
$dest]} {
1179 upvar #0 lookedfor($nlower) lf
1180 if {[info exists lf
]} { set oldvalue
$lf } else { set oldvalue
{} }
1181 set lf
[list [list $now $n $where]]
1182 foreach v
$oldvalue {
1183 if {"[irctolower [lindex $v 1]]" == "[irctolower $n]"} continue
1189 proc ensure_globalsecret
{} {
1192 if {[info exists globalsecret
]} return
1193 set gsfile
[open /dev
/urandom r
]
1194 fconfigure $gsfile -translation binary
1195 set globalsecret
[read $gsfile 32]
1196 binary scan $globalsecret H
* globalsecret
1201 proc ensure_outqueue
{} {
1203 if {[info exists out_queue
]} return
1204 set out_creditms
[expr {$out_maxburst*$out_interval}]
1205 set out_creditat
[clock seconds
]
1207 set out_lag_reported
0
1208 set out_lag_reportwhen
$out_creditat
1212 logerror
"failing: $msg"
1216 proc ensure_connecting
{} {
1217 global sock ownfullname host port nick
1218 global musthaveping_ms musthaveping_after
1220 if {[info exists sock
]} return
1221 set sock
[socket $host $port]
1222 fconfigure $sock -buffering line
1223 fconfigure $sock -translation crlf
1225 sendout USER blight
0 * $ownfullname
1227 fileevent $sock readable onread
1229 set musthaveping_after
[after $musthaveping_ms \
1230 {fail
"no ping within timeout"}]
1238 #if {![regexp {tclsh} $argv0]} {