HLStatsX:CE and GeoIP Setup for CS:GO

With the CounterStrike:Global Offensive server now up and running, I wanted to see some statistics around the activity on the server.    This is a post about the HLStatsX:CE plugin and the updates made to the Perl script to allow Geographical IP mapping to work properly.

Background

HLStatsX:CE is the program that is often used on other community servers.  If you have connected to a server running the plugin, you undoubtedly have seen the chat log scrolling statistics.   If you haven’t, then go get CS:GO and join counterstrike.destephen.com. 😉

This program communicates with the server via a remote console (rcon) and does not require any additional plug-in features to run.  My HLStatsX:CE server is running on a separate server than my CS:GO server.  This decision was intended to minimize updates to the counterstrike server itself as HLStatsX:CE requires a typical Ubuntu LAMP configuration to run.

The Geographical IP Mapping

The Geo IP mapping is nice to allow the HLStatsX:CE server to associate the country and location of a player based on its connected IP address.  The data is also able to be used to place  Pins for active players on Google Maps within a webpage.

The problem that most folks end up having is the database does not get entered into mySQL properly.  The HLStatsX:CE download does contain scripts, but they are outdated at the time of this writing.  Most folks resort to downloading a copy of the GeoLite Database and move it to the appropriate location with the Perl directories.

Fixing the Script

The script “geoip.py” included in the installation has been modified to update download locations and process the file more efficiently.  Below is the module that was updated. This module can replace the original.

def fetch_geodata():
   """
   Obtains the geoLiteCity raw data, resulting in geoLiteCity_Location.csv and geoLiteCity_Blocks.csv
   """
   # database is updated on 1st every month, so download the file from the 1st of current month
   # if file ever changes in the future, update line below accordingly
   FILE = "GeoLite2-City-CSV.zip"
   # cleanup any possible existing downloads
   system("rm *.csv > /dev/null")
   system("rm *.zip > /dev/null")
   if not os.path.exists(FILE):
      system("wget http://geolite.maxmind.com/download/geoip/database/" + str(FILE))
   system("unzip -j -o " + str(FILE))
   system("mv GeoLite2-City-Blocks.csv geoLiteCity_Blocks.csv")
   system("mv GeoLite2-City-Locations.csv geoLiteCity_Location.csv.temp")
   system("iconv -f ISO-8859-1 -t UTF-8 geoLiteCity_Location.csv.temp > geoLiteCity_Location.csv")

   return

I also had to correct some syntax for the mySQL insert – there needed to be a space after the “-p”.

def dump_sql(fname):
   """
   Dump the new sql data into our database
   """
   system("mysql -u %s -p %s -h %s %s < %s"%(DBUSER,DBPASS,DBHOST,DBNAME,fname))

Final Thoughts

I personally do not have a heavy coding background and imagine the script could be re-written to be more efficient.   For the frequency that the script would run, it should not be a concern.  Once I ran the updated Perl script, the database was populated with the appropriate information and the users were able to be tracked.

If you are following this to correct an issue with your HLStatsX:CE system, don’t forget to change the pointer from a local file to your mySQL database.  In addition, this Perl script will need to have your systems mySQL account details and database added.

For your viewing pleasure, the HLStatsX:CE server has been published to http://counterstrike.destephen.com.

Disclaimer: Please keep in mind that the user profile images pulled from Steam and server chat interactions on this site are beyond my control.  These sections are sub menus from the main page.

Leave a Reply

Your email address will not be published. Required fields are marked *