• Print

Author Topic: PHP Server Queries Useful?  (Read 24040 times)

0 Members and 1 Guest are viewing this topic.

Offline Rambomst

  • Newbie
  • *
  • Posts: 18
  • Karma: 0
Re: PHP Server Queries Useful?
« Reply #15 on: June 12, 2010, 04:25:03 pm »
Sure.
Here is what I use to do the basic server query.
Code: PHP
  1. function query_server($address)
  2. {
  3.         $array = explode(":", $address);
  4.  
  5.         $server['status'] = 0;
  6.         $server['ip']     = $array[0];
  7.         $server['port']   = $array[1];
  8.  
  9.         if (!$server['ip'] || !$server['port']) { exit("EMPTY OR INVALID ADDRESS"); }
  10.  
  11.         $socket = @fsockopen("udp://{$server['ip']}", $server['port'], $errno, $errstr, 1);
  12.  
  13.         if (!$socket) { return $server; }
  14.  
  15.         stream_set_timeout($socket, 1);
  16.         stream_set_blocking($socket, TRUE);
  17.         fwrite($socket, "\xFF\xFF\xFF\xFF\x54Source Engine Query\x00");
  18.         $packet = fread($socket, 4096);
  19.         @fclose($socket);
  20.  
  21.         if (!$packet) { return $server; }
  22.  
  23.         $header                = substr($packet, 0, 4);
  24.         $response_type         = substr($packet, 4, 1);
  25.         $network_version       = ord(substr($packet, 5, 1));
  26.  
  27.         if ($response_type != "I") { exit("NOT A SOURCE SERVER"); }
  28.  
  29.         $packet_array          = explode("\x00", substr($packet, 6), 5);
  30.         $server['name']        = $packet_array[0];
  31.         $server['map']         = $packet_array[1];
  32.         $server['game']        = $packet_array[2];
  33.         $server['description'] = $packet_array[3];
  34.         $packet                = $packet_array[4];
  35.         $server['players']     = ord(substr($packet, 2, 1));
  36.         $server['playersmax']  = ord(substr($packet, 3, 1));
  37.         $server['bots']        = ord(substr($packet, 4, 1));
  38.         $server['status']      = 1;
  39.         $server['dedicated']   =     substr($packet, 5, 1);
  40.         $server['os']          =     substr($packet, 6, 1);
  41.         $server['password']    = ord(substr($packet, 7, 1));
  42.         $server['vac']         = ord(substr($packet, 8, 1));
  43.  
  44.         return $server;
  45. }
  46.  
[EDIT - JamminR] Placed in code=php tags
« Last Edit: June 12, 2010, 05:11:23 pm by JamminR »

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: PHP Server Queries Useful?
« Reply #16 on: June 15, 2010, 08:20:12 am »
Thanks Rambomst.

Current progress:
     - Template built
     - All server queries ready
     - User registration

Todos:
     - User administration (web side)
     - How to handle the rcon passwords
     - Server status image maker

Further note on the RCon passwords. How do y'all think I should go about securing it.
     - Super Administrator (Installer of the CMS) enters the RCon password during install.
     - Password is 1-way hashed, can't be recovered.
     - Only allowed users (Web-based) can even attempt to login to console with RCon.
     - RCon is only during the session, after that you are required to re-enter it.
     - RCon is first compared to the password in the database then the game server to avoid sending any unnecessary queries to the game server.

Do y'all think that is the best way of handling it?

Current Live Progress
Obviously, not all the progress is live for security reasons.
« Last Edit: June 15, 2010, 08:21:43 am by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: PHP Server Queries Useful?
« Reply #17 on: June 15, 2010, 04:13:04 pm »
How do Steam games handle rcon? Per session?
If I start up my steam game, I can set an rcon_address and rcon_password and control any source game from that point.
Restart the game, and I have to enter password again (and address too if not connected to server or want to connect to different than what I'm playing on)
I'd attempt to use similar method. Definitely not stored long term.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: PHP Server Queries Useful?
« Reply #18 on: June 15, 2010, 08:16:36 pm »
I will definitely do it per session.

Update:
     - Homepage mock-up complete
     - Now on http://www.ulyssesmod.net/Jay/
     - Transparent Div overlay to keep user that aren't logged in from touching anything. If they try they are redirected to a login page. (This is totally optional)

« Last Edit: June 15, 2010, 08:18:32 pm by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: PHP Server Queries Useful?
« Reply #19 on: June 15, 2010, 09:02:17 pm »
Looking pretty sexy! :)
Experiencing God's grace one day at a time.

Offline Rambomst

  • Newbie
  • *
  • Posts: 18
  • Karma: 0
