public static function deleteScene($pack) { $pack->auth->game_id = dbconnection::queryObject("SELECT * FROM scenes WHERE scene_id = '{$pack->scene_id}'")->game_id; $pack->auth->permission = "read_write"; if (!editors::authenticateGameEditor($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } dbconnection::query("DELETE FROM scenes WHERE scene_id = '{$pack->scene_id}' LIMIT 1"); //cleanup $s = dbconnection::queryObject("SELECT * FROM scenes WHERE game_id = '{$pack->game_id}' LIMIT 1"); $s_id = $s ? $s->scene_id : 0; dbconnection::query("UPDATE games SET intro_scene_id = '{$s_id}' WHERE intro_scene_id = '{$pack->scene_id}'"); $triggers = dbconnection::queryArray("SELECT * FROM triggers WHERE scene_id = '{$pack->scene_id}'"); for ($i = 0; $i < count($triggers); $i++) { $pack->trigger_id = $triggers[$i]->trigger_id; triggers::deleteTrigger($pack); } $instances = dbconnection::queryArray("SELECT * FROM instances WHERE object_type = 'SCENE' AND object_id = '{$pack->scene_id}'"); for ($i = 0; $i < count($instances); $i++) { $pack->instance_id = $instances[$i]->instance_id; instances::deleteInstance($pack); } games::bumpGameVersion($pack); return new return_package(0); }
/** * [__call description] * @param [string] $name [virtual function name] * @param [array] $args [arguments of virtual function] * @return [type] [description] */ public function __call($name, $args) { $syntax = str_replace("String", '', $name) . "Caller"; if (method_exists($this, $syntax)) { $string = $this->{$syntax}($args); } if (preg_match("/^(insert|delete|update|select)(String)?\$/", $name)) { if (class_exists('\\cls\\sql') && method_exists('\\cls\\sql', "call")) { sql_cls::call($this->maker, $name); } $this->groupby($string); $this->order($string); $string .= count($this->maker->limit) > 0 ? " LIMIT " . join($this->maker->limit, ', ') : ''; // echo "\n<pre>\n"; // echo($string)."\n\n"; // echo "\n</pre>\n"; if (preg_match("/String\$/", $name)) { return $string; } else { $connection = new dbconnection(); $result = $connection->query($string); return $result; } } else { return $string; } }
public static function deleteItem($pack) { $item = dbconnection::queryObject("SELECT * FROM items WHERE item_id = '{$pack->item_id}'"); $pack->auth->game_id = $item->game_id; $pack->auth->permission = "read_write"; if (!editors::authenticateGameEditor($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } dbconnection::query("DELETE FROM items WHERE item_id = '{$pack->item_id}' LIMIT 1"); //cleanup $options = dbconnection::queryArray("SELECT * FROM dialog_options WHERE link_type = 'EXIT_TO_ITEM' AND link_id = '{$pack->item_id}'"); for ($i = 0; $i < count($options); $i++) { $pack->dialog_option_id = $options[$i]->dialog_option_id; dialogs::deleteDialogOption($pack); } $tabs = dbconnection::queryArray("SELECT * FROM tabs WHERE type = 'ITEM' AND content_id = '{$pack->item_id}'"); for ($i = 0; $i < count($tabs); $i++) { $pack->tab_id = $tabs[$i]->tab_id; tabs::deleteTab($pack); } $tags = dbconnection::queryArray("SELECT * FROM object_tags WHERE object_type = 'ITEM' AND object_id = '{$pack->item_id}'"); for ($i = 0; $i < count($tags); $i++) { $pack->object_tag_id = $tags[$i]->object_tag_id; tags::deleteObjectTag($pack); } $instances = dbconnection::queryArray("SELECT * FROM instances WHERE object_type = 'ITEM' AND object_id = '{$pack->item_id}'"); for ($i = 0; $i < count($instances); $i++) { $pack->instance_id = $instances[$i]->instance_id; instances::deleteInstance($pack); } $factories = dbconnection::queryArray("SELECT * FROM factories WHERE object_type = 'ITEM' AND object_id = '{$pack->item_id}'"); for ($i = 0; $i < count($factories); $i++) { $pack->factory_id = $factories[$i]->factory_id; factories::deleteFactory($pack); } $events = dbconnection::queryArray("SELECT * FROM events WHERE (event = 'GIVE_ITEM_PLAYER' OR event = 'TAKE_ITEM_PLAYER' OR event = 'GIVE_ITEM_GAME' OR event = 'TAKE_ITEM_GAME') AND content_id = '{$pack->item_id}'"); for ($i = 0; $i < count($events); $i++) { $pack->event_id = $events[$i]->event_id; events::deleteEvent($pack); } $reqAtoms = dbconnection::queryArray("SELECT * FROM requirement_atoms WHERE requirement = 'PLAYER_VIEWED_ITEM' AND content_id = '{$pack->item_id}'"); for ($i = 0; $i < count($reqAtoms); $i++) { $pack->requirement_atom_id = $reqAtoms[$i]->requirement_atom_id; requirements::deleteRequirementAtom($pack); } $reqAtoms = dbconnection::queryArray("SELECT * FROM requirement_atoms WHERE requirement = 'PLAYER_HAS_ITEM' AND content_id = '{$pack->item_id}'"); for ($i = 0; $i < count($reqAtoms); $i++) { $pack->requirement_atom_id = $reqAtoms[$i]->requirement_atom_id; requirements::deleteRequirementAtom($pack); } $reqAtoms = dbconnection::queryArray("SELECT * FROM requirement_atoms WHERE requirement = 'GAME_HAS_ITEM' AND content_id = '{$pack->item_id}'"); for ($i = 0; $i < count($reqAtoms); $i++) { $pack->requirement_atom_id = $reqAtoms[$i]->requirement_atom_id; requirements::deleteRequirementAtom($pack); } games::bumpGameVersion($pack); return new return_package(0); }
public static function removeEditorFromGame($pack) { $pack->auth->game_id = $pack->game_id; $pack->auth->permission = "read_write"; if (!editors::authenticateGameEditor($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } //note $pack->user_id is DIFFERENT than $pack->auth->user_id dbconnection::query("DELETE FROM user_games WHERE user_id = '{$pack->user_id}' AND game_id = '{$pack->game_id}'"); games::bumpGameVersion($pack); return new return_package(0); }
public static function deletePlaque($pack) { $plaque = dbconnection::queryObject("SELECT * FROM plaques WHERE plaque_id = '{$pack->plaque_id}'"); $pack->auth->game_id = $plaque->game_id; $pack->auth->permission = "read_write"; if (!editors::authenticateGameEditor($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } dbconnection::query("DELETE FROM plaques WHERE plaque_id = '{$pack->plaque_id}' LIMIT 1"); //cleanup /* Comment out until we've decided on desired behavior... $eventpack = dbconnection::queryObject("SELECT * FROM event_packages WHERE event_package_id = '{$plaque->event_package_id}'"); if($eventpack) { $pack->event_package_id = $eventpack->event_package_id; events::deleteEventPackage($pack); } */ $options = dbconnection::queryArray("SELECT * FROM dialog_options WHERE link_type = 'EXIT_TO_PLAQUE' AND link_id = '{$pack->plaque_id}'"); for ($i = 0; $i < count($options); $i++) { $pack->dialog_option_id = $options[$i]->dialog_option_id; dialogs::deleteDialogOption($pack); } $tabs = dbconnection::queryArray("SELECT * FROM tabs WHERE type = 'PLAQUE' AND content_id = '{$pack->plaque_id}'"); for ($i = 0; $i < count($tabs); $i++) { $pack->tab_id = $tabs[$i]->tab_id; tabs::deleteTab($pack); } $tags = dbconnection::queryArray("SELECT * FROM object_tags WHERE object_type = 'PLAQUE' AND object_id = '{$pack->plaque_id}'"); for ($i = 0; $i < count($tags); $i++) { $pack->object_tag_id = $tags[$i]->object_tag_id; tags::deleteObjectTag($pack); } $instances = dbconnection::queryArray("SELECT * FROM instances WHERE object_type = 'PLAQUE' AND object_id = '{$pack->plaque_id}'"); for ($i = 0; $i < count($instances); $i++) { $pack->instance_id = $instances[$i]->instance_id; instances::deleteInstance($pack); } $factories = dbconnection::queryArray("SELECT * FROM factories WHERE object_type = 'PLAQUE' AND object_id = '{$pack->plaque_id}'"); for ($i = 0; $i < count($factories); $i++) { $pack->factory_id = $factories[$i]->factory_id; factories::deleteFactory($pack); } $reqAtoms = dbconnection::queryArray("SELECT * FROM requirement_atoms WHERE requirement = 'PLAYER_VIEWED_PLAQUE' AND content_id = '{$pack->plaque_id}'"); for ($i = 0; $i < count($reqAtoms); $i++) { $pack->requirement_atom_id = $reqAtoms[$i]->requirement_atom_id; requirements::deleteRequirementAtom($pack); } games::bumpGameVersion($pack); return new return_package(0); }
public static function deleteGroup($pack) { $group = dbconnection::queryObject("SELECT * FROM groups WHERE group_id = '{$pack->group_id}'"); $pack->auth->game_id = $group->game_id; $pack->auth->permission = "read_write"; if (!editors::authenticateGameEditor($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } dbconnection::query("DELETE FROM groups WHERE group_id = '{$pack->group_id}' LIMIT 1"); //cleanup dbconnection::query("UPDATE game_user_groups SET group_id = 0 WHERE game_id = '{$group->game_id}' AND group_id = '{$group->group_id}';"); games::bumpGameVersion($pack); return new return_package(0); }
private static function applyUpgrade($user_id, $maj, $min) { $file = "db/upgrades/" . $maj . "." . $min . ".sql"; $upgrade = fopen($file, "r"); while (!feof($upgrade)) { $query = fgets($upgrade); if (preg_match("@^\\s*\$@is", $query)) { continue; } //ignore whitespace dbconnection::query($query); } fclose($upgrade); dbconnection::queryInsert("INSERT INTO db_upgrades (user_id, version_major, version_minor, timestamp) VALUES ('{$user_id}', '{$maj}', '{$min}', CURRENT_TIMESTAMP)"); }
public static function deleteOverlay($pack) { $overlay = dbconnection::queryObject("SELECT * FROM overlays WHERE overlay_id = '{$pack->overlay_id}'"); $pack->auth->game_id = $overlay->game_id; $pack->auth->permission = "read_write"; if (!editors::authenticateGameEditor($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } dbconnection::query("DELETE FROM overlays WHERE overlay_id = '{$pack->overlay_id}' LIMIT 1"); //cleanup $reqPack = dbconnection::queryObject("SELECT * FROM requirement_root_packages WHERE requirement_root_package_id = '{$overlay->requirement_root_package_id}'"); if ($reqPack) { $pack->requirement_root_package_id = $reqPack->requirement_root_package_id; requirements::deleteRequirementPackage($pack); } games::bumpGameVersion($pack); return new return_package(0); }
public static function deleteWebHook($pack) { $webhook = dbconnection::queryObject("SELECT * FROM web_hooks WHERE web_hook_id = '{$pack->web_hook_id}'"); $pack->auth->game_id = $webhook->game_id; $pack->auth->permission = "read_write"; if (!editors::authenticateGameEditor($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } dbconnection::query("DELETE FROM web_hooks WHERE web_hook_id = '{$pack->web_hook_id}' LIMIT 1"); //cleanup $reqPack = dbconnection::queryObject("SELECT * FROM requirement_root_packages WHERE requirement_root_package_id = '{$webhook->requirement_root_package_id}'"); if ($reqPack) { $pack->requirement_root_package_id = $reqPack->requirement_root_package_id; requirements::deleteRequirementPackage($pack); } $reqAtoms = dbconnection::queryArray("SELECT * FROM requirement_atoms WHERE requirement = 'PLAYER_HAS_RECEIVED_INCOMING_WEB_HOOK' AND content_id = '{$pack->web_hook_id}'"); for ($i = 0; $i < count($reqAtoms); $i++) { $pack->requirement_atom_id = $reqAtoms[$i]->requirement_atom_id; requirements::deleteRequirementAtom($pack); } games::bumpGameVersion($pack); return new return_package(0); }
public static function deleteTab($pack) { $tab = dbconnection::queryObject("SELECT * FROM tabs WHERE tab_id = '{$pack->tab_id}'"); $pack->auth->game_id = $tab->game_id; $pack->auth->permission = "read_write"; if (!editors::authenticateGameEditor($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } dbconnection::query("DELETE FROM tabs WHERE tab_id = '{$pack->tab_id}' LIMIT 1"); //cleanup $options = dbconnection::queryArray("SELECT * FROM dialog_options WHERE link_type = 'EXIT_TO_TAB' AND link_id = '{$pack->tab_id}'"); for ($i = 0; $i < count($options); $i++) { $pack->dialog_option_id = $options[$i]->dialog_option_id; dialogs::deleteDialogOption($pack); } $reqPack = dbconnection::queryObject("SELECT * FROM requirement_root_packages WHERE requirement_root_package_id = '{$tab->requirement_root_package_id}'"); if ($reqPack) { $pack->requirement_root_package_id = $reqPack->requirement_root_package_id; requirements::deleteRequirementPackage($pack); } games::bumpGameVersion($pack); return new return_package(0); }
public static function deleteNoteComment($pack) { $note_comment = dbconnection::queryObject("SELECT * FROM note_comments WHERE note_comment_id = '{$pack->note_comment_id}'"); $note = dbconnection::queryObject("SELECT * FROM notes WHERE note_id = '{$note_comment->note_id}'"); $pack->auth->game_id = $note_comment->game_id; $pack->auth->permission = "read_write"; //tl;dr: must be game owner, note owner, or comment owner to delete comment if (!(users::authenticateUser($pack->auth) && ($pack->auth->user_id == $note_comment->user_id || $pack->auth->user_id == $note->user_id)) && !editors::authenticateGameEditor($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } dbconnection::query("DELETE FROM note_comments WHERE note_comment_id = '{$pack->note_comment_id}' LIMIT 1"); games::bumpGameVersion($pack); return new return_package(0); }
public static function deleteMedia($pack) { $media_sql = dbconnection::queryObject("SELECT * FROM media WHERE media_id = '{$pack->media_id}'"); $pack->auth->game_id = $media_sql->game_id; $pack->auth->permission = "read_write"; if (!editors::authenticateGameEditor($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } if (!unlink(Config::v2_gamedata_folder . "/" . $media_sql->file_folder . "/" . $media_sql->file_name)) { return new return_package(1, "Could not delete file."); } dbconnection::query("DELETE FROM media WHERE media_id = '{$pack->media_id}' LIMIT 1"); //cleanup dbconnection::query("UPDATE games SET media_id = 0 WHERE media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE games SET icon_media_id = 0 WHERE icon_media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE tabs SET icon_media_id = 0 WHERE icon_media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE items SET media_id = 0 WHERE media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE items SET icon_media_id = 0 WHERE icon_media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE dialogs SET icon_media_id = 0 WHERE icon_media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE dialog_characters SET media_id = 0 WHERE media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE plaques SET media_id = 0 WHERE media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE plaques SET icon_media_id = 0 WHERE icon_media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE web_pages SET icon_media_id = 0 WHERE icon_media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE tags SET media_id = 0 WHERE media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE overlays SET media_id = 0 WHERE media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE note_media SET media_id = 0 WHERE media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE quests SET active_media_id = 0 WHERE active_media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE quests SET active_icon_media_id = 0 WHERE active_icon_media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE quests SET complete_media_id = 0 WHERE complete_media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE quests SET complete_icon_media_id = 0 WHERE complete_icon_media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE triggers SET icon_media_id = 0 WHERE icon_media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE factories SET trigger_icon_media_id = 0 WHERE trigger_icon_media_id = '{$pack->media_id}'"); dbconnection::query("UPDATE users SET media_id = 0 WHERE media_id = '{$pack->media_id}'"); games::bumpGameVersion($pack); return new return_package(0); }
public static function cleanOrphans($pack) { $tables = array(); $tables[] = "dialog_characters"; $tables[] = "dialog_options"; $tables[] = "dialog_scripts"; $tables[] = "dialogs"; $tables[] = "event_packages"; $tables[] = "events"; $tables[] = "factories"; $tables[] = "game_comments"; $tables[] = "instances"; $tables[] = "items"; $tables[] = "media"; $tables[] = "note_comments"; $tables[] = "note_likes"; $tables[] = "notes"; $tables[] = "object_tags"; $tables[] = "overlays"; $tables[] = "plaques"; $tables[] = "quests"; $tables[] = "requirement_and_packages"; $tables[] = "requirement_atoms"; $tables[] = "requirement_root_packages"; $tables[] = "scenes"; $tables[] = "tabs"; $tables[] = "tags"; $tables[] = "triggers"; $tables[] = "user_game_scenes"; $tables[] = "user_games"; $tables[] = "web_hooks"; $tables[] = "web_pages"; for ($i = 0; $i < count($tables); $i++) { $arr = dbconnection::queryArray("SELECT {$tables[$i]}.game_id as game_id, games.game_id as n_game_id FROM {$tables[$i]} LEFT JOIN games ON {$tables[$i]}.game_id = games.game_id WHERE games.game_id IS NULL GROUP BY game_id;"); for ($j = 0; $j < count($arr); $j++) { if ($tables[$i] == "media" && $arr[$j]->game_id == 0) { continue; } //allow default media if ($pack->execute) { dbconnection::query("DELETE FROM {$tables[$i]} WHERE game_id = '{$arr[$j]->game_id}';"); } else { //dry run echo "DELETE FROM {$tables[$i]} WHERE game_id = '{$arr[$j]->game_id}'; (game_id = '{$arr[$j]->game_id}')\n"; } } } //instances $types = array(); $tables = array(); $ids = array(); $types[] = "PLAQUE"; $tables[] = "plaques"; $ids[] = "plaque_id"; $types[] = "ITEM"; $tables[] = "items"; $ids[] = "item_id"; $types[] = "DIALOG"; $tables[] = "dialogs"; $ids[] = "dialog_id"; $types[] = "WEB_PAGE"; $tables[] = "web_pages"; $ids[] = "web_page_id"; $types[] = "NOTE"; $tables[] = "notes"; $ids[] = "note_id"; $types[] = "FACTORY"; $tables[] = "factories"; $ids[] = "factory_id"; for ($i = 0; $i < count($types); $i++) { $arr = dbconnection::queryArray("SELECT instances.* FROM instances LEFT JOIN {$tables[$i]} ON instances.object_id = {$tables[$i]}.{$ids[$i]} WHERE instances.object_type = '{$types[$i]}' AND {$tables[$i]}.{$ids[$i]} IS NULL;"); for ($j = 0; $j < count($arr); $j++) { if ($pack->execute) { dbconnection::query("DELETE FROM instances WHERE instance_id = '{$arr[$j]->instance_id}';"); } else { //dry run echo "DELETE FROM instances WHERE instance_id = '{$arr[$j]->instance_id}'; (game_id = '{$arr[$j]->game_id}')\n"; } } } //triggers $arr = dbconnection::queryArray("SELECT triggers.* FROM triggers LEFT JOIN instances ON triggers.instance_id = instances.instance_id WHERE instances.instance_id IS NULL;"); for ($j = 0; $j < count($arr); $j++) { if ($pack->execute) { dbconnection::query("DELETE FROM triggers WHERE trigger_id = '{$arr[$j]->trigger_id}';"); } else { //dry run echo "DELETE FROM triggers WHERE trigger_id = '{$arr[$j]->trigger_id}'; (game_id = '{$arr[$j]->game_id}')\n"; } } //requirements // \/ query to manually see requirement tree in SQL. nice for debugging. //SELECT ratom.requirement_atom_id, rand.requirement_and_package_id, rroot.requirement_root_package_id FROM requirement_atoms as ratom LEFT JOIN requirement_and_packages as rand ON ratom.requirement_and_package_id = rand.requirement_and_package_id LEFT JOIN requirement_root_packages as rroot ON rand.requirement_root_package_id = rroot.requirement_root_package_id WHERE rand.game_id = 3259; $arr = dbconnection::queryArray("SELECT requirement_and_packages.* FROM requirement_and_packages LEFT JOIN requirement_root_packages ON requirement_and_packages.requirement_root_package_id = requirement_root_packages.requirement_root_package_id WHERE requirement_root_packages.requirement_root_package_id IS NULL;"); for ($j = 0; $j < count($arr); $j++) { if ($pack->execute) { dbconnection::query("DELETE FROM requirement_and_packages WHERE requirement_and_package_id = '{$arr[$j]->requirement_and_package_id}';"); } else { //dry run echo "DELETE FROM requirement_and_packages WHERE requirement_and_package_id = '{$arr[$j]->requirement_and_package_id}'; (game_id = '{$arr[$j]->game_id}')\n"; } } $arr = dbconnection::queryArray("SELECT requirement_atoms.* FROM requirement_atoms LEFT JOIN requirement_and_packages ON requirement_atoms.requirement_and_package_id = requirement_and_packages.requirement_and_package_id WHERE requirement_and_packages.requirement_and_package_id IS NULL;"); for ($j = 0; $j < count($arr); $j++) { if ($pack->execute) { dbconnection::query("DELETE FROM requirement_atoms WHERE requirement_atom_id = '{$arr[$j]->requirement_atom_id}';"); } else { //dry run echo "DELETE FROM requirement_atoms WHERE requirement_atom_id = '{$arr[$j]->requirement_atom_id}'; (game_id = '{$arr[$j]->game_id}')\n"; } } return new return_package(0); }
public static function deleteFactory($pack) { $factory = dbconnection::queryObject("SELECT * FROM factories WHERE factory_id = '{$pack->factory_id}'"); $pack->auth->game_id = $factory->game_id; $pack->auth->permission = "read_write"; if (!editors::authenticateGameEditor($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } dbconnection::query("DELETE FROM factories WHERE factory_id = '{$pack->factory_id}' LIMIT 1"); //cleanup $instances = dbconnection::queryArray("SELECT * FROM instances WHERE factory_id = '{$pack->factory_id}'"); for ($i = 0; $i < count($instances); $i++) { $pack->instance_id = $instances[$i]->instance_id; instances::deleteInstance($pack); } $instances = dbconnection::queryArray("SELECT * FROM instances WHERE object_type = 'FACTORY' AND object_id = '{$pack->factory_id}'"); for ($i = 0; $i < count($instances); $i++) { $pack->instance_id = $instances[$i]->instance_id; instances::deleteInstance($pack); } $reqPack = dbconnection::queryObject("SELECT * FROM requirement_root_packages WHERE requirement_root_package_id = '{$factory->requirement_root_package_id}'"); if ($reqPack) { $pack->requirement_root_package_id = $reqPack->requirement_root_package_id; requirements::deleteRequirementPackage($pack); } $reqPack = dbconnection::queryObject("SELECT * FROM requirement_root_packages WHERE requirement_root_package_id = '{$factory->trigger_requirement_root_package_id}'"); if ($reqPack) { $pack->requirement_root_package_id = $reqPack->requirement_root_package_id; requirements::deleteRequirementPackage($pack); } games::bumpGameVersion($pack); return new return_package(0); }
public static function unlikeNote($pack) { $pack->auth->permission = "read_write"; if (!users::authenticateUser($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } dbconnection::query("DELETE FROM note_likes" . " WHERE game_id = '" . intval($pack->game_id) . "'" . " AND note_id = '" . intval($pack->note_id) . "'" . " AND user_id = '" . intval($pack->auth->user_id) . "'" . " LIMIT 1"); return new return_package(0); }
public static function noauth_deleteInstance($pack) { //and this "fixes" the security risk... if (strpos($_SERVER['REQUEST_URI'], 'noauth') !== false) { return new return_package(6, NULL, "Attempt to bypass authentication externally."); } dbconnection::query("DELETE FROM instances WHERE instance_id = '{$pack->instance_id}' LIMIT 1"); //cleanup $triggers = dbconnection::queryArray("SELECT * FROM triggers WHERE instance_id = '{$pack->instance_id}'"); for ($i = 0; $i < count($triggers); $i++) { $pack->trigger_id = $triggers[$i]->trigger_id; triggers::noauth_deleteTrigger($pack); } return new return_package(0); }
public static function deleteEvent($pack) { $pack->auth->game_id = dbconnection::queryObject("SELECT * FROM events WHERE event_id = '{$pack->event_id}'")->game_id; $pack->auth->permission = "read_write"; if (!editors::authenticateGameEditor($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } dbconnection::query("DELETE FROM events WHERE event_id = '{$pack->event_id}' LIMIT 1"); games::bumpGameVersion($pack); return new return_package(0); }
public static function noauth_deleteTrigger($pack) { //and this "fixes" the security risk... if (strpos($_SERVER['REQUEST_URI'], 'noauth') !== false) { return new return_package(6, NULL, "Attempt to bypass authentication externally."); } dbconnection::query("DELETE FROM triggers WHERE trigger_id = '{$pack->trigger_id}' LIMIT 1"); //cleanup $instances = dbconnection::queryArray("SELECT * FROM instances WHERE instance_id = '{$trigger->instance_id}'"); for ($i = 0; $i < count($instances); $i++) { $pack->instance_id = $instances[$i]->instance_id; instances::noauth_deleteInstance($pack); } $reqPack = dbconnection::queryObject("SELECT * FROM requirement_root_packages WHERE requirement_root_package_id = '{$trigger->requirement_root_package_id}'"); if ($reqPack) { $pack->requirement_root_package_id = $reqPack->requirement_root_package_id; requirements::noauth_deleteRequirementPackage($pack); } games::bumpGameVersion($pack); return new return_package(0); }
public static function logPlayerResetGame($pack) { $pack->auth->permission = "read_write"; if (!users::authenticateUser($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } dbconnection::queryInsert("INSERT INTO user_log (user_id, game_id, event_type, created) VALUES ('{$pack->auth->user_id}', '{$pack->game_id}', 'RESET_GAME', CURRENT_TIMESTAMP);"); dbconnection::query("UPDATE user_log SET deleted = 1 WHERE user_id = '{$pack->auth->user_id}' AND game_id = '{$pack->game_id}'"); //ok technically does more than just 'logs' //so should be separated into own func dbconnection::query("DELETE FROM instances WHERE game_id = '{$pack->game_id}' AND owner_type = 'USER' AND owner_id = '{$pack->auth->user_id}' AND owner_id != 0"); //extra '!= 0' to prevent accidentally deleting all non player instances dbconnection::query("DELETE FROM user_game_scenes WHERE user_id = '{$pack->auth->user_id}' AND game_id = '{$pack->game_id}'"); return new return_package(0); }
public static function deleteObjectTagsForObject($pack) { $pack->auth->game_id = $pack->game_id; $pack->auth->permission = "read_write"; if (!editors::authenticateGameEditor($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } dbconnection::query("DELETE FROM object_tags WHERE game_id = '{$pack->game_id}' AND object_type = '{$pack->object_type}' AND object_id = '{$pack->object_id}';"); games::bumpGameVersion($pack); }
public static function noauth_deleteRequirementAtom($pack) { //and this "fixes" the security risk... if (strpos($_server['request_uri'], 'noauth') !== false) { return new return_package(6, null, "attempt to bypass authentication externally."); } dbconnection::query("DELETE FROM requirement_atoms WHERE requirement_atom_id = '{$pack->requirement_atom_id}'"); games::bumpGameVersion($pack); return new return_package(0); }
public static function deleteQuest($pack) { $quest = dbconnection::queryObject("SELECT * FROM quests WHERE quest_id = '{$pack->quest_id}'"); $pack->auth->game_id = $quest->game_id; $pack->auth->permission = "read_write"; if (!editors::authenticateGameEditor($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } dbconnection::query("DELETE FROM quests WHERE quest_id = '{$pack->quest_id}' LIMIT 1"); //cleanup $reqAtoms = dbconnection::queryArray("SELECT * FROM requirement_atoms WHERE requirement = 'PLAYER_HAS_COMPLETED_QUEST' AND content_id = '{$pack->quest_id}'"); for ($i = 0; $i < count($reqAtoms); $i++) { $pack->requirement_atom_id = $reqAtoms[$i]->requirement_atom_id; requirements::deleteRequirementAtom($pack); } /* Comment out until we've decided on desired behavior... $eventpack = dbconnection::queryObject("SELECT * FROM event_packages WHERE event_package_id = '{$quest->active_event_package_id}'"); if($eventpack) { $pack->event_package_id = $eventpack->event_package_id; events::deleteEventPackage($pack); } $eventpack = dbconnection::queryObject("SELECT * FROM event_packages WHERE event_package_id = '{$quest->complete_event_package_id}'"); if($eventpack) { $pack->event_package_id = $eventpack->event_package_id; events::deleteEventPackage($pack); } */ $reqPack = dbconnection::queryObject("SELECT * FROM requirement_root_packages WHERE requirement_root_package_id = '{$quest->active_requirement_root_package_id}'"); if ($reqPack) { $pack->requirement_root_package_id = $reqPack->requirement_root_package_id; requirements::deleteRequirementPackage($pack); } $reqPack = dbconnection::queryObject("SELECT * FROM requirement_root_packages WHERE requirement_root_package_id = '{$quest->complete_requirement_root_package_id}'"); if ($reqPack) { $pack->requirement_root_package_id = $reqPack->requirement_root_package_id; requirements::deleteRequirementPackage($pack); } games::bumpGameVersion($pack); return new return_package(0); }
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); }
public static function fixPassword($pack) { $user_id = addslashes($pack->user_id); $junk = addslashes($pack->junk); $newPass = addslashes($pack->new_password); if ($junk != users::breakPassword($user_id)) { return new returnData(0); } //fail, but don't make it obvious //if changing password, invalidate all keys $salt = util::rand_string(64); $hash = hash("sha256", $salt . $newPass); $read = util::rand_string(64); $write = util::rand_string(64); $read_write = util::rand_string(64); dbconnection::query("UPDATE users SET " . "salt = '{$salt}', " . "hash = '{$hash}', " . "read_key = '{$read}', " . "write_key = '{$write}', " . "read_write_key = '{$read_write}' " . "WHERE user_id = '{$user_id}'"); return new return_package(0, NULL); }