Example #1
0
 public function getQuestsForPlayer($gameId, $playerId)
 {
     $quests = Module::queryArray("SELECT * FROM quests WHERE game_id = {$gameId} ORDER BY sort_index");
     if (mysql_error()) {
         return new returnData(3, NULL, "SQL Error");
     }
     $activeQuests = array();
     $completedQuests = array();
     for ($i = 0; $i < count($quests); $i++) {
         $quest = $quests[$i];
         $display = Module::objectMeetsRequirements($gameId, $playerId, "QuestDisplay", $quest->quest_id);
         $complete = Module::playerHasLog($gameId, $playerId, Module::kLOG_COMPLETE_QUEST, $quest->quest_id);
         if ($display && !$complete) {
             $activeQuests[] = $quest;
         }
         if ($display && $complete) {
             $completedQuests[] = $quest;
         }
     }
     $return = new stdClass();
     $return->totalQuests = count($quests);
     $return->active = $activeQuests;
     $return->completed = $completedQuests;
     return new returnData(0, $return);
 }
Example #2
0
 public static function getFullItems($gameId)
 {
     $items = Module::queryArray("SELECT * FROM items WHERE game_id = '{$gameId}';");
     $tags = Module::queryArray("SELECT ot.tag_id, ot.object_id, got.media_id, got.tag FROM (SELECT * FROM object_tags WHERE object_type = 'ITEM') as ot LEFT JOIN (SELECT * FROM game_object_tags WHERE game_id = '{$gameId}' AND use_for_sort = '1') as got ON ot.tag_id = got.tag_id;");
     for ($i = 0; $i < count($items); $i++) {
         $items[$i]->tags = array();
         for ($t = 0; $t < count($tags); $t++) {
             if ($tags[$t]->object_id == $items[$i]->item_id && $tags[$t]->tag != null) {
                 $items[$i]->tags[] = $tags[$t];
             }
         }
     }
     return new returnData(0, $items);
 }
Example #3
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 #4
0
 public function getOverlaysForPlayer($gameId, $playerId)
 {
     $overlays = Module::queryArray("SELECT * FROM overlays WHERE game_id = {$gameId};");
     $overlayIds = array();
     for ($i = 0; $i < count($overlays); $i++) {
         $overlay = $overlays[$i];
         $display = Module::objectMeetsRequirements($gameId, $playerId, "CustomMap", $overlay->overlay_id);
         if ($display) {
             $overlayObj = new stdClass();
             $overlayObj->overlay_id = $overlay->overlay_id;
             $overlayIds[] = $overlayObj;
         }
     }
     return new returnData(0, $overlayIds);
 }
Example #5
0
 public function topPlayersWithMostLikedNotes($gameId, $startFlag = "0000-00-00 00:00:00", $endFlag = "9999-99-99 12:59:59")
 {
     $notes = Module::queryArray("SELECT note_id, owner_id FROM notes WHERE game_id = '{$gameId}' AND created > '{$startFlag}' AND created < '{$endFlag}'");
     $playerLikes = array();
     for ($i = 0; $i < count($notes); $i++) {
         if (!$playerLikes[$notes[$i]->owner_id]) {
             $playerLikes[$notes[$i]->owner_id] = 0;
         }
         if (Module::queryObject("SELECT player_id FROM note_likes WHERE note_id = '{$notes[$i]->note_id}' LIMIT 1")) {
             $playerLikes[$notes[$i]->owner_id]++;
         }
     }
     $playerLikeObjects = array();
     foreach ($playerLikes as $pidkey => $countval) {
         $plo = new stdClass();
         $plo->player_id = $pidkey;
         $plo->liked_notes = $countval;
         $plo->display_name = Module::queryObject("SELECT display_name FROM players WHERE player_id = '{$pidkey}'")->display_name;
         $playerLikeObjects[] = $plo;
     }
     return $playerLikeObjects;
 }
Example #6
0
 public function getGameTags($gameId)
 {
     $tags = Module::queryArray("SELECT tag_id, tag, player_created, media_id from game_tags WHERE game_id = '{$gameId}'");
     return new returnData(0, $tags);
 }
Example #7
0
 private function getPackagedRequirementsForGameForTypeForId($gameId, $type, $id)
 {
     $pack = new stdClass();
     $pack->type = $type;
     $pack->type_id = $id;
     $pack->and_reqs = Module::queryArray("SELECT * FROM requirements WHERE game_id = '{$gameId}' AND content_type = '{$type}' AND content_id = '{$id}' AND boolean_operator = 'AND'");
     $pack->or_reqs = Module::queryArray("SELECT * FROM requirements WHERE game_id = '{$gameId}' AND content_type = '{$type}' AND content_id = '{$id}' AND boolean_operator = 'OR'");
     return $pack;
 }
