| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474 |
- <?php
- /**
- * Run logger script.
- *
- * Exposes an API to log a run.
- *
- * Mandatory PUT parameters are:
- * - result_response: JSON received from game server on run end.
- * - key: User API key.
- *
- * Optional POST parameters are:
- * - result_request: JSON sent to game server on run end.
- * - start_response: JSON received from game server on run start.
- * - start_request: JSON sent to game server on run start.
- *
- * @category API
- */
- /**
- * Calculates the currrent efficiency of a rune.
- *
- * @param JSON $rune JSON fragment of the rune.
- * @return int Efficiency (0-100)
- */
- function calculate_efficiency($rune){
- $efficiency = 0.0;
- $max_efficiency = 0.0;
- $substats = [];
- $level = $rune->{"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 JSON $rune JSON fragment of the rune.
- * @return int Maximum efficiency (0-100)
- */
- function calculate_maximum_efficiency($rune){
- $efficiency = 0.0;
- $max_efficiency = 0.0;
- $substats = [];
- $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 SQLiteConn $db Database connection.
- * @param int $uid Player UID.
- * @param int $id Run ID.
- * @param JSON[] $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);
- $statement->bindValue(":id", $id);
- $statement->bindValue(":dtime", $response->{"tvaluelocal"});
- $statement->bindValue(":area_type", AREA_TYPE_ID::ARENA);
- $statement->bindValue(":area", AREA_TYPE_ID::ARENA);
- $statement->bindValue(":stage", null);
- $statement->bindValue(":difficulty", null);
- $statement->bindValue(":win", $response->{"win_lose"});
- $statement->bindValue(":time", 1);
- if (array_key_exists("mana", $response->{"reward"})){
- $statement->bindValue(":mana", $response->{"reward"}->{"mana"});
- }
- else{
- $statement->bindValue(":mana", 0);
- }
- 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"});
- }
- else{
- $statement->bindValue(":crystal", 0);
- }
- $statement->bindValue(":guild_points", 0);
- if (array_key_exists("honor_point", $response->{"reward"})){
- $statement->bindValue(":honor_points", $response->{"reward"}->{"honor_point"});
- }
- else{
- $statement->bindValue(":honor_points", 0);
- }
- $statement->bindValue(":helper", 0);
- $statement->bindValue(":score", null);
- $statement->bindValue(":rank", null);
- $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);
- $statement->bindValue(":unit", $unit->{"unit_id"});
- $statement->bindValue(":k_unit", $unit->{"unit_master_id"});
- $statement->bindValue(":leader", $leader);
- $leader = 0;
- $statement->bindValue(":front", 0);
- $statement->execute();
- }
- // Return success
- return "201 Created.";
- }
- /**
- * Parses the JSONs relateds to a Dimensional Rift run and saves the data.
- *
- * @param SQLiteConn $db Database connection.
- * @param int $uid Player UID.
- * @param int $id Run ID.
- * @param JSON[] $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);
- $statement->bindValue(":id", $id);
- $statement->bindValue(":dtime", $response->{"tvaluelocal"});
- $statement->bindValue(":area_type", AREA_TYPE_ID::DIMENSIONAL_RIFT);
- // The area is the region the portal is open in.
- $statement->bindValue(":area", $response->{"region_id"});
- $statement->bindValue(":stage", null);
- $statement->bindValue(":difficulty", $response->{"difficulty"});
- $statement->bindValue(":win", $response->{"win_lose"});
- $statement->bindValue(":time", 1);
- if (array_key_exists("mana", $response->{"reward"})){
- $statement->bindValue(":mana", $response->{"reward"}->{"mana"});
- }
- else{
- $statement->bindValue(":mana", 0);
- }
- 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"});
- }
- else{
- $statement->bindValue(":crystal", 0);
- }
- $statement->bindValue(":guild_points", 0);
- $statement->bindValue(":honor_points", 0);
- $statement->bindValue(":helper", 0);
- $statement->bindValue(":score", null);
- $statement->bindValue(":rank", null);
- $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);
- $statement->bindValue(":unit", $unit->{"unit_id"});
- $statement->bindValue(":k_unit", $unit->{"unit_master_id"});
- $statement->bindValue(":leader", $leader);
- $leader = 0;
- $statement->bindValue(":front", 0);
- $statement->execute();
- }
- // Return success
- return "201 Created.";
- }
- /**
- * Parses the JSONs relateds to a scenario run and saves the data.
- *
- * @param SQLiteConn $db Database connection.
- * @param int $uid Player UID.
- * @param int $id Run ID.
- * @param JSON[] $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);
- $statement->bindValue(":id", $id);
- $statement->bindValue(":dtime", $response->{"tvaluelocal"});
- $statement->bindValue(":area_type", AREA_TYPE_ID::SCENARIO);
- $statement->bindValue(":area", $response->{"scenario_info"}->{"region_id"});
- $statement->bindValue(":stage", $response->{"scenario_info"}->{"stage_no"});
- $statement->bindValue(":difficulty", $response->{"scenario_info"}->{"difficulty"});
- $statement->bindValue(":win", $response->{"win_lose"});
- $statement->bindValue(":time", $response->{"clear_time"}->{"current_time"});
- if (array_key_exists("mana", $response->{"reward"})){
- $statement->bindValue(":mana", $response->{"reward"}->{"mana"});
- }
- else{
- $statement->bindValue(":mana", 0);
- }
- 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"});
- }
- else{
- $statement->bindValue(":crystal", 0);
- }
- $statement->bindValue(":guild_points", 0);
- $statement->bindValue(":honor_points", 0);
- if (array_key_exists("helper_unit_list", $request) && sizeof($request->{"helper_unit_list"}) > 0){
- $statement->bindValue(":helper", 1);
- }
- else{
- $statement->bindValue(":helper", 0);
- }
- $statement->bindValue(":score", null);
- $statement->bindValue(":rank", null);
- $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)){
- $item = $crate->{"unit_info"};
- $statement = $db->prepare("INSERT INTO run_drop_unit (run, unit) VALUES (:run, :unit);");
- $statement->bindValue(":run", $id);
- $statement->bindValue(":unit", $unit->{"unit_master_id"});
- $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);
- $statement->bindValue(":item", $item->{"item_master_id"});
- $statement->bindValue(":amount", $item->{"item_quantity"});
- $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);
- $statement->bindValue(":item", $item->{"item_master_id"});
- $statement->bindValue(":amount", $item->{"item_quantity"});
- $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);
- $statement->bindValue(":stars", intval($rune->{"class"}) - 10);
- $statement->bindValue(":quality", intval($rune->{"rank"}) - 10);
- }
- else{
- // Non Ancient rune
- $statement->bindValue(":ancient", 0);
- $statement->bindValue(":stars", $rune->{"class"});
- $statement->bindValue(":quality", $rune->{"rank"});
- }
- $efficiency = calculate_efficiency($rune);
- $max_efficiency = calculate_maximum_efficiency($rune);
- $statement->bindValue(":efficiency", $efficiency);
- $statement->bindValue(":max_efficiency", $max_efficiency);
- $statement->bindValue(":main_stat", $rune->{"pri_eff"}[0]);
- $statement->bindValue(":main_stat_value", $rune->{"pri_eff"}[1]);
- if ($rune->{"prefix_eff"}[0] > 0){
- $statement->bindValue(":innate_stat", $rune->{"prefix_eff"}[0]);
- $statement->bindValue(":innate_stat_value", $rune->{"prefix_eff"}[1]);
- }
- else{
- $statement->bindValue(":innate_stat", null);
- $statement->bindValue(":innate_stat_value", 0);
- }
- if (sizeof($rune->{"sec_eff"}) > 0){
- $statement->bindValue(":substat_1", $rune->{"sec_eff"}[0][0]);
- $statement->bindValue(":substat_1_value", $rune->{"sec_eff"}[0][1]);
- }
- else{
- $statement->bindValue(":substat_1", null);
- $statement->bindValue(":substat_1_value", 0);
- }
- 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);
- $statement->bindValue(":substat_2_value", 0);
- }
- if (sizeof($rune->{"sec_eff"}) > 2){
- $statement->bindValue(":substat_3", $rune->{"sec_eff"}[2][0]);
- $statement->bindValue(":substat_3_value", $rune->{"sec_eff"}[2][1]);
- }
- else{
- $statement->bindValue(":substat_3", null);
- $statement->bindValue(":substat_3_value", 0);
- }
- if (sizeof($rune->{"sec_eff"}) > 3){
- $statement->bindValue(":substat_4", $rune->{"sec_eff"}[3][0]);
- $statement->bindValue(":substat_4_value", $rune->{"sec_eff"}[3][1]);
- }
- else{
- $statement->bindValue(":substat_4", null);
- $statement->bindValue(":substat_4_value", 0);
- }
- $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);
- $statement->bindValue(":unit", $unit->{"unit_id"});
- $statement->bindValue(":k_unit", $unit->{"unit_master_id"});
- $statement->bindValue(":leader", $leader);
- $leader = 0;
- $statement->bindValue(":front", 0);
- $statement->execute();
- }
- // Return success
- return "201 Created.";
- }
- /**
- * Parses the JSONs relateds to a cairos run and saves the data.
- *
- * @param SQLiteConn $db Database connection.
- * @param int $uid Player UID.
- * @param int $id Run ID.
- * @param JSON[] $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);
- $statement->bindValue(":id", $id);
- $statement->bindValue(":dtime", $result->{"tvaluelocal"});
- $statement->bindValue(":area_type", AREA_TYPE_ID::RIFT_RAID);
- $statement->bindValue(":area", AREA_TYPE_ID::RIFT_RAID);
- $statement->bindValue(":stage", $start->{"battle_info"}->{"stage_id"});
- $statement->bindValue(":difficulty", null);
- $statement->bindValue(":win", $result->{"win_lose"});
- if ($result->{"win_lose"} == 1){
- $statement->bindValue(":time", $result->{"clear_time"}->{"current_time"});
- }
- else{
- $statement->bindValue(":time", 1);
- }
- $statement->bindValue(":mana", 0); // If reward is mana, i will be updated later
- $statement->bindValue(":energy", 0);
- $statement->bindValue(":crystal", 0);
- $statement->bindValue(":guild_points", 0);
- $statement->bindValue(":honor_points", 0);
- $statement->bindValue(":helper", 0);
- $statement->bindValue(":score", null);
- $statement->bindValue(":rank", null);
- $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);
- $statement->bindValue(":unit", $reward->{"item_master_id"});
- $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);
- $statement->bindValue(":item", $reward->{"item_master_id"});
- $statement->bindValue(":amount", $reward->{"item_quantity"});
- $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);
- $statement->bindValue(":id", $reward->{"runecraft_item_id"});
- $statement->bindValue(":type", $reward->{"runecraft_type"});
- $statement->bindValue(":quality", $reward->{"runecraft_rank"});
- $statement->bindValue(":rune", $reward->{"runecraft_set_id"});
- $statement->bindValue(":stat", $reward->{"runecraft_effect_id"});
- $statement->bindValue(":value", 0);
- $statement->execute();
- break;
- case 102: //: Mana
- $statement = $db->prepare("UPDATE run SET mana = :mana WHERE run = :run;");
- $statement->bindValue(":run", $id);
- $statement->bindValue(":id", $reward->{"runecraft_item_id"});
- $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);
- $statement->bindValue(":unit", $unit->{"unit_info"}->{"unit_id"});
- $statement->bindValue(":k_unit", $unit->{"unit_info"}->{"unit_master_id"});
- $statement->bindValue(":leader", $unit->{"leader"});
- if (intval($unit->{"index"}) <= 4){
- $statement->bindValue(":front", 1);
- }
- else{
- $statement->bindValue(":front", 0);
- }
- $statement->execute();
- }
- }
- }
- // Return success
- return "201 Created.";
- }
- /**
- * Parses the JSONs relateds to a cairos run and saves the data.
- *
- * @param SQLiteConn $db Database connection.
- * @param int $uid Player UID.
- * @param int $id Run ID.
- * @param JSON[] $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);
- $statement->bindValue(":id", $id);
- $statement->bindValue(":dtime", $response->{"tvaluelocal"});
- $statement->bindValue(":area_type", AREA_TYPE_ID::CAIROS_DUNGEON);
- $statement->bindValue(":area", $request->{"dungeon_id"});
- $statement->bindValue(":stage", $request->{"stage_id"});
- $statement->bindValue(":difficulty", null);
- $statement->bindValue(":win", $response->{"win_lose"});
- $statement->bindValue(":time", $response->{"clear_time"}->{"current_time"});
- if (array_key_exists("mana", $response->{"reward"})){
- $statement->bindValue(":mana", $response->{"reward"}->{"mana"});
- }
- else{
- $statement->bindValue(":mana", 0);
- }
- 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"});
- }
- else{
- $statement->bindValue(":crystal", 0);
- }
- $statement->bindValue(":guild_points", 0);
- $statement->bindValue(":honor_points", 0);
- $statement->bindValue(":helper", 0); // TODO Where is this information??
- $statement->bindValue(":score", null);
- $statement->bindValue(":rank", null);
- $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);
- $statement->bindValue(":unit", $response->{"changed_item_list"}[0]->{"view"}->{"item_master_id"});
- $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);
- $statement->bindValue(":item", $response->{"changed_item_list"}[0]->{"view"}->{"item_master_id"});
- $statement->bindValue(":amount", $response->{"changed_item_list"}[0]->{"view"}->{"item_quantity"});
- $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);
- $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);
- $statement->bindValue(":stars", intval($rune->{"class"}) - 10);
- $statement->bindValue(":quality", intval($rune->{"rank"}) - 10);
- }
- else{
- // Non Ancient rune
- $statement->bindValue(":ancient", 0);
- $statement->bindValue(":stars", $rune->{"class"});
- $statement->bindValue(":quality", $rune->{"rank"});
- }
- $efficiency = calculate_efficiency($rune);
- $max_efficiency = calculate_maximum_efficiency($rune);
- $statement->bindValue(":efficiency", $efficiency);
- $statement->bindValue(":max_efficiency", $max_efficiency);
- $statement->bindValue(":main_stat", $rune->{"pri_eff"}[0]);
- $statement->bindValue(":main_stat_value", $rune->{"pri_eff"}[1]);
- if ($rune->{"prefix_eff"}[0] > 0){
- $statement->bindValue(":innate_stat", $rune->{"prefix_eff"}[0]);
- $statement->bindValue(":innate_stat_value", $rune->{"prefix_eff"}[1]);
- }
- else{
- $statement->bindValue(":innate_stat", null);
- $statement->bindValue(":innate_stat_value", 0);
- }
- if (sizeof($rune->{"sec_eff"}) > 0){
- $statement->bindValue(":substat_1", $rune->{"sec_eff"}[0][0]);
- $statement->bindValue(":substat_1_value", $rune->{"sec_eff"}[0][1]);
- }
- else{
- $statement->bindValue(":substat_1", null);
- $statement->bindValue(":substat_1_value", 0);
- }
- 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);
- $statement->bindValue(":substat_2_value", 0);
- }
- if (sizeof($rune->{"sec_eff"}) > 2){
- $statement->bindValue(":substat_3", $rune->{"sec_eff"}[2][0]);
- $statement->bindValue(":substat_3_value", $rune->{"sec_eff"}[2][1]);
- }
- else{
- $statement->bindValue(":substat_3", null);
- $statement->bindValue(":substat_3_value", 0);
- }
- if (sizeof($rune->{"sec_eff"}) > 3){
- $statement->bindValue(":substat_4", $rune->{"sec_eff"}[3][0]);
- $statement->bindValue(":substat_4_value", $rune->{"sec_eff"}[3][1]);
- }
- else{
- $statement->bindValue(":substat_4", null);
- $statement->bindValue(":substat_4_value", 0);
- }
- $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);
- $statement->bindValue(":unit", $unit->{"unit_id"});
- $statement->bindValue(":k_unit", $unit->{"unit_master_id"});
- $statement->bindValue(":leader", $leader);
- $leader = 0;
- $statement->bindValue(":front", 0);
- $statement->execute();
- }
- // Return success
- return "201 Created.";
- }
- /**
- * Parses the JSONs relateds to a Dimension Hole run and saves the data.
- *
- * @param SQLiteConn $db Database connection.
- * @param int $uid Player UID.
- * @param int $id Run ID.
- * @param JSON[] $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 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);
- $statement->bindValue(":id", $id);
- $statement->bindValue(":dtime", $response->{"tvaluelocal"});
- $statement->bindValue(":area_type", AREA_TYPE_ID::DIMENSIONAL_HOLE);
- $statement->bindValue(":area", $response->{"dungeon_id"});
- $statement->bindValue(":stage", $response->{"difficulty"}); // Difficulty is stage
- $statement->bindValue(":difficulty", null);
- $statement->bindValue(":win", $response->{"win_lose"});
- $statement->bindValue(":time", $response->{"clear_time"}->{"current_time"});
- if (array_key_exists("mana", $response->{"reward"})){
- $statement->bindValue(":mana", $response->{"reward"}->{"mana"});
- }
- else{
- $statement->bindValue(":mana", 0);
- }
- if (array_key_exists("energy", $response->{"reward"})){
- $statement->bindValue(":energy", $response->{"reward"}->{"energy"});
- }
- $statement->bindValue(":energy", 0);
- if (array_key_exists("crystal", $response->{"reward"})){
- $statement->bindValue(":crystal", $response->{"reward"}->{"crystal"});
- }
- else{
- $statement->bindValue(":crystal", 0);
- }
- $statement->bindValue(":guild_points", 0);
- $statement->bindValue(":honor_points", 0);
- $statement->bindValue(":helper", 0); // TODO Where is this information??
- $statement->bindValue(":score", null);
- $statement->bindValue(":rank", null);
- $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);
- $statement->bindValue(":item", $drop->{"view"}->{"item_master_id"});
- $statement->bindValue(":amount", $drop->{"view"}->{"item_quantity"});
- $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);
- $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);
- $statement->bindValue(":stars", intval($rune->{"class"}) - 10);
- $statement->bindValue(":quality", intval($rune->{"rank"}) - 10);
- }
- else{
- // Non Ancient rune
- $statement->bindValue(":ancient", 0);
- $statement->bindValue(":stars", $rune->{"class"});
- $statement->bindValue(":quality", $rune->{"rank"});
- }
- $efficiency = calculate_efficiency($rune);
- $max_efficiency = calculate_maximum_efficiency($rune);
- $statement->bindValue(":efficiency", $efficiency);
- $statement->bindValue(":max_efficiency", $max_efficiency);
- $statement->bindValue(":main_stat", $rune->{"pri_eff"}[0]);
- $statement->bindValue(":main_stat_value", $rune->{"pri_eff"}[1]);
- if ($rune->{"prefix_eff"}[0] > 0){
- $statement->bindValue(":innate_stat", $rune->{"prefix_eff"}[0]);
- $statement->bindValue(":innate_stat_value", $rune->{"prefix_eff"}[1]);
- }
- else{
- $statement->bindValue(":innate_stat", null);
- $statement->bindValue(":innate_stat_value", 0);
- }
- if (sizeof($rune->{"sec_eff"}) > 0){
- $statement->bindValue(":substat_1", $rune->{"sec_eff"}[0][0]);
- $statement->bindValue(":substat_1_value", $rune->{"sec_eff"}[0][1]);
- }
- else{
- $statement->bindValue(":substat_1", null);
- $statement->bindValue(":substat_1_value", 0);
- }
- 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);
- $statement->bindValue(":substat_2_value", 0);
- }
- if (sizeof($rune->{"sec_eff"}) > 2){
- $statement->bindValue(":substat_3", $rune->{"sec_eff"}[2][0]);
- $statement->bindValue(":substat_3_value", $rune->{"sec_eff"}[2][1]);
- }
- else{
- $statement->bindValue(":substat_3", null);
- $statement->bindValue(":substat_3_value", 0);
- }
- if (sizeof($rune->{"sec_eff"}) > 3){
- $statement->bindValue(":substat_4", $rune->{"sec_eff"}[3][0]);
- $statement->bindValue(":substat_4_value", $rune->{"sec_eff"}[3][1]);
- }
- else{
- $statement->bindValue(":substat_4", null);
- $statement->bindValue(":substat_4_value", 0);
- }
- $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);
- $statement->bindValue(":unit", $unit->{"unit_id"});
- $statement->bindValue(":k_unit", $unit->{"unit_master_id"});
- $statement->bindValue(":leader", $leader);
- $leader = 0;
- $statement->bindValue(":front", 0);
- $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);
- $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;
- }
- // 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);
- $statement->bindValue(":dtime", $dtime);
- 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;
- }
- ?>
|