Version: 1.0 (30/06/2012)
Download
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.
Additional credits: Westie (for the original PHP SA-MP API and inspiration for this API)
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
/**
*
* @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
/**
*
* @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
// 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
/**
*
* @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
?>