Example #8
0
 private static function getPlayerArrayDataBP($gameId, $playerArray, $getItems = true, $getAttributes = true, $getNotes = true)
 {
     //preload data into memory for quick re-use
     $mediaA = Media::getMedia($gameId)->data;
     $mediaMap = array();
     $numMedia = count($mediaA);
     for ($i = 0; $i < $numMedia; $i++) {
         $mediaMap[$mediaA[$i]->media_id] = $mediaA[$i];
     }
     if ($getItems) {
         $itemsMap = array();
         $itemsA = Module::queryArray("SELECT * FROM items WHERE game_id = '{$gameId}' AND (is_attribute = '0' OR is_attribute = '')");
         $numItems = count($itemsA);
         for ($i = 0; $i < $numItems; $i++) {
             $itemsA[$i]->media_url = $mediaMap[$itemsA[$i]->media_id]->url;
             $itemsA[$i]->media_thumb_url = $mediaMap[$itemsA[$i]->media_id]->thumb_url;
             $itemsA[$i]->icon_url = $mediaMap[$itemsA[$i]->icon_media_id]->url;
             $itemsA[$i]->icon_thumb_url = $mediaMap[$itemsA[$i]->icon_media_id]->thumb_url;
             $itemsMap[$itemsA[$i]->item_id] = $itemsA[$i];
         }
     }
     if ($getAttributes) {
         $attributesMap = array();
         $attributesA = Module::queryArray("SELECT * FROM items WHERE game_id = '{$gameId}' AND is_attribute = '1'");
         $numAttributes = count($attributesA);
         for ($i = 0; $i < $numAttributes; $i++) {
             $attributesA[$i]->media_url = $mediaMap[$attributesA[$i]->media_id]->url;
             $attributesA[$i]->media_thumb_url = $mediaMap[$attributesA[$i]->media_id]->thumb_url;
             $attributesA[$i]->icon_url = $mediaMap[$attributesA[$i]->icon_media_id]->url;
             $attributesA[$i]->icon_thumb_url = $mediaMap[$attributesA[$i]->icon_media_id]->thumb_url;
             $attributesMap[$attributesA[$i]->media_id] = $attributesA[$i];
         }
     }
     if ($getNotes) {
         $gameTagsMap = array();
         $gameTagsA = Module::queryArray("SELECT * FROM game_tags WHERE game_id = '{$gameId}'");
         $numGameTags = count($gameTagsA);
         for ($i = 0; $i < $numGameTags; $i++) {
             $gameTagsMap[$gameTagsA[$i]->tag_id] = $gameTagsA[$i];
         }
     }
     $backpacks = array();
     $numPlayers = count($playerArray);
     for ($i = 0; $i < $numPlayers; $i++) {
         $backpack = new stdClass();
         $backpack->owner = Module::queryObject("SELECT player_id, user_name, display_name, group_name, media_id FROM players WHERE player_id = '{$playerArray[$i]}'");
         if (!$backpack->owner) {
             continue;
         }
         $playerPic = Media::getMediaObject('player', $backpack->owner->media_id)->data;
         $backpack->owner->player_pic_url = $playerPic->url;
         $backpack->owner->player_pic_thumb_url = $playerPic->thumb_url;
         $media->thumb_file_path = substr($media->file_path, 0, strrpos($media->file_path, '.')) . '_128' . substr($media->file_path, strrpos($media->file_path, '.'));
         $media->url_path = Config::gamedataWWWPath . "/";
         if ($getItems || $getAttributes) {
             if ($getItems) {
                 $backpack->items = array();
             }
             if ($getAttributes) {
                 $backpack->attributes = array();
             }
             $playerItemData = Module::queryArray("SELECT item_id, qty FROM player_items WHERE game_id = '{$gameId}' AND player_id = '{$playerArray[$i]}'");
             $numItems = count($playerItemData);
             for ($j = 0; $j < $numItems; $j++) {
                 if ($getItems && isset($itemsMap[$playerItemData[$j]->item_id])) {
                     $item = clone $itemsMap[$playerItemData[$j]->item_id];
                     $item->qty = $playerItemData[$j]->qty;
                     $backpack->items[] = $item;
                 } else {
                     if ($getAttributes && isset($attributesMap[$playerItemData[$j]->item_id])) {
                         $attribute = clone $attributesMap[$playerItemData[$j]->item_id];
                         $attribute->qty = $playerItemData[$j]->qty;
                         $backpack->attributes[] = $attribute;
                     }
                 }
             }
         }
         if ($getNotes) {
             $rawNotes = Module::query("SELECT * FROM notes WHERE owner_id = '{$playerArray[$i]}' AND game_id = '{$gameId}' AND parent_note_id = 0 ORDER BY sort_index ASC");
             $backpack->notes = array();
             while ($note = mysql_fetch_object($rawNotes)) {
                 $note->username = $backpack->owner->user_name;
                 if ($backpack->owner->display_name && $backpack->owner->display_name != "") {
                     $note->username = $backpack->owner->display_name;
                 }
                 $rawContent = Module::query("SELECT * FROM note_content WHERE note_id = '{$note->note_id}'");
                 $note->contents = array();
                 while ($content = mysql_fetch_object($rawContent)) {
                     $content->media_url = $mediaMap[$content->media_id]->url;
                     $content->media_thumb_url = $mediaMap[$content->media_id]->thumb_url;
                     $note->contents[] = $content;
                 }
                 $note->likes = Notes::getNoteLikes($note->note_id);
                 $note->player_liked = Notes::playerLiked($playerId, $note->note_id);
                 $result = Module::query("SELECT * FROM note_tags WHERE note_id = '{$note->note_id}'");
                 $note->tags = array();
                 while ($tag = mysql_fetch_object($result)) {
                     $note->tags[] = $gameTagsMap[$tag->tag_id];
                 }
                 $note->dropped = 0;
                 if ($location = Notes::noteDropped($note->note_id, $note->game_id)) {
                     $note->dropped = 1;
                 }
                 $note->lat = $location ? $location->latitude : 0;
                 $note->lon = $location ? $location->longitude : 0;
                 $rawComments = Module::query("SELECT * FROM notes WHERE game_id = '{$gameId}' AND parent_note_id = {$note->note_id} ORDER BY sort_index ASC");
                 $note->comments = array();
                 while ($comment = mysql_fetch_object($rawComments)) {
                     $player = Module::queryObject("SELECT user_name, display_name FROM players WHERE player_id = '{$comment->owner_id}' LIMIT 1");
                     $comment->username = $player->user_name;
                     $comment->displayname = $player->display_name;
                     $rawContent = Module::query("SELECT * FROM note_content WHERE note_id = '{$comment->note_id}'");
                     $comment->contents = array();
                     while ($content = mysql_fetch_object($rawContent)) {
                         $content->media_url = $mediaMap[$content->media_id]->url;
                         $content->media_thumb_url = $mediaMap[$content->media_id]->thumb_url;
                         $comment->contents[] = $content;
                     }
                     $comment->likes = Notes::getNoteLikes($comment->note_id);
                     $comment->player_liked = Notes::playerLiked($playerId, $comment->note_id);
                     $note->comments[] = $comment;
                 }
                 $backpack->notes[] = $note;
             }
         }
         $backpacks[] = $backpack;
     }
     return $backpacks;
 }
