R4nk3d Posted April 10, 2009 Share Posted April 10, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153413-pinging-a-gameserver-remote-rcon-page/ Share on other sites More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 PEAR has a class for pinging. Ping with PHP The other stuff you may need to read some tutorials for or get some examples for these forums, as they are too broad to answer. Quote Link to comment https://forums.phpfreaks.com/topic/153413-pinging-a-gameserver-remote-rcon-page/#findComment-805996 Share on other sites More sharing options...
R4nk3d Posted April 10, 2009 Author Share Posted April 10, 2009 Ok, ill check it out. Thanks a lot Maq. Quote Link to comment https://forums.phpfreaks.com/topic/153413-pinging-a-gameserver-remote-rcon-page/#findComment-805997 Share on other sites More sharing options...
corbin Posted April 10, 2009 Share Posted April 10, 2009 Just wondering, what game? Quote Link to comment https://forums.phpfreaks.com/topic/153413-pinging-a-gameserver-remote-rcon-page/#findComment-805998 Share on other sites More sharing options...
R4nk3d Posted April 10, 2009 Author Share Posted April 10, 2009 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; Quote Link to comment https://forums.phpfreaks.com/topic/153413-pinging-a-gameserver-remote-rcon-page/#findComment-806002 Share on other sites More sharing options...
xtopolis Posted April 10, 2009 Share Posted April 10, 2009 You can't ping a port. You can telnet/portscan/dounspeakablethings to them though. As for this being possible with PHP... not sure. Quote Link to comment https://forums.phpfreaks.com/topic/153413-pinging-a-gameserver-remote-rcon-page/#findComment-806007 Share on other sites More sharing options...
R4nk3d Posted April 10, 2009 Author Share Posted April 10, 2009 You can't ping a port. You can telnet/portscan/dounspeakablethings to them though. As for this being possible with PHP... not sure. What would be required for me to telnet it? Quote Link to comment https://forums.phpfreaks.com/topic/153413-pinging-a-gameserver-remote-rcon-page/#findComment-806010 Share on other sites More sharing options...
xtopolis Posted April 10, 2009 Share Posted April 10, 2009 Perhaps fsockopen. Ports are not my area of expertise, try googling. I can think of a few things, but I'm not sure the best one / safest one. exec is an option, but something people tend to stay away from. Research it on your own, or wait for other answers here. Quote Link to comment https://forums.phpfreaks.com/topic/153413-pinging-a-gameserver-remote-rcon-page/#findComment-806014 Share on other sites More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 You may find this useful: http://www.phpfreaks.com/forums/index.php/topic,247139.msg1155934.html#msg1155934 Quote Link to comment https://forums.phpfreaks.com/topic/153413-pinging-a-gameserver-remote-rcon-page/#findComment-806019 Share on other sites More sharing options...
R4nk3d Posted April 10, 2009 Author Share Posted April 10, 2009 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. So now i have my way to ping it. Now i just gotta figure out the rcon Quote Link to comment https://forums.phpfreaks.com/topic/153413-pinging-a-gameserver-remote-rcon-page/#findComment-806033 Share on other sites More sharing options...
MasterACE14 Posted April 10, 2009 Share Posted April 10, 2009 they might have info on this in the SAMP manual or wiki. I'm curious as to what type of gamemode you are running the server and where is the server located? Quote Link to comment https://forums.phpfreaks.com/topic/153413-pinging-a-gameserver-remote-rcon-page/#findComment-806037 Share on other sites More sharing options...
R4nk3d Posted April 10, 2009 Author Share Posted April 10, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153413-pinging-a-gameserver-remote-rcon-page/#findComment-806044 Share on other sites More sharing options...
xtopolis Posted April 10, 2009 Share Posted April 10, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153413-pinging-a-gameserver-remote-rcon-page/#findComment-806051 Share on other sites More sharing options...
R4nk3d Posted April 10, 2009 Author Share Posted April 10, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/153413-pinging-a-gameserver-remote-rcon-page/#findComment-806052 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.