Author Topic: SrcQR -- A PHP source query and rcon library  (Read 6887 times)

0 Members and 1 Guest are viewing this topic.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6215
  • Karma: 394
  • Project Lead
SrcQR -- A PHP source query and rcon library
« on: June 01, 2008, 06:21:09 PM »
History of this script: This is a PHP script I made four years ago during AP Computer Science in high school when I was bored enough to count dots on the ceiling. :)
This was my first and only real PHP script. (I had fragments of other scripts of things I came up with but never got much past inception with)

So why release it now?: Somehow it came up in a discussion with Ninjadude101, I found the poor script rotting in some forsaken corner of my archive, dusted it off a bit, updated the A2S_INFO query (it changed since I made it), and decided I may as well give the script the light of day. I never used it personally, but maybe there'll be some interest out there.

Things you should know: As I said, it was my first PHP script. Probably a bit messy and there's a few bugs. I know of a few already: it errors out if your server is down and I think it might choke on certain replies if there's a lot of information (except for the rcon bit, that seems to be okay with big stuff). If there's a lot of interest I'll fix any bugs found, seems like they'd be pretty easy to fix anyways.

How to use it:
Look at the code below, it should be pretty self explanatory. Use var_dump to see what the results of a query is.
Code: PHP
  1.       $a = new SrcQR( "38.96.12.159", "27016" );
  2.       $info = $a->getInfo();
  3.       $players = $a->getPlayers();
  4.       //$a->getRules();
  5.       $a->auth( 'rcon_pass' );
  6.       if ( $a->authed ) {
  7.         $rcon_result = $a->rconCommand( 'cvarlist' );
  8.       }

getRules() didn't work at the time I made this because garry refused to implement it. Not sure if it works now or not. Put your rcon pass in auth if you're using rcon. You do receive the rcon results with rconCommand.

License:
Note that this isn't the usual Ulysses license as it is the Creative Commons Attribution-NonCommercial-NoDerivs.

Download:
See below. You must be registered to see it.
« Last Edit: June 02, 2008, 10:14:00 AM by Megiddo »
Experiencing God's grace one day at a time.

Offline Ninjadude101

  • Newbie
  • *
  • Posts: 38
  • Karma: 4
Re: SrcQR -- A PHP source query and rcon library
« Reply #1 on: June 01, 2008, 11:24:24 PM »
Yay!
Really though, i would probably find some great use from this.

Ah, i put my rcon pass in and my serverip/port at the bottom, Just returns a white page :/
« Last Edit: June 01, 2008, 11:35:22 PM by Ninjadude101 »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6215
  • Karma: 394
  • Project Lead
Re: SrcQR -- A PHP source query and rcon library
« Reply #2 on: June 02, 2008, 04:43:37 AM »
You have to do something with it. It's a library like ULib. Of course it returns a white page.
Experiencing God's grace one day at a time.

Offline Lt.Smith

  • Newbie
  • *
  • Posts: 32
  • Karma: 4
Re: SrcQR -- A PHP source query and rcon library
« Reply #3 on: June 02, 2008, 09:14:44 AM »
I love it, thanks Megiddo. I haven't actually tried to do anything with it yet, but I'm going to over the coming few days. I saw another community with a server stats page and was jealous, now I can have the same  :D

***

Update:

It works, kinda. When I var_dump $a I get a load of information, which is great. However when I want a specific field (using echo $a[host], for instance) it dies, producing the following error:

Quote
Fatal error: Cannot use object of type SrcQR as array in /home/gmodsauc/public_html/banlist/srcqr.php on line 538

Any ideas?
« Last Edit: June 02, 2008, 09:33:15 AM by Lt.Smith »

Offline Lt.Smith

  • Newbie
  • *
  • Posts: 32
  • Karma: 4
Re: SrcQR -- A PHP source query and rcon library
« Reply #4 on: June 02, 2008, 09:59:07 AM »
... I've done it again.

Code: PHP
  1. $a = new SrcQR( "89.145.117.221", "27015" );
  2. $a->getChallenge();
  3. $a->getInfo();
  4. $a->getPlayers();
  5. //$a->getRules();
  6. //$a->auth( 'rcon_pass' );
  7. //$a->rconCommand( 'cvarlist' );*/
  8.  
  9.  
  10. $b = get_object_vars($a);
  11.  
  12. var_dump ($b); // Dump the entire contents of $b
  13. echo "<br /><br />";
  14. var_dump ($b[playerList]); //Only return the player list, which also happens to be an array.


turns whatever $a is into an array and breaks it into chunks that you can use. Perhaps this can help anyone else who's confused :P
« Last Edit: June 02, 2008, 11:26:43 AM by Lt.Smith »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6215
  • Karma: 394
  • Project Lead
Re: SrcQR -- A PHP source query and rcon library
« Reply #5 on: June 02, 2008, 10:12:51 AM »
Well, that works... but those functions actually return the values you're looking for. I should have been more clear in my example I guess. Here yah go:

Code: PHP
  1.       $a = new SrcQR( "38.96.12.159", "27016" );
  2.       $info = $a->getInfo();
  3.       $players = $a->getPlayers();
  4.       //$a->getRules();
  5.       $a->auth( 'rcon_pass' );
  6.       if ( $a->authed ) {
  7.         $rcon_result = $a->rconCommand( 'cvarlist' );
  8.       }
Experiencing God's grace one day at a time.

Offline Lt.Smith

  • Newbie
  • *
  • Posts: 32
  • Karma: 4
Re: SrcQR -- A PHP source query and rcon library
« Reply #6 on: June 02, 2008, 11:18:54 AM »
Ah! I get it. That makes a lot more sense.

Thanks! :)