]> git.xonotic.org Git - xonotic/xonotic.git/blob - server/rcon2irc/votestop.pl
Merge branch 'master' into divVerent/crypto2
[xonotic/xonotic.git] / server / rcon2irc / votestop.pl
1 # Xonotic rcon2irc plugin by Merlijn Hofstra licensed under GPL - votestop.pl
2 # Place this file inside the same directory as rcon2irc.pl and add the full filename to the plugins.
3
4 # This plugin will stop an ongoing vote when the person who called it leaves. Edit the options below
5 # to disallow votes after certain events.
6
7 { my %vs = (
8         mapstart => 90, # can't call mapchange votes for this amount of seconds after mapstart
9         connected => 120, # can't call votes when you just joined the server
10         minplayers => 2, # minimal amount of players for this script to work.
11 );
12
13 $store{plugin_votestop} = \%vs; }
14
15 # add a dependency on joinsparts.pl
16 if (defined %config && $config{plugins} !~ m/joinsparts.pl /gi) {
17         die "votestop.pl depends on joinsparts.pl but it appears to not be loaded.";
18 }
19
20 sub out($$@);
21
22 sub time_to_seconds {
23         my @ar = split /:/, $_[0];
24         return ($ar[0] * 60 * 60) + ($ar[1] * 60) + $ar[2];
25 }
26
27 [ dp => q{:vote:vcall:(\d+):(.*)} => sub {
28         my ($id, $command) = @_;
29         $command = color_dp2irc $command;
30         my $vs = $store{plugin_votestop};
31         
32         # use joinsparts for player check
33         return 0 unless ($id && get_player_count() >= $vs->{minplayers});
34         
35         my $slot = $store{"playerslot_byid_$id"};
36         if ($vs->{mapstart} && (time() - $store{map_starttime}) < $vs->{mapstart}) {
37                 if ($command =~ m/(endmatch|restart|gotomap|chmap)/gi) {
38                         $vs->{vstopignore} = 1;
39                         out dp => 0, "sv_cmd vote stop";
40                         out irc => 0, "PRIVMSG $config{irc_channel} :* vote \00304$command\017 by " . $store{"playernick_byid_$id"} .
41                                 "\017 was rejected because the map hasn't been played long enough";
42                                 
43                         out dp => 0, "tell #$slot your vote was rejected because this map only just started.";
44                         
45                         return -1;
46                 }
47         }
48         
49         my $time = time_to_seconds $store{"playerslot_$slot"}->{'time'};
50         $time ||= 0;
51         if ($vs->{connected} && $time < $vs->{connected}) {
52                 $vs->{vstopignore} = 1;
53                 out dp => 0, "sv_cmd vote stop";
54                 out irc => 0, "PRIVMSG $config{irc_channel} :* vote \00304$command\017 by " . $store{"playernick_byid_$id"} .
55                         "\017 was rejected because he isn't connected long enough";
56                         
57                 out dp => 0, "tell #$slot your vote was rejected because you just joined the server.";
58                         
59                 return -1;
60         }
61         
62         $vs->{currentvote} = $id;
63         return 0;
64 } ],
65
66 [ dp => q{:vote:v(yes|no|timeout|stop):.*} => sub {
67         my ($cmd) = @_;
68         $store{plugin_votestop}->{currentvote} = undef;
69         my $vs = $store{plugin_votestop};
70         
71         if ($cmd eq 'stop' && $vs->{vstopignore}) {
72                 $vs->{vstopignore} = undef;
73                 return -1;
74         }
75         
76         return 0;
77 } ],
78
79 [ dp => q{:part:(\d+)} => sub {
80         my ($id) = @_;
81         my $vs = $store{plugin_votestop};
82         
83         if (defined $store{plugin_votestop}->{currentvote} && $id == $store{plugin_votestop}->{currentvote}) {
84                 $vs->{vstopignore} = 1;
85                 out dp => 0, "sv_cmd vote stop";
86                 out irc => 0, "PRIVMSG $config{irc_channel} :* vote \00304$command\017 by " . $store{"playernick_byid_$id"} .
87                         "\017 was stopped because he left the server";
88         }
89         
90         return 0;
91 } ],
92
93 [ dp => q{:gamestart:(.*):[0-9.]*} => sub {
94         my $vs = $store{plugin_votestop};
95         
96         if (defined $store{plugin_votestop}->{currentvote}) {
97                 out dp => 0, "sv_cmd vote stop";
98                 $store{plugin_votestop}->{currentvote} = undef;
99                 $vs->{vstopignore} = undef;
100         }
101         
102         return 0;
103 } ],