Example #1
0
 public function updateOverlay($overlayId, $gameId, $name, $mediaId, $topLeftLat, $topLeftLong, $topRightLat, $topRightLong, $bottomLeftLat, $bottomLeftLong, $editorId, $editorToken)
 {
     if (!Module::authenticateGameEditor($gameId, $editorId, $editorToken, "read_write")) {
         return new returnData(6, NULL, "Failed Authentication");
     }
     $newName = addslashes($newName);
     Module::query("UPDATE overlays SET game_id = {$gameId}, name = '{$name}', media_id = {$mediaId}, top_left_latitude = {$topLeftLat}, top_left_longitude = {$topLeftLong}, top_right_latitude = {$topRightLat}, top_right_longitude = {$topRightLong}, bottom_left_latitude = {$bottomLeftLat}, bottom_left_longitude = {$bottomLeftLong} WHERE overlay_id = {$overlayId};");
     return new returnData(0);
 }
Example #2
0
 public static function migrateDB()
 {
     $migrations = array();
     if ($migrationsDir = opendir(Config::migrationsDir)) {
         while ($migration = readdir($migrationsDir)) {
             if (preg_match('/^[0..9]+\\.sql$/', $migration)) {
                 $migrations[intval(substr($migration, 0, -4))] = $migration;
             }
         }
     }
     $migrated = array();
     if (Module::queryObject("SHOW TABLES LIKE 'aris_migrations'")) {
         $knownVersions = Module::queryArray("SELECT * FROM aris_migrations");
         foreach ($knownVersions as $version) {
             if (!$migrated[intval($version->version_major)]) {
                 $migrated[intval($version->version_major)] = array();
             }
             $migrated[intval($version->version_major)][intval($version->version_minor)] = $version->timestamp;
         }
     } else {
         //The one migration/construction to be done outside the .sql files
         Module::query("CREATE TABLE aris_migrations ( version_major int(32) unsigned NOT NULL, version_minor int(32) unsigned NOT NULL, timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (version_major,version_minor))");
     }
     foreach ($migrations as $major => $file) {
         if ($migrated[$major + 1]) {
             continue;
         }
         $file_handle = fopen(Config::migrationsDir . "/" . $file, "r");
         $minor = 0;
         while (!feof($file_handle)) {
             //Funny way to continue to read from the file until it either ends, or reaches a semicolon
             $query = "";
             while (!feof($file_handle) && strpos($query .= fgets($file_handle), ';') === FALSE) {
             }
             if (!$migrated[$major][$minor]) {
                 mysql_query($query);
                 if (mysql_error()) {
                     $error = "Error upgrading database to version " . $major . "." . $minor . ". Error was:\n" . mysql_error() . "\n in query:\n" . $query;
                     Module::serverErrorLog($error);
                     echo $error;
                     return $error;
                 }
                 Module::query("INSERT INTO aris_migrations (version_major, version_minor) VALUES ('" . $major . "','" . $minor . "')");
             }
             $minor++;
         }
         fclose($file_handle);
     }
     return 0;
 }
Example #3
0
 public static function deleteWebPage($gameId, $webPageId)
 {
     Locations::deleteLocationsForObject($gameId, 'WebPage', $webPageId);
     Requirements::deleteRequirementsForRequirementObject($gameId, 'WebPage', $webPageId);
     PlayerStateChanges::deletePlayerStateChangesThatRefrenceObject($gameId, 'WebPage', $webPageId);
     $query = "DELETE FROM web_pages WHERE game_id = '{$gameId}' AND web_page_id = {$webPageId}";
     $rsResult = Module::query($query);
     if (mysql_error()) {
         return new returnData(3, NULL, "SQL Error");
     }
     if (mysql_affected_rows()) {
         return new returnData(0, TRUE);
     } else {
         return new returnData(0, FALSE);
     }
 }
Example #4
0
 public function swapSortIndex($gameId, $a, $b, $editorId, $editorToken)
 {
     if (!Module::authenticateGameEditor($gameId, $editorId, $editorToken, "read_write")) {
         return new returnData(6, NULL, "Failed Authentication");
     }
     $result = Module::query("SELECT * FROM quests WHERE game_id = {$gameId} AND (quest_id = '{$a}' OR quest_id = '{$b}')");
     $quests = array();
     while ($quest = mysql_fetch_object($result)) {
         $quests[$quest->quest_id] = $quest;
     }
     Module::query("UPDATE quests SET sort_index = '{$quests[$a]->sort_index}' WHERE game_id = {$gameId} AND quest_id = '{$b}'");
     Module::query("UPDATE quests SET sort_index = '{$quests[$b]->sort_index}' WHERE game_id = {$gameId} AND quest_id = '{$a}'");
     return new returnData(0);
 }
Example #5
0
 protected function fireOffWebHook($playerId, $gameId, $webHookId)
 {
     Module::appendLog($playerId, $gameId, "SEND_WEBHOOK", $webHookId);
     $query = "SELECT * FROM web_hooks WHERE web_hook_id = '{$webHookId}' LIMIT 1";
     $result = Module::query($query);
     $webHook = mysql_fetch_object($result);
     $name = str_replace(" ", "", $webHook->name);
     $name = str_replace("{playerId}", $playerId, $webHook->name);
     $url = $webHook->url . "?hook=" . $name . "&wid=" . $webHook->web_hook_id . "&gameid=" . $gameId . "&playerid=" . $playerId;
     @file_get_contents($url);
 }
