SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Tools and Files

Reply
 
Thread Tools Display Modes
Old 23/10/2009, 07:38 PM   #1
Westie
Gangsta
 
Westie's Avatar
 
Join Date: Jul 2009
Posts: 863
Reputation: 63
Default Server Query and RCON API - Be an admin at ease! (05/07/2010)

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

Last edited by Westie; 16/08/2011 at 05:20 PM.
Westie is offline   Reply With Quote
Old 23/10/2009, 07:41 PM   #2
MenaceX^
High-roller
 
Join Date: Aug 2008
Posts: 3,780
Reputation: 13
Default Re: [PHP] Server Query and RCON API - Be an admin at ease!

Wow, that's awesome.
Well done.
MenaceX^ is offline   Reply With Quote
Old 23/10/2009, 07:46 PM   #3
Silent314
Big Clucker
 
Join Date: Jul 2008
Posts: 65
Reputation: 0
Default Re: [PHP] Server Query and RCON API - Be an admin at ease!

Very nice.

P.S.: You got your download links backwards.
Silent314 is offline   Reply With Quote
Old 23/10/2009, 07:52 PM   #4
Westie
Gangsta
 
Westie's Avatar
 
Join Date: Jul 2009
Posts: 863
Reputation: 63
Default Re: [PHP] Server Query and RCON API - Be an admin at ease!

Oh, thanks for that. Fixed that stupid mistake
Westie is offline   Reply With Quote
Old 23/10/2009, 08:03 PM   #5
Johnstonio
Little Clucker
 
Join Date: Oct 2009
Posts: 9
Reputation: 0
Default Re: [PHP] Server Query and RCON API - Be an admin at ease!

Sounds awesome, I can't wait to see the panel.
Johnstonio is offline   Reply With Quote
Old 27/10/2009, 10:34 PM   #6
capikepi
Little Clucker
 
Join Date: May 2009
Posts: 6
Reputation: 0
Default Re: [PHP] Server Query and RCON API - Be an admin at ease!

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
capikepi is offline   Reply With Quote
Old 28/10/2009, 05:09 PM   #7
Westie
Gangsta
 
Westie's Avatar
 
Join Date: Jul 2009
Posts: 863
Reputation: 63
Default Re: [PHP] Server Query and RCON API - Be an admin at ease!

You may of modified it by mistake. Re-download the file.
Westie is offline   Reply With Quote
Old 28/10/2009, 08:39 PM   #8
_Healer_
Big Clucker
 
Join Date: Oct 2009
Posts: 71
Reputation: 0
Default Re: [PHP] Server Query and RCON API - Be an admin at ease!

Awesome
_Healer_ is offline   Reply With Quote
Old 29/10/2009, 04:20 PM   #9
dirkblok
Huge Clucker
 
Join Date: Aug 2009
Posts: 337
Reputation: 0
Default Re: [PHP] Server Query and RCON API - Be an admin at ease!

Helpful thanks
dirkblok is offline   Reply With Quote
Old 31/10/2009, 12:06 PM   #10
@TheShadow@
Big Clucker
 
Join Date: May 2009
Posts: 162
Reputation: 0
Default Re: [PHP] Server Query and RCON API - Be an admin at ease!

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....
@TheShadow@ is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FilterScript] [FS] RCON-manager (control your server easier from RCON-console) Correlli Filterscripts 34 09/04/2015 08:28 PM
i need car only rcon or admin can use matdav Help Archive 10 30/11/2009 09:21 PM
Server query url? kazimieras Server Support 2 02/03/2009 11:11 PM
Server Query Joe_Dean Server Support 6 26/01/2009 11:33 PM


All times are GMT. The time now is 05:29 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.