public function getQuest($gameId, $questId) { $quest = Module::queryObject("SELECT * FROM quests WHERE game_id = {$gameId} AND quest_id = {$questId} LIMIT 1"); if (!$quest) { return new returnData(2, NULL, "invalid quest id"); } return new returnData(0, $quest); }
public function getMediaObject($gameId, $mediaId) { //apparently, "is_numeric(NAN)" returns 'true'. NAN literally means "Not A Number". Think about that one for a sec. if (!$mediaId || !is_numeric($mediaId) || $mediaId == NAN || !($media = Module::queryObject("SELECT * FROM media WHERE media_id = {$mediaId} LIMIT 1"))) { $media = new stdClass(); $media->game_id = 0; $media->media_id = $mediaId; $media->name = "Default NPC"; $media->file_path = "0/npc.png"; return new returnData(0, Media::parseRawMedia($media)); } return new returnData(0, Media::parseRawMedia($media)); }
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; }
public function getToken($username, $password, $permission) { $username = addslashes($username); $password = addslashes($password); $permission = addslashes($permission); $e = Module::queryObject("SELECT editor_id, " . $permission . "_token FROM editors WHERE name = '" . $username . "' AND password = MD5('" . $password . "') LIMIT 1"); if ($e) { if ($e->{$permission . "_token"} == "") { $e->{$permission . "_token"} = Utils::rand_string(64); Module::query("UPDATE editors SET " . $permission . "_token = '" . $e->{$permission . "_token"} . "' WHERE editor_id = " . $e->editor_id); } return new returnData(0, $e); } else { return new returnData(4, NULL, "Bad Username or Password"); } }
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; }
public function deleteTagFromGame($gameId, $tagId, $editorId, $editorToken) { if (!Module::authenticateGameEditor($gameId, $editorId, $editorToken, "read_write")) { return new returnData(6, NULL, "Failed Authentication"); } $tag = Module::queryObject("SELECT * FROM game_tags WHERE tag_id = '{$tagId}'"); if ($tag->player_created == 1) { Module::query("DELETE FROM game_tags WHERE tag_id = '{$tagId}'"); Module::query("DELETE FROM note_tags WHERE tag_id = '{$tagId}'"); } else { $notesTagged = Module::queryObject("SELECT note_id FROM note_tags WHERE tag_id = '{$tagId}'"); if ($notesTagged) { Module::query("UPDATE game_tags SET player_created = 1 WHERE tag_id = '{$tagId}'"); } else { Module::query("DELETE FROM game_tags WHERE tag_id = '{$tagId}'"); Module::query("DELETE FROM note_tags WHERE tag_id = '{$tagId}'"); } } return new returnData(0); }
public function getRequirement($gameId, $requirementId) { //Old tables $requirement = Module::queryObject("SELECT * FROM requirements WHERE game_id = {$gameId} AND requirement_id = {$requirementId} LIMIT 1"); return new returnData(0, $requirement); /* //New tables //assume by requirement, they mean "requirement atom" $rAtom = Requirements::getRequirementAtom($requirementId); $returnObj = new stdClass(); $returnObj->data = new stdClass(); $returnObj->data->requirement_id = $rAtom->requirement_atom_id; $returnObj->data->game_id = $rAtom->game_id; $returnObj->data->requirement = $rAtom->requirement; $bool = Module::queryArray("SELECT * FROM requirement_atoms WHERE requirement_and_package_id = '{$rAtom->requirement_and_package_id}'"); $returnObj->data->boolean_operator = count($bool) > 1 ? "AND" : "OR"; $returnObj->data->not_operator = $rAtom->bool_operator ? "DO" : "NOT"; $returnObj->data->group_operator = "SELF"; $returnObj->data->requirement_detail_1 = $rAtom->content_id; $returnObj->data->requirement_detail_2 = $rAtom->qty; $returnObj->data->requirement_detail_3 = $rAtom->latitude; $returnObj->data->requirement_detail_4 = $rAtom->longitude; $packId = Module::queryObject("SELECT * FROM requirement_and_packages WHERE requirement_and_package_id = '{$rAtom->requirement_and_package_id}'")->requirement_root_package_id; if( $content = Module::queryObject("SELECT * FROM locations WHERE requirement_package_id = '{$packId}'")) { $returnObj->data->content_type = 'Location'; $returnObj->data->content_id = $content->location_id; } else if($content = Module::queryObject("SELECT * FROM nodes WHERE requirement_package_id = '{$packId}'")) { $returnObj->data->content_type = 'Node'; $returnObj->data->content_id = $content->node_id; } else if($content = Module::queryObject("SELECT * FROM quests WHERE display_requirement_package_id = '{$packId}'")) { $returnObj->data->content_type = 'QuestDisplay'; $returnObj->data->content_id = $content->quest_id; } else if($content = Module::queryObject("SELECT * FROM quests WHERE complete_requirement_package_id = '{$packId}'")) { $returnObj->data->content_type = 'QuestComplete'; $returnObj->data->content_id = $content->quest_id; } $returnObj->returnCode = 0; $returnObj->returnCodeDescription = null; return $returnObj; */ }
protected function giveItemToWorld($gameId, $itemId, $floatLat, $floatLong, $intQty = 1) { $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 = '{$itemId}' AND game_id = '{$gameId}'\n HAVING distance<= {$clumpingRangeInMeters}\n ORDER BY distance ASC"; $result = Module::query($query); if ($closestLocationWithinClumpingRange = @mysql_fetch_object($result)) { Module::query("UPDATE locations SET item_qty = item_qty + {$intQty} WHERE location_id = {$closestLocationWithinClumpingRange->location_id} AND game_id = '{$gameId}'"); } else { $item = Module::queryObject("SELECT * FROM items WHERE item_id = '{$itemId}'"); Module::query("INSERT INTO locations (game_id, name, type, type_id, icon_media_id, latitude, longitude, error, item_qty) VALUES ('{$gameId}', '{$item->name}','Item','{$itemId}', '{$item->icon_media_id}', '{$floatLat}','{$floatLong}', '100','{$intQty}')"); QRCodes::createQRCode($gameId, "Location", mysql_insert_id(), ''); } }
function addTagToNote($noteId, $gameId, $tag) { $id = Module::queryObject("SELECT tag_id FROM game_tags WHERE game_id = '{$gameId}' AND tag = '{$tag}' LIMIT 1"); if (!$id->tag_id) { $allow = Module::queryObject("SELECT allow_player_tags FROM games WHERE game_id = '{$gameId}'"); if ($allow->allow_player_tags != 1) { return new returnData(1, NULL, "Player Generated Tags Not Allowed In This Game"); } Module::query("INSERT INTO game_tags (tag, game_id, player_created) VALUES ('{$tag}', '{$gameId}', 1)"); $id->tag_id = mysql_insert_id(); } if (!Module::queryObject("SELECT * FROM note_tags WHERE note_id = '{$noteId}' AND tag_id = '{$id->tag_id}'")) { Module::query("INSERT INTO note_tags (note_id, tag_id) VALUES ('{$noteId}', '{$id->tag_id}')"); } return new returnData(0, $id->tag_id); }
public function duplicateGame($gameId, $editorId, $editorToken) { if (!Module::authenticateEditor($editorId, $editorToken, "read_write")) { return new returnData(6, NULL, "Failed Authentication"); } Module::serverErrorLog("Duplicating Game Id:" . $gameId); $game = Module::queryObject("SELECT * FROM games WHERE game_id = {$gameId} LIMIT 1"); if (!$game) { return new returnData(2, NULL, "invalid game id"); } $compatibleName = false; $appendNo = 1; while (!$compatibleName) { $query = "SELECT * FROM games WHERE name = '" . addslashes($game->name) . "_copy" . $appendNo . "'"; $result = Module::query($query); if (mysql_fetch_object($result)) { $appendNo++; } else { $compatibleName = true; } } $game->name = $game->name . "_copy" . $appendNo; $newGameId = Games::createGame($game->name, $game->description, $game->icon_media_id, $game->media_id, $game->ready_for_public, $game->is_locational, $game->on_launch_node_id, $game->game_complete_node_id, $game->allow_share_note_to_map, $game->allow_share_note_to_book, $game->allow_player_tags, $game->allow_player_comments, $game->allow_note_likes, $game->pc_media_id, $game->use_player_pic, $game->map_type, $game->show_player_location, $game->full_quick_travel, $game->inventory_weight_cap, $game->allow_trading, $editorId, $editorToken)->data; //Remove the tabs created by createGame Module::query("DELETE FROM game_tab_data WHERE game_id = {$newGameId}"); $result = Module::query("SELECT * FROM game_tab_data WHERE game_id = {$gameId}"); while ($result && ($row = mysql_fetch_object($result))) { Module::query("INSERT INTO game_tab_data (game_id, tab, tab_index, tab_detail_1) VALUES ('{$newGameId}', '{$row->tab}', '{$row->tab_index}', '{$row->tab_detail_1}')"); } $query = "SELECT * FROM requirements WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO requirements (game_id, content_type, content_id, requirement, not_operator, boolean_operator, requirement_detail_1, requirement_detail_2, requirement_detail_3, requirement_detail_4) VALUES ('{$newGameId}', '{$row->content_type}', '{$row->content_id}', '{$row->requirement}', '{$row->not_operator}', '{$row->boolean_operator}', '{$row->requirement_detail_1}', '{$row->requirement_detail_2}', '{$row->requirement_detail_3}', '{$row->requirement_detail_4}')"; Module::query($query); } $query = "SELECT * FROM quests WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO quests (game_id, name, description, text_when_complete, sort_index, exit_to_tab, active_media_id, complete_media_id, active_icon_media_id, complete_icon_media_id) VALUES ('{$newGameId}', '" . addSlashes($row->name) . "', '" . addSlashes($row->description) . "', '" . addSlashes($row->text_when_complete) . "', '{$row->sort_index}', '{$row->exit_to_tab}', '{$row->active_media_id}', '{$row->complete_media_id}', '{$row->active_icon_media_id}', '{$row->complete_icon_media_id}')"; Module::query($query); $newId = mysql_insert_id(); $query = "UPDATE requirements SET requirement_detail_1 = {$newId} WHERE game_id = '{$newGameId}' AND requirement = 'PLAYER_HAS_COMPLETED_QUEST' AND requirement_detail_1 = '{$row->quest_id}'"; Module::query($query); $query = "UPDATE requirements SET content_id = {$newId} WHERE game_id = '{$newGameId}' AND (content_type = 'QuestDisplay' OR content_type = 'QuestComplete') AND content_id = '{$row->quest_id}'"; Module::query($query); } $newFolderIds = array(); $query = "SELECT * FROM folders WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO folders (game_id, name, parent_id, previous_id, is_open) VALUES ('{$newGameId}', '" . addSlashes($row->name) . "', '{$row->parent_id}', '{$row->previous_id}', '{$row->is_open}')"; Module::query($query); $newFolderIds[$row->folder_id] = mysql_insert_id(); } $query = "SELECT * FROM folders WHERE game_id = {$newGameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { if ($row->folder_id != 0) { $query = "UPDATE folders SET parent_id = {$newFolderIds[$row->parent_id]} WHERE game_id = '{$newGameId}' AND folder_id = {$row->folder_id}"; Module::query($query); } } $query = "SELECT * FROM folder_contents WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO folder_contents (game_id, folder_id, content_type, content_id, previous_id) VALUES ('{$newGameId}', '{$newFolderIds[$row->folder_id]}', '{$row->content_type}', '{$row->content_id}', '{$row->previous_id}')"; Module::query($query); if ($row->folder_id != 0) { $query = "UPDATE folder_contents SET folder_id = {$newFolderIds[$row->folder_id]} WHERE game_id = '{$newGameId}' AND object_content_id = {$row->object_content_id}"; Module::query($query); } } $query = "SELECT * FROM qrcodes WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO qrcodes (game_id, link_type, link_id, code, match_media_id) VALUES ('{$newGameId}', '{$row->link_type}', '{$row->link_id}', '{$row->code}', '{$row->match_media_id}')"; Module::query($query); } $query = "SELECT * FROM overlays WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO overlays (game_id, sort_order, alpha, num_tiles, game_overlay_id) VALUES ('{$newGameId}', '{$row->sort_order}', '{$row->alpha}', '{$row->num_tiles}', '{$row->game_overlay_id}')"; Module::query($query); $newId = mysql_insert_id(); $query = "SELECT * FROM overlay_tiles WHERE overlay_id = '{$row->overlay_id}'"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO overlay_tiles (overlay_id, media_id, zoom, x, x_max, y, y_max) VALUES ('{$newId}', '{$row->media_id}', '{$row->zoom}', '{$row->x}', '{$row->x_max}', '{$row->y}', '{$row->y_max}')"; Module::query($query); } } $query = "SELECT * FROM fountains WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO fountains (game_id, type, location_id, spawn_probability, spawn_rate, max_amount, last_spawned, active) VALUES ('{$newGameId}', '{$row->type}', '{$row->location_id}', '{$row->spawn_probability}', '{$row->spawn_rate}', '{$row->max_amount}', '{$row->last_spawned}', '{$row->active}')"; Module::query($query); } $query = "SELECT * FROM spawnables WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO spawnables (game_id, type, type_id, amount, max_area, amount_restriction, location_bound_type, latitude, longitude, spawn_probability, spawn_rate, delete_when_viewed, last_spawned, error_range, force_view, hidden, allow_quick_travel, wiggle, time_to_live, active, location_name, show_title, min_area) VALUES ('{$newGameId}', '{$row->type}', '{$row->type_id}', '{$row->amount}', '{$row->max_area}', '{$row->amount_restriction}', '{$row->location_bound_type}', '{$row->latitude}', '{$row->longitude}', '{$row->spawn_probability}', '{$row->spawn_rate}', '{$row->delete_when_viewed}', '{$row->last_spawned}', '{$row->error_range}', '{$row->force_view}', '{$row->hidden}', '{$row->allow_quick_travel}', '{$row->wiggle}', '{$row->time_to_live}', '{$row->active}', '{$row->location_name}', '{$row->show_title}', '{$row->min_area}')"; Module::query($query); $newId = mysql_insert_id(); $query = "UPDATE fountains SET location_id = {$newId} WHERE game_id = '{$newGameId}' AND type = 'Spawnable' AND location_id = {$row->spawnable_id}"; Module::query($query); } $query = "SELECT * FROM locations WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO locations (game_id, name, description, latitude, longitude, error, type, type_id, icon_media_id, item_qty, hidden, force_view, allow_quick_travel) VALUES ('{$newGameId}', '" . addSlashes($row->name) . "', '" . addSlashes($row->description) . "', '{$row->latitude}', '{$row->longitude}', '{$row->error}', '{$row->type}', '{$row->type_id}', '{$row->icon_media_id}', '{$row->item_qty}', '{$row->hidden}', '{$row->force_view}', '{$row->allow_quick_travel}')"; Module::query($query); $newId = mysql_insert_id(); $query = "UPDATE fountains SET location_id = {$newId} WHERE game_id = '{$newGameId}' AND type = 'Location' AND location_id = {$row->location_id}"; Module::query($query); $query = "UPDATE qrcodes SET link_id = {$newId} WHERE game_id = '{$newGameId}' AND link_type = 'Location' AND link_id = {$row->location_id}"; Module::query($query); $query = "UPDATE requirements SET content_id = {$newId} WHERE game_id = '{$newGameId}' AND content_type = 'Location' AND content_id = {$row->location_id}"; Module::query($query); } $query = "SELECT * FROM npc_conversations WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO npc_conversations (game_id, npc_id, node_id, text, sort_index) VALUES ('{$newGameId}', '{$row->npc_id}', '{$row->node_id}', '" . addSlashes($row->text) . "', '{$row->sort_index}')"; Module::query($query); } $query = "SELECT * FROM player_state_changes WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO player_state_changes (game_id, event_type, event_detail, action, action_detail, action_amount) VALUES ('{$newGameId}', '{$row->event_type}', '{$row->event_detail}', '{$row->action}', '{$row->action_detail}', '{$row->action_amount}')"; Module::query($query); } $newNpcIds = array(); $query = "SELECT * FROM npcs WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO npcs (game_id, name, description, text, closing, media_id, icon_media_id) VALUES ('{$newGameId}', '" . addSlashes($row->name) . "', '" . addSlashes($row->description) . "', '" . addSlashes($row->text) . "', '" . addSlashes($row->closing) . "', '{$row->media_id}', '{$row->icon_media_id}')"; Module::query($query); $newId = mysql_insert_id(); $newNpcIds[$row->npc_id] = $newId; $query = "UPDATE npc_conversations SET npc_id = {$newId} WHERE game_id = '{$newGameId}' AND npc_id = {$row->npc_id}"; Module::query($query); $query = "UPDATE folder_contents SET content_id = {$newId} WHERE game_id = '{$newGameId}' AND content_type = 'Npc' AND content_id = {$row->npc_id}"; Module::query($query); $query = "UPDATE locations SET type_id = {$newId} WHERE game_id = '{$newGameId}' AND type = 'Npc' AND type_id = {$row->npc_id}"; Module::query($query); $query = "UPDATE player_state_changes SET event_detail = {$newId} WHERE game_id = '{$newGameId}' AND event_type = 'VIEW_NPC' AND event_detail = {$row->npc_id}"; Module::query($query); $query = "UPDATE requirements SET requirement_detail_1 = {$newId} WHERE game_id = '{$newGameId}' AND requirement = 'PLAYER_VIEWED_NPC' AND requirement_detail_1 = {$row->npc_id}"; Module::query($query); $query = "UPDATE spawnables SET type_id = {$newId} WHERE game_id = '{$newGameId}' AND type = 'Npc' AND type_id = {$row->npc_id}"; Module::query($query); } $newNodeIds = array(); $query = "SELECT * FROM nodes WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO nodes (game_id, title, text, opt1_text, opt1_node_id, opt2_text, opt2_node_id, opt3_text, opt3_node_id, require_answer_incorrect_node_id, require_answer_string, require_answer_correct_node_id, media_id, icon_media_id) VALUES ('{$newGameId}', '" . addSlashes($row->title) . "', '" . addSlashes($row->text) . "', '{$row->opt1_text}', '{$row->opt1_node_id}', '{$row->opt2_text}', '{$row->opt2_node_id}', '{$row->opt3_text}', '{$row->opt3_node_id}', '{$row->require_answer_incorrect_node_id}', '{$row->require_answer_string}', '{$row->require_answer_correct_node_id}', '{$row->media_id}', '{$row->icon_media_id}')"; Module::query($query); $newId = mysql_insert_id(); $newNodeIds[$row->node_id] = $newId; $query = "UPDATE folder_contents SET content_id = {$newId} WHERE game_id = '{$newGameId}' AND content_type = 'Node' AND content_id = {$row->node_id}"; Module::query($query); $query = "UPDATE locations SET type_id = {$newId} WHERE game_id = '{$newGameId}' AND type = 'Node' AND type_id = {$row->node_id}"; Module::query($query); $query = "UPDATE npc_conversations SET node_id = {$newId} WHERE game_id = '{$newGameId}' AND node_id = {$row->node_id}"; Module::query($query); $query = "UPDATE player_state_changes SET event_detail = {$newId} WHERE game_id = '{$newGameId}' AND event_type = 'VIEW_NODE' AND event_detail = {$row->node_id}"; Module::query($query); $query = "UPDATE requirements SET content_id = {$newId} WHERE game_id = '{$newGameId}' AND content_type = 'Node' AND content_id = {$row->node_id}"; Module::query($query); $query = "UPDATE requirements SET requirement_detail_1 = {$newId} WHERE game_id = '{$newGameId}' AND requirement = 'PLAYER_VIEWED_NODE' AND requirement_detail_1 = {$row->node_id}"; Module::query($query); $query = "UPDATE spawnables SET type_id = {$newId} WHERE game_id = '{$newGameId}' AND type = 'Node' AND type_id = {$row->node_id}"; Module::query($query); } $newItemIds = array(); $query = "SELECT * FROM items WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO items (game_id, name, description, is_attribute, icon_media_id, media_id, dropable, destroyable, max_qty_in_inventory, creator_player_id, origin_latitude, origin_longitude, origin_timestamp, weight, url, type, tradeable) VALUES ('{$newGameId}', '" . addSlashes($row->name) . "', '" . addSlashes($row->description) . "', '{$row->is_attribute}', '{$row->icon_media_id}', '{$row->media_id}', '{$row->dropable}', '{$row->destroyable}', '{$row->max_qty_in_inventory}', '{$row->creator_player_id}', '{$row->origin_latitude}', '{$row->origin_longitude}', '{$row->origin_timestamp}', '{$row->weight}', '{$row->url}', '{$row->type}', '{$row->tradeable}')"; Module::query($query); $newId = mysql_insert_id(); $newItemIds[$row->item_id] = $newId; $query = "UPDATE folder_contents SET content_id = {$newId} WHERE game_id = '{$newGameId}' AND content_type = 'Item' AND content_id = {$row->item_id}"; Module::query($query); $query = "UPDATE locations SET type_id = {$newId} WHERE game_id = '{$newGameId}' AND type = 'Item' AND type_id = {$row->item_id}"; Module::query($query); $query = "UPDATE player_state_changes SET event_detail = {$newId} WHERE game_id = '{$newGameId}' AND event_type = 'VIEW_ITEM' AND event_detail = {$row->item_id}"; Module::query($query); $query = "UPDATE player_state_changes SET action_detail = {$newId} WHERE game_id = '{$newGameId}' AND action_detail = {$row->item_id}"; Module::query($query); $query = "UPDATE requirements SET requirement_detail_1 = {$newId} WHERE game_id = '{$newGameId}' AND (requirement = 'PLAYER_HAS_ITEM' OR requirement = 'PLAYER_VIEWED_ITEM') AND requirement_detail_1 = {$row->item_id}"; Module::query($query); $query = "UPDATE spawnables SET type_id = {$newId} WHERE game_id = '{$newGameId}' AND type = 'Item' AND type_id = {$row->item_id}"; Module::query($query); } $query = "SELECT * FROM aug_bubble_media WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO aug_bubble_media (game_id, aug_bubble_id, media_id, text, index) VALUES ('{$newGameId}', '{$row->aug_bubble_id}', '{$row->media_id}', '{$row->text}', '{$row->index}')"; Module::query($query); } $newAugBubbleIds = array(); $query = "SELECT * FROM aug_bubbles WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO aug_bubbles (game_id, name, description, icon_media_id) VALUES ('{$newGameId}', '" . addSlashes($row->name) . "', '" . addSlashes($row->description) . "', '{$row->icon_media_id}'))."; Module::query($query); $newId = mysql_insert_id(); $newAugBubbleIds[$row->aug_bubble_id] = $newId; $query = "UPDATE aug_bubble_media SET aug_bubble_id = {$newId} WHERE aug_bubble_id = {$row->aug_bubble_id}"; Module::query($query); $query = "UPDATE locations SET type_id = {$newId} WHERE type = 'AugBubble' AND type_id = {$row->aug_bubble_id} AND game_id = '{$newGameId}'"; Module::query($query); $query = "UPDATE folder_contents SET content_id = {$newId} WHERE content_type = 'AugBubble' AND content_id = {$row->aug_bubble_id} AND game_id = '{$newGameId}'"; Module::query($query); $query = "UPDATE requirements SET requirement_detail_1 = {$newId} WHERE (requirement = 'PLAYER_HAS_NOT_VIEWED_AUGBUBBLE' OR requirement = 'PLAYER_VIEWED_AUGBUBBLE') AND requirement_detail_1 = {$row->aug_bubble_id} AND game_id = '{$newGameId}'"; Module::query($query); } $newWebPageIds = array(); $query = "SELECT * FROM web_pages WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO web_pages (game_id, name, url, icon_media_id) VALUES ('{$newGameId}', '" . addSlashes($row->name) . "', '{$row->url}', '{$row->icon_media_id}')"; Module::query($query); $newId = mysql_insert_id(); $newWebPageIds[$row->web_page_id] = $newId; $query = "UPDATE locations SET type_id = {$newId} WHERE type = 'WebPage' AND type_id = {$row->web_page_id} AND game_id = '{$newGameId}'"; Module::query($query); $query = "UPDATE folder_contents SET content_id = {$newId} WHERE content_type = 'WebPage' AND content_id = {$row->web_page_id} AND game_id = '{$newGameId}'"; Module::query($query); $query = "UPDATE requirements SET requirement_detail_1 = {$newId} WHERE (requirement = 'PLAYER_HAS_NOT_VIEWED_WEBPAGE' OR requirement = 'PLAYER_VIEWED_WEBPAGE') AND requirement_detail_1 = {$row->web_page_id} AND game_id = '{$newGameId}'"; Module::query($query); } $query = "SELECT * FROM web_hooks WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $query = "INSERT INTO web_hooks (game_id, name, url, incoming) VALUES ('{$newGameId}', '" . addSlashes($row->name) . "', '" . addSlashes($row->url) . "', '{$row->incoming}')"; Module::query($query); $newId = mysql_insert_id(); $query = "UPDATE requirements SET content_id = {$newId} WHERE content_type = 'OutgoingWebHook' AND content_id = {$row->web_hook_id} AND game_id = '{$newGameId}'"; Module::query($query); } $originalOverlayId = array(); $newOverlayId = array(); $query = "SELECT * FROM overlays WHERE game_id = {$gameId}"; $result = Module::query($query); while ($row = mysql_fetch_object($result)) { array_push($originalOverlayId, $row->overlay_id); $origOverlayId = $row->overlay_id; $query = "INSERT INTO overlays (game_id, game_overlay_id, name, sort_index, file_uploaded) VALUES ('{$newGameId}', '{$row->game_overlay_id}', '{$row->name}', '{$row->sort_index}', '{$row->file_uploaded}')"; Module::query($query); $newId = mysql_insert_id(); array_push($newOverlayId, $newId); $query2 = "SELECT * FROM overlay_tiles WHERE overlay_id = {$origOverlayId}"; $result2 = Module::query($query2); while ($row2 = mysql_fetch_object($result2)) { $query3 = "INSERT INTO overlay_tiles (overlay_id, media_id, zoom, x, y) VALUES ('{$newId}', '{$row2->media_id}', '{$row2->zoom}', '{$row2->x}', '{$row2->y}')"; Module::query($query3); } $query = "UPDATE requirements SET content_id = {$newId} WHERE content_type = 'CustomMap' AND content_id = {$row->overlay_id}"; Module::query($query); } $originalMediaId = array(); $newMediaId = array(); $query = "SELECT * FROM media WHERE game_id = {$gameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { $newMediaFilePath = $newGameId . substr($row->file_path, strpos($row->file_path, '/')); $query = "INSERT INTO media (game_id, name, file_path, is_icon) VALUES ('{$newGameId}', '" . addSlashes($row->name) . "', '{$newMediaFilePath}', '{$row->is_icon}')"; Module::query($query); $newId = mysql_insert_id(); $newMediaIds[$row->media_id] = $newId; if ($row->file_path != "" && substr($row->file_path, -1) != "/" && file_exists("../../gamedata/" . $row->file_path)) { copy("../../gamedata/" . $row->file_path, "../../gamedata/" . $newMediaFilePath); } $query = "UPDATE items SET icon_media_id = {$newId} WHERE icon_media_id = {$row->media_id} AND game_id = '{$newGameId}'"; Module::query($query); $query = "UPDATE items SET media_id = {$newId} WHERE media_id = {$row->media_id} AND game_id = '{$newGameId}'"; Module::query($query); $query = "UPDATE locations SET icon_media_id = {$newId} WHERE icon_media_id = {$row->media_id} AND game_id = '{$newGameId}'"; Module::query($query); $query = "UPDATE nodes SET icon_media_id = {$newId} WHERE icon_media_id = {$row->media_id} AND game_id = '{$newGameId}'"; Module::query($query); $query = "UPDATE nodes SET media_id = {$newId} WHERE media_id = {$row->media_id} AND game_id = '{$newGameId}'"; Module::query($query); $query = "UPDATE npcs SET icon_media_id = {$newId} WHERE icon_media_id = {$row->media_id} AND game_id = '{$newGameId}'"; Module::query($query); $query = "UPDATE npcs SET media_id = {$newId} WHERE media_id = {$row->media_id} AND game_id = '{$newGameId}'"; Module::query($query); $query = "UPDATE qrcodes SET match_media_id = {$newId} WHERE match_media_id = {$row->media_id} AND game_id = '{$newGameId}'"; Module::query($query); $query = "UPDATE quests SET active_icon_media_id = {$newId} WHERE active_icon_media_id = {$row->media_id} AND game_id = '{$newGameId}'"; Module::query($query); $query = "UPDATE quests SET complete_icon_media_id = {$newId} WHERE complete_icon_media_id = {$row->media_id} AND game_id = '{$newGameId}'"; Module::query($query); $query = "UPDATE quests SET active_media_id = {$newId} WHERE active_media_id = {$row->media_id} AND game_id = '{$newGameId}'"; Module::query($query); $query = "UPDATE quests SET complete_media_id = {$newId} WHERE complete_media_id = {$row->media_id} AND game_id = '{$newGameId}'"; Module::query($query); $query = "UPDATE aug_bubbles SET icon_media_id = {$newId} WHERE icon_media_id = {$row->media_id} AND game_id = {$newGameId}"; Module::query($query); $query = "UPDATE aug_bubble_media SET media_id = {$newId} WHERE media_id = {$row->media_id} AND game_id = {$newGameId}"; Module::query($query); $query = "UPDATE games SET icon_media_id = {$newId} WHERE icon_media_id = {$row->media_id} AND game_id = {$newGameId}"; Module::query($query); $query = "UPDATE games SET media_id = {$newId} WHERE media_id = {$row->media_id} AND game_id = {$newGameId}"; Module::query($query); $query = "UPDATE games SET pc_media_id = {$newId} WHERE pc_media_id = {$row->media_id} AND game_id = {$newGameId}"; Module::query($query); $query = "UPDATE web_pages SET icon_media_id = {$newId} WHERE icon_media_id = {$row->media_id} AND game_id = {$newGameId}"; Module::query($query); $query = "UPDATE overlay_tiles, overlays SET overlay_tiles.media_id = {$newId} WHERE overlay_tiles.media_id = {$row->media_id} AND overlays.game_id = {$newGameId} AND overlay_tiles.overlay_id = overlays.overlay_id"; Module::query($query); } //NOTE: substr removes <?xml version="1.0" ? //> from the beginning of the text $query = "SELECT node_id FROM npc_conversations WHERE game_id = {$newGameId}"; $result = Module::query($query); while ($result && ($npcConvo = mysql_fetch_object($result))) { $query = "SELECT node_id, text FROM nodes WHERE node_id = {$npcConvo->node_id}"; $resultNode = Module::query($query); if ($result && ($node = mysql_fetch_object($resultNode))) { $inputString = $node->text; $output = Games::replaceXMLIds($inputString, $newNpcIds, $newNodeIds, $newItemIds, $newAugBubbleIds, $newWebPageIds, $newMediaIds); if ($output) { $output = substr($output, 22); $updateQuery = "UPDATE nodes SET text = '" . addslashes($output) . "' WHERE node_id = {$node->node_id} AND game_id = {$newGameId}"; Module::query($updateQuery); } } } $query = "SELECT * FROM npcs WHERE game_id = {$newGameId}"; $result = Module::query($query); while ($result && ($row = mysql_fetch_object($result))) { if ($row->text) { $inputString = $row->text; $output = Games::replaceXMLIds($inputString, $newNpcIds, $newNodeIds, $newItemIds, $newAugBubbleIds, $newWebPageIds, $newMediaIds); if ($output) { $output = substr($output, 22); $updateQuery = "UPDATE npcs SET text = '" . addslashes($output) . "' WHERE npc_id = {$row->npc_id} AND game_id = {$newGameId}"; Module::query($updateQuery); } } if ($row->closing) { $inputString = $row->closing; $output = Games::replaceXMLIds($inputString, $newNpcIds, $newNodeIds, $newItemIds, $newAugBubbleIds, $newWebPageIds, $newMediaIds); if ($output) { $output = substr($output, 22); $updateQuery = "UPDATE npcs SET closing = '" . addslashes($output) . "' WHERE npc_id = {$row->npc_id} AND game_id = {$newGameId}"; Module::query($updateQuery); } } } return new returnData(0, $newGameId, NULL); }
protected function fireOffWebHook($playerId, $gameId, $webHookId) { Module::appendLog($playerId, $gameId, "SEND_WEBHOOK", $webHookId); $webHook = Module::queryObject("SELECT * FROM web_hooks WHERE web_hook_id = '{$webHookId}' LIMIT 1"); $name = str_replace(" ", "", $webHook->name); $name = str_replace("{playerId}", $playerId, $name); $url = $webHook->url . "?hook=" . $name . "&wid=" . $webHook->web_hook_id . "&gameid=" . $gameId . "&playerid=" . $playerId; $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_exec($ch); curl_close($ch); }
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))); } }
protected function giveNoteToWorld($gameId, $noteId, $floatLat, $floatLong) { $query = "SELECT * FROM locations WHERE type = 'PlayerNote' AND type_id = '{$noteId}' AND game_id = '{$gameId}'"; $result = Module::query($query); if ($existingNote = @mysql_fetch_object($result)) { //We have a match $query = "UPDATE locations\n SET latitude = '{$floatLat}', longitude = '{$floatLong}'\n WHERE location_id = {$existingNote->location_id} AND game_id = '{$gameId}'"; Module::query($query); $obj = Module::queryObject("SELECT title, owner_id FROM notes WHERE note_id = '{$noteId}'"); } else { $error = 100; //Use 100 meters $query = "SELECT title, owner_id FROM notes WHERE note_id = '{$noteId}'"; $result = Module::query($query); $obj = @mysql_fetch_object($result); $title = $obj->title; $query = "INSERT INTO locations (game_id, name, type, type_id, icon_media_id, latitude, longitude, error, item_qty, hidden, force_view, allow_quick_travel)\n VALUES ('{$gameId}', '{$title}','PlayerNote','{$noteId}', " . Module::kPLAYER_NOTE_DEFAULT_ICON . ", '{$floatLat}','{$floatLong}', '{$error}','1',0,0,0)"; Module::query($query); $newId = mysql_insert_id(); } Module::processGameEvent($obj->owner_id, $gameId, Module::kLOG_UPLOAD_MEDIA_ITEM, $noteId, $floatLat, $floatLong); Module::processGameEvent($obj->owner_id, $gameId, Module::kLOG_DROP_NOTE, $noteId, $floatLat, $floatLong); }
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; }
public function getLocationById($locId) { $loc = Module::queryObject("SELECT * FROM locations WHERE location_id = '{$locId}'"); return new returnData(0, $loc); }