Games\Game Impl

This commit is contained in:
Astrologies 2021-12-21 03:24:08 -05:00
parent 0db2c2e82e
commit 309f1df376
15 changed files with 287 additions and 307 deletions

View File

@ -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";
}
}
}
}

View File

@ -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 = "<div style='margin:0 auto;Overflow:hidden;text-align: center' class='alert alert-danger' role='alert'>WARNING: Thumbnailer is offline, no Avatar changes will be applied</div>";
}
if (!isGameServerAlive())
if (!Game::ArbiterOnline())
{
$gameserverstatus = "<div style='margin:0 auto;Overflow:hidden;text-align: center' class='alert alert-danger' role='alert'>WARNING: Gameserver is offline, games will not launch</div>";
}
@ -5062,7 +4793,7 @@ function getNav()
</header>
<script>
setInterval(function(){ getJSONCDS("https://api.alphaland.cc/sitepresence/ping"); }, 60000); //ping every minute
setTimeout(function() { new Snow("alphaland-main-body");}, 800);
setTimeout(function() { new Snow("alphaland-main-body");}, 800);
</script>
<br/>';
}
@ -5146,7 +4877,7 @@ function adminPanelStats() {
}
$gameserverstatus = "OK";
if (!isGameServerAlive())
if (!Game::ArbiterOnline())
{
$gameserverstatus = "DOWN";
}

View File

@ -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;

View File

@ -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);

View File

@ -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";
}

View File

@ -1,5 +1,6 @@
<?php
use Alphaland\Games\Game;
use Alphaland\Web\WebContextManager;
$body = '';
@ -25,16 +26,16 @@ else
if (isset($_POST['ConvertToRegular']))
{
if (gameCloseAllJobs($gameid))
if (Game::CloseAllJobs($gameid))
{
if (setRegularGame($gameid))
if (Game::SetToPlace($gameid))
{
handleRenderPlace($gameid);
WebContextManager::Redirect("/games/config?id=".$gameid);
}
else
{
setPBSGame($gameid);
Game::SetToPersonalBuildPlace($gameid);
}
}
}
@ -286,6 +287,7 @@ function updatePBSGen()
function whitelistUser(username)
{
updatePBSGen();
postJSONCDS("https://api.alphaland.cc/game/pbs/configure?id="+gameid+"&whitelist=true", JSON.stringify({"username": username}))
.done(function(object) {
var alert = object.alert;

View File

@ -4,6 +4,7 @@
Alphaland 2021
*/
use Alphaland\Games\Game;
use Alphaland\Web\WebContextManager;
$gameID = $_GET['id'];
@ -22,7 +23,7 @@ else
WebContextManager::Redirect("/404");
}
checkForDeadJobs($gameID);
Game::CloseDeadJobs($gameID);
$body = '

View File

@ -1,5 +1,6 @@
<?php
use Alphaland\Games\Game;
use Alphaland\Web\WebContextManager;
WebContextManager::ForceHttpsCloudflare();
@ -26,7 +27,7 @@ foreach($b as $jobInfo)
{
$jobid = $jobInfo['jobid'];
$placeid = $jobInfo['gameID'];
checkForDeadJobs($placeid);
Game::CloseDeadJobs($placeid);
$jsonInfo = array(
"JobID" => $jobid,

View File

@ -1,5 +1,6 @@
<?php
use Alphaland\Games\Game;
use Alphaland\Grid\RccServiceHelper;
use Alphaland\Web\WebContextManager;
@ -16,7 +17,7 @@ $jobid = $data->jobid;
$script = $data->script;
$output = "";
if (!isJobMarkedClosed($jobid))
if (!Game::JobClosed($jobid))
{
$jobExecuteEx = new RccServiceHelper($GLOBALS['gamesArbiter']);
$jobExecuteEx->ExecuteEx(

View File

@ -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),

View File

@ -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']);

View File

@ -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) {

View File

@ -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
);
}

View File

@ -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(

View File

@ -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']);