The online racing simulator
PHPInSim
(96 posts, started )
PHPInSim
C:\Documents and Settings\Dygear\Desktop\PHPInSim>php InSim.php
Listen socket created!
Binded to listen socket!
Send socket created!
Conneceted to send socket!
¶☻☺ 0.5Y S2 ♦ ∟♣ Ç?Ç♀ ☺ ♣ KY1 ☺♦♥ (
☺ SimFIA : InSim ∟♣ Ç?Ç♫ ☺ ♣ KY1 ☺♦♥ §ê♂ Tr
ack loaded
∟♣ Ç?ÇN ☺☺ ♣ KY1 ☺L§ ☺
I♠^1(E^7AGL^4E)^7Dygear Dygear BF1 BMWSauber_NH-16 ♥♥♥♥ ☺ $$ ☺☺
∟◄ ♣ ☺ KY1 ☺# · ▲ u ****∟♣ Ç?üN♥☺☺☺ ☺ ♣ KY1
☺♦♥ ►↓ ☺ΣH ΣH ☺ ♦♥ ¶↑ ☺2¢ 2¢ ☺ I♠ ►↓ ☺Ä+ └╞ ☺ ♦♥ ¶↑ ☺░| Γ↨☺ ☻
I♠ ►↓ ☺╩+ ¼C☺ ☺ ♦♥ ¶↑ ☺d} Fò☺ ♥ I♠ ♦♥ ►↓ ☺└+ ♠┴☺ ☺ ¶↑ ☺~| ─◄☻ ♦
I♠ ♦♥ ►↓ ☺$, Φ=☻ ☺ ¶↑ ☺2} ÷Ä☻ ♣ I♠ ¶" ☺÷Ä☻ ~| ♣ I♠∟♣ Ç?üN♥☺☺☺
☺☺ ♣ KY1 ☺T# ☺Dygear ^1(E^7AGL^4E)^7Dygear Dygear BF1 ÷Ä
☻ ~| ☻ ♣ I♠ ☺ ê♂ ^1(E^7AGL^4E)^7Dygear^8 finished
♦♥ ☺
☺☻

Yeah, I know, it's kinda dirty and raw for the moment. But it works, it's open source, it's for everyone to use and I will continue work on it.

If anyone wants to post this code to the LFS Wiki on how to connect to InSim with PHP5, please do.


<?php 
php

/*
** @package   PHPInSim.
** @since     2008-02-23 17:10 EST.
** @author    Mark 'Dygear' Tomlin.
** @license   MIT License (http://opensource.org/licenses/mit-license.php).
** @copyright Copyright (C) 2008, Mark 'Dygear' Tomlin.
** @version   0.2.1
*/

$InSim = new InSim();

class 
InSim {
    private 
$skIn;
    private 
$skOt;
    private 
$time;

    function 
__construct($AdminPass ''$Address '127.0.0.1'$Port 29999$PreFixChar '!') {
        
// Socket In;
        
if ($this->skIn socket_create(AF_INETSOCK_DGRAMSOL_UDP)) {
            echo(
'Listen socket created!' PHP_EOL);
            if (
socket_bind($this->skIn$Address$Port 1))
                echo(
'Binded to listen socket!' PHP_EOL);
            else
                die(
'Could not bind to listen socket, address or port!' PHP_EOL);
        }
        else
            die(
'Could not create listen socket!' PHP_EOL);
        
        
// Socket Out;
        
if ($this->skOt socket_create(AF_INETSOCK_DGRAMSOL_UDP)) {
            echo(
'Send socket created!' PHP_EOL);
            if (
socket_connect($this->skOt$Address$Port))
                echo(
'Conneceted to send socket!' PHP_EOL);
            else
                die(
'Could not connect to send socket, address or port!' PHP_EOL);
        }
        else
            die(
'Could not create send socket!');
        
        
// Connect To InSim;
        
$this->send(pack('CCCxSSxCSa16a16'4411$Port 18360$AdminPass'phpInSim'));
        
$this->main();
    }
    
    function 
send($packet) {
        return 
socket_write($this->skOt$packetstrlen($packet));
    }
    
    function 
main() {
        while (
TRUE) {
            
// Keep Alive;
            
if (time() > $this->time) {
                
$this->send(pack('CCCC'4300));
                
$this->time time() + 30;
            }
            
// Get Packet;
            
if ($data $this->recv()) {
                
print_r($data);
            }
        }
    }
    
    function 
recv() {
        return 
socket_read($this->skIn256PHP_BINARY_READ);
    }
    
    function 
__destruct() {
        
$this->send(pack('CCCC'4302));
    }
}

?>