Re: PHP Server Queries Useful?
« Reply #20 on: June 16, 2010, 06:34:55 am »
If you are unsure on how to dynamically write text to an image for the server status have a look at http://forums.interwavestudios.com/topic/530-addon-server-status-image/. Yes it is for HLStats but it will give you an general idea on how to go about it. Also make the page GET statement throw up a "page cannot be found" or something like that or some sort of generic page if someone alters "?page=Home" to go to something that isn't there, it just makes it neater :P

*edit*

Another thing, make it so the nav button images load before you hover over them.
« Last Edit: June 16, 2010, 06:38:50 am by Rambomst »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: PHP Server Queries Useful?
« Reply #21 on: June 16, 2010, 01:35:49 pm »
By default, I use Firefox 3.6. Due to some vision issues I have (retinopathy, diabetes related + many surgeries), I set a windows color scheme that for all intents and purposes, makes text monochromatic for me, easier to read for long periods of time. (Classic windows, high contrast #2, modified greatly)
I have firefox ignore fonts and background images, and have it follow Windows color scheme instead of those set by pages.

To see if your page looked 'good' using normal colors, I used IE 6 to attempt to view it. (I don't have IE set to view with forced settings)
IE6 does some oddddd things to it. Perhaps IE6 doesn't understand the javascript / html tags you're doing.
Just a heads up. IE6 is still out there. It doesn't look good.
You may want to test it in other browsers to see how it looks.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: PHP Server Queries Useful?
« Reply #22 on: June 16, 2010, 02:18:06 pm »
If you are unsure on how to dynamically write text to an image for the server status have a look at http://forums.interwavestudios.com/topic/530-addon-server-status-image/. Yes it is for HLStats but it will give you an general idea on how to go about it. Also make the page GET statement throw up a "page cannot be found" or something like that or some sort of generic page if someone alters "?page=Home" to go to something that isn't there, it just makes it neater :P

*edit*

Another thing, make it so the nav button images load before you hover over them.
     - Thanks for the link, that will be very helpful.
     - As for using javascript to preload the tab already a on my scratch paper of todos :P
     - That's a great idea with the Get page thing. I'll probably just make it go back to the home page.


...Just a heads up. IE6 is still out there. It doesn't look good.
You may want to test it in other browsers to see how it looks.
     - Awh, I didn't even try IE 6, did 7 and 8. Thanks for the heads-up.

::EDIT:: Now that I take a look in IE again, all the versions mess it up.
« Last Edit: June 16, 2010, 02:22:53 pm by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: PHP Server Queries Useful?
« Reply #23 on: June 18, 2010, 07:50:00 am »
Well, I tried all the tricks I know to try and fix the IE issue, but I can't get it to work without a major work over, so I guess IE is out of the question unless Y'all can figure something out.
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline Aqua92

  • Newbie
  • *
  • Posts: 18
  • Karma: 0
Re: PHP Server Queries Useful?
« Reply #24 on: June 19, 2010, 03:46:35 am »
What exactly does not work on IE?
Maybe i can help a bit :)

Offline Rambomst

  • Newbie
  • *
  • Posts: 18
  • Karma: 0
Re: PHP Server Queries Useful?
« Reply #25 on: June 19, 2010, 05:03:19 am »
Well, I tried all the tricks I know to try and fix the IE issue, but I can't get it to work without a major work over, so I guess IE is out of the question unless Y'all can figure something out.
You don't want to do that. 80% if not more of internet users use IE.
« Last Edit: June 19, 2010, 07:12:04 am by Rambomst »

Offline Aqua92

  • Newbie
  • *
  • Posts: 18
  • Karma: 0
Re: PHP Server Queries Useful?
« Reply #26 on: June 19, 2010, 05:30:53 am »
You don't want to do that. 80% if not more of internet using use IE.

Yeah, but a "good" Web Programm should work on all Browsers, not, for example, only on Opera (yeah i saw some which only worked on Opera)

Offline Rambomst

  • Newbie
  • *
  • Posts: 18
  • Karma: 0
Re: PHP Server Queries Useful?
« Reply #27 on: June 19, 2010, 07:13:42 am »
Yeah, but a "good" Web Programm should work on all Browsers, not, for example, only on Opera (yeah i saw some which only worked on Opera)
Yeah I know, I am currently half way through my diploma for Web Development. If I didn't already know that well that would be pretty :P

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: PHP Server Queries Useful?
« Reply #28 on: June 19, 2010, 08:55:18 am »
The problem is, in IE if no width is given to the <li> elements, it defaults to 100% rather than size to contents. I could, however, give the li's static width, but then the tabs couldn't expand later on.
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: PHP Server Queries Useful?
« Reply #29 on: June 19, 2010, 09:32:41 am »
The problem is, in IE if no width is given to the <li> elements, it defaults to 100% rather than size to contents. I could, however, give the li's static width, but then the tabs couldn't expand later on.

Any way you could do it with style sheets instead?
Experiencing God's grace one day at a time.

  • Print