new_team.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. function action($db = null){
  3. global $AREA_TYPE;
  4. global $DIFFICULTY;
  5. global $SCENARIO;
  6. global $DUNGEON;
  7. global $ELEMENTAL_RIFT_DUNGEON;
  8. global $LABYRINTH_STAGES;
  9. global $UID;
  10. //$player = SQLite3::escapeString($_POST["uid"]);
  11. $player = filter_input(INPUT_POST, 'uid');
  12. $area_type = filter_input(INPUT_POST, 'area_type');
  13. $area = filter_input(INPUT_POST, 'area');
  14. $stage = filter_input(INPUT_POST, 'stage');
  15. error_log("STAGE1: " . $stage);
  16. $difficulty = filter_input(INPUT_POST, 'difficulty');
  17. $ids = filter_input(INPUT_POST, 'ids');
  18. $name = filter_input(INPUT_POST, 'name');
  19. $description = filter_input(INPUT_POST, 'description');
  20. $id = preg_split("/[\s,]+/", $ids);
  21. $id_count = sizeof($id);
  22. if ($name == null || strlen($name) == 0){
  23. return -1;
  24. }
  25. switch ($area_type){
  26. case $AREA_TYPE["SCENARIO"]:
  27. if ($stage < 0 || $stage > 7){
  28. return -31;
  29. }
  30. if (!($difficulty == 0 || in_array($difficulty, $DIFFICULTY) || $difficulty == $DIFFICULTY["EASY"])){
  31. return -32;
  32. }
  33. if ($id_count < 1 || $id_count > 4){
  34. return -33;
  35. }
  36. if (!in_array($area, $SCENARIO)){
  37. return -34;
  38. }
  39. break;
  40. case $AREA_TYPE["CAIROS_DUNGEON"]:
  41. if ($stage < 0 || $stage > 10){
  42. return -35;
  43. }
  44. $difficulty = null;
  45. if ($id_count < 1 || $id_count > 5){
  46. return -36;
  47. }
  48. if (!in_array($area, $DUNGEON)){
  49. return -37;
  50. }
  51. break;
  52. case $AREA_TYPE["RIFT_DUNGEON"]:
  53. $stage = null;
  54. $difficulty = null;
  55. if ($id_count < 1 || $id_count > 6){
  56. return -39;
  57. }
  58. if (!in_array($area, $ELEMENTAL_RIFT_DUNGEON)){
  59. return -40;
  60. }
  61. break;
  62. case $AREA_TYPE["RIFT_RAID"]:
  63. if ($stage < 0 || $stage > 5){
  64. return -41;
  65. }
  66. $difficulty = null;
  67. if ($id_count < 1 || $id_count > 6){
  68. return -42;
  69. }
  70. $area = null;
  71. break;
  72. case $AREA_TYPE["ARENA"]:
  73. $area = null;
  74. $stage = null;
  75. $difficulty = null;
  76. break;
  77. case $AREA_TYPE["GUILD_WAR"]:
  78. $area = null;
  79. $stage = null;
  80. $difficulty = null;
  81. break;
  82. case $AREA_TYPE["GUILD_SIEGE"]:
  83. $area = null;
  84. $stage = null;
  85. $difficulty = null;
  86. break;
  87. case $AREA_TYPE["TARTARUS_LABYRINTH"]:
  88. $stage = null;
  89. if ($difficulty < 0 || !in_array($difficulty, $DIFFICULTY)){
  90. return -43;
  91. }
  92. if ($id_count < 1 || $id_count > 5){
  93. return -44;
  94. }
  95. if (!in_array($area, $LABYRINTH_STAGES)){
  96. return -45;
  97. }
  98. break;
  99. case $AREA_TYPE["TRIAL_OF_ASCENSION"]:
  100. if ($difficulty != 0 && $difficulty != $DIFFICULTY["NORMAL"] && $difficulty != $DIFFICULTY["HARD"]){
  101. return -46;
  102. }
  103. $stage = null;
  104. if ($id_count < 1 || $id_count > 5){
  105. return -47;
  106. }
  107. $area = null;
  108. break;
  109. case $AREA_TYPE["DIMENSIONAL_HOLE"]:
  110. if ($stage < 0 || $stage > 5){
  111. return -48;
  112. }
  113. $difficulty = null;
  114. if ($id_count < 1 || $id_count > 4){
  115. return -49;
  116. }
  117. if (!in_array($area, $DUNGEON)){
  118. return -50;
  119. }
  120. break;
  121. case $AREA_TYPE["DIMENSIONAL_RIFT"]:
  122. if ($difficulty != 0 && $difficulty != $DIFFICULTY["NORMAL"] && $difficulty != $DIFFICULTY["HARD"]){
  123. return -51;
  124. }
  125. $stage = null;
  126. if ($id_count < 1 || $id_count > 5){
  127. return -52;
  128. }
  129. $area = null;
  130. break;
  131. default:
  132. return -3;
  133. }
  134. $unique_id = array_unique($id);
  135. if ($id_count != sizeof($unique_id)){
  136. return -4;
  137. }
  138. error_log("STAGE2: " . $stage);
  139. $s = "SELECT CASE WHEN MAX(id) IS NULL THEN 1 ELSE MAX(id) + 1 END AS id FROM team;";
  140. $q = $db->query($s);
  141. $r = $q->fetchArray(SQLITE3_ASSOC);
  142. $team_id = $r["id"];
  143. $statement = $db->prepare('INSERT INTO team (uid, id, name, description, area_type, area, stage, difficulty) VALUES (:uid, :id, :name, :description, :area_type, :area, :stage, :difficulty);');
  144. $statement->bindValue(':uid', $player);
  145. $statement->bindValue(':id', $team_id);
  146. $statement->bindValue(':name', $name);
  147. $statement->bindValue(':description', $description);
  148. $statement->bindValue(':area_type', $area_type);
  149. $statement->bindValue(':area', $area);
  150. $statement->bindValue(':stage', $stage);
  151. $statement->bindValue(':difficulty', $difficulty);
  152. $res = $statement->execute();
  153. if (!$res){
  154. return -5;
  155. }
  156. foreach ($id as $i){
  157. $s = "INSERT INTO team_unit VALUES ($team_id, $i);";
  158. $db->query($s);
  159. }
  160. return 0;
  161. }
  162. ?>