Example #9
0
 public function getEditorsWithEmail($email)
 {
     $eArray = Module::queryArray("SELECT editor_id, email FROM editors WHERE email LIKE '" . $email . "'");
     return new returnData(0, $eArray);
 }
Example #10
0
 public function getPlayerLogs($glob)
 {
     ini_set('display_errors', 1);
     error_reporting(E_ALL);
     //Grrr amfphp should take care of this...
     $data = file_get_contents("php://input");
     $glob = json_decode($data);
     $reqOutputFormat = $glob->output_format;
     $reqOutputToFile = $glob->output_to_file;
     $reqOutputFilename = $glob->output_filename;
     $reqGameId = $glob->game_id;
     $reqEditorId = $glob->editor_id;
     $reqEditorToken = $glob->editor_token;
     $reqGroup = $glob->groupname;
     $reqPlayers = $glob->players;
     $reqPlayer = $glob->player;
     $reqStartDate = $glob->start_date;
     $reqEndDate = $glob->end_date;
     $reqGetExpired = $glob->get_expired;
     $reqVerbose = $glob->verbose;
     $iknowwhatimdoing = $glob->i_know_what_im_doing == "yes";
     //minimal level of "security" to prevent massive data requests
     if ($iknowwhatimdoing) {
         set_time_limit(0);
         ignore_user_abort(1);
     }
     //validation
     $expectsNotice = 'Expects JSON argument of minimal form: {"output_format":"json","game_id":1,"editor_id":1,"editor_token":"abc123"}';
     if (!is_string($reqOutputFormat)) {
         $reqOutputFormat = "json";
     } else {
         $reqOutputFormat = strToLower($reqOutputFormat);
     }
     if ($reqOutputFormat != "json" && $reqOutputFormat != "csv" && $reqOutputFormat != "xml") {
         return new returnData(1, NULL, "Error- Invalid output format (" . $reqOutputFormat . ")\n" . $expectsNotice);
     }
     if (is_numeric($reqOutputToFile)) {
         $reqOutputToFile = intval($reqOutputToFile);
     } else {
         $reqOutputToFile = 0;
     }
     if (!is_string($reqOutputFilename)) {
         $reqOutputFilename = $reqOutputToFile ? "mostrecentlogrequest" : "tmpmostrecentlogrequest";
     }
     if (is_numeric($reqGameId)) {
         $reqGameId = intval($reqGameId);
     } else {
         return new returnData(1, NULL, "Error- Empty Game (" . $reqGameId . ")\n" . $expectsNotice);
     }
     if (is_numeric($reqEditorId)) {
         $reqEditorId = intval($reqEditorId);
     } else {
         return new returnData(1, NULL, "Error- Empty Editor (" . $reqEditorId . ")\n" . $expectsNotice);
     }
     if (!is_string($reqEditorToken)) {
         return new returnData(1, NULL, "Error- Invalid EditorToken (" . $reqEditorToken . ")\n" . $expectsNotice);
     }
     if (!Module::authenticateGameEditor($reqGameId, $reqEditorId, $reqEditorToken, "read_write")) {
         return new returnData(6, NULL, "Failed Authentication");
     }
     $filterMode = "none";
     if (is_string($reqGroup)) {
         $filterMode = "group";
     }
     if (is_array($reqPlayers)) {
         $filterMode = "players";
     }
     if (is_numeric($reqPlayer)) {
         $filterMode = "player";
     }
     if (!preg_match("/\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}/", $reqStartDate)) {
         $reqStartDate = "0000-00-00 00:00:00";
     }
     if (!preg_match("/\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}/", $reqEndDate)) {
         $reqEndDate = "9999-00-00 00:00:00";
     }
     if (!$iknowwhatimdoing && floor(abs(strtotime($reqEndDate) - strtotime($reqStartDate)) / (60 * 60 * 24 * 31)) > 0) {
         return new returnData(1, NULL, "Please don't ask for more than a month of data at a time!");
     }
     if (!is_numeric($reqGetExpired)) {
         $reqGetExpired = 0;
     } else {
         if (intval($reqGetExpired) > 0) {
             $reqGetExpired = 1;
         }
     }
     if (!is_numeric($reqVerbose)) {
         $reqVerbose = 0;
     } else {
         if (intval($reqVerbose) > 0) {
             $reqVerbose = 1;
         }
     }
     $playerLogs = array();
     if ($filterMode == "group") {
         $p = Module::queryArray("SELECT player_id, display_name, media_id, group_name from players WHERE group_name = '{$reqGroup}'");
         for ($i = 0; $i < count($p); $i++) {
             $log = new stdClass();
             $log->player = $p[$i];
             if ($log->player->display_name == "") {
                 $log->player->display_name = $log->player->user_name;
             }
             $log->player->pic_url = Media::getMediaObject("player", $p[$i]->media_id)->data->url;
             $playerLogs[] = $log;
         }
     } else {
         if ($filterMode == "players") {
             for ($i = 0; $i < count($reqPlayers); $i++) {
                 $p = Module::queryObject("SELECT player_id, display_name, media_id, group_name from players WHERE player_id = '{$reqPlayers[$i]}'");
                 $log = new stdClass();
                 $log->player = $p;
                 if ($log->player->display_name == "") {
                     $log->player->display_name = $log->player->user_name;
                 }
                 $log->player->pic_url = Media::getMediaObject("player", $p->media_id)->data->url;
                 $playerLogs[] = $log;
             }
         } else {
             if ($filterMode == "player") {
                 $p = Module::queryObject("SELECT player_id, display_name, media_id, group_name from players WHERE player_id = '{$reqPlayer}'");
                 $log = new stdClass();
                 $log->player = $p;
                 if ($log->player->display_name == "") {
                     $log->player->display_name = $log->player->user_name;
                 }
                 $log->player->pic_url = Media::getMediaObject("player", $p->media_id)->data->url;
                 $playerLogs[] = $log;
             } else {
                 $r = Module::queryArray("SELECT player_id FROM player_log WHERE game_id = '{$reqGameId}' AND timestamp BETWEEN '{$reqStartDate}' AND '{$reqEndDate}' AND (deleted = 0 OR deleted = {$reqGetExpired}) GROUP BY player_id");
                 for ($i = 0; $i < count($r); $i++) {
                     $p = Module::queryObject("SELECT player_id, user_name, display_name, media_id, group_name from players WHERE player_id = '{$r[$i]->player_id}'");
                     if (!$p) {
                         continue;
                     }
                     $log = new stdClass();
                     $log->player = $p;
                     if ($log->player->display_name == "") {
                         $log->player->display_name = $log->player->user_name;
                     }
                     $log->player->pic_url = Media::getMediaObject("player", intval($p->media_id))->data->url;
                     $playerLogs[] = $log;
                 }
             }
         }
     }
     //caches for quick content construction
     $questsA = Module::queryArray("SELECT quest_id, name FROM quests WHERE game_id = '{$reqGameId}'");
     $questsH = array();
     for ($i = 0; $i < count($questsA); $i++) {
         $questsH[$questsA[$i]->quest_id] = $questsA[$i];
     }
     $itemsA = Module::queryArray("SELECT item_id, name FROM items WHERE game_id = '{$reqGameId}'");
     $itemsH = array();
     for ($i = 0; $i < count($itemsA); $i++) {
         $itemsH[$itemsA[$i]->item_id] = $itemsA[$i];
     }
     $nodesA = Module::queryArray("SELECT node_id, title FROM nodes WHERE game_id = '{$reqGameId}'");
     $nodesH = array();
     for ($i = 0; $i < count($nodesA); $i++) {
         $nodesH[$nodesA[$i]->node_id] = $nodesA[$i];
     }
     $npcsA = Module::queryArray("SELECT npc_id, name FROM npcs WHERE game_id = '{$reqGameId}'");
     $npcsH = array();
     for ($i = 0; $i < count($npcsA); $i++) {
         $npcsH[$npcsA[$i]->npc_id] = $npcsA[$i];
     }
     $webpagesA = Module::queryArray("SELECT web_page_id, name FROM web_pages WHERE game_id = '{$reqGameId}'");
     $webpagesH = array();
     for ($i = 0; $i < count($webpagesA); $i++) {
         $webpagesH[$webpagesA[$i]->web_page_id] = $webpagesA[$i];
     }
     $locationsA = Module::queryArray("SELECT location_id, name FROM locations WHERE game_id = '{$reqGameId}'");
     $locationsH = array();
     for ($i = 0; $i < count($locationsA); $i++) {
         $locationsH[$locationsA[$i]->location_id] = $locationsA[$i];
     }
     $qrcodesA = Module::queryArray("SELECT qrcode_id, link_id, code FROM qrcodes WHERE game_id = '{$reqGameId}'");
     $qrcodesH = array();
     for ($i = 0; $i < count($qrcodesA); $i++) {
         $qrcodesH[$qrcodesA[$i]->code] = $qrcodesA[$i];
     }
     $webhooksA = Module::queryArray("SELECT web_hook_id, name FROM web_hooks WHERE game_id = '{$reqGameId}'");
     $webhooksH = array();
     for ($i = 0; $i < count($webhooksA); $i++) {
         $webhooksH[$webhooksA[$i]->web_hook_id] = $webhooksA[$i];
     }
     //used to segment writes so not too much memory is used
     $pagesize = 1000;
     $i = 0;
     $output_filename = Config::gamedataFSPath . "/" . $reqGameId . "/" . addslashes($reqOutputFilename) . "." . $reqOutputFormat;
     $output_fileurl = Config::gamedataWWWPath . "/" . $reqGameId . "/" . addslashes($reqOutputFilename) . "." . $reqOutputFormat;
     file_put_contents($output_filename, "", 0);
     //clear output file
     while ($i < count($playerLogs)) {
         $playerLogs[$i]->log = array();
         $r = Module::queryArray("SELECT * FROM player_log WHERE player_id = '{$playerLogs[$i]->player->player_id}' AND game_id = '{$reqGameId}' AND timestamp BETWEEN '{$reqStartDate}' AND '{$reqEndDate}' AND (deleted = 0 OR deleted = {$reqGetExpired});");
         for ($j = 0; $j < count($r); $j++) {
             $row = new stdClass();
             switch ($r[$j]->event_type) {
                 case "PICKUP_ITEM":
                     $row->event = "Received Item";
                     $row->object = $itemsH[$r[$j]->event_detail_1]->name;
                     $row->qty = $r[$j]->event_detail_2;
                     $row->timestamp = $r[$j]->timestamp;
                     $row->human = $playerLogs[$i]->player->display_name . " received " . $row->qty . " " . $row->object . " (Item).";
                     break;
                 case "DROP_ITEM":
                 case "DESTROY_ITEM":
                     $row->event = "Lost Item";
                     $row->object = $itemsH[$r[$j]->event_detail_1]->name;
                     $row->qty = $r[$j]->event_detail_2;
                     $row->timestamp = $r[$j]->timestamp;
                     $row->human = $playerLogs[$i]->player->display_name . " lost " . $row->qty . " " . $row->object . " (Item).";
                     break;
                 case "VIEW_ITEM":
                     $row->event = "Viewed Item";
                     $row->object = $itemsH[$r[$j]->event_detail_1]->name;
                     $row->timestamp = $r[$j]->timestamp;
                     $row->human = $playerLogs[$i]->player->display_name . " viewed " . $row->object . " (Item).";
                     break;
                 case "VIEW_NODE":
                     $row->event = "Viewed Node";
                     $row->object = $nodesH[$r[$j]->event_detail_1]->title;
                     $row->timestamp = $r[$j]->timestamp;
                     $row->human = $playerLogs[$i]->player->display_name . " viewed " . $row->object . " (Node).";
                     break;
                 case "VIEW_NPC":
                     $row->event = "Viewed NPC";
                     $row->object = $npcsH[$r[$j]->event_detail_1]->name;
                     $row->timestamp = $r[$j]->timestamp;
                     $row->human = $playerLogs[$i]->player->display_name . " viewed " . $row->object . " (Npc).";
                     break;
                 case "VIEW_WEBPAGE":
                     $row->event = "Viewed Web Page";
                     $row->object = $webpagesH[$r[$j]->event_detail_1]->name;
                     $row->timestamp = $r[$j]->timestamp;
                     $row->human = $playerLogs[$i]->player->display_name . " viewed " . $row->object . " (Web Page).";
                     break;
                 case "ENTER_QRCODE":
                     $row->event = "Entered QR";
                     $row->code = $r[$j]->event_detail_1;
                     $row->object = $locationsH[$qrcodesH[$r[$j]->event_detail_1]->link_id]->name;
                     $row->timestamp = $r[$j]->timestamp;
                     $row->human = $playerLogs[$i]->player->display_name . " scanned " . $row->object . ".";
                     break;
                 case "COMPLETE_QUEST":
                     $row->event = "Completed Quest";
                     $row->object = $questsH[$r[$j]->event_detail_1]->name;
                     $row->timestamp = $r[$j]->timestamp;
                     $row->human = $playerLogs[$i]->player->display_name . " completed quest '" . $row->object . "'.";
                     break;
                 case "VIEW_MAP":
                     $row->event = "Viewed Map";
                     $row->timestamp = $r[$j]->timestamp;
                     $row->human = $playerLogs[$i]->player->display_name . " viewed the map.";
                     break;
                 case "VIEW_QUESTS":
                     $row->event = "Viewed Quests";
                     $row->timestamp = $r[$j]->timestamp;
                     $row->human = $playerLogs[$i]->player->display_name . " viewed the quests.";
                     break;
                 case "VIEW_INVENTORY":
                     $row->event = "Viewed Inventory";
                     $row->timestamp = $r[$j]->timestamp;
                     $row->human = $playerLogs[$i]->player->display_name . " viewed the inventory.";
                     break;
                 case "MOVE":
                     $row->event = "Moved";
                     $row->lat = $r[$j]->event_detail_1;
                     $row->lon = $r[$j]->event_detail_2;
                     $row->timestamp = $r[$j]->timestamp;
                     $row->human = $playerLogs[$i]->player->display_name . " moved to (" . $row->lat . ($reqOutputFormat == "csv" ? " " : ",") . $row->lon . ")";
                     break;
                 case "RECEIVE_WEBHOOK":
                     $row->event = "Received Hook";
                     $row->object = $webhooksH[$r[$j]->event_detail_1]->name;
                     $row->timestamp = $r[$j]->timestamp;
                     $row->human = $playerLogs[$i]->player->display_name . " received hook '" . $row->object . "'";
                     break;
                 default:
                     $row->event = $r[$j]->event_type;
                     $row->timestamp = $r[$j]->timestamp;
                     $row->human = $playerLogs[$i]->player->display_name . " " . $row->event;
                     break;
             }
             if ($reqVerbose) {
                 $row->raw = new stdClass();
                 $row->raw->id = $r[$j]->id;
                 $row->raw->player_id = $r[$j]->player_id;
                 $row->raw->game_id = $r[$j]->game_id;
                 $row->raw->timestamp = $r[$j]->timestamp;
                 $row->raw->event_type = $r[$j]->event_type;
                 $row->raw->event_detail_1 = $r[$j]->event_detail_1;
                 $row->raw->event_detail_2 = $r[$j]->event_detail_2;
                 $row->raw->event_detail_3 = $r[$j]->event_detail_3;
                 $row->raw->deleted = $r[$j]->deleted;
             }
             $playerLogs[$i]->log[] = $row;
         }
         if ($reqOutputFormat == "json") {
             $json = "";
             if ($i == 0) {
                 $json .= "[";
             } else {
                 $json .= ",";
             }
             $json .= json_encode($playerLogs[$i]);
             file_put_contents($output_filename, $json, FILE_APPEND);
         }
         if ($reqOutputFormat == "csv") {
             $csv = "";
             if ($i == 0) {
                 $csv .= "group_name,";
                 $csv .= "player_id,";
                 $csv .= "display_name,";
                 $csv .= "timestamp,";
                 $csv .= "human" . ($reqVerbose ? "," : "\n");
                 if ($reqVerbose) {
                     $csv .= "player_log_id,";
                     $csv .= "player_id,";
                     $csv .= "game_id,";
                     $csv .= "timestamp,";
                     $csv .= "event_type,";
                     $csv .= "event_detail_1,";
                     $csv .= "event_detail_2,";
                     $csv .= "event_detail_3,";
                     $csv .= "deleted\n";
                 }
             }
             for ($j = 0; $j < count($playerLogs[$i]->log); $j++) {
                 $csv .= $playerLogs[$i]->player->group_name . ",";
                 $csv .= $playerLogs[$i]->player->player_id . ",";
                 $csv .= $playerLogs[$i]->player->display_name . ",";
                 $csv .= $playerLogs[$i]->log[$j]->timestamp . ",";
                 $csv .= $playerLogs[$i]->log[$j]->human . ($reqVerbose ? "," : "\n");
                 if ($reqVerbose) {
                     $csv .= $playerLogs[$i]->log[$j]->raw->id . ",";
                     $csv .= $playerLogs[$i]->log[$j]->raw->player_id . ",";
                     $csv .= $playerLogs[$i]->log[$j]->raw->game_id . ",";
                     $csv .= $playerLogs[$i]->log[$j]->raw->timestamp . ",";
                     $csv .= $playerLogs[$i]->log[$j]->raw->event_type . ",";
                     $csv .= $playerLogs[$i]->log[$j]->raw->event_detail_1 . ",";
                     $csv .= $playerLogs[$i]->log[$j]->raw->event_detail_2 . ",";
                     $csv .= $playerLogs[$i]->log[$j]->raw->event_detail_3 . ",";
                     $csv .= $playerLogs[$i]->log[$j]->raw->deleted . "\n";
                 }
             }
             file_put_contents($output_filename, $csv, FILE_APPEND);
         }
         $playerLogs[$i]->log = array();
         //clear data to save memory
         $i++;
     }
     if ($reqOutputFormat == "json" && count($playerLogs) > 0) {
         //closing ]
         file_put_contents($output_filename, "]", FILE_APPEND);
     }
     if ($reqOutputToFile) {
         return new returnData(0, $output_fileurl);
     } else {
         //literally json decodes valid json data so the framework can re-encode it...
         return new returnData(0, json_decode(file_get_contents(Config::gamedataFSPath . "/" . $reqGameId . "/" . addslashes($reqOutputFilename) . "." . $reqOutputFormat)));
     }
 }
