Added full source code
This commit is contained in:
commit
33f8586698
1377 changed files with 123808 additions and 0 deletions
87
scripts/game/main/account/library.inc
Normal file
87
scripts/game/main/account/library.inc
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
class main_account_library {
|
||||
var $index = array(
|
||||
'createAccount',
|
||||
'getAccounts',
|
||||
'getKickList',
|
||||
'getLanguage',
|
||||
'getQuitCountdown',
|
||||
'getUserName',
|
||||
'isLeech',
|
||||
'log',
|
||||
'requestKick',
|
||||
'setQuitCountdown',
|
||||
'terminate'
|
||||
);
|
||||
|
||||
function main_account_library($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function isOnline($uid) {
|
||||
$q = $this->db->query("SELECT COUNT(*) FROM account WHERE id=$uid AND last_login IS NOT NULL AND (last_logout IS NULL OR last_logout<last_login)");
|
||||
list($online) = dbFetchArray($q);
|
||||
return ($online == 1);
|
||||
}
|
||||
|
||||
function lastOnline($userID) {
|
||||
$q = $this->db->query("SELECT last_login, last_logout FROM account WHERE id = $userID");
|
||||
list($login, $logout) = dbFetchArray($q);
|
||||
|
||||
if (is_null($logout) || $logout < $login) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $logout;
|
||||
}
|
||||
|
||||
|
||||
function cancelQuitCountdown($uid) {
|
||||
$this->db->query("UPDATE account SET quit_ts=NULL,reason=NULL WHERE id=$uid");
|
||||
}
|
||||
|
||||
|
||||
function isAdmin($uid) {
|
||||
$q = $this->db->query("SELECT admin FROM account WHERE id=$uid");
|
||||
if ($q && dbCount($q) == 1) {
|
||||
list($a) = dbFetchArray($q);
|
||||
} else {
|
||||
$a = 'f';
|
||||
}
|
||||
return ($a == 't');
|
||||
}
|
||||
|
||||
|
||||
function getUser($name) {
|
||||
$i = (int) $name;
|
||||
if ((string)$i == (string)$name) {
|
||||
$qs = "id=$name";
|
||||
} else {
|
||||
$qs = "LOWER(name)=LOWER('" . addslashes($name) . "')";
|
||||
}
|
||||
$q = $this->db->query("SELECT * FROM account WHERE $qs");
|
||||
if (!($q && dbCount($q) == 1)) {
|
||||
return null;
|
||||
}
|
||||
return dbFetchHash($q);
|
||||
}
|
||||
|
||||
|
||||
function getKickRequest($kid) {
|
||||
$q = $this->db->query("SELECT * FROM adm_kick WHERE id=$kid");
|
||||
if (!($q && dbCount($q) == 1)) {
|
||||
return null;
|
||||
}
|
||||
return dbFetchHash($q);
|
||||
}
|
||||
|
||||
|
||||
function kickRequestHandled($kid, $admin, $accepted) {
|
||||
$this->db->query("UPDATE adm_kick SET examined_by=$admin,status='" . ($accepted ? "Y" : "N") . "' WHERE id=$kid");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
58
scripts/game/main/account/library/createAccount.inc
Normal file
58
scripts/game/main/account/library/createAccount.inc
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
class main_account_createAccount {
|
||||
|
||||
function main_account_createAccount($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
function run($user, $password, $email, $lang, $pName) {
|
||||
$conf = substr(md5(uniqid(rand())), 0, 16);
|
||||
$asu = addslashes($user);
|
||||
|
||||
$id = $this->db->query(
|
||||
"INSERT INTO account(name,email,password,status,conf_code) "
|
||||
. "VALUES('$asu','$email','".addslashes($password)."','NEW','$conf')"
|
||||
);
|
||||
if (!$id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->db->query(
|
||||
"INSERT INTO pass_change (account, old_pass, new_pass) "
|
||||
. "VALUES($id, '', '" . addslashes($password) . "')"
|
||||
);
|
||||
$this->db->query("INSERT INTO credits (account) VALUES ($id)");
|
||||
|
||||
$this->db->query("INSERT INTO user_preferences VALUES('language','main',$id,'$lang');");
|
||||
$this->db->query(
|
||||
"INSERT INTO account_log(tracking,account,ip_addr,action) VALUES("
|
||||
. tracking::$dbId . ",$id,'".$_SERVER['REMOTE_ADDR']."','CREATE')"
|
||||
);
|
||||
|
||||
// Insert the planet in the registration queue for the default game
|
||||
$game = config::getDefaultGame();
|
||||
$this->db->query(
|
||||
"INSERT INTO reg_queue (account, game) "
|
||||
. "VALUES ($id, '{$game->name}')"
|
||||
);
|
||||
$game->getLib()->call('preRegister', $id, $pName);
|
||||
|
||||
$main = $this->lib->game->getLib('main');
|
||||
$rv = $main->call('sendMail', "mail-reg.$lang.txt", $email, array(
|
||||
"USER" => $user,
|
||||
"PASS" => $password,
|
||||
"CCODE" => $conf
|
||||
));
|
||||
|
||||
// If sending the mail failed, rollback the transaction
|
||||
if (!$rv) {
|
||||
$this->db->end(true); $this->db->begin();
|
||||
}
|
||||
|
||||
return $rv;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
27
scripts/game/main/account/library/getAccounts.inc
Normal file
27
scripts/game/main/account/library/getAccounts.inc
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
class main_account_getAccounts {
|
||||
|
||||
function __construct($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
function run() {
|
||||
$q = $this->db->query("SELECT COUNT(*) FROM account WHERE status IN ('STD','VAC')");
|
||||
if (!($q && dbCount($q))) {
|
||||
return null;
|
||||
}
|
||||
list($total) = dbFetchArray($q);
|
||||
|
||||
$q = $this->db->query("SELECT COUNT(*) FROM account WHERE status IN ('STD','VAC') AND last_login IS NOT NULL AND (last_logout IS NULL OR last_logout<last_login)");
|
||||
if (!($q && dbCount($q))) {
|
||||
return null;
|
||||
}
|
||||
list($online) = dbFetchArray($q);
|
||||
|
||||
return array($total, $online);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
24
scripts/game/main/account/library/getKickList.inc
Normal file
24
scripts/game/main/account/library/getKickList.inc
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
class main_account_getKickList {
|
||||
|
||||
function main_account_getKickList($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run() {
|
||||
$lists = array(array(),array(),array());
|
||||
$types = array("P" => 0, "Y" => 1, "N" => 2);
|
||||
|
||||
$q = $this->db->query("SELECT * FROM adm_kick");
|
||||
while ($r = dbFetchHash($q)) {
|
||||
array_push($lists[$types[$r['status']]], $r);
|
||||
}
|
||||
|
||||
return $lists;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
22
scripts/game/main/account/library/getLanguage.inc
Normal file
22
scripts/game/main/account/library/getLanguage.inc
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
class main_account_getLanguage {
|
||||
|
||||
function main_account_getLanguage($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($id) {
|
||||
$ql = $this->db->query("SELECT value FROM user_preferences WHERE id='language' AND version='main' AND account=$id");
|
||||
if ($ql && dbCount($ql)) {
|
||||
list($l) = dbFetchArray($ql);
|
||||
} else {
|
||||
$l = 'en';
|
||||
}
|
||||
return $l;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
22
scripts/game/main/account/library/getQuitCountdown.inc
Normal file
22
scripts/game/main/account/library/getQuitCountdown.inc
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
class main_account_getQuitCountdown {
|
||||
|
||||
function main_account_getQuitCountdown($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($uid) {
|
||||
$q = $this->db->query("SELECT quit_ts FROM account WHERE id=$uid");
|
||||
if ($q && dbCount($q) == 1) {
|
||||
list($quit) = dbFetchArray($q);
|
||||
} else {
|
||||
$quit = null;
|
||||
}
|
||||
return $quit;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
25
scripts/game/main/account/library/getUserName.inc
Normal file
25
scripts/game/main/account/library/getUserName.inc
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
class main_account_getUserName {
|
||||
var $userNames = array(); // FIXME: can be cached
|
||||
|
||||
function main_account_getUserName($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($uid) {
|
||||
if (!is_null($this->userNames[$uid])) {
|
||||
return $this->userNames[$uid];
|
||||
}
|
||||
$q = $this->db->query("SELECT name FROM account WHERE id=$uid");
|
||||
if (!($q && dbCount($q))) {
|
||||
return null;
|
||||
}
|
||||
list($this->userNames[$uid]) = dbFetchArray($q);
|
||||
return $this->userNames[$uid];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
32
scripts/game/main/account/library/isLeech.inc
Normal file
32
scripts/game/main/account/library/isLeech.inc
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
class main_account_isLeech {
|
||||
|
||||
function __construct($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
function run($id) {
|
||||
$q = $this->db->query("SELECT UNIX_TIMESTAMP(NOW())-donated FROM pp_history ORDER BY donated ASC LIMIT 1");
|
||||
if (!($q && dbCount($q))) {
|
||||
return true;
|
||||
}
|
||||
list($interval) = dbFetchArray($q);
|
||||
if ($interval == 0) {
|
||||
return true;
|
||||
}
|
||||
$days = $interval / 86400;
|
||||
|
||||
$q = $this->db->query("SELECT SUM(amount) FROM pp_history WHERE account=$id");
|
||||
if (!($q && dbCount($q))) {
|
||||
return false;
|
||||
}
|
||||
list($sum) = dbFetchArray($q);
|
||||
$sum = is_null($sum) ? 0 : $sum;
|
||||
|
||||
return ($sum / $days <= 0.05);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
63
scripts/game/main/account/library/log.inc
Normal file
63
scripts/game/main/account/library/log.inc
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
/** This function adds an entry to the account_log table. The $uid parameter
|
||||
* indicates the user's database identifier; the $what parameter indicates
|
||||
* the action that warrants the log entry. $what can take the following
|
||||
* values:
|
||||
*
|
||||
* [Ii] User has logged in
|
||||
* [Oo] User has logged out
|
||||
* [Cc] The account has just been created
|
||||
* [Vv] User has validated his account using his confirmation code
|
||||
* [Qq] User has quit the game
|
||||
* VS User has entered vacation mode
|
||||
* VE User has left vacation mode
|
||||
*/
|
||||
|
||||
class main_account_log {
|
||||
|
||||
function main_account_log($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($uid, $what) {
|
||||
if (class_exists('tracking') && !is_null(tracking::$dbId)) {
|
||||
$track = tracking::$dbId;
|
||||
} else {
|
||||
$track = 'NULL';
|
||||
}
|
||||
|
||||
if (gettype($_SERVER['REMOTE_ADDR']) == 'NULL') {
|
||||
$addr = 'AUTO';
|
||||
} else {
|
||||
$addr = addslashes($_SERVER['REMOTE_ADDR']);
|
||||
}
|
||||
|
||||
switch ($what) :
|
||||
case 'I': case 'i':
|
||||
$w = 'IN'; break;
|
||||
case 'O': case 'o':
|
||||
$w = 'OUT'; break;
|
||||
case 'C': case 'c':
|
||||
$w = 'CREATE'; break;
|
||||
case 'V': case 'v':
|
||||
$w = 'CONF'; break;
|
||||
case 'Q': case 'q':
|
||||
$w = 'QUIT'; break;
|
||||
case 'Q': case 'q':
|
||||
$w = 'QUIT'; break;
|
||||
case 'VS': case 'vs':
|
||||
$w = 'VSTART'; break;
|
||||
case 'VE': case 've':
|
||||
$w = 'VEND'; break;
|
||||
default:
|
||||
return;
|
||||
endswitch;
|
||||
|
||||
$this->db->query("INSERT INTO account_log(tracking,account,ip_addr,action) VALUES ($track,$uid,'$addr','$w')");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
24
scripts/game/main/account/library/requestKick.inc
Normal file
24
scripts/game/main/account/library/requestKick.inc
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
class main_account_requestKick {
|
||||
|
||||
function main_account_requestKick($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($admin, $account, $reason) {
|
||||
$q = $this->db->query("SELECT * FROM adm_kick WHERE to_kick=$account AND status<>'N'");
|
||||
if (!$q || dbCount($q)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$id = $this->db->query("INSERT INTO adm_kick (to_kick,requested_by,requested_at,reason) "
|
||||
. "VALUES ($account,$admin," . time() . ",'" . addslashes($reason) . "')");
|
||||
|
||||
return !!$id;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
23
scripts/game/main/account/library/setQuitCountdown.inc
Normal file
23
scripts/game/main/account/library/setQuitCountdown.inc
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
class main_account_setQuitCountdown {
|
||||
|
||||
function main_account_setQuitCountdown($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
function run($uid, $reason) {
|
||||
$reason = trim(preg_replace('/\s+/', ' ', $reason));
|
||||
if ($reason == '') {
|
||||
$rqs = "";
|
||||
} else {
|
||||
$rqs = ",reason='" . addslashes($reason) . "'";
|
||||
}
|
||||
$this->db->query("UPDATE account SET quit_ts=UNIX_TIMESTAMP(NOW())$rqs WHERE id=$uid AND status='STD'");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
32
scripts/game/main/account/library/terminate.inc
Normal file
32
scripts/game/main/account/library/terminate.inc
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
class main_account_terminate {
|
||||
|
||||
function main_account_terminate($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($uid, $status, $reason = null) {
|
||||
foreach (config::getGames() as $game) {
|
||||
if ($game->name == 'main' || $game->status() == 'FINISHED') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$lib = $game->getLib();
|
||||
$pid = $lib->call('doesUserPlay', $uid);
|
||||
if (is_null($pid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$lib->call('leaveGame', $pid, $status);
|
||||
}
|
||||
|
||||
$qs = is_null($reason) ? "" : (",reason='" . addslashes($reason) . "'");
|
||||
$this->db->query("UPDATE account SET status='$status',quit_ts=NULL,vac_start=NULL$qs WHERE id=$uid");
|
||||
$this->lib->call('log', $uid, 'q');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Reference in a new issue