Skip to content

Demon0no/NetspherePiratesWeb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

NetspherePiratesWeb

Manage NetspherePirates accounts through PHP.

Requirements

PHP 7 or higher (or for servers where only PHP 5.X is available: https://github.com/paragonie/random_compat )
PDO compatibility

Basic Example

// require_once 'include/random_compat/random.php'; // only needed if you run php version 5.X

require_once 'include/NetspherePiratesWeb/Autoloader.php';
use \NetspherePiratesWeb\AuthServer as AuthServer;
use \NetspherePiratesWeb\GameServer as GameServer;
use \NetspherePiratesWeb\Database as Database;

$auth_database = new Database(
	'HOST_HERE',
	'AUTH_DATABASE_HERE',
	'DATABASE_USER_HERE',
	'PASSWORD_HERE'
);

$game_database = new Database(
	'HOST_HERE',
	'GAME_DATABASE_HERE',
	'DATABASE_USER_HERE',
	'PASSWORD_HERE'
);

$auth_server = new AuthServer($auth_database);
$game_server = new GameServer($game_database);

Create an account

With nickname...

$auth_server->create_account('username', 'password', 'nickname');

...or without (so the user can choose his/her nickname on first ingame login)

$auth_server->create_account('username', 'password');

The function returns either the new account object, or NULL (if an account with the username already exists).

Get account info

By id...

$account = $auth_server->get_account_by_id(1);

...or by username

$account = $auth_server->get_account_by_username('EpitaphHaseo');

Then you can get the values like this

$account->id();
$account->username();
$account->nickname();
$account->password(); // salted and hashed
$account->salt(); // the salt used in the password
$account->security_level(); // one of the values in \NetspherePiratesWeb\Constants::$security_levels

If you want to check the password of a user (in example for a login form) you can use the following function

$account->check_password('asdf123');

It returns true if the password is correct, or false if it isn't. Easy, right?

Get player info

$player = $game_server->get_player_by_id(1);

$player->id();
$player->tutorial_state();
$player->level();
$player->total_experience();
$player->pen();
$player->ap();
$player->coins1();
$player->coins2();
$player->current_character_slot();

Releases

No releases published

Packages

No packages published

Languages