[Tool/Web/Other] [PHP] Query and RCON API (30/06/2012)
#1

SA-MP Query and RCON API for PHP
Edward McKnight (EM-Creations.co.uk) - StatusRed
Version: 1.1 (24/07/2014)
PHP Version: 5.3 (should work with earlier versions also however)
Additional credits: Westie (for the original PHP SA-MP API and inspiration for this API)

As well as the examples here; included in the download are SampRconExample.php and SampQueryExample.php files. These are full of examples of how to call functions as well as documentation.

Feel free to post if you have any questions or problems.

SampQuery functions:
SampQuery(server, port)
SampQuery->connect()
SampQuery->close()
SampQuery->getInfo()
SampQuery->getBasicPlayers()
SampQuery->getDetailedPlayers()
SampQuery->getRules()
SampQuery->getPing() - Not in Westie's API

Example | Output server info and basic players:
PHP код:
<?php
/**
 *
 * @author Edward McKnight (EM-Creations.co.uk)
 * This example assumes this file is in the same directory as the SampQuery class.
 */
        
require("SampQuery.class.php");
        
$query = new SampQuery("127.0.0.1"7777);
        
        if (
$query->connect()) { // If a successful connection has been made
            
            
print_r($query->getInfo()); // Print server info array
            
            
print_r($query->getBasicPlayers()); // Print basic players array, connection will time out if the player counter is above 100 and will return an empty array if no players are online
            
$query->close(); // Close the connection
        
} else {
            echo 
"Server did not respond!";
        }
?>
SampRcon functions:
SampRcon(server, port, password)
SampRcon->connect()
SampRcon->close()
SampRcon->getCommandList()
SampRcon->getServerVariables()
SampRcon->setWeather(weatherID=1)
SampRcon->setGravity(gravity=0.008)
SampRcon->ban(playerID)
SampRcon->kick(playerID)
SampRcon->banAddress(address)
SampRcon->unbanAddress(address)
SampRcon->reloadLog()
SampRcon->reloadBans()
SampRcon->say(message)
SampRcon->changeGameMode(gameMode)
SampRcon->setGameModeText(gameModeText) - Not in Westie's API
SampRcon->nextGameMode()
SampRcon->gmx() {same as SampRcon->nextGameMode()}
SampRcon->execConfig(config)
SampRcon->loadFilterscript(fs)
SampRcon->loadFS(fs) {same as SampRcon->loadFilterscript(fs)}
SampRcon->unloadFilterscript(fs)
SampRcon->unloadFS(fs) {same as SampRcon->unloadFilterscript(fs)}
SampRcon->reloadFilterscript(fs)
SampRcon->reloadFS(fs) {same as SampRcon->reloadFilterscript(fs)}
SampRcon->exitGame()
SampRcon->setHostName(hostName) - Not in Westie's API
SampRcon->setMapName(mapName) - Not in Westie's API
SampRcon->setTime(time) - Not in Westie's API
SampRcon->setURL(url) - Not in Westie's API
SampRcon->setPassword(password) - Not in Westie's API
SampRcon->removePassword() - Not in Westie's API
SampRcon->setRconPassword(password) - Not in Westie's API
SampRcon->disableRcon() - Not in Westie's API
SampRcon->enableQuery() - Not in Westie's API
SampRcon->disableQuery() - Not in Westie's API
SampRcon->enableAnnounce() - Not in Westie's API
SampRcon->disableAnnounce() - Not in Westie's API
SampRcon->setMaxNPCs(maxNPCs) - Not in Westie's API
SampRcon->call(command, delay)

Example | Output command list:
PHP код:
<?php
/**
 *
 * @author Edward McKnight (EM-Creations.co.uk)
 * This example assumes this file is in the same director as the SampRcon class.
 */
        
require("SampRcon.class.php");
        
$query = new SampRcon("127.0.0.1"7777"changeme1");
        
        if (
$query->connect()) { // If a successful connection has been made
            // Output command list
            
print_r($query->getCommandList());
            
            
$query->close(); // Close the connection
        
} else {
            echo 
"Server did not respond!";
        }
        
$query->close(); // Close the connection
?>
Example | Ban player:
PHP код:
<?php
/**
 *
 * @author Edward McKnight (EM-Creations.co.uk)
 * This example assumes this file is in the same directory as the SampRcon class.
 */
        
require("SampRcon.class.php");
        
$query = new SampRcon("127.0.0.1"7777"changeme1");
        
        if (
$query->connect()) { // If a successful connection has been made
            
$query->ban(1); // Ban player ID 1
            
$query->reloadBans(); // Reload the server's bans file
            
$query->close(); // Close the connection
        
} else {
            echo 
"Server did not respond!";
        }
        
$query->close(); // Close the connection
?>
Reply


Messages In This Thread
[PHP] Query and RCON API (24/07/2014) - by StatusRed - 30.06.2012, 14:52
Re: [PHP] Query and RCON API (30/06/2012) - by next-studio|TheKiller - 30.06.2012, 14:56
Re: [PHP] Query and RCON API (30/06/2012) - by StatusRed - 30.06.2012, 15:00
Re: [PHP] Query and RCON API (30/06/2012) - by SomebodyAndMe - 10.07.2012, 10:03
Re: [PHP] Query and RCON API (30/06/2012) - by StatusRed - 10.07.2012, 16:20
Re: [PHP] Query and RCON API (30/06/2012) - by SomebodyAndMe - 10.07.2012, 16:53
Re: [PHP] Query and RCON API (30/06/2012) - by StatusRed - 10.07.2012, 17:01
Re: [PHP] Query and RCON API (30/06/2012) - by SomebodyAndMe - 10.07.2012, 17:08
Re: [PHP] Query and RCON API (30/06/2012) - by StatusRed - 10.07.2012, 17:11
Re: [PHP] Query and RCON API (30/06/2012) - by SomebodyAndMe - 10.07.2012, 17:14
Re: [PHP] Query and RCON API (30/06/2012) - by iRaiDeN - 12.06.2014, 11:54
Re: [PHP] Query and RCON API (30/06/2012) - by StatusRed - 27.06.2014, 11:50

Forum Jump:


Users browsing this thread: 1 Guest(s)