[Tool/Web/Other] [PHP] Server Query and RCON API - Be an admin at ease! (16/02/2010)
#1

(Alright, that was a lame description, but I needed something. Folks, could you please gimmie a decent catchphrase for the title? Thanks!)

Server Query and RCON API - 1.2


Introduction
I was doing some investigation into SA-MP's RCON when I realised, there's no decent tool to help you with RCON (well... not for download anyway). So, out of either complete boredom, or a burning desire to figure out how to get this working, I made it. I made an API (SDK?) that retrieves every output that the server gives out, to do with that command. I've also found out a few bugs (or 'measures') along the way, bla bla bla. I'm also releasing the Server Query script, that provides you with the tools necessary to check how your server is going on, etc. (The RCON and Query protocols IMHO both compliment each other...)


Function list: SampQueryAPI
Full documentation for this class are available here.

SampQueryAPI::__construct( string $sServer, [integer $iPort = 7777] )
SampQueryAPI::getBasicPlayers( )
SampQueryAPI::getDetailedPlayers( )
SampQueryAPI::getInfo( )
SampQueryAPI::getRules( )
SampQueryAPI::isOnline( )


You can use this class, as an example, to get the server environment rules, like below. For an example list of the rules that can be sent, please check the documentation.

Code:
<?php

$query = new SampQueryAPI('192.168.4.1', 7777);

print_r
(
    $query->getRules()
);

?>
Function list: SampRconAPI
Full documentation for this class are available here.

SampRconAPI::__construct( $sServer, $iPort, $sPassword )
SampRconAPI::addressBan( string $sIPAddress )
SampRconAPI::addressUnban( string $sIPAddress )
SampRconAPI::adminSay( string $sMessage )
SampRconAPI::Call( string $sCommand, [float $fDelay = 1.0] )
SampRconAPI::gameChangeMode( string $sGamemode )
SampRconAPI::gameExec( string $sConfig )
SampRconAPI::gameExit( )
SampRconAPI::gameLoadFilterscript( string $sFilterscript )
SampRconAPI::gameNextMode( )
SampRconAPI::gameReloadFilterscript( string $sFilterscript )
SampRconAPI::gameUnloadFilterscript( string $sFilterscript )
SampRconAPI::getCommandList( )
SampRconAPI::getServerVariables( )
SampRconAPI::isOnline( )
SampRconAPI::playerBan( integer $iPlayerID )
SampRconAPI::playerKick( integer $iPlayerID )
SampRconAPI::reloadBans( )
SampRconAPI::reloadLogs( )
SampRconAPI::setGravity( float $fGravity )
SampRconAPI::setWeather( integer $iWeatherID )


You can use this class to do general administration work with, calling custom commands, or maybe banning someone. The below example explains how to ban an IP address, and how to unban another.

Code:
<?php

$rcon = new SampRconAPI('192.168.4.1', 7777, 'lolarcon');

$rcon->addressBan('192.168.5.1'); // Just banned an address.
$rcon->addressUnban('192.168.5.6'); // Just unbanned another address.

$rcon->reloadBans(); // You'll need to reload the ban files!

?>
Do you need to call a command that is not listed here, for example a custom RCON command? You can use the SampRconAPI::Call() method (example 1), or you can integrate this into another class to make your code all nice and neat! (example 2)

Code:
<?php

/* Example 1 */
$rcon = new SampRconAPI('192.168.4.1', 7777, 'lolarcon');
$rcon->Call('your_custom_func_here');


/* Example 2 */
class CustomRcon extends SampRconAPI
{
	public function someFunctionName()
	{
		parent::Call('your_custom_func_here');
	}
}

$rcon = new CustomRcon('192.168.4.1', 7777, 'lolarcon');
$rcon->someFunctionName();
Download
Was that simple enough? If not, I'll be uploading a sample RCON panel, as well as a script demonstrating examples what you could do with the query script. Watch this space, or maybe this space, don't really know.



API files
(Both files updated 05/07/2010)
SampQueryAPI: http://files.typefish.co.uk/sa-mp/SampQueryAPI.php
SampRconAPI: http://files.typefish.co.uk/sa-mp/SampRconAPI.php

Examples
Query example: http://gist.github.com/234209

(Don't worry, they'll download in your browser... hopefully.)

Remember, no mirrors, but most importantly, post if you have problems!
Reply
#2

Wow, that's awesome.
Well done.
Reply
#3

Very nice.

P.S.: You got your download links backwards.
Reply
#4

Oh, thanks for that. Fixed that stupid mistake
Reply
#5

Sounds awesome, I can't wait to see the panel.
Reply
#6

Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /szerver/SampRconAPI.php on line 20
Reply
#7

You may of modified it by mistake. Re-download the file.
Reply
#8

Awesome
Reply
#9

Helpful thanks
Reply
#10

Quote:
Originally Posted by _Star_
Awesome
little spammer xD you go to every thread and say "Awesome", but i don't think you have even tested one of it....
Reply
#11

Quote:
Originally Posted by @TheShadow@
little spammer
How ironic.
Reply
#12

Quote:
Originally Posted by /^We(stie|z+[e|a
r)$/ ]
Quote:
Originally Posted by @TheShadow@
little spammer
How ironic.
I'm A Very Stupid Noob at PHP but I Want This For My Server. Could You Give Me A Step By Step Guide On How To Set IT Up?
Reply
#13

Good job.
What a new version.
Created Rice.
Reply
#14

nice
Reply
#15

Good work, and nice!
Reply
#16

Quote:
Originally Posted by &&Saiber
Quote:
Originally Posted by /^We(stie|z+[e|a
r)$/ ]
Quote:
Originally Posted by @TheShadow@
little spammer
How ironic.
I'm A Very Stupid Noob at PHP but I Want This For My Server. Could You Give Me A Step By Step Guide On How To Set IT Up?
http://gist.github.com/234209

This is an example of how to use the script. You can just download both the files, and execute on the server. If it looks familiar, that's because it is - the HTML is based on Peter's script.
Reply
#17

Download links not working anymore... Does anybody have mirrored these files ?
Reply
#18

well done
Reply
#19

Quote:
Originally Posted by devnull
Download links not working anymore... Does anybody have mirrored these files ?
Sorry, I'm in the process of changing HTTP daemons. It'll be up when it's up.

EDIT: Fixed.
Reply
#20

OMFG, i love you! but please could you reupload it please, Thanks in advance
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)