[PHP] Clientless Silkroad Security + ServerStats

06/14/2011 06:18 pushedx#1
Short and sweet: this project allows you to have native server stats via PHP without having to use an external program to collect the server stats.

In other words, everyone should be able to host their own server stats on their site as long as they have a capable web server. I've tested locally and on a remote host, so it should be fine with most modern hosts. Unfortunately, as tricky as this code was to write, there is nothing that can be done if your server does not support all the components.

This is a bare minimal release, so you will need some web designing skills to make it look "pretty" or additional php/database skills to enhance it more.

readme.txt
Quote:
[PHP] Clientless Silkroad Security + ServerStats
pushedx

Please read "license.txt" first!

This is a native PHP port of my Silkroad Security API.
Included is a fully functional ServerStats example.
To use, your server must support: PHP, Sockets, BCMATH, and MCRYPT.
If your server does not support or allow use of all components, you cannot use this code.

To customize the ServerStats script, you must know PHP, HTML/CSS/etc.., and optionally database programming (MySQL/MSSQL).

*** No support will be provided for ServerStats customization. ***

To test ServerStats:

0. Demo "http://edxlabs.web44.net/rsro". This is a free host, so it might be down time to time...
1. Upload all *.php files to a folder on your website.
2. Access "index.php" in that folder (you might need to update the hard-coded version if it changes).

IMPORTANT: You will probably want to set file permissions or add additional security restrictions to the scripts to prevent any abuse. I cannot help you with this, but it should be looked into.

To use ServerStats:
1. Read and follow "examples.txt".
2. Open "index.php" and read through the concepts.
3. To understand what goes on behind the scenes go through "ServerStats.php".
4. For everything else, refer to the rest of the php files code.
Just a helpful hint: if you wonder how to "loop" updates, take a look into CRON jobs (your web host must support them!). If not, you will have to come up with another solution (such as using a program that always runs to force the refresh).

Also, using these concepts, you can use this code for other games and projects in a similar fashion! PHP is quite capable afterall.

Enjoy! :)

Troubleshooting:

Make a test page with the following code:
Code:
<?php
	phpinfo();
?>
Upload the page, run the script, and save the results. Delete the page afterwards.

Q. Why do I see an empty page when I try to use the server stats?
A. This usually means a needed php component is not there. Check for the following strings in "Configure Command": '--enable-sockets', '--with-mcrypt=', and '--enable-bcmath'.

Look for each section in the configuration. It should look something like the following.
BCMath: [Only registered and activated users can see links. Click Here To Register...]
mcrypt: [Only registered and activated users can see links. Click Here To Register...]
sockets: [Only registered and activated users can see links. Click Here To Register...]

Q. Can more/less debugging information be provided for PHP errors?
A. In short, no. It all depends on how PHP is configured and most hosts are really restrictive to changes made to PHP. Unless you are running your own server where you can reconfigure PHP!

Q. What do the different errors mean?
A. Most errors should be self descriptive. Try to search the text in the php files to see what they are associated with.

Q. I get a bunch of MCRYPT warnings when trying to run the stats?
A. Please see [Only registered and activated users can see links. Click Here To Register...].

More Q/A will be added as they arise.
06/14/2011 08:39 * White *#2
i got this.
Code:
Array ( [0] => [1] => Warning: mcrypt_ecb() [function.mcrypt-ecb]: Attempt to use an empty IV, which is NOT recommend in /var/site/test/SilkroadSecurity.php on line 174 [2] => [3] => Warning: mcrypt_ecb() [function.mcrypt-ecb]: Attempt to use an empty IV, which is NOT recommend in /var/site/test/SilkroadSecurity.php on line 134 [4] => [5] => Warning: mcrypt_ecb() [function.mcrypt-ecb]: Attempt to use an empty IV, which is NOT recommend in /var/site/test/SilkroadSecurity.php on line 231 [6] => [7] => Warning: mcrypt_ecb() [function.mcrypt-ecb]: Attempt to use an empty IV, which is NOT recommend in /var/site/test/SilkroadSecurity.php on line 231 [8] => Error [9] => The version packet was rejected because the GatewayServer is closed. [10] => 
 [11] => )
06/14/2011 09:45 pushedx#3
Quote:
Originally Posted by White&Black View Post
Warning: mcrypt_ecb() [function.mcrypt-ecb]: Attempt to use an empty IV, which is NOT recommend in /var/site/test/SilkroadSecurity.php on line 174
Warning: mcrypt_ecb() [function.mcrypt-ecb]: Attempt to use an empty IV, which is NOT recommend in /var/site/test/SilkroadSecurity.php on line 134
Warning: mcrypt_ecb() [function.mcrypt-ecb]: Attempt to use an empty IV, which is NOT recommend in /var/site/test/SilkroadSecurity.php on line 231
Warning: mcrypt_ecb() [function.mcrypt-ecb]: Attempt to use an empty IV, which is NOT recommend in /var/site/test/SilkroadSecurity.php on line 231
This is due to how mcrypt is configured on your host.

