]> icculus.org git repositories - divverent/nexuiz.git/blob - Docs/server/rcon2irc/rbiserver.pl
hopefully fix high CPU load in connection trouble
[divverent/nexuiz.git] / Docs / server / rcon2irc / rbiserver.pl
1 sub out($$@);
2
3 sub markmap($$$$;$)
4 {
5         my ($state, $map, $pro, $total, $who) = @_;
6         open my $fh, '>>', "$ENV{HOME}/.nexuiz/__votelog.$config{irc_nick}.txt"
7                 or die "votelog open: $!";
8         print $fh "@{[time()]} $config{irc_nick} $state $map $pro $total" . (defined $who ? " $who" : "") . "\n";
9         close $fh;
10 }
11
12 # call the log analyzer at the end of a match
13 [ dp => q{:end} => sub {
14         system(q{
15                 for X in ~/Nexuiz/home/.nexuiz/extramaps/data/*.log; do
16                         if [ x"`tail -n 1 "$X"`" = x":gameover" ]; then
17                                 ssh hector 'l=$HOME/.nexuiz/server-remote-$RANDOM.log; cat >"$l"; ~/.nexuiz/logspam/addlogs-processonly.sh "$l"' < "$X"
18                                 rm -f "$X"
19                         fi
20                 done
21         });
22         return 0;
23 } ],
24
25 # the AOL calendar
26 [ dp => q{\001(.*?)\^7: d} => sub {
27         my $aoltime = time() - 746748000;
28         my $day = int($aoltime / 86400);
29         my $wday = [qw[Tue Wed Thu Fri Sat Sun Mon]]->[$day % 7];
30         my $hour = int($aoltime / 3600) % 24;
31         my $minute = int($aoltime / 60) % 60;
32         my $second = int($aoltime / 1) % 60;
33         out dp => 0, sprintf 'rcon2irc_say_as "AOL service" "The time is %3s Sep %2d %02d:%02d:%02d 1993"',
34                 $wday, $day, $hour, $minute, $second;
35         return 1;
36 } ],
37
38 # map vote logging
39 [ dp => q{:vote:suggestion_accepted:(.*)} => sub {
40         my ($map) = @_;
41         markmap suggestion_accepted => $map, $store{rbi_winvotes}, $store{rbi_totalvotes};
42         return 0;
43 } ],
44 [ dp => q{:vote:suggested:(.*?):\d+:(.*)} => sub {
45         my ($map, $who) = @_;
46         markmap suggested => $map, 1, 1, $who;
47         return 0;
48 } ],
49 [ dp => q{\001\^2\* .*'s vote for \^1gotomap (.*)\^2 was accepted} => sub {
50         my ($map) = @_;
51         markmap voted => $map, 1, 1;
52         return 0;
53 } ],
54 [ dp => q{\001\^2\* .*'s vote for \^1timelimit -1\^2 was accepted} => sub {
55         markmap cancelled => $store{map}, 1, 1;
56         return 0;
57 } ],
58 [ dp => q{:vote:(keeptwo|finished):(.*)} => sub {
59         my ($status, $result) = @_;
60         my @result = split /:/, $result;
61         my $totalvotes = 0;
62         my $cutoff = -1;
63         my @allmaps = map
64         {
65                 $cutoff = $_ if $result[2*$_] eq '';
66                 $totalvotes += int($result[2*$_+1] || 0);
67                 [$result[2*$_], int($result[2*$_+1] || 0)]
68         } 0..((@result-1)/2);
69         die "Invalid vote result: $result" unless $cutoff >= 0;
70         my @winners = @allmaps[0..($cutoff-1)];
71         my @losers = @allmaps[($cutoff+1)..(@allmaps-1)];
72         my $winvotes = 0;
73         $winvotes += $_->[1] for @winners;
74         if($status eq 'keeptwo')
75         {
76                 markmap irrelevant_relative => $_->[0], $winvotes, $totalvotes
77                         for @losers;
78         }
79         elsif($status eq 'finished')
80         {
81                 markmap((@losers == 1 ? 'duel_winner' : 'winner_absolute') => $_->[0], $_->[1], $totalvotes)
82                         for @winners;
83                 markmap((@losers == 1 ? 'duel_loser' : 'irrelevant_absolute') => $_->[0], $winvotes, $totalvotes)
84                         for @losers;
85         }
86         $store{rbi_winvotes} = $winvotes;
87         $store{rbi_totalvotes} = $totalvotes;
88         return 0;
89 } ],