Jump to content
SSForum.net is back!

Recommended Posts

Posted (edited)

Hello,

 

For the upcoming new statistics website I want to create a directory client in PHP. I already have a directory client in Java but running a java program from a PHP script isn't the most efficient and in this case the performance (or more specifically, the time of execution) is important.

 

This is what I have so far. You can see I have followed the program structure of the PHP ping client by GoldEye (more or less).

 

-- snip snap, see attachment below --

 

 

I haven't done much socket programming in PHP so this piece of code isn't working as it should. Basically, I need to make sure I'm going the right path.

 

Given the following protocol and D1st0rt's protocol packets, can someone help me with the correct format parameters of the PHP pack method?

 

CLIENT 								SERVER
------------------------------------                            --------------------------------------------------
Encryption request 		0x01	------->
					<------ 	0x02 Encryption response
Server list request (reliable)	0x03	------->	
Synchronization request		0x05	------->
					<------		0x03 Reliable Packet
Reliable ACK			0x04	------->
					<------		0x0E Cluster

					<------		0x03 Reliable Packet (contains 0x0A Massive Chunk)
Reliable ACK			0x04	------->                (0x03 is received multiple times for the complete server list)

Disconnect			0x07	------->
					<------		0x07 Confirm Disconnection

 

For example, the Encryption request packet I need to send contains 0x00, 0x01 (type byte), client encryption key of 4 bytes and 2 bytes for the protocol version (0x00 and 0x01). Right now I have this done with

$out=pack("vvVvv",0x00,0x01,$clientkey,0x01,0x00);

but I doubt this is correct.

 

Which format parameter do I need to use for packing 4 bytes? an unsigned short (v) or an unsigned long (V)?

Edited by Maverick

Check out your zone population statistics at stats.sshq.net!

 

 

Maverick

Subspace Statistics Administrator

Retired SSCU Trench Wars Super Moderator

TWCore Coordinator Administrator

Posted (edited)

 

For example, the Encryption request packet I need to send contains 0x00, 0x01 (type byte), client encryption key of 4 bytes and 2 bytes for the protocol version (0x00 and 0x01). Right now I have this done with

$out=pack("vvVvv",0x00,0x01,$clientkey,0x01,0x00);

but I doubt this is correct.

 

Which format parameter do I need to use for packing 4 bytes? an unsigned short (v) or an unsigned long (V)?

 

You want this

$out=pack("CCVCC",0x00,0x01,$clientkey,0x01,0x00);

or

$out=pack("vVv",0x0001,$clientkey,0x0100);

 

http://php.net/manual/en/function.pack.php

 

C = 1 bytes (byte)

v = 2 bytes (short)

V = 4 bytes (long)

Edited by doc flabby

Rediscover online gaming. Get Subspace.

Owner of the PlaySubSpace Network (level 0 BanG) and PSSF server

  • 3 weeks later...
Posted (edited)

I've completed the script. Attached is the script for anyone to use.

 

These are the test results :

 

Offline testing [Windows Vista x64]

Catid's server : success

Snrrrubs directory server : success

Doc Flabby's Central : fail (no response after sending 0x01 encryption request, although directory server does receive it)

 

 

Online testing

sscentral.sscuservers.net : [offline]

sscentral.com : success

ssdir.playsubspace.com : fail

nanavati.net : fail (does connect but only receives one reliable message then receives 0x07 disconnection)

ds1.krslynx.com : success

 

It's weird that the directory server at nanavati.net doesn't work, offline testing on Snrrrub's server works fine.

Unfortunately sscentral.sscuservers.net was offline when testing so the most important directory server couldn't be tested.

Note the script doesn't use any encryption. Sending a client key on the encryption request of 0 accomplishes this.

 

Requirements: php_sockets module enabled

directoryclient.php

Edited by Maverick

Check out your zone population statistics at stats.sshq.net!

 

 

Maverick

Subspace Statistics Administrator

Retired SSCU Trench Wars Super Moderator

TWCore Coordinator Administrator

Posted (edited)

With a small modification (making the script identify itself as a Continuum client instead of a Subspace one) Doc Flabby's directory server works :clapping:

 

These are the test results :

 

Offline testing [Windows Vista x64]

Catid's server : success

Snrrrubs directory server : success

Doc Flabby's Central : success

 

 

Online testing

sscentral.sscuservers.net : [offline]

sscentral.com : success

ssdir.playsubspace.com : success

nanavati.net : fail (Continuum client and Snrrrubs directory server are also having trouble dowloading from it so I guess it's not working as it should or contains no zones)

ds1.krslynx.com : success

 

You can view the current online directory servers at http://directoryservers.sshq.net

 

Update 29-june-2010: SSCentral has come back online and has successfully been tested.

directoryclient.php

Edited by Maverick

Check out your zone population statistics at stats.sshq.net!

 

 

Maverick

Subspace Statistics Administrator

Retired SSCU Trench Wars Super Moderator

TWCore Coordinator Administrator

Posted

you could now make a zone list from the directory responses, then use your tw stats experience to make zone population graphs...

 

would be unprecedented

SSC Distension Owner
SSCU Trench Wars Developer


3:JabJabJab> sometimes i feel like when im in this mood im like a productive form of Cheese
Dr Brain> Pretty much everything you said was wrong. Except where you called me a lazy jerk with no time. That was true.
3:KrynetiX> do you ever open your web browser and type ?go google
5:Ceiu> Wow. My colon decided that was a good time to evacuate itself.

Posted

Note the script doesn't use any encryption. Sending a client key on the encryption request of 0 accomplishes this.

 

Requirements: php_sockets module enabled

 

IIRC think prittks directory server only works with encryption turned on :clapping:

Rediscover online gaming. Get Subspace.

Owner of the PlaySubSpace Network (level 0 BanG) and PSSF server

Posted
It generates invalid resource errors when calling socket_close(x) at line 85 if it fails to reconnect after the first time. You could cheat and check to see if it's a valid resource (is_resource(x)) before attempting to close it, but that doesn't really address the issue and defeats the purpose of trying to reconnect. Other than that, kudos on the work.
Posted

Another update due to a major bug I discovered.

If the Directory Server sends the response in a 0x0E cluster, the containing 0x0A Huge Chunk (encapsulated in a 0x03 Reliable message) is the tail of the resulting zone list. The packet protocol does mention this but I didn't take notion of it while making the directory client because I didn't fully understand the note. I modified the directory client to handle this tail correctly.

directoryclient.php

Check out your zone population statistics at stats.sshq.net!

 

 

Maverick

Subspace Statistics Administrator

Retired SSCU Trench Wars Super Moderator

TWCore Coordinator Administrator

Posted

Another and hopefully the last update.

 

This time another necessary bugfix as the script malfunctioned now and then. Sometimes the directory server doesn't respond/receive the acknowledgement packet it is send, resulting in the directory server resending a Huge Chunk packet. The PHP Directory client script didn't handle this properly and just concatenate the (duplicate) huge chunk data to the buffer, resulting in a corrupted server list.

I've modified the script to properly handle huge chunk packets that are received more then once by putting all the huge chunk packets in an array using the ACK id of the reliable packet as key.

 

From now on the script will be released as a command-line script and a web-script (one that can be executed in the browser).

If you compare the two, you'll notice that the only difference is how the scripts receive the arguments from either the command-line or a GET parameter.

 

Have fun.

directoryclient-cmd.php

directoryclient-web.php

Check out your zone population statistics at stats.sshq.net!

 

 

Maverick

Subspace Statistics Administrator

Retired SSCU Trench Wars Super Moderator

TWCore Coordinator Administrator

  • 1 month later...
Posted

IIRC think prittks directory server only works with encryption turned on :blink:

Unfortunately Doc Flabby is correct and sscentral.sscuservers.net doesn't support the unencrypted communication. Hopefully I can port the (subspace) encryption from my Java client to the PHP script. If someone can help me or give me some tips, please do :lol:

 

 

PS. Doc Flabby, if you read this, your directory server isn't working anymore. It's online but it stops sending the zone list after it has send 22% of it.

Check out your zone population statistics at stats.sshq.net!

 

 

Maverick

Subspace Statistics Administrator

Retired SSCU Trench Wars Super Moderator

TWCore Coordinator Administrator

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...