]> git.xonotic.org Git - xonotic/xonotic.git/blob - server/rcon2irc/votestop.pl
Merge remote branch 'refs/remotes/origin/merlijn/rcon2irc-fix'
[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         $vs->{command} = $command;
64         return 0;
65 } ],
66
67 [ dp => q{:vote:v(yes|no|timeout|stop):.*} => sub {
68         my ($cmd) = @_;
69         my $vs = $store{plugin_votestop};
70         $vs->{currentvote} = undef;
71         $vs->{command} = undef;
72         
73         if ($cmd eq 'stop' && $vs->{vstopignore}) {
74                 $vs->{vstopignore} = undef;
75                 return -1;
76         }
77         
78         return 0;
79 } ],
80
81 [ dp => q{:part:(\d+)} => sub {
82         my ($id) = @_;
83         my $vs = $store{plugin_votestop};
84         
85         if (defined $vs->{currentvote} && $id == $vs->{currentvote}) {
86                 $vs->{vstopignore} = 1;
87                 out dp => 0, "sv_cmd vote stop";
88                 out dp => 0, "say Vote was stopped as player left the server";
89                 out irc => 0, "PRIVMSG $config{irc_channel} :* vote \00304" . $vs->{command} . "\017 by " . $store{"playernick_byid_$id"} .
90                         "\017 was stopped because he left the server";
91         }
92         
93         return 0;
94 } ],
95
96 [ dp => q{:gamestart:(.*):[0-9.]*} => sub {
97         my $vs = $store{plugin_votestop};
98         
99         if (defined $vs->{currentvote}) {
100                 out dp => 0, "sv_cmd vote stop";
101                 $vs->{currentvote} = undef;
102                 $vs->{command} = undef;
103                 $vs->{vstopignore} = undef;
104         }
105         
106         return 0;
107 } ],