Machines

API Documentation

\GSPPanel\Machines

This class allows interaction with machines

Methods

AddIPs(array $params = array()) : array

Add IPs to the machine

$params must contain the following:

  • sid: The server ID
  • ips: Array of IPs

Returns one of the following in an array format:

  • error
    • -1 - No server ID provided
    • -2 - No ips provided
    • 0 - Added successfully
Parameters
NameTypeDescription
$paramsarray
Returns
TypeDescription
array
AddMachine(array $params) : array

Adds a machine to the database

$params requires the following:

  • alias: The name of the server(REQUIRED)
  • main_ip: The main IP address of the server(REQUIRED)
  • file_location: The location of game server files(REQUIRED if game_server is 1)
  • userfile_location: The location for user installs to be placed(REQUIRED if game_server is 1)
  • backupfile_location: The location to store user game backups
  • listenport: The port the backend should listen on(REQUIRED if game_server is 1)
  • os: The operating system of the server(REQUIRED)
  • location: The location of the server
  • ftpport: The port the FTP server should listen on(0 disables the ftp server)
  • httpport: The port the HTTP server should listen on(0 disables the http server)
  • game_server: 0/1 to enable this server to host game servers
  • slots_quota: The maximum amount of slots this server can hold
  • servers_quota: The maximum amount of game servers this server can hold
  • debugging: Enables backend debugging on the machine
  • fileserver: The machines ID to download files from
  • diskthrottle: Only applies to Linux servers, the command to run when copy, delete, and extract commands are ran (e.g ionice -c2 -n7)
  • uid: The user id that owns this server, if nothing is specified this server will be a shared server

Returns one of the following in an array format:

  • error
    • -1 - License limitation reached
    • -2 - Field left empty
    • 0 - Added successfully
  • sid: The new servers id
Parameters
NameTypeDescription
$paramsarray
Returns
TypeDescription
array
AddUser(array $params) : void

Add a user to a machine if it doesn't already exist, this only works on Linux

$params must contain the following:

  • sid: The server ID
  • username: Username to add
  • password: Password for the user
  • homedirectory: The user's home directory on the file system

Returns one of the following in an array format:

  • error
    • -1 - Missing sid
    • -2 - Missing username
    • -3 - Missing homedirectory
    • -4 - User already exists
    • -5 - Error adding user
    • 0 - User added
Parameters
NameTypeDescription
$paramsarray
Count() : integer

Returns the number of machines

Returns
TypeDescription
integer
CreateHTTPData(integer $sid) : array

Create the data file for the HTTP server

Returns one of the following in an array format:

  • error
    • -1 - No server ID supplied
    • -2 - Unable to connect to server
    • -3 - Server needs to be updated
    • -4 - Server not found in database
    • 0 - File written
Parameters
NameTypeDescription
$sidinteger

Server's id to scan the game on

Returns
TypeDescription
array
Details
Access
public  
DeleteIP(integer $ipid) : array

Delete an IP from the machine

Returns one of the following in an array format:

  • error
    • -1 - IP has services
    • -2 - IP not found
    • 0 - IP Removed
Parameters
NameTypeDescription
$ipidinteger

The IPs ID to delete

Returns
TypeDescription
array
DeleteMachine(array $params) : array

Deletes a machine from the database

$params requires the following:

  • sid: The server id to delete(REQUIRED)

Returns one of the following in an array format:

  • error
    • -1 - No server id provided
    • -2 - Server has user game servers installed
    • -3 - Unable to find server in database
    • -4 - Machine is set as the scheduling host
    • 0 - Deleted successfully
Parameters
NameTypeDescription
$paramsarray
Returns
TypeDescription
array
DownloadFile(integer $sid, string $url, string $localfile) : array

Download File to the machine

Returns one of the following in an array format:

  • error
    • -1 - No server ID supplied
    • -2 - No URL supplied
    • -3 - No localfile save path supplied
    • -4 - Server not found in database
    • -5 - Server needs to be updated
    • -6 - Unable to connect to server
    • 0 - Download Started
  • result: result of the downloadfile command
  • taskid: The taskid relating to the download
Parameters
NameTypeDescription
$sidinteger

Server's id to scan the game on

$urlstring

URL to download from

$localfilestring

Location to save file

Returns
TypeDescription
array
Details
Access
public  
EditMachine(array $params) : array

Edits a machine in the database.

Changing listenport or ftpport will require the backend to be manually restarted

