πŸ“œ ⬆️ ⬇️

Setting up a Source Source Server for Linux, Part 4


Statistics Server HLstatsX


It would be unfair not to catch a glimpse of the HLstatsX Community Edition (HLstatsX: CE) statistics server. The project is currently developing not very actively, the last stable version is 1.6.19 from 2014. You can install it, or you can install the current version, at the time of writing, which is not fundamentally edited. You still have to finish.


We still need a sql server (mysql / mariadb), a web server (nginx), perl and php with some modules. Also on our game servers MetaMod and SourceMod should already be installed.


Installation


The current repository is https://bitbucket.org/Maverick_of_UC/hlstatsx-community-edition/


Download the current version:


$ wget https://bitbucket.org/Maverick_of_UC/hlstatsx-community-edition/get/master.tar.bz2 $ mkdir ~/stat $ tar -jxvf master.tar.bz2 -C ~/stat --strip 1 

HLstatsX consists of three logical parts - a SourceMod plugin that broadcasts game events, receives a daemon, and displays a web part.


Statistics will be collected as follows:



Go to the ~ / stat directory. There we see subdirectories


amxmodx - plug-ins for AMX Mod X
heatmaps - scripts for building heat maps
scripts - demon scripts
sourcemod - sourcemod plugins
sql - script to create sql database
web - web interface.