Example #6
0
 public static function getSpawnablesForGame($gameId)
 {
     $query = "SELECT * FROM spawnables WHERE game_id = {$gameId} AND active = 1";
     $result = Module::query($query);
     $spawnables = array();
     while ($obj = mysql_fetch_object($result)) {
         $spawnables[] = $obj;
     }
     return new returnData(0, $spawnables);
 }
Example #7
0
 public static function getDetailedPlayerItems($playerId, $gameId)
 {
     /* OTHER ITEMS */
     $query = "SELECT DISTINCT i.item_id, i.name, i.description, i.max_qty_in_inventory, i.weight, i.type, i.url, pi.qty, m.file_path as media_url, m.game_id as media_game_id, im.file_path as icon_url, im.game_id as icon_game_id FROM (SELECT * FROM player_items WHERE game_id={$gameId} AND player_id = {$playerId}) as pi LEFT JOIN (SELECT * FROM items WHERE game_id = {$gameId}) as i ON pi.item_id = i.item_id LEFT JOIN media as m ON i.media_id = m.media_id LEFT JOIN media as im ON i.icon_media_id = im.media_id WHERE i.type != 'ATTRIB' GROUP BY i.item_id";
     $result = Module::query($query);
     $contents = array();
     while ($content = mysql_fetch_object($result)) {
         if ($content->media_url) {
             $content->media_url = Config::gamedataWWWPath . '/' . $content->media_url;
             $content->media_thumb_url = substr($content->media_url, 0, strrpos($content->media_url, '.')) . '_128' . substr($content->media_url, strrpos($content->media_url, '.'));
         }
         if ($content->icon_url) {
             $content->icon_url = Config::gamedataWWWPath . '/' . $content->icon_url;
             $content->icon_thumb_url = substr($content - icon_url, 0, strrpos($content - icon_url, '.')) . '_128' . substr($content - icon_url, strrpos($content - icon_url, '.'));
         }
         $content->tags = Items::getItemTags($content->item_id)->data;
         $contents[] = $content;
     }
     return $contents;
 }
Example #8
0
 public function uploadPlayerMediaFromJSON($glob)
 {
     //WHY DOESNT THIS HAPPEN VIA THE FRAMEWORK?!
     $data = file_get_contents("php://input");
     $glob = json_decode($data);
     $playerId = $glob->playerId;
     $media = $glob->media;
     $media->path = "player";
     if (!is_numeric($playerId)) {
         return new returnData(1, NULL, "JSON package has no numeric member \"playerId\"");
     }
     $media = Media::createMediaFromJSON($media)->data;
     Module::query("UPDATE players SET media_id = '{$media->media_id}' WHERE player_id = '{$playerId}'");
     return new returnData(0, $media);
 }
Example #9
0
 protected function giveItemToWorld($gameId, $intItemID, $floatLat, $floatLong, $intQty = 1)
 {
     //Find any items on the map nearby
     $clumpingRangeInMeters = 10;
     $query = "SELECT *,((ACOS(SIN({$floatLat} * PI() / 180) * SIN(latitude * PI() / 180) + \n            COS({$floatLat} * PI() / 180) * COS(latitude * PI() / 180) * \n            COS(({$floatLong} - longitude) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) * 1609.344\n            AS `distance`, location_id \n            FROM locations \n            WHERE type = 'item' AND type_id = '{$intItemID}' AND game_id = '{$gameId}'\n            HAVING distance<= {$clumpingRangeInMeters}\n        ORDER BY distance ASC";
     $result = Module::query($query);
     if ($closestLocationWithinClumpingRange = @mysql_fetch_object($result)) {
         //We have a match
         $query = "UPDATE locations\n                SET item_qty = item_qty + {$intQty}\n            WHERE location_id = {$closestLocationWithinClumpingRange->location_id} AND game_id = '{$gameId}'";
         Module::query($query);
     } else {
         $itemName = $this->getItemName($gameId, $intItemID);
         $error = 100;
         //Use 100 meters
         $icon_media_id = $this->getItemIconMediaId($gameId, $intItemID);
         //Set the map icon = the item's icon
         $query = "INSERT INTO locations (game_id, name, type, type_id, icon_media_id, latitude, longitude, error, item_qty)\n                VALUES ('{$gameId}', '{$itemName}','Item','{$intItemID}', '{$icon_media_id}', '{$floatLat}','{$floatLong}', '{$error}','{$intQty}')";
         Module::query($query);
         $newId = mysql_insert_id();
         //Create a coresponding QR Code
         QRCodes::createQRCode($gameId, "Location", $newId, '');
     }
 }
 public static function deleteContent($gameId, $intContentID, $editorId, $editorToken)
 {
     if (!Module::authenticateGameEditor($gameId, $editorId, $editorToken, "read_write")) {
         return new returnData(6, NULL, "Failed Authentication");
     }
     //Lookup the object
     $query = "SELECT content_type,content_id FROM folder_contents WHERE object_content_id = {$intContentID} AND game_id = '{$gameId}' LIMIT 1";
     $contentQueryResult = Module::query($query);
     $content = @mysql_fetch_object($contentQueryResult);
     if (mysql_error()) {
         return new returnData(3, NULL, "SQL Error");
     }
     Spawnables::deleteSpawnablesOfObject($gameId, $content->content_type, $content->content_id, $editorId, $editorToken);
     //Delete the content record
     $query = "DELETE FROM folder_contents WHERE object_content_id = {$intContentID} AND game_id = '{$gameId}'";
     Module::query($query);
     if (mysql_error()) {
         return new returnData(3, NULL, "SQL Error");
     }
     //Delete the object
     if ($content->content_type == "Node") {
         Nodes::deleteNode($gameId, $content->content_id, $editorId, $editorToken);
     } else {
         if ($content->content_type == "Item") {
             Items::deleteItem($gameId, $content->content_id, $editorId, $editorToken);
         } else {
             if ($content->content_type == "Npc") {
                 Npcs::deleteNpc($gameId, $content->content_id, $editorId, $editorToken);
             } else {
                 if ($content->content_type == "WebPage") {
                     WebPages::deleteWebPage($gameId, $content->content_id, $editorId, $editorToken);
                 } else {
                     if ($content->content_type == "AugBubble") {
                         AugBubbles::deleteAugBubble($gameId, $content->content_id, $editorId, $editorToken);
                     } else {
                         if ($content->content_type == "PlayerNote") {
                             Notes::deleteNote($content->content_id, $editorId, $editorToken);
                         }
                     }
                 }
             }
         }
     }
     if (mysql_affected_rows()) {
         return new returnData(0);
     } else {
         return new returnData(2, 'invalid folder id');
     }
 }