$params requires the following:

  • sid: The server's id to edit(REQURIED)
  • alias: The name of the server(REQUIRED)
  • main_ip: The main IP address of the server(REQUIRED)
  • file_location: The location of game server files(REQUIRED if game_server is 1)
  • userfile_location: The location for user installs to be placed(REQUIRED if game_server is 1)
  • backupfile_location: The location to store user game backups
  • listenport: The port the backend should listen on(REQUIRED if game_server is 1)
  • os: The operating system of the server(REQUIRED)
  • location: The location of the server
  • ftpport: The port the FTP server should listen on(0 disables the ftp server)
  • httpport: The port the HTTP server should listen on(0 disables the http server)
  • game_server: 0/1 to enable this server to host game servers
  • slots_quota: The maximum amount of slots this server can hold
  • servers_quota: The maximum amount of game servers this server can hold
  • debugging: Enables backend debugging on the machine
  • fileserver: The machines ID to download files from
  • diskthrottle: Only applies to Linux servers, the command to run when copy, delete, and extract commands are ran (e.g ionice -c2 -n7)
  • uid: The user id that owns this server, if nothing is specified this server will be a shared server

Returns one of the following in an array format:

  • error
    • -1 - No server id provided
    • -2 - Field left empty
    • -3 - Unable to change machine owner, machine has gameservers that belong to other users
    • 0 - Saved successfully
Parameters
NameTypeDescription
$paramsarray
Returns
TypeDescription
array
FindPort(integer $ipid, integer $default, integer $increment) : integer

Finds a usable port on that specified ip.

Does a database search and attempts to connect to the ip/port via sockets

Parameters
NameTypeDescription
$ipidinteger

The ipid to scan for an available port on

$defaultinteger

The port to start the scan on

$incrementinteger

The increment to increase $default by if the port is taken

Returns
TypeDescription
integer
GameLocationIPList(array $params = array()) : array

This returns an array of online servers at the specified location.

This function is mainly used for the dropdown lists of locations, servers, and ips to install a users server to

$params can accept the following variables:

  • location: Location to return a list for
  • gid: Only list machines with the specified game
  • offline: Set to true to include offline machines in the list, default is false
  • iplist: true/false to return a list of valid ips at the location, per available machine
  • currentip: The ipid of the current gameserver
  • dedicatedip: If set to 1 it will only return IPs that do not have game servers, default is 0
  • uid: Look for servers that belong to the specified user

Returns an array depending on what was requested

  • It's best to print_r the array to see the variables for your query
  • View admin/manageusergames/ajax-location.tpl to see how the information is handled
Parameters
NameTypeDescription
$paramsarray
Returns
TypeDescription
array
GetIP(integer $ipid, boolean $alias = false, string $type = "external") : string

Returns an ip address (External or internal) or an alias from an ipid

Parameters
NameTypeDescription
$ipidinteger

The ipid to convert

$aliasboolean

Return the domain alias instead of the IP (if set)

$typestring

The type of ip to return(internal/external)

Returns
TypeDescription
string
GetIPs(integer $sid) : array

Returns an array of IPs from the server.

The array contains "ip" and "used"(yes/no)

Parameters
NameTypeDescription
$sidinteger

The server id to retrieve ips from

Returns
TypeDescription
array
GetMachineInfo(integer $sid) : array

Returns an array of machine information

Parameters
NameTypeDescription
$sidinteger

The servers id

Returns
TypeDescription
array
GetOS(integer $sid) : string

Gets the OS of the specified machine

Parameters
NameTypeDescription
$sidinteger

Server's ID to get OS for

Returns
TypeDescription
stringLinux or Windows
GetUsedQuota(string $type, integer $machineid, integer $gid = null) : integer

Returns the amount of used slots or gameservers

Parameters
NameTypeDescription
$typestring

The type you want to return, can be "slots" or "servers"

$machineidinteger

The server's id you want to return slots for

$gidinteger

The game id to return the quota for

Returns
TypeDescription
integer
LeastUsedIP(integer $sid) : integer

Returns the ipid of the least used ip on the server that is not dedicated

Parameters
NameTypeDescription
$sidinteger

Server's id

Returns
TypeDescription
integer
ListIPs(integer $sid) : array

Returns an array of IPs on the machine

Parameters
NameTypeDescription
$sidinteger

The servers id

Returns
TypeDescription
array
ListMachines(array $params = array()) : array

Returns an array of machines

$params can use the following (optional):

  • os: 0 for Windows, 1 for Linux
  • gameserver: 0 for machines that won't host games, 1 for machines that can host games
  • uid: List machines that are assigned to the specified user
Parameters
NameTypeDescription
$paramsarray
Returns
TypeDescription
array
RemoveUser(array $params) : void

Removes a user account from the specified machine, this only works on Linux

$params must contain the following:

  • sid: The server ID
  • username: Username to remove

Returns one of the following in an array format:

  • error
    • -1 - Missing sid
    • -2 - Missing or invalid username
    • -3 - User not found on server
    • -4 - Error removing user
    • 0 - User removed
Parameters
NameTypeDescription
$paramsarray
SendCommand(integer $sid, string $command, boolean $response, string $user = "", string $pingback = "") : mixed

