$group = $_REQUEST['group']; } else { throw new Exception('ERROR NO GROUP SPECIFIED.'); } if (isset($_REQUEST['key'])) { $key = $_REQUEST['key']; } else { throw new Exception('ERROR NO KEY SPECIFIED.'); } if (isset($_REQUEST['player_data'])) { $str_player_data = $_REQUEST['player_data']; $new_player_data = json_decode($str_player_data, true); } else { throw new Exception('ERROR NO PLAYER DATA SPECIFIED.'); } $full_player_data = get_player_data($group, null, 0); $old_player_data = $full_player_data[$key]; // If we don't have existing data, use an empty array. if (!isset($old_player_data)) { $old_player_data = array(); } // Merge the new player data into the old player data. $merged_player_data = array_merge($old_player_data, $new_player_data); // Store the server timestamp. $dateNow = new DateTime(); $merged_player_data['last_update_time'] = $dateNow->format(__DATE_FORMAT__); $full_player_data[$key] = $merged_player_data; $result['data']['player_data'] = $merged_player_data; set_player_data($group, $full_player_data); } catch (Exception $e) { $result['error'] = $e->getMessage();
function check_login($player_id, $session_id) { global $db, $db_prefix; //this function is run on every logged-in page so we'll clean up using this... $remove = $db->Prepare("DELETE FROM {$db_prefix}sessions WHERE expiry < ?"); $time_max = time() + 900; //if a session is due to expire within 15 minutes-we'll kill it. $res = $db->Execute($remove, array($time_max)); $sql = $db->Prepare("SELECT expiry FROM {$db_prefix}sessions WHERE sesskey = ?"); $result = $db->Execute($sql, array($session_id)); db_op_result($result, __LINE__, __FILE__); $data = $result->fields; if ($data['expiry'] > 0) { get_player_data($player_id); $update = $db->Prepare("UPDATE {$db_prefix}players SET last_update=NOW() where player_id=?"); $result = $db->Execute($update, array($player_id)); db_op_result($result, __LINE__, __FILE__); return true; } else { return false; } }
$data = "Login Error attempted login with username " . $_POST['username'] . " and password " . $_POST['password'] . " from IP {$ip} at " . date("Y-m-d H:i:s") . "."; Adminlog(LOGIN_ERROR, $data); header("Location: index.php"); die; } if ($data['active'] == "0" && $validation == 1) { $errors[$i] = $MSG_LANG_LOGIN['not_validated']; $i++; $smarty->assign('errors', $errors); $smarty->assign('title2', "Email Confirmation"); $smarty->display("{$template_set}/activate_account.php"); die; } if (empty($errors)) { //OK we should be fine for login, user and password match up... $res = get_player_data($data['player_id']); if (!$res) { adminlog(3000, "Function get_player_data Failed! {$ip}" . date("Y-m-d H:i:s")); header("Location: index.php"); } if (0) { //OK I'm leaving it here for now just in case, but function seems to work perfectly //and the session should maintain state from this point on. so if it works correctly, this //shit can be safely deleted within the if(0){brackets} //get the user data from db here and assign necessary stuff to Session $user_array = array($data['player_id']); $user = $db->Prepare("SELECT player_id,username FROM {$db_prefix}players WHERE player_id=?"); $query = $db->Execute($user, $user_array); db_op_result($query, __LINE__, __FILE__); $user_data = $query->fields; //get preferences
<?php header('Access-Control-Allow-Origin: *'); if (!defined('__IS_LIVE__')) { require_once './CONFIG.php'; } $result = array(); //$result['server_time'] = (new DateTime())->format(__DATE_FORMAT__); $result['data'] = array(); $result['error'] = null; try { $group = null; $timeout = 0; $key = null; if (isset($_REQUEST['group'])) { $group = $_REQUEST['group']; } else { throw new Exception('ERROR NO GROUP SPECIFIED.'); } if (isset($_REQUEST['timeout'])) { $timeout = (int) $_REQUEST['timeout']; } if (isset($_REQUEST['key'])) { $key = $_REQUEST['key']; } $player_data = get_player_data($group, $key, $timeout); $result['data']['player_data'] = $player_data; } catch (Exception $e) { $result['error'] = $e->getMessage(); } echo json_encode($result);