{"upgrade_curr"}; $stars = $rune->{"class"}; // Ancient stars are + 10 if ($stars > 10){ $stars -= 10; } $list = null; // Main stat $main_stat = $rune->{"pri_eff"}[0]; switch ($main_stat){ case RUNE_STAT_ID::HP: $list = RUNE_STAT_VALUES::HP; break; case RUNE_STAT_ID::HP_P: $list = RUNE_STAT_VALUES::HP_P; break; case RUNE_STAT_ID::ATK: $list = RUNE_STAT_VALUES::ATK; break; case RUNE_STAT_ID::ATK_P: $list = RUNE_STAT_VALUES::ATK_P; break; case RUNE_STAT_ID::DEF: $list = RUNE_STAT_VALUES::DEF; break; case RUNE_STAT_ID::DEF_P: $list = RUNE_STAT_VALUES::DEF_P; break; case RUNE_STAT_ID::SPD: $list = RUNE_STAT_VALUES::SPD; break; case RUNE_STAT_ID::CRR: $list = RUNE_STAT_VALUES::CRR; break; case RUNE_STAT_ID::CRD: $list = RUNE_STAT_VALUES::CRD; break; case RUNE_STAT_ID::ACC: $list = RUNE_STAT_VALUES::ACC; break; case RUNE_STAT_ID::RES: $list = RUNE_STAT_VALUES::RES; break; } $efficiency += floatval($list[$stars][$level]) / floatval($list[6][15]); // Innate stat if ($rune->{"prefix_eff"}[0] > 0){ $innate_stat = $rune->{"pri_eff"}[0]; $innate_stat_value = $rune->{"pri_eff"}[1]; $efficiency += floatval($innate_stat_value) / (5 * floatval(RUNE_SUBSTAT_MAX_VALUES::SUBSTAT[$innate_stat][6])); } // Substats for ($i = 0; $i <= 3; $i ++){ if (sizeof($rune->{"sec_eff"}) > $i){ $substat = $rune->{"sec_eff"}[$i][0]; $substat_value = $rune->{"sec_eff"}[$i][1]; $efficiency += floatval($substat_value) / (5 * floatval(RUNE_SUBSTAT_MAX_VALUES::SUBSTAT[$substat][6])); } } $efficiency = $efficiency / 2.8 * 100; if ($efficiency > 100){ $efficiency = 100; } return $efficiency; } /** * Calculates the maximum efficiency of a rune. * * @param mixed[] $rune JSON fragment of the rune. * @return int Maximum efficiency (0-100) */ function calculate_maximum_efficiency($rune){ $efficiency = 0.0; $stars = $rune->{"class"}; // Ancient stars are + 10 if ($stars > 10){ $stars -= 10; } $list = null; // Main stat $main_stat = $rune->{"pri_eff"}[0]; switch ($main_stat){ case RUNE_STAT_ID::HP: $list = RUNE_STAT_VALUES::HP; break; case RUNE_STAT_ID::HP_P: $list = RUNE_STAT_VALUES::HP_P; break; case RUNE_STAT_ID::ATK: $list = RUNE_STAT_VALUES::ATK; break; case RUNE_STAT_ID::ATK_P: $list = RUNE_STAT_VALUES::ATK_P; break; case RUNE_STAT_ID::DEF: $list = RUNE_STAT_VALUES::DEF; break; case RUNE_STAT_ID::DEF_P: $list = RUNE_STAT_VALUES::DEF_P; break; case RUNE_STAT_ID::SPD: $list = RUNE_STAT_VALUES::SPD; break; case RUNE_STAT_ID::CRR: $list = RUNE_STAT_VALUES::CRR; break; case RUNE_STAT_ID::CRD: $list = RUNE_STAT_VALUES::CRD; break; case RUNE_STAT_ID::ACC: $list = RUNE_STAT_VALUES::ACC; break; case RUNE_STAT_ID::RES: $list = RUNE_STAT_VALUES::RES; break; } $efficiency += floatval($list[$stars][15]) / floatval($list[6][15]); // Innate stat if ($rune->{"prefix_eff"}[0] > 0){ $innate_stat = $rune->{"pri_eff"}[0]; $innate_stat_value = $rune->{"pri_eff"}[1]; $efficiency += floatval($innate_stat_value) / (5 * floatval(RUNE_SUBSTAT_MAX_VALUES::SUBSTAT[$innate_stat][6])); } // Substats for ($i = 0; $i <= 3; $i ++){ if (sizeof($rune->{"sec_eff"}) > $i){ $substat = $rune->{"sec_eff"}[$i][0]; $efficiency += floatval(RUNE_SUBSTAT_MAX_VALUES::SUBSTAT[$substat][$stars]) / (5 * floatval(RUNE_SUBSTAT_MAX_VALUES::SUBSTAT[$substat][6])); } } $efficiency = $efficiency / 2.8 * 100; if ($efficiency > 100){ $efficiency = 100; } return $efficiency; } /** * Parses the JSONs relateds to an Arena run and saves the data. * * @param resource $db Database connection. * @param int $uid Player UID. * @param int $id Run ID. * @param mixed[] $json List of received JSONs. */ function log_arena_run($db, $id, $uid, $json){ // Only the result request and response JSONs are needed: $response = $json["result_res"]; // Prepare the "run" insert. $statement = $db->prepare(" INSERT INTO run ( uid, id, dtime, area_type, area, stage, difficulty, win, time, mana, energy, crystal, guild_points, honor_points, helper, score, rank ) VALUES ( :uid, :id, :dtime, :area_type, :area, :stage, :difficulty, :win, :time, :mana, :energy, :crystal, :guild_points, :honor_points, :helper, :score, :rank ); "); // Bind data and insert $statement->bindValue(":uid", $uid, SQLITE3_INTEGER); $statement->bindValue(":id", $id, SQLITE3_INTEGER); $statement->bindValue(":dtime", $response->{"tvaluelocal"}, SQLITE3_TEXT); $statement->bindValue(":area_type", AREA_TYPE_ID::ARENA, SQLITE3_INTEGER); $statement->bindValue(":area", AREA_TYPE_ID::ARENA, SQLITE3_INTEGER); $statement->bindValue(":stage", null, SQLITE3_INTEGER); $statement->bindValue(":difficulty", null, SQLITE3_INTEGER); $statement->bindValue(":win", $response->{"win_lose"}, SQLITE3_INTEGER); $statement->bindValue(":time", 1, SQLITE3_INTEGER); if (array_key_exists("mana", $response->{"reward"})){ $statement->bindValue(":mana", $response->{"reward"}->{"mana"}, SQLITE3_INTEGER); } else{ $statement->bindValue(":mana", 0, SQLITE3_INTEGER); } if (array_key_exists("energy", $response->{"reward"})){ $statement->bindValue(":energy", $response->{"reward"}->{"energy"}, SQLITE3_INTEGER); } else{ $statement->bindValue(":energy", 0, SQLITE3_INTEGER); } if (array_key_exists("crystal", $response->{"reward"})){ $statement->bindValue(":crystal", $response->{"reward"}->{"crystal"}, SQLITE3_INTEGER); } else{ $statement->bindValue(":crystal", 0, SQLITE3_INTEGER); } $statement->bindValue(":guild_points", 0, SQLITE3_INTEGER); if (array_key_exists("honor_point", $response->{"reward"})){ $statement->bindValue(":honor_points", $response->{"reward"}->{"honor_point"}, SQLITE3_INTEGER); } else{ $statement->bindValue(":honor_points", 0, SQLITE3_INTEGER); } $statement->bindValue(":helper", 0, SQLITE3_INTEGER); $statement->bindValue(":score", null, SQLITE3_INTEGER); $statement->bindValue(":rank", null, SQLITE3_TEXT); $statement->execute(); // Parse party $leader = 1; foreach ($response->{"unit_list"} as $unit){ $statement = $db->prepare(" INSERT INTO run_party (run, unit, k_unit, leader, front) VALUES (:run, :unit, :k_unit, :leader, :front);" ); $statement->bindValue(":run", $id, SQLITE3_INTEGER); $statement->bindValue(":unit", $unit->{"unit_id"}, SQLITE3_INTEGER); $statement->bindValue(":k_unit", $unit->{"unit_master_id"}, SQLITE3_INTEGER); $statement->bindValue(":leader", $leader, SQLITE3_INTEGER); $leader = 0; $statement->bindValue(":front", 0, SQLITE3_INTEGER); $statement->execute(); } // Return success return "201 Created."; } /** * Parses the JSONs relateds to a Dimensional Rift run and saves the data. * * @param resource $db Database connection. * @param int $uid Player UID. * @param int $id Run ID. * @param mixed[] $json List of received JSONs. */ function log_dark_portal_run($db, $id, $uid, $json){ // Only the result request and response JSONs are needed: $response = $json["result_res"]; // Prepare the "run" insert. $statement = $db->prepare(" INSERT INTO run ( uid, id, dtime, area_type, area, stage, difficulty, win, time, mana, energy, crystal, guild_points, honor_points, helper, score, rank ) VALUES ( :uid, :id, :dtime, :area_type, :area, :stage, :difficulty, :win, :time, :mana, :energy, :crystal, :guild_points, :honor_points, :helper, :score, :rank ); "); // Bind data and insert $statement->bindValue(":uid", $uid, SQLITE3_INTEGER); $statement->bindValue(":id", $id, SQLITE3_INTEGER); $statement->bindValue(":dtime", $response->{"tvaluelocal"}, SQLITE3_INTEGER); $statement->bindValue(":area_type", AREA_TYPE_ID::DIMENSIONAL_RIFT, SQLITE3_INTEGER); // The area is the region the portal is open in. $statement->bindValue(":area", $response->{"region_id"}, SQLITE3_INTEGER); $statement->bindValue(":stage", null, SQLITE3_INTEGER); $statement->bindValue(":difficulty", $response->{"difficulty"}, SQLITE3_INTEGER); $statement->bindValue(":win", $response->{"win_lose"}, SQLITE3_INTEGER); $statement->bindValue(":time", 1, SQLITE3_INTEGER); if (array_key_exists("mana", $response->{"reward"})){ $statement->bindValue(":mana", $response->{"reward"}->{"mana"}, SQLITE3_INTEGER); } else{ $statement->bindValue(":mana", 0, SQLITE3_INTEGER); } if (array_key_exists("energy", $response->{"reward"})){ $statement->bindValue(":energy", $response->{"reward"}->{"energy"}); } else{ $statement->bindValue(":energy", 0); } if (array_key_exists("crystal", $response->{"reward"})){ $statement->bindValue(":crystal", $response->{"reward"}->{"crystal"}, SQLITE3_INTEGER); } else{ $statement->bindValue(":crystal", 0, SQLITE3_INTEGER); } $statement->bindValue(":guild_points", 0, SQLITE3_INTEGER); $statement->bindValue(":honor_points", 0, SQLITE3_INTEGER); $statement->bindValue(":helper", 0, SQLITE3_INTEGER); $statement->bindValue(":score", null, SQLITE3_INTEGER); $statement->bindValue(":rank", null, SQLITE3_TEXT); $statement->execute(); // Parse party $leader = 1; foreach ($response->{"unit_list"} as $unit){ $statement = $db->prepare(" INSERT INTO run_party (run, unit, k_unit, leader, front) VALUES (:run, :unit, :k_unit, :leader, :front);" ); $statement->bindValue(":run", $id, SQLITE3_INTEGER); $statement->bindValue(":unit", $unit->{"unit_id"}, SQLITE3_INTEGER); $statement->bindValue(":k_unit", $unit->{"unit_master_id"}, SQLITE3_INTEGER); $statement->bindValue(":leader", $leader, SQLITE3_INTEGER); $leader = 0; $statement->bindValue(":front", 0, SQLITE3_INTEGER); $statement->execute(); } // Return success return "201 Created."; } /** * Parses the JSONs relateds to a scenario run and saves the data. * * @param resource $db Database connection. * @param int $uid Player UID. * @param int $id Run ID. * @param mixed[] $json List of received JSONs. */ function log_scenario_run($db, $id, $uid, $json){ // Only the result request and response JSONs are needed: $response = $json["result_res"]; if ($json["start_res"] === null){ return ("400 Start response is required to parse scenario runs."); } $request = $json["start_res"]; // Prepare the "run" insert. $statement = $db->prepare(" INSERT INTO run ( uid, id, dtime, area_type, area, stage, difficulty, win, time, mana, energy, crystal, guild_points, honor_points, helper, score, rank ) VALUES ( :uid, :id, :dtime, :area_type, :area, :stage, :difficulty, :win, :time, :mana, :energy, :crystal, :guild_points, :honor_points, :helper, :score, :rank ); "); // Bind data and insert $statement->bindValue(":uid", $uid, SQLITE3_INTEGER); $statement->bindValue(":id", $id, SQLITE3_INTEGER); $statement->bindValue(":dtime", $response->{"tvaluelocal"}, SQLITE3_TEXT); $statement->bindValue(":area_type", AREA_TYPE_ID::SCENARIO, SQLITE3_INTEGER); $statement->bindValue(":area", $response->{"scenario_info"}->{"region_id"}, SQLITE3_INTEGER); $statement->bindValue(":stage", $response->{"scenario_info"}->{"stage_no"}, SQLITE3_INTEGER); $statement->bindValue(":difficulty", $response->{"scenario_info"}->{"difficulty"}, SQLITE3_INTEGER); $statement->bindValue(":win", $response->{"win_lose"}, SQLITE3_INTEGER); $statement->bindValue(":time", $response->{"clear_time"}->{"current_time"}, SQLITE3_INTEGER); if (array_key_exists("mana", $response->{"reward"})){ $statement->bindValue(":mana", $response->{"reward"}->{"mana"}, SQLITE3_INTEGER); } else{ $statement->bindValue(":mana", 0, SQLITE3_INTEGER); } if (array_key_exists("energy", $response->{"reward"})){ $statement->bindValue(":energy", $response->{"reward"}->{"energy"}, SQLITE3_INTEGER); } else{ $statement->bindValue(":energy", 0, SQLITE3_INTEGER); } if (array_key_exists("crystal", $response->{"reward"})){ $statement->bindValue(":crystal", $response->{"reward"}->{"crystal"}, SQLITE3_INTEGER); } else{ $statement->bindValue(":crystal", 0, SQLITE3_INTEGER); } $statement->bindValue(":guild_points", 0, SQLITE3_INTEGER); $statement->bindValue(":honor_points", 0, SQLITE3_INTEGER); if (array_key_exists("helper_unit_list", $request) && sizeof($request->{"helper_unit_list"}) > 0){ $statement->bindValue(":helper", 1, SQLITE3_INTEGER); } else{ $statement->bindValue(":helper", 0, SQLITE3_INTEGER); } $statement->bindValue(":score", null, SQLITE3_INTEGER); $statement->bindValue(":rank", null, SQLITE3_TEXT); $statement->execute(); // Parse various types of reward if (array_key_exists("crate", $response->{"reward"})){ $crate = $response->{"reward"}->{"crate"}; if (array_key_exists("unit_info", $crate)){ $unit = $crate->{"unit_info"}; $statement = $db->prepare("INSERT INTO run_drop_unit (run, unit) VALUES (:run, :unit);"); $statement->bindValue(":run", $id, SQLITE3_INTEGER); $statement->bindValue(":unit", $unit->{"unit_master_id"}, SQLITE3_INTEGER); $statement->execute(); } if (array_key_exists("craft_stuff", $crate)){ $item = $crate->{"craft_stuff"}; $statement = $db->prepare("INSERT INTO run_drop_item (run, item, amount) VALUES (:run, :item, :amount);"); $statement->bindValue(":run", $id, SQLITE3_INTEGER); $statement->bindValue(":item", $item->{"item_master_id"}, SQLITE3_INTEGER); $statement->bindValue(":amount", $item->{"item_quantity"}, SQLITE3_INTEGER); $statement->execute(); } if (array_key_exists("random_scroll", $crate)){ $item = $crate->{"random_scroll"}; $statement = $db->prepare("INSERT INTO run_drop_item (run, item, amount) VALUES (:run, :item, :amount);"); $statement->bindValue(":run", $id, SQLITE3_INTEGER); $statement->bindValue(":item", $item->{"item_master_id"}, SQLITE3_INTEGER); $statement->bindValue(":amount", $item->{"item_quantity"}, SQLITE3_INTEGER); $statement->execute(); } if (array_key_exists("rune", $crate)){ $rune = $crate->{"rune"}; $statement = $db->prepare(" INSERT INTO run_drop_rune ( run, id, type, slot, stars, ancient, quality, value, efficiency, max_efficiency, main_stat, main_stat_value, innate_stat, innate_stat_value, substat_1, substat_1_value, substat_2, substat_2_value, substat_3, substat_3_value, substat_4, substat_4_value ) VALUES ( :run, :id, :type, :slot, :stars, :ancient, :quality, :value, :efficiency, :max_efficiency, :main_stat, :main_stat_value, :innate_stat, :innate_stat_value, :substat_1, :substat_1_value, :substat_2, :substat_2_value, :substat_3, :substat_3_value, :substat_4, :substat_4_value ); "); $statement->bindValue(":run", $id); $statement->bindValue(":id", $rune->{"rune_id"}); $statement->bindValue(":type", $rune->{"set_id"}); $statement->bindValue(":slot", $rune->{"slot_no"}); $statement->bindValue(":value", $rune->{"sell_value"}); if ($rune->{"class"} > 10){ // Ancient rune $statement->bindValue(":ancient", 1, SQLITE3_INTEGER); $statement->bindValue(":stars", intval($rune->{"class"}) - 10, SQLITE3_INTEGER); $statement->bindValue(":quality", intval($rune->{"rank"}) - 10, SQLITE3_INTEGER); } else{ // Non Ancient rune $statement->bindValue(":ancient", 0, SQLITE3_INTEGER); $statement->bindValue(":stars", $rune->{"class"}, SQLITE3_INTEGER); $statement->bindValue(":quality", $rune->{"rank"}, SQLITE3_INTEGER); } $efficiency = calculate_efficiency($rune); $max_efficiency = calculate_maximum_efficiency($rune); $statement->bindValue(":efficiency", $efficiency, SQLITE3_FLOAT); $statement->bindValue(":max_efficiency", $max_efficiency, SQLITE3_FLOAT); $statement->bindValue(":main_stat", $rune->{"pri_eff"}[0], SQLITE3_INTEGER); $statement->bindValue(":main_stat_value", $rune->{"pri_eff"}[1], SQLITE3_INTEGER); if ($rune->{"prefix_eff"}[0] > 0){ $statement->bindValue(":innate_stat", $rune->{"prefix_eff"}[0], SQLITE3_INTEGER); $statement->bindValue(":innate_stat_value", $rune->{"prefix_eff"}[1], SQLITE3_INTEGER); } else{ $statement->bindValue(":innate_stat", null, SQLITE3_INTEGER); $statement->bindValue(":innate_stat_value", 0, SQLITE3_INTEGER); } if (sizeof($rune->{"sec_eff"}) > 0){ $statement->bindValue(":substat_1", $rune->{"sec_eff"}[0][0], SQLITE3_INTEGER); $statement->bindValue(":substat_1_value", $rune->{"sec_eff"}[0][1], SQLITE3_INTEGER); } else{ $statement->bindValue(":substat_1", null, SQLITE3_INTEGER); $statement->bindValue(":substat_1_value", 0, SQLITE3_INTEGER); } if (sizeof($rune->{"sec_eff"}) > 1){ $statement->bindValue(":substat_2", $rune->{"sec_eff"}[1][0], SQLITE3_INTEGER); $statement->bindValue(":substat_2_value", $rune->{"sec_eff"}[1][1], SQLITE3_INTEGER); } else{ $statement->bindValue(":substat_2", null, SQLITE3_INTEGER); $statement->bindValue(":substat_2_value", 0, SQLITE3_INTEGER); } if (sizeof($rune->{"sec_eff"}) > 2){ $statement->bindValue(":substat_3", $rune->{"sec_eff"}[2][0], SQLITE3_INTEGER); $statement->bindValue(":substat_3_value", $rune->{"sec_eff"}[2][1], SQLITE3_INTEGER); } else{ $statement->bindValue(":substat_3", null, SQLITE3_INTEGER); $statement->bindValue(":substat_3_value", 0, SQLITE3_INTEGER); } if (sizeof($rune->{"sec_eff"}) > 3){ $statement->bindValue(":substat_4", $rune->{"sec_eff"}[3][0], SQLITE3_INTEGER); $statement->bindValue(":substat_4_value", $rune->{"sec_eff"}[3][1], SQLITE3_INTEGER); } else{ $statement->bindValue(":substat_4", null, SQLITE3_INTEGER); $statement->bindValue(":substat_4_value", 0, SQLITE3_INTEGER); } $statement->execute(); } } // Parse party $leader = 1; foreach ($response->{"unit_list"} as $unit){ $statement = $db->prepare(" INSERT INTO run_party (run, unit, k_unit, leader, front) VALUES (:run, :unit, :k_unit, :leader, :front);" ); $statement->bindValue(":run", $id, SQLITE3_INTEGER); $statement->bindValue(":unit", $unit->{"unit_id"}, SQLITE3_INTEGER); $statement->bindValue(":k_unit", $unit->{"unit_master_id"}, SQLITE3_INTEGER); $statement->bindValue(":leader", $leader, SQLITE3_INTEGER); $leader = 0; $statement->bindValue(":front", 0, SQLITE3_INTEGER); $statement->execute(); } // Return success return "201 Created."; } /** * Parses the JSONs relateds to a cairos run and saves the data. * * @param resource $db Database connection. * @param int $uid Player UID. * @param int $id Run ID. * @param mixed[] $json List of received JSONs. */ function log_rift_raid_run($db, $id, $uid, $json){ // Only the start and result requests JSONs are needed: $result = $json["result_res"]; if ($json["start_res"] === null){ return ("400 Start response is required to parse Rift Raid runs."); } $start = $json["start_res"]; // Prepare the "run" insert. $statement = $db->prepare(" INSERT INTO run ( uid, id, dtime, area_type, area, stage, difficulty, win, time, mana, energy, crystal, guild_points, honor_points, helper, score, rank ) VALUES ( :uid, :id, :dtime, :area_type, :area, :stage, :difficulty, :win, :time, :mana, :energy, :crystal, :guild_points, :honor_points, :helper, :score, :rank ); "); // Bind data and insert $statement->bindValue(":uid", $uid, SQLITE3_INTEGER); $statement->bindValue(":id", $id, SQLITE3_INTEGER); $statement->bindValue(":dtime", $result->{"tvaluelocal"}, SQLITE3_TEXT); $statement->bindValue(":area_type", AREA_TYPE_ID::RIFT_RAID, SQLITE3_INTEGER); $statement->bindValue(":area", AREA_TYPE_ID::RIFT_RAID, SQLITE3_INTEGER); $statement->bindValue(":stage", $start->{"battle_info"}->{"stage_id"}, SQLITE3_INTEGER); $statement->bindValue(":difficulty", null, SQLITE3_INTEGER); $statement->bindValue(":win", $result->{"win_lose"}, SQLITE3_INTEGER); if ($result->{"win_lose"} == 1){ $statement->bindValue(":time", $result->{"clear_time"}->{"current_time"}, SQLITE3_TEXT); } else{ $statement->bindValue(":time", 1, SQLITE3_INTEGER); } $statement->bindValue(":mana", 0, SQLITE3_INTEGER); // If reward is mana, i will be updated later $statement->bindValue(":energy", 0, SQLITE3_INTEGER); $statement->bindValue(":crystal", 0, SQLITE3_INTEGER); $statement->bindValue(":guild_points", 0, SQLITE3_INTEGER); $statement->bindValue(":honor_points", 0, SQLITE3_INTEGER); $statement->bindValue(":helper", 0, SQLITE3_INTEGER); $statement->bindValue(":score", null, SQLITE3_INTEGER); $statement->bindValue(":rank", null, SQLITE3_TEXT); $statement->execute(); // Parse various types of reward if ($result->{"win_lose"} == 1 && array_key_exists("battle_reward_list", $result)){ foreach ($result->{"battle_reward_list"} as $reward_list){ if ($reward_list->{"wizard_id"} == $uid){ $reward = $reward_list->{"reward_list"}[0]; $reward_type = $reward->{"item_master_type"}; switch ($reward_type){ case INVENTORY_TYPE_ID::MONSTER: // Unit $statement = $db->prepare("INSERT INTO run_drop_unit (run, unit) VALUES (:run, :unit);"); $statement->bindValue(":run", $id, SQLITE3_INTEGER); $statement->bindValue(":unit", $reward->{"item_master_id"}, SQLITE3_INTEGER); $statement->execute(); break; case INVENTORY_TYPE_ID::SCROLL: case INVENTORY_TYPE_ID::ESSENCES: $statement = $db->prepare("INSERT INTO run_drop_item (run, item, amount) VALUES (:run, :item, :amount);"); $statement->bindValue(":run", $id, SQLITE3_INTEGER); $statement->bindValue(":item", $reward->{"item_master_id"}, SQLITE3_INTEGER); $statement->bindValue(":amount", $reward->{"item_quantity"}, SQLITE3_INTEGER); $statement->execute(); break; case INVENTORY_TYPE_ID::ENCHANTMENT: $statement = $db->prepare(" INSERT INTO run_drop_enchantment (run, id, type, quality, rune, stat, value) VALUES (:run, :id, :type, :quality, :rune, :stat, :value); "); $statement->bindValue(":run", $id, SQLITE3_INTEGER); $statement->bindValue(":id", $reward->{"runecraft_item_id"}, SQLITE3_INTEGER); $statement->bindValue(":type", $reward->{"runecraft_type"}, SQLITE3_INTEGER); $statement->bindValue(":quality", $reward->{"runecraft_rank"}, SQLITE3_INTEGER); $statement->bindValue(":rune", $reward->{"runecraft_set_id"}, SQLITE3_INTEGER); $statement->bindValue(":stat", $reward->{"runecraft_effect_id"}, SQLITE3_INTEGER); $statement->bindValue(":value", 0, SQLITE3_INTEGER); $statement->execute(); break; case 102: //: Mana $statement = $db->prepare("UPDATE run SET mana = :mana WHERE run = :run;"); $statement->bindValue(":run", $id, SQLITE3_INTEGER); $statement->bindValue(":id", $reward->{"runecraft_item_id"}, SQLITE3_INTEGER); $statement->execute(); break; } } } } // Parse party foreach ($start->{"battle_info"}->{"user_list"} as $user){ if ($user->{"wizard_id"} == $uid){ foreach ($user->{"deck_list"} as $unit){ $statement = $db->prepare(" INSERT INTO run_party (run, unit, k_unit, leader, front) VALUES (:run, :unit, :k_unit, :leader, :front);" ); $statement->bindValue(":run", $id, SQLITE3_INTEGER); $statement->bindValue(":unit", $unit->{"unit_info"}->{"unit_id"}, SQLITE3_INTEGER); $statement->bindValue(":k_unit", $unit->{"unit_info"}->{"unit_master_id"}, SQLITE3_INTEGER); $statement->bindValue(":leader", $unit->{"leader"}, SQLITE3_INTEGER); if (intval($unit->{"index"}) <= 4){ $statement->bindValue(":front", 1, SQLITE3_INTEGER); } else{ $statement->bindValue(":front", 0, SQLITE3_INTEGER); } $statement->execute(); } } } // Return success return "201 Created."; } /** * Parses the JSONs relateds to a cairos run and saves the data. * * @param resource $db Database connection. * @param int $uid Player UID. * @param int $id Run ID. * @param mixed[] $json List of received JSONs. */ function log_cairos_run($db, $id, $uid, $json){ // Only the result request and response JSONs are needed: $response = $json["result_res"]; if ($json["result_req"] === null){ return ("400 Result request is required to parse Cairos runs."); } $request = $json["result_req"]; // Prepare the "run" insert. $statement = $db->prepare(" INSERT INTO run ( uid, id, dtime, area_type, area, stage, difficulty, win, time, mana, energy, crystal, guild_points, honor_points, helper, score, rank ) VALUES ( :uid, :id, :dtime, :area_type, :area, :stage, :difficulty, :win, :time, :mana, :energy, :crystal, :guild_points, :honor_points, :helper, :score, :rank ); "); // Bind data and insert $statement->bindValue(":uid", $uid, SQLITE3_INTEGER); $statement->bindValue(":id", $id, SQLITE3_INTEGER); $statement->bindValue(":dtime", $response->{"tvaluelocal"}, SQLITE3_TEXT); $statement->bindValue(":area_type", AREA_TYPE_ID::CAIROS_DUNGEON, SQLITE3_INTEGER); $statement->bindValue(":area", $request->{"dungeon_id"}, SQLITE3_INTEGER); $statement->bindValue(":stage", $request->{"stage_id"}, SQLITE3_INTEGER); $statement->bindValue(":difficulty", null, SQLITE3_INTEGER); $statement->bindValue(":win", $response->{"win_lose"}, SQLITE3_INTEGER); $statement->bindValue(":time", $response->{"clear_time"}->{"current_time"}, SQLITE3_INTEGER); if (array_key_exists("mana", $response->{"reward"})){ $statement->bindValue(":mana", $response->{"reward"}->{"mana"}, SQLITE3_INTEGER); } else{ $statement->bindValue(":mana", 0, SQLITE3_INTEGER); } if (array_key_exists("energy", $response->{"reward"})){ $statement->bindValue(":energy", $response->{"reward"}->{"energy"}, SQLITE3_INTEGER); } else{ $statement->bindValue(":energy", 0, SQLITE3_INTEGER); } if (array_key_exists("crystal", $response->{"reward"})){ $statement->bindValue(":crystal", $response->{"reward"}->{"crystal"}, SQLITE3_INTEGER); } else{ $statement->bindValue(":crystal", 0, SQLITE3_INTEGER); } $statement->bindValue(":guild_points", 0, SQLITE3_INTEGER); $statement->bindValue(":honor_points", 0, SQLITE3_INTEGER); $statement->bindValue(":helper", 0, SQLITE3_INTEGER); // TODO Where is this information?? $statement->bindValue(":score", null, SQLITE3_INTEGER); $statement->bindValue(":rank", null, SQLITE3_TEXT); $statement->execute(); // Parse various types of reward if (array_key_exists("changed_item_list", $response)){ $reward_type = $response->{"changed_item_list"}[0]->{"type"}; switch ($reward_type){ case INVENTORY_TYPE_ID::MONSTER: // Unit $statement = $db->prepare("INSERT INTO run_drop_unit (run, unit) VALUES (:run, :unit);"); $statement->bindValue(":run", $id, SQLITE3_INTEGER); $statement->bindValue(":unit", $response->{"changed_item_list"}[0]->{"view"}->{"item_master_id"}, SQLITE3_INTEGER); $statement->execute(); break; case INVENTORY_TYPE_ID::SCROLL: case INVENTORY_TYPE_ID::ESSENCES: $statement = $db->prepare("INSERT INTO run_drop_item (run, item, amount) VALUES (:run, :item, :amount);"); $statement->bindValue(":run", $id, SQLITE3_INTEGER); $statement->bindValue(":item", $response->{"changed_item_list"}[0]->{"view"}->{"item_master_id"}, SQLITE3_INTEGER); $statement->bindValue(":amount", $response->{"changed_item_list"}[0]->{"view"}->{"item_quantity"}, SQLITE3_INTEGER); $statement->execute(); break; case INVENTORY_TYPE_ID::RUNE: $rune = $response->{"changed_item_list"}[0]->{"info"}; $statement = $db->prepare(" INSERT INTO run_drop_rune ( run, id, type, slot, stars, ancient, quality, value, efficiency, max_efficiency, main_stat, main_stat_value, innate_stat, innate_stat_value, substat_1, substat_1_value, substat_2, substat_2_value, substat_3, substat_3_value, substat_4, substat_4_value ) VALUES ( :run, :id, :type, :slot, :stars, :ancient, :quality, :value, :efficiency, :max_efficiency, :main_stat, :main_stat_value, :innate_stat, :innate_stat_value, :substat_1, :substat_1_value, :substat_2, :substat_2_value, :substat_3, :substat_3_value, :substat_4, :substat_4_value ); "); $statement->bindValue(":run", $id, SQLITE3_INTEGER); $statement->bindValue(":id", $rune->{"rune_id"}, SQLITE3_INTEGER); $statement->bindValue(":type", $rune->{"set_id"}, SQLITE3_INTEGER); $statement->bindValue(":slot", $rune->{"slot_no"}, SQLITE3_INTEGER); $statement->bindValue(":value", $rune->{"sell_value"}, SQLITE3_INTEGER); if ($rune->{"class"} > 10){ // Ancient rune $statement->bindValue(":ancient", 1, SQLITE3_INTEGER); $statement->bindValue(":stars", intval($rune->{"class"}) - 10, SQLITE3_INTEGER); $statement->bindValue(":quality", intval($rune->{"rank"}) - 10, SQLITE3_INTEGER); } else{ // Non Ancient rune $statement->bindValue(":ancient", 0, SQLITE3_INTEGER); $statement->bindValue(":stars", $rune->{"class"}, SQLITE3_INTEGER); $statement->bindValue(":quality", $rune->{"rank"}, SQLITE3_INTEGER); } $efficiency = calculate_efficiency($rune); $max_efficiency = calculate_maximum_efficiency($rune); $statement->bindValue(":efficiency", $efficiency, SQLITE3_FLOAT); $statement->bindValue(":max_efficiency", $max_efficiency, SQLITE3_FLOAT); $statement->bindValue(":main_stat", $rune->{"pri_eff"}[0], SQLITE3_INTEGER); $statement->bindValue(":main_stat_value", $rune->{"pri_eff"}[1], SQLITE3_INTEGER); if ($rune->{"prefix_eff"}[0] > 0){ $statement->bindValue(":innate_stat", $rune->{"prefix_eff"}[0], SQLITE3_INTEGER); $statement->bindValue(":innate_stat_value", $rune->{"prefix_eff"}[1], SQLITE3_INTEGER); } else{ $statement->bindValue(":innate_stat", null, SQLITE3_INTEGER); $statement->bindValue(":innate_stat_value", 0, SQLITE3_INTEGER); } if (sizeof($rune->{"sec_eff"}) > 0){ $statement->bindValue(":substat_1", $rune->{"sec_eff"}[0][0], SQLITE3_INTEGER); $statement->bindValue(":substat_1_value", $rune->{"sec_eff"}[0][1], SQLITE3_INTEGER); } else{ $statement->bindValue(":substat_1", null, SQLITE3_INTEGER); $statement->bindValue(":substat_1_value", 0, SQLITE3_INTEGER); } if (sizeof($rune->{"sec_eff"}) > 1){ $statement->bindValue(":substat_2", $rune->{"sec_eff"}[1][0]); $statement->bindValue(":substat_2_value", $rune->{"sec_eff"}[1][1]); } else{ $statement->bindValue(":substat_2", null, SQLITE3_INTEGER); $statement->bindValue(":substat_2_value", 0, SQLITE3_INTEGER); } if (sizeof($rune->{"sec_eff"}) > 2){ $statement->bindValue(":substat_3", $rune->{"sec_eff"}[2][0], SQLITE3_INTEGER); $statement->bindValue(":substat_3_value", $rune->{"sec_eff"}[2][1], SQLITE3_INTEGER); } else{ $statement->bindValue(":substat_3", null, SQLITE3_INTEGER); $statement->bindValue(":substat_3_value", 0, SQLITE3_INTEGER); } if (sizeof($rune->{"sec_eff"}) > 3){ $statement->bindValue(":substat_4", $rune->{"sec_eff"}[3][0], SQLITE3_INTEGER); $statement->bindValue(":substat_4_value", $rune->{"sec_eff"}[3][1], SQLITE3_INTEGER); } else{ $statement->bindValue(":substat_4", null, SQLITE3_INTEGER); $statement->bindValue(":substat_4_value", 0, SQLITE3_INTEGER); } $statement->execute(); break; } } // Parse party $leader = 1; foreach ($response->{"unit_list"} as $unit){ $statement = $db->prepare(" INSERT INTO run_party (run, unit, k_unit, leader, front) VALUES (:run, :unit, :k_unit, :leader, :front);" ); $statement->bindValue(":run", $id, SQLITE3_INTEGER); $statement->bindValue(":unit", $unit->{"unit_id"}, SQLITE3_INTEGER); $statement->bindValue(":k_unit", $unit->{"unit_master_id"}, SQLITE3_INTEGER); $statement->bindValue(":leader", $leader, SQLITE3_INTEGER); $leader = 0; $statement->bindValue(":front", 0, SQLITE3_INTEGER); $statement->execute(); } // Return success return "201 Created."; } /** * Parses the JSONs relateds to a Dimension Hole run and saves the data. * * @param resource $db Database connection. * @param int $uid Player UID. * @param int $id Run ID. * @param mixed[] $json List of received JSONs. */ function log_dimension_hole_run($db, $id, $uid, $json){ // Only the result request and response JSONs are needed: $response = $json["result_res"]; if ($json["result_req"] === null){ return ("400 Result request is required to parse Dimension Hole runs."); } // Prepare the "run" insert. $statement = $db->prepare(" INSERT INTO run ( uid, id, dtime, area_type, area, stage, difficulty, win, time, mana, energy, crystal, guild_points, honor_points, helper, score, rank ) VALUES ( :uid, :id, :dtime, :area_type, :area, :stage, :difficulty, :win, :time, :mana, :energy, :crystal, :guild_points, :honor_points, :helper, :score, :rank ); "); // Bind data and insert $statement->bindValue(":uid", $uid, SQLITE3_INTEGER); $statement->bindValue(":id", $id, SQLITE3_INTEGER); $statement->bindValue(":dtime", $response->{"tvaluelocal"}, SQLITE3_TEXT); $statement->bindValue(":area_type", AREA_TYPE_ID::DIMENSIONAL_HOLE, SQLITE3_INTEGER); $statement->bindValue(":area", $response->{"dungeon_id"}, SQLITE3_INTEGER); $statement->bindValue(":stage", $response->{"difficulty"}, SQLITE3_INTEGER); // Difficulty is stage $statement->bindValue(":difficulty", null, SQLITE3_INTEGER); $statement->bindValue(":win", $response->{"win_lose"}, SQLITE3_INTEGER); $statement->bindValue(":time", $response->{"clear_time"}->{"current_time"}, SQLITE3_INTEGER); if (array_key_exists("mana", $response->{"reward"})){ $statement->bindValue(":mana", $response->{"reward"}->{"mana"}, SQLITE3_INTEGER); } else{ $statement->bindValue(":mana", 0, SQLITE3_INTEGER); } if (array_key_exists("energy", $response->{"reward"})){ $statement->bindValue(":energy", $response->{"reward"}->{"energy"}, SQLITE3_INTEGER); } $statement->bindValue(":energy", 0, SQLITE3_INTEGER); if (array_key_exists("crystal", $response->{"reward"})){ $statement->bindValue(":crystal", $response->{"reward"}->{"crystal"}, SQLITE3_INTEGER); } else{ $statement->bindValue(":crystal", 0, SQLITE3_INTEGER); } $statement->bindValue(":guild_points", 0, SQLITE3_INTEGER); $statement->bindValue(":honor_points", 0, SQLITE3_INTEGER); $statement->bindValue(":helper", 0, SQLITE3_INTEGER); // TODO Where is this information?? $statement->bindValue(":score", null, SQLITE3_INTEGER); $statement->bindValue(":rank", null, SQLITE3_TEXT); $statement->execute(); // Parse various types of reward if (array_key_exists("changed_item_list", $response)){ foreach ($response->{"changed_item_list"} as $drop){ $reward_type = $drop->{"type"}; switch ($reward_type){ case INVENTORY_TYPE_ID::CRAFT_STUFF: $statement = $db->prepare("INSERT INTO run_drop_item (run, item, amount) VALUES (:run, :item, :amount);"); $statement->bindValue(":run", $id, SQLITE3_INTEGER); $statement->bindValue(":item", $drop->{"view"}->{"item_master_id"}, SQLITE3_INTEGER); $statement->bindValue(":amount", $drop->{"view"}->{"item_quantity"}, SQLITE3_INTEGER); $statement->execute(); break; case INVENTORY_TYPE_ID::RUNE: // TODO: Investigate with no awaken dungeons /*$rune = $response->{"changed_item_list"}[0]->{"info"}; $statement = $db->prepare(" INSERT INTO run_drop_rune ( run, id, type, slot, stars, ancient, quality, value, efficiency, max_efficiency, main_stat, main_stat_value, innate_stat, innate_stat_value, substat_1, substat_1_value, substat_2, substat_2_value, substat_3, substat_3_value, substat_4, substat_4_value ) VALUES ( :run, :id, :type, :slot, :stars, :ancient, :quality, :value, :efficiency, :max_efficiency, :main_stat, :main_stat_value, :innate_stat, :innate_stat_value, :substat_1, :substat_1_value, :substat_2, :substat_2_value, :substat_3, :substat_3_value, :substat_4, :substat_4_value ); "); $statement->bindValue(":run", $id, SQLITE3_INTEGER); $statement->bindValue(":id", $rune->{"rune_id"}, SQLITE3_INTEGER); $statement->bindValue(":type", $rune->{"set_id"}, SQLITE3_INTEGER); $statement->bindValue(":slot", $rune->{"slot_no"}, SQLITE3_INTEGER); $statement->bindValue(":value", $rune->{"sell_value"}, SQLITE3_INTEGER); if ($rune->{"class"} > 10){ // Ancient rune $statement->bindValue(":ancient", 1, SQLITE3_INTEGER); $statement->bindValue(":stars", intval($rune->{"class"}) - 10, SQLITE3_INTEGER); $statement->bindValue(":quality", intval($rune->{"rank"}) - 10, SQLITE3_INTEGER); } else{ // Non Ancient rune $statement->bindValue(":ancient", 0, SQLITE3_INTEGER); $statement->bindValue(":stars", $rune->{"class"}, SQLITE3_INTEGER); $statement->bindValue(":quality", $rune->{"rank"}, SQLITE3_INTEGER); } $efficiency = calculate_efficiency($rune); $max_efficiency = calculate_maximum_efficiency($rune); $statement->bindValue(":efficiency", $efficiency, SQLITE3_FLOAT); $statement->bindValue(":max_efficiency", $max_efficiency, SQLITE3_FLOAT); $statement->bindValue(":main_stat", $rune->{"pri_eff"}[0], SQLITE3_INTEGER); $statement->bindValue(":main_stat_value", $rune->{"pri_eff"}[1], SQLITE3_INTEGER); if ($rune->{"prefix_eff"}[0] > 0){ $statement->bindValue(":innate_stat", $rune->{"prefix_eff"}[0], SQLITE3_INTEGER); $statement->bindValue(":innate_stat_value", $rune->{"prefix_eff"}[1], SQLITE3_INTEGER); } else{ $statement->bindValue(":innate_stat", null, SQLITE3_INTEGER); $statement->bindValue(":innate_stat_value", 0, SQLITE3_INTEGER); } if (sizeof($rune->{"sec_eff"}) > 0){ $statement->bindValue(":substat_1", $rune->{"sec_eff"}[0][0], SQLITE3_INTEGER); $statement->bindValue(":substat_1_value", $rune->{"sec_eff"}[0][1], SQLITE3_INTEGER); } else{ $statement->bindValue(":substat_1", null, SQLITE3_INTEGER); $statement->bindValue(":substat_1_value", 0, SQLITE3_INTEGER); } if (sizeof($rune->{"sec_eff"}) > 1){ $statement->bindValue(":substat_2", $rune->{"sec_eff"}[1][0], SQLITE3_INTEGER); $statement->bindValue(":substat_2_value", $rune->{"sec_eff"}[1][1], SQLITE3_INTEGER); } else{ $statement->bindValue(":substat_2", null, SQLITE3_INTEGER); $statement->bindValue(":substat_2_value", 0, SQLITE3_INTEGER); } if (sizeof($rune->{"sec_eff"}) > 2){ $statement->bindValue(":substat_3", $rune->{"sec_eff"}[2][0], SQLITE3_INTEGER); $statement->bindValue(":substat_3_value", $rune->{"sec_eff"}[2][1], SQLITE3_INTEGER); } else{ $statement->bindValue(":substat_3", null, SQLITE3_INTEGER); $statement->bindValue(":substat_3_value", 0, SQLITE3_INTEGER); } if (sizeof($rune->{"sec_eff"}) > 3){ $statement->bindValue(":substat_4", $rune->{"sec_eff"}[3][0], SQLITE3_INTEGER); $statement->bindValue(":substat_4_value", $rune->{"sec_eff"}[3][1], SQLITE3_INTEGER); } else{ $statement->bindValue(":substat_4", null, SQLITE3_INTEGER); $statement->bindValue(":substat_4_value", 0, SQLITE3_INTEGER); } $statement->execute();*/ break; } } } // Parse party $leader = 1; foreach ($response->{"unit_list"} as $unit){ $statement = $db->prepare(" INSERT INTO run_party (run, unit, k_unit, leader, front) VALUES (:run, :unit, :k_unit, :leader, :front);" ); $statement->bindValue(":run", $id, SQLITE3_INTEGER); $statement->bindValue(":unit", $unit->{"unit_id"}, SQLITE3_INTEGER); $statement->bindValue(":k_unit", $unit->{"unit_master_id"}, SQLITE3_INTEGER); $statement->bindValue(":leader", $leader, SQLITE3_INTEGER); $leader = 0; $statement->bindValue(":front", 0, SQLITE3_INTEGER); $statement->execute(); } // Return success return "201 Created."; } global $db; try{ header("Content-type: application/json; charset=utf-8"); // Get put data parse_str(file_get_contents("php://input"), $_POST); // Check API key. if (!array_key_exists("key", $_POST)){ header("HTTP/1.1 400 API key not received."); syslog(LOG_INFO, "[APIv3] HTTP/1.1 400 API key not received."); return 400; } $key = $_POST["key"]; // Get all JSON files $json = [ "start_req" => null, "start_res" => null, "result_req" => null, "result_res" => null, ]; // Result response - mandatory if (!array_key_exists("result_response", $_POST)){ header("HTTP/1.1 400 No result response data received."); syslog(LOG_INFO, "[APIv3] HTTP/1.1 400 No result response data received."); return 400; } $data_json = json_decode($_POST["result_response"]); if ($data_json === null){ header("HTTP/1.1 400 Result response data is no valid JSON."); syslog(LOG_INFO, "[APIv3] HTTP/1.1 400 Result response data is no valid JSON."); return 400; } $json["result_res"] = $data_json; // Result request - optional if (array_key_exists("result_request", $_POST)){ $data_raw = $_POST["result_request"]; if ($data_raw != null && $data_raw != false){ $data_json = json_decode($data_raw); if ($data_json != null){ $json["result_req"] = $data_json; } } } // Start result - optional if (array_key_exists("start_response", $_POST)){ $data_raw = $_POST["start_response"]; if ($data_raw != null && $data_raw != false){ $data_json = json_decode($data_raw); if ($data_json != null){ $json["start_res"] = $data_json; } } } // Start result - optional if (array_key_exists("start_request", $_POST)){ $data_raw = $_POST["start_request"]; if ($data_raw != null && $data_raw != false){ $data_json = json_decode($data_raw); if ($data_json != null){ $json["start_req"] = $data_json; } } } // Extract basic data $uid = $json["result_res"]->{"wizard_info"}->{"wizard_id"}; $command = $json["result_res"]->{"command"}; // Authenticate $statement = $db->prepare("SELECT COUNT(uid) AS c FROM player WHERE uid = :uid AND api_key = :api_key;"); $statement->bindValue(":uid", $uid, SQLITE3_INTEGER); $statement->bindValue(":api_key", $key, SQLITE3_TEXT); if (1 != $statement->execute()->fetchArray(SQLITE3_ASSOC)["c"]){ header("HTTP/1.1 401 Invalid credentials."); syslog(LOG_INFO, "[APIv3] HTTP/1.1 401 Invalid credentials."); return 401; } // Check for implemented command $accepted_commands = [ "BattleDungeonResult_V2", // Dungeon Run "BattleDimensionHoleDungeonResult_v2", // Dimension Hole Run "BattleRiftOfWorldsRaidResult", // Rift Raid Run "BattleScenarioResult", // Scenario Run "BattleArenaResult", // Arena Run "BattleDarkPortalResult" // Dimensinal Rift Run ]; if (!in_array($command, $accepted_commands)){ header("HTTP/1.1 405 Command not implemented."); syslog(LOG_INFO, "[APIv3] HTTP/1.1 405 Command not implemented."); return 405; } // Check if already in DB $dtime = $json["result_res"]->{"tvaluelocal"}; $statement = $db->prepare("SELECT count(id) AS c FROM run WHERE uid = :uid AND dtime = :dtime;"); $statement->bindValue(":uid", $uid, SQLITE3_INTEGER); $statement->bindValue(":dtime", $dtime, SQLITE3_TEXT); if (0 != $statement->execute()->fetchArray(SQLITE3_ASSOC)["c"]){ header("HTTP/1.1 409 Run already in database."); syslog(LOG_INFO, "[APIv3] HTTP/1.1 409 Run already in database."); return 409; } // Get new ID $q = $db->query("SELECT max(id) + 1 AS id FROM run;"); $r = $q->fetchArray(SQLITE3_ASSOC); if ($r){ $id = $r["id"]; } else{ $id = 1; } // Run parsing function $result = "500 Unknown Error"; switch($command){ case "BattleDungeonResult_V2": $result = log_cairos_run($db, $id, $uid, $json); break; case "BattleDimensionHoleDungeonResult_v2": $result = log_dimension_hole_run($db, $id, $uid, $json); break; case "BattleRiftOfWorldsRaidResult": $result = log_rift_raid_run($db, $id, $uid, $json); break; case "BattleScenarioResult": $result = log_scenario_run($db, $id, $uid, $json); break; case "BattleArenaResult": $result = log_arena_run($db, $id, $uid, $json); break; case "BattleDarkPortalResult": $result = log_dark_portal_run($db, $id, $uid, $json); break; } // Process result $status_code = intval(substr($result, 0, 3)); $status_message = substr($result, 4); if ($status_code == 0 || $status_code < 100 || $status_code > 599){ header("HTTP/1.1 500 Unknown error."); syslog(LOG_ERR, "[APIv3] HTTP/1.1 500 Unknown error."); return 500; } else{ header("HTTP/1.1 $status_code $status_message"); syslog(LOG_INFO, "[APIv3] HTTP/1.1 $status_code $status_message"); return $status_code; } } catch(Exception $e) { header("HTTP/1.1 500 Unexpeced error: " . $e->getMessage()); syslog(LOG_ERR, "[APIv3] HTTP/1.1 500 Unexpected error: " . $e->getMessage()); return 500; } ?>