Sends a command to the server

Returns either an integer error, false, or the server's response:

  • -1 - Server not found in database
  • -2 - Invalid version, might require a backend update to match frontend version
  • false - Unable to connect to the server
  • Server response
Parameters
NameTypeDescription
$sidinteger

The server id to run the command on

$commandstring

The command to send to the server

$responseboolean

True/False to wait and receive a response

$userstring

The username to run the command as(Linux only)

$pingbackstring

The URL to ping back to once the task is completed

Returns
TypeDescription
mixed
SystemInfo(array $params) : array

Retrieves system infomation such as operating system, memory, hdd space, and backend version

$params requires the following:

  • sid: The server id to get information from(REQUIRED)

Returns one of the following in an array format:

  • error
    • -1 - No server id provided
    • -2 - Server is offline
    • -3 - Server does not exist
    • -5 - Backend upgrade required
    • 0 - Queried successfully
  • os: Array of operating system information(name, edition, servicepack)
  • memory: Array of memory information(free, total)
  • hd: The hard drive information(drive, freespace, totalsize, percentage used)
  • version: The backend version
Parameters
NameTypeDescription
$paramsarray
Returns
TypeDescription
array
Update(integer $sid) : boolean

Updates the backend with the version required by the frontend

Parameters
NameTypeDescription
$sidinteger

The server's id you want to update

Returns
TypeDescription
boolean
VerifyConnection(integer $sid) : integer

Verifies the connection to the server

Returns one of the following:

  • 1 - Online
  • 0 - Offline or not in database
  • -1 - Invalid version, might require a backend update to match frontend version
Parameters
NameTypeDescription
$sidinteger

Server's id to check

Returns
TypeDescription
integer
VerifyGames(array $params) : array

Lists the games on the specified server

$params requires the following:

  • sid: The server id to scan games on(REQUIRED)
  • expiretime: The time in seconds for that cached games expire(Optional, default is 86400, 1 day)
  • forceupdate: Defaults to retrieving information from cache, set to true to get a live update(Optional)

Returns one of the following in an array format:

  • error
    • -1 - No server id provided
    • -2 - Server is offline
    • -3 - Server does not exist
    • -4 - No games for that OS (REMOVED)
    • -5 - Invalid backend version
    • 0 - Queried successfully
  • gamelist: Array of game information(game, folder, exists(boolean), size, enabled(boolean), quota)
Parameters
NameTypeDescription
$paramsarray
Returns
TypeDescription
array
canHostGame(integer $gid, integer $sid) : boolean

Returns true if the machine can host the specified game, this does not check quotas

False will be returned if:

  • The game is not enabled for the operating system the machine is running
  • The game files don't exist
  • The game files cannot be downloaded from the fileserver, if setup
Parameters
NameTypeDescription
$gidinteger
$sidinteger
Returns
TypeDescription
boolean
doesUserOwn(array $params) : boolean

Determine if the user owns the specified server or the server for the specified gameserver

$params can use the following:

  • uid: User id to match (MANDATORY)
  • sid: Server ID to match user to
  • ugid: Does user own the server running this gameserver
Parameters
NameTypeDescription
$paramsarray
Returns
TypeDescription
boolean
getGameCacheData(integer $gid, integer $sid) : array

Returns an array of game information from the cache

Returned array contains: gid, size, exists, enabled

Parameters
NameTypeDescription
$gidinteger

Game ID

$sidinteger

Machine ID

Returns
TypeDescription
array
hasGameFiles(array $params) : boolean

Returns true if the game files exist on the specified server, will use cache if it's not older then 24 hours

$params can take the following:

  • sid: The machines ID (REQURIED)
  • gid: The games ID (REQUIRED)
  • os: The OS to check files for (e.g. do we want to see if a Windows server has the files for Linux servers so we can download them)
  • skipcache: true/false, will automatically be skipped if OS is specified
  • expirecache: How long is the cache valid for (default 86400)
Parameters
NameTypeDescription
$paramsarray
Returns
TypeDescription
boolean
isGameEnabled(integer $gid, integer $sid) : boolean

Returns true if the game is enabled on the specified machine

Parameters
NameTypeDescription
$gidinteger

Game ID

$sidinteger

Machine ID

Returns
TypeDescription
boolean
isIPUsed(integer $ipid) : boolean

Check if an IP is in use by a game server

Parameters
NameTypeDescription
$ipidinteger
Returns
TypeDescription
boolean
isPortUsed(integer $ipid, integer $port) : boolean

Checks if a port is used Returns true if its used, false if its not

Parameters
NameTypeDescription
$ipidinteger

The ipid to check

$portinteger

The port to check

Returns
TypeDescription
boolean
Documentation was generated by phpDocumentor 2.9.0.