SA-MP Forums Archive
[Tool/Web/Other] [PHP] Server Query and RCON API - Be an admin at ease! (16/02/2010) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Tools and Files (https://sampforum.blast.hk/forumdisplay.php?fid=82)
+---- Thread: [Tool/Web/Other] [PHP] Server Query and RCON API - Be an admin at ease! (16/02/2010) (/showthread.php?tid=104299)

Pages: 1 2 3 4 5 6


Server Query and RCON API - Be an admin at ease! (05/07/2010) - Westie - 23.10.2009

(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!


Re: [PHP] Server Query and RCON API - Be an admin at ease! - MenaceX^ - 23.10.2009

Wow, that's awesome.
Well done.


Re: [PHP] Server Query and RCON API - Be an admin at ease! - Silent314 - 23.10.2009

Very nice.

P.S.: You got your download links backwards.


Re: [PHP] Server Query and RCON API - Be an admin at ease! - Westie - 23.10.2009

Oh, thanks for that. Fixed that stupid mistake


Re: [PHP] Server Query and RCON API - Be an admin at ease! - Johnstonio - 23.10.2009

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


Re: [PHP] Server Query and RCON API - Be an admin at ease! - capikepi - 27.10.2009

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


Re: [PHP] Server Query and RCON API - Be an admin at ease! - Westie - 28.10.2009

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


Re: [PHP] Server Query and RCON API - Be an admin at ease! - _Healer_ - 28.10.2009

Awesome


Re: [PHP] Server Query and RCON API - Be an admin at ease! - dirkblok - 29.10.2009

Helpful thanks


Re: [PHP] Server Query and RCON API - Be an admin at ease! - @TheShadow@ - 31.10.2009

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....


Re: [PHP] Server Query and RCON API - Be an admin at ease! - Westie - 31.10.2009

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


Re: [PHP] Server Query and RCON API - Be an admin at ease! - (Jeff) - 13.11.2009

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?


Re: [PHP] Server Query and RCON API - Be an admin at ease! - sakang - 13.11.2009

Good job.
What a new version.
Created Rice.


Re: [PHP] Server Query and RCON API - Be an admin at ease! - thimo - 13.11.2009

nice


Re: [PHP] Server Query and RCON API - Be an admin at ease! - elvago - 13.11.2009

Good work, and nice!


Re: [PHP] Server Query and RCON API - Be an admin at ease! - Westie - 13.11.2009

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.


Re: [PHP] Server Query and RCON API - Be an admin at ease! - devnull - 12.01.2010

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


Re: [PHP] Server Query and RCON API - Be an admin at ease! - LifestealeR - 12.01.2010

well done


Re: [PHP] Server Query and RCON API - Be an admin at ease! - Westie - 12.01.2010

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.


Re: [PHP] Server Query and RCON API - Be an admin at ease! - Nokia - 13.01.2010

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