The amxmodx and sourcemod subdirectories contain plug-ins for AMX Mod X and SourceMod, respectively. Since we do not use AMX Mod X, the contents of amxmodx are not relevant to us, unlike sourcemod, which contains statistics plugins in source codes (sourcemod / scripting) and in compiled form (sourcemod / plugins). Theoretically, there may be problems when the version of SourceMod installed here is very different from the one under which the plugin is compiled, so we will copy the source code for the plug-ins hlstatsx.sp and superlogs-tf2.sp to the scripting directory of the first server and recompile them:


  $ cp ~/stat/sourcemod/scripting/{hlstatsx.sp,superlogs-tf2.sp} ~/tf2/tf/addons/sourcemod1/scripting $ cp ~/stat/sourcemod/scripting/include/* ~/tf2/tf/addons/sourcemod1/scripting/include $ cd ~/tf2/tf/addons/sourcemod1/scripting 

To avoid compilation errors, correct the file:


  $ sed -i -es/char/char1/g ~/tf2/tf/addons/sourcemod1/scripting/hlstatsx.sp 

Compile and decompose directories:


  $ ./compile.sh hlstatsx.sp superlogs-tf2.sp $ cp compiled/hlstatsx.smx compiled/superlogs-tf2.smx ~/tf2/tf/addons/sourcemod1/plugins $ mv compiled/hlstatsx.smx compiled/superlogs-tf2.smx ~/tf2/tf/addons/sourcemod2/plugins 

If the game servers are already running, then enter their consoles (commands are indicated by angle brackets):


  >>> sm plugins refresh [SM] The plugin list has been refreshed and reloaded. >>> sm plugins list [SM] Listing 19 plugins: [...] 18 "SuperLogs: TF2" (2.0.32) by Thomas "CmptrWz" Berezansky & psychonic 19 "HLstatsX CE Ingame Plugin" (1.6.19) by psychonic 

Good. In principle, players can already call the HLstatsX plugin by typing "hlx_menu" in the chat window. True so far without much effect. Settings for these plug-ins (and not only these) are made through their console variables - ConVars, usually by writing in the server configuration files, or a specific card. Their list is usually in the documentation, but if you want you can see for yourself:


  $ grep CreateConVar ~/tf2/tf/addons/sourcemod1/scripting/hlstatsx.sp $ grep CreateConVar ~/tf2/tf/addons/sourcemod1/scripting/superlogs-tf2.sp 

We find out that superlogs_headshots is off by default. If you need to register headshots, then add "superlogs_headshots 1" to any configuration file, and for an already running server, execute the same command in the console.


Mysql setup


The mysql server (mariadb) is already installed, configured and running, so we immediately proceed to create a database for the statistics server. Go to ~ / stat / sql (where install.sql should be), remember the administrator password for mysql, start the client:


  $ cd ~/stat/sql $ mysql --user=root mysql --password 

Create a database and a user with a password:


  Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 1513 Server version: 5.5.47-MariaDB-log MariaDB Server Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [mysql]> CREATE DATABASE hlx_db; Query OK, 1 row affected (0.02 sec) MariaDB [mysql]> GRANT ALL PRIVILEGES ON hlx_db.* TO hlx_user@localhost IDENTIFIED BY 'hlx_password' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec) MariaDB [mysql]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) MariaDB [mysql]> QUIT; Bye 

The database has been created, now we delete ~ / .mysql_history, with an immodestly fixed password from hlx_user, run the script that creates the necessary tables. When prompted, enter the password from our database - 'hlx_password'.


  $ rm -f ~/.mysql_history $ mysql --user=hlx_user hlx_db --password < ~/stat/sql/install.sql 

  Enter password: Table Op Msg_type Msg_text hlx_db.hlstats_Ranks optimize status OK 

Everything, the database is created


In the process of setting up, Adminer , a compact but powerful web-based control panel consisting of just one php script, can be useful for surfing through sql tables, analyzing problems and deleting unsuccessful experiments. If you do not have phpMyAdmin installed or something else, then this Adminer is a great option.

Configuring the HLstatsX daemon


The ~ / stat / scripts directory contains the main scripts of the statistics server daemon. Edit the settings file ~ / stat / scripts / hlstats.conf, set the parameters for connecting to the sql server:


  DBHost "localhost" DBUsername "hlx_user" DBPassword "hlx_password" DBName "hlx_db" 

In the UDP Socket Settings section, we don’t touch anything. If we had one game server, then there they would register the address and port specified in logaddress_add in server.cfg. But since we are setting up two servers, we leave the BindIP parameter empty, and the port numbers will be specified on the command line when the daemon is started.


In the file ~ / stat / scripts / run_hlstats we fix the directory for the logs:


  LOGDIR=/home/game/log/hlstats 

Install the GeoIP database. It is useful both for displaying messages like "A player such and such from a country such and such" during a game, and for displaying statistics on a site. Run the cal program, check what the first day of the week is. The locale is en_US everywhere, so cal shows Sunday. Go to the ~ / stat / scripts / GeoLiteCity directory and edit the GeoLite_Import.sh file:


  # Set this value to 1 if you are running Gentoo linux, or any other linux distro # where the "cal" command outputs not Sunday as the first day in every row! LINUX_OTHER="0" # Login information for your MySQL server DBHOST="localhost" DBNAME="hlx_db" DBUSER="hlx_user" DBPASS="hlx_password" 

Make the GeoLite_Import.sh script executable and run it. GeoIP database is downloaded and imported into the sql database. With a successful import, something of the form is issued:


  [...] hlx_db.geoLiteCity_Blocks: Records: 2359593 Deleted: 0 Skipped: 0 Warnings: 0 hlx_db.geoLiteCity_Location: Records: 793056 Deleted: 0 Skipped: 0 Warnings: 793056 

Alternatively, you can store the GeoIP data in a separate file (this is done using the install_binary.sh script - but then you need to install (if not) perl module Geo :: IP :: PurePerl - perl -MCPAN -e 'install Geo::IP::PurePerl . But we will store GeoIP data inside our sql database. Not so much of a load on it is expected.


Web server setup


We will have a statistics server at http://stat.example.org/ . As in the case of setting Fast Download, create a separate directory /var/www/stat.example.org. The access_log and error.log logs will also be rendered into separate files and allow the game user to read them.


Statistics Server will serve both of our game servers. From root, we create directories, transfer the ~ / stat / web directory, set the owner and permissions. Create logs. You can also make symbolic links for convenience.


  # mkdir -p /var/www/stat.example.org/{htdocs,log} # mv /home/game/stat/web/* /var/www/stat.example.org/htdocs # chown -R game. /var/www/stat.example.org/htdocs # touch /var/www/stat.example.org/log/{access,error}.log # chmod 644 /var/www/stat.example.org/log/*.log # ln -s /var/www/stat.example.org/log /home/game/log/www-stat 

Currently, HLstatsX is developing to put it mildly, not so actively, so frequent updates are not predicted, and there is not much point in giving the nginx user full access to his files for the built-in auto-update function.


In order to reduce the load, the statistics server creates a small cache in the hlstatsimg / progress folder - it stores game server download schedules and Player Trend schedules (visible on the players' pages), so the web server should be allowed to write to this directory:


  # chown nginx. /var/www/stat.example.org/htdocs/hlstatsimg/progress 

Go to /var/www/stat.example.org/htdocs, edit the config.php, after making dos2unix config.php :


  define("DB_ADDR", "localhost"); define("DB_USER", "hlx_user"); define("DB_PASS", "hlx_password"); define("DB_NAME", "hlx_db"); 

Other options do not touch yet.


While we are still root, we are creating the configuration file /etc/nginx/conf.d/stat.example.org.conf our web server for this subdomain.


stat.example.org.conf
 server { server_name stat.example.org; listen 80; root /var/www/stat.example.org/htdocs; #  rewrite   ,   rewrite sig-(.*)-(.*).png$ /sig.php?player_id=$1&background=$2 break; location / { try_files $uri $uri/ /index.php$request_uri; } #  .htaccess ,     pages, pages/admintasks, pages/ingame location ~ /\.ht { deny all; } #      php location ~ ^.+\.php(?:/.*)?$ { include /etc/nginx/php.conf; fastcgi_pass unix:/var/run/php5-fpm.sock; } access_log /var/www/stat.example.org/log/access.log main; error_log /var/www/stat.example.org/log/error.log warn; } 

Above, we gave the game user access to read the logs of the web server, but only until their first rotation. We fix this too. Based on /etc/logrotate.d/nginx we create the srcds-nginx file, set the path to the logs and fix the access rights mask from 640 to 644 in the create 640 nginx adm :


srcds-nginx
 #/etc/logrotate.d/srcds-nginx /var/www/stat.example.org/log/*.log /var/www/fastdl.example.org/log/*.log /var/www/replay.example.org/log/*.log { daily missingok rotate 52 compress delaycompress notifempty create 644 nginx adm sharedscripts postrotate if [ -f /var/run/nginx.pid ]; then kill -USR1 `cat /var/run/nginx.pid` fi endscript } 

Here we are in the paths for rotation at the same time indicated directories with logs from servers with records and Fast Download.


We check the correctness of the configuration and restart the web server.


  # nginx -t # systemctl reload nginx 

Further we continue as the user of game.


Broadcast logs


We had to enable logging as early as the configuration stage, in the configuration files of our servers. Just in case, we check for the presence of the "log on" and "logaddress_add <...>" parameters in them.


Patch


Before running the scripts we will have to fix them a bit. The fact is that since 2014, a new version of the Steam ID record has been used. The previous, second, was of the form STEAM_0: 1: 12345678, and the current third was [U: 1: 12345678]. But the current version of HLstatsX (1.6.19) does not understand the new version of the identifier, which adds curvature to the statistics. To prevent this, we will make several changes to the scripts that will convert the new version of steamid3 into the old one, steamid2. The patch is taken from forums.alliedmods.net . Save the following to the file and run.


idpatch.sh
 #!/bin/sh uudecode -o ~/idpatch << EOF begin-base64 664 idpatch ZGlmZiAtTmF1cnAgc2NyaXB0cy9ITHN0YXRzX0V2ZW50SGFuZGxlcnMucGxp YiBzY3JpcHRzLmZpeGVkL0hMc3RhdHNfRXZlbnRIYW5kbGVycy5wbGliCi0t LSBzY3JpcHRzL0hMc3RhdHNfRXZlbnRIYW5kbGVycy5wbGliCTIwMTYtMDct MzAgMDI6NTE6NDUuMDAwMDAwMDAwICswNTAwCisrKyBzY3JpcHRzLmZpeGVk L0hMc3RhdHNfRXZlbnRIYW5kbGVycy5wbGliCTIwMTYtMTAtMTIgMTc6MDg6 MjcuNDM0NDA0MzczICswNTAwCkBAIC0xNTk0LDYgKzE1OTQsNyBAQCBzdWIg ZG9FdmVudF9QbGF5ZXJBY3Rpb24KIAkJCQlteSAkb3duZXJzdHJpbmcgPSAi IjsKIAkJCQlpZiAoZGVmaW5lZCgkcHJvcGVydGllc3tvYmplY3Rvd25lcn0p KSB7CiAJCQkJCW15ICRvd25lciA9ICRwcm9wZXJ0aWVze29iamVjdG93bmVy fTsKKwkJCQkJJG93bmVyID1+IHMhXFtVOjE6KFxkKylcXSEnU1RFQU1fMDon LigkMSAlIDIpLic6Jy5pbnQoJDEgLyAyKSFlZzsKIAkJCQkJJG93bmVyID1+ IC8uKz88U1RFQU1fWzAtOV0rOihbMC05XSs6WzAtOV0rKT4uKi87CiAJCQkJ CSRvd25lciA9ICQxOwogCQkJCQlpZiAoJG93bmVyIGVxICRwbGF5ZXItPnt1 bmlxdWVpZH0pIHsKZGlmZiAtTmF1cnAgc2NyaXB0cy9obHN0YXRzLnBsIHNj cmlwdHMuZml4ZWQvaGxzdGF0cy5wbAotLS0gc2NyaXB0cy9obHN0YXRzLnBs CTIwMTYtMDctMzAgMDI6NTE6NDUuMDAwMDAwMDAwICswNTAwCisrKyBzY3Jp cHRzLmZpeGVkL2hsc3RhdHMucGwJMjAxNi0xMC0xMiAxNzowOTowNS4wODA4 ODc1MDkgKzA1MDAKQEAgLTEwNjEsNiArMTA2MSw3IEBAIHN1YiBnZXRQbGF5 ZXJJbmZvCiAJCW15ICRoYXZlcGxheWVyICA9IDA7CiAJCQogCQkkcGxhaW51 bmlxdWVpZCA9ICR1bmlxdWVpZDsKKwkJJHVuaXF1ZWlkID1+IHMhXFtVOjE6 KFxkKylcXSEnU1RFQU1fMDonLigkMSAlIDIpLic6Jy5pbnQoJDEgLyAyKSFl ZzsKIAkJJHVuaXF1ZWlkID1+IHMvXlNURUFNX1swLTldKz9cOi8vOwogCQkK IAkJaWYgKCgkdW5pcXVlaWQgZXEgIkNvbnNvbGUiKSAmJiAoJHRlYW0gZXEg IkNvbnNvbGUiKSkgewpkaWZmIC1OYXVycCBzY3JpcHRzL1RSY29uLnBtIHNj cmlwdHMuZml4ZWQvVFJjb24ucG0KLS0tIHNjcmlwdHMvVFJjb24ucG0JMjAx Ni0wNy0zMCAwMjo1MTo0NS4wMDAwMDAwMDAgKzA1MDAKKysrIHNjcmlwdHMu Zml4ZWQvVFJjb24ucG0JMjAxNi0xMC0xMiAxNzowOTozMC42OTk4NTUzMTkg KzA1MDAKQEAgLTMzOCw2ICszMzgsNyBAQCBzdWIgZ2V0UGxheWVycwogICAg ICAgbXkgJGFkZHJlc3MgID0gJDg7CiAgICAgICBteSAkcG9ydCAgICAgPSAk OTsKIAorCSAgJHVuaXF1ZWlkID1+IHMhXFtVOjE6KFxkKylcXSEoJDEgJSAy KS4nOicuaW50KCQxIC8gMikhZWc7CiAJICAkdW5pcXVlaWQgPX4gcy9eU1RF QU1fWzAtOV0rP1w6Ly9pOwogCSAgCiAgICAgICAjICY6OnByaW50RXZlbnQo IkRFQlVHIiwgIlVTRVJJRDogJyR1c2VyaWQnLCBOQU1FOiAnJG5hbWUnLCBV TklRVUVJRDogJyR1bmlxdWVpZCcsIFRJTUU6ICckdGltZScsIFBJTkc6ICck cGluZycsIExPU1M6ICckbG9zcycsIFNUQVRFOiAnJHN0YXRlJywgQUREUkVT UzonJGFkZHJlc3MnLCBDTElfUE9SVDogJyRwb3J0JyIsIDEpOwo= ==== EOF patch --backup --directory ~/stat/scripts < ~/idpatch rm -f ~/idpatch 

Well, either pens on the article from the forum.


First start


So, we must have everything ready:



It remains to configure the launch of the demon. Return to ~ / stat. In principle, there you can delete already unnecessary directories amxmodx, sourcemod, sql, web. Leave only the heatmaps and scripts. In the ~ / stat / scripts directory, the *.pl and run_* files must be with the "executable" attribute:


  $ chmod +x ~/stat/scripts/*.pl ~/stat/scripts/run_* 

We start both game servers (if not started earlier).


The ~ / stat / scripts / run_hlstats file is a daemon that receives statistics from game servers and writes it to the sql database. Running it without parameters shows valid start parameters - start, stop, restart and others. For our configuration, its launch parameters are as follows: run_hlstats start < > < > < > - this is why in the settings of our game servers, in the logaddress_add parameters, the port numbers must go in series - 27500 for the first server and 27501 for the second . We start.


  $ ~/stat/scripts/run_hlstats start 2 27500 1 

Something like this should appear on the screen:


  HLstatsX:CE daemon control http://www.hlxce.com --------------------------- Attempting to start HLstatsX:CE daemon on port 27500... Daemon successfully started on port 27500 Attempting to start HLstatsX:CE daemon on port 27501... Daemon successfully started on port 27501 

And in the ~ / log / hlstats directory there were two files with logs (for each daemon its own). We look at the first log:


  2014-01-24 14:24:16: - MYSQL: Connecting to MySQL database 'hlx_db' on 'localhost' as user 'hlx_user' ... connected ok 2014-01-24 14:24:16: - CONFIG: Reading database config... 2014-01-24 14:24:16: - CONFIG: I have found the following server configs in database: 2014-01-24 14:24:16: - ERROR: GeoIP method set to binary file lookup but .//GeoLiteCity/GeoLiteCity.dat NOT FOUND 2014-01-24 14:24:16: - HLSTATSX: HLstatsX:CE 1.6.19 starting... 2014-01-24 14:24:16: - UDP: Opening UDP listen socket on port 27500 ... ok 2014-01-24 14:24:16: - HLSTATSX: Maximum Skill Change on all servers are 25 points 2014-01-24 14:24:16: - HLSTATSX: Tracking Trend of the stats are enabled 2014-01-24 14:24:16: - HLSTATSX: Minimum Skill Change on all servers are 2 points 2014-01-24 14:24:16: - HLSTATSX: Minimum Players Kills on all servers are 50 kills 2014-01-24 14:24:16: - HLSTATSX: Players chat logging is enabled 2014-01-24 14:24:16: - HLSTATSX: Broadcasting public chat is disabled 2014-01-24 14:24:16: - HLSTATSX: Event queue size is set to 10 2014-01-24 14:24:16: - HLSTATSX: HLstatsX:CE is now running (Normal mode, debug level 1) 

Swearing about GeoIP is normal, later we will tell the statistics server that the information is stored in the database, and not in an external file.


Now it is necessary to provide some kind of motion on our game servers - so that something is written to the logs. The easiest way to join the server. If at the same time in the logs all the same every two minutes begins to appear


  2014-01-24 15:21:33: - HLSTATSX: No data since 120 seconds 2014-01-24 15:23:33: - HLSTATSX: No data since 120 seconds 

either the game server is not running (or running but not this or not) or something with settings β€” first of all ip: port (if you specified ip 127.0.0.1 in the server settings, logaddress_add, then try to fix it with an external ), secondly, whether our logs are included at all, if so, where they are transmitted. Well, we can not exclude the influence of evil forces - the same firewall. With the correct settings, running netstat -lpn | grep perl netstat -lpn | grep perl should output something like:


  udp 0 0 0.0.0.0:27500 0.0.0.0:* 15855/perl udp 0 0 0.0.0.0:27501 0.0.0.0:* 15861/perl 

If after connecting to the server, the lines in the log ran:


  2014-01-24 15:39:37: 192.0.2.0:27015 - E997: NOT ALLOWED SERVER:  01/24/2014 - 15:39:39: "Ich<4><[U:1:123456789]><>" connected, address "198.51.100.0:44098" 2014-01-24 15:39:39: 192.0.2.0:27015 - E997: NOT ALLOWED SERVER:  01/24/2014 - 15:39:39: "Ich<4><[U:1:123456789]><>" STEAM USERID validated 

That is good. HLstatsX receives logs from the server, but since we have not yet configured the statistics server itself - in particular, we have not registered our game server there, it does not recognize it.


In case of errors like "Can't setup UDP socket on port 27500: Address already in use", use the netstat -lpn utility to determine the culprit netstat -lpn


So, we’ve finished with the most interesting, now let's move on to setting up the statistics server.


Server registration


Open our server in the browser - http://stat.example.org/


On the screen a warning about checking for updates, click on the link HLX: CE Database Updater , we see a notification that "Your database is up to date (78)", delete the updater folder:


  $ rm -rf /var/www/stat.example.org/htdocs/updater 

Again, go to http://stat.example.org/ , see the Google Map and at the very bottom of the page click on the link "[Admin]", enter the default login and password, admin: 123456. First of all, go to General Settings -> Admin Users . We change the administrator password and, optionally, his login. [Apply]. Then we start slowly setting up.


We register our servers. Go to Game Settings -> Team Fortress 2 (tf) -> Add Server, enter the data for the first server:


Server IP Address:
Our server IP is 192.0.2.0
Server Port:
server port - 27015 - the '-port' parameter from the srcds_run command line
Server Name:
can be left blank, will determine
Rcon Password:
specify the same as in rcon_password in the settings of the first server
Public Address:
leave blank - it matches the Server IP Address
Admin Mod:
we only have SourceMod installed, and choose it.


Next [Add Server], [Apply]. Restart the daemon - go to the proposed link , specify the port number - for the first server 27500, for the second 27501, click 'Execute'.


See the result:


  HLstatsX: CE Daemon Control Sending Command to HLstatsX: CE Daemon at localhost:27500 β€” 50 bytes OK Waiting for Backend Answer...recieving 29 bytes in 1 packets...OK Backend Answer: OK, EXECUTING COMMAND: RELOAD Closing connection to backend...OK Return to Administration Center 

If everything is done correctly, then the first daemon ~/log/hlstats/hlstats_27500<...> log will be updated:


  2016-10-12 21:43:48: - PROXY, Reload request from 127.0.0.1:43992: 2016-10-12 21:43:49: - CONTROL: Command received: RELOAD 2016-10-12 21:43:49: 127.0.0.1:43992 - CONTROL: Sent 29 bytes to frontend at '127.0.0.1:43992' 2016-10-12 21:43:49: 127.0.0.1:43992 - CONTROL: Re-Reading Configuration by request from Frontend... 2016-10-12 21:43:49: 127.0.0.1:43992 - CONFIG: Reading database config... 2016-10-12 21:43:49: 127.0.0.1:43992 - CONFIG: I have found the following server configs in database: 2016-10-12 21:43:49: 127.0.0.1:43992 - S_CONFIG: 192.0.2.0:27015 2016-10-12 21:43:49: 127.0.0.1:43992 - ERROR: GeoIP method set to binary file lookup but .//GeoLiteCity/GeoLiteCity.dat NOT FOUND 2016-10-12 21:45:05: - HLSTATSX: Insert new server trend timestamp 2016-10-12 21:45:47: - HLSTATSX: No data since 120 seconds 2016-10-12 21:47:35: 192.0.2.0:27015 - SERVER: Connecting to rcon on 192.0.2.0:27015 ... ok 2016-10-12 21:47:35: 192.0.2.0:27015 - TRCON: Trying to get rcon access (auth) 2016-10-12 21:47:35: 192.0.2.0:27015 - TRCON: Junk packet from Source Engine 2016-10-12 21:47:35: 192.0.2.0:27015 - TRCON: Rcon password accepted 2016-10-12 21:47:36: 192.0.2.0:27015 - SERVER: Server running map: cp_granary 2016-10-12 21:47:36: 192.0.2.0:27015 - SERVER: Ingame-URL: http://stat.example.org 2016-10-12 21:47:36: 192.0.2.0:27015 - SERVER: Query results will displayed in valve browser 2016-10-12 21:47:36: 192.0.2.0:27015 - SERVER: Showing stats is enabled 2016-10-12 21:47:36: 192.0.2.0:27015 - SERVER: Broadcasting Live-Events with "hlx_sm_psay" is enabled 

Everything, the first server is recognized as native, the rcon password is correct, the connection is established.


Similarly, we write the second server.


Server IP Address:
192.0.2.0
Server Port:
27016 (!)
Server Name:
is empty
Rcon Password:
specify the same as in rcon_password in the settings of the second server
Public Address:
is empty
Admin Mod:
Sourcemod


Next [Add Server], check the details.


A small moment that we can apply to the second server. During the period of trial operation, to check the operation of the statistics server, its further configuration and the search for possible problems, it is desirable that data be accumulated. Since it is hardly worth expecting that 24 players will fly to our fresh server like flies, and they will immediately start generating statistics on us, then you will have to do with improvised material - bots. How to populate the map with young, energetic bots is described in the "Bots" section, but for now when registering the second server, in the window before the final "[Apply]" we look for the "IgnoreBots" parameter and change its value to "0". Then, for the second game server, bots will be counted as real players and statistics will be kept on them (nothing, but just to be). Subsequently, before launching into production, we will reset all statistics of the second server and start life from scratch. In the meantime, we will assume that on the second server we have a koth_sawmill map, on which bots run.


If the moral core inside does not allow to descend to this, then you can change another parameter on the same server registration page, "MinPlayers", by setting it to "1". By default, the rating of the players begins to be considered when there are at least four people on the map. This was done to reduce markups on empty cards, but now we reduce the threshold to one - ourselves.


Then, when you need to return everything back, we can get to this window through the Game Settings section - Team Fortress 2 (tf) - Edit Servers - (select the server you need) - CONFIGURE - >> Server Details, return as it was. Then [Apply] and do not forget to restart the daemon.

Now restart the HLstatsX daemon to apply the settings for registering the second server. It is possible through the web interface, not forgetting to specify another port - 27501, but you can use handles:


  $ ~/stat/scripts/run_hlstats reload 

  HLstatsX:CE daemon control http://www.hlxce.com --------------------------- Successfully reloaded daemon running on port 27500 Successfully reloaded daemon running on port 27501 

In the browser we update the page http://stat.example.org/ , we see on the main page both our servers. We are happy.


We enter the game, join our server. In the chat window ("y") enter "hlx_menu". A menu appears. You can learn :-)


Initial setup


. General Settings -> HLstatsX:CE Settings:


Site Name
β€” HLstatsX at example.org


Site URL
URL , β€” http://stat.example.org/


Contact URL
, e-mail url β€” game@example.org


Use modrewrite to make forum signature image...
Disabled, http://stat.example.org/sig.php?player_id=1&background=random . url , Enabled rewrite sig-(.*)-(.*).png$ /sig.php?player_id=$1&background=$2 break; nginx ( -). url http://stat.example.org/sig-1-random.png .


Choose whether to use GeoCityLite data...
GeoIP . sql , "GeoIP lookup via database". run_hlstats.


Map Download URL...
, . Fast Download, - http://fastdl.example.org/maps/%MAP%.bsp.bz2 . , Maps -> < > , "Download this map...", , url ( ). . . Fast Download - , "", referer.


? [Apply], , GeoIP , .


HLstatsX, , ~/stat/scripts/logs, hlstats.conf "DebugLevel" "0".


Errors


- β€” ~/log/www-stat/error.log. :


  PHP Fatal error: Call to undefined function imagecreatetruecolor() in <...>/show_graph.php on line 194 

php-gd php, -.


  PHP Fatal error: Call to undefined function imageftbbox() in <...>/pChart.class on line 556 

, freetype.


  PHP Warning: imagepng(./hlstatsimg/progress/trend_123_4567890987.png): failed to open stream: Permission denied in /var/www/stat.example.org/htdocs/includes/pChart/pChart.class 

- hlstatsimg/progress.


  PHP Warning: session_start(): open(/var/lib/php/session/sess_m5ekot332e5k97au3a21hpqto6, O_RDWR) failed: No such file or directory (2) 

/var/lib/php/session, "php_value[session.save_path]" /etc/php-fpm.d/www.conf β€” php-fpm, , , - root:


  # mkdir /var/lib/php/session # chown nginx. /var/lib/php/session # chmod -R 700 /var/lib/php/session 


. https://bitbucket.org/Maverick_of_UC/hlstatsx-community-edition/downloads dev / HLstatsX Community Edition / extras / HeatmapPack / heatmap-src_3.zip


  $ wget https://bitbucket.org/Maverick_of_UC/hlstatsx-community-edition/raw/0577b45e5f33df4e2a6122077fa44902073a8844/extras/HeatmapPack/heatmap-src_3.zip $ unzip heatmap-src_3.zip tf/*.jpg -d ~/stat/heatmaps/src 

~/stat/heatmaps/src tf .jpg β€” . 65 , 32 Team Fortress 2 ( ), 33 β€” . , . , .


~/stat/heatmaps, config.inc.php. DB_ , HLXCE_WEB - β€” hlstatsimg. , OUTPUT_SIZE "large". DB_PREFIX ! , - :


  define('DB_HOST', 'localhost'); define('DB_USER', 'hlx_user'); define('DB_PASS', 'hlx_password'); define('DB_NAME', 'hlx_db'); define('HLXCE_WEB', '/var/www/stat.example.org/htdocs'); define('HUD_URL', 'http://stat.example.org'); 

cache/tf β€”


  $ mkdir -p ~/stat/heatmaps/cache/tf 

, /var/www/stat.example.org/htdocs/hlstatsimg/games/tf game ( ).


heatmap.class.php :


  $ sed -i -es#"m/d/y"#"d M Y"#g ~/stat/heatmaps/heatmap.class.php $ sed -i -es#"Ymd H:i:s"#"d MYH:i:s P"#g ~/stat/heatmaps/heatmap.class.php 

Run:


  $ ~/stat/heatmaps/generate.php 

, koth_sawmill . ( ):


  25-07-2016 20:38:30 DB: Connected to hlx_db as hlx_user@localhost 25-07-2016 20:38:31 IGNORE: Game: tf, Map: cp_warpath_v3, Kills: 0, (to few kills) 25-07-2016 20:38:47 IGNORE: Game: tf, Map: cp_wolf2_b1, Kills: 0, (to few kills) 25-07-2016 20:38:47 IGNORE: Game: tf, Map: koth_nucleus, Kills: 0, (to few kills) 25-07-2016 20:38:47 CREATE: Game: tf, Map: koth_sawmill, Kills: 2014 25-07-2016 20:39:24 IGNORE: Game: tf, Map: koth_viaduct, Kills: 0, (to few kills) 25-07-2016 20:39:24 CREATE: Heatmap creation done. 

/var/www/stat.example.org/htdocs/hlstatsimg/games/tf/heatmaps β€” koth_sawmill-kill.jpg koth_sawmill-kill-thumb.jpg.


, , , . Maps, koth_sawmill, , TOTAL KILLS:



. $timescope = (time() - 60*60*24*$mapinfo[$code][$map]['days']); heatmap.class.php, , , "days" sql hlstats_Heatmap_Config, "30".


, , , .jpg . hlstats_Heatmap_Config sql .



HLstatsX. :


run_hlstats
, ;


hlstats-awards.pl
, , sql ;


hlstats-resolve.pl
ip- ;


GeoLite_Import.sh
geoip ;


generate.php
.


- game, crontab ( ), . crontab -e , :


crontab
 */5 * * * * cd $HOME/stat/scripts && ./run_hlstats start 2 27500 1 1 0 * * * cd $HOME/stat/scripts && ./hlstats-awards.pl 5 4 * * * cd $HOME/stat/scripts && ./hlstats-resolve.pl 20 2 12 * * cd $HOME/stat/scripts/GeoLiteCity/ && ./GeoLite_Import.sh 30 2 12 * * cd $HOME/stat/scripts && ./hlstats-awards.pl --geoip 40 3 14 * * cd $HOME/stat/scripts && ./hlstats-awards.pl --optimize 15 * * * * cd $HOME/stat/heatmaps && ./generate.php 

β€” run_hlstats . -, . .


β€” hlstats-awards.pl, --inactive --awards --ribbons --prune .


β€” hlstats-resolve.pl, ip , Tools -> Host Statistics . β€” , ip .


β€” GeoIP.


β€” GeoIP, ip- .


β€” sql .


β€” .


cron , game ""


Tuning


Fonts


, , DejaVu Sans, , Unicode, , , - . Bitstream Cyberbit .


  $ wget http://ftp.netscape.com/pub/communicator/extras/fonts/windows/Cyberbit.ZIP $ unzip Cyberbit.ZIP -d /var/www/stat.example.org/htdocs/hlstatsimg/sig/font/ 

DejaVuSans.ttf .php , Cyberbit.ttf DejaVuSans.ttf, :


  $ sed -i -e 's/DejaVuSans.ttf/Cyberbit.ttf/g' /var/www/stat.example.org/htdocs/*.php 

:



Card preview


Maps -> < >, . , ( !) , , 218x164 < >.jpg /var/www/stat.example.org/htdocs/hlstatsimg/games/tf/maps. cp_orange_x3 cp_orange_x3.jpg :


Card preview


Separate accounting statistics


, (Team Fortress 2), , , . , , Tools -> Duplicate Game settings "tf β€” Team Fortress 2" . - hlstatsimg/games: chmod o+w /var/www/stat.example.org/htdocs/hlstatsimg/games . , Game Settings .


Disable statistics


- β€” , achievement … , ~/cfg < >.cfg ( ~/tf2/tf/cfg/) :


  echo "*** < >.cfg" logaddress_delall 

( ~/log/server2/ ). , ~/cfg/server2.cfg, . "hlx_protect_address" , .



HTTP Basic Authentication -, , motd , "/hlx". ingame.php .png, .gif, .css


New weapon


Game Settings, Team Fortress 2 (tf), Actions Weapons. , , HLstatsX.


Password recovery


HLstatsX, (admin:123456), , . ~/stat/sql/install.sql,


  INSERT INTO `hlstats_Users` VALUES ('admin','e10adc3949ba59abbe56e057f20f883e',100,0); 

- , reset_pwd.sql sql :


  $ mysql --user=hlx_user hlx_db --password < reset_pwd.sql 

- (admin:123456) General Settings -> Admin Users .



')

Source: https://habr.com/ru/post/312936/


All Articles