Example #11
0
 protected function getUnfiredWebhooks($playerId, $gameId)
 {
     //Get all webhooks for game
     $query = "SELECT * FROM web_hooks WHERE game_id = '{$gameId}' AND incoming = 0";
     $result = Module::query($query);
     $gameWebhooks = array();
     while ($gameWebhook = mysql_fetch_object($result)) {
         $gameWebhooks[] = $gameWebhook;
     }
     //Get all webhooks fired by player
     $query = "SELECT * FROM player_log WHERE player_id = {$playerId} AND game_id = {$gameId} AND event_type = 'SEND_WEBHOOK' AND deleted = 0;";
     $result = Module::query($query);
     $playerFiredWebhooks = array();
     while ($playerFiredWebhook = mysql_fetch_object($result)) {
         $playerFiredWebhooks[] = $playerFiredWebhook;
     }
     //Cross reference lists to remove already-fired webhooks
     $unfiredWebhooks = array();
     foreach ($gameWebhooks as $gameWebhook) {
         $webhookAlreadyFired = false;
         foreach ($playerFiredWebhooks as $playerFiredWebhook) {
             if ($gameWebhook->web_hook_id == $playerFiredWebhook->event_detail_1) {
                 $webhookAlreadyFired = true;
             }
         }
         if (!$webhookAlreadyFired) {
             $unfiredWebhooks[] = $gameWebhook;
         }
     }
     return $unfiredWebhooks;
 }
Example #12
0
 public function emailUserName($strEmail)
 {
     //set the editor record to this pw
     $query = "SELECT * FROM editors\tWHERE email = '{$strEmail}'";
     $result = Module::query($query);
     if (mysql_error()) {
         return new returnData(3, NULL, 'SQL Error' . mysql_error());
     }
     if (!($editor = mysql_fetch_array($result))) {
         return new returnData(4, NULL, "Email is not an editor");
     }
     $subject = "Recover ARIS Login Information";
     $body = "Your ARIS username is: {$editor['name']}";
     if (Module::sendEmail($strEmail, $subject, $body)) {
         return new returnData(0, NULL);
     } else {
         return new returnData(5, NULL, "Mail could not be sent");
     }
 }
Example #13
0
 public function deleteConversationWithNode($gameId, $conversationId, $editorId, $editorToken)
 {
     if (!Module::authenticateGameEditor($gameId, $editorId, $editorToken, "read_write")) {
         return new returnData(6, NULL, "Failed Authentication");
     }
     $query = "SELECT node_id FROM npc_conversations WHERE game_id = '{$gameId}' AND conversation_id = {$conversationId} LIMIT 1";
     $nodeIdRs = Module::query($query);
     if (mysql_error()) {
         return new returnData(3, NULL, "SQL Error:" . mysql_error() . "while running query:" . $query);
     }
     $nodeIdObject = @mysql_fetch_object($nodeIdRs);
     if (!$nodeIdObject) {
         return new returnData(2, NULL, "No such conversation");
     }
     $nodeId = $nodeIdObject->node_id;
     Nodes::deleteNode($gameId, $nodeId);
     $query = "DELETE FROM npc_conversations WHERE game_id = '{$gameId}' AND conversation_id = {$conversationId}";
     $rsResult = Module::query($query);
     if (mysql_error()) {
         return new returnData(3, NULL, "SQL Error");
     }
     if (mysql_affected_rows()) {
         return new returnData(0);
     } else {
         return new returnData(2, NULL, 'invalid conversation id');
     }
 }
Example #14
0
 private function lookupActionTypeOptionsFromSQL()
 {
     $query = "SHOW COLUMNS FROM player_state_changes LIKE 'action'";
     $result = Module::query($query);
     $row = mysql_fetch_array($result, MYSQL_NUM);
     $regex = "/'(.*?)'/";
     preg_match_all($regex, $row[1], $enum_array);
     $enum_fields = $enum_array[1];
     return $enum_fields;
 }
Example #15
0
 private static function playerLikedAPI($playerId, $noteId)
 {
     $query = "SELECT COUNT(*) as liked FROM note_likes WHERE player_id = '{$playerId}' AND note_id = '{$noteId}' LIMIT 1";
     $result = Module::query($query);
     $liked = mysql_fetch_object($result);
     return $liked->liked;
 }
