Jump to content

Pinging a Gameserver && Remote Rcon Page


R4nk3d

Recommended Posts

Hi everyone.

Currently I'm building a website for a multiplayer game. This game is linked into an sql database and so this is where it gets a lot of the information for it from. But what I'm trying to do is:

1. Make a small script saying

$result = ping(gameserverhost,gameserverport);
if($result) echo("Good connection.");
else echo("Bad connection.");

2. Make a live RCON administration page. This way if you are logged in to the site and you click the link to this page itll show you the updated server log(Updated every second?) and then an input line where you can type things like "kick 3" to kick the players who id is 3. Itll pass the string to the server and then it can deal with it from there.

 

Any help would be appreciated. I've been looking for the ping function for awhile but i cant find it. I havent looked into the rcon page too much. Thanks in advance.

Link to comment
Share on other sites

Just wondering, what game?

Grand Theft Auto San Andreas: Multiplayer.

I'm gonna work out the code on this format, then convert it to some other games possibly.

 

Another question: I found exactly what you gave me, but I left out a large part of that question. What I needed to say is:

Is it possible to ping a server port?

Like ping(localhost,80) and it'd return 1;

Link to comment
Share on other sites

Well i just found a good tut on the scripting website for the game. :)

 

It shows

$fp = fsockopen('udp://' . "127.0.0.1", "1337", $errno, $errstr);

the port for the server config file is udp 7777. So if i connect to the server host and udp port, i get a list of the configurations. :D So now i have my way to ping it. Now i just gotta figure out the rcon

Link to comment
Share on other sites

Well, im scripting a new roleplay gamemode that is all sql based. At the moment, it is on my server that i host my websites on(including this one) and other things such as emails. For the time being this server is in my room until i take it into my work next week to be hosted there. PM if you want more info, id like to stay on topic.

 

 

Anywho, now i have this code.

$fp = @fsockopen('udp://' . "IP", 7777, $errno, $errstr, 5);
if(!fp)
{
	echo("<img src=\"images/serverdown.png\" alt=\"The Game Server Is Down!\">");
}
else if($fp)
{
	$packet = 'SAMP';
	$packet .= chr(strtok($ip, '.'));
	$packet .= chr(strtok('.'));
	$packet .= chr(strtok('.'));
	$packet .= chr(strtok('.'));
	$packet .= chr($port & 0xFF);
	$packet .= chr($port >> 8 & 0xFF);

	fwrite($fp, $packet.'i');
	fread($fp, 11);
	$is_passworded = ord(fread($fp, 1));
	$plr_count     = ord(fread($fp, 2));
	$max_plrs      = ord(fread($fp, 2));
	$strlen        = ord(fread($fp, 4));
	$hostname      = fread($fp, $strlen);
	$strlen        = ord(fread($fp, 4));
	$gamemode      = fread($fp, $strlen);
	$strlen        = ord(fread($fp, 4));
	$mapname       = fread($fp, $strlen);
	echo("<img src=\"images/serverup.png\" alt=\"The Game Server Is Up!\">");
	fclose($fp);
}

It works great when the server is up, but if i shut it down, the page just loads for about 30 seconds straight, then pops up half of it, but all the code i have after this strip doesnt show. And neither does the server down image or anything else.

Link to comment
Share on other sites

Since it's hosted on the same server currently, but due to change later, perhaps you could first cURL the IP to see if the entire server is accessible, then fsockopen and try to read your config.  When you say the server is down, I'm not sure if you mean the process isn't running, or the IP address is unable to be reached.

 

edit: in the notes:

Notes

 

    Note: Depending on the environment, the Unix domain or the optional connect timeout may not be available.

 

Warning

 

UDP sockets will sometimes appear to have opened without an error, even if the remote host is unreachable. The error will only become apparent when you read or write data to/from the socket. The reason for this is because UDP is a "connectionless" protocol, which means that the operating system does not try to establish a link for the socket until it actually needs to send or receive data.

 

I had an alternative suggestion, using a while loop to check if 5 seconds had passed, but I'm not sure if the fsockopen would lock the thread while trying to connect.  You could test it by doing a mktime before the while loop and then attempting fsockopen while 5 seconds haven't passed.

Link to comment
Share on other sites

Since it's hosted on the same server currently, but due to change later, perhaps you could first cURL the IP to see if the entire server is accessible, then fsockopen and try to read your config.  When you say the server is down, I'm not sure if you mean the process isn't running, or the IP address is unable to be reached.

Oops, again. I mistyped. Heres the layout:

Server Running:

IIS 6

MySQL 5.0.0

 

My Computer Running:

Samp Server

 

So the server is running on my computer for the game, but the computer server is running the websites. So im opening a socket from 192.168.0.115(server) to 192.168.0.101(computer). But i want to check if the process is running. Thats why i open the socket for the udp port on the computer.

 

EDIT: im having a problem with the fsockopen timeout. it wont change no matter what number i put. =/ i put 2 and it it still takes for ever to load. Whats the problem here?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.