public static function createNote($pack) { $pack->auth->permission = "read_write"; if (!users::authenticateUser($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } if ($pack->media) { $pack->media->auth = $pack->auth; $pack->media->game_id = $pack->game_id; $pack->media_id = media::createMedia($pack->media)->data->media_id; } $game = games::getGame($pack); $pack->note_id = dbconnection::queryInsert("INSERT INTO notes (" . "game_id," . "user_id," . (isset($pack->name) ? "name," : "") . (isset($pack->description) ? "description," : "") . (isset($pack->media_id) ? "media_id," : "") . "published," . "created" . ") VALUES (" . "'" . $pack->game_id . "'," . "'" . $pack->auth->user_id . "'," . (isset($pack->name) ? "'" . addslashes($pack->name) . "'," : "") . (isset($pack->description) ? "'" . addslashes($pack->description) . "'," : "") . (isset($pack->media_id) ? "'" . addslashes($pack->media_id) . "'," : "") . ($game->data->moderated ? "'PENDING'" : "'AUTO'") . "," . "CURRENT_TIMESTAMP" . ")"); if ($pack->trigger) { $scene_id = dbconnection::queryObject("SELECT * FROM user_game_scenes WHERE user_id = '{$pack->auth->user_id}' AND game_id = '{$pack->game_id}'")->scene_id; if (!$scene_id) { $scene_id = $game->data->intro_scene_id; } $instance_id = dbconnection::queryInsert("INSERT INTO instances (game_id, object_id, object_type, created) VALUES ('{$pack->game_id}', '{$pack->note_id}', 'NOTE', CURRENT_TIMESTAMP)"); $trigger_id = dbconnection::queryInsert("INSERT INTO triggers (game_id, instance_id, scene_id, type, latitude, longitude, infinite_distance, created) VALUES ( '{$pack->game_id}', '{$instance_id}', '{$scene_id}', 'LOCATION', '{$pack->trigger->latitude}', '{$pack->trigger->longitude}', '1', CURRENT_TIMESTAMP);"); } //allow for 'tag_id' in API, but really just use object_tags if ($pack->tag_id) { dbconnection::queryInsert("INSERT INTO object_tags (game_id, object_type, object_id, tag_id, created) VALUES ('{$pack->game_id}', 'NOTE', '{$pack->note_id}', '{$pack->tag_id}', CURRENT_TIMESTAMP)"); } client::logPlayerCreatedNote($pack); games::bumpGameVersion($pack); return notes::getNote($pack); }
public static function getFullGame($pack) { $pack->auth->permission = "read_write"; if (!users::authenticateUser($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } $sql_game = dbconnection::queryObject("SELECT * FROM games WHERE game_id = '{$pack->game_id}' LIMIT 1"); if (!$sql_game) { return new return_package(2, NULL, "The game you've requested does not exist"); } $game = games::getGame($pack)->data; $game->authors = users::getUsersForGame($pack)->data; //pack already has auth and game_id //heres where we just hack the pack for use in other requests without overhead of creating new packs $pack->media_id = $game->media_id; $game->media = media::getMedia($pack)->data; $pack->media_id = $game->icon_media_id; $game->icon_media = media::getMedia($pack)->data; return new return_package(0, $game); }
private static function importGameData($pack) { $tables = array(); //not actually used $columns = array(); //not actually used $coltablemap = array(); duplicate::getSchema($tables, $columns, $coltablemap); $maps = array(); $import = $pack->import; $game_id = $import->game_id; $table_data = $import->table_data; for ($i = 0; $i < count($table_data); $i++) { $table = $table_data[$i]->table; $cols = $table_data[$i]->columns; $old_data = $table_data[$i]->data; $maps[$table] = array(); $maps[$table][0] = 0; for ($j = 0; $j < count($old_data); $j++) { $old_datum = $old_data[$j]; $col_query = ""; $val_query = ""; $old_id = 0; for ($k = 0; $k < count($cols); $k++) { $col = $cols[$k]; $old_datum[$col->name] = addslashes($old_datum[$col->name]); //best thing I can think of for sanitation... if ($col->meta == 'id') { $old_id = $old_datum[$col->name]; //just store old id } else { if ($col->meta == 'timestamp') { if ($col_query != "") { $col_query .= ', '; $val_query .= ', '; } $col_query .= "{$col->name}"; $val_query .= "CURRENT_TIMESTAMP"; } else { if ($col_query != "") { $col_query .= ', '; $val_query .= ', '; } $col_query .= "{$col->name}"; if ($col->meta == 'special') { if ($col->name == 'siftr_url') { $val_query .= "NULL"; } else { $val_query .= "'0'"; } } else { if ($col->meta == 'map') { $val_query .= "'0'"; } else { $val_query .= "'{$old_datum[$col->name]}'"; } } } } } if ($pack->verbose) { echo "INSERT INTO {$table} ({$col_query}) VALUES ({$val_query});"; } $maps[$table][$old_id] = dbconnection::queryInsert("INSERT INTO {$table} ({$col_query}) VALUES ({$val_query});"); if ($pack->verbose) { echo " (id: {$maps[$table][$old_id]})\n"; } } } //NOTE- must do setup normally handled by games::createGame mkdir(Config::v2_gamedata_folder . "/{$maps['games'][$game_id]}", 0777); //second pass- fill in bogus mappings with known maps for ($i = 0; $i < count($table_data); $i++) { $table = $table_data[$i]->table; $cols = $table_data[$i]->columns; $old_data = $table_data[$i]->data; for ($j = 0; $j < count($old_data); $j++) { $old_datum = $old_data[$j]; $update_query = ""; $id_col = ""; $old_id = 0; for ($k = 0; $k < count($cols); $k++) { $col = $cols[$k]; $old_datum[$col->name] = addslashes($old_datum[$col->name]); //best thing I can think of for sanitation... if ($col->meta == 'id') { $id_col = $col->name; $old_id = $old_datum[$col->name]; //just store old id to find new id to update } else { if ($col->meta == '') { } else { if ($col->meta == 'map') { if ($update_query != '') { $update_query .= ', '; } $update_query .= "{$col->name} = '{$maps[$coltablemap[$col->name]][$old_datum[$col->name]]}'"; } else { if ($col->meta == 'special') { if ($update_query != '') { $update_query .= ', '; } if ($col->name == 'siftr_url') { $update_query .= "siftr_url = NULL"; } else { if ($col->name == 'file_folder') { //copy media to new folder $filenametitle = substr($old_datum['file_name'], 0, strrpos($old_datum['file_name'], '.')); $filenameext = substr($old_datum['file_name'], strrpos($old_datum['file_name'], '.')); $old_file_path = Config::v2_gamedata_folder . "/" . $old_datum['file_folder'] . "/" . $old_datum['file_name']; $new_file_path = Config::v2_gamedata_folder . "/" . $maps['games'][$game_id] . "/" . $old_datum['file_name']; $new_file_path_128 = Config::v2_gamedata_folder . "/" . $maps['games'][$game_id] . "/" . $filenametitle . "_128" . $filenameext; if (file_exists($old_file_path)) { copy($old_file_path, $new_file_path); if ($filenameext == ".jpg" || $filenameext == ".png" || $filenameext == ".gif") { try { if (exif_imagetype($new_file_path)) { $image = new Imagick($new_file_path); //aspect fill to 128x128 $w = $image->getImageWidth(); $h = $image->getImageHeight(); if ($w < $h) { $image->thumbnailImage(128, 128 / $w * $h, 1, 1); } else { $image->thumbnailImage(128 / $h * $w, 128, 1, 1); } //crop around center $w = $image->getImageWidth(); $h = $image->getImageHeight(); $image->cropImage(128, 128, ($w - 128) / 2, ($h - 128) / 2); $image->writeImage($new_file_path_128); } } catch (ImagickException $e) { //do nothing } } } $update_query .= "file_folder = '{$maps['games'][$game_id]}'"; } else { if ($col->name == 'content_id') { if ($table == 'events') { $update_query .= "content_id = '{$maps['items'][$old_datum['content_id']]}'"; } else { if ($table == 'requirement_atoms') { switch ($old_datum['requirement']) { case 'PLAYER_HAS_ITEM': case 'PLAYER_HAS_TAGGED_ITEM': case 'GAME_HAS_ITEM': case 'GAME_HAS_TAGGED_ITEM': case 'PLAYER_VIEWED_ITEM': $update_query .= "content_id = '{$maps['items'][$old_datum['content_id']]}'"; break; case 'PLAYER_VIEWED_PLAQUE': $update_query .= "content_id = '{$maps['plaques'][$old_datum['content_id']]}'"; break; case 'PLAYER_VIEWED_DIALOG': $update_query .= "content_id = '{$maps['dialogs'][$old_datum['content_id']]}'"; break; case 'PLAYER_VIEWED_DIALOG_SCRIPT': $update_query .= "content_id = '{$maps['dialog_scripts'][$old_datum['content_id']]}'"; break; case 'PLAYER_VIEWED_WEB_PAGE': $update_query .= "content_id = '{$maps['web_pages'][$old_datum['content_id']]}'"; break; case 'PLAYER_HAS_COMPLETED_QUEST': $update_query .= "content_id = '{$maps['quests'][$old_datum['content_id']]}'"; break; case 'PLAYER_HAS_RECEIVED_INCOMING_WEB_HOOK': $update_query .= "content_id = '{$maps['web_hooks'][$old_datum['content_id']]}'"; break; case 'ALWAYS_TRUE': case 'ALWAYS_FALSE': case 'PLAYER_HAS_UPLOADED_MEDIA_ITEM': case 'PLAYER_HAS_UPLOADED_MEDIA_ITEM_IMAGE': case 'PLAYER_HAS_UPLOADED_MEDIA_ITEM_AUDIO': case 'PLAYER_HAS_UPLOADED_MEDIA_ITEM_VIDEO': case 'PLAYER_HAS_NOTE': case 'PLAYER_HAS_NOTE_WITH_TAG': case 'PLAYER_HAS_NOTE_WITH_LIKES': case 'PLAYER_HAS_NOTE_WITH_COMMENTS': case 'PLAYER_HAS_GIVEN_NOTE_COMMENTS': default: $update_query .= "content_id = '{$old_datum['content_id']}'"; break; } } else { if ($table == 'tabs') { switch ($old_datum['type']) { case 'NOTE': $update_query .= "content_id = '{$maps['notes'][$old_datum['content_id']]}'"; break; case 'DIALOG': $update_query .= "content_id = '{$maps['dialogs'][$old_datum['content_id']]}'"; break; case 'ITEM': $update_query .= "content_id = '{$maps['items'][$old_datum['content_id']]}'"; break; case 'PLAQUE': $update_query .= "content_id = '{$maps['plaques'][$old_datum['content_id']]}'"; break; case 'WEB_PAGE': $update_query .= "content_id = '{$maps['web_pages'][$old_datum['content_id']]}'"; break; case 'MAP': case 'DECODER': case 'SCANNER': case 'QUESTS': case 'INVENTORY': case 'PLAYER': case 'NOTEBOOK': default: $update_query .= "content_id = '{$old_datum['content_id']}'"; break; } } } } } else { if ($col->name == 'object_id') { switch ($old_datum['object_type']) { case 'PLAQUE': $update_query .= "object_id = '{$maps['plaques'][$old_datum['object_id']]}'"; break; case 'ITEM': $update_query .= "object_id = '{$maps['items'][$old_datum['object_id']]}'"; break; case 'DIALOG': $update_query .= "object_id = '{$maps['dialogs'][$old_datum['object_id']]}'"; break; case 'WEB_PAGE': $update_query .= "object_id = '{$maps['web_pages'][$old_datum['object_id']]}'"; break; case 'NOTE': $update_query .= "object_id = '{$maps['notes'][$old_datum['object_id']]}'"; break; case 'FACTORY': $update_query .= "object_id = '{$maps['factories'][$old_datum['object_id']]}'"; break; case 'SCENE': $update_query .= "object_id = '{$maps['scenes'][$old_datum['object_id']]}'"; break; default: $update_query .= "object_id = '{$old_datum['object_id']}'"; break; } } else { if ($col->name == 'link_id') { switch ($old_datum['link_type']) { case 'EXIT_TO_PLAQUE': $update_query .= "link_id = '{$maps['plaques'][$old_datum['link_id']]}'"; break; case 'EXIT_TO_ITEM': $update_query .= "link_id = '{$maps['items'][$old_datum['link_id']]}'"; break; case 'EXIT_TO_WEB_PAGE': $update_query .= "link_id = '{$maps['web_pages'][$old_datum['link_id']]}'"; break; case 'EXIT_TO_DIALOG': $update_query .= "link_id = '{$maps['dialogs'][$old_datum['link_id']]}'"; break; case 'EXIT_TO_TAB': $update_query .= "link_id = '{$maps['tabs'][$old_datum['link_id']]}'"; break; case 'DIALOG_SCRIPT': $update_query .= "link_id = '{$maps['dialog_scripts'][$old_datum['link_id']]}'"; break; case 'EXIT': default: $update_query .= "link_id = '{$old_datum['link_id']}'"; break; } } } } } } } } } } } if ($update_query != "") { if ($pack->verbose) { echo "UPDATE {$table} SET {$update_query} WHERE {$id_col} = '{$maps[$table][$old_id]}';"; } dbconnection::query("UPDATE {$table} SET {$update_query} WHERE {$id_col} = '{$maps[$table][$old_id]}';"); if ($pack->verbose) { echo " (id: {$maps[$table][$old_id]})\n"; } } } } // Now make the game visible to the user, so they don't see a half-imported game dbconnection::query("INSERT INTO user_games (game_id, user_id, created) VALUES ('{$maps['games'][$game_id]}','{$pack->auth->user_id}',CURRENT_TIMESTAMP);"); $pack->game_id = $maps['games'][$game_id]; return games::getGame($pack); }