The online racing simulator
InSim + PHP - How to build, send and receive packages
Hi there... I am actually trying to understand how I can build, send and receive InSim-Packages, but I actually do not even know how to send an InSimInit-Package.

I would be very pleased about some basic help and maybe a simple sample script to show how to send an InSimInit-Package.

Thanks in advance for your help, it's much appreciated.


Greets, Stalker
I think you can't send packages using php? Or am I wrong?
#3 - filur
do I have to use a separate input-server? I only have php 4 and it would be great if it would also work with this version... thanks again for your help anyway.
#5 - filur
Quote from St4Lk3R :do I have to use a separate input-server? I only have php 4 and it would be great if it would also work with this version... thanks again for your help anyway.

Yes, you need to open a server socket for LFS to respond to.

It'll all work in PHP4 as well, just not the same commands, maybe a few more lines. PHP5 has been out for quite some time now (years), maybe it's time to upgrade?
well... I do not find anything anywhere, so i'll ask here: how can I set up a listening port in php4? sorry for the noob question and I know that you are not an approved substitute for my brain, but I really have a blackout right now... thanks in advance again.
#8 - filur
Quote from St4Lk3R :well... I do not find anything anywhere, so i'll ask here: how can I set up a listening port in php4? sorry for the noob question and I know that you are not an approved substitute for my brain, but I really have a blackout right now... thanks in advance again.

Look up socket_create(), socket_listen(), socket_create_listen(), fsockopen() is for connecting to a destination, not listen for incoming connections.

I do however remember a major hassle with PHP 4's sockets, major problems with not being able to run them fully non-blocking (atleast on windows), meaning a read operation won't instantly complete if there's nothing to read, it will need to wait for something to read, or wait for a timeout (atleast 1 second iirc), halting your script.

If you for some reason don't want to upgrade your 'global' php installation, why not set up a PHP 5 package for just this project? Streams are so much simpler.
Quote from filur :You're incredibly wrong.

I'm incredibly ashamed. :sorry:
But now I know I can try some stuff with that
Quote :
If you for some reason don't want to upgrade your 'global' php installation, why not set up a PHP 5 package for just this project? Streams are so much simpler.

I have a confixx-Installation on my Rootserver and can not setup a php5-package for this purpose because php is running as an apache module and not as CGI-version.

Big thanks to you all, I now really understand what I have to do.

Let's go coding

Bye, Stalker
Quote from St4Lk3R :I have a confixx-Installation on my Rootserver and can not setup a php5-package for this purpose because php is running as an apache module and not as CGI-version.

Which is kind of exactly why you should install a separate setup for this, you really don't want to run this under apache.
Quote from filur :Which is kind of exactly why you should install a separate setup for this, you really don't want to run this under apache.

As your web host will kill you if it's not dedicated box for you and you alone. Unless your host is really cool, but thats really rare.
It is a dedicated box for me alone, but why shouldn't I run this under apache?
because you can't?

(at least it seems like this)
Quote from St4Lk3R :It is a dedicated box for me alone, but why shouldn't I run this under apache?

Because it has nothing to do with webserving, talking to insim is not a 1-second-operation thing - you want the script to run for hours.

You'd probably want a console for printing debug messages, you'd probaby want to be able to stop a script without having to wait for apache to finally kill the thread after x amount of time, etc.
Quote :
Because it has nothing to do with webserving, talking to insim is not a 1-second-operation thing - you want the script to run for hours.

I don't want it... I only want to have a nice little webinterface for my LfS Servers with the small functionality start, stop, restart, status and maybe a little webftp using the ftplib.

By the way, I have a problem with the socket_*-functionality of php.
When I try to send a VER-Request to the server, I can't receive the answer on the created listening socket.

Source of my LfS-Class:
http://www.stalkernet.info/sou ... classes/scmslfs.class.php

Error Message:
http://www.stalkernet.info/ruunv3/lfsconn.php

The third time I have to thank you in advance for your help.
Greets,
Stalker
You might have to accept the connection or something, i moved to PHP 5 rather quickly when i started writing insim stuff.

Check out socket_accept()
I tried that earlier and now tried it again, but the script times out.
There does not seem to be an answer from the lfs-server, but I'm sure I set the right port to answer to...

[EDIT]

Well, I didn't. After some thinking I found out that I have to decrement the port value again... I incremented it after trying to open a listening socket and when the "listener" is at port 30000, LFS will send replys to port 30001 and so on. thanks all for your help anyway. the class will later be released to the public.
Quote from St4Lk3R :... [T]he class will later be released to the public.

I hope so, I'm making quite a few plugins for it. I think this could be the AMX Mod for Live For Speed really . Very easy to program for, and very easy to get off the ground.
Quote from St4Lk3R :... I incremented it after trying to open a listening socket and when the "listener" is at port 30000, LFS will send replys to port 30001 and so on. thanks all for your help anyway.

I don't get it, did you stop incrementing it or did you get it working with the exact port you specified? Because LFS will respond to the exact port as sent in the packet.

Quote from Dygear :I hope so, I'm making quite a few plugins for it.

Dumped my code already?

J/k, i think you're confusing St4Lk3R's class with my stuff.
Quote from filur :Dumped my code already?

J/k, i think you're confusing St4Lk3R's class with my stuff.

Oh well. Yea, I did confuse the two. Still, once you post that I'm going to be a happy bunny. .
well here I am again, having the next problem to solve: what pack-type should I use when I want to pack/unpack an int value? I tried it with l, (signed long (always 32 bit, machine byte order)), but that doesn't seem to work (I assume the server ignores bad-encoded packages, because I do not get any answer on my listening socket).

Thanks in advance
I will be making an LFS plugin for an existing php web module for server monitoring on legaue sites. (see sample image below)

The module incudes the network interface to the dedicated server, mysql database storage / integration, as well as a generic php sidebar moduel as described.

Much of the back end code is alreday done, so it shouldn't take a long time for me to finish. The initial release will cover this featureset, with the possibility of expanded features later on.

It will be released under the GNU GPL. Here's a little shot of how it is implemented at my league site (for GTL)

erm... thx for hijacking my thread, it was not requested. if its ready, open another thread, but please stay at topic here. thanks.
Quote from St4Lk3R :erm... thx for hijacking my thread, it was not requested. if its ready, open another thread, but please stay at topic here. thanks.

? You are asking for help and I tell you that I will hand you a solution. You then tell me to get out of your thread? illepall

In case you don;t know, releasing it under the GPL means that you can take my code and do what you like with it.


To answer your question more directly, the data may need to be packed. I say "may" because I am only now begining to look at insim, though the interface to other sims usually work in a similar manner. So, give this a try:

So, where $command is the packet being sent to the server, encoding the data might look like this. The quoted digits is a string of the required characters which need to be encoded. (FYI, this is the signature of a GTL direct to dedicated server "send me a status packet" comand):



# HEX signature fot the GTL search packet
$command = pack("H*",'47544c5f4469726563745f49505f53656172636800');


FGED GREDG RDFGDR GSFDG