The online racing simulator
Searching in All forums
(15 results)
xergio
S3 licensed
Another PHP parser...


<?php 
php

/*

xergio - [email protected]
http://en.lfsmanual.net/wiki/User:xergio

http://en.lfsmanual.net/wiki/File_Formats#SET
http://www.lfsforum.net/showthread.php?t=14477
http://www.lfsforum.net/showthread.php?t=27054

*/

class PHPSET {

    public 
$file;
    public 
$headers;
    public 
$fields;

    function 
__construct($file) {
        
$this->file trim($file);
        
        
$this->header_len 12;
        
$this->body_len 132 $this->header_len//132 char == \0
        
        
$this->parse();
    }
    
    public function 
parse($file null) {
    
        
$this->stime microtime(true);
        
        
        if (
$file) {
            
$this->file trim($file);
        }
        
        if (!
file_exists($this->file) or !is_file($this->file) or !preg_match('#\.set$#i'$this->file))
            throw new 
Exception("SET not exists: ".basename($this->file)."");
            
        if (!(
$f fopen($this->file'rb')))
            throw new 
Exception("Error opening ".basename($this->file)."");


        if (!(
$header fread($f$this->header_len)))
            throw new 
Exception("Error reading header");


        
$this->headers = new PHPSET_Header($header);

        if (!(
$data fread($f$this->body_len)))
            throw new 
Exception("Error reading data");
        
$this->fields = new PHPSET_Fields($data);
        
        
$this->etime microtime(true);
        
$this->ptime $this->etime $this->stime;
        
        
        if (
$file) return $this;
    }

}


class 
PHPSET_Data {

    protected 
$data;
    protected 
$value;

    public function 
__set($name$value) {
        
$class_name 'PHPSET_'$name;
        
        if (
class_exists($class_name))
            
$this->$name = new $class_name($value);
            
        else if (
is_string($value))
            
$this->$name trim($value);
            
        else
            
$this->$name $value;
    }
    
    
    function 
__toString() {
        if (
$this->value) return $this->value;
        return 
$this->data;
    }
    
    
    function 
translate($translations) {
        
$this->value $translations[$this->data];
    }
    
}


class 
PHPSET_Header extends PHPSET_Data {

    function 
__construct($bin) {
        
$headers unpack("A6SRSETT/x1/C1lfsInternalVersion/C1fileFormatVersion/x3"$bin);
        
        foreach ((array)
$headers as $header => $value) {
            
$this->$header $value;
        }
        
        if (
$this->SRSETT != 'SRSETT')
            throw new 
Exception("File has not a valid SET format");
    }
    
}


class 
PHPSET_Fields extends PHPSET_Data {

    function 
__construct($bin) {
        
$fields unpack("C1misc/C1unknown/C1handicapMassPosition/C1tyreBrand/f1brakeStrength/C1rearWingAngle/C1frontWingAngle/C1voluntaryHandicapMass/C1voluntaryIntakeRestriction/C1maxSteeringLock/C1parallelSteering/C1brakeBalance/C1engineBrakeReduction/C1centreDiffType/C1centreDiffViscousTorque/x1/C1centreDiffTorqueSplit/S1gearRatio7/S1gearRatioFinal/S1gearRatio1/S1gearRatio2/S1gearRatio3/S1gearRatio4/S1gearRatio5/S1gearRatio6/C1passenger/C1carConfig/C1tractionControlSlip/C1tractionControlEngageSpeed/frearTravel/frearSpring/frearComp/frearRebound/frearAR/x4/C1rearToe/C1rearCaster/C1rearTyreType/x1/C1LRcamberAdjust/C1RRcamberAdjust/x1/C1rearDiffClutchPack/C1rearDiffType/C1rearViscousTorque/C1rearPowerLocking/C1rearCoastLocking/S1LRtyrePressure/S1RRtyrePressure/ffrontTravel/ffrontSpring/ffrontComp/ffrontRebound/ffrontAR/x4/C1frontToe/C1frontCaster/C1frontTyreType/x1/C1LFcamberAdjust/C1RFcamberAdjust/x1/C1frontDiffClutchPack/C1frontDiffType/C1frontViscousTorque/C1frontPowerLocking/C1frontCoastLocking/S1LFtyrePressure/S1RFtyrePressure"$bin);
        
        foreach ((array)
$fields as $field => $value) {
            
$this->$field $value;
        }
    }
    
}