Example #11
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;
 }
Example #12
0
 public function getLocationsForPlayer($gameId, $intPlayerId, $lat = 0, $lon = 0)
 {
     $arrayLocations = array();
     //Gets all non-spawned locations
     $query = "SELECT game_locations.*, gamefountains.fountain_id, gamefountains.spawn_probability, gamefountains.spawn_rate, gamefountains.max_amount, gamefountains.last_spawned, gamefountains.active FROM (SELECT * FROM locations WHERE game_id = {$gameId}) AS game_locations LEFT JOIN (SELECT * FROM spawnables WHERE game_id = {$gameId}) AS gamespawns ON game_locations.type = gamespawns.type AND game_locations.type_id = gamespawns.type_id LEFT JOIN (SELECT * FROM fountains WHERE game_id = {$gameId}) AS gamefountains ON game_locations.location_id = gamefountains.location_id WHERE game_locations.latitude != '' AND game_locations.longitude != '' AND (spawnable_id IS NULL OR gamespawns.active = 0)";
     $rsLocations = Module::query($query);
     if (mysql_error()) {
         return new returnData(3, NULL, "SQL Error" . mysql_error());
     }
     $query = "SELECT full_quick_travel FROM games WHERE game_id = '{$gameId}'";
     $fqtresult = Module::query($query);
     $fullQuickTravel = mysql_fetch_object($fqtresult)->full_quick_travel == 1 ? true : false;
     while ($location = mysql_fetch_object($rsLocations)) {
         //If location and object it links to meet requirments, add it to the array
         //Does it Exist?
         switch ($location->type) {
             case 'Item':
                 $query = "SELECT icon_media_id FROM items WHERE game_id = {$gameId} AND item_id = {$location->type_id} LIMIT 1";
                 break;
             case 'Node':
                 $query = "SELECT icon_media_id FROM nodes WHERE game_id = {$gameId} AND node_id = {$location->type_id} LIMIT 1";
                 break;
             case 'Npc':
                 $query = "SELECT icon_media_id FROM npcs WHERE game_id = {$gameId} AND npc_id = {$location->type_id} LIMIT 1";
                 break;
             case 'WebPage':
                 $query = "SELECT icon_media_id FROM web_pages WHERE web_page_id = {$location->type_id} LIMIT 1";
                 break;
             case 'AugBubble':
                 $query = "SELECT icon_media_id FROM aug_bubbles WHERE aug_bubble_id = {$location->type_id} LIMIT 1";
                 break;
             case 'PlayerNote':
                 $query = "SELECT public_to_map FROM notes WHERE note_id = {$location->type_id} LIMIT 1";
                 break;
         }
         if ($location->type == 'PlayerNote') {
             $rsObject = Module::query($query);
             $object = @mysql_fetch_object($rsObject);
             if (!$object || $object->public_to_map == 0) {
                 continue;
             }
         } else {
             $rsObject = Module::query($query);
             $object = @mysql_fetch_object($rsObject);
             if (!$object) {
                 continue;
             }
         }
         //Deal with qty (whether empty, or fountain)
         if ($location->fountain_id && $location->active) {
             $secondsOfSpawning = strtotime("now") - strtotime($location->last_spawned);
             while ($secondsOfSpawning > $location->spawn_rate && $location->item_qty < $location->max_amount) {
                 if (rand(0, 100) < $location->spawn_probability) {
                     $location->item_qty++;
                 }
                 $secondsOfSpawning -= $location->spawn_rate;
                 $query = "UPDATE fountains SET last_spawned = now() WHERE fountain_id = " . $location->fountain_id;
                 Module::query($query);
             }
             if ($location->item_qty >= $location->max_amount) {
                 $query = "UPDATE fountains SET last_spawned = now() WHERE fountain_id = " . $location->fountain_id;
                 Module::query($query);
             }
             $query = "UPDATE locations SET item_qty = " . $location->item_qty . " WHERE game_id = {$gameId} AND location_id = " . $location->location_id;
             Module::query($query);
         }
         if ($location->type == 'Item' && $location->item_qty < 1 && $location->item_qty != -1) {
             continue;
         }
         //Does it meet it's requirements?
         if (!$this->objectMeetsRequirements($gameId, $intPlayerId, 'Location', $location->location_id)) {
             continue;
         }
         //Special Case for Notes
         if ($location->type == 'PlayerNote') {
             $query = "SELECT public_to_map, public_to_notebook, owner_id FROM notes WHERE note_id='{$location->type_id}' LIMIT 1";
             $result = Module::query($query);
             $note = mysql_fetch_object($result);
             //If note doesn't exist, or if it is neither public nor owned by the owner, skip it.
             if (!$note || !($note->public_to_map || $note->owner_id == $intPlayerId)) {
                 continue;
             }
             if ($note->public_to_notebook || $note->owner_id == $intPlayerId) {
                 $location->allow_quick_travel = 1;
             }
         }
         //If location's icon is not defined, use the object's icon
         if (!$location->icon_media_id) {
             $objectsIconMediaId = $object->icon_media_id;
             $location->icon_media_id = $objectsIconMediaId;
         }
         $location->delete_when_viewed = 0;
         if ($fullQuickTravel) {
             $location->allow_quick_travel = true;
         }
         //Add it
         $arrayLocations[] = $location;
     }
     //Get all spawned locations (needs separate calculations, as requirements are not associated with each location)
     $spawnables = Module::queryArray("SELECT * FROM spawnables WHERE game_id = " . $gameId . " AND active = 1");
     for ($i = 0; $i < count($spawnables); $i++) {
         $spawnable = $spawnables[$i];
         //If spawnable and object it links to meet requirments, add it to the array
         //Does it Exist?
         switch ($spawnable->type) {
             case 'Item':
                 $query = "SELECT name as title, icon_media_id FROM items WHERE game_id = {$gameId} AND item_id = {$spawnable->type_id} LIMIT 1";
                 break;
             case 'Node':
                 $query = "SELECT title, icon_media_id FROM nodes WHERE game_id = {$gameId} AND node_id = {$spawnable->type_id} LIMIT 1";
                 break;
             case 'Npc':
                 $query = "SELECT name as title, icon_media_id FROM npcs WHERE game_id = {$gameId} AND npc_id = {$spawnable->type_id} LIMIT 1";
                 break;
             case 'WebPage':
                 $query = "SELECT name as title, icon_media_id FROM web_pages WHERE web_page_id = {$spawnable->type_id} LIMIT 1";
                 break;
             case 'AugBubble':
                 $query = "SELECT name as title, icon_media_id FROM aug_bubbles WHERE aug_bubble_id = {$spawnable->type_id} LIMIT 1";
                 break;
             default:
                 continue;
                 break;
         }
         $object = Module::queryObject($query);
         if (!$object) {
             continue;
         }
         $spawnable->icon_media_id = $object->icon_media_id;
         $spawnable->title = $object->title;
         //Does it meet it's requirements?
         if (!$this->objectMeetsRequirements($gameId, $intPlayerId, 'Spawnable', $spawnable->spawnable_id)) {
             continue;
         }
         //Create spawnables
         if ($spawnable->location_bound_type == 'PLAYER') {
             //Find player location from log and set lat and lon accordingly
             if ($lat == 0 && $lon == 0 && ($obj = Module::queryObject("SELECT event_detail_1, event_detail_2 FROM player_log WHERE player_id = {$intPlayerId} AND (game_id = {$gameId} OR game_id = 0) AND event_type = 'MOVE' AND deleted = 0 ORDER BY timestamp DESC LIMIT 1"))) {
                 $lat = $obj->event_detail_1;
                 $lon = $obj->event_detail_2;
             }
         } else {
             if ($spawnable->location_bound_type == 'LOCATION') {
                 $lat = $spawnable->latitude;
                 $lon = $spawnable->longitude;
             }
         }
         if ($spawnable->amount_restriction == 'PER_PLAYER') {
             //Special case for calculating max on a per_player basis with a set spawn location
             if ($spawnable->location_bound_type == 'LOCATION') {
                 $result = Module::query("SELECT DISTINCT player_id FROM player_log WHERE game_id = {$gameId} AND deleted = 0 AND timestamp >= NOW() - INTERVAL 20 MINUTE");
                 $spawnable->amount *= mysql_num_rows($result);
             }
             $radius = Module::mToDeg($spawnable->max_area);
             $result = Module::query("SELECT * FROM locations WHERE game_id = {$gameId} AND type = '" . $spawnable->type . "' AND type_id = " . $spawnable->type_id . " AND latitude < " . ($lat + $radius) . " AND latitude > " . ($lat - $radius) . " AND longitude < " . ($lon + $radius) . " AND longitude > " . ($lon - $radius));
             $numLocs = mysql_num_rows($result);
         } else {
             if ($spawnable->amount_restriction == 'TOTAL') {
                 $result = Module::query("SELECT * FROM locations WHERE game_id = {$gameId} AND type = '" . $spawnable->type . "' AND type_id = " . $spawnable->type_id);
                 $numLocs = mysql_num_rows($result);
             }
         }
         $secondsOfSpawning = strtotime("now") - strtotime($spawnable->last_spawned);
         while ($secondsOfSpawning > $spawnable->spawn_rate && $numLocs < $spawnable->amount) {
             if (rand(0, 100) < $spawnable->spawn_probability) {
                 $numLocs++;
                 $spawnLoc = Module::randomLatLnWithinRadius($lat, $lon, $spawnable->min_area, $spawnable->max_area);
                 $newLat = $spawnLoc->lat;
                 //$lat+Module::mToDeg(((rand(0,100)/50)*$spawnable->max_area)-$spawnable->max_area);
                 $newLon = $spawnLoc->lon;
                 //$lon+Module::mToDeg(((rand(0,100)/50)*$spawnable->max_area)-$spawnable->max_area);
                 Locations::createLocationWithQrCode($gameId, $spawnable->location_name, $spawnable->icon_media_id, $newLat, $newLon, $spawnable->error_range, $spawnable->type, $spawnable->type_id, 1, $spawnable->hidden, $spawnable->force_view, $spawnable->allow_quick_travel, $spawnable->wiggle, $spawnable->show_title, '', 0, "You've incorrectly encountered a spawnable! Weird...");
             }
             $query = "UPDATE spawnables SET last_spawned = now() WHERE spawnable_id = " . $spawnable->spawnable_id;
             Module::query($query);
             $secondsOfSpawning -= $spawnable->spawn_rate;
             if (location_bound_type != 'LOCATION') {
                 $secondsOfSpawning = 0;
             }
             //Only simulate once unless location bound is a location
         }
         if ($numLocs >= $spawnable->amount) {
             $query = "UPDATE spawnables SET last_spawned = now() WHERE spawnable_id = " . $spawnable->spawnable_id;
             Module::query($query);
         }
         //Destroy spawnables
         if ($spawnable->time_to_live != -1) {
             /*$query = "DELETE game_locations, game_qrcodes 
                FROM (SELECT * FROM locations WHERE game_id = {$gameId}) AS game_locations 
                LEFT_JOIN (SELECT * FROM qrcodes WHERE game_id = {$gameId}) AS game_qrcodes ON game_locations.location_id = game_qrcodes.link_id 
                WHERE type = '".$spawnable->type."' AND type_id = ".$spawnable->type_id." AND ((spawnstamp < NOW() - INTERVAL ".$spawnable->time_to_live." SECOND) OR (type = 'Item' AND item_qty = 0))";
               */
             $query = "DELETE locations, qrcodes FROM locations, qrcodes WHERE locations.game_id = {$gameId} AND qrcodes.game_id = {$gameId} AND locations.location_id = qrcodes.link_id AND locations.type = '" . $spawnable->type . "' AND locations.type_id = " . $spawnable->type_id . " AND ((locations.spawnstamp < NOW() - INTERVAL " . $spawnable->time_to_live . " SECOND) OR (locations.type = 'Item' AND locations.item_qty = 0))";
             Module::query($query);
         }
         $query = "SELECT * FROM locations WHERE game_id = {$gameId} AND type = '" . $spawnable->type . "' AND type_id = " . $spawnable->type_id;
         $locresults = Module::query($query);
         while ($locobj = mysql_fetch_object($locresults)) {
             //If location's icon is not defined, use the object's icon
             if (!$locobj->icon_media_id) {
                 $locobj->icon_media_id = $object->icon_media_id;
             }
             $locobj->delete_when_viewed = $spawnable->delete_when_viewed && $spawnable->active;
             //Add it
             if ($locobj->type != 'Item' || ($locobj->item_qty == -1 || $locobj->item_qty > 0)) {
                 $arrayLocations[] = $locobj;
             }
         }
     }
     return new returnData(0, $arrayLocations);
 }