📄 functions.in
字号:
setbits();}# *** help() ***# Prints the cheesy help screen.sub help { my $handle = shift; toHandle($handle, "*", " " . dateStr()); toHandle($handle, "* Geektalk Help:"); toHandle($handle, "* /bye or /quit" .(" " x 21)."quit from geektalk"); toHandle($handle, "* /signon [<channel #>]" .(" " x 13). "signon to geektalk session"); toHandle($handle, "* /signoff" .(" " x 26)."signoff from geektalk session"); toHandle($handle, "* /channel [<channel #>]" .(" " x 12)."show/change channel"); toHandle($handle, "* /invite <user>" .(" " x 20)."invite <user> to your channel"); toHandle($handle, "* /names [<user>]" .(" " x 19)."list users"); toHandle($handle, "* /stats [<user>]" .(" " x 19)."get various statistics"); toHandle($handle, "* /ping <user>".(" " x 22). "send a 'beep' to <user>"); toHandle($handle, "* /tell <user> <msg>".(" " x 16). "send a message to <user>"); toHandle($handle, "* /ignore [<user> [on|off|0|1]]".(" " x 5). "start or stop ignoring a user"); toHandle($handle, "* /times [on|off|1|0]" .(" " x 15). "Turn timestamping of messages on/off"); toHandle($handle, "* /echo [on|off|1|0]" .(" " x 16). "Turn echoing of your own message on/off"); toHandle($handle, "* /me <message>" .(" " x 21). "Do an action (\"/me eats bl00d.\")"); toHandle($handle, "* /nuclear <message>" .(" "x16). "Print something anonymously"); toHandle($handle, "* /username <username>" .(" "x14). "Change your username"); toHandle($handle, "*");}# *** ignore() ***# Accepts a user to ignore (or unignore...).sub ignore { my ($handle, $user, $boolean) = @_; $boolean = lc($boolean); if(!defined $user || $user eq "") { if(keys(%{$handles{$handle}{ignore}}) == 0) { toHandle($handle, "", "<".dateStr()."> ", "* You are not ignoring anyone."); } else { my $ignorelist; foreach(sort {$a cmp $b} keys %{$handles{$handle}{ignore}}) { $ignorelist .= "$_ "; } toHandle($handle, "","<".dateStr()."> ", "* Users you are ignoring: ".$ignorelist); } } elsif($user eq $handles{$handle}{username}) { toHandle($handle, "", "<".dateStr().". ", "* You can not ignore yourself. Use /echo off."); } elsif(!defined $boolean || $boolean eq "") { if(exists $handles{$handle}{ignore}{$user}) { delete $handles{$handle}{ignore}{$user}; toHandle($handle, "","<".dateStr()."> ", "* You are no longer ignoring $user."); } else { $handles{$handle}{ignore}{$user} = 1; toHandle($handle, "","<".dateStr()."> ", "* You are now ignoring $user."); } } elsif($boolean eq "on" || $boolean eq "1") { $handles{$handle}{ignore}{$user} = 1; toHandle($handle, "","<".dateStr()."> ", "* You are now ignoring $user."); } elsif($boolean eq "off" || $boolean eq "0") { delete $handles{$handle}{ignore}{$user}; toHandle($handle, "","<".dateStr()."> ", "* You are no longer ignoring $user."); } else { toHandle($handle, "", "<".dateStr()."> ", "* Invalid argument."); }}# *** initstats() ***# Sets some initial values to 0 in %statssub initstats { $stats{signon} = 0; $stats{lines} = 0; $stats{spoken} = 0; $stats{start} = time();}# *** invite() ***# Accepts a user to invite from, and a user to invite.sub invite { my ($from, $to) = @_; if ($handles{$from}{flag} != 5) { notOn($from); } elsif(!exists $users{$to}) { toHandle($from, "", "<".dateStr()."> ", "* User not found."); } elsif($users{$to}{flag} != 5) { toHandle($from, "", "<".dateStr()."> ", "* User is not signed on."); } else { my $fromname = $handles{$from}{username}; my $tohandle = $users{$to}{handle}; my $fromchan = $handles{$from}{channel}; my $tochan = $users{$to}{channel}; if($fromchan == $tochan) { toHandle($from, "", "<".dateStr()."> ", " $to is already on this channel."); } else { toHandle($from, "", "<".dateStr()."> ", "* you invite $to to channel $fromchan."); toHandle($tohandle, "", "<".dateStr()."> ", "\a\a* $fromname invites you to channel $fromchan."); } }}# *** logmsg() ***# Logs any passed arguments in a standardized format.sub logmsg { my ($sec,$min,$hour,$mday,$mon) = localtime; my $monname = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep", "Oct","Nov","Dec")[$mon]; my $datestr = sprintf("%s %2d %02d:%02d:%02d", $monname, $mday, $hour, $min, $sec); print LOG "$datestr geektalkd: @_", "\n" if (defined $logging); print STDERR "$datestr geektalkd: @_", "\n" if (defined $debug);}# *** nameline() ***# Sends a little info about $user to $handle (for /names and names()sub nameline { my ($handle, $user) = @_; my ($you, $idlestr, $namestr, $chanstr, $hostname); $you = " "; $you = ">" if $handle eq $users{$user}{handle}; $idlestr = timeDiff($users{$user}{spoke}, time()); my $timestr = timeDiff($users{$user}{connect}, time()); $hostname = $users{$user}{hostname}; if($users{$user}{flag} < 5) { $chanstr = "offline"; } elsif($users{$user}{channel} < 0) { $chanstr = "private"; } else { $chanstr = $users{$user}{channel}; } $namestr = sprintf("* %1s%-10s %-15s %6s %7s %s\@%s", $you, $chanstr, $user, $idlestr, $timestr, $user, $hostname); toHandle($handle,$namestr);}# *** names() ***# Lists the currently connected users.sub names { my ($handle, $name) = @_; my $current = time(); my ($you, $idlestr, $namestr, $chanstr); if((!defined $name) || (exists($users{$name}) && $users{$name}{flag} > 3)) { toHandle($handle,"*", " " . dateStr()); toHandle($handle,"* Channel Username Idle Conn'd UserID\@Node"); } if(defined $name) { if(!exists $users{$name} || $users{$name}{flag} < 4) { toHandle($handle, "*", dateStr() . "*", " No such user."); } else { nameline($handle,$name); } } else { foreach my $cuser (sort namesort (keys %users)) { nameline($handle,$cuser) if $users{$cuser}{flag} > 3; } } if((!defined $name) || (exists($users{$name}) && $users{$name}{flag} > 3)) { toHandle($handle, "*"); }}sub namesort { $users{$b}{spoke} <=> $users{$a}{spoke} or $users{$a}{username} cmp $users{$b}{username};}# *** notOn() ***# Prints a standard error message.sub notOn { my $handle = shift; toHandle($handle, "", "<".dateStr()."> ", "* You are not signed on.");}# *** password() ***# Checks to see if the admin password was sent.sub password { my $pw = shift; if($password eq crypt($pw, $password)) { return 1; } else { return 0; }}# *** ping() ***# Accepts a user to ping from, and a user to ping.sub ping { my ($from, $to) = @_; if ($handles{$from}{flag} != 5) { notOn($from); } elsif(!exists $users{$to}) { toHandle($from, "", "<".dateStr()."> ", "* User not found."); } elsif($users{$to}{flag} != 5) { toHandle($from, "", "<".dateStr()."> ", "* User is not signed on."); } else { my $fromname = $handles{$from}{username}; my $tohandle = $users{$to}{handle}; toHandle($from, "", "<".dateStr()."> ", "* You pung $to."); if(!exists $users{$to}{ignore}{$handles{$from}{username}}) { toHandle($tohandle, "", "<".dateStr()."> ", "* $fromname pung \a\ayou!!"); } }}# *** processClients() ***# Called from the main loop. Checks for status on all filehandles. If there is# activity on the Server socket, opens a new connection. Otherwise, reads a# line from the active handle, and passes it off for processing to# processInput();sub processClients { my ($eol, $rout, $chandle, $line, @lines); select($rout=$bits, undef, undef, undef); if(vec($rout, fileno(Server), 1)) { getConnect(); } else { foreach $chandle (keys %handles) { if(vec($rout, fileno($chandle), 1)) { sysread($chandle, $line, 512); if(!$line) { removeHandle($chandle); } else { $eol = chomp($line); @lines = split /\n/, $line; if(!$eol) { ## you know, it seems that elkinsd came up with this ## marvelous idea. if((!exists($handles{$chandle}{glue})) || length($handles{$chandle}{glue}) < 8192) { $handles{$chandle}{glue} .= pop(@lines); } else { shift(@lines); } } else { if(exists $handles{$chandle}{glue}) { if(length($handles{$chandle}{glue}) < 8192) { $handles{$chandle}{glue} .= shift(@lines); } else { shift(@lines); } processInput($chandle, $handles{$chandle}{glue}); delete($handles{$chandle}{glue}); } } foreach (@lines) { processInput($chandle, $_); } } } } }}# *** processInput() ***# Called from processClients when a line of input is read. Parses the input# and passes it off to one of several functions for handling.sub processInput { my($handle, $line) = @_; my @ARGV; ++$stats{lines}; ++$handles{$handle}{lines}; $line =~ s/[\1-\6\10-\37\177]//g; if($line =~ /^\/reparse\b/) { $rehash = 1; toHandle($handle, "", "<".dateStr()."> ", "* Reparsing functions. Thank you for playing."); } elsif($line =~ /^\/access\b/) { if(defined $access) { logmsg("ACCESS: Reparsing $aclfile"); my @return = parseAccessFile(); if($return[0] != 1) { foreach(@return) { toHandle($handle, "", "<".dateStr()."> ", $_); logmsg("ACCESS: $_"); } } else { toHandle($handle, "", "<".dateStr()."> ", "* The access control file $aclfile was parsed ". "sucessfully."); logmsg("ACCESS: $aclfile reparsed successfully."); } } else { toHandle($handle, "", "<".dateStr()."> ", "* Access control was not enabled at runtime. Use the -a ". "option."); } } elsif($line =~ /^\/code\b/) { if(defined $codeon) { @ARGV = split /\s+/, $line, 3; if($password eq crypt($ARGV[1], $password)) { runCode($handle, $ARGV[2]); } else { toHandle($handle, "", "<".dateStr()."> ", "* WRONG PASSWORD, BUCKO."); } } else { toHandle($handle, "", "<".dateStr()."> ", "* /code is disabled in this server."); } } elsif(cmd("help", $line)) { help($handle); } elsif(cmd("bye", $line) || cmd("quit", $line)) { removeHandle($handle); } elsif(cmd("names", $line)) { @ARGV = split /\s+/, $line, 3; names($handle, $ARGV[1]); } elsif($line =~ /^\/stats\b/) { @ARGV = split /\s+/, $line, 3; stats($handle, $ARGV[1]); } elsif($line =~ /^\/about\b/) { about($handle); } elsif(cmd("date", $line)) { open(DATE, 'date|'); my $date = <DATE>; chomp $date; toHandle($handle, "", "<".dateStr()."> ", "* The date is: ".$date); } elsif($handles{$handle}{flag} < 4) { doLoginProcessing($handle, $line); } elsif(cmd("signon", $line)) { @ARGV = split /\s+/, $line, 3; if($handles{$handle}{flag} == 4) { signon($handles{$handle}{username}, $ARGV[1]); } else { toHandle($handle, "", "<".dateStr()."> ", "* You are already signed on."); } } elsif(cmd("signoff", $line)) { if($handles{$handle}{flag} == 5) { signoff($handles{$handle}{username}); } else { notOn($handle); } } elsif(cmd("channel", $line)) { @ARGV = split /\s+/, $line, 3; channel($handle, $ARGV[1]); } elsif(cmd("echo", $line)) { @ARGV = split /\s+/, $line, 3; echo($handle, $ARGV[1]); } elsif(cmd("tell", $line)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -