SRCDS Steam group


Useful scripts for a web server
#1
Using a french tutorial about PHP requests to a source server, I've made several scripts for my server's website, Geekzone TF2 Server News.

I thought you'd like to use those scripts, so here they are.
Download http://www.coldfire.info/tf2/ressources/scripts.zip or the one attached to this post.

EDIT: Also take http://www.coldfire.info/tf2/ressources/fonts.zip and extract the fonts to a "fonts" subfolder (same level as "images"), so you have for example:
/tf2/
/tf2/images/
/tf2/images/maps/
/tf2/fonts/
/tf2/*.php
END EDIT


In this zip archive, you'll find:

- testonline.php: quick script which fast checks if your server is online/offline
- tf2info8.php: script which generated a status image. You use it in a html page like this:
PHP Code:
<img src="http://your.url.here/path/tf2info8.php"
- tf2map.php: You can using it with a php include in a html page. Displays a screenshot of the currently played map.
- tf2mapcycle.php: Give it the path to your server's mapcycle.txt, it just displays it. (do a php include)
- tf2maplist.php: Again, do an include. Displays installed maps list with a screenshot for everyone of them.
- tf2nextmap.php: Ask the source server with rcon le serveur to get the content of the sm_nextmap CVAR (you need sourcemod), so it tells which is the next map
- tf2players.php: Displays currently connected players list with their score, ordered by scores descending
- userbardynamic.php: same thing as tf2info8.php but return a userbar image. For example: [Image: userbardynamic.php]
- userbarstatic.php: For the forums which don't accept dynamic images, generated a png file on the server, named tf2userbar.png, so you can have a "not so dynamic" userbar in your signature. You need to crontab the execution of this script (for example every minute)
- an images folder which has the images used in my scripts tf2info8.php and userbar*.php
- a subfolder of images, named maps, which has screenshots for around 20 maps .

You can see most of this script running on my TF2 server's blog, Geekzone TF2 Server News.

Have fun!


Attached Files
.zip   scripts.zip (Size: 365.38 KB / Downloads: 433)
.zip   fonts.zip (Size: 70.63 KB / Downloads: 209)
Reply
#2
This looks pretty nice
Join the Source Dedicated Server Support Group on Steam Community!
Source Dedicated Server (SRCDS)
Free to join, Live support! (When available)

http://forums.srcds.com/viewtopic/5114
Reply
#3
Forgot to put the fonts used in the archive, look at my edit in the first post
Reply
#4
Thanks man Smile.
realchamp Wrote:
Hazz Wrote:Has someone helped you on these forums? If so, help someone else
Mooga Wrote:OrangeBox is a WHORE.
Reply
#5
Seems like a lot of good work!
Reply
#6
matafaka Wrote:i can't get this thing to work...
I took a quick peek at the code. It seems there are two major flaws in the code.

The code in tf2players.php reads only one packet from the queried server. The code should read the first packet, then parse from the first packet how many packets there are in total and then receive rest of the packets. The code should also make sure that the packets arrive in the correct order. The code in tf2players.php won't work for servers which have ~32 players (the response packet size grows over 1400 bytes, which will split the response in multiple packets).

Another major flaw is lack of bzip2 decompression. Bzip2 compression in the server replies is relatively new feature (but this script is newer). The compression is used in server rules and player lists. Thus, when the server query script receives a response packet, it should first check whether the response is compressed or not and after that proceed. The code in tf2players.php won't work for servers which use new Source 2007 engine (ie. TF2).

I recommend not to use the server query scripts in this package. The scripts don't work for large CS:S servers or TF2 servers reliably. However there are couple usable scripts in this package, so it's not completely useless. Just be cautious about the scripts which rely on server rules or player lists.

@matafaka
Thanks for sharing your incompetence - or do you want help? Share the error message + elaborate on how it doesn't work and you might get the help you need.
Reply
#7
They work fine, at least they did when I used them for CSS. Maybe now they dont, or whatever. If you "reccomend not to use the server query scripts in this package," maybe you could help by fixing them? Thats more constructive than just saying they dont work.
realchamp Wrote:
Hazz Wrote:Has someone helped you on these forums? If so, help someone else
Mooga Wrote:OrangeBox is a WHORE.
Reply
#8
Spartanfrog Wrote:They work fine, at least they did when I used them for CSS. Maybe now they dont, or whatever.
"At least when I...", "Maybe...", "... or whatever". Dude, this is great uncertainty shining through in your post. Read my previous post. There I tell why the scripts don't work in some cases.

It's unfortunate that the scripts don't work perfectly, but that's how it is.

Spartanfrog Wrote:If you "reccomend not to use the server query scripts in this package," maybe you could help by fixing them? Thats more constructive than just saying they dont work.
Eh.. why don't you fix them? That'd be constructive of you - more constructive than telling me to do it. Really, I took the time to see the code, noticed how they're flawed with the new server engine and pointed out how they should be fixed. Now you tell me that I'm not constructive. What's your problem?

The scripts are extremely simple. "Fixing" them means adding about 3x more code.

I recommend ripping the query code from Psychostats. Stormtrooper has kept the code up-to date and parses all the little pieces of information from the packets. There are couple things in parsing the packets that most coders wouldn't even know how to access them (ie. (Half-Life 1)The lower four bits represent the number of packets (2 to 15) and the upper four bits represent the current packet starting with 0.).

The server query code in Psychostats is in file "includes/PQ/halflife.php". It's GPLv3 so you can rip it under the terms of the license.

However, it seems that even Psychostats is still one step behind. Valve has added "Size of the Splits" in the packet headers, but Psychostats doesn't seem to account for that. It may or may not break compatibility. Nevertheless, it works better than the query script in this thread.
Reply
#9
Quick reply:
- it works for TF2 if you don't use packet compression. I'd have to check that with compression
- about tf2players.php, it works. I read only the first packet since all the players are on this one. It accelerates the reading since it doesn't have to wait for a timeout.
But believe me, for me (on my website, for my 24 players TF2 servers) it works fine

But yes, you could rip the right code from psychostats. And I think it'll be way better coded :p

If someone want to fix all these flaws and post the code, well, thanks!
Reply
#10
ColdFire Wrote:Quick reply:
- it works for TF2 if you don't use packet compression. I'd have to check that with compression
By default TF2 servers use compression. Your script doesn't work with TF2 servers with default settings. Big flaw.

ColdFire Wrote:- about tf2players.php, it works. I read only the first packet since all the players are on this one. It accelerates the reading since it doesn't have to wait for a timeout.
Huh? Have you read the protocol specification: http://developer.valvesoftware.com/wiki/Server_Queries#A2S_PLAYER

Player information is in all packets. There will be multiple packets if the player data doesn't fit into one packet (=1400 bytes). You can't say that the player data is only in the first packet. You can't accelerate processing by retrieving only the first packet. You risk losing rest of the player data.

You can calculate how many players there must be that the packet size grows over 1400 bytes.

Index = byte (1 byte)
Player Name = string (n bytes + null byte)
Kills = long (4 bytes)
Time connected = float (4 bytes)

n = average player name length ~ 15 bytes

(1+n+1+4+4)*[num of players] = something

Actually it seems that the player information fits into one packet quite well. This 15 bytes per name supports 56 players on the server Smile Rules usually require multiple packets (on other than TF2 servers because TF2 servers use compression).
Reply
#11
css Wrote:
Spartanfrog Wrote:They work fine, at least they did when I used them for CSS. Maybe now they dont, or whatever.
"At least when I...", "Maybe...", "... or whatever". Dude, this is great uncertainty shining through in your post. Read my previous post. There I tell why the scripts don't work in some cases.

It's unfortunate that the scripts don't work perfectly, but that's how it is.

Spartanfrog Wrote:If you "reccomend not to use the server query scripts in this package," maybe you could help by fixing them? Thats more constructive than just saying they dont work.
Eh.. why don't you fix them? That'd be constructive of you - more constructive than telling me to do it. Really, I took the time to see the code, noticed how they're flawed with the new server engine and pointed out how they should be fixed. Now you tell me that I'm not constructive. What's your problem?

The scripts are extremely simple. "Fixing" them means adding about 3x more code.
lol.........Thats all I'm gonna say. I cant help if you didn't understand what I meant.
realchamp Wrote:
Hazz Wrote:Has someone helped you on these forums? If so, help someone else
Mooga Wrote:OrangeBox is a WHORE.
Reply
#12
Spartanfrog Wrote:I cant help if you didn't understand what I meant.
I didn't ask for help, matafaka did.

Don't attack me. I told why the scripts don't work. If you can't fix them, so be it. You can't help yourself. Don't take it on me.

Please, try to stick on the topic. ColdFire released the scripts, which do not work properly with all servers. Matafaka had problems getting the scripts to work. I don't have problem here. You don't seem to have problem either because you've got CS:S server. So stick to the topic and try to help those who need help. You can help, but you're looking at the wrong way.
Reply
#13
css Wrote:
ColdFire Wrote:Quick reply:
- it works for TF2 if you don't use packet compression. I'd have to check that with compression
By default TF2 servers use compression. Your script doesn't work with TF2 servers with default settings. Big flaw.

ColdFire Wrote:- about tf2players.php, it works. I read only the first packet since all the players are on this one. It accelerates the reading since it doesn't have to wait for a timeout.
Huh? Have you read the protocol specification: http://developer.valvesoftware.com/wiki/Server_Queries#A2S_PLAYER

Player information is in all packets. There will be multiple packets if the player data doesn't fit into one packet (=1400 bytes). You can't say that the player data is only in the first packet. You can't accelerate processing by retrieving only the first packet. You risk losing rest of the player data.

You can calculate how many players there must be that the packet size grows over 1400 bytes.

Index = byte (1 byte)
Player Name = string (n bytes + null byte)
Kills = long (4 bytes)
Time connected = float (4 bytes)

n = average player name length ~ 15 bytes

(1+n+1+4+4)*[num of players] = something

Actually it seems that the player information fits into one packet quite well. This 15 bytes per name supports 56 players on the server Smile Rules usually require multiple packets (on other than TF2 servers because TF2 servers use compression).

I don't pretend to respect the full protocol, or doing it the best way possible. I've given scripts that work for me, that may work for others, that's all. And yep, all the players fit in only one packet. That's why I don't wait for the other ones, so when my script is called, it doesn't slow too long the web page display.
Reply
#14
ColdFire Wrote:That's why I don't wait for the other ones, so when my script is called, it doesn't slow too long the web page display.
Bullshit.

As soon as the target server replies anything, it sends all data it wants to. There's no slow "okay I got the first packet, now send me the second packet" style discussion between the server and the client. As soon as the first packet comes from the target server, the rest packets are <1ms behind.

The scripts work pretty well for 99% of world's CS:S servers. The only thing they fail is big rules and player lists. That's on CS:S servers. For TF2 servers the script does only general info (hostname, numplayers, numbots, ..). The scripts are not compatible enough with the new TF2 server engine for greater use.

Take it as a challenge to update the scripts.
Reply
#15
hi,
players.php begin work after change "$challengeNumber = preg_replace($pattern, '', $response);" -> "$challengeNumber = str_replace($pattern, '', $response);" ))
sanks for script )
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)