|
@@ -521,54 +521,20 @@
|
|
|
$statement->execute();
|
|
$statement->execute();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- try{
|
|
|
|
|
-
|
|
|
|
|
- header("Content-type: application/json; charset=utf-8");
|
|
|
|
|
-
|
|
|
|
|
- // Get put data
|
|
|
|
|
- parse_str(file_get_contents("php://input"), $_PUT);
|
|
|
|
|
-
|
|
|
|
|
- // Check API key.
|
|
|
|
|
- $key = $_PUT["key"];
|
|
|
|
|
- if ($key == null || $key == false){
|
|
|
|
|
- header("HTTP/1.1 400 API key not received.");
|
|
|
|
|
- syslog(LOG_INFO, "[APIv3] HTTP/1.1 400 API key not received.");
|
|
|
|
|
- return 400;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Check data
|
|
|
|
|
- $data = $_PUT["response"];
|
|
|
|
|
- if ($data == null || $data == false){
|
|
|
|
|
- header("HTTP/1.1 400 No data received.");
|
|
|
|
|
- syslog(LOG_INFO, "[APIv3] HTTP/1.1 400 No data received.");
|
|
|
|
|
- return 400;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Check data format.
|
|
|
|
|
- $json = json_decode($data);
|
|
|
|
|
- if ($json === null){
|
|
|
|
|
- header("HTTP/1.1 400 Data is no valid JSON.");
|
|
|
|
|
- syslog(LOG_INFO, "[APIv3] HTTP/1.1 400 Data is no valid JSON.");
|
|
|
|
|
- return 400;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Authenticate
|
|
|
|
|
- $uid = $json->{"wizard_id"};
|
|
|
|
|
- $uname = $json->{"wizard_info"}->{"wizard_name"};
|
|
|
|
|
- $statement = $db->prepare("SELECT COUNT(uid) AS c FROM player WHERE uid = :uid AND api_key = :api_key;");
|
|
|
|
|
- $statement->bindValue(":uid", $uid);
|
|
|
|
|
- $statement->bindValue(":api_key", $key);
|
|
|
|
|
- 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;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Parses the response to the HubUserLogin command and updates profile.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param SQLiteConn $db Database connection.
|
|
|
|
|
+ * @param int $uid Player UID.
|
|
|
|
|
+ * @param JSON $json Response.
|
|
|
|
|
+ */
|
|
|
|
|
+ function parse_profile($db, $uid, $json){
|
|
|
// Save data file
|
|
// Save data file
|
|
|
|
|
+ $uname = $json->{"wizard_info"}->{"wizard_name"};
|
|
|
$dtime = (new DateTime())->format("Y-m-dTH:i:s");
|
|
$dtime = (new DateTime())->format("Y-m-dTH:i:s");
|
|
|
$fname = ($_SERVER["DOCUMENT_ROOT"] . "/../data/profile_" . $uid . "_" . $uname . "_" . $dtime . ".json");
|
|
$fname = ($_SERVER["DOCUMENT_ROOT"] . "/../data/profile_" . $uid . "_" . $uname . "_" . $dtime . ".json");
|
|
|
try{
|
|
try{
|
|
|
- file_put_contents($fname, $data);
|
|
|
|
|
|
|
+ file_put_contents($fname, json_encode($json));
|
|
|
}
|
|
}
|
|
|
catch(Exception $e) {
|
|
catch(Exception $e) {
|
|
|
header("HTTP/1.1 500 Unable to save profile file: " . $e->getMessage());
|
|
header("HTTP/1.1 500 Unable to save profile file: " . $e->getMessage());
|
|
@@ -1182,11 +1148,511 @@
|
|
|
SELECT DISTINCT id FROM team
|
|
SELECT DISTINCT id FROM team
|
|
|
);"
|
|
);"
|
|
|
);
|
|
);
|
|
|
|
|
+ // Return success
|
|
|
|
|
+ return "201 Created.";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Parses the response to the GetUnitCollection command and updates the
|
|
|
|
|
+ * user monster collection status.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param SQLiteConn $db Database connection.
|
|
|
|
|
+ * @param int $uid Player UID.
|
|
|
|
|
+ * @param JSON $json Response.
|
|
|
|
|
+ */
|
|
|
|
|
+ function parse_collection($db, $uid, $json){
|
|
|
|
|
+ // Clear previous collection data
|
|
|
|
|
+ $db->query("PRAGMA foreign_keys = OFF;");
|
|
|
|
|
+ $statement = $db->prepare("DELETE FROM collection WHERE uid = :uid;");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+ foreach ($json->{"collection"} as $unit){
|
|
|
|
|
+ $statement = $db->prepare("
|
|
|
|
|
+ INSERT INTO collection (uid, unit, open)
|
|
|
|
|
+ VALUES (:uid, :unit, :open);
|
|
|
|
|
+ ");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":unit", $unit->{"unit_master_id"});
|
|
|
|
|
+ $statement->bindValue(":open", $unit->{"open"});
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+ }
|
|
|
|
|
+ // Return success
|
|
|
|
|
+ return "201 Created.";
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // At this point, status code should be 200
|
|
|
|
|
- header("HTTP/1.1 204 Profile imported.");
|
|
|
|
|
- syslog(LOG_INFO, "[APIv3] HTTP/1.1 204 Profile imported.");
|
|
|
|
|
- return 204;
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Parses the response to the GetLobbyWizardLog command and updates the
|
|
|
|
|
+ * user records.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param SQLiteConn $db Database connection.
|
|
|
|
|
+ * @param int $uid Player UID.
|
|
|
|
|
+ * @param JSON $json Response.
|
|
|
|
|
+ */
|
|
|
|
|
+ function parse_records($db, $uid, $json){
|
|
|
|
|
+
|
|
|
|
|
+ # Page 1: Cairos non-elemental, rift raid, rift dungeon.
|
|
|
|
|
+ if (intval($json->{"lobby_wizard_log"}->{"page_no"}) == 1){
|
|
|
|
|
+
|
|
|
|
|
+ // Update data in player table
|
|
|
|
|
+ $db->query("PRAGMA foreign_keys = OFF;");
|
|
|
|
|
+ $statement = $db->prepare("
|
|
|
|
|
+ UPDATE player SET
|
|
|
|
|
+ joined = :joined,
|
|
|
|
|
+ top_rank_arena = :top_rank_arena,
|
|
|
|
|
+ top_rank_world_arena = :top_rank_world_arena,
|
|
|
|
|
+ top_rank_special_league = :top_rank_special_league,
|
|
|
|
|
+ top_rank_gw = :top_rank_gw,
|
|
|
|
|
+ top_rank_siege = :top_rank_siege,
|
|
|
|
|
+ top_rank_wboss = :top_rank_wboss,
|
|
|
|
|
+ top_rank_toan = :top_rank_toan,
|
|
|
|
|
+ top_rank_toah = :top_rank_toah
|
|
|
|
|
+ WHERE uid = :uid;
|
|
|
|
|
+ ");
|
|
|
|
|
+ $statement->bindValue(":joined", $json->{"lobby_wizard_log"}->{"account_create_timestamp"});
|
|
|
|
|
+ $statement->bindValue(":top_rank_arena", $json->{"lobby_wizard_log"}->{"pvp_best_rating_id"});
|
|
|
|
|
+ $statement->bindValue(":top_rank_world_arena", $json->{"lobby_wizard_log"}->{"rtpvp_rank_best_rating_id"});
|
|
|
|
|
+ $statement->bindValue(":top_rank_special_league", $json->{"lobby_wizard_log"}->{"rtpvp_contest_best_rating_id"});
|
|
|
|
|
+ $statement->bindValue(":top_rank_gw", $json->{"lobby_wizard_log"}->{"guildwar_best_rating_id"});
|
|
|
|
|
+ $statement->bindValue(":top_rank_siege", $json->{"lobby_wizard_log"}->{"guildsiege_best_rating_id"});
|
|
|
|
|
+ $statement->bindValue(":top_rank_wboss", $json->{"lobby_wizard_log"}->{"world_boss_best_rank_id"});
|
|
|
|
|
+ $statement->bindValue(":top_rank_toan", $json->{"lobby_wizard_log"}->{"trial_tower_normal_best_floor"});
|
|
|
|
|
+ $statement->bindValue(":top_rank_toah", $json->{"lobby_wizard_log"}->{"trial_tower_hard_best_floor"});
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+
|
|
|
|
|
+ // Loop Cairos records
|
|
|
|
|
+ foreach ($json->{"lobby_wizard_log"}->{"dungeon_best_clear_info_list"} as $record){
|
|
|
|
|
+ // Delete prevous data
|
|
|
|
|
+ $statement = $db->prepare("
|
|
|
|
|
+ DELETE FROM record_party
|
|
|
|
|
+ WHERE
|
|
|
|
|
+ uid = :uid AND
|
|
|
|
|
+ area_type = :area_type AND
|
|
|
|
|
+ area = :area;
|
|
|
|
|
+ ");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":area_type", AREA_TYPE_ID::CAIROS_DUNGEON);
|
|
|
|
|
+ $statement->bindValue(":area", $record->{"dungeon_id"});
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+ $statement = $db->prepare("
|
|
|
|
|
+ DELETE FROM record
|
|
|
|
|
+ WHERE
|
|
|
|
|
+ uid = :uid AND
|
|
|
|
|
+ area_type = :area_type AND
|
|
|
|
|
+ area = :area;
|
|
|
|
|
+ ");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":area_type", AREA_TYPE_ID::CAIROS_DUNGEON);
|
|
|
|
|
+ $statement->bindValue(":area", $record->{"dungeon_id"});
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+
|
|
|
|
|
+ // Insert new data
|
|
|
|
|
+ $statement = $db->prepare("
|
|
|
|
|
+ INSERT INTO record
|
|
|
|
|
+ (uid, area_type, area, stage, time, score, rank)
|
|
|
|
|
+ VALUES
|
|
|
|
|
+ (:uid, :area_type, :area, :stage, :time, :score, :rank);
|
|
|
|
|
+ ");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":area_type", AREA_TYPE_ID::CAIROS_DUNGEON);
|
|
|
|
|
+ $statement->bindValue(":area", $record->{"dungeon_id"});
|
|
|
|
|
+ $statement->bindValue(":area", $record->{"dungeon_id"});
|
|
|
|
|
+ $statement->bindValue(":stage", $record->{"stage_id"});
|
|
|
|
|
+ $statement->bindValue(":time", $record->{"clear_time"});
|
|
|
|
|
+ $statement->bindValue(":score", 0);
|
|
|
|
|
+ $statement->bindValue(":rank", null);
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+
|
|
|
|
|
+ // Loop party
|
|
|
|
|
+ foreach ($record->{"my_unit_deck_list"} as $party){
|
|
|
|
|
+ $statement = $db->prepare("
|
|
|
|
|
+ INSERT INTO record_party
|
|
|
|
|
+ (uid, area_type, area, unit, k_unit, leader, front)
|
|
|
|
|
+ VALUES
|
|
|
|
|
+ (:uid, :area_type, :area, :unit, :k_unit, :leader, :front);
|
|
|
|
|
+ ");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":area_type", AREA_TYPE_ID::CAIROS_DUNGEON);
|
|
|
|
|
+ $statement->bindValue(":area", $record->{"dungeon_id"});
|
|
|
|
|
+ $statement->bindValue(":unit", $party->{"unit_id"});
|
|
|
|
|
+ $statement->bindValue(":k_unit", $party->{"unit_master_id"});
|
|
|
|
|
+ $statement->bindValue(":leader", $party->{"leader"});
|
|
|
|
|
+ $statement->bindValue(":front", 0);
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Rift Raid record
|
|
|
|
|
+ if (sizeof($json->{"lobby_wizard_log"}->{"raid_best_clear_info_list"}) > 0){
|
|
|
|
|
+ $record = $json->{"lobby_wizard_log"}->{"raid_best_clear_info_list"}[0];
|
|
|
|
|
+
|
|
|
|
|
+ // Delete prevous data
|
|
|
|
|
+ $statement = $db->prepare("
|
|
|
|
|
+ DELETE FROM record_party
|
|
|
|
|
+ WHERE
|
|
|
|
|
+ uid = :uid AND
|
|
|
|
|
+ area_type = :area_type AND
|
|
|
|
|
+ area = :area;
|
|
|
|
|
+ ");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":area_type", AREA_TYPE_ID::RIFT_RAID);
|
|
|
|
|
+ $statement->bindValue(":area", $record->{"stage_id"});
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+ $statement = $db->prepare("
|
|
|
|
|
+ DELETE FROM record
|
|
|
|
|
+ WHERE
|
|
|
|
|
+ uid = :uid AND
|
|
|
|
|
+ area_type = :area_type AND
|
|
|
|
|
+ area = :area;
|
|
|
|
|
+ ");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":area_type", AREA_TYPE_ID::RIFT_RAID);
|
|
|
|
|
+ $statement->bindValue(":area", $record->{"stage_id"});
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+
|
|
|
|
|
+ // Insert new data
|
|
|
|
|
+ $statement = $db->prepare("
|
|
|
|
|
+ INSERT INTO record
|
|
|
|
|
+ (uid, area_type, area, stage, time, score, rank)
|
|
|
|
|
+ VALUES
|
|
|
|
|
+ (:uid, :area_type, :area, :stage, :time, :score, :rank);
|
|
|
|
|
+ ");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":area_type", AREA_TYPE_ID::RIFT_RAID);
|
|
|
|
|
+ $statement->bindValue(":area", $record->{"stage_id"});
|
|
|
|
|
+ $statement->bindValue(":stage", $record->{"stage_id"});
|
|
|
|
|
+ $statement->bindValue(":time", $record->{"clear_time"});
|
|
|
|
|
+ $statement->bindValue(":score", 0);
|
|
|
|
|
+ $statement->bindValue(":rank", null);
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+
|
|
|
|
|
+ // Loop party
|
|
|
|
|
+ foreach ($record->{"my_unit_deck_list"} as $party){
|
|
|
|
|
+ $statement = $db->prepare("
|
|
|
|
|
+ INSERT INTO record_party
|
|
|
|
|
+ (uid, area_type, area, unit, k_unit, leader, front)
|
|
|
|
|
+ VALUES
|
|
|
|
|
+ (:uid, :area_type, :area, :unit, :k_unit, :leader, :front);
|
|
|
|
|
+ ");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":area_type", AREA_TYPE_ID::RIFT_RAID);
|
|
|
|
|
+ $statement->bindValue(":area", $record->{"stage_id"});
|
|
|
|
|
+ $statement->bindValue(":unit", $party->{"unit_id"});
|
|
|
|
|
+ $statement->bindValue(":k_unit", $party->{"unit_master_id"});
|
|
|
|
|
+ $statement->bindValue(":leader", $party->{"leader"});
|
|
|
|
|
+ if ($party->{"slot_index"} <= 4){
|
|
|
|
|
+ $statement->bindValue(":front", 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ $statement->bindValue(":front", 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Loop Rift Dungeon records
|
|
|
|
|
+ foreach ( $json->{"lobby_wizard_log"}->{"rift_dungeon_best_clear_info_list"} as $record){
|
|
|
|
|
+
|
|
|
|
|
+ // Delete prevous data
|
|
|
|
|
+ $statement = $db->prepare("
|
|
|
|
|
+ DELETE FROM record_party
|
|
|
|
|
+ WHERE
|
|
|
|
|
+ uid = :uid AND
|
|
|
|
|
+ area_type = :area_type AND
|
|
|
|
|
+ area = :area;
|
|
|
|
|
+ ");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":area_type", AREA_TYPE_ID::RIFT_DUNGEON);
|
|
|
|
|
+ $statement->bindValue(":area", $record->{"rift_dungeon_id"});
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+ $statement = $db->prepare("
|
|
|
|
|
+ DELETE FROM record
|
|
|
|
|
+ WHERE
|
|
|
|
|
+ uid = :uid AND
|
|
|
|
|
+ area_type = :area_type AND
|
|
|
|
|
+ area = :area;
|
|
|
|
|
+ ");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":area_type", AREA_TYPE_ID::RIFT_DUNGEON);
|
|
|
|
|
+ $statement->bindValue(":area", $record->{"rift_dungeon_id"});
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+
|
|
|
|
|
+ // Insert new data
|
|
|
|
|
+ $statement = $db->prepare("
|
|
|
|
|
+ INSERT INTO record
|
|
|
|
|
+ (uid, area_type, area, stage, time, score, rank)
|
|
|
|
|
+ VALUES
|
|
|
|
|
+ (:uid, :area_type, :area, :stage, :time, :score, :rank);
|
|
|
|
|
+ ");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":area_type", AREA_TYPE_ID::RIFT_DUNGEON);
|
|
|
|
|
+ $statement->bindValue(":area", $record->{"rift_dungeon_id"});
|
|
|
|
|
+ $statement->bindValue(":stage", 0);
|
|
|
|
|
+ $statement->bindValue(":time", 0);
|
|
|
|
|
+ $statement->bindValue(":score", $record->{"clear_damage"});
|
|
|
|
|
+ switch (intval($record->{"clear_rating"})){
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ $statement->bindValue(":rank", "D");
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 3:
|
|
|
|
|
+ $statement->bindValue(":rank", "C");
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 4:
|
|
|
|
|
+ $statement->bindValue(":rank", "B-");
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 5:
|
|
|
|
|
+ $statement->bindValue(":rank", "B");
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 6:
|
|
|
|
|
+ $statement->bindValue(":rank", "B+");
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 7:
|
|
|
|
|
+ $statement->bindValue(":rank", "A-");
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 8:
|
|
|
|
|
+ $statement->bindValue(":rank", "A");
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 9:
|
|
|
|
|
+ $statement->bindValue(":rank", "A+");
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 10:
|
|
|
|
|
+ $statement->bindValue(":rank", "S");
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 11:
|
|
|
|
|
+ $statement->bindValue(":rank", "SS");
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 12:
|
|
|
|
|
+ $statement->bindValue(":rank", "SS");
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ $statement->bindValue(":rank", "F");
|
|
|
|
|
+ }
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+
|
|
|
|
|
+ // Loop party
|
|
|
|
|
+ foreach ($record->{"my_unit_deck_list"} as $party){
|
|
|
|
|
+ $statement = $db->prepare("
|
|
|
|
|
+ INSERT INTO record_party
|
|
|
|
|
+ (uid, area_type, area, unit, k_unit, leader, front)
|
|
|
|
|
+ VALUES
|
|
|
|
|
+ (:uid, :area_type, :area, :unit, :k_unit, :leader, :front);
|
|
|
|
|
+ ");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":area_type", AREA_TYPE_ID::RIFT_DUNGEON);
|
|
|
|
|
+ $statement->bindValue(":area", $record->{"rift_dungeon_id"});
|
|
|
|
|
+ $statement->bindValue(":unit", $party->{"unit_id"});
|
|
|
|
|
+ $statement->bindValue(":k_unit", $party->{"unit_master_id"});
|
|
|
|
|
+ $statement->bindValue(":leader", $party->{"leader"});
|
|
|
|
|
+ if ($party->{"slot_index"} <= 4){
|
|
|
|
|
+ $statement->bindValue(":front", 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ $statement->bindValue(":front", 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ # Page 2: Cairos non-elemental, rift raid, rift dungeon.
|
|
|
|
|
+ elseif (intval($json->{"lobby_wizard_log"}->{"page_no"} == 2)){
|
|
|
|
|
+ // Loop Cairos records
|
|
|
|
|
+ foreach ($json->{"lobby_wizard_log"}->{"dungeon_best_clear_info_list"} as $record){
|
|
|
|
|
+ // Delete prevous data
|
|
|
|
|
+ $statement = $db->prepare("
|
|
|
|
|
+ DELETE FROM record_party
|
|
|
|
|
+ WHERE
|
|
|
|
|
+ uid = :uid AND
|
|
|
|
|
+ area_type = :area_type AND
|
|
|
|
|
+ area = :area;
|
|
|
|
|
+ ");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":area_type", AREA_TYPE_ID::CAIROS_DUNGEON);
|
|
|
|
|
+ $statement->bindValue(":area", $record->{"dungeon_id"});
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+ $statement = $db->prepare("
|
|
|
|
|
+ DELETE FROM record
|
|
|
|
|
+ WHERE
|
|
|
|
|
+ uid = :uid AND
|
|
|
|
|
+ area_type = :area_type AND
|
|
|
|
|
+ area = :area;
|
|
|
|
|
+ ");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":area_type", AREA_TYPE_ID::CAIROS_DUNGEON);
|
|
|
|
|
+ $statement->bindValue(":area", $record->{"dungeon_id"});
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+
|
|
|
|
|
+ // Insert new data
|
|
|
|
|
+ $statement = $db->prepare("
|
|
|
|
|
+ INSERT INTO record
|
|
|
|
|
+ (uid, area_type, area, stage, time, score, rank)
|
|
|
|
|
+ VALUES
|
|
|
|
|
+ (:uid, :area_type, :area, :stage, :time, :score, :rank);
|
|
|
|
|
+ ");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":area_type", AREA_TYPE_ID::CAIROS_DUNGEON);
|
|
|
|
|
+ $statement->bindValue(":area", $record->{"dungeon_id"});
|
|
|
|
|
+ $statement->bindValue(":area", $record->{"dungeon_id"});
|
|
|
|
|
+ $statement->bindValue(":stage", $record->{"stage_id"});
|
|
|
|
|
+ $statement->bindValue(":time", $record->{"clear_time"});
|
|
|
|
|
+ $statement->bindValue(":score", 0);
|
|
|
|
|
+ $statement->bindValue(":rank", null);
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+
|
|
|
|
|
+ // Loop party
|
|
|
|
|
+ foreach ($record->{"my_unit_deck_list"} as $party){
|
|
|
|
|
+ $statement = $db->prepare("
|
|
|
|
|
+ INSERT INTO record_party
|
|
|
|
|
+ (uid, area_type, area, unit, k_unit, leader, front)
|
|
|
|
|
+ VALUES
|
|
|
|
|
+ (:uid, :area_type, :area, :unit, :k_unit, :leader, :front);
|
|
|
|
|
+ ");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":area_type", AREA_TYPE_ID::CAIROS_DUNGEON);
|
|
|
|
|
+ $statement->bindValue(":area", $record->{"dungeon_id"});
|
|
|
|
|
+ $statement->bindValue(":unit", $party->{"unit_id"});
|
|
|
|
|
+ $statement->bindValue(":k_unit", $party->{"unit_master_id"});
|
|
|
|
|
+ $statement->bindValue(":leader", $party->{"leader"});
|
|
|
|
|
+ $statement->bindValue(":front", 0);
|
|
|
|
|
+ $statement->execute();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ elseif (intval($json->{"lobby_wizard_log"}->{"page_no"}) == 3){
|
|
|
|
|
+ return "204 Page not logged (only pages 1 and 2 are needed).";
|
|
|
|
|
+ }
|
|
|
|
|
+ elseif (intval($json->{"lobby_wizard_log"}->{"page_no"}) == 4){
|
|
|
|
|
+ return "204 Page not logged (only pages 1 and 2 are needed).";
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ return "400 Unknown page.";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Return success
|
|
|
|
|
+ return "201 Created.";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try{
|
|
|
|
|
+
|
|
|
|
|
+ header("Content-type: application/json; charset=utf-8");
|
|
|
|
|
+
|
|
|
|
|
+ // Get put data
|
|
|
|
|
+ parse_str(file_get_contents("php://input"), $_PUT);
|
|
|
|
|
+
|
|
|
|
|
+ // Check API key.
|
|
|
|
|
+ $key = $_PUT["key"];
|
|
|
|
|
+ if ($key == null || $key == false){
|
|
|
|
|
+ header("HTTP/1.1 400 API key not received.");
|
|
|
|
|
+ syslog(LOG_INFO, "[APIv3] HTTP/1.1 400 API key not received.");
|
|
|
|
|
+ return 400;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Check data
|
|
|
|
|
+ $data = $_PUT["response"];
|
|
|
|
|
+ if ($data == null || $data == false){
|
|
|
|
|
+ header("HTTP/1.1 400 No data received.");
|
|
|
|
|
+ syslog(LOG_INFO, "[APIv3] HTTP/1.1 400 No data received.");
|
|
|
|
|
+ return 400;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Check data format.
|
|
|
|
|
+ $json = json_decode($data);
|
|
|
|
|
+ if ($json === null){
|
|
|
|
|
+ header("HTTP/1.1 400 Data is no valid JSON.");
|
|
|
|
|
+ syslog(LOG_INFO, "[APIv3] HTTP/1.1 400 Data is no valid JSON.");
|
|
|
|
|
+ return 400;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Get and validate command
|
|
|
|
|
+ $command = $json->{"command"};
|
|
|
|
|
+ $accepted_commands = [
|
|
|
|
|
+ "HubUserLogin", // Login, full profile
|
|
|
|
|
+ "GetUnitCollection", // Unit collection
|
|
|
|
|
+ "GetLobbyWizardLog" // Records
|
|
|
|
|
+ ];
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Get user info and Authenticate
|
|
|
|
|
+ switch ($command){
|
|
|
|
|
+ case "HubUserLogin":
|
|
|
|
|
+ $uid = $json->{"wizard_id"};
|
|
|
|
|
+ $statement = $db->prepare("SELECT COUNT(uid) AS c FROM player WHERE uid = :uid AND api_key = :api_key;");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":api_key", $key);
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "GetUnitCollection":
|
|
|
|
|
+ // No identification in this JSON, get uid from databases
|
|
|
|
|
+ $statement = $db->prepare("SELECT uid FROM player WHERE api_key = :api_key;");
|
|
|
|
|
+ $statement->bindValue(":api_key", $key);
|
|
|
|
|
+ $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
|
|
|
|
|
+ if ($r){
|
|
|
|
|
+ $uid = $r["uid"];
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ header("HTTP/1.1 401 Invalid credentials.");
|
|
|
|
|
+ syslog(LOG_INFO, "[APIv3] HTTP/1.1 401 Invalid credentials.");
|
|
|
|
|
+ return 401;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "GetLobbyWizardLog":
|
|
|
|
|
+ $uid = $json->{"lobby_wizard_log"}->{"wizard_id"};
|
|
|
|
|
+ $statement = $db->prepare("SELECT COUNT(uid) AS c FROM player WHERE uid = :uid AND api_key = :api_key;");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":api_key", $key);
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($command == "GetUnitCollection"){ // This command doesnt provide wizard_id
|
|
|
|
|
+ $statement = $db->prepare("SELECT COUNT(uid) AS c FROM player WHERE uid = :uid AND api_key = :api_key;");
|
|
|
|
|
+ $statement->bindValue(":uid", $uid);
|
|
|
|
|
+ $statement->bindValue(":api_key", $key);
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Run parser
|
|
|
|
|
+ $result = "500 Unknown Error";
|
|
|
|
|
+ switch($command){
|
|
|
|
|
+ case "HubUserLogin":
|
|
|
|
|
+ $result = parse_profile($db, $uid, $json);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "GetUnitCollection":
|
|
|
|
|
+ $result = parse_collection($db, $uid, $json);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "GetLobbyWizardLog":
|
|
|
|
|
+ $result = parse_records($db, $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) {
|
|
catch(Exception $e) {
|
|
|
header("HTTP/1.1 500 Unexpeced error: " . $e->getMessage());
|
|
header("HTTP/1.1 500 Unexpeced error: " . $e->getMessage());
|