1 # Xonotic rcon2irc plugin by Merlijn Hofstra licensed under GPL - ping-pl.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.
5 # This script monitors players ping and packet loss, people with really large values here are
6 # lagging a lot, and this lag appears to other players as well as seeing the lagging player move
7 # with lots of stutter. Bare in mind that even those of us on very good connections may lose a
8 # packet or have a high ping every once in the while.
9 # PLEASE CHOOSE SANE VALUES HERE !!!
14 warn_player => 1, # send a tell command to the player to notify of bad connection (0 or 1)
15 warn_irc => 1, # send a warning to irc to notify that a player has a bad connection (0 or 1)
16 warnings => 3, # how many times must ping/pl exceed the limit before a warning
17 kick => 0, # how many times must ping/pl exceed the limit before a kick (0 to disable)
18 timeframe => 20, # minutes until a count is forgotten
19 warnmsg => 'You are having connection problems, causing you to lag - please fix them',
20 kickmsg => 'You are getting kicked for having connection problems.'
23 $store{plugin_ping-pl} = \%pp; }
27 # Check users ping and packet loss
28 [ dp => q{\^\d(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(-?\d+)\s+\#(\d+)\s+\^\d(.*)} => sub {
29 my ($ip, $pl, $ping, $time, $frags, $no, $name) = ($1, $2, $3, $4, $5, $6, $7);
30 my $id = $store{"playerid_byslot_$no"};
31 return 0 unless ( defined $id );
32 return 0 if ($frags == -666 || $ip eq 'bot');
33 my $pp = $store{plugin_ping-pl};
35 #does the player violate one of our limits?
37 if ($ping >= $pp->{max_ping} || $pl >= $pp->{max_pl}) {
39 push @{ $pp->{"violation_$id"} }, time();
43 #maybe we need to clear the oldest violation
44 shift @{ $pp->{"violation_$id"} } if (defined ${ $pp->{"violation_$id"} }[0] && (${ $pp->{"violation_$id"} }[0] + (60 * $pp->{timeframe})) <= time());
46 #do we have to kick the user?
47 if ((scalar @{ $pp->{"violation_$id"} }) >= $pp->{kick} && $pp->{kick} > 0) {
48 if ($pp->{warn_player}) {
49 out dp => 0, "tell #$no " . $pp->{kickmsg};
51 if ($pp->{warn_irc}) {
52 out irc => 0, "PRIVMSG $config{irc_channel} :\00304* kicking\017 " . $store{"playernick_byid_$id"} . "\017 for having a bad connection" .
53 " (current ping/pl: \00304$ping/$pl\017)";
55 out dp => 0, "kick # $no bad connection";
56 $pp->{"violation_$id"} = undef;
60 #do we have to warn the user?
61 if ($warn && (scalar @{ $pp->{"violation_$id"} }) && ((scalar @{ $pp->{"violation_$id"} }) % $pp->{warnings}) == 0) {
62 if ($pp->{warn_player}) {
63 out dp => 0, "tell #$no " . $pp->{warnmsg};
65 if ($pp->{warn_irc}) {
66 out irc => 0, "PRIVMSG $config{irc_channel} :\00308* warning\017 " . $store{"playernick_byid_$id"} . "\017 has a bad connection" .
67 " (current ping/pl: \00304$ping/$pl\017)";
73 # For now will just empty our data at the end of a match
74 [ dp => q{^:end} => sub {
75 my $pp = $store{plugin_ping-pl};
76 foreach ( keys %{ $pp } ) {
77 $pp->{$_} = undef if ($_ =~ m/^violation/);