Skip to content

ServerAuth Web API

Flavius12 edited this page May 26, 2015 · 13 revisions

Table of Contents

Basic Tutorial

In this tutorial you will check if a ServerAuth account exists

1. Create example.php file in your Web Server directory
2. Add ServerAuthWebAPI.php file in the same directory
3. Now add this code in example.php

<?php
//Include ServerAuth Web API
include 'ServerAuthWebAPI.php';
//Player to check
$player = "Steve";
//Initialize a ServerAuthWebAPI instance (put your ServerAuth MySQL data)
$api = new ServerAuthWebAPI("host", 3306, "username", "password", "serverauth", "srvauth_");
var_dump($api->isPlayerRegistered($player));
?>

ServerAuth Web API Constants

SUCCESS

Description:
Success
Value:
1

ERR_OUTDATED_WEBAPI

Description:
Outdated ServerAuthWebAPI error
Value:
2

ERR_OUTDATED_PLUGIN

Description:
Outdated ServerAuth plugin error
Value:
3

ERR_MYSQL

Description:
MySQL error
Value:
4

ServerAuth Web API Functions

ServerAuth Web API construct:

function __construct($host, $port, $username, $password, $database, $table_prefix)

Description:
Initialize a new ServerAuth Web API instance
Parameters:
$host MySQL database host
$port MySQL database port (default 3306)
$username MySQL database username
$password MySQL database password
$database MySQL ServerAuth database
$table_prefix ServerAuth MySQL database table prefix

Get Status:

int getStatus()

Description:
Initialize a new ServerAuth Web API instance.
Return:
SUCCESS, ERR_OUTDATED_WEBAPI, ERR_OUTDATED_PLUGIN or ERR_MYSQL

Get ServerAuth plugin version:

string|int getVersion()

Description:
Get ServerAuth plugin version.
Return:
The current version string on SUCCESS, otherwise the current status

Get ServerAuth plugin API version:

string|int getAPIVersion()

Description:
Get ServerAuth plugin version.
Return:
The current API version string on SUCCESS, otherwise the current status

Get ServerAuthWebAPI API version:

string getWebAPIVersion()

Description:
Get ServerAuthWebAPI version
Return:
The current ServerAuthWebAPI version string.

Get ServerAuth Password Hash:

string getPasswordHash()

Description:
Get ServerAuth Password Hash.
Return:
string

Get MySQL host:

string getHost()

Description:
Get MySQL host.
Return:
string

Get MySQL port:

int getPort()

Description:
Get MySQL port.
Return:
int

Get MySQL username:

string getUsername()

Description:
Get MySQL username.
Return:
string

Get MySQL password:

string getPassword()

Description:
Get MySQL password.
Return:
string

Get MySQL ServerAuth database name:

string getDatabaseName()

Description:
Get MySQL ServerAuth database name.
Return:
string

Get MySQL ServerAuth table prefix:

string getTablePrefix()

Description:
Get MySQL ServerAuth table prefix
Return:
string

Get Database:

mysqli|boolean getDatabase()

Description:
Get ServerAuth MySQLi instance.
Return:
mysqli on success
false on MySQL connection failure

Check if a player is registered to ServerAuth:

boolean|int isPlayerRegistered($player)

Description:
Check if a player is registered to ServerAuth.
Parameters:
$player The player name
Return:
true or false on SUCCESS, otherwise the current status

Get player data:

array|int getPlayerData($player)

Description:
Get player data.
Parameters:
$player The player name
Return:
The array of player data on SUCCESS, otherwise the current status

Register a player to ServerAuth:

int|boolean registerPlayer($player, $password, $ip, $firstlogin, $lastlogin)

Description:
Register a player to ServerAuth.
Parameters:
$player The player name $password The player password $ip The player IP $firstlogin (UNIX timestamp) The player first login $lastlogin (UNIX timestamp) The player last login Return:
true on SUCCESS or false if the player is already registered, otherwise the current status

Unregister a player:

int|boolean unregisterPlayer($player)

Description:
Unregister a player from ServerAuth.
Parameters:
$player The player name
Return:
true on SUCCESS or false if the player is not registered, otherwise the current status

Change player password:

int|boolean changePlayerPassword($player, $new_password)

Description:
Change player password.
Parameters:
$player The player name
$new_password The new password
Return:
true on SUCCESS or false if the player is not registered, otherwise the current status