You can try to add an "@" right before the 'mcrypt_ecb' function name on lines 134, 174, and 231. That is a PHP directive to suppress warning messages. The changed code would look like:
Code:
134:
$expected_challenge_key = @mcrypt_ecb( MCRYPT_BLOWFISH, bcbytearray( $this->key_array, 8 ), swap( bcbytearray( $expected_challenge_key, 8 ), 8 ), MCRYPT_ENCRYPT );

174:
$this->m_client_key = @mcrypt_ecb( MCRYPT_BLOWFISH, bcbytearray( $this->key_array, 8 ), swap( bcbytearray( $this->m_client_key, 8 ), 8 ), MCRYPT_ENCRYPT );

231:
$packet_payload_tmp = @mcrypt_ecb( MCRYPT_BLOWFISH, bcbytearray( $this->m_handshake_blowfish_key, 8 ), $packet_payload_tmp, MCRYPT_ENCRYPT );
Quote:
Error
The version packet was rejected because the GatewayServer is closed.
That's the real error message, although the warning messages would mess up the output parsing.

Also, what version of PHP is your host running? You can use the [Only registered and activated users can see links. Click Here To Register...] function in a script to find out.
06/14/2011 13:10 LastThief#4
may i know what is this ?

Quote:
Array ( [0] => Error [1] => No host set. )
06/14/2011 13:58 * White *#5
thirst when i added all files i get
Quote:
Quote:
Originally Posted by LastThief View Post
Array ( [0] => Error [1] => No host set. )
this. Later i do somthing and get The version packet was rejected because the GatewayServer is closed.

i using gamerzcorp.com hosting
06/14/2011 14:15 bootdisk#6
lol how long have it been? a week? xD
awesome work pushedx!
06/14/2011 16:35 Kape7#7
This is totally awesome.
rayko just told me that he loves you XD
Now we can get rid of the 24/7 running PC with the stats for our site and run it directly on the webhost! No words for this.
[Only registered and activated users can see links. Click Here To Register...]

Testing... soon telling the results.
<3
06/14/2011 17:13 * White *#8
Quote:
Originally Posted by Synx7 View Post
This is totally awesome.
rayko just told me that he loves you XD
Now we can get rid of the 24/7 running PC with the stats for our site and run it directly on the webhost! No words for this.
[Only registered and activated users can see links. Click Here To Register...]

Testing... soon telling the results.
<3
it working on gamerzcorp.com host? Good for you :D

Quote:
Originally Posted by prot3ctor View Post
Array ( [0] => Error [1] => A connection could not be established. )
same here
06/14/2011 17:14 prot3ctor#9
Array ( [0] => Error [1] => A connection could not be established. )
06/14/2011 17:19 Kape7#10
[Only registered and activated users can see links. Click Here To Register...]

Works fine so far, I had to hide some warnings, but overall is awesome <3
06/14/2011 17:28 * White *#11
Quote:
Originally Posted by Synx7 View Post
[Only registered and activated users can see links. Click Here To Register...]

Works fine so far, I had to hide some warnings, but overall is awesome <3
[Only registered and activated users can see links. Click Here To Register...]

why this bad ?.
06/14/2011 17:34 Kape7#12
Quote:
Originally Posted by White&Black View Post
[Only registered and activated users can see links. Click Here To Register...]

why this bad ?.
The way it works actually its pretty unstable. We have the statistics program running on my home computer 24/7 (doesn't matter at all since I normally left my PC running 24/7 even when the website didn't exist).
Well, the stat program generates a .txt files with the stats, we have another script running every 3 secs gathering the stats from my PC and storing them into the DB. Then, when an user check the capacity page, the php script takes the capacity from the DB and shows to the user. The problem is that this process takes around 10 secs, so the end-user will get statistics from 10 seconds ago as max, which is not very accurate, and also there are some times when I have to restart my PC, so the stats are static for 2 mins or so.
We planned to buy an VPS for the statistics tools the next month, but with this new script we can save that and run the stats directly on the web host.
[Only registered and activated users can see links. Click Here To Register...]
^The stat tools from klevre.
06/14/2011 19:53 inv123#13
My only prob that suddenly after some changes stats changed to ratios, hehe
06/14/2011 20:00 vorosmihaly#14
Quote:
Originally Posted by inv123 View Post
My only prob that suddenly after some changes stats changed to ratios, hehe
as far as I know,isro has a different structure in that packet and it doesn't send the actual number of people,it just sends the percent..so that's why,I really think so^^
06/14/2011 20:13 theonly112#15
Impressive as always.