Example #16
0
 public function getNpcsInfoForGameIdFormattedForArisConvoOutput($gameId)
 {
     $characters = array();
     $query = "SELECT * FROM npcs WHERE game_id = {$gameId}";
     $npcs = Module::query($query);
     if (mysql_error()) {
         return new returnData(1, NULL, mysql_error);
     }
     while ($npc = mysql_fetch_object($npcs)) {
         $character = new stdClass();
         $character->name = $npc->name;
         $scripts = array();
         //Greeting
         $script = new stdClass();
         $script->option = "Greeting";
         $script->content = $npc->text;
         $script->req = "(start conversation)";
         $script->exchange = "n/a";
         $scripts[] = $script;
         //Convos
         $query = "SELECT * FROM npc_conversations WHERE game_id = {$gameId} AND npc_id = '{$npc->npc_id}'";
         $convos = Module::query($query);
         if (mysql_error()) {
             return new returnData(1, NULL, mysql_error);
         }
         while ($convo = mysql_fetch_object($convos)) {
             $script = new stdClass();
             $script->option = $convo->text;
             $query = "SELECT * FROM nodes WHERE game_id = {$gameId} AND node_id = '{$convo->node_id}'";
             $nodeRow = Module::query($query);
             if (mysql_error()) {
                 return new returnData(1, NULL, mysql_error);
             }
             $node = mysql_fetch_object($nodeRow);
             $script->content = $node->text;
             $requirements = array();
             $query = "SELECT * FROM requirements WHERE content_type = 'Node' AND content_id = '{$node->node_id}' AND game_id = {$gameId}";
             $reqs = Module::query($query);
             if (mysql_error()) {
                 return new returnData(1, NULL, mysql_error);
             }
             while ($reqObj = mysql_fetch_object($reqs)) {
                 $req = new stdClass();
                 $req->requirement = $reqObj->requirement;
                 $req->boole = $reqObj->boolean_operator;
                 $req->rDetail1 = $reqObj->requirement_detail_1;
                 $req->rDetail2 = $reqObj->requirement_detail_2;
                 $req->rDetail3 = $reqObj->requirement_detail_3;
                 $requirements[] = $req;
             }
             $script->req = $requirements;
             $exchanges = array();
             $query = "SELECT * FROM player_state_changes WHERE event_type = 'VIEW_NODE' AND event_detail = '{$node->node_id}' AND game_id = {$gameId}";
             $exchngs = Module::query($query);
             if (mysql_error()) {
                 return new returnData(1, NULL, mysql_error);
             }
             while ($exchangeObj = mysql_fetch_object($exchngs)) {
                 $exchange = new stdClass();
                 $exchange->action = $exchangeObj->action;
                 $exchange->obj = $exchangeObj->action_detail;
                 $exchange->amount = $exchangeObj->action_amount;
                 $exchanges[] = $exchange;
             }
             $script->exchange = $exchanges;
             $scripts[] = $script;
         }
         //Closing
         $script = new stdClass();
         $script->option = "Closing";
         $script->content = $npc->closing;
         $script->req = "(end conversation)";
         $script->exchange = "n/a";
         $scripts[] = $script;
         $character->scripts = $scripts;
         $characters[] = $character;
     }
     return $characters;
 }
