TeamSpeak flood protection
Entry Filed under: Coding
April 4th, 2008
Since I am having a hard time controlling flood attacks on my TeamSpeak server, I decided that it would be a good idea to automate the protection of the server's integrity by upgrading an already great app - TS2PerlMod. If you don't have TS2PerlMod already installed, grab a free copy of ActivePerl and install it on your Windows machine (for *nix systems, I'm assuming perl is already present), then configure all the needed settings as you would usually do (see the ReadMe).
Now, here's the perl code snippet that I coded today (I am not very familiar with perl, but the C like syntax made it easy to write), it will enable you to ban every bot that tries to flood your server:
ts2perlmod.pl
# update TeamSpeak2::TCPquery::Server object
$server->getServerinfo();
Add this below the above code:
# bureX-ANTISPAM-MOD: making life a bit more easier on TeamSpeak...
my @cplayerlist;
my @iplayerlist;
my $i;
my $j;
my $kicked;
foreach my $player (@playerlist)
{
if ($player->{loginname} eq "")
{
$i=0;
for ($j=0;$j{"ip"})
{
$cplayerlist[$j] = $cplayerlist[$j]+1;
$i++;
}
}
if ($i==0)
{
push(@cplayerlist, 1);
push(@iplayerlist, $player->{"ip"});
}
$i=0;
}
}
$kicked = 0;
for ($i=0;$i 3) #number of allowed players to connect from the same IP address
{
$server->sendMessage("Spam Attack detected from ".$iplayerlist[$i]);
$server->sendMessage("Initiating retaliation sequence for ".$cplayerlist[$i]." bots...");
foreach my $player (@playerlist)
{
if ($player->{ip} eq $iplayerlist[$i])
{
$player->banIp(240); #ban spammers for 240 minutes
$player->kick("Spam protection");
$kicked = 1;
}
}
$server->sendMessage("Retaliation sequence executed.");
$server->sendMessage("Done... Have a nice day!");
$server->sendMessage("TS defence system - crafted by bureX");
}
}
if ($kicked == 1) {sleep(10);} #Let the TS Server rest for 10 seconds before updating the new list
delete @cplayerlist[0..scalar(@cplayerlist)];
delete @iplayerlist[0..scalar(@iplayerlist)];
1 Comment Add your own
1. Scor9ioN | July 18th, 2008 at 10:10 pm
Great job Burex! Works like a charm
Sure beats manually removing one at a time (or running TS Admin Client to mass-kick - which still requires ones attention)
TS2: dzone.webhop.net
[DZone] Canada
Say something!
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed