Local tracker to database

You can download the local tracker (without PHP, 26kB) from the LFS forum thread, or download the local tracker (with PHP 4.4.7, 5MB), my dropbox account. Created by WolleT and Frankmd.

Contents

  1. Configuration
    1. server.txt
    2. Database
    3. Race/Qualifying/Practice
  2. Batch files
    1. clean_database.bat
    2. start_tracker.bat
    3. steal someones db and start_tracker.bat
  3. Useful information
    1. On disconnection
    2. Post Race

Configuration

The local tracker is fairly simple to set up - simply edit the server.txt file and import db.sql into the database.

server.txt

# server number ~> SERVERNAME(Relay)|Host(IP)|Port|Admin_PW|Spec_PW|Use_Relay(0|1)

#
#
#
1  ~> servername|ip|insim port|admin pw|spec pw|0
2  ~> servername #2|ip|insim port|admin pw|spec pw|0
etc

Simply edit the server.txt file in notepad or another text editor, and add the IP, insim port and admin password of the server. You can add as many servers as you wish, but by default only the first 3 servers will be used to provide data to the web tracker.

Database

By default, the web & local tracker both use database named moetracker, with user moesite and password moepassword. These need to be created, and then the file db.sql should be imported. Here is the SQL contained in db.sql.

-- 
-- Table structure for table `data`
--

CREATE TABLE `data` (
  `id` int(11) NOT NULL auto_increment,
  `lfsworld` varchar(40) NOT NULL default '',
  `type` varchar(40) NOT NULL default '',
  `value` varchar(250) NOT NULL default '',
  `lap` int(11) NOT NULL default '0',
  `race_id` int(11) NOT NULL default '0',
  `created_on` int(11) NOT NULL default '0',
  `time` int(11) NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `lfsworld` (`lfsworld`),
  KEY `type` (`type`),
  KEY `race_id` (`race_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- --------------------------------------------------------

-- 
-- Table structure for table `race`-- 

CREATE TABLE `race` (
  `id` int(11) NOT NULL auto_increment,
  `server` int(2) unsigned NOT NULL default '0',
  `track` varchar(6) NOT NULL default '',
  `laps` int(11) NOT NULL default '0',
  `weather` int(1) NOT NULL default '0',
  `wind` int(1) NOT NULL default '0',
  `created_on` int(11) NOT NULL default '0',
  `type` varchar(4) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Race/Qualifying/Practice

By default, only tracking of race sessions (where a race is in progress and laps > 0) is enabled by default. To track qualifying or practice sessions, you need to edit the boolean (true/false) values on lines 6-8 of insim/vr.php to get the local tracker to process the insim data during those sessions.

Batch files

These batch files are for Windows, in order to ensure the local tracker connection does not time out in PHP. By default the local tracker uses a PHP install in the /php-4.4.7-Win32/ directory. It may use more than an average amount of CPU, so it should be run on a good processor or a second computer.

clean_database.bat

Empties the data and race tables in the moetracker database.

start_tracker.bat

Runs php.exe and vr.php from the command line - which connects to the servers and starts storing data in the database.

steal someones db and start_tracker.bat

Connects to the IP address specified in the batch file to retrieve the contents of the database. Displays the highest race_id found in the database, then starts the tracker. You may need to put a filepath in front of the mysql commands mysqldump and mysql - e.g. C:\wamp\bin\mysql\mysql5.1.36\bin\

Useful Information

To ensure redundancy, more than one person should run the local tracker, preferably 3 people all of whom have good connections, especially for long endurance races.

On disconnection

If the tracker connection to the server times out, then the following should be done to ensure accuracy:

  1. Clean the database by running clean_database.bat
  2. Steal someone else's database using the batch file, which also starts the tracker.
  3. In the dos box, you should see a value for max(id), this is the highest race_id from the race table in the other person's database. This is the old race_id.
  4. Once the tracker is recording again, use phpMyAdmin to check the last race_id in the race table. This is the new race_id.
  5. To get all of the information in the data table back on the same race_id, execute the following query in phpMyAdmin while in the moetracker database: UPDATE 'data' SET 'race_id' = new_race_id WHERE 'race_id' = old_race_id; - substituting the new and old race_ids into the query.

This is also useful when there is a server problem requiring a race restart, meaning 2 different race_ids - set them both to the same race_id and delete the other one in the race table.

Post Race

Once all of the cars have completed their final lap, the tracker dos box should be closed to stop any further recording. If this is not possible, then update.php should be closed, so that the web tracker does not continue updating if for example, a new race starts on the server. If you do not use $trimFinished in the web tracker or if for some reason it does not work properly, then the extra laps and splits should be deleted after everyone has finished their final lap.

Also, the moetracker database should be exported and stored along with the .html, config.php and teams.yaml/.csv files to allow archiving, and so that the tracker can be recreated at a later data if required.