class 
PHPSET_misc extends PHPSET_Data {

    function 
__construct($data) {
        
$this->data decbin($data);
    }
}


class 
PHPSET_passenger extends PHPSET_Data {

    function 
__construct($data) {
        
$this->data decbin($data);
    }
}


class 
PHPSET_tyreBrand extends PHPSET_Data {
    
    function 
__construct($data) {
        
$this->data $data;
        
$this->translate(array('Cromo Plain''Cromo''Torro''Michelin''Evostar'));
    }
}


class 
PHPSET_centreDiffType extends PHPSET_Data {
    
    function 
__construct($data) {
        
$this->data $data;
        
$this->translate(array('Open''Viscous'));
    }
}


class 
PHPSET_rearDiffType extends PHPSET_Data {
    
    function 
__construct($data) {
        
$this->data $data;
        
$this->translate(array('Open''Locked''Viscous''Clutch Pack'));
    }
}
class 
PHPSET_frontDiffType extends PHPSET_rearDiffType {}


?>

Example of use:


<?php 
php

require('phpset.php');

$set = new PHPSET('RB4_FE5r_test.set');
print_r($set);

?>

var_dump example:

PHPSET Object
(
[file] => /home/salvarez/mch.lfsteam.es/forum/setups/store/RB4/FE5R/RB4_FE5r zarugor.set
[headers] => PHPSET_Header Object
(
[data:protected] =>
[value:protected] =>
[SRSETT] => SRSETT
[lfsInternalVersion] => 251
[fileFormatVersion] => 2
)

[fields] => PHPSET_Fields Object
(
[data:protected] =>
[value:protected] =>
[misc] => PHPSET_misc Object
(
[data:protected] => 10000100
[value:protected] =>
)

[unknown] => 0
[handicapMassPosition] => 50
[tyreBrand] => PHPSET_tyreBrand Object
(
[data:protected] => 3
[value:protected] => Michelin
)

[brakeStrength] => 920
[rearWingAngle] => 0
[frontWingAngle] => 0
[voluntaryHandicapMass] => 0
[voluntaryIntakeRestriction] => 0
[maxSteeringLock] => 30
[parallelSteering] => 0
[brakeBalance] => 72
[engineBrakeReduction] => 0
[centreDiffType] => PHPSET_centreDiffType Object
(
[data:protected] => 1
[value:protected] => Viscous
)

[centreDiffViscousTorque] => 20
[centreDiffTorqueSplit] => 39
[gearRatio7] => 0
[gearRatioFinal] => 32767
[gearRatio1] => 26214
[gearRatio2] => 16852
[gearRatio3] => 11047
[gearRatio4] => 7958
[gearRatio5] => 5243
[gearRatio6] => 3253
[passenger] => PHPSET_passenger Object
(
[data:protected] => 0
[value:protected] =>
)

[carConfig] => 0
[tractionControlSlip] => 20
[tractionControlEngageSpeed] => 5
[rearTravel] => 0.274268299341
[rearSpring] => 40000
[rearComp] => 4497.56103516
[rearRebound] => 5126.82910156
[rearAR] => 37000
[rearToe] => 6
[rearCaster] => 0
[rearTyreType] => 6
[LRcamberAdjust] => 20
[RRcamberAdjust] => 36
[rearDiffClutchPack] => 20
[rearDiffType] => PHPSET_rearDiffType Object
(
[data:protected] => 1
[value:protected] => Locked
)

[rearViscousTorque] => 20
[rearPowerLocking] => 80
[rearCoastLocking] => 80
[LRtyrePressure] => 162
[RRtyrePressure] => 165
[frontTravel] => 0.236869946122
[frontSpring] => 45000
[frontComp] => 4785.36572266
[frontRebound] => 6341.46337891
[frontAR] => 18000
[frontToe] => 10
[frontCaster] => 0
[frontTyreType] => 6
[LFcamberAdjust] => 29
[RFcamberAdjust] => 39
[frontDiffClutchPack] => 16
[frontDiffType] => PHPSET_frontDiffType Object
(
[data:protected] => 2
[value:protected] => Viscous
)

[frontViscousTorque] => 20
[frontPowerLocking] => 60
[frontCoastLocking] => 80
[LFtyrePressure] => 170
[RFtyrePressure] => 170
)

[header_len] => 12
[body_len] => 120
[stime] => 1266580405.69
[etime] => 1266580405.69
[ptime] => 0.000797033309937
)