Example #17
0
 public function writeOverlayToDatabase($gameId, $overlayId, $folderName, $editorId, $editorToken)
 {
     if (!Module::authenticateGameEditor($gameId, $editorId, $editorToken, "read_write")) {
         return new returnData(6, NULL, "Failed Authentication");
     }
     // go to folder for game ID: /var/www/html/server/gamedata/{game_id}/
     $sGameDir = "/var/www/html/server/gamedata/" . $gameId . "/";
     $sOverlayDir = $sGameDir . $folderName;
     $diOverlay = new DirectoryIterator($sOverlayDir);
     $i = 0;
     $query = "DELETE FROM overlay_tiles WHERE overlay_id = {$overlayId}";
     $rsResult = Module::query($query);
     if (mysql_error()) {
         return new returnData(3, NULL, "SQL Error");
     }
     foreach ($diOverlay as $dirMain1) {
         if ($dirMain1->isDir() && !$dirMain1->isDot() && $i != 0) {
             //&& !(strpos($dirMain1->getFilename(), "__") > 0)
             //echo "dirMain1:" . $dirMain1->getFilename() ."---- ";
             $diMain1 = new DirectoryIterator($dirMain1->getPath() . "/" . $dirMain1->getFilename());
             foreach ($diMain1 as $dirZoom) {
                 //go to last one
                 if ($dirZoom->isDir() && !$dirZoom->isDot()) {
                     //&& !(strpos($dirMain2->getFilename(), "__") > 0)
                     $diZoom = new DirectoryIterator($dirZoom->getPath() . "/" . $dirZoom->getFilename());
                     // step through zoom level folders
                     foreach ($diZoom as $dirX) {
                         if ($dirX->isDir() && !$dirX->isDot()) {
                             // step through y folders
                             $diX = new DirectoryIterator($dirX->getPath() . "/" . $dirX->getFilename());
                             foreach ($diX as $fileY) {
                                 if (strpos($fileY->getFilename(), ".png") > 0) {
                                     $fileYName = $fileY->getFilename();
                                     $fileYShortName = substr($fileYName, 0, -4);
                                     $dirMain1Name = $dirMain1->getFilename();
                                     $dirZoomName = $dirZoom->getFilename();
                                     $dirXName = $dirX->getFilename();
                                     $fullFileName = $overlayId . "_" . $dirZoomName . "_" . $dirXName . "_" . $fileYName;
                                     $fullNewDirAndFileName = $sGameDir . $fullFileName;
                                     $fullOldDirAndFileName = $sOverlayDir . "/" . $dirMain1Name . "/" . $dirZoomName . "/" . $dirXName . "/" . $fileYName;
                                     $filePath = $gameId . "/" . $fullFileName;
                                     $query3 = "INSERT INTO media SET game_id = {$gameId}, name = '{$fullFileName}', file_path = '{$filePath}'";
                                     $rsResult3 = Module::query($query3);
                                     if (mysql_error()) {
                                         return new returnData(3, NULL, "SQL Error inserting Media: " . $query3);
                                     }
                                     $media_id = mysql_insert_id();
                                     $query4 = "REPLACE INTO overlay_tiles SET overlay_id = {$overlayId}, media_id={$media_id}, zoom={$dirZoomName}, x={$dirXName}, y={$fileYShortName}";
                                     $rsResult4 = Module::query($query4);
                                     if (mysql_error()) {
                                         return new returnData(3, NULL, "SQL Error inserting tiles: " . $query4);
                                     }
                                     // copy file into root game directory
                                     copy($fullOldDirAndFileName, $fullNewDirAndFileName);
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $i = $i + 1;
     }
     $query5 = "UPDATE overlays SET file_uploaded = 1 WHERE overlay_id = {$overlayId} and game_id = {$gameId}";
     $rsResult5 = Module::query($query5);
     if (mysql_error()) {
         return new returnData(3, NULL, "SQL Error setting zip file uploaded flag: " . $query5);
     }
     // delete overlay folder now that it is no longer needed
     $this->recursiveRemoveDirectory($sOverlayDir);
     return new returnData(0, $fullOldDirAndFileName . "->" . $fullNewDirAndFileName);
 }
Example #18
0
 public function searchGameForErrors($gid)
 {
     //     $query = "SELECT name FROM games WHERE game_id = {$gid}";
     //     $name = Module::query($query);
     //return "\nLooking for problems in {$name}\nNote: This check does not quarantee there are no errors in your game, but only checks for a few common mistakes.\n";
     $query = "SELECT * FROM requirements WHERE game_id = {$gid}";
     $resultMain = Module::query($query);
     while ($resultMain && ($row = mysql_fetch_object($resultMain))) {
         if (!$row->requirement_detail_1) {
             if ($row->requirement == "PLAYER_HAS_ITEM" || $row->requirement == "PLAYER_VIEWED_ITEM") {
                 if (!($row->content_type == "Node")) {
                     return "\nThere is a requirement of a {$row->content_type} with id: {$row->content_id} that doesn't specify which item the player needs to have/have viewed.\n";
                 } else {
                     $scriptTitle = Module::query("SELECT title FROM nodes WHERE game_id = {$gid} AND node_id = {$row->content_id}");
                     return "\nThere is a requirement of a {$row->content_type} with the title of {$scriptTitle} that doesn't specify which item the player needs to have/have viewed.\n";
                 }
                 if (!$row->requirement_detail_2 && $row->requirement == "Player_HAS_ITEM") {
                     if (!($row->content_type == "Node")) {
                         return "\nThere is a requirement of a {$row->content_type} with id: {$row->content_id} that requires the player has a certain item, but not the quantity of that item needed.\n";
                     } else {
                         $scriptTitle = Module::query("SELECT title FROM nodes WHERE game_id = {$gid} AND node_id = {$row->content_id}");
                         return "\nThere is a requirement of a {$row->content_type} with the title of {$scriptTitle} that requires that the player has a certain item, but not the quantity of that item neeeded.\n";
                     }
                 }
             } else {
                 if ($row->requirement == "PLAYER_VIEWED_NODE") {
                     if (!($row->content_type == "Node")) {
                         return "\nThere is a requirement of a {$row->content_type} with id: {$row->content_id} that doesn't specify which node the player needed to view in order to satisfy that requirement.\n";
                     } else {
                         $scriptTitle = Module::query("SELECT title FROM nodes WHERE game_id = {$gid} AND node_id = {$row->content_id}");
                         return "\nThere is a requirement of a {$row->content_type} with the title of  {$scriptTitle} that doesn't specify which node the player needed to view in order to satisfy that requirement.\n";
                     }
                 } else {
                     if ($row->requirement == "PLAYER_VIEWED_NPC") {
                         if (!($row->content_type == "Node")) {
                             return "\nThere is a requirement of a {$row->content_type} with id: {$row->content_id} that doesn't specify which character the player needed to view in order to satisfy that requirement.\n";
                         } else {
                             $scriptTitle = Module::query("SELECT title FROM nodes WHERE game_id = {$gid} AND node_id = {$row->content_id}");
                             return "\nThere is a requirement of a {$row->content_type} with the title of {$scriptTitle} that doesn't specify which character the player needed to view in order to satisfy that requirement.\n";
                         }
                     } else {
                         if ($row->requirement == "PLAYER_VIEWED_WEBPAGE") {
                             if (!($row->content_type == "Node")) {
                                 return "\nThere is a requirement of a {$row->content_type} with id: {$row->content_id} that doesn't specify which web page the player needed to view in order to satisfy that requirement.\n";
                             } else {
                                 $scriptTitle = Module::query("SELECT title FROM nodes WHERE game_id = {$gid} AND node_id = {$row->content_id}");
                                 return "\nThere is a requirement of a {$row->content_type} with the title of {$scriptTitle} that doesn't specify which web page the player needed to view in order to satisfy that requirement.\n";
                             }
                         } else {
                             if ($row->requirement == "PLAYER_VIEWED_AUGBUBBLE") {
                                 if (!($row->content_type == "Node")) {
                                     return "\nThere is a requirement of a {$row->content_type} with id: {$row->content_id} that doesn't specify which panoramic the player needed to view in order to satisfy that requirement.\n";
                                 } else {
                                     $scriptTitle = Module::query("SELECT title FROM nodes WHERE game_id = {$gid} AND node_id = {$row->content_id}");
                                     return "\nThere is a requirement of a {$row->content_type} with the title of {$scriptTitle} that doesn't specify which panoramic the player needed to view in order to satisfy that requirement.\n";
                                 }
                             } else {
                                 if ($row->requirement == "PLAYER_HAS_COMPLETED_QUEST") {
                                     if (!($row->content_type == "Node")) {
                                         return "\nThere is a requirement of a {$row->content_type} with id: {$row->content_id} that doesn't specify which quest the player needed to complete in order to satisfy that requirement.\n";
                                     } else {
                                         $scriptTitle = Module::query("SELECT title FROM {$gid}_nodes WHERE node_id = {$row->content_id}");
                                         return "\nThere is a requirement of a {$row->content_type} with the title of {$scriptTitle} that doesn't specify which quest the player needed to complete in order to satisfy that requirement.\n";
                                     }
                                 } else {
                                     if ($row->requirement == "PLAYER_HAS_RECEIVED_INCOMING_WEB_HOOK") {
                                         if (!($row->content_type == "Node")) {
                                             return "\nThere is a requirement of a {$row->content_type} with id: {$row->content_id} that doesn't specify which incoming web hook the player needed to receive in order to satisfy that requirement.\n";
                                         } else {
                                             $scriptTitle = Module::query("SELECT title FROM {$gid}_nodes WHERE node_id = {$row->content_id}");
                                             return "\nThere is a requirement of a {$row->content_type} with the title of {$scriptTitle} that doesn't specify which incoming web hook the player needed to receive in order to satisfy that requirement.\n";
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $query = "SELECT * FROM player_state_changes";
     $resultMain = Module::query($query);
     while ($resultMain && ($row = mysql_fetch_object($resultMain))) {
         if ($row->event_type == "VIEW_ITEM") {
             if (!$row->action_detail) {
                 return "\nThere is an item of id: {$row->event_detail} that doesn't specify what item to give or take when viewed.\n";
             }
             if (!$row->action_amount) {
                 return "\nThere is an item of id: {$row->event_detail} that doesn't specify what quantity of an item to give or take when viewed.\n";
             }
         } else {
             if ($row->event_type == "VIEW_NODE") {
                 if (!$row->action_detail) {
                     $scriptTitle = Module::query("SELECT title FROM nodes WHERE game_id = {$gid} AND node_id = {$row->event_detail}");
                     return "\nThere is a node with the title of {$scriptTitle} that doesn't specify what item to give or take when viewed.\n";
                 }
                 if (!$row->action_amount) {
                     $scriptTitle = Module::query("SELECT title FROM nodes WHERE game_id = {$gid} AND node_id = {$row->event_detail}");
                     return "\nThere is a node with the title of {$scriptTitle} that doesn't specify what quantity of an item to give or take when viewed.\n";
                 }
             } else {
                 if ($row->event_type == "VIEW_NPC") {
                     if (!$row->action_detail) {
                         return "\nThere is a character of id: {$row->event_detail} that doesn't specify what item to give or take when viewed.\n";
                     }
                     if (!$row->action_amount) {
                         return "\nThere is a character of id: {$row->event_detail} that doesn't specify what quantity of an item to give or take when viewed.\n";
                     }
                 } else {
                     if ($row->event_type == "VIEW_WEBPAGE") {
                         if (!$row->action_detail) {
                             return "\nThere is a web page of id: {$row->event_detail} that doesn't specify what item to give or take when viewed.\n";
                         }
                         if (!$row->action_amount) {
                             return "\nThere is a web page of id: {$row->event_detail} that doesn't specify what quantity of an item to give or take when viewed.\n";
                         }
                     } else {
                         if ($row->event_type == "VIEW_AUGBUBBLE") {
                             if (!$row->action_detail) {
                                 return "\nThere is a panoramic of id: {$row->event_detail} that doesn't specify what item to give or take when viewed.\n";
                             }
                             if (!$row->action_amount) {
                                 return "\nThere is a panoramic of id: {$row->event_detail} that doesn't specify what quantity of an item to give or take when viewed.\n";
                             }
                         } else {
                             if ($row->event_type == "RECEIVE_WEBHOOK") {
                                 if (!$row->action_detail) {
                                     return "\nThere is an web hook of id: {$row->event_detail} that doesn't specify what item to give or take when received.\n";
                                 }
                                 if (!$row->action_amount) {
                                     return "\nThere is an web hook of id: {$row->event_detail} that doesn't specify what quantity of an item to give or take when received.\n";
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $query = "SELECT * FROM nodes WHERE game_id = {$gid}";
     $result = Module::query($query);
     while ($result && ($row = mysql_fetch_object($result))) {
         if ($row->text) {
             $inputString = $row->text;
             if (strspn($inputString, "<>") > 0 && (substr_count($inputString, "<npc>") > 0 || substr_count($inputString, "<pc>") > 0 || substr_count($inputString, "<dialog>") > 0) && !(substr_count($inputString, "<p>") > 0) && !(substr_count($inputString, "<b>") > 0) && !(substr_count($inputString, "<i>") > 0) && !(substr_count($inputString, "<img") > 0) && !(substr_count($inputString, "<table>") > 0)) {
                 @($output = simplexml_load_string($inputString));
                 if (!$output) {
                     return "\nThere is improperly formatted xml in the node with title:\n{$row->title}\nand text:\n{$row->text}\n";
                 }
             }
         }
     }
     $query = "SELECT * FROM npcs WHERE game_id = {$gid}";
     $result = Module::query($query);
     while ($result && ($row = mysql_fetch_object($result))) {
         if ($row->text) {
             $inputString = $row->text;
             if (strspn($inputString, "<>") > 0 && (substr_count($inputString, "<npc>") > 0 || substr_count($inputString, "<pc>") > 0 || substr_count($inputString, "<dialog>") > 0) && !(substr_count($inputString, "<p>") > 0) && !(substr_count($inputString, "<b>") > 0) && !(substr_count($inputString, "<i>") > 0) && !(substr_count($inputString, "<img") > 0) && !(substr_count($inputString, "<table>") > 0)) {
                 @($output = simplexml_load_string($inputString));
                 if (!$output) {
                     return "\nThere is improperly formatted xml in the npc with name:\n{$row->name}\nand greeting:\n{$row->text}\n";
                 }
             }
         }
         if ($row->closing) {
             $inputString = $row->closing;
             if (strspn($inputString, "<>") > 0 && (substr_count($inputString, "<npc>") > 0 || substr_count($inputString, "<pc>") > 0 || substr_count($inputString, "<dialog>") > 0) && !(substr_count($inputString, "<p>") > 0) && !(substr_count($inputString, "<b>") > 0) && !(substr_count($inputString, "<i>") > 0) && !(substr_count($inputString, "<img") > 0) && !(substr_count($inputString, "<table>") > 0)) {
                 @($output = simplexml_load_string($inputString));
                 if (!$output) {
                     return "\nThere is improperly formatted xml in the npc with name:\n{$row->name}\nand closing:\n{$row->text}\n";
                 }
             }
         }
     }
 }
Example #19
0
 private function lookupContentTypeOptionsFromSQL()
 {
     $query = "SHOW COLUMNS FROM qrcodes LIKE 'link_type'";
     $result = Module::query($query);
     $row = @mysql_fetch_array($result, MYSQL_NUM);
     $regex = "/'(.*?)'/";
     preg_match_all($regex, $row[1], $enum_array);
     $enum_fields = $enum_array[1];
     return $enum_fields;
 }
Example #20
0
 public function setWebHookReq($gameId, $webHookId, $lastLocationId, $playerId)
 {
     if ($playerId != NULL) {
         Module::processGameEvent($playerId, $gameId, "RECEIVE_WEBHOOK", $webHookId);
     } else {
         $query = "SELECT player_id FROM player_log WHERE game_id='{$gameId}', event_detail_1='{$lastLocationId}', deleted='0'";
         $result = Module::query($query);
         while ($pid = mysql_fetch_object($result)) {
             Module::processGameEvent($playerId, $gameId, "RECEIVE_WEBHOOK", $webHookId);
         }
     }
 }
Example #21
0
 private function lookupRequirementTypeOptionsFromSQL()
 {
     $result = Module::query("SHOW COLUMNS FROM requirements LIKE 'requirement'");
     $row = mysql_fetch_array($result, MYSQL_NUM);
     $regex = "/'(.*?)'/";
     preg_match_all($regex, $row[1], $enum_array);
     $enum_fields = $enum_array[1];
     return $enum_fields;
 }
Example #22
0
 public static function getDetailedGameInfo($gameId)
 {
     $query = "SELECT games.*, pcm.name as pc_media_name, pcm.file_path as pc_media_url, m.name as media_name, m.file_path as media_url, im.name as icon_name, im.file_path as icon_url FROM games LEFT JOIN media as m ON games.media_id = m.media_id LEFT JOIN media as im ON games.icon_media_id = im.media_id LEFT JOIN media as pcm on games.pc_media_id = pcm.media_id WHERE games.game_id = '{$gameId}'";
     $result = Module::query($query);
     $game = mysql_fetch_object($result);
     if (!$game) {
         return "Invalid Game Id";
     }
     if ($game->media_url) {
         $game->media_url = Config::gamedataWWWPath . '/' . $game->media_url;
     }
     if ($game->icon_url) {
         $game->icon_url = Config::gamedataWWWPath . '/' . $game->icon_url;
     }
     $query = "SELECT editors.name FROM game_editors JOIN editors ON editors.editor_id = game_editors.editor_id WHERE game_editors.game_id = '{$gameId}'";
     $result = Module::query($query);
     $auth = array();
     while ($a = mysql_fetch_object($result)) {
         $auth[] = $a;
     }
     $game->authors = $auth;
     return $game;
 }
Example #23
0
 public function addNoteFromJSON($glob)
 {
     //WHY DOESNT THIS HAPPEN VIA THE FRAMEWORK?!
     $data = file_get_contents("php://input");
     $glob = json_decode($data);
     $gameId = $glob->gameId;
     $noteId = $glob->noteId;
     $playerId = $glob->playerId;
     $title = $glob->title;
     $description = $glob->description;
     $publicToMap = $glob->publicToMap;
     $publicToBook = $glob->publicToBook;
     $location = $glob->location;
     $media = $glob->media;
     $tags = $glob->tags;
     $publicToMap = 1;
     $publicToBook = 1;
     if (!is_numeric($gameId)) {
         return new returnData(1, NULL, "JSON package has no numeric member \"gameId\"");
     }
     if (!is_numeric($playerId)) {
         return new returnData(1, NULL, "JSON package has no numeric member \"playerId\"");
     }
     if (!$noteId) {
         $noteId = Notebook::createNote($gameId, $playerId)->data;
     }
     Notebook::updateNote($noteId, $title, $publicToMap, $publicToBook, $location->latitude, $location->longitude);
     //THIS IS THE CLEANEST WAY TO HANDLE LEGACY DESCRIPTION STORAGE
     Module::query("DELETE FROM note_content WHERE game_id = '{$gameId}' AND note_id = '{$noteId}' AND type = 'TEXT'");
     Module::query("INSERT INTO note_content (note_id, game_id, media_id, type, text) VALUES ('" . $noteId . "', '" . $gameId . "', 0, 'TEXT', '" . $description . "')");
     for ($i = 0; is_array($media) && $i < count($media); $i++) {
         $mediaId = Media::createMediaFromJSON($media[$i])->data->media_id;
         Notebook::addContentToNote($noteId, $mediaId, "MEDIA");
     }
     $oldTags = Notebook::getNoteTags($noteId, $gameId);
     for ($i = 0; is_array($oldTags) && $i < count($oldTags); $i++) {
         $tagDeleted = true;
         for ($j = 0; is_array($tags) && $j < count($tags); $j++) {
             if ($oldTags[$i]->tag == $tags[$j]) {
                 $tagDeleted = false;
             }
         }
         if ($tagDeleted) {
             Notebook::deleteTagFromNote($noteId, $oldTags[$i]->tag_id);
         }
     }
     for ($i = 0; is_array($tags) && $i < count($tags); $i++) {
         Notebook::addTagToNote($noteId, $tags[$i]);
     }
     return new returnData(0, Notebook::getNote($noteId)->data);
 }
Example #24
0
 public function deleteMedia($gameId, $mediaId, $editorId, $editorToken)
 {
     if (!Module::authenticateGameEditor($gameId, $editorId, $editorToken, "read_write")) {
         return new returnData(6, NULL, "Failed Authentication");
     }
     $query = "SELECT * FROM media \n            WHERE media_id = {$mediaId}";
     $rsResult = Module::query($query);
     if (mysql_error()) {
         return new returnData(3, NULL, "SQL Error:" . mysql_error());
     }
     $mediaRow = mysql_fetch_array($rsResult);
     if ($mediaRow === FALSE) {
         return new returnData(2, NULL, "Invalid Media Record");
     }
     //Delete the Record
     $query = "DELETE FROM media \n            WHERE media_id = {$mediaId}";
     $rsResult = Module::query($query);
     if (mysql_error()) {
         return new returnData(3, NULL, "SQL Error:" . mysql_error());
     }
     //Delete the file
     $fileToDelete = Config::gamedataFSPath . "/" . $mediaRow['file_path'];
     if (!@unlink($fileToDelete)) {
         return new returnData(4, NULL, "Record Deleted but file was not: {$fileToDelete}");
     }
     //Done
     if (mysql_affected_rows()) {
         return new returnData(0, TRUE);
     } else {
         return new returnData(0, FALSE);
     }
 }
Example #25
0
 public function deleteNode($gameId, $intNodeID)
 {
     Locations::deleteLocationsForObject($gameId, 'Node', $intNodeID);
     Requirements::deleteRequirementsForRequirementObject($gameId, 'Node', $intNodeID);
     PlayerStateChanges::deletePlayerStateChangesThatRefrenceObject($gameId, 'Node', $intNodeID);
     $query = "DELETE FROM nodes WHERE game_id = {$gameId} AND node_id = {$intNodeID}";
     $rsResult = Module::query($query);
     if (mysql_error()) {
         return new returnData(3, NULL, "SQL Error");
     }
     if (mysql_affected_rows()) {
         return new returnData(0);
     } else {
         return new returnData(2, NULL, 'invalid node id');
     }
 }
Example #26
0
 public function pruneNoteContentFromGame($gameId, $surrogate, $editorId, $editorToken)
 {
     if (!Module::authenticateGameEditor($gameId, $editorId, $editorToken, "read_write")) {
         return new returnData(6, NULL, "Failed Authentication");
     }
     $unused_content = array();
     $noteContent = Module::queryArray("SELECT * FROM note_content WHERE game_id = '{$gameId}'");
     for ($i = 0; $i < count($noteContent); $i++) {
         if (!Module::queryObject("SELECT * FROM notes WHERE game_id = '{$gameId}' AND note_id = '{$noteContent[$i]->note_id}'")) {
             $unused_content[] = $noteContent[$i]->content_id;
         }
     }
     if ($surrogate) {
         for ($i = 0; $i < count($unused_content); $i++) {
             Module::query("UPDATE note_content SET game_id = '{$surrogate}' WHERE game_id = '{$gameId}' AND content_id = '{$unused_content[$i]}'");
         }
     } else {
         for ($i = 0; $i < count($unused_content); $i++) {
             Module::query("DELETE FROM note_content WHERE game_id = '{$gameId}' AND content_id = '{$unused_content[$i]}'");
         }
     }
     return $unused_content;
 }