From 309f1df3766b1d8aee35b50219ce341c7874425a Mon Sep 17 00:00:00 2001 From: Astrologies Date: Tue, 21 Dec 2021 03:24:08 -0500 Subject: [PATCH] Games\Game Impl --- globals/Dependencies/Games/Game.php | 223 ++++++++++++++++- globals/functions.php | 285 +--------------------- html/Game/Join.php | 2 +- html/Game/PlaceLauncher.php | 15 +- html/games/config.php | 6 +- html/games/pbs/config.php | 8 +- html/games/view.php | 3 +- html_admin/lua-executer/activeJobs.php | 3 +- html_admin/lua-executer/executeScript.php | 3 +- html_api/game/info.php | 5 +- html_api/game/jobList.php | 5 +- html_api/game/pbs/configure.php | 21 +- html_api/game/pbs/users.php | 5 +- html_api/games/sitegames.php | 5 +- html_api/user/games/recents.php | 5 +- 15 files changed, 287 insertions(+), 307 deletions(-) diff --git a/globals/Dependencies/Games/Game.php b/globals/Dependencies/Games/Game.php index 25ee396..e90ad68 100644 --- a/globals/Dependencies/Games/Game.php +++ b/globals/Dependencies/Games/Game.php @@ -6,15 +6,42 @@ namespace Alphaland\Games { + use Alphaland\Assets\Asset; + use Alphaland\Grid\RccServiceHelper; + use Exception; use PDO; class Game { + public static function AllocatePort() //allocs a port between 50000 - 60000, verifies the port isn't in use by another game server + { + $port = 0; + do { + $port = rand(50000,60000); //port range forwarded on the server side (support up to 10000 jobs) + $s = $GLOBALS['pdo']->prepare("SELECT * FROM `open_servers` WHERE `port` = :p AND `status` < 2"); + $s->bindParam(":p", $port, PDO::PARAM_STR); + $s->execute(); + } while ($s->fetchColumn() != 0); + return $port; + } + + public static function GenerateJobId() + { + $jobid = ""; + do { + $jobid = gen_uuid(); + $jobcheck = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM `open_servers` WHERE `jobid` = :u"); + $jobcheck->bindParam(":u", $jobid, PDO::PARAM_STR); + $jobcheck->execute(); + + } while ($jobcheck->fetchColumn() != 0); + return $jobid; + } + public static function SetChatStyle(int $assetid, int $enum) { - if ($enum > -1 && $enum < 3) - { - $update = $GLOBALS['pdo']->prepare("UPDATE assets SET ChatStyleEnum = :enum WHERE id = :i"); + if ($enum > -1 && $enum < 3) { + $update = $GLOBALS['pdo']->prepare("UPDATE `assets` SET `ChatStyleEnum` = :enum WHERE `id` = :i"); $update->bindParam(":enum", $enum, PDO::PARAM_INT); $update->bindParam(":i", $assetid, PDO::PARAM_INT); $update->execute(); @@ -23,7 +50,7 @@ namespace Alphaland\Games { public static function GetChatStyle(int $assetid) { - $enum = $GLOBALS['pdo']->prepare("SELECT ChatStyleEnum FROM assets WHERE id = :i"); + $enum = $GLOBALS['pdo']->prepare("SELECT `ChatStyleEnum` FROM `assets` WHERE `id` = :i"); $enum->bindParam(":i", $assetid, PDO::PARAM_INT); $enum->execute(); return $enum->fetch(PDO::FETCH_OBJ)->ChatStyleEnum; @@ -31,8 +58,7 @@ namespace Alphaland\Games { public static function ConvertChatStyle(int $chatstyle) { - switch ($chatstyle) - { + switch ($chatstyle) { case 0: return "Classic"; case 1: @@ -43,5 +69,190 @@ namespace Alphaland\Games { return "ClassicAndBubble"; } } + + public static function EnableWhitelist(int $placeid) + { + if (isOwner($placeid)) { + $configgame = $GLOBALS['pdo']->prepare("UPDATE `assets` SET `isGameWhitelisted` = 1 WHERE `id` = :assetid"); + $configgame->bindParam(":assetid", $placeid, PDO::PARAM_INT); + $configgame->execute(); + if ($configgame->rowCount() > 0) { + return true; + } + return false; + } + } + + public static function UserAccess(int $placeid, int $userid) + { + if (Asset::GetAssetInfo($placeid)->isGameWhitelisted) { //game whitelisted + $whitelist = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM `game_access` WHERE `placeid` = :pid AND `userid` = :uid"); + $whitelist->bindParam(":pid", $placeid, PDO::PARAM_INT); + $whitelist->bindParam(":uid", $userid, PDO::PARAM_INT); + $whitelist->execute(); + if ($whitelist->fetchColumn() > 0 || $userid == Asset::GetAssetInfo($placeid)->CreatorId) { + return true; + } + return false; + } + return true; + } + + public static function WhitelistAddUser(int $placeid, int $userid) + { + if (isOwner($placeid)) { + if ($userid != Asset::GetAssetInfo($placeid)->CreatorId && !Game::UserAccess($placeid, $userid)) { + $whitelist = $GLOBALS['pdo']->prepare("INSERT INTO game_access(placeid, userid, whenWhitelisted) VALUES (:pid, :uid, UNIX_TIMESTAMP())"); + $whitelist->bindParam(":pid", $placeid, PDO::PARAM_INT); + $whitelist->bindParam(":uid", $userid, PDO::PARAM_INT); + $whitelist->execute(); + return true; + } + throw new Exception("Invalid user"); + } + throw new Exception("Invalid permissions"); + } + + public static function WhitelistRemoveUser(int $placeid, int $userid) + { + if (isOwner($placeid)) { + if ($userid != Asset::GetAssetInfo($placeid)->CreatorId) { + $whitelistremove = $GLOBALS['pdo']->prepare("DELETE FROM game_access WHERE placeid = :pid AND userid = :uid"); + $whitelistremove->bindParam(":pid", $placeid, PDO::PARAM_INT); + $whitelistremove->bindParam(":uid", $userid, PDO::PARAM_INT); + $whitelistremove->execute(); + if ($whitelistremove->rowCount() > 0) { + return true; + } + throw new Exception("Failed to remove user"); + } + throw new Exception("Invalid user"); + } + throw new Exception("Invalid permissions"); + } + + public static function ClearWhitelist(int $placeid) + { + if (isOwner($placeid)) { + $whitelistclear = $GLOBALS['pdo']->prepare("DELETE FROM game_access WHERE placeid = :pid"); + $whitelistclear->bindParam(":pid", $placeid, PDO::PARAM_INT); + $whitelistclear->execute(); + if ($whitelistclear->rowCount() > 0) + { + return true; + } + } + return false; + } + + public static function CloseDeadJobs(int $placeid) + { + $jobinfo = $GLOBALS['pdo']->prepare("UPDATE `open_servers` SET `status` = 2, `killedby` = 0, `whenDied` = UNIX_TIMESTAMP() WHERE `gameID` = :g AND (`lastPing` + 95) < UNIX_TIMESTAMP() AND (`status` = 0 OR `status` = 1)"); + $jobinfo->bindParam(":g", $placeid, PDO::PARAM_INT); + $jobinfo->execute(); + if ($jobinfo->rowCount() > 0) { + return true; + } + return false; + } + + public static function JobClosed(string $jobid) + { + $job = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM `open_servers` WHERE `jobid` = :j AND `status` = 2"); + $job->bindParam(":j", $jobid, PDO::PARAM_STR); + $job->execute(); + + if ($job->fetchColumn() > 0) { + return true; + } + return false; + } + + public static function TotalPlayerCount(int $placeid) + { + $job = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM `game_presence` WHERE `placeid` = :placeid AND (`lastPing` + 50) > UNIX_TIMESTAMP()"); + $job->bindParam(":placeid", $placeid, PDO::PARAM_INT); + $job->execute(); + return $job->fetchColumn(); + } + + public static function JobPlayerCount(int $placeid, string $jobid) + { + $p = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM `game_presence` WHERE `placeid` = :p AND `jobid` = :j AND (`lastPing` + 50) > UNIX_TIMESTAMP()"); + $p->bindParam(":p", $placeid, PDO::PARAM_INT); + $p->bindParam(":j", $jobid, PDO::PARAM_STR); + $p->execute(); + return $p->fetchColumn(); + } + + public static function CloseAllJobs(int $placeid) + { + $servers = $GLOBALS['pdo']->prepare("SELECT * FROM `open_servers` WHERE `gameID` = :gid AND `status` < 2"); + $servers->bindParam(":gid", $placeid, PDO::PARAM_INT); + $servers->execute(); + if ($servers->rowCount() > 0) { + $CloseJob = new RccServiceHelper($GLOBALS['gamesArbiter']); + foreach ($servers as $server) { + $CloseJob->CloseJob($server['jobid']); + } + return true; + } + return false; + } + + public static function SetToPersonalBuildPlace(int $placeid) + { + $set = $GLOBALS['pdo']->prepare("UPDATE `assets` SET `isPersonalServer` = 1 WHERE `id` = :i"); + $set->bindParam(":i", $placeid, PDO::PARAM_INT); + $set->execute(); + if ($set->rowCount() > 0) { + return true; + } + return false; + } + + public static function SetToPlace(int $placeid) + { + $set = $GLOBALS['pdo']->prepare("UPDATE assets SET `isPersonalServer` = 0 WHERE `id` = :i"); + $set->bindParam(":i", $placeid, PDO::PARAM_INT); + $set->execute(); + if ($set->rowCount() > 0) { + return true; + } + return false; + } + + public static function GetAllGames() + { + $games = $GLOBALS['pdo']->query("SELECT * FROM assets WHERE AssetTypeId = 9 ORDER BY Visited DESC"); + return $games; + } + + public static function ArbiterOnline() //the main portion of this check is now a background script + { + $check = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM websettings WHERE isGameServerAlive = 1"); + $check->execute(); + if ($check->fetchColumn() > 0) { + return true; + } + return false; + } + + public static function PersonalBuildRankToName($rank) + { + switch ($rank) + { + case 255: + return "Owner"; + case 240: + return "Admin"; + case 128: + return "Member"; + case 10: + return "Visitor"; + case 0: + return "Banned"; + } + } } } diff --git a/globals/functions.php b/globals/functions.php index e7f0086..440b27a 100644 --- a/globals/functions.php +++ b/globals/functions.php @@ -7,6 +7,7 @@ */ use Alphaland\Assets\Render; +use Alphaland\Games\Game; use Alphaland\Users\Render as UsersRender; use Alphaland\Web\WebContextManager; @@ -188,24 +189,6 @@ function gen_uuid() { ); } -function genJobId() -{ - $uuid = ""; - $alloc = true; - while ($alloc) { - $uuid = gen_uuid(); - $uuidcheck = $GLOBALS['pdo']->prepare("SELECT * FROM open_servers WHERE jobid = :u"); - $uuidcheck->bindParam(":u", $uuid, PDO::PARAM_STR); - $uuidcheck->execute(); - if ($uuidcheck->rowCount() > 0) { - continue; - } else { - $alloc = false; - } - } - return $uuid; -} - // //auth ticket utilities @@ -449,89 +432,6 @@ function logChatMessage($userid, $text, $trippedfilter) //privacy concern? //personal build servers -function isUserWhitelisted($placeid, $userid) -{ - $whitelist = $GLOBALS['pdo']->prepare("SELECT * FROM game_access WHERE placeid = :pid AND userid = :uid"); - $whitelist->bindParam(":pid", $placeid, PDO::PARAM_INT); - $whitelist->bindParam(":uid", $userid, PDO::PARAM_INT); - $whitelist->execute(); - if ($whitelist->rowCount() > 0) - { - return true; - } - return false; -} - -function gameWhitelistAddUser($placeid, $userid) -{ - if (isOwner($placeid)) - { - if ($userid != getAssetInfo($placeid)->CreatorId && !isUserWhitelisted($placeid, $userid)) - { - $whitelist = $GLOBALS['pdo']->prepare("INSERT INTO game_access(placeid, userid, whenWhitelisted) VALUES (:pid, :uid, UNIX_TIMESTAMP())"); - $whitelist->bindParam(":pid", $placeid, PDO::PARAM_INT); - $whitelist->bindParam(":uid", $userid, PDO::PARAM_INT); - if ($whitelist->execute()) - { - return true; - } - return "Failed to whitelist user"; - } - return "Invalid User"; - } - return "No Permission"; -} - -function gameWhitelistRemoveUser($placeid, $userid) -{ - if (isOwner($placeid)) - { - if ($userid != getAssetInfo($placeid)->CreatorId) - { - $whitelistremove = $GLOBALS['pdo']->prepare("DELETE FROM game_access WHERE placeid = :pid AND userid = :uid"); - $whitelistremove->bindParam(":pid", $placeid, PDO::PARAM_INT); - $whitelistremove->bindParam(":uid", $userid, PDO::PARAM_INT); - $whitelistremove->execute(); - if ($whitelistremove->rowCount() > 0) - { - return true; - } - return "Failed to unwhitelist user"; - } - return "Invalid User"; - } - return "No Permission"; -} - -function gameClearWhitelist($placeid) -{ - if (isOwner($placeid)) - { - $whitelistclear = $GLOBALS['pdo']->prepare("DELETE FROM game_access WHERE placeid = :pid"); - $whitelistclear->bindParam(":pid", $placeid, PDO::PARAM_INT); - $whitelistclear->execute(); - return true; - } - return false; -} - -function getPBSRankName($rank) -{ - switch ($rank) - { - case 255: - return "Owner"; - case 240: - return "Admin"; - case 128: - return "Member"; - case 10: - return "Visitor"; - case 0: - return "Banned"; - } -} - function updateBuildServerRank($placeid, $userid, $rank) { if ($userid != getAssetInfo($placeid)->CreatorId && getAssetInfo($placeid)->isPersonalServer == 1) @@ -657,7 +557,7 @@ function updatePBSGameSettings($placeid, $name, $description, $commentsenabled, if ($whitelistenabled == 0) //whitelist being disabled { - if (!gameClearWhitelist($placeid)) + if (!Game::ClearWhitelist($placeid)) { $whitelistenabled = 1; } @@ -1686,54 +1586,6 @@ function configPermission($groupid) // ... -//game utility functions - -function userAccessToGame($placeid, $userid) -{ - if (getAssetInfo($placeid)->isGameWhitelisted == 1) //game whitelisted - { - $whitelist = $GLOBALS['pdo']->prepare("SELECT * FROM game_access WHERE placeid = :pid AND userid = :uid"); - $whitelist->bindParam(":pid", $placeid, PDO::PARAM_INT); - $whitelist->bindParam(":uid", $userid, PDO::PARAM_INT); - $whitelist->execute(); - if ($whitelist->rowCount() > 0 || $userid == getAssetInfo($placeid)->CreatorId || $GLOBALS['user']->IsAdmin()) - { - return true; - } - return false; - } - return true; -} - -function checkForDeadJobs($placeid) -{ - $jobinfo = $GLOBALS['pdo']->prepare("SELECT * FROM open_servers WHERE gameID = :g AND (lastPing + 95) < UNIX_TIMESTAMP() AND (status = 0 OR status = 1)"); - $jobinfo->bindParam(":g", $placeid, PDO::PARAM_INT); - $jobinfo->execute(); - - foreach ($jobinfo as $job) - { - $editjob = $GLOBALS['pdo']->prepare("UPDATE open_servers SET status = 2, killedby = 0, whenDied = UNIX_TIMESTAMP() WHERE jobid = :j"); - $editjob->bindParam(":j", $job['jobid'], PDO::PARAM_STR); - $editjob->execute(); - } -} - -function isJobMarkedClosed($jobid) -{ - $job = $GLOBALS['pdo']->prepare("SELECT * FROM open_servers WHERE jobid = :j AND status = 2"); - $job->bindParam(":j", $jobid, PDO::PARAM_STR); - $job->execute(); - - if ($job->rowCount() > 0) - { - return true; - } - return false; -} - -//end game utility functions - //render utility functions function setHeadshotAngleRight($userid) @@ -1806,7 +1658,7 @@ function checkUserPendingRender($player) $checkdata = $check->fetch(PDO::FETCH_OBJ); $waspendingrender = false; - + if ($checkdata->pendingRender == true) //render pending { if (($checkdata->lastRender + 15) < time()) //last render still pending after 15 seconds @@ -1818,7 +1670,7 @@ function checkUserPendingRender($player) else { $waspendingrender = true; - } + } } if ($checkdata->pendingHeadshotRender == true) //headshot render pending @@ -1832,7 +1684,7 @@ function checkUserPendingRender($player) else { $waspendingrender = true; - } + } } return $waspendingrender; @@ -3233,22 +3085,6 @@ function rewardUserBadge($UserID, $BadgeID, $PlaceID) //backend communication and utilities for jobs { -function gameCloseAllJobs($id) -{ - $s = $GLOBALS['pdo']->prepare("SELECT * FROM open_servers WHERE gameID = :gid AND status < 2"); - $s->bindParam(":gid", $id, PDO::PARAM_INT); - - if ($s->execute()) - { - foreach ($s as $server) - { - soapCloseJob($GLOBALS['gamesArbiter'], $server['jobid']); - } - return true; - } - return false; -} - function logSoapFault($soapresult, $description, $script) { $theFault = print_r($soapresult, TRUE); @@ -3259,39 +3095,6 @@ function logSoapFault($soapresult, $description, $script) $fault->execute(); } -function allocGamePort() //allocs a port between 50000 - 60000, verifies the port isn't in use by another game server -{ - $port = 0; - $alloc = true; - while ($alloc) - { - $port = rand(50000,60000); //port range forwarded on the server side (support up to 10000 jobs) - - $s = $GLOBALS['pdo']->prepare("SELECT * FROM open_servers WHERE port = :p AND status < 2"); - $s->bindParam(":p", $port, PDO::PARAM_STR); - $s->execute(); - - if ($s->rowCount() > 0 || $port == 57236) { - continue; - } else { - $alloc = false; - } - } - return $port; -} - -function isGameServerAlive() //the main portion of this check is now a background script -{ - $check = $GLOBALS['pdo']->prepare("SELECT * FROM websettings WHERE isGameServerAlive = 1"); - $check->execute(); - - if ($check->rowCount() > 0) - { - return true; - } - return false; -} - function isThumbnailerAlive() //the main portion of this check is now a background script { $check = $GLOBALS['pdo']->prepare("SELECT * FROM websettings WHERE isThumbnailerAlive = 1"); @@ -4361,30 +4164,6 @@ function userShout($uid) //end of shouts } //games portion { - -function setPBSGame($placeid) -{ - $set = $GLOBALS['pdo']->prepare("UPDATE assets SET isPersonalServer = 1 WHERE id = :i"); - $set->bindParam(":i", $placeid, PDO::PARAM_INT); - $set->execute(); - if ($set->rowCount() > 0) - { - return true; - } - return false; -} - -function setRegularGame($placeid) -{ - $set = $GLOBALS['pdo']->prepare("UPDATE assets SET isPersonalServer = 0 WHERE id = :i"); - $set->bindParam(":i", $placeid, PDO::PARAM_INT); - $set->execute(); - if ($set->rowCount() > 0) - { - return true; - } - return false; -} function createPlace($userid, $name, $description, $maxplayers) { @@ -4501,54 +4280,6 @@ function userPlaceVisits($userid) } -function getAllSiteGames() -{ - $check = $GLOBALS['pdo']->query("SELECT * FROM assets WHERE AssetTypeId = 9 ORDER BY Visited DESC"); - return $check; -} - -function getRecentlyPlayed() -{ - $localuser = $GLOBALS['user']->id; - $check = $GLOBALS['pdo']->prepare("SELECT * FROM game_recents WHERE uid = :u ORDER by whenPlayed DESC"); - $check->bindParam(":u", $localuser, PDO::PARAM_INT); - $check->execute(); - return $check; -} - -function gamePlayerCount($id) -{ - $sQ = $GLOBALS['pdo']->prepare("SELECT * FROM open_servers WHERE status != 2 AND gameID = :i"); - $sQ->bindParam(":i", $id, PDO::PARAM_INT); - $sQ->execute(); - - if($sQ->rowCount() > 0) - { - $servers = $sQ->fetchAll(PDO::FETCH_ASSOC); - - foreach($servers as $server) // TODO: re-work this when i implement job-id based presence - { - $p = $GLOBALS['pdo']->prepare("SELECT * FROM game_presence WHERE placeid = :p AND (lastPing + 50) > UNIX_TIMESTAMP()"); - $p->bindParam(":p", $id, PDO::PARAM_INT); - $p->execute(); - - return $p->rowCount(); - } - } - else - { - return 0; - } -} - -function jobPlayerCount($placeid, $jobid) -{ - $p = $GLOBALS['pdo']->prepare("SELECT * FROM game_presence WHERE placeid = :p AND jobid = :j AND (lastPing + 50) > UNIX_TIMESTAMP()"); - $p->bindParam(":p", $placeid, PDO::PARAM_INT); - $p->bindParam(":j", $jobid, PDO::PARAM_STR); - $p->execute(); - return $p->rowCount(); -} //end games portion } //utility { @@ -4978,7 +4709,7 @@ function getNav() $thumbnailerstatus = ""; } - if (!isGameServerAlive()) + if (!Game::ArbiterOnline()) { $gameserverstatus = ""; } @@ -5062,7 +4793,7 @@ function getNav()
'; } @@ -5146,7 +4877,7 @@ function adminPanelStats() { } $gameserverstatus = "OK"; - if (!isGameServerAlive()) + if (!Game::ArbiterOnline()) { $gameserverstatus = "DOWN"; } diff --git a/html/Game/Join.php b/html/Game/Join.php index ef9a9ce..4279ac7 100644 --- a/html/Game/Join.php +++ b/html/Game/Join.php @@ -53,7 +53,7 @@ if ($_SERVER['HTTP_USER_AGENT'] == $GLOBALS['clientUserAgent']) //user agent res $gameInfo = getAssetInfo($serverInfo->gameID); - if (userAccessToGame($gameInfo->id, $sInfo->uid)) + if (Game::UserAccess($gameInfo->id, $sInfo->uid)) { $jobid = $sInfo->jobid; $placeid = $gameInfo->id; diff --git a/html/Game/PlaceLauncher.php b/html/Game/PlaceLauncher.php index 4ee7489..5b640c4 100644 --- a/html/Game/PlaceLauncher.php +++ b/html/Game/PlaceLauncher.php @@ -5,6 +5,8 @@ This is used on the client (if the client has the session token set) to request TODO: Clean up */ +use Alphaland\Assets\Asset; +use Alphaland\Games\Game; use Alphaland\Grid\RccServiceHelper; $requesttype = $_GET['request']; @@ -72,8 +74,9 @@ function StartServer($gid) { $gameInfo = getAssetInfo($gid); $jobuuid = genJobId(); //generate a UUID for the job + $jobuuid = Game::GenerateJobId(); //generate a UUID for the job $ip = $GLOBALS['gameMachine']; //IP address of the gameserver machine - $port = allocGamePort(); //generate an available port for the gameserver + $port = Game::AllocatePort(); //generate an available port for the gameserver //add this server to the database $s = $GLOBALS['pdo']->prepare("INSERT INTO open_servers(jobid,gameID,ip,port,whenStarted,lastPing) VALUES(:j,:g,:ip,:port,UNIX_TIMESTAMP(),UNIX_TIMESTAMP())"); @@ -134,10 +137,10 @@ if ($requesttype == "RequestGame") //start new server or join existing one { //safe ID $gameID = $gInfo->id; - - checkForDeadJobs($gameID); + + Game::CloseDeadJobs($gameID); - if (userAccessToGame($gameID, $user->id)) + if (Game::UserAccess($gameID, $user->id)) { //check for open servers $servers = $pdo->prepare("SELECT * FROM open_servers WHERE gameID = :i AND (status = 0 OR status = 1) ORDER BY status DESC LIMIT 1"); @@ -155,7 +158,7 @@ if ($requesttype == "RequestGame") //start new server or join existing one addPlayerToQueue($gameID, $sInfo->jobid, $user->id); //add player to queue (if they are in it, this updates ping) if (isNextInQueue($gameID, $sInfo->jobid, $user->id)) //player next in queue { - if (jobPlayerCount($gameID, $sInfo->jobid) >= $gInfo->MaxPlayers) + if (Game::JobPlayerCount($gameID, $sInfo->jobid) >= $gInfo->MaxPlayers) { echo constructJson($sInfo->jobid."", 6, "", "", "", ""); //return job full } @@ -203,7 +206,7 @@ else if ($requesttype == "RequestFollowUser") //follow user if ($assettype == 9) //asset is a game { - checkForDeadJobs($placeid); + Game::CloseDeadJobs($placeid); $playersgame = $pdo->prepare("SELECT * FROM game_presence WHERE uid = :u AND placeid = :p"); $playersgame->bindParam(":u", $userid, PDO::PARAM_INT); diff --git a/html/games/config.php b/html/games/config.php index a8faf42..befb123 100644 --- a/html/games/config.php +++ b/html/games/config.php @@ -57,9 +57,9 @@ function convertToPBSPlace($placetype, $placeid) //copy template, set the game type to PBS, update the hash, delete persistence data, close all servers, start place render and redirect if (copy($selectedPlacePath, $assetcdn . $gamehash)) { - if (gameCloseAllJobs($placeid)) + if (Game::CloseAllJobs($placeid)) { - if (setPBSGame($placeid)) + if (Game::SetToPersonalBuildPlace($placeid)) { $set = $GLOBALS['pdo']->prepare("UPDATE assets SET Hash = :hash WHERE id = :i"); $set->bindParam(":hash", $gamehash, PDO::PARAM_INT); @@ -77,7 +77,7 @@ function convertToPBSPlace($placetype, $placeid) } } } - setRegularGame($placeid); + Game::SetToPlace($placeid); } return "Error converting to PBS"; } diff --git a/html/games/pbs/config.php b/html/games/pbs/config.php index 27c15b4..813c07b 100644 --- a/html/games/pbs/config.php +++ b/html/games/pbs/config.php @@ -1,5 +1,6 @@ $jobid, diff --git a/html_admin/lua-executer/executeScript.php b/html_admin/lua-executer/executeScript.php index 1eca055..33d75bd 100644 --- a/html_admin/lua-executer/executeScript.php +++ b/html_admin/lua-executer/executeScript.php @@ -1,5 +1,6 @@ jobid; $script = $data->script; $output = ""; -if (!isJobMarkedClosed($jobid)) +if (!Game::JobClosed($jobid)) { $jobExecuteEx = new RccServiceHelper($GLOBALS['gamesArbiter']); $jobExecuteEx->ExecuteEx( diff --git a/html_api/game/info.php b/html_api/game/info.php index 249c192..6f03b36 100644 --- a/html_api/game/info.php +++ b/html_api/game/info.php @@ -6,6 +6,9 @@ Alphaland 2021 */ //headers + +use Alphaland\Games\Game; + header("Access-Control-Allow-Origin: https://www.alphaland.cc"); header("access-control-allow-credentials: true"); @@ -30,7 +33,7 @@ $userInfo = array( "Creator" => getUsername($assetinfo->CreatorId), "CreatorId" => $assetinfo->CreatorId, "isPersonalServer" => boolval($assetinfo->isPersonalServer), - "playPermission" => userAccessToGame($assetinfo->id, $user->id), + "playPermission" => Game::UserAccess($assetinfo->id, $user->id), "canManage" => boolval($assetinfo->CreatorId == $user->id || $user->IsAdmin()), "CommentsEnabled" => boolval($assetinfo->IsCommentsEnabled), "PersonalServerWhitelist" => boolval($assetinfo->isGameWhitelisted), diff --git a/html_api/game/jobList.php b/html_api/game/jobList.php index 3944311..5833ead 100644 --- a/html_api/game/jobList.php +++ b/html_api/game/jobList.php @@ -6,6 +6,9 @@ Alphaland 2021 */ //headers + +use Alphaland\Games\Game; + header("Access-Control-Allow-Origin: https://www.alphaland.cc"); header("access-control-allow-credentials: true"); header('Content-Type: application/json'); @@ -65,7 +68,7 @@ $jsonData = array( foreach($servers as $server) { $jobid = $server['jobid']; - $playing = jobPlayerCount($server['gameID'], $jobid); + $playing = Game::JobPlayerCount($server['gameID'], $jobid); $maxplayers = (int)getAssetInfo($server['gameID'])->MaxPlayers; $isowner = isOwner($server['gameID']); $whenStarted = date("h:ia", $server['whenStarted']); diff --git a/html_api/game/pbs/configure.php b/html_api/game/pbs/configure.php index b8cc71f..a8d0868 100644 --- a/html_api/game/pbs/configure.php +++ b/html_api/game/pbs/configure.php @@ -6,6 +6,9 @@ Alphaland 2021 */ //headers + +use Alphaland\Games\Game; + header("Access-Control-Allow-Origin: https://www.alphaland.cc"); header("access-control-allow-credentials: true"); @@ -68,17 +71,29 @@ else $userid = getID($data->username); if ($userid) { - $message = gameWhitelistAddUser($assetid, $userid); + try { + if (Game::WhitelistAddUser($assetid, $userid)) { + $message = true; + } + } catch (Exception $e) { + $message = $e->getMessage(); + } } else { - $message = "Invalid User"; + $message = "User not found"; } } else if ($removewhitelistuser) { $userid = $data->userid; - $message = gameWhitelistRemoveUser($assetid, $userid); + try { + if (Game::WhitelistRemoveUser($assetid, $userid)) { + $message = true; + } + } catch (Exception $e) { + $message = $e->getMessage(); + } } if ($message === true) { diff --git a/html_api/game/pbs/users.php b/html_api/game/pbs/users.php index dc24dd6..aaed811 100644 --- a/html_api/game/pbs/users.php +++ b/html_api/game/pbs/users.php @@ -6,6 +6,9 @@ */ //headers + +use Alphaland\Games\Game; + header("Access-Control-Allow-Origin: https://www.alphaland.cc"); header("access-control-allow-credentials: true"); @@ -85,7 +88,7 @@ foreach($members as $member) "username" => $username, "userid" => $userid, "thumbnail" => $thumbnail, - "rankname" => getPBSRankName($rank), + "rankname" => Game::PersonalBuildRankToName($rank), "rank" => $rank ); } diff --git a/html_api/games/sitegames.php b/html_api/games/sitegames.php index ba26657..f3e357d 100644 --- a/html_api/games/sitegames.php +++ b/html_api/games/sitegames.php @@ -8,6 +8,9 @@ This is parsed with javascript on the users end, this allows the user to handle //headers + +use Alphaland\Games\Game; + header("Access-Control-Allow-Origin: https://www.alphaland.cc"); header("access-control-allow-credentials: true"); @@ -75,7 +78,7 @@ foreach($games as $game) $visits = $game['Visited']; //visit count of the game $creation = date("m/d/Y", $game['Created']); //creation date of the game NOTE: to get the date, use UNIX_TIMESTAMP() $creatorN = getUsername($game['CreatorId']); //creator of the game username - $playercount = gamePlayerCount($gameID); //players in the game + $playercount = Game::TotalPlayerCount($gameID); //players in the game $placerender = handleGameThumb($gameID); $placeInfo = array( diff --git a/html_api/user/games/recents.php b/html_api/user/games/recents.php index cab41ad..77bb930 100644 --- a/html_api/user/games/recents.php +++ b/html_api/user/games/recents.php @@ -6,6 +6,9 @@ Alphaland 2021 */ //headers + +use Alphaland\Games\Game; + header("Access-Control-Allow-Origin: https://www.alphaland.cc"); header("access-control-allow-credentials: true"); @@ -71,7 +74,7 @@ foreach($recents as $game) $id = $game['gid']; $visits = $placeinfo->Visited; $placename = cleanOutput($placeinfo->Name); - $playercount = gamePlayerCount($game['gid']); + $playercount = Game::TotalPlayerCount($game['gid']); $creatorid = $placeinfo->CreatorId; $creator = getUsername($creatorid); $thumbnail = handleGameThumb($game['gid']);