bot:seer
Differences
This shows you the differences between two versions of the page.
bot:seer [2018/02/21 21:37] โ created karl | bot:seer [2018/02/21 21:48] (current) โ removed karl | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== BOT Seer ====== | ||
- | The BOT //Seer// found on the [[: | ||
- | As a player, I use him occasionally. | ||
- | |||
- | This is what the client cmdline '' | ||
- | < | ||
- | Seer tells you: | ||
- | I'm a bot, and I'm writing kill logs for all players and monsters. | ||
- | |||
- | You can ask me about: | ||
- | last < | ||
- | | ||
- | |||
- | Seer tells you: | ||
- | | ||
- | tell < | ||
- | | ||
- | |||
- | Seer tells you: | ||
- | kills < | ||
- | | ||
- | how killed < | ||
- | |||
- | Seer tells you: | ||
- | | ||
- | | ||
- | how died < | ||
- | |||
- | Seer tells you: | ||
- | what killed < | ||
- | did < | ||
- | |||
- | find < | ||
- | |||
- | Seer tells you: | ||
- | Besides this, I'm afraid I'm not very intelligent. :) | ||
- | </ | ||
- | |||
- | Some years ago (Modification time tells me February 2013), I found a [[: | ||
- | < | ||
- | This is Google' | ||
- | It is a snapshot of the page as it appeared on Feb 16, 2013 04:44:39 | ||
- | GMT. The current page < | ||
- | could have changed in the meantime. Learn more | ||
- | < | ||
- | Tip: To quickly find your search term on this page, press *Ctrl+F* or | ||
- | *โ-F* (Mac) and use the find bar. | ||
- | |||
- | Text-only version | ||
- | < | ||
- | These search terms are highlighted: | ||
- | </ | ||
- | It is a //GNU General Public License// file by '' | ||
- | <code pl> | ||
- | # | ||
- | |||
- | # | ||
- | # ------------------------------------------------------------------------- | ||
- | # | ||
- | # Copyright (C) 2003 Jochen Suckfuell < | ||
- | # | ||
- | # This program is free software; you can redistribute it and/or modify | ||
- | # it under the terms of the GNU General Public License as published by | ||
- | # the Free Software Foundation; either version 2 of the License, or | ||
- | # (at your option) any later version. | ||
- | # | ||
- | # This program is distributed in the hope that it will be useful, | ||
- | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
- | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
- | # GNU General Public License for more details. | ||
- | # | ||
- | # You should have received a copy of the GNU General Public License | ||
- | # along with this program; if not, write to the Free Software | ||
- | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
- | # | ||
- | # ----------------------------------------------------------------------- | ||
- | # | ||
- | # TODO | ||
- | # | ||
- | # - fix inventory logging | ||
- | # - check if event_wait and event_listen loops work | ||
- | # | ||
- | # | ||
- | # Changelog: | ||
- | # | ||
- | # 2005-05-28 0.9.9 | ||
- | # - added the setup flag "bot 1" to tell the server that this is a bot | ||
- | # | ||
- | # 2004-03-11 0.9.8 | ||
- | # - new commands: add_admin, rem_admin, admins | ||
- | # - added the admin commands to the help output | ||
- | # - removed the " | ||
- | # - fixed parsing changed 'who output format | ||
- | # - save the is_admin flag with the players | ||
- | # - allow several admin users | ||
- | # - implement numdeaths, numkills | ||
- | # - ' | ||
- | # - implemented storing more stats | ||
- | # - added events_stats callbacks | ||
- | # - we now log the players that enter a map whose name matches a pattern in | ||
- | # the predefined array @check_maps | ||
- | # | ||
- | # 2003-02-13 Release 0.9.7 | ||
- | # | ||
- | # - 'last < | ||
- | # - implemented the 'host < | ||
- | # - Don't answer to " | ||
- | # | ||
- | # 2003-02-04 Release 0.9.6 | ||
- | # | ||
- | # - implemented script command "when hearing < | ||
- | # | ||
- | # | ||
- | # 2003-02-03 Release 0.9.5 | ||
- | # | ||
- | # - implemented simple scripting commands, conditions are still missing | ||
- | # - slowed down the decay of map scores | ||
- | # - output integer values for map scores | ||
- | # - use the ' | ||
- | # - only reply to " | ||
- | # | ||
- | </ | ||
- | I am not capable in the //perl// scripting language, and can not say anything about this script. 1900 lines : | ||
- | <code perl> | ||
- | # | ||
- | |||
- | # | ||
- | # ------------------------------------------------------------------------- | ||
- | # | ||
- | # Copyright (C) 2003 Jochen Suckfuell < | ||
- | # | ||
- | # This program is free software; you can redistribute it and/or modify | ||
- | # it under the terms of the GNU General Public License as published by | ||
- | # the Free Software Foundation; either version 2 of the License, or | ||
- | # (at your option) any later version. | ||
- | # | ||
- | # This program is distributed in the hope that it will be useful, | ||
- | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
- | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
- | # GNU General Public License for more details. | ||
- | # | ||
- | # You should have received a copy of the GNU General Public License | ||
- | # along with this program; if not, write to the Free Software | ||
- | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
- | # | ||
- | # ----------------------------------------------------------------------- | ||
- | # | ||
- | # TODO | ||
- | # | ||
- | # - fix inventory logging | ||
- | # - check if event_wait and event_listen loops work | ||
- | # | ||
- | # | ||
- | # Changelog: | ||
- | # | ||
- | # 2005-05-28 0.9.9 | ||
- | # - added the setup flag "bot 1" to tell the server that this is a bot | ||
- | # | ||
- | # 2004-03-11 0.9.8 | ||
- | # - new commands: add_admin, rem_admin, admins | ||
- | # - added the admin commands to the help output | ||
- | # - removed the " | ||
- | # - fixed parsing changed 'who output format | ||
- | # - save the is_admin flag with the players | ||
- | # - allow several admin users | ||
- | # - implement numdeaths, numkills | ||
- | # - ' | ||
- | # - implemented storing more stats | ||
- | # - added events_stats callbacks | ||
- | # - we now log the players that enter a map whose name matches a pattern in | ||
- | # the predefined array @check_maps | ||
- | # | ||
- | # 2003-02-13 Release 0.9.7 | ||
- | # | ||
- | # - 'last < | ||
- | # - implemented the 'host < | ||
- | # - Don't answer to " | ||
- | # | ||
- | # 2003-02-04 Release 0.9.6 | ||
- | # | ||
- | # - implemented script command "when hearing < | ||
- | # | ||
- | # | ||
- | # 2003-02-03 Release 0.9.5 | ||
- | # | ||
- | # - implemented simple scripting commands, conditions are still missing | ||
- | # - slowed down the decay of map scores | ||
- | # - output integer values for map scores | ||
- | # - use the ' | ||
- | # - only reply to " | ||
- | # | ||
- | # | ||
- | # | ||
- | # | ||
- | # | ||
- | # | ||
- | # | ||
- | |||
- | # ====================== | ||
- | |||
- | use vars qw/ | ||
- | |||
- | $remote_host = " | ||
- | $player_name = " | ||
- | $player_password = " | ||
- | $retry_interval = 30; # time in seconds | ||
- | $admin = " "; | ||
- | $leave_cmd = "go home"; | ||
- | |||
- | # We keep a player log for these maps: | ||
- | @check_map = ( " | ||
- | |||
- | # =================== | ||
- | |||
- | $version = " | ||
- | | ||
- | use POSIX; | ||
- | use IO::Socket; | ||
- | use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); | ||
- | |||
- | |||
- | $events_stats{' | ||
- | $events_stats{' | ||
- | $events_stats{' | ||
- | $events_stats{' | ||
- | |||
- | load(); | ||
- | |||
- | $socket = ''; | ||
- | init_connection(); | ||
- | |||
- | $recvbuf = ''; | ||
- | $quit = 0; | ||
- | my $save_minutes = 10; # This will be counted down and reset to 10, below. | ||
- | |||
- | my $last_time = time; | ||
- | $getting_who_answer = 0; | ||
- | $last_maps_decay_time = time; | ||
- | |||
- | $SIG{INT} = sub { $quit = 1; print STDERR " | ||
- | |||
- | # main event loop | ||
- | while(! $quit) | ||
- | { | ||
- | my $r_in = ''; | ||
- | vec($r_in, $socket-> | ||
- | |||
- | my $rv = select($r_in, | ||
- | if(!defined($rv) || $rv < 0) | ||
- | { | ||
- | unless($! == EINTR) { die " | ||
- | last; | ||
- | } | ||
- | |||
- | if($rv && vec($r_in, $socket-> | ||
- | { | ||
- | my $rv = $socket-> | ||
- | unless (defined($rv)) | ||
- | { | ||
- | print STDERR "recv failed: $!\n"; | ||
- | init_connection(); | ||
- | $recvbuf = ''; | ||
- | next; | ||
- | } | ||
- | |||
- | if(length($buf) == 0) | ||
- | { | ||
- | print STDERR " | ||
- | init_connection(); | ||
- | $recvbuf = ''; | ||
- | next; | ||
- | } | ||
- | $recvbuf .= $buf; | ||
- | while(length($recvbuf) >= 2) | ||
- | { | ||
- | my $len = unpack(" | ||
- | #print "DEBUG len $len , recvbuf length is " | ||
- | |||
- | if(length($recvbuf) < 2 + $len) { last; } | ||
- | |||
- | #print unpack(" | ||
- | my $data = substr($recvbuf, | ||
- | handle($data); | ||
- | $recvbuf = substr($recvbuf, | ||
- | } # len info | ||
- | } # $socket is readable | ||
- | |||
- | my $now = time; | ||
- | next if $last_time == $now; | ||
- | |||
- | if($now - $last_time > 60) | ||
- | { | ||
- | # This is processed once per minute. | ||
- | |||
- | $last_time = $now; | ||
- | |||
- | $save_minutes--; | ||
- | if($save_minutes == 0) | ||
- | { | ||
- | save(); | ||
- | $save_minutes = 10; | ||
- | } | ||
- | |||
- | if($now - $last_maps_decay_time > 24*60*60) | ||
- | { | ||
- | # once per day | ||
- | |||
- | # We halve the map score values once per day: | ||
- | foreach my $map (keys %maps) | ||
- | { | ||
- | $maps{$map} *= 0.25; | ||
- | if($maps{$map} == 0) { delete $maps{$map}; | ||
- | } | ||
- | $last_maps_decay_time = $now; | ||
- | } | ||
- | |||
- | cf_send_cmd(" | ||
- | } | ||
- | |||
- | for(my $i = 0; $i < scalar @events_wait; | ||
- | { | ||
- | my $event_ref = $events_wait[$i]; | ||
- | if($event_ref-> | ||
- | { | ||
- | splice @events_wait, | ||
- | do_execute($event_ref-> | ||
- | } | ||
- | } | ||
- | |||
- | } | ||
- | |||
- | save(); | ||
- | |||
- | exit 0; | ||
- | |||
- | # =============================================================== | ||
- | |||
- | sub init_connection | ||
- | { | ||
- | if($socket) { $socket-> | ||
- | while(!($socket = IO:: | ||
- | { | ||
- | print STDERR " | ||
- | print STDERR " | ||
- | sleep $retry_interval; | ||
- | } | ||
- | |||
- | my $flags = fcntl($socket, | ||
- | fcntl($socket, | ||
- | |||
- | $pkg_sent = 0; | ||
- | $pkg_ackd = 0; | ||
- | cf_send(" | ||
- | cf_send(" | ||
- | cf_send(" | ||
- | $upsince = time; | ||
- | print "Login at " | ||
- | } | ||
- | |||
- | sub handle | ||
- | { | ||
- | my $line = shift; | ||
- | $line =~ / | ||
- | my $cmd = $1; | ||
- | my $args = $2; | ||
- | |||
- | if($cmd =~ / | ||
- | { | ||
- | $args =~ / | ||
- | my $color = $1; | ||
- | my $info = $2; | ||
- | |||
- | if($getting_who_answer) | ||
- | { | ||
- | $getting_who_answer = parse_who($info); | ||
- | |||
- | # Return if we got another WHO line, else process the new line as | ||
- | # normal. | ||
- | return if $getting_who_answer; | ||
- | } | ||
- | |||
- | if($info =~ /^((?:(?! killed) ? | ||
- | { | ||
- | if(defined $kills{$info}) | ||
- | { | ||
- | $kills{$info}++; | ||
- | } | ||
- | else | ||
- | { | ||
- | $kills{$info} = 1; | ||
- | } | ||
- | return; | ||
- | } | ||
- | |||
- | if($info =~/ | ||
- | { | ||
- | $getting_who_answer = 1; | ||
- | return; | ||
- | } | ||
- | |||
- | if($info =~ /^(\S+) has entered the game.$/) | ||
- | { | ||
- | my $name = $1; | ||
- | $player_ref = $players{$name}; | ||
- | unless(defined $player_ref) | ||
- | { | ||
- | $player_ref = { asked_me => 0, message => "", | ||
- | $players{$name} = $player_ref; | ||
- | } | ||
- | elsif($player_ref-> | ||
- | { | ||
- | my $msg = $player_ref-> | ||
- | $msg =~ s/_-/\n/g; | ||
- | sleep 3; | ||
- | cf_send_info(" | ||
- | $player_ref-> | ||
- | } | ||
- | |||
- | $player_ref-> | ||
- | $player_ref-> | ||
- | |||
- | |||
- | print "> | ||
- | return; | ||
- | } | ||
- | |||
- | if($info =~ /^(\S+) (leaves|left) the game.$/) | ||
- | { | ||
- | my $name = $1; | ||
- | $player_ref = $players{$name}; | ||
- | unless(defined $player_ref) | ||
- | { | ||
- | $player_ref = { asked_me => 0, message => "" | ||
- | $players{$name} = $player_ref; | ||
- | } | ||
- | $player_ref-> | ||
- | $player_ref-> | ||
- | |||
- | return; | ||
- | } | ||
- | |||
- | if($info =~ /^(\S+) tells you: (.*)\??$/) | ||
- | { | ||
- | handle_player_request($1, | ||
- | return; | ||
- | } | ||
- | |||
- | if($info =~ /^(\S+) shouts: $player_name[:, | ||
- | { | ||
- | handle_player_request($1, | ||
- | return; | ||
- | } | ||
- | |||
- | if($info =~ /^(\S+) shouts: (hi\b|hello|morning)\s+$player_name!?/ | ||
- | { | ||
- | my $pl = $1; | ||
- | return if $pl eq $player_name; | ||
- | my $pl_ref = $players{$pl}; | ||
- | return unless (defined $pl_ref && $pl_ref-> | ||
- | sleep 3; | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | if($info =~ /^Welcome Back!$/) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | cf_send_cmd(" | ||
- | if(defined $scripts{" | ||
- | { | ||
- | $script_stack{" | ||
- | do_execute(" | ||
- | } | ||
- | return; | ||
- | } | ||
- | |||
- | # Blue color text (in cfclient at least) is for NPC speech and other | ||
- | # messages from the map. | ||
- | if($color == 2) | ||
- | { | ||
- | for(my $i = 0; $i < scalar @events_listen; | ||
- | { | ||
- | my $event_ref = $events_listen[$i]; | ||
- | if($info =~ / | ||
- | { | ||
- | splice @events_listen, | ||
- | do_execute($event_ref-> | ||
- | } | ||
- | } | ||
- | } | ||
- | |||
- | #print "INFO: $color $info\n"; | ||
- | |||
- | return; | ||
- | } | ||
- | |||
- | if($cmd =~ /^query$/) | ||
- | { | ||
- | print "$args "; | ||
- | if($args =~ /What is your name/) | ||
- | { | ||
- | cf_send(" | ||
- | return; | ||
- | } | ||
- | |||
- | if($args =~ /What is your password/) | ||
- | { | ||
- | cf_send(" | ||
- | return; | ||
- | } | ||
- | |||
- | if($args =~ /Do you want to play again/) | ||
- | { | ||
- | cf_send(" | ||
- | return; | ||
- | } | ||
- | |||
- | my $answer = < | ||
- | chomp $answer; | ||
- | cf_send(" | ||
- | return; | ||
- | } | ||
- | |||
- | if($cmd =~ /^comc$/) | ||
- | { | ||
- | ($pkg_ackd) = unpack(" | ||
- | if(scalar @cmds_waiting) | ||
- | { | ||
- | $pkg_sent++; | ||
- | if($pkg_sent == 256) { $pkg_sent = 0; } | ||
- | cf_send(" | ||
- | } | ||
- | |||
- | return; | ||
- | } | ||
- | |||
- | if($cmd =~ /^stats$/) | ||
- | { | ||
- | while($args) | ||
- | { | ||
- | my $s; | ||
- | ($s, $args) = unpack ('C a*', $args); | ||
- | last if $s > 26; | ||
- | if($s == 18) # food | ||
- | { | ||
- | ($stats{' | ||
- | #print "food: $stats{food}\n"; | ||
- | if($stats{' | ||
- | { | ||
- | foreach my $event_ref (@{$events_stats{' | ||
- | { | ||
- | do_execute($event_ref-> | ||
- | } | ||
- | $events_stats{ ' | ||
- | } | ||
- | } | ||
- | elsif($s == 1) # HP | ||
- | { | ||
- | ($stats{' | ||
- | #print "hp: $stats{hp}\n"; | ||
- | if(defined $stats{' | ||
- | { | ||
- | @events = @{$events_stats{' | ||
- | $events_stats{ ' | ||
- | foreach my $event_ref (@events) | ||
- | { | ||
- | do_execute($event_ref-> | ||
- | } | ||
- | $events_stats{ ' | ||
- | } | ||
- | } | ||
- | elsif($s == 2) # max HP | ||
- | { | ||
- | ($stats{' | ||
- | #print " | ||
- | } | ||
- | elsif($s == 3) # SP | ||
- | { | ||
- | ($stats{' | ||
- | #print "sp: $stats{sp}\n"; | ||
- | if(defined $stats{' | ||
- | { | ||
- | @events = @{$events_stats{' | ||
- | $events_stats{ ' | ||
- | foreach my $event_ref (@events) | ||
- | { | ||
- | do_execute($event_ref-> | ||
- | } | ||
- | } | ||
- | } | ||
- | elsif($s == 4) # max SP | ||
- | { | ||
- | ($stats{' | ||
- | #print " | ||
- | } | ||
- | elsif($s == 23) # grace | ||
- | { | ||
- | ($stats{' | ||
- | #print " | ||
- | if(defined $stats{' | ||
- | { | ||
- | @events = @{$events_stats{' | ||
- | $events_stats{ ' | ||
- | foreach my $event_ref (@events) | ||
- | { | ||
- | do_execute($event_ref-> | ||
- | } | ||
- | $events_stats{ ' | ||
- | } | ||
- | } | ||
- | elsif($s == 24) # max SP | ||
- | { | ||
- | ($stats{' | ||
- | #print " | ||
- | } | ||
- | elsif($s == 11) # exp | ||
- | { | ||
- | ($stats{' | ||
- | #print "exp: $stats{exp}\n"; | ||
- | } | ||
- | elsif($s == 12) # level | ||
- | { | ||
- | ($stats{' | ||
- | print " | ||
- | } | ||
- | elsif($s == 13) # WC | ||
- | { | ||
- | my $wc; | ||
- | ($wc, $args) = unpack(' | ||
- | $stats{' | ||
- | print "wc: $stats{wc}\n"; | ||
- | } | ||
- | elsif($s == 14) # AC | ||
- | { | ||
- | my $ac; | ||
- | ($ac, $args) = unpack(' | ||
- | $stats{' | ||
- | print "ac: $stats{ac}\n"; | ||
- | } | ||
- | elsif($s == 17 || $s == 19 || $s == 26) | ||
- | { | ||
- | (undef, $args) = unpack(' | ||
- | } | ||
- | else | ||
- | { | ||
- | (undef, $args) = unpack(' | ||
- | } | ||
- | } | ||
- | return; | ||
- | } | ||
- | |||
- | if($cmd =~ /^item1$/) | ||
- | { | ||
- | my ($location, $tag, $flags, $weight, $name, $nrof); | ||
- | %inv = (); | ||
- | ($location, | ||
- | return unless $location; | ||
- | while($args) | ||
- | { | ||
- | ($tag, $flags, $weight, undef, $name, undef, undef, $nrof, $args) = unpack ('N N N N C/A n C N a*', $args); | ||
- | ($name, undef) = split /\0/, $name; | ||
- | $inv{$tag} = { name => $name, flags => $flags, weight => $weight, nrof => $nrof }; | ||
- | #print "INV1: $nrof $name ($weight)\n"; | ||
- | } | ||
- | return; | ||
- | } | ||
- | |||
- | if($cmd =~ /^item2$/) | ||
- | { | ||
- | my ($location, $tag, $flags, $weight, $name, $nrof); | ||
- | %inv = (); | ||
- | ($location, | ||
- | return unless $location; | ||
- | while($args) | ||
- | { | ||
- | ($tag, $flags, $weight, undef, $name, undef, undef, $nrof, undef, $args) = unpack ('N N N N C/A n C N n a*', $args); | ||
- | $inv{$tag} = { name => $name, flags => $flags, weight => $weight, nrof => $nrof }; | ||
- | #print "INV2: $nrof $name ($weight)\n"; | ||
- | } | ||
- | return; | ||
- | } | ||
- | |||
- | if($cmd =~ / | ||
- | { | ||
- | return; | ||
- | } | ||
- | |||
- | print "> | ||
- | |||
- | if( | ||
- | $cmd =~ /^setup$/ | ||
- | ) | ||
- | { | ||
- | print " $args"; | ||
- | } | ||
- | print " | ||
- | } | ||
- | |||
- | |||
- | sub handle_player_request | ||
- | { | ||
- | my $player = shift; | ||
- | my $request = shift; | ||
- | my $answer_command = shift; | ||
- | |||
- | $player_ref = $players{$player}; | ||
- | unless(defined $player_ref) | ||
- | { | ||
- | $player_ref = { asked_me => 0, last_seen => time, is_here => 1, message => "" | ||
- | $players{$player} = $player_ref; | ||
- | } | ||
- | |||
- | $player_ref-> | ||
- | |||
- | if($learning && $admin =~ / $player /) | ||
- | { | ||
- | # This continues a script. | ||
- | if($request eq "end $learning" | ||
- | { | ||
- | cf_send_cmd(" | ||
- | $learning = ""; | ||
- | return; | ||
- | } | ||
- | |||
- | push @{$scripts{$learning}}, | ||
- | return; | ||
- | } | ||
- | |||
- | # | ||
- | if($request =~ / | ||
- | { | ||
- | sleep 2; | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | cf_send_info($answer_command, | ||
- | I'm a bot, and I'm writing kill logs for all players and monsters. | ||
- | |||
- | You can ask me about: | ||
- | |||
- | last < | ||
- | | ||
- | | ||
- | tell < | ||
- | | ||
- | |||
- | kills < | ||
- | | ||
- | how killed < | ||
- | |||
- | | ||
- | | ||
- | who killed < | ||
- | what killed < | ||
- | |||
- | Besides this, I'm afraid I'm not very intelligent. :) | ||
- | |||
- | HELP | ||
- | if($players{$player}{is_admin} == 1) | ||
- | { | ||
- | cf_send_info($answer_command, | ||
- | Special admin commands are: | ||
- | |||
- | do < | ||
- | learn < | ||
- | end < | ||
- | | ||
- | | ||
- | | ||
- | stop < | ||
- | | ||
- | |||
- | | ||
- | | ||
- | | ||
- | | ||
- | |||
- | For my scripting abilities please check the document at: | ||
- | | ||
- | |||
- | ADMIN_HELP | ||
- | } | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | my $other = $1; | ||
- | my $other_ref = $players{$other}; | ||
- | unless(defined $other_ref) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | my $msg = " | ||
- | |||
- | if($other_ref-> | ||
- | { | ||
- | cf_send_info(" | ||
- | sleep 2; | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | $msg =~ s#\n#_-#g; | ||
- | $other_ref-> | ||
- | sleep 2; | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | my $other = $1; | ||
- | |||
- | unless(defined $players{$other}) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | sleep 2; | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ /^last$/i) | ||
- | { | ||
- | my @last_seen = sort { $players{$b}{last_seen} <=> $players{$a}{last_seen} } keys %players; | ||
- | my $i = 0; | ||
- | my $out = ""; | ||
- | foreach my $pl (@last_seen) | ||
- | { | ||
- | next if $players{$pl}{" | ||
- | $out .= "\n$pl was here at " | ||
- | $i++; | ||
- | last if $i == 10; | ||
- | } | ||
- | cf_send_info($answer_command, | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ /uptime/i) | ||
- | { | ||
- | sleep 2; | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | my $name = $1; | ||
- | chomp $name; | ||
- | my $info = ""; | ||
- | my $total = 0; | ||
- | foreach my $kill (sort { $kills{$b} <=> $kills{$a} } keys %kills) | ||
- | { | ||
- | if($kill =~ /^$name killed /i) | ||
- | { | ||
- | $info .= $kills{$kill}." | ||
- | $total += $kills{$kill}; | ||
- | } | ||
- | } | ||
- | |||
- | if(!$info) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | $info .= " | ||
- | |||
- | |||
- | cf_send_info($answer_command, | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | my $name = $1; | ||
- | chomp $name; | ||
- | my $total = 0; | ||
- | foreach my $kill (sort { $kills{$b} <=> $kills{$a} } keys %kills) | ||
- | { | ||
- | if($kill =~ /^$name killed /i) | ||
- | { | ||
- | $total += $kills{$kill}; | ||
- | } | ||
- | } | ||
- | |||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | my $name = $1; | ||
- | chomp $name; | ||
- | my $total = 0; | ||
- | foreach my $kill (sort { $kills{$b} <=> $kills{$a} } keys %kills) | ||
- | { | ||
- | if($kill =~ / killed $name(\.| with )/i) | ||
- | { | ||
- | $total += $kills{$kill}; | ||
- | } | ||
- | } | ||
- | |||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | my $name = $1; | ||
- | chomp $name; | ||
- | my $info = ""; | ||
- | my $total = 0; | ||
- | foreach my $kill (sort { $kills{$b} <=> $kills{$a} } keys %kills) | ||
- | { | ||
- | if($kill =~ / killed $name(\.| with )/i) | ||
- | { | ||
- | $info .= " | ||
- | $total += $kills{$kill}; | ||
- | } | ||
- | } | ||
- | |||
- | if(!$info) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | $info .= " | ||
- | |||
- | cf_send_info($answer_command, | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | my $who = $1; | ||
- | if(length($who) < 3) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | my %matches = (); | ||
- | my $info = ""; | ||
- | foreach my $kill (sort { $kills{$b} <=> $kills{$a} } keys %kills) | ||
- | { | ||
- | unless($kill =~ / | ||
- | { | ||
- | #print STDERR "find regexp failed, ' | ||
- | next; | ||
- | } | ||
- | |||
- | my $name1 = $1; | ||
- | my $name2 = $2; | ||
- | next if defined $matches{$name1}; | ||
- | next if defined $matches{$name2}; | ||
- | #print STDERR " | ||
- | if($name1 =~ /$who/i) | ||
- | { | ||
- | $matches{$name1} = 1; | ||
- | $info .= " | ||
- | } | ||
- | if($name2 =~ /$who/i) | ||
- | { | ||
- | $matches{$name2} = 1; | ||
- | $info .= " | ||
- | } | ||
- | } | ||
- | |||
- | if(!$info) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | $info = " | ||
- | |||
- | cf_send_info($answer_command, | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ /did\s+((?! kill ).+) kill ([^?]+)$/i) | ||
- | { | ||
- | my $name = $1; | ||
- | my $killed = $2; | ||
- | |||
- | my $info = ""; | ||
- | foreach my $kill (sort { $kills{$b} <=> $kills{$a} } keys %kills) | ||
- | { | ||
- | if($kill =~ /$name killed $killed(\.| with )/i) | ||
- | { | ||
- | $info .= " | ||
- | } | ||
- | } | ||
- | |||
- | if(!$info) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | cf_send_info($answer_command, | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ /^how killed\s+([^? | ||
- | { | ||
- | my $name = $1; | ||
- | chomp $name; | ||
- | my %count; | ||
- | foreach my $kill (keys %kills) | ||
- | { | ||
- | if($kill =~ /^($name) killed (?:(?!with )[^.])*([^.]*)\.$/ | ||
- | { | ||
- | my $type = $2; | ||
- | if(! $type) { $type = "with melee"; | ||
- | if(defined $count{$type}) | ||
- | { | ||
- | $count{$type} += $kills{$kill}; | ||
- | } | ||
- | else | ||
- | { | ||
- | $count{$type} = $kills{$kill}; | ||
- | } | ||
- | } | ||
- | } | ||
- | |||
- | if(scalar keys %count == 0) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | my $info = "$1 killed"; | ||
- | foreach my $c (sort { $count{$a} <=> $count{$b} } keys %count) | ||
- | { | ||
- | $info .= " | ||
- | } | ||
- | |||
- | cf_send_info($answer_command, | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ /^how died\s+([^? | ||
- | { | ||
- | my $name = $1; | ||
- | chomp $name; | ||
- | my %count; | ||
- | foreach my $kill (keys %kills) | ||
- | { | ||
- | if($kill =~ / killed $name(?: with ([^.]+))? | ||
- | { | ||
- | my $type = $1; | ||
- | if(! $type) { $type = " | ||
- | |||
- | if(defined $count{$type}) | ||
- | { | ||
- | $count{$type} += $kills{$kill}; | ||
- | } | ||
- | else | ||
- | { | ||
- | $count{$type} = $kills{$kill}; | ||
- | } | ||
- | } | ||
- | } | ||
- | |||
- | if(scalar keys %count == 0) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | my $info = "$name died"; | ||
- | foreach my $c (sort { $count{$a} <=> $count{$b} } keys %count) | ||
- | { | ||
- | $info .= " | ||
- | } | ||
- | |||
- | cf_send_info($answer_command, | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ /^what killed\s+([^? | ||
- | { | ||
- | my $name = $1; | ||
- | chomp $name; | ||
- | my %count; | ||
- | foreach my $kill (keys %kills) | ||
- | { | ||
- | if($kill =~ /killed $name\s*(with[^.]*)? | ||
- | { | ||
- | my $type = $1; | ||
- | if(! $type) { $type = "with melee"; | ||
- | if(defined $count{$type}) | ||
- | { | ||
- | $count{$type} += $kills{$kill}; | ||
- | } | ||
- | else | ||
- | { | ||
- | $count{$type} = $kills{$kill}; | ||
- | } | ||
- | } | ||
- | } | ||
- | |||
- | if(scalar keys %count == 0) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | my $info = "$name was killed"; | ||
- | foreach my $c (sort { $count{$a} <=> $count{$b} } keys %count) | ||
- | { | ||
- | $info .= " | ||
- | } | ||
- | |||
- | cf_send_info($answer_command, | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | if($admin !~ / $player /) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | admin_msg(" | ||
- | return; | ||
- | } | ||
- | |||
- | cf_send_cmd(" | ||
- | $quit = 1; | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | sleep 2; | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ /^maps$/i) | ||
- | { | ||
- | sleep 2; | ||
- | my $show = 0; | ||
- | |||
- | my $info = "The most popular maps are:"; | ||
- | |||
- | foreach my $map (sort { $maps{$b} <=> $maps{$a} } keys %maps) | ||
- | { | ||
- | #print "MAPS $maps{$map} $map\n"; | ||
- | last if $maps{$map} < 5; | ||
- | $info .= " | ||
- | $show++; | ||
- | last if $show == 30; | ||
- | } | ||
- | |||
- | cf_send_info($answer_command, | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | $learning = $1; | ||
- | if($admin !~ / $player /) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | admin_msg(" | ||
- | $learning = ""; | ||
- | return; | ||
- | } | ||
- | |||
- | if(defined $scripts{$learning}) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | $learning = ""; | ||
- | return; | ||
- | } | ||
- | |||
- | $scripts{$learning} = []; | ||
- | cf_send_cmd(" | ||
- | |||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | my $forget = $1; | ||
- | if($admin !~ / $player /) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | admin_msg(" | ||
- | return; | ||
- | } | ||
- | |||
- | unless(defined $scripts{$forget}) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | delete $scripts{$forget}; | ||
- | cf_send_cmd(" | ||
- | |||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | my $command = $1; | ||
- | if($admin !~ / $player /) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | admin_msg(" | ||
- | return; | ||
- | } | ||
- | |||
- | cf_send_cmd(" | ||
- | do_command($command); | ||
- | |||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | my $execute = $1; | ||
- | if($admin !~ / $player /) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | admin_msg(" | ||
- | return; | ||
- | } | ||
- | |||
- | if(!defined $scripts{$execute}) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | if(defined $script_stack{$execute}) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | $script_stack{$execute} = []; | ||
- | |||
- | cf_send_cmd(" | ||
- | do_execute($execute); | ||
- | |||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | my $stop = $1; | ||
- | if($admin !~ / $player /) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | admin_msg(" | ||
- | return; | ||
- | } | ||
- | |||
- | unless(defined $script_stack{$stop}) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | stop_script($stop); | ||
- | |||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | if($admin !~ / $player /) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | my $info = " | ||
- | foreach my $script (keys %script_stack) | ||
- | { | ||
- | $info .= " | ||
- | } | ||
- | cf_send_info($answer_command, | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | if($admin !~ / $player /) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | my $info = "Known scripts are:"; | ||
- | foreach my $script (keys %scripts) | ||
- | { | ||
- | $info .= " | ||
- | } | ||
- | cf_send_info($answer_command, | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ /^inv/) | ||
- | { | ||
- | if($admin !~ / $player /) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | admin_msg(" | ||
- | return; | ||
- | } | ||
- | |||
- | my $info = "My inventory is:"; | ||
- | foreach my $item (keys %inv) | ||
- | { | ||
- | $info .= " | ||
- | } | ||
- | |||
- | cf_send_info($answer_command, | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ /^checked maps$/) | ||
- | { | ||
- | # | ||
- | #{ | ||
- | # | ||
- | # | ||
- | # | ||
- | #} | ||
- | |||
- | my $info = " | ||
- | foreach my $map (keys %checked_map) | ||
- | { | ||
- | $info .= " | ||
- | foreach my $pl (keys %{$checked_map{$map}}) | ||
- | { | ||
- | $info .= "\n$pl $checked_map{$map}{$pl}"; | ||
- | } | ||
- | } | ||
- | |||
- | cf_send_info($answer_command, | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ /^stats$/) | ||
- | { | ||
- | if($admin !~ / $player /) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | admin_msg(" | ||
- | return; | ||
- | } | ||
- | |||
- | my $info = "My stats are:"; | ||
- | foreach my $stat (keys %stats) | ||
- | { | ||
- | $info .= " | ||
- | } | ||
- | |||
- | cf_send_info($answer_command, | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | my $newadm = $1; | ||
- | if($admin !~ / $player /) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | admin_msg(" | ||
- | return; | ||
- | } | ||
- | |||
- | my $newadm_ref = $players{$newadm}; | ||
- | unless(defined $newadm_ref) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | if($newadm_ref-> | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | $admin .= " | ||
- | $newadm_ref-> | ||
- | |||
- | if($newadm_ref-> | ||
- | { | ||
- | cf_send_info(" | ||
- | } | ||
- | else | ||
- | { | ||
- | $newadm_ref-> | ||
- | } | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ / | ||
- | { | ||
- | my $remadm = $1; | ||
- | if($admin !~ / $player /) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | admin_msg(" | ||
- | return; | ||
- | } | ||
- | |||
- | my $remadm_ref = $players{$remadm}; | ||
- | unless(defined $remadm_ref) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | if($remadm_ref-> | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | if($remadm eq $player) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | $admin =~ s/ $remadm / /; | ||
- | $remadm_ref-> | ||
- | |||
- | if($remadm_ref-> | ||
- | { | ||
- | cf_send_info(" | ||
- | } | ||
- | else | ||
- | { | ||
- | $remadm_ref-> | ||
- | } | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | if($request =~ /^admins$/) | ||
- | { | ||
- | sleep 2; | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | sleep 2; | ||
- | cf_send_cmd(" | ||
- | } | ||
- | |||
- | sub do_command | ||
- | { | ||
- | my $cmd = shift; | ||
- | if($cmd =~ / | ||
- | { | ||
- | # We just pass this through. | ||
- | cf_send_cmd($cmd); | ||
- | } | ||
- | } | ||
- | |||
- | sub stop_script | ||
- | { | ||
- | my $scr = shift; | ||
- | return unless defined $scripts{$scr}; | ||
- | return unless defined $script_stack{$scr}; | ||
- | |||
- | foreach my $events_array_ref (\@events_listen, | ||
- | { | ||
- | for(my $i = 0; $i < scalar @$events_array_ref; | ||
- | { | ||
- | my $event_ref = $events_array_ref-> | ||
- | if($scr eq $event_ref-> | ||
- | { | ||
- | splice @$events_array_ref, | ||
- | } | ||
- | } | ||
- | } | ||
- | delete $script_stack{$scr}; | ||
- | } | ||
- | |||
- | sub do_execute | ||
- | { | ||
- | my $scriptname = shift; | ||
- | my $pc = shift || 0; | ||
- | |||
- | for(; $pc < scalar @{$scripts{$scriptname}}; | ||
- | { | ||
- | $cmd = $scripts{$scriptname}[$pc]; | ||
- | print " | ||
- | if($cmd =~ / | ||
- | { | ||
- | # We just pass this through. | ||
- | cf_send_cmd($cmd); | ||
- | next; | ||
- | } | ||
- | |||
- | if($cmd =~ /^execute (\S+)$/) | ||
- | { | ||
- | my $scr = $1; | ||
- | next unless defined $scripts{$scr}; | ||
- | next if defined $script_stack{$scr}; | ||
- | |||
- | $script_stack{$scr} = []; | ||
- | do_execute($scr); | ||
- | next; | ||
- | } | ||
- | |||
- | if($cmd =~ /^stop (\S+)$/) | ||
- | { | ||
- | stop_script($1); | ||
- | last; | ||
- | } | ||
- | |||
- | if($cmd =~ /^wait (\d+)$/) | ||
- | { | ||
- | push @events_wait, | ||
- | last; | ||
- | } | ||
- | |||
- | if($cmd =~ /^for (\d+) times$/) | ||
- | { | ||
- | push @{$script_stack{$scriptname}}, | ||
- | next; | ||
- | } | ||
- | |||
- | if($cmd =~ / | ||
- | { | ||
- | if(scalar @{$script_stack{$scriptname}} == 0) | ||
- | { | ||
- | print "Stack underflow in end_for!\n"; | ||
- | stop_script($scriptname); | ||
- | last; | ||
- | } | ||
- | |||
- | $stack_last = $script_stack{$scriptname}[0]; | ||
- | unless($stack_last-> | ||
- | { | ||
- | print " | ||
- | stop_script($scriptname); | ||
- | return; | ||
- | } | ||
- | $stack_last-> | ||
- | if($stack_last-> | ||
- | { | ||
- | shift @{$script_stack{$scriptname}}; | ||
- | next; | ||
- | } | ||
- | |||
- | $pc = $stack_last-> | ||
- | next; | ||
- | } | ||
- | |||
- | if($cmd =~ / | ||
- | { | ||
- | push @{$script_stack{$scriptname}}, | ||
- | next; | ||
- | } | ||
- | |||
- | if($cmd =~ / | ||
- | { | ||
- | if(scalar @{$script_stack{$scriptname}} == 0) | ||
- | { | ||
- | print "Stack underflow in end_forever!\n"; | ||
- | stop_script($scriptname); | ||
- | return; | ||
- | } | ||
- | |||
- | $stack_last = $script_stack{$scriptname}[0]; | ||
- | unless($stack_last-> | ||
- | { | ||
- | print " | ||
- | stop_script($scriptname); | ||
- | return; | ||
- | } | ||
- | |||
- | $pc = $stack_last-> | ||
- | next; | ||
- | } | ||
- | |||
- | if($cmd =~ /^when hearing\s+(\S.+)$/ | ||
- | { | ||
- | push @events_listen, | ||
- | last; | ||
- | } | ||
- | |||
- | if($cmd =~ /^when stats_event\s+(maxhp|maxsp|maxgrace|lowfood)$/ | ||
- | { | ||
- | push @{$events_stats{$1}}, | ||
- | last; | ||
- | } | ||
- | |||
- | if($cmd eq " | ||
- | { | ||
- | stop_script($scriptname); | ||
- | last; | ||
- | } | ||
- | |||
- | if($cmd =~ /^assert (.*)$/) | ||
- | { | ||
- | last unless script_condition($1); | ||
- | next; | ||
- | } | ||
- | |||
- | cf_send_cmd(" | ||
- | last; | ||
- | } | ||
- | |||
- | if($pc == scalar @{$scripts{$scriptname}}) | ||
- | { | ||
- | stop_script($scriptname); | ||
- | } | ||
- | |||
- | } | ||
- | |||
- | sub script_condition | ||
- | { | ||
- | my $cond = shift; | ||
- | my @words = split (/\s+/, $cond); | ||
- | my @stack = ( ); | ||
- | while (my $word = shift(@words)) | ||
- | { | ||
- | if($word eq " | ||
- | { | ||
- | return 0 if scalar @stack < 1; | ||
- | $stack[$# | ||
- | next; | ||
- | } | ||
- | |||
- | if($word eq " | ||
- | { | ||
- | return 0 if scalar @stack < 2; | ||
- | splice @stack, $#stack-1, 2, ($stack[$# | ||
- | next; | ||
- | } | ||
- | |||
- | if($word eq " | ||
- | { | ||
- | return 0 if scalar @stack < 2; | ||
- | splice @stack, $#stack-1, 2, ($stack[$# | ||
- | next; | ||
- | } | ||
- | |||
- | if($word eq " | ||
- | { | ||
- | return 0 if scalar @stack < 2; | ||
- | splice @stack, $#stack-1, 2, ($stack[$# | ||
- | next; | ||
- | } | ||
- | |||
- | # implement some conditions here XXX | ||
- | } | ||
- | return pop @stack; | ||
- | } | ||
- | |||
- | sub parse_who | ||
- | { | ||
- | my $line = shift; | ||
- | unless ($line =~ /^(\S+) the ([^\]]+)\[([^\]]+)\]/ | ||
- | { | ||
- | #print "WHO next line: $line\n"; | ||
- | return 0; | ||
- | } | ||
- | my $pl = $1; | ||
- | return 1 if $pl eq $player_name; | ||
- | my $title = $2; | ||
- | my $map = $3; | ||
- | $title =~ s/ $//; | ||
- | |||
- | #print "> | ||
- | |||
- | # Set this player' | ||
- | my $player_ref = $players{$pl}; | ||
- | if(defined $player_ref) | ||
- | { | ||
- | if(! $player_ref-> | ||
- | { | ||
- | $player_ref-> | ||
- | if($player_ref-> | ||
- | { | ||
- | my $msg = $player_ref-> | ||
- | $msg =~ s/_-/\n/g; | ||
- | cf_send_info(" | ||
- | $player_ref-> | ||
- | } | ||
- | } | ||
- | } | ||
- | else | ||
- | { | ||
- | $player_ref = { asked_me => 0, is_here => 1, message => "", | ||
- | $players{$pl} = $player_ref; | ||
- | } | ||
- | $player_ref-> | ||
- | |||
- | # Do we log this map's usage? | ||
- | foreach my $map_pat (@check_map) | ||
- | { | ||
- | if($map =~ m# | ||
- | { | ||
- | if(defined $checked_map{$map}{$pl}) | ||
- | { | ||
- | $checked_map{$map}{$pl}++; | ||
- | } | ||
- | else | ||
- | { | ||
- | $checked_map{$map}{$pl} = 1; | ||
- | } | ||
- | } | ||
- | } | ||
- | |||
- | if($map =~ m#/ | ||
- | { | ||
- | # We don't log these maps. | ||
- | return 1; | ||
- | } | ||
- | |||
- | # remove number from random maps: | ||
- | if($map =~ m# | ||
- | { | ||
- | $map =~ s/ | ||
- | } | ||
- | |||
- | # Add to the map popularity: | ||
- | if(defined $maps{$map}) | ||
- | { | ||
- | $maps{$map}++; | ||
- | } | ||
- | else | ||
- | { | ||
- | $maps{$map} = 1; | ||
- | } | ||
- | |||
- | return 1; | ||
- | } | ||
- | |||
- | sub admin_msg | ||
- | { | ||
- | for my $adm (split /\s+/, $admin) | ||
- | { | ||
- | next unless $adm; | ||
- | my $admin_ref = $players{$adm}; | ||
- | return unless defined $admin_ref; | ||
- | |||
- | my $msg = shift; | ||
- | |||
- | if($admin_ref-> | ||
- | { | ||
- | cf_send_cmd(" | ||
- | return; | ||
- | } | ||
- | |||
- | $msg =~ s#\n#_-#g; | ||
- | $admin_ref-> | ||
- | } | ||
- | } | ||
- | |||
- | |||
- | sub cf_send_info | ||
- | { | ||
- | my $answer_command = shift; | ||
- | my $info = shift; | ||
- | my @lines = split(/\n/, $info); | ||
- | |||
- | if(! @lines) { return; } | ||
- | |||
- | my $chunk = shift @lines; | ||
- | foreach $line (@lines) | ||
- | { | ||
- | if(length($chunk) + length($line) < 220) | ||
- | { | ||
- | $chunk .= " | ||
- | } | ||
- | else | ||
- | { | ||
- | if(! $chunk) | ||
- | { | ||
- | die "Text chunk is too large (" | ||
- | } | ||
- | cf_send_cmd(" | ||
- | $chunk = " | ||
- | } | ||
- | } | ||
- | if($chunk) | ||
- | { | ||
- | cf_send_cmd(" | ||
- | } | ||
- | } | ||
- | |||
- | sub cf_send_cmd | ||
- | { | ||
- | push @cmds_waiting, | ||
- | |||
- | my $pending = $pkg_sent - $pkg_ackd; | ||
- | if($pending < 0) { $pending += 256; } | ||
- | while($pending < 3) | ||
- | { | ||
- | my $msg = shift @cmds_waiting; | ||
- | |||
- | # send this command immediately | ||
- | $pkg_sent++; | ||
- | if($pkg_sent == 256) { $pkg_sent = 0; } | ||
- | cf_send(" | ||
- | |||
- | last unless scalar @cmds_waiting; | ||
- | |||
- | $pending++; | ||
- | } | ||
- | |||
- | } | ||
- | |||
- | sub cf_send | ||
- | { | ||
- | my $msg = shift; | ||
- | #print "< | ||
- | my $out = pack(" | ||
- | #print unpack(" | ||
- | print $socket $out; | ||
- | $socket-> | ||
- | } | ||
- | |||
- | |||
- | sub save | ||
- | { | ||
- | open(KILLS, | ||
- | foreach my $key (keys %kills) | ||
- | { | ||
- | print KILLS $key.":" | ||
- | } | ||
- | close KILLS; | ||
- | |||
- | open(SCRIPTS, | ||
- | foreach my $scriptname (keys %scripts) | ||
- | { | ||
- | #print " | ||
- | print SCRIPTS " | ||
- | foreach my $line (@{$scripts{$scriptname}}) | ||
- | { | ||
- | print SCRIPTS " | ||
- | } | ||
- | print SCRIPTS " | ||
- | } | ||
- | close SCRIPTS; | ||
- | |||
- | open(PLS, "> | ||
- | foreach my $key (keys %players) | ||
- | { | ||
- | #print " | ||
- | print PLS " | ||
- | foreach my $plkey (keys %{$players{$key}}) | ||
- | { | ||
- | print PLS " | ||
- | } | ||
- | } | ||
- | close PLS; | ||
- | |||
- | open(MAPS, "> | ||
- | print MAPS " | ||
- | foreach my $map (keys %maps) | ||
- | { | ||
- | #print " | ||
- | print MAPS "$map $maps{$map}\n"; | ||
- | } | ||
- | print MAPS " | ||
- | foreach my $map (keys %checked_map) | ||
- | { | ||
- | print MAPS " | ||
- | foreach my $pl (keys %{$checked_map{$map}}) | ||
- | { | ||
- | print MAPS " | ||
- | } | ||
- | } | ||
- | close MAPS; | ||
- | |||
- | print STDERR "Data saved.\n"; | ||
- | } | ||
- | |||
- | |||
- | sub load | ||
- | { | ||
- | %kills = (); | ||
- | unless(open(KILLS, | ||
- | { | ||
- | print STDERR " | ||
- | } | ||
- | else | ||
- | { | ||
- | print " | ||
- | while(< | ||
- | { | ||
- | chomp; | ||
- | my ($key, $value) = split(/:/, $_); | ||
- | $kills{$key} = $value; | ||
- | } | ||
- | close KILLS; | ||
- | } | ||
- | |||
- | %scripts = (); | ||
- | unless(open(SCRIPTS, | ||
- | { | ||
- | print STDERR " | ||
- | } | ||
- | else | ||
- | { | ||
- | print " | ||
- | while(< | ||
- | { | ||
- | chomp; | ||
- | my $scriptname = $_; | ||
- | print " | ||
- | $scripts{$scriptname} = []; | ||
- | for(;;) | ||
- | { | ||
- | my $line = < | ||
- | chomp $line; | ||
- | last unless $line; | ||
- | print ": | ||
- | |||
- | push @{$scripts{$scriptname}}, | ||
- | } | ||
- | } | ||
- | close SCRIPTS; | ||
- | } | ||
- | |||
- | %players = (); | ||
- | unless(open(PLS, | ||
- | { | ||
- | print STDERR " | ||
- | } | ||
- | else | ||
- | { | ||
- | $current_name = ""; | ||
- | print " | ||
- | while(< | ||
- | { | ||
- | chomp; | ||
- | if(/ | ||
- | { | ||
- | my $key = $1; | ||
- | my $val = $2; | ||
- | if($key eq " | ||
- | { | ||
- | $admin .= " | ||
- | } | ||
- | if($key eq " | ||
- | { | ||
- | # We get the current users from the 'who command. | ||
- | $val = 0; | ||
- | } | ||
- | $players{$current_name}{$key} = $val; | ||
- | } | ||
- | else | ||
- | { | ||
- | $current_name = $_; | ||
- | } | ||
- | } | ||
- | } | ||
- | |||
- | %maps = (); | ||
- | unless(open(MAPS, | ||
- | { | ||
- | print STDERR " | ||
- | } | ||
- | else | ||
- | { | ||
- | print " | ||
- | my $last_maps_decay_time = < | ||
- | chomp $last_maps_decay_time; | ||
- | while(< | ||
- | { | ||
- | chomp; | ||
- | last unless $_; | ||
- | my ($key, $value) = split(/ /, $_); | ||
- | $maps{$key} = $value; | ||
- | } | ||
- | $current_name = ""; | ||
- | while(< | ||
- | { | ||
- | chomp; | ||
- | if(/ | ||
- | { | ||
- | $checked_map{$current_name}{$1} = $2; | ||
- | } | ||
- | else | ||
- | { | ||
- | $current_name = $_; | ||
- | } | ||
- | } | ||
- | close MAPS; | ||
- | } | ||
- | |||
- | } | ||
- | |||
- | </ |
bot/seer.1519270639.txt.gz ยท Last modified: (external edit)