Anonymous 3D Imageboard http://cyberia.digital/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

389 lines
9.9KB

  1. <?php
  2. /*
  3. ________ _ _______
  4. / ____/ /_ ____ _____ | | / / ___/
  5. / / / __ \/ __ `/ __ \ | | /| / /\__ \
  6. / /___/ / / / /_/ / / / / | |/ |/ /___/ /
  7. \____/_/ /_/\__,_/_/ /_/ |__/|__//____/
  8. Chan WEBSERVICES
  9. reception of the webservice for chan
  10. */
  11. require_once 'ChanController.php';
  12. require_once 'AdminController.php';
  13. require_once 'Models/Post.php';
  14. $action = "";
  15. if(isset($_POST["action"]))
  16. $action = $_POST["action"];
  17. /*
  18. controls the RESTful services
  19. URL mapping
  20. */
  21. switch($action){
  22. //**************************************
  23. // * WS ADMIN
  24. // *************************************
  25. case "setAdminPassword":
  26. $password = "";
  27. if( isset($_POST['password']) ) $password = $_POST['password'];
  28. $AdminController = new AdminController();
  29. $result = $AdminController -> setPassword($password);
  30. Helpers::makeGenericResponse(true, $result, null);
  31. break;
  32. case "validAdmin":
  33. $password = "";
  34. if( isset($_POST['password']) ) $password = $_POST['password'];
  35. $AdminController = new AdminController();
  36. $result = $AdminController -> validPassword($password);
  37. Helpers::makeGenericResponse(true, $result, null);
  38. break;
  39. case "testAdminSession":
  40. $AdminController = new AdminController();
  41. $result = $AdminController -> isAdminLogged();
  42. Helpers::makeGenericResponse(true, $result, null);
  43. break;
  44. case "unLog":
  45. $AdminController = new AdminController();
  46. $result = $AdminController -> unlog();
  47. Helpers::makeGenericResponse(true, $result, null);
  48. break;
  49. case "deletePost":
  50. $chanController = new ChanController();
  51. $mapKey = "";
  52. $postId = -1;
  53. if( isset($_POST['map_key']) ) $mapKey = $_POST['map_key'];
  54. if( isset($_POST['post_id']) ) $postId = $_POST['post_id'];
  55. $result = $chanController -> deletePost($mapKey ,$postId );
  56. Helpers::makeGenericResponse(true, $result, null);
  57. break;
  58. case "setBan":
  59. $chanController = new ChanController();
  60. $mapKey = "";
  61. $postId = -1;
  62. if( isset($_POST['post_id']) ) $postId = $_POST['post_id'];
  63. $result = $chanController -> setBan($postId );
  64. Helpers::makeGenericResponse(true, $result, null);
  65. break;
  66. case "deletePostForVal":
  67. $chanController = new ChanController();
  68. $val = "";
  69. $result = false;
  70. if( isset($_POST['val']) ){
  71. $val = $_POST['val'];
  72. $result = $chanController -> deletePostForVal($val);
  73. }
  74. Helpers::makeGenericResponse(true, $result, null);
  75. break;
  76. case "setPostUrlToFile":
  77. $chanController = new ChanController();
  78. $mapKey = "";
  79. $postId = -1;
  80. if( isset($_POST['post_id']) ) $postId = $_POST['post_id'];
  81. $result = $chanController -> setPostUrlToFile($postId );
  82. Helpers::makeGenericResponse(true, $result, null);
  83. break;
  84. case "setPostCanon":
  85. $chanController = new ChanController();
  86. $mapKey = "";
  87. $postId = -1;
  88. if( isset($_POST['map_key']) ) $mapKey = $_POST['map_key'];
  89. if( isset($_POST['post_id']) ) $postId = $_POST['post_id'];
  90. $result = $chanController -> setPostCanon($mapKey ,$postId );
  91. Helpers::makeGenericResponse(true, $result, null);
  92. break;
  93. /*
  94. case "banUser":
  95. $chanController = new ChanController();
  96. $mapKey = "";
  97. $reason = "";
  98. $durationD = 0;
  99. $postId = -1;
  100. if( isset($_POST['map_key']) ) $mapKey = $_POST['map_key'];
  101. if( isset($_POST['post_id']) ) $postId = $_POST['post_id'];
  102. if( isset($_POST['durationD']) ) $durationD = $_POST['durationD'];
  103. if( isset($_POST['reason']) ) $reason = $_POST['reason'];
  104. $result = $chanController -> banForPost($mapKey, $postId, $reason, $durationD);
  105. Helpers::makeGenericResponse(true, $result, null);
  106. break;*/
  107. case "getAllPost":
  108. $chanController = new ChanController();
  109. $result = $chanController -> getAllPost();
  110. Helpers::makeGenericResponse(true, $result, null);
  111. break;
  112. case "getAllMaps":
  113. $chanController = new ChanController();
  114. $result = $chanController -> getAllMaps();
  115. Helpers::makeGenericResponse(true, $result, null);
  116. break;
  117. case "getAllTiles":
  118. $chanController = new ChanController();
  119. $result = $chanController -> getAllTiles();
  120. Helpers::makeGenericResponse(true, $result, null);
  121. break;
  122. case "saveMapModel":
  123. $mapKey = "";
  124. $levelData = "";
  125. if( isset($_POST['id']) ) $mapKey = $_POST['key'];
  126. if( isset($_POST['level_data']) ) $levelData = $_POST['level_data'];
  127. $chanController = new ChanController();
  128. $result = $chanController -> saveMapModel($mapKey, $levelData);
  129. Helpers::makeGenericResponse(true, $result, null);
  130. break;
  131. //**************************************
  132. // * WS for PUR CHAN
  133. // * Actual version
  134. // *************************************
  135. case "getDungeonSettings":
  136. $chanController = new ChanController();
  137. $result = $chanController -> getSettings();
  138. Helpers::makeGenericResponse(true, $result, null);
  139. break;
  140. case "getMapPosts":
  141. $chanController = new ChanController();
  142. $result = $chanController -> getMapPosts();
  143. Helpers::makeGenericResponse(true, $result, null);
  144. break;
  145. /*
  146. case "getAllPost":
  147. $chanController = new ChanController();
  148. $result = $chanController -> getAllPost();
  149. Helpers::makeGenericResponse(true, $result, null);
  150. break;*/
  151. case "getReplies":
  152. if( isset($_POST['post_id']) ) $postId = $_POST['post_id'];
  153. $chanController = new ChanController();
  154. $result = $chanController -> getReplies($postId);
  155. Helpers::makeGenericResponse(true, $result, null);
  156. break;
  157. case "createPost":
  158. $chanController = new ChanController();
  159. $torrentBytes = NULL;
  160. $file = NULL;
  161. $img = NULL;
  162. if( isset($_FILES['file']) ) $file = $_FILES['file'];
  163. if( isset($_POST['torrent']) ) $torrentBytes = $_POST['torrent'];
  164. if( isset($_POST['image_data']) ) $img = $_POST['image_data'];
  165. $postModel = new Post();
  166. $postModel -> fillWithPostData();
  167. $result = $chanController -> createPost($postModel,$file, $img);
  168. Helpers::makeGenericResponse(true, $result, null);
  169. break;
  170. //**************************************
  171. // * WS PLAYER
  172. // *************************************
  173. case "getActions":
  174. $chanController = new ChanController();
  175. $result = $chanController -> getActions();
  176. Helpers::makeGenericResponse(true, $result, null);
  177. break;
  178. case "setAction":
  179. if( isset($_POST['player_action']) ) $player_action = $_POST['player_action'];
  180. if( isset($_POST['value']) ) $value = $_POST['value'];
  181. $chanController = new ChanController();
  182. $result = $chanController -> setAction($player_action,$value);
  183. Helpers::makeGenericResponse(true, $result, null);
  184. break;
  185. case "initPlayer":
  186. $chanController = new ChanController();
  187. $playerId = null;
  188. $playerKey = null;
  189. $mapKey = null;
  190. $playerPassword = null;
  191. if( isset($_POST['player_id']) ) $playerId = $_POST['player_id'];
  192. if( isset($_POST['player_key']) ) $playerKey = $_POST['player_key'];
  193. if( isset($_POST['player_password']) ) $playerPassword = $_POST['player_password'];
  194. if( isset($_POST['map_key']) ) $mapKey = $_POST['map_key'];
  195. $playerData = $chanController->init( $playerId, $playerKey, $playerPassword, $mapKey );
  196. //$playerId = null;
  197. //if(array_key_exists ("id", $playerData)) $playerId = $playerData["id"];
  198. //return the player postion
  199. //$playersList = $chanController->getAllPlayers($playerId);
  200. //$arts = $chanController->getArtByMap($playerData);
  201. /*
  202. $result = array (
  203. 'list' => $playersList,
  204. 'player' => $playerData
  205. );*/
  206. Helpers::makeGenericResponse(true, $playerData, null);
  207. break;
  208. case "changeMapPlayer":
  209. $chanController = new ChanController();
  210. $mapKey = null;
  211. if( isset($_POST['map_key']) ) $mapKey = $_POST['map_key'];
  212. $chanController->setPlayerMapKey( $mapKey );
  213. $result = $chanController -> getMapPosts();
  214. Helpers::makeGenericResponse(true, $result, null);
  215. break;
  216. case "changeMapPlayerName":
  217. $chanController = new ChanController();
  218. $mapName = null;
  219. if( isset($_POST['map_name']) ) $mapName = $_POST['map_name'];
  220. $chanController->setPlayerMapName( $mapName );
  221. $result = $chanController -> getMapPosts();
  222. Helpers::makeGenericResponse(true, $result, null);
  223. break;
  224. case "changeMapRandom":
  225. $chanController = new ChanController();
  226. $secret = true;
  227. if( isset($_POST['secret']) ) $secret = $_POST['secret'];
  228. $chanController->setPlayerMapRand( $secret );
  229. $result = $chanController -> getMapPosts();
  230. Helpers::makeGenericResponse(true, $result, null);
  231. break;
  232. case "setPlayerItem":
  233. $chanController = new ChanController();
  234. $itemKey = null;
  235. if( isset($_POST['item_key']) ) $itemKey = $_POST['item_key'];
  236. $chanController->setItem( $itemKey );
  237. $result = $chanController -> getMapPosts();
  238. Helpers::makeGenericResponse(true, $result, null);
  239. break;
  240. /*
  241. case "movePlayer":
  242. $chanController = new ChanController();
  243. $playerId = null;
  244. $playerKey = null;
  245. $playerPassword = null;
  246. if( isset($_POST['player_id']) ) $playerId = $_POST['player_id'];
  247. if( isset($_POST['player_key']) ) $playerKey = $_POST['player_key'];
  248. if( isset($_POST['player_password']) ) $playerPassword = $_POST['player_password'];
  249. //position in 3D to get
  250. $playerData = array();
  251. if( isset($_POST['position_x']) ) $playerData['position_x'] = $_POST['position_x'];
  252. if( isset($_POST['position_y']) ) $playerData['position_y'] = $_POST['position_y'];
  253. if( isset($_POST['position_z']) ) $playerData['position_z'] = $_POST['position_z'];
  254. if( isset($_POST['map_key']) ) $playerData['map_key'] = $_POST['map_key'];
  255. $playerResult = $chanController->move( $playerId, $playerKey, $playerPassword, $playerData);
  256. if($playerResult == null){
  257. //PLAYER DONT EXIST ANYMORE!!!
  258. $playerResult = $chanController->init( $playerId, $playerKey, $playerPassword );
  259. $playerId = null;
  260. if(array_key_exists ("id", $playerResult)) $playerId = $playerResult["id"];
  261. }
  262. //return the player postion
  263. $playersList = $chanController->getAllPlayers($playerId);
  264. //Gte post datas
  265. $postsList = $chanController->getArtByMap($playerData);
  266. //IS the player Null??? if yes
  267. $result = array(
  268. 'user' => $playerResult,
  269. 'players' => $playersList,
  270. 'arts' => $postsList
  271. );
  272. Helpers::makeGenericResponse(true,$result, null);
  273. break;
  274. */
  275. }