WOW....Nice work Dygear.
Thanks, but this is just the working release, just to get something and get an idea of who wants to use it. The plugin system is what is going to make or break this addon. I'm very very excited on what can be done with this, just given the time. While I've not started on that yet, it should be in the release after next.
How Do I Use it, sorry for being so noob!
Quote from Eclipse2000 :How Do I Use it, sorry for being so noob!

iirc, you need php installed and call it from the command line. Open notepad, copy that code, save it as "insim.php" or something. Then copy it to php directory. then call it from command line something like..... php.exe insim.php


that "should" work from my limited knoledge...
Yeah, that should do it. I will post a zip file soon that will have all of the required files to run the program.

Just working on the Constants.php file right now ... That's gonna be a HUGE file. Once that's over with I have to build some functions based off that. Then the next release will allow for much easier use of the packets.
Looks pretty good man. Ill keep my eye on this thread and possibly use this to start learning php once it gets a bit more advanced. Could help me a lot.
I might just take a step back for a minute, as I kinda went into this head first.

What I am trying to achieve here is basically AMX Mod X for Live For Speed. The fantastic thing about AMX Mod was that you could really simply make plugins that gave you compleat control of your environment within the Counter-Strike engine. While I can't quite make it to that same level here, I can at lest make it easy for other people to make plugins for Live For Speed's InSim system.

So, with that said, write me a plugin and I'll make the interface for it.
Quote from Dygear :What I am trying to achieve here is basically AMX Mod for Live For Speed.
....
I can at lest make it easy for other people to make plugins for Live For Speed's InSim system.

I'll wish you luck with that If you can expose the LFS insim packets without actually referring to them as events, or packets, then I applaud you

Quote from Dygear :So, with that said, write me a plugin and I'll make the interface for it.

Ok, the first idea that I've been meaning to work on, but not gotten time to even think about properly, was a simple (non-images) HTML to LFS button renderer. The idea behind this was a simple & dynamic welcome screen.

Then again, a simple welcome screen plugin where you set a message would be a very simple plugin to do..

Are you after someone writing the plugin with our ideal API, or did you just want the idea?
Karl, wouldnt this be in the same boat as the program you told me about on msn last week sometime?
Quote from mcgas001 :Karl, wouldnt this be in the same boat as the program you told me about on msn last week sometime?

Yup, only this is restricted to PHP, where as the one I was talking to you about was based around compiled languages, which means that you could potentially use a number of very different languages to plug into it, or even extend it.
I've been thinking long and hard about the system for the packets. And I'm still not sure how I would like to handle them. It might be best to handle them as the methods inside of a packet class, or each of them as there own class, or just individual functions. However, with the individual functions, there is really no good way to then take that into a plugin systems. I don't know, the definion for each packet is done, but the defines also have to be in place. God there is alot of work ahead of me.
Quote from Dygear :I've been thinking long and hard about the system for the packets. And I'm still not sure how I would like to handle them. It might be best to handle them as the methods inside of a packet class, or each of them as there own class, or just individual functions. However, with the individual functions, there is really no good way to then take that into a plugin systems. I don't know, the definion for each packet is done, but the defines also have to be in place. God there is alot of work ahead of me.

Why not have a "settings.php" file - which has a list of "fires"...

And when you add a new plugin, it adds to the list of "fires".
The fires could like "EXECUTE ON NCN FUNCTION plugin_name_send_welcome($conn, $uname, $pname)"

Or something.... Then whenever the class fires its built-in functions for the NCN packets, it fires the plugin_name_send_welcome function too?
hmm could be handy for making a web-based server control...
Quote from G. Dierckx :hmm could be handy for making a web-based server control...

I've already got one, and LTC runs off PHP.

I'm tempted to release the web-control for LFS. I'll tidy up the code a bit, and make a few options - and then maybe I shall
Quote from Krammeh :I've already got one, and LTC runs off PHP.

I'm tempted to release the web-control for LFS. I'll tidy up the code a bit, and make a few options - and then maybe I shall

Well if u want to i'm making for my own a php lfs server script for my dedicated server. It can add & remove lfs servers (all installed as services) and stop start them... just a base...
Grew tired of waiting, eh?
Well, as i'm just getting to grips with PHP after making the new Adaptive site, i'm very interested to see where this leads...
Quote from filur :Grew tired of waiting, eh?

Yeah, and it's really to bad, as I love what lurLFSd is, and the fact that it still works kills me seeing as you have seemed to have stoped all support for it (update.php no longer works, and at that point I saw it as a dead project, thus started brainstorming for this). So, do tell, is lurLFSd dead?

Quote from Krammeh :Why not have a "settings.php" file - which has a list of "fires"...

To rigid, I want people to drop plugins into the /plugins directory, and that should be all of the editing they need to do. I might also consider a plugins.ini file (like AMXMod) that would allow some plugins to control other plugins, with special return values.
Plugin Style
Here's my idea of what a plugin could look like. What style would you use?


<?php 
php

class myPluginName {
    public function 
register_plugin() {
        
$this->name 'Simple Example Plugin';
        
$this->author 'Mark \'Dygear\' Tomlin';
        
$this->version '0.Example1.1';
        
$this->functions = array(
            
'client_connect' => array('ISP_NCN'),
            
'client_sectors' => array('ISP_SPX''ISP_LAP')
        );
    }
    public function 
client_connect($packet) {
        
// This function fires when NCN packets are received.
        
extract($packet); # Extends the packet data into symbol table.
        /*
            Here's some of the different ways to setup & handle
            sending packets from with in your own functions.
            Still, have to program this, but this is the plan.
        */
        // Setup Option 1 - OOP, But Long.
        
$MSO = new MSO();
        
$MSO->UCID $UCID
        $MSO
->PLID $PLID
        $MSO
->UserType MSO_USER;
        
$MSO->Msg "Welcome to the Race, {$PName}^9 ({$UName})!"
        
// Setup Option 2 - Array, Fast, and Short, but Ugly.
        
$MSO = new MSO(array(
            
'UCID' => $UCID,
            
'PLID' => $PLID,
            
'UserType' => MSO_USER;
            
'Msg' => "Welcome to the Race, {$PName}^9 ({$UName})!"
        
);
        
// Setup & Send Option 3 - OOP, Arrays and it's own send method built in!
        
MSO::send(array('UCID' => $UCID'PLID' => $PLID'UserType' => MSO_USER'Msg' => "Welcome to the Race, {$PName}^9 ({$UName})!");
        
/*
            As You've Seen The send function was included in the last Option.
            But the other two, did not. There are two ways to handle this in PHPInSim.
        */
        // Send Option 1 - We could send the packet to the user, via the packet's own Method.;
        
$MSO->send();
        
// Send Option 2 - Send as a part of the main InSim class.
        
$InSim->send($MSO);
    }
    public function 
client_sectors($packet) {
        
// This function fires when both SPX, and LAP packets are recived.
        
extract($packet); # Extends the packet data into symbol table.
        
if ($Size == ISP_LAP)
            
$Time $LTime;
        else if (
$Size == ISP_SPX)
            
$Time $STime;
        else
            return;
        
$Time $InSim->ConvertMS2String($Time); // 33000 = 33.00 or 144530 = 2:24.53
    
}
}

?>

My mind is out for the count, so there might be errors in there, thus. I am going to sleep now. I shall explain more about this later.
If you put the plugins into a ./proxy/plugins type dir, would you really need the register_plugin func? The .ini file can hold this info, and be read from there at start-up or manually invoked with a command to the proxy script.

From your example it looks like every plugin would have to extract every packet? Maybe instead of the current stuff in the register_plugin, you could send which events (packets) that plugin wants to subscribe to. If a table is kept of all of these, the proxy script could look it up and pass on only the relevant packets. Maybe the proxy script could also have an api of custom events and funcs that all plugins could use. E.g., maybe a send func. It could receive a packet, make sure its content matches the type and is a valid packet, then send it off.
Quote from NotAnIllusion :If you put the plugins into a ./proxy/plugins type dir, would you really need the register_plugin func? The .ini file can hold this info, and be read from there at start-up or manually invoked with a command to the proxy script.

But, I want people to just drop there plugins into the plugin directory and away they go. Not editing files, no configuration should be needed. Plug and Play.

----

I used the extract function from PHP. With out the extract function the code would look like this.


<?php 
public function client_sectors($packet) {
    if (
$packet['Size'] == ISP_LAP)
        
$Time $packet['LTime'];
    else if (
$packet['Size'] == ISP_SPX)
        
$Time $packet['STime'];
    else
        return;
    
$Time $InSim->ConvertMS2String($Time);
}
?>

Quote from Dygear :is lurLFSd dead?

It's alive and well (stable), not much progress in the last few months tho. Updating should work, server is back up since yesterday after a few days downtime (short circuited PSU :arge.

We'll just have to write wrappers so our plugins can run cross-program.
Quote from filur :It's alive and well (stable), not much progress in the last few months tho. Updating should work, server is back up since yesterday after a few days downtime (short circuited PSU :arge.

We'll just have to write wrappers so our plugins can run cross-program.

Anywhere i can download it(LurLFS)?
Quote from filur :It's alive and well (stable), not much progress in the last few months tho. Updating should work, server is back up since yesterday after a few days downtime (short circuited PSU :arge.

We'll just have to write wrappers so our plugins can run cross-program.

... I hate you, and love you! Please for the LOVE OF GOD, RELEASE IT! Like today, not just today I mean like RIGHT NOW.

PHPInSim
(96 posts, started )
FGED GREDG RDFGDR GSFDG