The online racing simulator
Searching in All forums
(535 results)
misiek08
S3 licensed
DB structure:
-- phpMyAdmin SQL Dump
-- version 2.11.8.1deb5+lenny7
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Czas wygenerowania: 24 Lut 2011, 17:49
-- Wersja serwera: 5.0.51
-- Wersja PHP: 5.3.5-0.dotdeb.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Baza danych: `ltwt`
--

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

--
-- Struktura tabeli dla `classes`
--

CREATE TABLE IF NOT EXISTS `classes` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(255) collate utf8_unicode_ci NOT NULL,
`short` varchar(255) collate utf8_unicode_ci NOT NULL,
`cars` text collate utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

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

--
-- Struktura tabeli dla `drivers`
--

CREATE TABLE IF NOT EXISTS `drivers` (
`id` int(10) unsigned NOT NULL auto_increment,
`team_nr` int(10) unsigned NOT NULL,
`session` int(10) unsigned NOT NULL default '0',
`nick` varchar(255) collate utf8_unicode_ci default NULL,
`uname` varchar(255) collate utf8_unicode_ci NOT NULL,
`car` varchar(255) collate utf8_unicode_ci default NULL,
`plate` varchar(255) collate utf8_unicode_ci default NULL,
`admin` int(10) unsigned NOT NULL default '0',
`add_mass` int(10) unsigned NOT NULL default '0',
`rest_intake` int(10) unsigned NOT NULL default '0',
`flags` int(10) unsigned NOT NULL default '0',
`pla` int(10) unsigned NOT NULL default '0',
`country` varchar(3) collate utf8_unicode_ci default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=148 ;

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

--
-- Struktura tabeli dla `laps`
--

CREATE TABLE IF NOT EXISTS `laps` (
`id` int(10) unsigned NOT NULL auto_increment,
`session` int(11) NOT NULL default '0',
`server` int(11) NOT NULL default '1',
`driver` int(11) NOT NULL,
`s1` int(11) NOT NULL default '0',
`s2` int(11) NOT NULL default '0',
`s3` int(11) NOT NULL default '0',
`s4` int(11) NOT NULL default '0',
`ltime` int(11) NOT NULL,
`ttime` int(11) NOT NULL,
`lap` int(11) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1679 ;

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

--
-- Struktura tabeli dla `packets`
--

CREATE TABLE IF NOT EXISTS `packets` (
`id` int(10) unsigned NOT NULL auto_increment,
`server` int(11) NOT NULL default '1',
`time` int(10) unsigned NOT NULL,
`data` mediumtext collate utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=6844 ;

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

--
-- Struktura tabeli dla `teams`
--

CREATE TABLE IF NOT EXISTS `teams` (
`id` int(10) unsigned NOT NULL auto_increment,
`session` int(11) NOT NULL default '0',
`team_nr` int(11) NOT NULL,
`start_pos` int(11) NOT NULL default '0',
`pos` int(11) NOT NULL default '0',
`name` varchar(255) collate utf8_unicode_ci NOT NULL,
`car` varchar(255) collate utf8_unicode_ci NOT NULL,
`changes` int(11) NOT NULL default '0',
`penalty` int(11) NOT NULL default '0',
`dsq` int(11) NOT NULL default '0',
`s1` int(11) NOT NULL default '0',
`s2` int(11) NOT NULL default '0',
`s3` int(11) NOT NULL default '0',
`s4` int(11) NOT NULL default '0',
`last_time` int(11) NOT NULL default '0',
`laps_done` int(11) NOT NULL default '0',
`ttime` int(11) NOT NULL default '0',
`online_driver` int(11) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=43 ;

misiek08
S3 licensed
Code of beta version can you see below. It's working but there is still a lot of things to do.
Code of plugin:

<?php 
php

class ltwt2 extends Plugins {
    const 
NAME 'Test';
    const 
AUTHOR 'Misiek';
    const 
VERSION PHPInSimMod::VERSION;
    const 
DESCRIPTION 'Testing PRISM.';

    public 
$poss = array();
    public 
$misiek_plid 0;
    public 
$lapsdone = array();
    public 
$session 0;

    public function 
__construct() {
        require_once(
'includes/DB.class.php');
        
DB::gi()->query('SET NAMES utf8');
        
$this->registerPacket('save_to_db'ISP_SPXISP_LAPISP_PITISP_PLAISP_PENISP_FLGISP_NPLISP_REO);
        
$this->registerPacket('lap'ISP_LAP);
        
$this->registerPacket('spx'ISP_SPX);
        
$this->registerPacket('npl'ISP_NPL);
        
$this->registerPacket('npl'ISP_NPL);
        
$this->registerPacket('toc'ISP_TOC);
        
$this->createTimer('showMemoryUsage'30Timer::REPEAT);
        
error_reporting(E_ALL E_NOTICE);
    }

    public function 
showMemoryUsage() {
        echo 
'-------------------------------' PHP_EOL;
        echo 
'-------------------------------' PHP_EOL;
        echo 
'@memory_get_usage(): ' . @memory_get_usage() . PHP_EOL;
        echo 
'@memory_get_usage(true): ' . @memory_get_usage(true) . PHP_EOL;
        echo 
'@memory_get_peak_usage(): ' . @memory_get_peak_usage() . PHP_EOL;
        echo 
'@memory_get_peak_usage(true): ' . @memory_get_peak_usage(true) . PHP_EOL;
        echo 
'-------------------------------' PHP_EOL;
        echo 
'-------------------------------' PHP_EOL;
    }

// Convert LFS Time to minutes:seconds.ms string
    
public function sekdoczas($czas) {
        
$ret "";
        
$minutes intval(intval($czas 1000) / 60);
        if (
$minutes 0) {
            
$ret .= $minutes ':';
        }
        
$seconds bcmod(intval($czas 1000), 60);
        
$ret .= ( ($seconds 10) ? '0' $seconds $seconds) . '.';
        
$setne bcmod($czas1000);
        
$ret .= $setne;

        return 
$ret;
    }

    public function 
cpr($packet) {
        
$client $this->getClientByUCID($packet->UCID);
        if (
$client != NULL) {
            
/* Wpisz dane gracza do tabeli, zeby byly aktualne */
            
$query 'UPDATE {{table}}drivers SET nick = :nick WHERE id = :id';
            
$quer DB::gi()->prepare($query);
            
$quer->bindValue(':id'$client->driver_id);
            
$quer->bindValue(':nick'$this->lfs_codepage_convert($packet->PName));
            
$quer->execute();
        }
    }

    public function 
npl($packet) {
        
$client $this->getClientByPLID($packet->PLID);
        if (
$client != NULL) {
            
/* Pobierz dane gracza i zapisz w danych o klientach hosta */
            
$quer DB::gi()->prepare('SELECT * FROM drivers WHERE uname = :uname AND session = :session');
            
$quer->bindValue(':uname'$client->UName);
            
$quer->bindValue(':session'$this->session);
            
$quer->execute();
            
$driver $quer->fetch(PDO::FETCH_OBJ);
            unset(
$quer);
            
$client->driver_id $driver->id;
            
$client->driver $driver;

            
/* Ustaw w tabeli teams aktualnego kierowcę */
            
$quer DB::gi()->prepare('UPDATE teams SET online_driver = :driver WHERE team_nr = (SELECT team_nr from drivers WHERE uname = :uname) AND session = :session');
            
$quer->bindValue(':uname'$client->UName);
            
$quer->bindValue(':driver'$client->driver_id);
            
$quer->bindValue(':session'$this->session);
            
$quer->execute();
            unset(
$quer);
            
/* Pobierz dane zespołu i dopisz do danych gracza */
            
$quer2 DB::gi()->prepare('SELECT laps_done, ttime FROM teams WHERE team_nr = :team_nr AND session = :session');
            
$quer2->bindValue(':team_nr'$client->driver->team_nr);
            
$quer2->bindValue(':session'$this->session);
            
$quer2->execute();
            
$quer2 $quer2->fetch(PDO::FETCH_OBJ);
            
$client->laps_done $quer2->laps_done;
            
$client->ttime 0;
            
$client->ttime $quer2->ttime;
            unset(
$quer2);
            
/* Wpisz dane gracza do tabeli, zeby byly aktualne */
            
$query 'UPDATE {{table}}drivers SET nick = :nick, car = :car WHERE id = :id';
            
$quer DB::gi()->prepare($query);
            
$quer->bindValue(':id'$client->driver_id);
            
$quer->bindValue(':nick'$this->lfs_codepage_convert($packet->PName));
            
$quer->bindValue(':car'$packet->CName);
            
$quer->execute();
            unset(
$quer);
            echo 
'PName: ' $client->PName ' / UName: ' $client->UName ' / Car: ' $packet->car '/ PLID: ' $packet->PLID ' / UCID: ' $client->UCID PHP_EOL;
            echo 
'Team #: ' $client->driver->team_nr ' / Intake: ' $client->driver->rest_intake ' / Added mass: ' $client->driver->add_mass PHP_EOL;
        } else {
            echo 
'-------------------------------' PHP_EOL;
            echo 
'-------------------------------' PHP_EOL;
            echo 
'NIE MA: ' $client->UName PHP_EOL;
            echo 
'-------------------------------' PHP_EOL;
            echo 
'-------------------------------' PHP_EOL;
        }
    }

    public function 
toc($packet) {
        
/* Obsługa TOC, ktora kiedys zrobi sam PRISM */
        
$client $this->getClientByUCID($packet->NewUCID);
        
$client->players[] = $this->getClientByUCID($packet->OldUCID)->players[$packet->PLID];
        unset(
$this->getClientByUCID($packet->OldUCID)->players[$packet->PLID]);
        
$this->getPlayerByPLID($packet->PLID)->setUCID($packet->NewUCID);
        
/* Koniec obsługi TOC */
        
if ($client != NULL) {
            
/* Pobierz dane gracza i zapisz w danych o klientach hosta */
            
$quer DB::gi()->prepare('SELECT * FROM drivers WHERE uname = :uname AND session = :session');
            
$quer->bindValue(':uname'$client->UName);
            
$quer->bindValue(':session'$this->session);
            
$quer->execute();
            
$driver $quer->fetch(PDO::FETCH_OBJ);
            unset(
$quer);
            
$client->driver_id $driver->id;
            
$client->driver $driver;
            
/* Ustaw w tabeli teams aktualnego kierowcę */
            
$quer DB::gi()->prepare('UPDATE teams SET online_driver = :driver WHERE team_nr = (SELECT team_nr from drivers WHERE uname = :uname) AND session = :session');
            
$quer->bindValue(':uname'$client->UName);
            
$quer->bindValue(':driver'$client->driver_id);
            
$quer->bindValue(':session'$this->session);
            
$quer->execute();
            unset(
$quer);
            
/* Pobierz dane zespołu i dopisz do danych gracza */
            
$quer2 DB::gi()->prepare('SELECT laps_done, ttime FROM teams WHERE team_nr = :team_nr AND session = :session');
            
$quer2->bindValue(':team_nr'$client->driver->team_nr);
            
$quer2->bindValue(':session'$this->session);
            
$quer2->execute();
            
$quer2 $quer2->fetch(PDO::FETCH_OBJ);
            
$client->laps_done $quer2->laps_done 1;
            
$client->ttime 0;
            
$client->ttime $quer2->ttime;
            unset(
$quer2);
            
/* Wpisz dane gracza do tabeli, zeby byly aktualne */
            
$query 'UPDATE {{table}}drivers SET nick = :nick WHERE id = :id';
            
$quer DB::gi()->prepare($query);
            
$quer->bindValue(':id'$client->driver_id);
            
$quer->bindValue(':nick'$this->lfs_codepage_convert($client->PName));
            
$quer->execute();
            unset(
$quer);
            echo 
'PName: ' $client->PName ' / UName: ' $client->UName ' / PLID: ' $packet->PLID ' / UCID: ' $client->UCID PHP_EOL;
            echo 
'Team #: ' $client->driver->team_nr ' / Intake: ' $client->driver->rest_intake ' / Added mass: ' $client->driver->add_mass PHP_EOL;
        } else {
            echo 
'NIE MA: ' $client->UName PHP_EOL;
        }
    }

    public function 
lap($packet) {
        
$client $this->getClientByPLID($packet->PLID);
        
$laptime $packet->LTime;
        if(
$packet->LapsDone == 1){
            
$laptime $laptime $client->ttime;
        }
        if (
$client != NULL) {
            
$client->laps_done++;
            
$client->ttime $client->ttime $laptime;
            
$query 'UPDATE {{table}}laps SET ltime = :ltime, ttime = :ttime WHERE driver = :driver AND lap = :lap AND session = :session';
            
$quer DB::gi()->prepare($query);
            
$quer->bindValue(':driver'$client->driver_id);
            
$quer->bindValue(':ltime'$laptime);
            
$quer->bindValue(':ttime'$client->ttime);
            
$quer->bindValue(':lap'$client->laps_done);
            
$quer->bindValue(':session'$this->session);
            
$quer->execute();
            unset(
$quer);
            
$query 'UPDATE {{table}}teams SET laps_done = laps_done + 1, ttime = ttime + ' $laptime ', last_time = ' $laptime ' WHERE team_nr = :team';
            
$quer DB::gi()->prepare($query);
            
$quer->bindValue(':team'$client->driver->team_nr);
            
$quer->execute();

            unset(
$quer);
        }
    }

    public function 
spx($packet) {
        
$client $this->getClientByPLID($packet->PLID);
        if (
$client != NULL) {
            
$db_split 's' $packet->Split;
            if (
$packet->Split == 1) {
                
$query 'INSERT INTO {{table}}laps (driver, lap, session) VALUES(:driver, :lap, :session)';
                
$quer DB::gi()->prepare($query);
                
$quer->bindValue(':driver'$client->driver_id);
                
$lap $client->laps_done 1;
                
$quer->bindValue(':lap'$lap);
                
$quer->bindValue(':session'$this->session);
                
$quer->execute();
                unset(
$quer);
                unset(
$lap);
                
$query 'UPDATE {{table}}teams SET  s1 = \'0\', s2 = \'0\', s3 = \'0\', s4 = \'0\', last_time = \'0\' WHERE team_nr = :team_nr AND session = :session';
                
$quer DB::gi()->prepare($query);
                
$quer->bindParam(':team_nr'$client->driver->team_nrPDO::PARAM_INT);
                
$quer->bindParam(':session'$this->sessionPDO::PARAM_INT);
                
$quer->execute();
                unset(
$quer);
            }
            
$query 'UPDATE {{table}}laps SET  ' $db_split ' = :value WHERE lap = :lap AND driver = :driver AND session = :session';
            
$quer DB::gi()->prepare($query);
            
$quer->bindValue(':driver'$client->driver_id);
            
$quer->bindValue(':lap'$client->laps_done 1);
            
$quer->bindValue(':value'$packet->STime);
            
$quer->bindValue(':session'$this->session);
            
$quer->execute();
            unset(
$quer);
            
$query 'UPDATE {{table}}teams SET  ' $db_split ' = :value WHERE team_nr = :team_nr AND session = :session';
            
$quer DB::gi()->prepare($query);
            
$quer->bindValue(':value'$packet->STime);
            
$quer->bindValue(':team_nr'$client->driver->team_nr);
            
$quer->bindValue(':session'$this->session);
            
$quer->execute();
            unset(
$quer);
            unset(
$db_split);
            unset(
$query);
        }
    }

// Saves packets into db
    
public function save_to_db($packet) {
        
$save_str serialize($packet);
        
$query 'INSERT INTO {{table}}packets (time, data) VALUES(unix_timestamp(),:serialized)';
        
$quer DB::gi()->prepare($query);
        
$quer->bindValue(':serialized'$save_str);
        
$quer->execute();
        unset(
$quer);
        unset(
$save_str);
    }

    private function 
lfs_codepage_convert($str$conv_to 'UTF-8') {
        
$sets = array('L' => 'CP1252',
            
'G' => 'ISO-8859-7',
            
'C' => 'CP1251',
            
'E' => 'ISO-8859-2',
            
'T' => 'ISO-8859-9',
            
'B' => 'ISO-8859-13',
            
'J' => 'SJIS-win',
            
'S' => 'CP936',
            
'K' => 'CP949',
            
'H' => 'CP950');

        
$tr_ptrn = array("/\^d/""/\^s/""/\^c/""/\^a/""/\^q/""/\^t/""/\^l/""/\^r/""/\^v/");
        
$tr_ptrn_r = array("\\""/"":""*""?""\"""<"">""|");
        
$str preg_replace($tr_ptrn$tr_ptrn_r$str);

        
$newstr $tmp '';
        
$current_cp 'L';
        
$len strlen($str);
        for (
$i 0$i $len$i++) {
            if (
$str{$i} == '^' && isset($sets[$str{$i 1}]) && $str{$i 1} != "^") {
                if (
$tmp != '') {
                    
$newstr .= iconv($sets[$current_cp], $conv_to$tmp);  
                    
$tmp '';
                }
                
$current_cp $str{++$i};
            }
            
// Filter out every character below 0x20
            
else if (ord($str{$i}) > 31)
                
$tmp .= $str{$i};
        }
        if (
$tmp != '')
            
$newstr .= iconv($sets[$current_cp], $conv_to$tmp);  

        
// Final special char to convert - could not do that before codepage conversion
        
return str_replace('^^''^'$newstr);
    }

    
/*
      public function lap($packet){
      $nick = $this->getPlayerByPLID($packet->PLID)->PName;
      $nick = preg_replace('/\^[0-9A-Za-z]/','', $nick);
      # if($nick == 'Misiek')
      echo 'Nick: ', $nick, ' / Czas: ', @$this->sekdoczas($packet->LTime), ' / Ukonczone: ',$packet->LapsDone, PHP_EOL;
      } */
}

?>

Code to display live stats:

<?php 
php
ini_set
('display_errors'1);
error_reporting(E_ALL);
$title 'Live';
require_once 
'inc/DB.class.php';
/* connecting to DB, creating instance and setting utf */
DB::gi()->query('SET NAMES utf8');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

### convert lfs time to stdClass object {hours, minutes, seconds, mili)

function lfs_time($time$mili true) {
    if (!
$mili) {
        
$time $time 1000;
    }
    
$return = new stdClass();
    
$return->hours floor($time 3600000);
    
$time $time - ($return->hours 3600000);
    
$return->minutes floor($time 60000);
    
$time $time - ($return->minutes 60000);
    
$return->seconds floor($time 1000);
    
$time $time - ($return->seconds 1000);
    if(
$time 100$time '0' $time;
    
$return->mili $time;
    return 
$return;
}

### convert lfs time to string H:i:s.ms

function lfs_time2string($time$mili true$hours false) {
    
$obj lfs_time($time);
    return ((
$hours) ? ($obj->hours ':') : '') . fillZero($obj->minutes) . ':' fillZero($obj->seconds) . (($mili) ? ('.' $obj->mili) : '');
}

### add 0 at the beginning of <10

function fillZero($where) {
    return (
$where 10) ? '0' $where $where;
}

### define colors for HTML-output ###

function lfs_getColorCode($col) {
    switch (
$col) {
        case 
: return "#000000";
        case 
: return "#ff0000";
        case 
: return "#00ff00";
        case 
: return "#ffff00";
        case 
: return "#0000ff";
        case 
: return "#ff00ff";
        case 
: return "#00ffff";
        case 
: return "#ffffff";
        case 
: return "#000000";
        case 
: return "#000000";
        default : return 
$col;
    }
}

### strip colors from names ###

function lfs_nameblank($name) {
    return 
stripslashes(preg_replace("/\^[0-9]/"""htmlspecialchars($name)));
}

### get colored names for HTML-output ###

function lfs_namecolored($name) {
    return 
stripslashes(preg_replace("/\^([0-9])(.[^\^]*)/e"'"<span style=\"color:".getColorCode($1).";\">$2</span>"'htmlspecialchars($name)));
}

/* L = Latin 1
 * G = Greek
 * C = Cyrillic
 * E = Central Europe
 * T = Turkish
 * B = Baltic
 * J = Japanese
 * S = Simplified Chinese
 * K = Korean
 * H = Traditional Chinese
 * 
 */
function lfs_codepage_convert($str$conv_to 'UTF-8') {
    
$sets = array('L' => 'CP1252',
        
'G' => 'ISO-8859-7',
        
'C' => 'CP1251',
        
'E' => 'ISO-8859-2',
        
'T' => 'ISO-8859-9',
        
'B' => 'ISO-8859-13',
        
'J' => 'SJIS-win',
        
'S' => 'CP936',
        
'K' => 'CP949',
        
'H' => 'CP950');

    
$tr_ptrn = array("/\^d/""/\^s/""/\^c/""/\^a/""/\^q/""/\^t/""/\^l/""/\^r/""/\^v/");
    
$tr_ptrn_r = array("\\""/"":""*""?""\"""<"">""|");
    
$str preg_replace($tr_ptrn$tr_ptrn_r$str);

    
$newstr $tmp '';
    
$current_cp 'L';
    
$len strlen($str);
    for (
$i 0$i $len$i++) {
        if (
$str{$i} == '^' && isset($sets[$str{$i 1}]) && $str{$i 1} != "^") {
            if (
$tmp != '') {
                
$newstr .= mb_convert_encoding($tmp$conv_to$sets[$current_cp]);
                
$tmp '';
            }
            
$current_cp $str{++$i};
        }
        
// Filter out every character below 0x20
        
else if (ord($str{$i}) > 31)
            
$tmp .= $str{$i};
    }
    if (
$tmp != '')
        
$newstr .= mb_convert_encoding($tmp$conv_to$sets[$current_cp]);

    
// Final special char to convert - could not do that before codepage conversion
    
return str_replace('^^''^'$newstr);
}

### get next position in class by car/carstype
function get_pos($car, &$classes){
    foreach(
$classes as $class){
        if(
in_array($car$class->cars)){
            
$class->pos++;
            return 
$class->pos 1;
        }
    }
}

### define colors for HTML-output ###
function getColorCode($col) {
    switch (
$col) {
        case 
: return "#000000";
        case 
: return "#ff0000";
        case 
: return "#00ff00";
        case 
: return "#ffff00";
        case 
: return "#0000ff";
        case 
: return "#ff00ff";
        case 
: return "#00ffff";
        case 
: return "#ffffff";
        case 
: return "#000000";
        case 
: return "#000000";
        default : return 
$col;
    }
}

$classes['XR3'] = 1;
$classes['FZ3'] = 1;
$classes['FX3'] = 1;
$classes['TBA'] = 1;
$classes['FZ5'] = 1;
$classes['RB4'] = 1;
$classes['XRG'] = 1;

/* $teamy_kierowcy = DB::gi()->prepare('
  SELECT
  (l.s1 + l.s2 + l.s3 + l.s4) AS splits_tog, l.s1, l.s2, l.s3, l.s4, l.ltime, l.lap,
  d.id as driver_id, d.nick, d.uname, d.admin, d.add_mass, d.rest_intake, d.flags, d.pla, d.country,
  t.id as team_id, t.team_nr, t.name, t.car, t.changes, t.penalty, t.dsq, t.online_driver, t.laps_done, t.ttime
  FROM (SELECT * FROM laps ORDER BY id DESC, lap DESC, ttime ASC) AS l
  LEFT JOIN drivers d ON(d.id = l.driver)
  LEFT JOIN teams t ON(t.team_nr = d.id_team)
  GROUP BY l.driver
  ORDER BY t.laps_done DESC, l.ttime ASC'); */
/* $teamy_kierowcy = DB::gi()->prepare('
  SELECT
  t.*,
  d.*,
  l.*
  FROM (SELECT * FROM laps GROUP BY driver ORDER BY lap) AS l LEFT JOIN drivers d ON d.id = l.driver LEFT JOIN teams t ON t.id = d.id_team'); */
$teamy_kierowcy DB::gi()->prepare('
    SELECT
    t.s1, t.s2, t.s3, t.s4, l.ltime, l.lap,
    d.id as driver_id, d.nick, d.uname, d.admin, d.car, d.add_mass, d.rest_intake, d.flags, d.pla, d.country,
    t.id as team_id, t.team_nr, t.name, t.car as class, t.changes, t.penalty, t.dsq, t.online_driver, t.laps_done, t.ttime,
    (SELECT ltime FROM laps WHERE driver = d.id ORDER BY id DESC LIMIT 1) AS ltime
    FROM teams t
    LEFT JOIN drivers d ON (d.id = t.online_driver)
    LEFT JOIN (SELECT * FROM laps GROUP BY driver ORDER BY lap) AS l ON(l.driver = d.id)
    ORDER BY t.laps_done DESC, t.ttime ASC, t.team_nr ASC'
);
$teamy_kierowcy->execute();
$teamy_kierowcy $teamy_kierowcy->fetchAll(PDO::FETCH_OBJ);

>?
xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <title>LFS Tracker - Misiek echo ($title && $title != '') ? '::' . $title : ''; </title>
        <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
        <link rel="stylesheet" href="style_1.css" />
        <script type="text/javascript" src="js/jQuery.js"></script>
        <script type="text/javascript" src="js/jquery.tooltip.min.js"></script>
        <!--script type="text/javascript" src="js/jquery.color.js"></script>
        <script type="text/javascript" src="js/jquery.dump.js"></script>
        <script type="text/javascript" src="js/functions.js"></script>
        <script type="text/javascript" src="js/lang_pl.js"></script>
        <script type="text/javascript" src="js/main.js"></script-->
    </head>
    <body>
        <div id="top_menu">
            <div id="top_menu_inner"><ul class="inline_list" style="margin:0; list-style-type: none;">
                    <li><a href="index.php" class="full_white">Home</a></li>
                    <li><a href="best.php" class="full_white">Best laps</a></li>
                    <li><a href="teams_drivers.php" class="full_white">Teams & Drivers</a></li>
                    <li><a href="rescue.php" class="full_white">Rescue live progress</a></li>
                </ul></div>
        </div>
        <div id="cala_strona">
<!--div id="pitstopy">
    <div id="pitstopy_desc">Pitstopy:</div>
    <div id="pitstop_temp" style="display:none;">
        <div id="pitstop_dr_team"></div>
        <div id="pitstop"></div>
        <div id="opony"></div>
    </div>
</div-->
<center>
    <h1> This is 3rd round race progress...</h1>
    <div id="main_stat_table_div">
        <table id="main_stat_table">
            <tr id="main_stat_desc" class="main_stat_row">
                <td id="id_desc" class="first w_help" title="Position">Pos.</td>
                <td id="id_desc" class="first w_help" title="Team number">#</td>
                <td id="kierowca_desc" style="width: 150px">Driver</td>
                <td id="team_desc" style="width: 150px">Team</td>
                <td id="samochod_desc" class="w_help" title="Car">Car</td>
                <td id="split1_desc" class="w_help" title="Sector 1">S1</td>
                <td id="split2_desc" class="w_help" title="Sector 2">S2</td>
                <!--td id="split3_desc" class="w_help" title="Sector 3">S3</td-->
                <td id="czasokr_desc" class="w_help" title="Lap time">Lap time</td>
                <td id="okr_desc" class="w_help" title="Lap">Lap</td>
                <td id="najokr_desc" class="w_help" title="Best driver lap">Best driver lap</td>
                <!--td id="kara_desc" style="width: 20px">Penalty</td-->
                <td id="gap1_desc">Gap to 1st</td>
                <td id="gap2_desc">Gap</td>
            </tr>
            <!--<tr id="main_stat_1" class="main_stat_row">
                    <td id="id_1" class="first">1</td>
                    <td id="kierowca_1">Misiek 1</td>
                    <td id="team_1">Fast Racing 1</td>
                    <td id="samochod_1">FZR</td>
                    <td id="split1_1">26.39</td>
                    <td id="split2_1">1:02.12</td>
                    <td id="split3_1">--:--.--</td>
                    <td id="czasokr_1">1:48.23</td>
                    <td id="okr_1">2</td>
                    <td id="najokr_1">1:48.23 (1)</td>
                    <td id="kara_1" class="last">-</td>
            </tr> -->
            php
            if(count($teamy_kierowcy) > 0){
                $first_ttime = $teamy_kierowcy[0]->ttime;
                $last_ttime = $first_ttime;
            }
            $i = 1;
            foreach ($teamy_kierowcy as $team) {
                $class_pos = $i;
                if (array_key_exists($team->class, $classes)) {
                    $class_pos = $classes[$team->class];
                    $classes[$team->class]++;
                }
                $best_czas = DB::gi()->prepare('SELECT * FROM laps l WHERE driver = \'' . $team->online_driver . '\' AND ltime <> 3600000 AND ltime <> 0 ORDER BY ltime ASC LIMIT 1');
                $best_czas->execute();
                if ($best_czas2 = $best_czas->fetch(PDO::FETCH_OBJ)) {
                    $team->best_czas = lfs_time2string($best_czas2->ltime);
                    $team->best_nr = $best_czas2->lap;
                    $best_czas->closeCursor();
                } else {
                    $team->best_czas = '---------';
                    $team->best_nr = '--';
                }

                echo '<tr id="main_stat_' . $team->team_id . '" class="main_stat_row"> ';
                echo '<td id="poz_' . $team->team_id . '" class="first" title="' . $class_pos . ' in class ' . strtoupper($team->class) . '">' . $i . '</td> ';
                echo '<td id="id_' . $team->team_id . '" class="first">' . $team->team_nr . '</td> ';
                echo '<td id="kierowca_' . $team->team_id . '">' . lfs_namecolored($team->nick) . '<br />(' . $team->uname . ')</td> ';
                echo '<td id="team_' . $team->team_id . '">' . $team->name . '</td> ';
                echo '<td id="samochod_' . $team->team_id . '">' . strtoupper($team->car) . '<br />Class:' . strtoupper($team->class) . '</td> ';
                echo '<td id="split1_' . $team->team_id . '">' . lfs_time2string($team->s1) . '</td> ';
                echo '<td id="split2_' . $team->team_id . '">' . lfs_time2string($team->s2) . '</td> ';
                //echo '<td id="split3_' . $team->team_id . '">' . lfs_time2string($team->s3) . '</td> ';
                echo '<td id="czasokr_' . $team->team_id . '">' . lfs_time2string($team->ltime) . '</td> ';
                echo '<td id="okr_' . $team->team_id . '">' . ($team->laps_done + 1) . '</td> ';
                echo '<td id="najokr_' . $team->team_id . '">' . $team->best_czas . '<br />(' . $team->best_nr . ')</td> ';
                //echo '<td id="kara_' . $team->team_id . '" class="last">' . $team->penalty . '</td> ';
                //echo '<td id="ttime_' . $team->team_id . '" class="last">' . $team->ttime . '</td> ';
                echo '<td id="gap1_' . $team->team_id . '" class="last">' . lfs_time2string($team->ttime - $first_ttime) . '</td> ';
                echo '<td id="gap2_' . $team->team_id . '" class="last">' . lfs_time2string($team->ttime - $last_ttime) . '</td> ';
                echo '<td id="lapslink_' . $team->team_id . '" class="last"><a href="laps.php?t=' . $team->team_nr . '">Laps</a></td> ';
                echo '</tr>';
                $last_ttime = $team->ttime;
                $i++;
            }
            unset($best_czas);
            
        </table>
</center>
<!--table id="legenda">
    <tr>
        <th colspan="3">Legenda:</th>
    </tr>
    <tr>
        <td style="width:40px; background-color:#FFCC00;"> </td><td>Kierowca znajduje się w pitlane</td>
    </tr>
    <tr>
        <td style="width:40px; background-color:#FF0000;"> </td><td>Zespół nie uczestniczy w wyścigu</td>
    </tr>
</table>
</div>
<div id="komentarz">
<div>komentarz 1</div>
<div>komentarz 1</div>
<div>komentarz 1</div>
<div>komentarz 1</div>
<div>komentarz 1</div>
</div-->
<script type="text/javascript">
    setTimeout("window.location.reload()", 25000);
</script>
</div>
<!--div onclick="do_example()" style="clear:both">Teraz</div>

</div>
<div id="end"></div>

<div>
    <textarea id="kod"></textarea>

    <div id="eval_kod">Execute</div>
    <textarea id="debug"></textarea>
</div-->
<script type="text/javascript">
$('*').tooltip({track: true,
    delay: 0,
    showURL: false});
</script>
</body>
</html>
?>

DB.class:

<?php 
php
class DB extends PDO {

    private static 
$instance NULL;
    private 
$prefix;

    static public function 
gi() {
        if (
self::$instance == NULL) {
            try {
                
self::$instance = new DB('62.75.188.55','ltwt''officiale''ltwt''');
                
self::$instance->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_WARNING);
            } catch (
PDOException $e) {
                die(
'Error while connecting to DB: ' $e->getMessage());
            }
        }
        return 
self::$instance;
    }

    public function 
__construct($host$user$pass$name$prefix '') {
        
$this->prefix $prefix;
        
parent::__construct('mysql:dbname=' $name ';host=' $host$user$pass);
    }

    public function 
exec($query$file false$line false) {
        
$query str_replace('{{table}}'$this->prefix$query);
        return 
parent::exec($query);
    }

    public function 
query($query) {
        
$query str_replace('{{table}}'$this->prefix$query);

        return 
parent::query($query);
    }

    public function 
prepare($query) {
        
$query str_replace('{{table}}'$this->prefix$query);
        return 
parent:[:p]repare($query);
    }

}
?>

I think here are still good PHP programmers so maybe someone can edit it and make it better. @boothy is going to release tracker of MoE but I think it can take some time.
misiek08
S3 licensed
It's possible to join every server as admin and as any account. Joining as admin is easy but as other LFSW account it's harder to do. I didn't that but someone did it on my server. It's really awesome when you change password and he is coming as admin back.
misiek08
S3 licensed
Ok. So now I'm merging tables. Datas are putted correctly.

What is alternative for GROUP BY to get last LAP row for every team in JOIN query.
misiek08
S3 licensed
Here are queries (packet : query):
LAP : $query = 'INSERT INTO {{table}}laps (driver, ltime, ttime, ldone) VALUES(:driver, :ltime, :ttime,:ldone)';
SPX : $query = 'INSERT INTO {{table}}splits (driver, lap, split, stime, ttime) VALUES(:driver, :lap, :split, :stime, :ttime)';
:lap is getted from last LAP packet + 1
ALL : $query = 'INSERT INTO {{table}}packets (time, data) VALUES(unix_timestamp(),:serialized)';
MySQL problem
misiek08
S3 licensed
Hello!
I've attached the structure for my DB. I'm making teams tracker for long races and I have first problem here. I need to get teams ordered by laps done and total time and split in 1 query to display it. Here is my query, but it shows only data for 1st lap. On the next lap nothing changes in results and I have ldone = 1 for every row. I don't wonna use trigger but if no one will know how to fix it I will add some columns to teams table and with triggers or by InSim I will put there data.
Last edited by misiek08, .
misiek08
S3 licensed
The settings file isn't honored. Look at it please. You have only 1 line with Flags. There is no place where you get it from settings file and set into InsimConnection class.
misiek08
S3 licensed
@Dygear - if I understood PRISM code good I can write in hosts.ini flags=8 and it will overwrite your code. So this is way to avoid MCI packets. Sry for creating problem but defining MCI receive flag at default is good only for part of PRISM users.
misiek08
S3 licensed
Make alone top speed and add 30kph to it. It's caused beacuse sometimes another car can go ahead and they together can rich bigger speed. Physics.
misiek08
S3 licensed
Set autosave MPR to 1. It's an option in setup.cfg
misiek08
S3 licensed
@cargame.nl - really? 7-zip is compressing to normal Zip. I'm opening 7-zip zip's on clear XP's because I'm installing many systems for ppl and everything works ok. I don't have problem with ZipX and other stuff.
misiek08
S3 licensed
@Dygear. I was responding to @T3charmy question about: how to receive MCI packets again in new version of PRISM.

Can u make an subversion because I wonna have synced folder with newest, official version. Make it 0.3.3.1 pls.
misiek08
S3 licensed
Currspeed > Maxspeed
misiek08
S3 licensed
If I didn't miss anything you should add in hosts.ini:
Quote :
flags = 40

Because 8 + 32 = 40 from this definitions:
Quote :#define ISF_RES_0 1 // bit 0 : spare
#define ISF_RES_1 2 // bit 1 : spare
#define ISF_LOCAL 4 // bit 2 : guest or single player
#define ISF_MSO_COLS 8 // bit 3 : keep colours in MSO text
#define ISF_NLP 16 // bit 4 : receive NLP packets
#define ISF_MCI 32 // bit 5 : receive MCI packets

I'm waiting for changing the $ISP->Flags definition in next PRISM version because console with 4239489238492348 packets it's hard to read and if someone is going to do LFS Mail based on PRISM then for 1000 hosts it could be terrible to have enabled MCI packets. It could be big traffic...
misiek08
S3 licensed
Is PRISM is line:
Quote :
$ISP->Flags = (isset($this->Flags) && $this->Flags > 0) ? $this->Flags : ISF_MSO_COLS | ISF_MCI;

I think dla it shouldn't have the last flag | ISF_MCI. Then it will be possible to enable mci in .ini files.
Avoid receiving MCI and/or NLP
misiek08
S3 licensed
Hi!
Maybe it was written but after 6 hours with PHP code of plugin it's hard to see anything. How can I avoid receiving MCI and/or NLP packets. Sometimes we don't need both but only one and sometimes we don't need any of this packets. So?

I thought to set pps = 0 but it will probably show error about Division by 0. I don't have server to test it now.
misiek08
S3 licensed
I copied from Windows to Linux and it's working. So the file on Windows it's good. Phucking Windows.
misiek08
S3 licensed
I have next problem.
I have singleton class for DB:

<?php 

php

require_once('settings.class.php');

class 
DB extends PDO {

    private static 
$instance NULL;
    private 
$prefix;

    static public function 
gi() {
        if (
self::$instance == NULL) {
            try {
                
$settings Settings::getInstance();
                
$settings->import('ltwt.ini');
                
$settings $settings->settings;
                
self::$instance = new DB($settings['host'], $settings['user'], $settings['pass'], $settings['name'], $settings['prefix']);
                
self::$instance->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_WARNING);
            } catch (
PDOException $e) {
                die(
'Error while connecting to DB: ' $e->getMessage());
            }
        }
        return 
self::$instance;
    }

    public function 
__construct($host$user$pass$name$prefix '') {
        
$this->prefix $prefix;
        
parent::__construct('mysql:dbname=' $name ';host=' $host$user$pass);
    }

    public function 
exec($query$file false$line false) {
        
$query str_replace('{{table}}'$this->prefix$query);
        return 
parent::exec($query);
    }

    public function 
query($query) {
        
$query str_replace('{{table}}'$this->prefix$query);

        return 
parent::query($query);
    }

    public function 
prepare($query) {
        
$query str_replace('{{table}}'$this->prefix$query);
        return 
parent:[:p]repare($query);
    }

}
?>

It's showing me unexcepted T_SL error. Why? PHP version 5.3.3. OS: Windows.
On linux it's working ok.
Last edited by Dygear, . Reason : Don't quote code, surround it with PHP tags.
misiek08
S3 licensed
Big, epic fail. I upgraded PHP by dotdeb entries in sources.list and..... PRISM is working. Damn. Thanks filur.
misiek08
S3 licensed
Epic fail. 5.2.6 now. I'll try to run on 5.3.0
misiek08
S3 licensed
I know how to export errors from script. Here you have the dev.log contents:
Quote :Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in /root/prism/Dygear-PRISM-12942d8/PHPInSimMod.php on line 271

I'm running it on Debian Lenny.
misiek08
S3 licensed
There is. I don't have source on my computer but it's line inside foreach(....plugins as $plugin) .....console($plugin::NAME, $plugin::VERSION). Something like that. It's near the 273 line. Maybe 271.
Parse error
misiek08
S3 licensed
Hi!
I tried to run PRISM on my VPS by hand. I downloaded it and then executed php PHPInSimMod.php. I get:
Quote :php PHPInSimMod.php

Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in /root/prism/Dygear-PRISM-12942d8/modules/prism_packets.php on line 271

Any help?
In test version (branch current) line is 273.
misiek08
S3 licensed
I wonna it too.
misiek08
S3 licensed
My official release maybe will be February or early March. (early means here early not 3 years later as for LFS)
Maybe someone will do it faster but I don't have so many time. I'll be testing first version in January on some league but this will be beta only.
FGED GREDG RDFGDR GSFDG