Detecting my Server on my Website

Started by
15 comments, last by RonHiler 20 years, 4 months ago
So I''m coding away on my mutliplayer game, and I''ve gotten it to the point where players can log on and walk around my virtual world and see other players and blah blah blah What I would now like to do is show some sort of status on my web page about the server. That is to say, when the server is running, I''d like for the page to show that fact (with a little green light or something), and what would be REALLY nice is if I could show the server population as well. Something like "The server is UP, 12 people are logged in", or "The server is DOWN". Any tips on how to do this? I know enough PHP to get by, though it''s not my native tounge Should I somehow send some sort of packet to my server and look for a response every few minutes? I''m not entirely sure how to send a packet to a specific IP like I can in C++, heh. In my code I use WinSock. Tips are appreciated! -Ron
Creation is an act of sheer will
Advertisement
While you could get complex and have PHP directly connected into your game, the easiest and perhaps best in terms of stability would be to simply have a file like "serverstatus.php" which is updated every 60 seconds by your game server.

Something like:

<?$LastUpdate = A timestamp of when this file was last written by the game server$Population = blah//Other game statsfunction IsServerUp(){  return ( time()-120 < $LastUpdate );}?> 


Then in your website scripts you can just include_once("serverstatus.php");
That''s interesting! Yes, I like the idea.

However, I think there is a snag. My game server sits in my office, and my web server is somewhere on the east coast

How would I have my game server write to a file that is on my web server?
Creation is an act of sheer will
quote:Original post by RonHiler
That's interesting! Yes, I like the idea.

However, I think there is a snag. My game server sits in my office, and my web server is somewhere on the east coast

How would I have my game server write to a file that is on my web server?


If they are on machines connected only by an unprotected wan (like the Internet) then I would suggest not trying to write a file remotely (you could do it a secure manner, but it would require that you write a lot of stuff into your game, like a complete HTTPS client from scratch).

Instead I would suggest that you have a php script on your webserver that either writes the file, or writes the details to a database like MySQL (the database approach would allow you to do interesting things like have uptime reports and such) using parameters provided by a form (you don't need to have the form anywhere, only know what the value names are).

A very simple way to make it secure would be this:

Make a mini HTTP client on your game server (it doesn't need to understand much, just how to send a GET command which includes form parameters, not very hard over TCP) and have it send the various details (server status and such) as form data. For (easy to impliment, fairly strong) security two more details should be used. The first is the game server time (this is compared to the reported game server time of the last update. If it is equal or less the information sent is rejected). The second piece of information is the MD5 hash of all the previous information (server stats and server time) plus an additional, secret value (a key of whatever length you choose). When recieved by the php script it attempts to recreate this hash value itself (by combining the server stats and key and using the MD5() function on the resulting string). If the hash provided by the client and the hash generated by the php script don't match the information is rejected as false. For added security you could also have it check the IP address of the client and compare it to the known IP address of the game server.


[edited by - michalson on November 26, 2003 7:26:47 PM]
Why not use the socket functions built into PHP to connect to the game server every time a user requests the page, and if the server responds then that means the server is up?

http://jamesthornton.com/php/english/ref.sockets.html (the php site is down right now)

[edited by - Firewalker on November 26, 2003 7:37:57 PM]
As an alternative you could switch over to using ASP and program a Web Service that you could then access the servers through a standard winsock interface. This could allow you to choose your poison...C++, C#, VB.
There is no point in doing anything at all, you'll die pretty soon anyway.
quote:Original post by Synth0id
As an alternative you could switch over to using ASP and program a Web Service that you could then access the servers through a standard winsock interface. This could allow you to choose your poison...C++, C#, VB.

have you ever tried php??
if not you will most likely ditch asp instanly once you try

besides that php runs on nearly every system whereas asp... you know.
http://mitglied.lycos.de/lousyphreak/
Don't bother LousyPhreak...

I know full and well the pros and cons of each language. .NET Webservices are an awesome feature of ASP, so grow up and stop turning this into a langauge war.

synth0id

[edited by - synth0id on November 27, 2003 5:53:48 PM]
There is no point in doing anything at all, you'll die pretty soon anyway.
Synth0id you take everything that dead serious do you?

btw to make this post a bit more useful than the last 2 here''s some code to query a halflife server in php, just to get you (RonHiler) an idea.

$command can be a string like ''info'', for more you need to look at the specs in the hl-sdk.
function sendCommand($command,$server=''127.0.0.1'',$port=27015){  if(($sock = socket_create (AF_INET, SOCK_DGRAM, 0)) < 0)  {    echo "socket_create() failed: reason: " . socket_strerror($sock) . "\n";  }  $send=sprintf(''%c%c%c%c%s%c%c'',255,255,255,255,$command,0,0);  $x=socket_sendto($sock,$send,strlen($send)-1,0,$server,$port);  $y=socket_recvfrom($sock,$recvbuf,1000,0,$from,$port);  return $y;}

http://mitglied.lycos.de/lousyphreak/
Ah, that''s very interesting LousyPhreak, it looks like it would work okay with my setup. I''ll give it a try
Creation is an act of sheer will

This topic is closed to new replies.

Advertisement