Community Forums Today's Posts     Member List     Archive    
Page 11 of 13 FirstFirst ... 910111213 LastLast
Results 151 to 165 of 194
  1. #151
    Join Date
    Jul 2006
    Posts
    1,573
    Code:
    if($serverversion[0] != 2 || $serverversion[2] < 21) {
    That's the line which checks the version. Normally nothing unnormal...

    Goto line 75 and put on every newline a "#" so the compiler doesn't read the line until line 85. So it will looke like this:
    Code:
    # checking the servers version info
    #print "Checking server compatibility -> ";
    #my @serverversion = $tcpquery->get_serverversion();
    #if($serverversion[0] != 2 || $serverversion[2] < 21) {
    #  print "[!!]\n";
    #  print "$current_time - You are running an outdated version of the TeamSpeak 2 server #($serverversion[0].$serverversion[1].$serverversion[2].$serverversion[3]).\n";
    #  sleep 3;
    #  exit;
    #} else {
    #  print "[OK]\n";
    #}
    After that, save and try to restart the deamon.

  2. #152
    Join Date
    Jan 2007
    Location
    Zoetermeer, Zuid-Holland, The Netherlands
    Posts
    13
    After some more editing, it finally works, thanks For people with the same prob:

    Code:
    #!/usr/bin/perl -w
    
    # ts2afd.pl - TeamSpeak 2 Anti-Flood Daemon
    # This script reads a TeamSpeak 2 servers logfile and detects flooding attempts
    # Written 2006 by Sven Paulsen
    
    use strict;
    use TeamSpeak2::TCPquery;
    use TeamSpeak2::Log;
    
    # ============================================================================================
    # ======================================= CONFIGURATION ======================================
    # ============================================================================================
    
    # ****** SERVER ADDRESS AND TCP QUERY PORT ******
    # This is the hostname or IP address and  TCP port of the TeamSpeak 2 server.
    # If you are unsure of what to put here, leave the default values.
    my $server_address = "localhost";
    my $server_tcpport = "51234";
    
    # ****** SUPERADMIN USERNAME & PASSWORD ******
    # This is the username and password you use to access your TeamSpeak 2 server.
    # This must be an existing superadmn account.
    my $ssa_username = "SUPERADMIN";
    my $ssa_password = "IWOULDNTPOSTTHATHERE";
    
    # ****** FULL PATH TO SERVER LOGFILE ******
    # On a few systems it may be necessary to input the full path to your servers logfile
    # for the TeamSpeak 2 Anti-Flood Daemon to function normally. 
    # Example Unix:
    #   my $server_logfile = "/home/ts2/teamspeak2/server.log";
    # Example Windows:
    #   my $server_logfile = "C:/Program Files/TeamSpeak2/server.log";
    my $server_logfile = "C:/Program Files/Teamspeak2_RC2_SERVER/server.log";
    
    # ****** SERVER SPAM LIMITS ******
    # These values define the max amount of new connections from an IP address in a limited 
    # number of seconds. 
    # Do NOT set one of these values to 0!
    # Example:
    #   my $spam_connections = 1;
    #   my $spam_seconds = 10;
    #   In this case an IP address will be able to connect 3 times in 10 seconds.
    my $spam_connections = 1;
    my $spam_seconds = 10;
    
    # ****** ENABLE/DISABLE UNIX DAEMON ******
    # This option allows you to start the script as a background process on Unix based systems.
    # Do not enable this feature on Windows servers.
    my $script_daemonize = 0;
    
    # ============================================================================================
    # ============================ DO NOT CHANGE ANYTHING BELOW ==================================
    # ============================================================================================
    
    use POSIX qw(strftime);
    my $current_time = strftime "%H:%M:%S", localtime;
    
    print "TeamSpeak 2 Anti-Flood Daemon [Version 0.5 NOT VERSION CHECKING!]\n";
    print "Copyright (c) 2006 by Sven 'ScP' Paulsen\n";
    print "\n";
    
    # connect to the TeamSpeak 2 server
    print "Connecting to server $server_address -> ";
    my $tcpquery = TeamSpeak2::TCPquery->new($server_address, $server_tcpport);
    if(!$tcpquery) {
      print "[!!]\n";
      print "$current_time - The server is not responding. Maybe the server is offline or TeamSpeak 2 is not running on it.\n";
      sleep 3;
      exit;
    } else {
      print "[OK]\n";
    }
    
    # checking the servers version info
    #print "Checking server compatibility -> ";
    #my @serverversion = $tcpquery->get_serverversion();
    #if($serverversion[0] != 2 || $serverversion[2] < 21) {
    #  print "[!!]\n";
    #  print "$current_time - You are running an outdated version of the TeamSpeak 2 server #($serverversion[0].$serverversion[1].$serverversion[2].$serverversion[3]).\n";
    #  sleep 3;
    #  exit;
    #} else {
    #  print "[OK]\n";
    #}
    
    # authenticating with a valid superadmin accout
    print "Authenticating as $ssa_username -> ";
    if(!$tcpquery->login_superadmin($ssa_username, $ssa_password)) {
      print "[!!]\n";
      print "$current_time - You have entered an invalid username and/or password.\n";
      sleep 3;
      exit;
    } else {
      print "[OK]\n";
    }
    
    # get serverlist from database
    print "Getting serverlist from database -> ";
    my $current_servers;
    my @dbserverlist = $tcpquery->get_dbserverlist();
    if(!$dbserverlist[0]) {
      print "[!!]\n";
      print "$current_time - The server created some invalid output.\n";
      sleep 3;
      exit;
    } else {
      $current_servers = @dbserverlist;
      print "[OK]\n";
    }
    
    # open the servers logfile
    print "Accessing the servers logfile -> ";
    my $log = TeamSpeak2::Log->new($server_logfile);
    if(!$log) {
      print "[!!]\n";
      print "$current_time - The servers logfile could not be opened.\n";
      sleep 3;
      exit;
    } else {
      print "[OK]\n";
    }
    
    # create/open a logfile for the script
    print "Accessing the scripts logfile -> ";
    if(!open(LOG, ">>ts2afd.log")) {
      print "[!!]\n";
      print "$current_time - The scripts logfile could not be created/opened.\n";
      sleep 3;
      exit;
    } else {
      autoflush LOG;
      print "[OK]\n";
    }
    
    # write init entries to log file
    $current_time = strftime "%m/%d/%y %H:%M:%S", localtime;
    print LOG "---------------------------------------------------------------\n";
    print LOG "------------ log started at $current_time -------------\n";
    print LOG "---------------------------------------------------------------\n";
    print LOG "$current_time\tTeamSpeak 2 Anti-Flood Daemon started\n";
    print LOG "$current_time\tConnected to server $server_address on TCP port $server_tcpport\n";
    print LOG "$current_time\tAuthenticated as $ssa_username\n";
    print LOG "$current_time\tFound $current_servers virtual servers in the database\n";
    print LOG "$current_time\tInitialization sequence completed\n";
    
    # jump to the end of the servers logfile
    $log->goto_eof();
    
    # deamonize the current process
    print "\n";
    $script_daemonize = 1 if(defined($ARGV[0]) && $ARGV[0] =~ /^daemon\s*$/);
    deamonize() if($script_daemonize);
    
    print @_;
    
    # create new vars, arrays and hashes to store various info
    my @servers;
    my %connections;
    
    eval {
    
      # enter main loop
      while(1) {
        $current_time = strftime "%m/%d/%y %H:%M:%S", localtime;
    
        # get new lines from logfile
        my @lines = $log->analyze();
      
        # Search for new connections
        foreach my $line (@lines) {
        
          # check if current line is a new connection
          if($line->[2] =~ /^AccessLog\s*$/ && $line->[4] =~ /^client\sconnected\s\[IP:\s(\d+\.\d+\.\d+\.\d+),\sNick:\s.+,\sVersion:\s\d+\.\d+\.\d+\.\d+\]\s*$/) {
            my $server_id = $line->[3];
            my $client_ip = $1;
    
            # perform anti-flood actions
            if(!exists($connections{"$server_id-$client_ip"})) {
              $connections{"$server_id-$client_ip"} = [time(), 1];
            } else {
              my $remaining_connections = $spam_connections-@{$connections{"$server_id-$client_ip"}}[1];
              @{$connections{"$server_id-$client_ip"}}[1]++ if(time()-@{$connections{"$server_id-$client_ip"}}[0] <= $spam_seconds);
              if(!$remaining_connections) {
            
                # find server UDP port in serverlist
                foreach my $server (@dbserverlist) {
                  if($server_id == $server->[0]) {
                    if($tcpquery->select_server($server->[1])) {
                  
                      # ban IP address
                      $tcpquery->add_ban($client_ip, 5);
                    
                      # search connected serveradmins
                      my @playerlist = $tcpquery->get_playerlist();
                      if($playerlist[0] != 0) {
                        foreach my $player (@playerlist) {
                          my $player_is_serveradmin = substr(unpack('B*', pack('C', $player->[11])), -1);
                        
                          # send a notice to all serveradmins
                          if($player_is_serveradmin) {
                            $tcpquery->send_playermsg($player->[0], "IP \"$client_ip\" got banned from the server by \"TeamSpeak 2 Anti-Flood Daemon\"");
                          }
                        }
                      }
                    
                      # write a new entry to the scripts logfile
                      print LOG "$current_time\tIP \"$client_ip\" got banned from the server \[ID: $server->[0], Port: $server->[1], Name: $server->[2]\]\n";
                    }
                    last;
                  }
                }                  
              }
            }    
          }
        
          # check if current line is a virtual servers start
          elsif($line->[2] =~ /^server\s*$/ && $line->[4] =~ /^Started\sVirtualServer\sid:\d+\swith port:(\d+)\s*$/) {
        
            # get a new serverlist from database
            @dbserverlist = $tcpquery->get_dbserverlist();
            $current_servers = @dbserverlist;
    		
            # write a new entry to the scripts logfile
            print LOG "$current_time\tVirtual server on port $1 has been started\n";
            print LOG "$current_time\tFound $current_servers virtual servers in the database\n";
          }
        
          # check if current line is a virtual servers stop
          elsif($line->[2] =~ /^server\s*$/ && $line->[4] =~ /^Stopped\sVirtualServer\sid:\d+\swith port:(\d+)\s*$/) {
    		
    		# get a new serverlist from database
            @dbserverlist = $tcpquery->get_dbserverlist();
            $current_servers = @dbserverlist;
    		
            # write a new entry to the scripts logfile
            print LOG "$current_time\tVirtual server on port $1 has been stopped\n";
            print LOG "$current_time\tFound $current_servers virtual servers in the database\n";
          }
        
          # check if current line is a server shutdown
          elsif($line->[2] =~ /^server\s*$/ && $line->[4] =~ /^Server\sshutdown\sinitialized\s*$/) {
    		
            # write a new entry to the scripts logfile
            print LOG "$current_time\tServer shutdown initialized\n";
          
            # disconnect from the TeamSpeak 2 server
            $tcpquery->execute("quit");
          
            # write shutdown entries to log file
            print LOG "$current_time\tTeamSpeak 2 Anti-Flood Daemon stopped\n";
            print LOG "---------------------------------------------------------------\n";
            print LOG "------------- log ended at $current_time --------------\n";
            print LOG "---------------------------------------------------------------\n";
          
            exit(0);
          }
        
          # wait for 0.01 seconds
          select(undef, undef, undef, 0.01);
        }
    
        # remove outdated entries from connections hash
        foreach(keys(%connections)) {
          delete $connections{$_} if(time()-@{$connections{$_}}[0] > $spam_seconds);
        }
      
        # wait for 0.1 seconds
        select(undef, undef, undef, 0.1);  
      }
    
    };
    
    # catch and log critical errors
    if($@) {
      print LOG "$current_time\t".$@."\n";
    }
    
    sub deamonize {
      exit(0) if(fork());
      print "TeamSpeak 2 Anti-Flood Daemon started with PID $$\n";
      open(STDIN, "</dev/null") || return 0;
      open(STDOUT, ">/dev/null") || return 0;
      open(STDERR, ">&STDOUT") || return 0;
      open(PID, ">ts2afd.pid") || return 0;
      print PID $$;
      close PID;
      chdir("/");
      umask(0);
      return $$;
    }
    
    exit(0);
    Last edited by PGOn03L; 31-08-2007 at 08:35.

  3. #153
    Join Date
    Jun 2007
    Location
    Tampa, FL
    Posts
    3

    Oh noes

    I get all the way through the startup until the server log. Here is the problem below :/.

    Accessing the servers logfile -> [!!]
    4:44:15 - The servers logfile could not be opened.

    Also I have this romanian called Violet_Blood and he spams my server using one connection and uses a dynamic IP (it doesn't change as much as you think). So I really hope this can ban him if he uses one connection please respond ASAP as this guy is about to spam attack again :/.

  4. #154
    Join Date
    Jul 2006
    Posts
    1,573
    You sure that the path to the logfile is correct? And see that the server isn't started as root and the deamon as normal user. because the deamon could then not acess the server.log

  5. #155
    Join Date
    Jun 2007
    Location
    Tampa, FL
    Posts
    3
    I have tried sudo :/. Also I think its the permissions what should I set it too (command only please).

    EDIT: FIXED WOOT

  6. #156
    Join Date
    Jul 2006
    Posts
    1,573
    Quote Originally Posted by helfrichmike View Post
    I have tried sudo :/. Also I think its the permissions what should I set it too (command only please).

    EDIT: FIXED WOOT
    Could you please tell us how you solved the problem?

  7. #157
    Join Date
    Jun 2007
    Location
    Tampa, FL
    Posts
    3
    This is how I fixed it.

    The example shows you having to do the /home/ and all that but instead since its executing all of the ts stuff in that folder I just did this for the directory ./server.log. The problem is you should do ./server.log by default. I recommend that be added in later versions . I am at school so I had to do this off memory :P.

  8. #158
    Join Date
    Sep 2007
    Location
    USA
    Posts
    1
    Question about error I'm getting with the script. If this has already been covered, my apologies. I've downloaded and installed the latest version of ActivePerl for Windows (5.8, build 822), and have configured the anti-flood script per the info in the file. When I run it, I get this error:

    Can't locate TeamSpeak2/TCPquery.pm in @INC <@INC contains: C:/Perl64/site/lib c:/Perl64/lib .> at c:\program files (x86)\Teamspeak2_RC2_Server\AntiFloodScript\ts2afd .pl line 8.
    BEGIN failed--compilation aborted at c:\program files (x86)\Teamspeak2_RC2_Server\AntiFloodScript\ts2afd .pl line8.


    Line 8 in the file is "use TeamSpeak2::TCPquery;", which I've not changed as it wasn't listed to do so. Any ideas?

    I'm running WinXP x64 and the Perl version is the build for x64 systems, as additional info.

  9. #159
    Join Date
    Nov 2007
    Location
    GA
    Posts
    22
    It keeps saying the server could not be found.

    Here is a copy of mine.

    Code:
    # ============================================================================================
    # ======================================= CONFIGURATION ======================================
    # ============================================================================================
    
    # ****** SERVER ADDRESS AND TCP QUERY PORT ******
    # This is the hostname or IP address and  TCP port of the TeamSpeak 2 server.
    # If you are unsure of what to put here, leave the default values.
    my $server_address = "bftclan.servegame.com";
    my $server_tcpport = "51234";
    
    # ****** SUPERADMIN USERNAME & PASSWORD ******
    # This is the username and password you use to access your TeamSpeak 2 server.
    # This must be an existing superadmn account.
    my $ssa_username = "****";
    my $ssa_password = "*";
    
    # ****** FULL PATH TO SERVER LOGFILE ******
    # On a few systems it may be necessary to input the full path to your servers logfile
    # for the TeamSpeak 2 Anti-Flood Daemon to function normally. 
    # Example Unix:
    #   my $server_logfile = "/home/ts2/teamspeak2/server.log";
    # Example Windows:
    #   my $server_logfile = "C:/Program Files/TeamSpeak2/server.log";
    my $server_logfile = "C:/Program Files/Teamspeak2_RC2/server.log";
    
    # ****** SERVER SPAM LIMITS ******
    # These values define the max amount of new connections from an IP address in a limited 
    # number of seconds. 
    # Do NOT set one of these values to 0!
    # Example:
    #   my $spam_connections = 3;
    #   my $spam_seconds = 10;
    #   In this case an IP address will be able to connect 3 times in 10 seconds.
    my $spam_connections = 3;
    my $spam_seconds = 30;
    
    # ****** ENABLE/DISABLE UNIX DAEMON ******
    # This option allows you to start the script as a background process on Unix based systems.
    # Do not enable this feature on Windows servers.
    my $script_daemonize = 0;

  10. #160
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,296
    Try to set the $server_address variable to localhost.

  11. #161
    Join Date
    Nov 2007
    Location
    GA
    Posts
    22
    Thanks!

    But now its giving me logfile could not be opened.

    (Ill go back through this thread and try to find a solution if it was posted, still need help though because I can't find it)

    Quote Originally Posted by helfrichmike View Post
    This is how I fixed it.

    The example shows you having to do the /home/ and all that but instead since its executing all of the ts stuff in that folder I just did this for the directory ./server.log. The problem is you should do ./server.log by default. I recommend that be added in later versions . I am at school so I had to do this off memory :P.
    That didn't work.
    Last edited by BFT_Mists; 28-11-2007 at 11:35.

  12. #162
    Join Date
    Dec 2007
    Location
    UK
    Posts
    1

    Question How to: Multiple Modded TS Servers

    Hello,

    I am having an issue which I can't answer.

    I want to be able to host many teamspeak servers to people and if they ask for the mod they can have it.

    How would I go around doing this?

    E.G

    1. Person 1 - Normal TS server.
    2. Clan 1 - Modded TS Server
    3. Clan 2 - Modded TS Server
    4. Clan 3 - Modded TS Server
    5. Person 2 - Normal TS server.

    Thanks!

    MSN Address : racknetz(@)Hotmail.com

  13. #163
    Join Date
    Dec 2007
    Location
    NY
    Posts
    1
    Mine says it cannot connect for some reason.
    My server address is "74.86.83.202:8767"

    I tried both localhost and just "74.86.83.202"
    Is it asking for the IP to the web control panel?
    Also, we have a password on our TS also. Could this be the reason?

    Code:
    #!/usr/bin/perl -w
    
    # ts2afd.pl - TeamSpeak 2 Anti-Flood Daemon
    # This script reads a TeamSpeak 2 servers logfile and detects flooding attempts
    # Written 2006 by Sven Paulsen
    
    use strict;
    use TeamSpeak2::TCPquery;
    use TeamSpeak2::Log;
    
    # ============================================================================================
    # ======================================= CONFIGURATION ======================================
    # ============================================================================================
    
    # ****** SERVER ADDRESS AND TCP QUERY PORT ******
    # This is the hostname or IP address and  TCP port of the TeamSpeak 2 server.
    # If you are unsure of what to put here, leave the default values.
    my $server_address ="localhost";
    my $server_tcpport = "8767";
    
    # ****** SUPERADMIN USERNAME & PASSWORD ******
    # This is the username and password you use to access your TeamSpeak 2 server.
    # This must be an existing superadmn account.
    my $ssa_username = "***";
    my $ssa_password = "***";
    
    # ****** FULL PATH TO SERVER LOGFILE ******
    # On a few systems it may be necessary to input the full path to your servers logfile
    # for the TeamSpeak 2 Anti-Flood Daemon to function normally. 
    # Example Unix:
    #   my $server_logfile = "/home/ts2/teamspeak2/server.log";
    # Example Windows:
    #   my $server_logfile = "C:/Program Files/TeamSpeak2/server.log";
    my $server_logfile = "C:/Program Files/TeamSpeak2/server.log";
    
    # ****** SERVER SPAM LIMITS ******
    # These values define the max amount of new connections from an IP address in a limited 
    # number of seconds. 
    # Do NOT set one of these values to 0!
    # Example:
    #   my $spam_connections = 3;
    #   my $spam_seconds = 10;
    #   In this case an IP address will be able to connect 3 times in 10 seconds.
    my $spam_connections = 3;
    my $spam_seconds = 10;
    
    # ****** ENABLE/DISABLE UNIX DAEMON ******
    # This option allows you to start the script as a background process on Unix based systems.
    # Do not enable this feature on Windows servers.
    my $script_daemonize = 0;
    
    # ============================================================================================
    # ============================ DO NOT CHANGE ANYTHING BELOW ==================================
    # ============================================================================================
    
    use POSIX qw(strftime);
    my $current_time = strftime "%H:%M:%S", localtime;
    
    print "TeamSpeak 2 Anti-Flood Daemon [Version 0.5]\n";
    print "Copyright (c) 2006 by Sven 'ScP' Paulsen\n";
    print "\n";
    
    # connect to the TeamSpeak 2 server
    print "Connecting to server $server_address -> ";
    my $tcpquery = TeamSpeak2::TCPquery->new($server_address, $server_tcpport);
    if(!$tcpquery) {
      print "[!!]\n";
      print "$current_time - The server is not responding. Maybe the server is offline or TeamSpeak 2 is not running on it.\n";
      sleep 3;
      exit;
    } else {
      print "[OK]\n";
    }
    
    # checking the servers version info
    print "Checking server compatibility -> ";
    my @serverversion = $tcpquery->get_serverversion();
    if($serverversion[0] != 2 || $serverversion[2] < 21) {
      print "[!!]\n";
      print "$current_time - You are running an outdated version of the TeamSpeak 2 server ($serverversion[0].$serverversion[1].$serverversion[2].$serverversion[3]).\n";
      sleep 3;
      exit;
    } else {
      print "[OK]\n";
    }
    
    # authenticating with a valid superadmin accout
    print "Authenticating as $ssa_username -> ";
    if(!$tcpquery->login_superadmin($ssa_username, $ssa_password)) {
      print "[!!]\n";
      print "$current_time - You have entered an invalid username and/or password.\n";
      sleep 3;
      exit;
    } else {
      print "[OK]\n";
    }
    
    # get serverlist from database
    print "Getting serverlist from database -> ";
    my $current_servers;
    my @dbserverlist = $tcpquery->get_dbserverlist();
    if(!$dbserverlist[0]) {
      print "[!!]\n";
      print "$current_time - The server created some invalid output.\n";
      sleep 3;
      exit;
    } else {
      $current_servers = @dbserverlist;
      print "[OK]\n";
    }
    
    # open the servers logfile
    print "Accessing the servers logfile -> ";
    my $log = TeamSpeak2::Log->new($server_logfile);
    if(!$log) {
      print "[!!]\n";
      print "$current_time - The servers logfile could not be opened.\n";
      sleep 3;
      exit;
    } else {
      print "[OK]\n";
    }
    
    # create/open a logfile for the script
    print "Accessing the scripts logfile -> ";
    if(!open(LOG, ">>ts2afd.log")) {
      print "[!!]\n";
      print "$current_time - The scripts logfile could not be created/opened.\n";
      sleep 3;
      exit;
    } else {
      autoflush LOG;
      print "[OK]\n";
    }
    
    # write init entries to log file
    $current_time = strftime "%m/%d/%y %H:%M:%S", localtime;
    print LOG "---------------------------------------------------------------\n";
    print LOG "------------ log started at $current_time -------------\n";
    print LOG "---------------------------------------------------------------\n";
    print LOG "$current_time\tTeamSpeak 2 Anti-Flood Daemon started\n";
    print LOG "$current_time\tConnected to server $server_address on TCP port $server_tcpport\n";
    print LOG "$current_time\tAuthenticated as $ssa_username\n";
    print LOG "$current_time\tFound $current_servers virtual servers in the database\n";
    print LOG "$current_time\tInitialization sequence completed\n";
    
    # jump to the end of the servers logfile
    $log->goto_eof();
    
    # deamonize the current process
    print "\n";
    $script_daemonize = 1 if(defined($ARGV[0]) && $ARGV[0] =~ /^daemon\s*$/);
    deamonize() if($script_daemonize);
    
    print @_;
    
    # create new vars, arrays and hashes to store various info
    my @servers;
    my %connections;
    
    eval {
    
      # enter main loop
      while(1) {
        $current_time = strftime "%m/%d/%y %H:%M:%S", localtime;
    
        # get new lines from logfile
        my @lines = $log->analyze();
      
        # Search for new connections
        foreach my $line (@lines) {
        
          # check if current line is a new connection
          if($line->[2] =~ /^AccessLog\s*$/ && $line->[4] =~ /^client\sconnected\s\[IP:\s(\d+\.\d+\.\d+\.\d+),\sNick:\s.+,\sVersion:\s\d+\.\d+\.\d+\.\d+\]\s*$/) {
            my $server_id = $line->[3];
            my $client_ip = $1;
    
            # perform anti-flood actions
            if(!exists($connections{"$server_id-$client_ip"})) {
              $connections{"$server_id-$client_ip"} = [time(), 1];
            } else {
              my $remaining_connections = $spam_connections-@{$connections{"$server_id-$client_ip"}}[1];
              @{$connections{"$server_id-$client_ip"}}[1]++ if(time()-@{$connections{"$server_id-$client_ip"}}[0] <= $spam_seconds);
              if(!$remaining_connections) {
            
                # find server UDP port in serverlist
                foreach my $server (@dbserverlist) {
                  if($server_id == $server->[0]) {
                    if($tcpquery->select_server($server->[1])) {
                  
                      # ban IP address
                      $tcpquery->add_ban($client_ip, 5);
                    
                      # search connected serveradmins
                      my @playerlist = $tcpquery->get_playerlist();
                      if($playerlist[0] != 0) {
                        foreach my $player (@playerlist) {
                          my $player_is_serveradmin = substr(unpack('B*', pack('C', $player->[11])), -1);
                        
                          # send a notice to all serveradmins
                          if($player_is_serveradmin) {
                            $tcpquery->send_playermsg($player->[0], "IP \"$client_ip\" got banned from the server by \"TeamSpeak 2 Anti-Flood Daemon\"");
                          }
                        }
                      }
                    
                      # write a new entry to the scripts logfile
                      print LOG "$current_time\tIP \"$client_ip\" got banned from the server \[ID: $server->[0], Port: $server->[1], Name: $server->[2]\]\n";
                    }
                    last;
                  }
                }                  
              }
            }    
          }
        
          # check if current line is a virtual servers start
          elsif($line->[2] =~ /^server\s*$/ && $line->[4] =~ /^Started\sVirtualServer\sid:\d+\swith port:(\d+)\s*$/) {
        
            # get a new serverlist from database
            @dbserverlist = $tcpquery->get_dbserverlist();
            $current_servers = @dbserverlist;
    		
            # write a new entry to the scripts logfile
            print LOG "$current_time\tVirtual server on port $1 has been started\n";
            print LOG "$current_time\tFound $current_servers virtual servers in the database\n";
          }
        
          # check if current line is a virtual servers stop
          elsif($line->[2] =~ /^server\s*$/ && $line->[4] =~ /^Stopped\sVirtualServer\sid:\d+\swith port:(\d+)\s*$/) {
    		
    		# get a new serverlist from database
            @dbserverlist = $tcpquery->get_dbserverlist();
            $current_servers = @dbserverlist;
    		
            # write a new entry to the scripts logfile
            print LOG "$current_time\tVirtual server on port $1 has been stopped\n";
            print LOG "$current_time\tFound $current_servers virtual servers in the database\n";
          }
        
          # check if current line is a server shutdown
          elsif($line->[2] =~ /^server\s*$/ && $line->[4] =~ /^Server\sshutdown\sinitialized\s*$/) {
    		
            # write a new entry to the scripts logfile
            print LOG "$current_time\tServer shutdown initialized\n";
          
            # disconnect from the TeamSpeak 2 server
            $tcpquery->execute("quit");
          
            # write shutdown entries to log file
            print LOG "$current_time\tTeamSpeak 2 Anti-Flood Daemon stopped\n";
            print LOG "---------------------------------------------------------------\n";
            print LOG "------------- log ended at $current_time --------------\n";
            print LOG "---------------------------------------------------------------\n";
          
            exit(0);
          }
        
          # wait for 0.01 seconds
          select(undef, undef, undef, 0.01);
        }
    
        # remove outdated entries from connections hash
        foreach(keys(%connections)) {
          delete $connections{$_} if(time()-@{$connections{$_}}[0] > $spam_seconds);
        }
      
        # wait for 0.1 seconds
        select(undef, undef, undef, 0.1);  
      }
    
    };
    
    # catch and log critical errors
    if($@) {
      print LOG "$current_time\t".$@."\n";
    }
    
    sub deamonize {
      exit(0) if(fork());
      print "TeamSpeak 2 Anti-Flood Daemon started with PID $$\n";
      open(STDIN, "</dev/null") || return 0;
      open(STDOUT, ">/dev/null") || return 0;
      open(STDERR, ">&STDOUT") || return 0;
      open(PID, ">ts2afd.pid") || return 0;
      print PID $$;
      close PID;
      chdir("/");
      umask(0);
      return $$;
    }
    
    exit(0);

  14. #164
    Join Date
    Jan 2008
    Location
    detroit michigan
    Posts
    7

    TeamSpeak 2 Anti-Flood Daemon 0.5 trouble

    Hi i installed everything where it go's but when i go to start it up i get a message connecting to server then it says the server is not responding
    any idea what i did wrong also i noticed you suppied a folder called teamspeak 2 in it is a log.file and a file called tcpquery.pm where do i install this file?

  15. #165
    Join Date
    May 2008
    Location
    Hungary
    Posts
    8

    Strange problem

    Hi all, I recently changed my server's os from ws2003 to debian, and i am having some problems using the ts2afd. The problem is that it starts up perfectly, and it is running (checked with ps), but it does not do it's job, it doesn't do anything.

    Here is the prompt of the startup:
    Code:
    TeamSpeak 2 Anti-Flood Daemon [Version 0.5]
    Copyright (c) 2006 by Sven 'ScP' Paulsen
    
    Connecting to server localhost -> [OK]
    Checking server compatibility -> [OK]
    Authenticating as Anti-Flood -> [OK]
    Getting serverlist from database -> [OK]
    Accessing the servers logfile -> [OK]
    Accessing the scripts logfile -> [OK]
    
    TeamSpeak 2 Anti-Flood Daemon started with PID 31158
    And here is the ts2afd.pl (I downloaded it today).
    Code:
    #!/usr/bin/perl -w
    
    # ts2afd.pl - TeamSpeak 2 Anti-Flood Daemon
    # This script reads a TeamSpeak 2 servers logfile and detects flooding attempts
    # Written 2006 by Sven Paulsen
    
    use strict;
    use TeamSpeak2::TCPquery;
    use TeamSpeak2::Log;
    
    # ============================================================================================
    # ======================================= CONFIGURATION ======================================
    # ============================================================================================
    
    # ****** SERVER ADDRESS AND TCP QUERY PORT ******
    # This is the hostname or IP address and  TCP port of the TeamSpeak 2 server.
    # If you are unsure of what to put here, leave the default values.
    my $server_address = "localhost";
    my $server_tcpport = "51234";
    
    # ****** SUPERADMIN USERNAME & PASSWORD ******
    # This is the username and password you use to access your TeamSpeak 2 server.
    # This must be an existing superadmn account.
    my $ssa_username = "";
    my $ssa_password = "";
    
    # ****** FULL PATH TO SERVER LOGFILE ******
    # On a few systems it may be necessary to input the full path to your servers logfile
    # for the TeamSpeak 2 Anti-Flood Daemon to function normally. 
    # Example Unix:
    #   my $server_logfile = "/home/med/tss2_rc2/server.log";
    # Example Windows:
    #   my $server_logfile = "C:/Program Files/TeamSpeak2/server.log";
    my $server_logfile = "/home/med/tss2_rc2/server.log";
    
    # ****** SERVER SPAM LIMITS ******
    # These values define the max amount of new connections from an IP address in a limited 
    # number of seconds. 
    # Do NOT set one of these values to 0!
    # Example:
    #   my $spam_connections = 3;
    #   my $spam_seconds = 10;
    #   In this case an IP address will be able to connect 3 times in 10 seconds.
    my $spam_connections = 3;
    my $spam_seconds = 8;
    
    # ****** ENABLE/DISABLE UNIX DAEMON ******
    # This option allows you to start the script as a background process on Unix based systems.
    # Do not enable this feature on Windows servers.
    my $script_daemonize = 0;
    
    # ============================================================================================
    # ============================ DO NOT CHANGE ANYTHING BELOW ==================================
    # ============================================================================================
    
    use POSIX qw(strftime);
    my $current_time = strftime "%H:%M:%S", localtime;
    
    print "TeamSpeak 2 Anti-Flood Daemon [Version 0.5]\n";
    print "Copyright (c) 2006 by Sven 'ScP' Paulsen\n";
    print "\n";
    
    # connect to the TeamSpeak 2 server
    print "Connecting to server $server_address -> ";
    my $tcpquery = TeamSpeak2::TCPquery->new($server_address, $server_tcpport);
    if(!$tcpquery) {
      print "[!!]\n";
      print "$current_time - The server is not responding. Maybe the server is offline or TeamSpeak 2 is not running on it.\n";
      sleep 3;
      exit;
    } else {
      print "[OK]\n";
    }
    
    # checking the servers version info
    print "Checking server compatibility -> ";
    my @serverversion = $tcpquery->get_serverversion();
    if($serverversion[0] != 2 || $serverversion[2] < 21) {
      print "[!!]\n";
      print "$current_time - You are running an outdated version of the TeamSpeak 2 server ($serverversion[0].$serverversion[1].$serverversion[2].$serverversion[3]).\n";
      sleep 3;
      exit;
    } else {
      print "[OK]\n";
    }
    
    # authenticating with a valid superadmin accout
    print "Authenticating as $ssa_username -> ";
    if(!$tcpquery->login_superadmin($ssa_username, $ssa_password)) {
      print "[!!]\n";
      print "$current_time - You have entered an invalid username and/or password.\n";
      sleep 3;
      exit;
    } else {
      print "[OK]\n";
    }
    
    # get serverlist from database
    print "Getting serverlist from database -> ";
    my $current_servers;
    my @dbserverlist = $tcpquery->get_dbserverlist();
    if(!$dbserverlist[0]) {
      print "[!!]\n";
      print "$current_time - The server created some invalid output.\n";
      sleep 3;
      exit;
    } else {
      $current_servers = @dbserverlist;
      print "[OK]\n";
    }
    
    # open the servers logfile
    print "Accessing the servers logfile -> ";
    my $log = TeamSpeak2::Log->new($server_logfile);
    if(!$log) {
      print "[!!]\n";
      print "$current_time - The servers logfile could not be opened.\n";
      sleep 3;
      exit;
    } else {
      print "[OK]\n";
    }
    
    # create/open a logfile for the script
    print "Accessing the scripts logfile -> ";
    if(!open(LOG, ">>ts2afd.log")) {
      print "[!!]\n";
      print "$current_time - The scripts logfile could not be created/opened.\n";
      sleep 3;
      exit;
    } else {
      autoflush LOG;
      print "[OK]\n";
    }
    
    # write init entries to log file
    $current_time = strftime "%m/%d/%y %H:%M:%S", localtime;
    print LOG "---------------------------------------------------------------\n";
    print LOG "------------ log started at $current_time -------------\n";
    print LOG "---------------------------------------------------------------\n";
    print LOG "$current_time\tTeamSpeak 2 Anti-Flood Daemon started\n";
    print LOG "$current_time\tConnected to server $server_address on TCP port $server_tcpport\n";
    print LOG "$current_time\tAuthenticated as $ssa_username\n";
    print LOG "$current_time\tFound $current_servers virtual servers in the database\n";
    print LOG "$current_time\tInitialization sequence completed\n";
    
    # jump to the end of the servers logfile
    $log->goto_eof();
    
    # deamonize the current process
    print "\n";
    $script_daemonize = 1 if(defined($ARGV[0]) && $ARGV[0] =~ /^daemon\s*$/);
    deamonize() if($script_daemonize);
    
    print @_;
    
    # create new vars, arrays and hashes to store various info
    my @servers;
    my %connections;
    
    eval {
    
      # enter main loop
      while(1) {
        $current_time = strftime "%m/%d/%y %H:%M:%S", localtime;
    
        # get new lines from logfile
        my @lines = $log->analyze();
      
        # Search for new connections
        foreach my $line (@lines) {
        
          # check if current line is a new connection
          if($line->[2] =~ /^AccessLog\s*$/ && $line->[4] =~ /^client\sconnected\s\[IP:\s(\d+\.\d+\.\d+\.\d+),\sNick:\s.+,\sVersion:\s\d+\.\d+\.\d+\.\d+\]\s*$/) {
            my $server_id = $line->[3];
            my $client_ip = $1;
    
            # perform anti-flood actions
            if(!exists($connections{"$server_id-$client_ip"})) {
              $connections{"$server_id-$client_ip"} = [time(), 1];
            } else {
              my $remaining_connections = $spam_connections-@{$connections{"$server_id-$client_ip"}}[1];
              @{$connections{"$server_id-$client_ip"}}[1]++ if(time()-@{$connections{"$server_id-$client_ip"}}[0] <= $spam_seconds);
              if(!$remaining_connections) {
            
                # find server UDP port in serverlist
                foreach my $server (@dbserverlist) {
                  if($server_id == $server->[0]) {
                    if($tcpquery->select_server($server->[1])) {
                  
                      # ban IP address
                      $tcpquery->add_ban($client_ip, 5);
                    
                      # search connected serveradmins
                      my @playerlist = $tcpquery->get_playerlist();
                      if($playerlist[0] != 0) {
                        foreach my $player (@playerlist) {
                          my $player_is_serveradmin = substr(unpack('B*', pack('C', $player->[11])), -1);
                        
                          # send a notice to all serveradmins
                          if($player_is_serveradmin) {
                            $tcpquery->send_playermsg($player->[0], "IP \"$client_ip\" got banned from the server by \"TeamSpeak 2 Anti-Flood Daemon\"");
                          }
                        }
                      }
                    
                      # write a new entry to the scripts logfile
                      print LOG "$current_time\tIP \"$client_ip\" got banned from the server \[ID: $server->[0], Port: $server->[1], Name: $server->[2]\]\n";
                    }
                    last;
                  }
                }                  
              }
            }    
          }
        
          # check if current line is a virtual servers start
          elsif($line->[2] =~ /^server\s*$/ && $line->[4] =~ /^Started\sVirtualServer\sid:\d+\swith port:(\d+)\s*$/) {
        
            # get a new serverlist from database
            @dbserverlist = $tcpquery->get_dbserverlist();
            $current_servers = @dbserverlist;
    		
            # write a new entry to the scripts logfile
            print LOG "$current_time\tVirtual server on port $1 has been started\n";
            print LOG "$current_time\tFound $current_servers virtual servers in the database\n";
          }
        
          # check if current line is a virtual servers stop
          elsif($line->[2] =~ /^server\s*$/ && $line->[4] =~ /^Stopped\sVirtualServer\sid:\d+\swith port:(\d+)\s*$/) {
    		
    		# get a new serverlist from database
            @dbserverlist = $tcpquery->get_dbserverlist();
            $current_servers = @dbserverlist;
    		
            # write a new entry to the scripts logfile
            print LOG "$current_time\tVirtual server on port $1 has been stopped\n";
            print LOG "$current_time\tFound $current_servers virtual servers in the database\n";
          }
        
          # check if current line is a server shutdown
          elsif($line->[2] =~ /^server\s*$/ && $line->[4] =~ /^Server\sshutdown\sinitialized\s*$/) {
    		
            # write a new entry to the scripts logfile
            print LOG "$current_time\tServer shutdown initialized\n";
          
            # disconnect from the TeamSpeak 2 server
            $tcpquery->execute("quit");
          
            # write shutdown entries to log file
            print LOG "$current_time\tTeamSpeak 2 Anti-Flood Daemon stopped\n";
            print LOG "---------------------------------------------------------------\n";
            print LOG "------------- log ended at $current_time --------------\n";
            print LOG "---------------------------------------------------------------\n";
          
            exit(0);
          }
        
          # wait for 0.01 seconds
          select(undef, undef, undef, 0.01);
        }
    
        # remove outdated entries from connections hash
        foreach(keys(%connections)) {
          delete $connections{$_} if(time()-@{$connections{$_}}[0] > $spam_seconds);
        }
      
        # wait for 0.1 seconds
        select(undef, undef, undef, 0.1);  
      }
    
    };
    
    # catch and log critical errors
    if($@) {
      print LOG "$current_time\t".$@."\n";
    }
    
    sub deamonize {
      exit(0) if(fork());
      print "TeamSpeak 2 Anti-Flood Daemon started with PID $$\n";
      open(STDIN, "</dev/null") || return 0;
      open(STDOUT, ">/dev/null") || return 0;
      open(STDERR, ">&STDOUT") || return 0;
      open(PID, ">ts2afd.pid") || return 0;
      print PID $$;
      close PID;
      chdir("/");
      umask(0);
      return $$;
    }
    
    exit(0);
    If someone has met this problem before, or knows what am i doing wrong please help.
    Thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Start stop script for TeamSpeak daemon (init)
    By Cybernaut in forum [TeamSpeak 2] Server Support
    Replies: 2
    Last Post: 11-11-2004, 17:07
  2. TeamSpeak daemon dies unexpectedly
    By lbaker in forum [TeamSpeak 2] Server Support
    Replies: 5
    Last Post: 04-09-2003, 20:01

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •