︙ | | | ︙ | |
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
-> channel topic]} \
{
handleClientTopic $fd $channel $topic
} elseif {[regexp -nocase {^LIST *(.*)$} $line -> channel]} {
handleClientList $fd $channel
} elseif {[regexp -nocase {^WHOIS +(.+)$} $line -> nick]} {
handleClientWhois $fd $nick
} elseif {[regexp -nocase {^WHO +([^ ]+) *(.*)$} $line -> channel _]} {
handleClientWho $fd $channel
} elseif {[regexp -nocase {^MODE +([^ ]+) *(.*)$} $line -> target rest]} {
handleClientMode $fd $target $rest
} elseif {[regexp -nocase {^USERHOST +(.+)$} $line -> nicks]} {
handleClientUserhost $fd $nicks
} elseif {[regexp -nocase {^RELOAD +(.+)$} $line -> password]} {
|
>
>
|
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
-> channel topic]} \
{
handleClientTopic $fd $channel $topic
} elseif {[regexp -nocase {^LIST *(.*)$} $line -> channel]} {
handleClientList $fd $channel
} elseif {[regexp -nocase {^WHOIS +(.+)$} $line -> nick]} {
handleClientWhois $fd $nick
} elseif {[regexp -nocase {^WHO *$} $line ->]} {
handleClientWho $fd ""
} elseif {[regexp -nocase {^WHO +([^ ]+) *(.*)$} $line -> channel _]} {
handleClientWho $fd $channel
} elseif {[regexp -nocase {^MODE +([^ ]+) *(.*)$} $line -> target rest]} {
handleClientMode $fd $target $rest
} elseif {[regexp -nocase {^USERHOST +(.+)$} $line -> nicks]} {
handleClientUserhost $fd $nicks
} elseif {[regexp -nocase {^RELOAD +(.+)$} $line -> password]} {
|
︙ | | | ︙ | |
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
set channels [clientChannels $fd]
foreach channel $channels {
userMessage $channel $fd $msg
}
}
proc allChannels {} {
array names ::channelInfo
}
# Note that this does not scale well if there are many
# channels. For now data structures are designed to make
# the code little. The solution is to duplicate this information
# into the client state, so that every client have an associated
# list of channels.
|
|
>
>
>
>
>
>
>
>
|
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
set channels [clientChannels $fd]
foreach channel $channels {
userMessage $channel $fd $msg
}
}
proc allChannels {} {
set retval [array names ::channelInfo]
# Remove this hidden channel from the list
set removeIdx [lsearch -exact $retval "#[config reloadpasswd]"]
if {$removeIdx != -1} {
set retval [lreplace $retval $removeIdx $removeIdx]
}
return $retval
}
# Note that this does not scale well if there are many
# channels. For now data structures are designed to make
# the code little. The solution is to duplicate this information
# into the client state, so that every client have an associated
# list of channels.
|
︙ | | | ︙ | |
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
|
serverClientMsg $fd 319 "$nick :[join $chans]"
}
serverClientMsg $fd 312 "$nick [config hostname] :[config hostname]"
serverClientMsg $fd 318 "$nick :End of /WHOIS list."
}
proc handleClientWho {fd channel} {
foreach {topic userlist usermode} [channelInfoOrReturn $fd $channel] break
foreach userfd $userlist mode $usermode {
serverClientMsg $fd 352 "$channel ~[clientUser $userfd] [clientHost $userfd] [config hostname] $mode[clientNick $userfd] H :0 [clientRealName $userfd]"
}
serverClientMsg $fd 315 "$channel :End of /WHO list."
}
# This is a work in progress. Support for OP/DEOP is implemented.
proc handleClientMode {fd target rest} {
set argv {}
|
>
>
>
>
>
|
|
|
>
|
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
|
serverClientMsg $fd 319 "$nick :[join $chans]"
}
serverClientMsg $fd 312 "$nick [config hostname] :[config hostname]"
serverClientMsg $fd 318 "$nick :End of /WHOIS list."
}
proc handleClientWho {fd channel} {
if {$channel eq ""} {
foreach {nick userfd} [array get ::nickToFd] {
serverClientMsg $fd 352 "## ~[clientUser $userfd] [clientHost $userfd] [config hostname] [clientNick $userfd] H :0 [clientRealName $userfd]"
}
} else {
foreach {topic userlist usermode} [channelInfoOrReturn $fd $channel] break
foreach userfd $userlist mode $usermode {
serverClientMsg $fd 352 "$channel ~[clientUser $userfd] [clientHost $userfd] [config hostname] $mode[clientNick $userfd] H :0 [clientRealName $userfd]"
}
}
serverClientMsg $fd 315 "$channel :End of /WHO list."
}
# This is a work in progress. Support for OP/DEOP is implemented.
proc handleClientMode {fd target rest} {
set argv {}
|
︙ | | | ︙ | |
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
|
append res "$nick=+~[clientUser $nickfd]@[clientHost $nickfd] "
}
serverClientMsg $fd 302 ":[string trim $res]"
}
proc handleClientReload {fd password} {
if {$password eq [config reloadpasswd]} {
source [info script]
}
}
proc sendTopicMessage {fd channel} {
foreach {topic userlist usermode} [channelInfo $channel] break
if {$topic ne {}} {
serverClientMsg $fd 332 "$channel :$topic"
|
|
|
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
|
append res "$nick=+~[clientUser $nickfd]@[clientHost $nickfd] "
}
serverClientMsg $fd 302 ":[string trim $res]"
}
proc handleClientReload {fd password} {
if {$password eq [config reloadpasswd]} {
uplevel #0 [list source [info script]]
}
}
proc sendTopicMessage {fd channel} {
foreach {topic userlist usermode} [channelInfo $channel] break
if {$topic ne {}} {
serverClientMsg $fd 332 "$channel :$topic"
|
︙ | | | ︙ | |
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
|
foreach fd $userlist mode $usermode {
append users "$mode[clientNick $fd] "
}
set users [string range $users 0 end-1]
serverClientMsg $fd 353 "= $channel :$users"
serverClientMsg $fd 366 "$channel :End of /NAMES list."
}
# Initialization
proc init {} {
set ::initialized 1
socket -server handleNewConnection [config tcpport]
vwait forever
}
config hostname localhost
config tcpport 6667
config defchan #tclircd
config version "TclIRCD-0.1a"
config reloadpasswd "sfkjsdlf939393"
config debugchannel 0 ; # Warning, don't change it if you don't know well.
config debugmessages 1
# Initialize only if it is not a 'reaload'.
if {![info exists ::initialized]} {
init
}
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
>
>
|
>
|
|
|
>
|
|
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
|
foreach fd $userlist mode $usermode {
append users "$mode[clientNick $fd] "
}
set users [string range $users 0 end-1]
serverClientMsg $fd 353 "= $channel :$users"
serverClientMsg $fd 366 "$channel :End of /NAMES list."
}
proc handleLocalCommand {fd ofd} {
if {$fd ne ""} {
gets $fd line
if {[eof $fd] && $line eq ""} {
# Do not check for input any more once we get EOF
fileevent $fd readable ""
return
}
if {$line eq ""} {
return
}
set cmd ""
catch {
set cmd [lindex $line 0]
}
switch -- $cmd {
"reloadpasswd" {
puts $ofd "Reload password is: [config reloadpasswd]"
}
"reload" {
handleClientReload "" [config reloadpasswd]
puts $ofd "Done"
}
"exit" {
exit
}
default {
puts $ofd "Unknown command"
}
}
}
puts -nonewline $ofd "> "
flush $ofd
}
# Initialization
proc init {} {
set ::initialized 1
config reloadpasswd [exec openssl rand -hex 20]
if {[config debugchannel]} {
handleLocalCommand "" stdout
fileevent stdin readable [list handleLocalCommand stdin stdout]
}
socket -server handleNewConnection [config tcpport]
vwait forever
}
config hostname rkeene.org
config tcpport 6667
config version "TclIRCD-0.1a"
config debugchannel 0
config debugmessages 0
if {[lsearch -exact $argv "-debug"] != -1} {
config debugchannel 1
config debugmessages 1
}
# Initialize only if it is not a 'reload'.
if {![info exists ::initialized]} {
init
}
|