In addition... I've restored the .set spec in lfs manual. For some reason someone deleted it ¬¬ http://en.lfsmanual.net/wiki/File_Formats#SET
xergio
S3 licensed
who have to make this is your lapper. I think that this "request" must be in Lapper forum
xergio
S3 licensed
http://en.lfsmanual.net/wiki/InSim.txt

Search: IS_ISI packet

byte Prefix; // Special host message prefix character

xergio
S3 licensed
Quote from DarkTimes :Only thing is you might want to turn off the ISF_MCI flag to save some resources, as you're not using any MCI packets.

done
External ingame chat-window
xergio
S3 licensed
Hi all!

This is a short post to show you an small InSim program to export all ingame chat messages outside the game. It's simple, connect the program, read the cache file and printf()!

You can see the result in my team's page (bottom page): http://mch.lfsteam.es/forum

You need Pyinsim >= 1.6.3 . This is a simple adaptation from the author's examples.

import sys
import os
import time

VERSION = '1.6.3'
try:
import pyinsim
if not pyinsim.version(VERSION):
raise ImportError
except ImportError:
print 'You must install pyinsim %s or better' % VERSION
sys.exit(1)


HEARTBEAT_INTERVAL = 10
PATH_CACHE = './cache.txt'


insim = pyinsim.InSim()
insim.message_cache = []


def heartbeat(insim):
save_cache(insim)
insim.timer(heartbeat, HEARTBEAT_INTERVAL)


def load_cache(insim):
if not os.path.isfile(PATH_CACHE):
open(PATH_CACHE, 'a').close()

p = open(PATH_CACHE, 'r')
lines = p.readlines()
for line in lines:
if len(line.strip()) > 0:
insim.message_cache.append(line.strip())
p.close()


def save_cache(insim):
lines = insim.message_cache[-100:]
p = open(PATH_CACHE, 'w')
for line in lines:
p.write("%s\n" % line.strip().replace("\r", "").replace("\n", ""))
p.close()


def message_out(insim, mso):
insim.message_cache.append(str(int(time.time())) +";"+ mso.Msg.strip())


if __name__ == '__main__':
try:
insim.bind(pyinsim.ISP_MSO, message_out)
insim.init('localhost', 29999, Admin='admin', IName='logexport', Flags=pyinsim.ISF_MSO_COLS, Interval=500)
insim.timer(load_cache, 1)
insim.timer(heartbeat, HEARTBEAT_INTERVAL)

except pyinsim.InSimError as err:
print 'InSim Error:', err
sys.exit(1)

except:
print 'Unexpected error:', sys.exc_info()[0]
sys.exit(1)

The format of the cache file is a line per message, in the form:
timestamp;message

You can parse it with PHP with something like:


<?php 
$logexport_lines 
file("cache.txt");

foreach (
$logexport_lines as $logexport_line) {
  list(
$timestamp$message) = split(";"$logexport_line2);
  
// do something here
}
?>

In my case, I use phpBB to show the messages, but you can use any system that you like.

Yes, my english is bad... sorry. And yes, I'm bored... I'm looking for ideas to make something more usefull with InSim, any suggestion?
Last edited by xergio, .
xergio
S3 licensed
Count with me. Now I have very fresh all that I'm learning, and I have a good PoV about what is the first wall that the people see when start to make insim programs.

I've playing WoW for 4 years, and I've make some addons... of course, the documentation al wowwiki it's exceptional, and there is too many addons that make you life better. And, of course, the libs than make a lot of things for you.

This is what LFS need, to customize each server, to allow peaple to be different from others, think in mirc, as well as wow...

For this all of this, count with me to help in this ^^
xergio
S3 licensed
It sounds very nice We'll stay tuned!
PHP5 - Simple MPR parser
xergio
S3 licensed
Hi all!

It's simple, this script allow to you to read the MPR files and extract the headers and the results of the race (if someone finish the race)

This is a frustrating try to read all the race. All I obtain was the documented info at www.lfs.net/?page=MPR .... and all the car/head skins used by the participants... but It isn't implemented. As I've said... I finished frustrated

You can use my script with something like this:


<?php 

require_once('phpmpr.php');

// parse the file
$o = new PHPMPR('some-mpr-file.mpr');

// see the content
var_dump($o);

?>

The $o object has two principal properties: $o->headers with all the header info, and $o->players with an array with all the results.

See the code and the dump for more info Demo: http://mch.lfsteam.es/forum/mpr.php

