]> icculus.org git repositories - divverent/nexuiz.git/blob - server/rcon2irc/joinsparts.pl
sloppy (faster) gibs
[divverent/nexuiz.git] / server / rcon2irc / joinsparts.pl
1 # Nexuiz rcon2irc plugin by Merlijn Hofstra licensed under GPL - joinsparts.pl
2 # Place this file inside the same directory as rcon2irc.pl and add the full filename to the plugins.
3 # Don't forget to edit the options below to suit your needs.
4
5 my %pj = (
6         irc_announce_joins => 1,
7         irc_announce_parts => 1,
8         irc_show_playerip => 0,
9         irc_show_mapname => 0,
10         irc_show_amount_of_players => 0
11 );
12
13 $store{plugin_joinsparts} = \%pj;
14
15 sub out($$@);
16
17 sub get_player_count
18 {
19         my $count = 0;
20         for (1 .. $store{slots_max}) {
21                 my $id = $store{"playerid_byslot_$_"};
22                 $count++ if (defined $id && $store{"playerip_byid_$id"} ne 'bot');
23         }
24         return $count;
25 }
26
27 # chat: Nexuiz server -> IRC channel, nick set
28 [ dp => q{:join:(\d+):(\d+):([^:]*):(.*)} => sub {
29         my ($id, $slot, $ip, $nick) = @_;
30         my $pj = $store{plugin_joinsparts};
31         $store{"playernickraw_byid_$id"} = $nick;
32         $nick = color_dp2irc $nick;
33         if ($pj->{irc_announce_joins} && !$store{"playerid_byslot_$slot"} && $ip ne 'bot') {
34                 out irc => 0, "PRIVMSG $config{irc_channel} :\00309+ join\017: $nick\017" . 
35                         ($pj->{irc_show_playerip} ? " (\00304$ip\017)" : '') .
36                         ($pj->{irc_show_mapname} ? " playing on \00304$store{map}\017" : '') .
37                         ($pj->{irc_show_amount_of_players} ? " players: \00304" . (get_player_count()+1) . "\017/$store{slots_max}" : '');
38         }
39         return 0;
40 } ],
41 # Record parts so the info in $store is always up to date
42 [ dp => q{:part:(\d+)} => sub {
43         my ($id) = @_;
44         my $pj = $store{plugin_joinsparts};
45         if ($pj->{irc_announce_parts} && defined $store{"playernick_byid_$id"} && $store{"playerip_byid_$id"} ne 'bot') {
46                 out irc => 0, "PRIVMSG $config{irc_channel} :\00304- part\017: " . $store{"playernick_byid_$id"} . "\017" . 
47                         ($pj->{irc_show_playerip} ? " (\00304" . $store{"playerip_byid_$id"} . "\017)" : '') .
48                         ($pj->{irc_show_mapname} ? " playing on \00304$store{map}\017" : '') .
49                         ($pj->{irc_show_amount_of_players} ? " players: \00304" . (get_player_count()-1) . "\017/$store{slots_max}" : '');
50         }
51         my $slot = $store{"playerslot_byid_$id"};
52         $store{"playernickraw_byid_$id"} = undef;
53         $store{"playernick_byid_$id"} = undef;
54         $store{"playerip_byid_$id"} = undef;
55         $store{"playerslot_byid_$id"} = undef;
56         $store{"playerid_byslot_$slot"} = undef;
57         return 0;
58 } ],