Raised This Month: $32 Target: $400
 8% 

Very Basic Player Tracker (Updated 7/15/10)


Post New Thread Reply   
 
Thread Tools Display Modes
Author
msleeper
Veteran Member
Join Date: May 2008
Location: Atlanta, Jawjuh
Plugin ID:
1197
Plugin Version:
1.5
Plugin Category:
Statistical
Plugin Game:
Any
Plugin Dependencies:
    Servers with this Plugin:
    2 
    Plugin Description:
    Tracks basic player information to a MySQL database.
    Old 10-01-2009 , 19:01   Very Basic Player Tracker (Updated 7/15/10)
    Reply With Quote #1

    Very Basic Player Tracker

    This plugin is a simple player tracker that logs player information into a MySQL database. It uses the "default" database from your databases.cfg file for storage. It logs the player name, SteamID, player's IP address, server game type (using GetGameFolderName()) and server IP address, and the GeoIP country code for the player's location. It logs this information X seconds after being connected, which is controlled with a cvar. This is useful if you only want to keep track of players who are connected for a minimum amount of time, the default is 90 seconds. If a duplicate player is found, it updates their information

    I am not providing any web interface at this time, though I may in the future. This is really just a base for anyone who may want to develop it further, or use it for a more specific purpose. For those of you in need of a web interface, I highly recommend using the Sourcemod Webadmin which has built in support for this plugin!

    Feel free to use this code for any other plugins, however please give credit back to me.

    Installation
    Installation is incredibly easy, install the plugin in your /addons/sourcemod/plugins/ directory and refresh your plugin list, or change map.

    Configuration
    A config file will automatically be generated in /cfg/sourcemod/ when the plugin is first ran.

    sm_tracker_addtime - Add/update players in the database after this many seconds
    sm_tracker_geoiptype - Add player's GeoIP country to the database. 0 = Disabled, 1 = 2 letter Country Code, 2 = 3 letter Country Code, 3 = full Country Name.

    Use this SQL to create your table.

    PHP Code:
    CREATE TABLE `player_tracker` (
      `
    idint(11NOT NULL auto_increment,
      `
    steamidvarchar(255NOT NULL,
      `
    playernamevarchar(255NOT NULL,
      `
    playeripvarchar(255NOT NULL,
      `
    servertypevarchar(255NOT NULL,
      `
    serveripvarchar(255NOT NULL,
      `
    serverportvarchar(255NOT NULL,
      `
    geoipcountryvarchar(255NOT NULL,
      `
    statusvarchar(255NOT NULL,
      
    PRIMARY KEY  (`id`),
      
    UNIQUE KEY `steamid` (`steamid`),
      
    KEY `playername` (`playername`),
      
    KEY `playerip` (`playerip`),
      
    KEY `servertype` (`servertype`),
      
    KEY `serverip` (`serverip`),
      
    KEY `status` (`status`)
    ); 
    Attached Files
    File Type: sp Get Plugin or Get Source (tracker.sp - 3611 views - 6.4 KB)
    __________________

    Last edited by msleeper; 07-15-2010 at 16:56. Reason: Updated to 1.5
    msleeper is offline
    rotab
    Junior Member
    Join Date: Dec 2005
    Location: Sweden
    Old 10-03-2009 , 11:15   Re: Basic Player Tracker
    Reply With Quote #2

    Exactly what i was looking for. Thanks.
    rotab is offline
    msleeper
    Veteran Member
    Join Date: May 2008
    Location: Atlanta, Jawjuh
    Old 10-04-2009 , 00:24   Re: Basic Player Tracker
    Reply With Quote #3

    That's why I posted it, I'm sure people out there would like to track player visits. Glad I could help.
    __________________
    msleeper is offline
    Rescue9
    Junior Member
    Join Date: Apr 2009
    Old 10-17-2009 , 00:03   Re: Basic Player Tracker
    Reply With Quote #4

    I've been rewriting a bit of this. It is broken, but a work in progress.

    The changed code is as such (from line 86 of above tracker.sp):
    Code:
        new String:SteamID[32];
        GetClientAuthString(client, SteamID, sizeof(SteamID));
    
        new String:PlayerName[32];
        GetClientName(client, PlayerName, sizeof(PlayerName));
        
        new String:PlayerIP[32];
        GetClientIP(client, PlayerIP, sizeof(PlayerIP));
    
        new String:GameType[32];
        GetGameFolderName(GameType, sizeof(GameType));
    
        new String:ServerIP[32];
        cvar_ServerIP = FindConVar("ip");
        GetConVarString(cvar_ServerIP, ServerIP, sizeof(ServerIP));
    
        new String:query[512];
        Format(query, sizeof(query), "INSERT INTO player_tracker (steamid, playername, playerip, servertype, serverip, status) VALUES ('%s', '%s', '%s', '%s', '%s', 'new') ON DUPLICATE KEY UPDATE playerip='%s', status='seen', playername=IF( playername like '%%s%', playername, CONCAT_WS(', ', playername, '%s'));", SteamID, PlayerName, PlayerIP, GameType, ServerIP, PlayerIP, PlayerName, PlayerName);
        SendQuery(query);
    }
    This basically updates playername with PlayerName only if PlayerName isn't already in playername. My problem is this section:
    Code:
    playername like '%%s%',
    Basically, mysql needs the two % to match the name. So, when it hits the sql server, if the players name were Bob, I'd need it to say:
    Code:
    playername like '%Bob%',
    Any suggestions.
    Rescue9 is offline
    Rescue9
    Junior Member
    Join Date: Apr 2009
    Old 10-17-2009 , 09:45   Re: Basic Player Tracker
    Reply With Quote #5

    Think it might be better to use REGEXP statement instead of LIKE for the sql. THis way I can get away from having multiple % characters inside the code. I'll post findings later when I can test this out.

    BTW... thanks for the nice plugin msleeper!
    Rescue9 is offline
    Rescue9
    Junior Member
    Join Date: Apr 2009
    Old 10-19-2009 , 22:01   Re: Basic Player Tracker
    Reply With Quote #6

    After dealing with this issue for days now, I've determined that REGEXP doesn't play well with unicode characters. Because of this the IF statement keeps writing the same name to playername, even though it's already listed, if it has unicode characters in it.

    So... as it stands now, I've changed the code a bit more like the original code. It will only log the last playername the SteamID was seen under, but I'm working on using separate tables to take care of the Name issue. Just have to decide how I'm going to design the other tables, and what other information I'm going to put in there as well. Probably going to implement a Last Seen date at least, but who knows.

    Also, if you'll notice above, I changed the SteamID string a bit. I'm not sure why, but on my server it was only inserting every 3rd or 4th person that joined into the DB. Since changing it to GetClientAuthString I'm now catching everyone. Don't know if this was a bug, or just something unnoticed previously.

    Here is the new code that is actually working if plugged into the tracker.sp. Not much change from the original, but I thought it needed to be documented. Again... much thanks goes to msleeper. His plugin jumpstarted my thought process.

    Code:
        new String:SteamID[32];
        GetClientAuthString(client, SteamID, sizeof(SteamID));
    
        new String:PlayerName[32];
        GetClientName(client, PlayerName, sizeof(PlayerName));
        
        new String:PlayerIP[32];
        GetClientIP(client, PlayerIP, sizeof(PlayerIP));
    
        new String:GameType[32];
        GetGameFolderName(GameType, sizeof(GameType));
    
        new String:ServerIP[32];
        cvar_ServerIP = FindConVar("ip");
        GetConVarString(cvar_ServerIP, ServerIP, sizeof(ServerIP));
    
        new String:query[512];
        Format(query, sizeof(query), "INSERT INTO player_tracker (steamid, playername, playerip, servertype, serverip, status) VALUES ('%s', '%s', '%s', '%s', '%s', 'new') ON DUPLICATE KEY UPDATE playerip='%s', status='seen', playername='%s';", SteamID, PlayerName, PlayerIP, GameType, ServerIP, PlayerIP, PlayerName);
        SendQuery(query);
    }
    Rescue9 is offline
    msleeper
    Veteran Member
    Join Date: May 2008
    Location: Atlanta, Jawjuh
    Old 10-20-2009 , 06:28   Re: Basic Player Tracker
    Reply With Quote #7

    Quote:
    Originally Posted by Rescue9 View Post
    Also, if you'll notice above, I changed the SteamID string a bit. I'm not sure why, but on my server it was only inserting every 3rd or 4th person that joined into the DB. Since changing it to GetClientAuthString I'm now catching everyone. Don't know if this was a bug, or just something unnoticed previously.
    I will go ahead and update my plugin with this change. I'll admit that using the method I did was a little lazy and possibly sloppy.

    As for the rest of your edits, they look good. I wish that SM/Source Pawn was quite a bit more SQL friendly, but I guess it wasn't really designed with being a database interface in mind.
    __________________
    msleeper is offline
    Rescue9
    Junior Member
    Join Date: Apr 2009
    Old 10-22-2009 , 22:39   Re: Basic Player Tracker
    Reply With Quote #8

    Hmmmm.... just found another bug. Because Pawn uses single quotes but not double quotes for variables, player names with apostrophes in them are getting borked. I'm working on a few additional values right now and will eventually get to dealing with apostrophized player names. However, if you have the time, can you take a look at this as well please.
    Rescue9 is offline
    msleeper
    Veteran Member
    Join Date: May 2008
    Location: Atlanta, Jawjuh
    Old 10-23-2009 , 19:27   Re: Basic Player Tracker
    Reply With Quote #9

    I personally don't track player name, but I have ran into this bug before. I fixed this in L4D stats by simply stripping out quote marks. Here is the code you would need to use, feel free to add this to yours:

    Code:
        new String:Name[MAX_LINE_WIDTH];
        GetClientName(client, Name, sizeof(Name));
        ReplaceString(Name, sizeof(Name), "\\", "");
        ReplaceString(Name, sizeof(Name), "\"", "");
        ReplaceString(Name, sizeof(Name), "'", "");
        ReplaceString(Name, sizeof(Name), ";", "");
        ReplaceString(Name, sizeof(Name), "´", "");
        ReplaceString(Name, sizeof(Name), "`", "");
    You also might want to strip out the PHP open and close tags if you are using some sort of script to look at the player list.
    __________________

    Last edited by msleeper; 10-23-2009 at 19:31.
    msleeper is offline
    Rescue9
    Junior Member
    Join Date: Apr 2009
    Old 11-13-2009 , 11:41   Re: Basic Player Tracker
    Reply With Quote #10

    Nice. Thanks for the fix. As it stands now, i've made the changes to the plugin, but have given up development for a while.

    Our clan is not using a dedicated server, and after a week's worth of testing, I figured out that the writing of information to an external database source was creating a great deal of lag for the players. Every time someone would join, there would be about a 1-2 second period of lag spikes. This was simply unacceptable for gameplay.

    As it stands now, I'm working on getting a dedicated host with mysql on the same box. it's just a matter of time.


    Thanks again for the great work msleeper!
    Rescue9 is offline
    Reply



    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off

    Forum Jump


    All times are GMT -4. The time now is 21:00.


    Powered by vBulletin®
    Copyright ©2000 - 2024, vBulletin Solutions, Inc.
    Theme made by Freecode