P.D.: Sorry for my english... I know PHP, not english



Edit1: updated file to avoid a file requirement
Last edited by xergio, .
xergio
S3 licensed
Hi.

First of all, very good job! I've abandoned PHPLFS and I adopted Pyinsim 4ever! :P

Well, I downloaded the last version 1.1.4, and when i've tested (for example) the buttons example, I got this traceback:

Traceback (most recent call last):
File "insim_buttons.py", line 40, in <module>
insim.send(pyinsim.ISP_ISI, Admin='Pass', IName='^3pyinsim', Flags=pyinsim.ISF_LOCAL)
File "/home/salvarez/_/_p/salvarez/pylfs/pyinsim_1.1.4/examples/pyinsim.py", line 1478, in send
self.sendB(Packet(packetType, **values).pack())
File "/home/salvarez/_/_p/salvarez/pylfs/pyinsim_1.1.4/examples/pyinsim.py", line 1748, in pack
return struct.pack(self.__packStr, [values.append(self[p[0]]) for p in _PACKET_DEFS[self['Type']]])
UnboundLocalError: local variable 'values' referenced before assignment

I've switched this commented lines:

def pack(self):
"""Pack the current packet values into a binary string, which can then
be sent to InSim.

Returns:
A binary formatted string.

"""
[COLOR=Red] return struct.pack(self.__packStr, [values.append(self[p[0]]) for p in _PACKET_DEFS[self['Type']]]) [/COLOR]

[COLOR=SeaGreen]# values = []
# for packetDef in _PACKET_DEFS[self['Type']]:
# values.append(self[packetDef[0]])
# return struct.pack(self.__packStr, *values)[/COLOR]

And all work now.

It's correct?

ty!
xergio
S3 licensed
When you have a huge number of servers... this isn't the best solution... :/ And not the best practice.

Well, I'll think in it.

ty!
xergio
S3 licensed
I've updated my wine and there aren't changes with my problem.

wine 1.1.12, you can't connect after /reinit

grrrr... there are no solution under unix?
xergio
S3 licensed
mmm ok, I'll try to update the wine version that I'm using now.
xergio
S3 licensed
xergio
S3 licensed
No, forget the insim.

If I send the /reinit via ingame, without any more player, and without insim programs, it fails. I can't re-connect after send /reinit command and I have to kill the process LFS if I want someone can connect again to the server.
Can't connect after /reinit
xergio
S3 licensed
Hi all.

My question is simple. When I send /reinit command, I can't reconnect to the server anymore, this is the log:

$ cat deb.log
May 26 16:42:16 LFS DEDICATED HOST : 0.5Z13
May 26 16:42:16 ?
May 26 16:42:16 ?
May 26 16:42:16 ?
May 26 16:42:16 ?
May 26 16:42:16 ?
May 26 16:42:16 ?
May 26 16:42:16 ?
May 26 16:42:16 ?
May 26 16:42:16 ?
May 26 16:42:16 ?
May 26 16:42:16 ?
May 26 16:42:16 ?
May 26 16:42:16 load bans
May 26 16:42:16 load font
May 26 16:42:16 Could not get device context of LFS window
May 26 16:42:16 create english file
May 26 16:42:16 initialisations
May 26 16:42:16 tables
May 26 16:42:16 load objects
May 26 16:42:16 start intro
May 26 16:42:16 Kyoto Ring
May 26 16:42:16 end of initialisation
May 26 16:42:17 Track loaded
May 26 16:42:24 Send Track : 212.163.4.98
May 26 16:42:24 Send Track : 212.163.4.98
May 26 16:42:24 Connect : 212.163.4.98
May 26 16:42:24 A new guest is connecting
May 26 16:42:25 [MCH]BrEaThE^L connected (BriZz^L)
May 26 16:42:29 Host will restart in 3 seconds
May 26 16:42:32 TCP Socket : bind failed
May 26 16:42:32
May 26 16:42:32 Track loaded

As you can see, there is a "TCP Socket : bind failed" at the end. This message appears 3 second after the /reinit command, as log says.

What is the problem? How can I fix it? Am I doing something wrong?

What I want to do is just to restart the server (via InSim), but I got the same issue when I send it ingame as Admin.

The only way to connect again is a hard-restart of the process, killing it... (linux host).

Software version: LFS_S2_DEDI_Z13

ty!
FGED GREDG RDFGDR GSFDG