-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
110 lines (88 loc) · 2.56 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
*
*/
require_once 'defines.php';
use MRZX\Tools;
function convertPhpInputToFormInput(){
$data =json_decode(file_get_contents('php://input'));
$type=Tools::strtolower($_SERVER['REQUEST_METHOD']);
if(empty($data))
return;
if($type==='post')
{
foreach($data as $k=>$d){
$_POST[Tools::safeReadInput($k)]=Tools::safeReadInput($d);
}
}
elseif($type==='get'){
foreach($data as $k=>$d){
$_GET[Tools::safeReadInput($k)]=Tools::safeReadInput($d);
}
}
}
function apiSuccessHeaders(){
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
header('X-Powered-By: MRZX.ir');
header('Access-Control-Allow-Headers:Content-Type,Authorization,X-Requested-With,Accept,Origin');
header('HTTP/1.1 200 OK');
}
$request = Tools::getRequestUri();
$router=new \Bramus\Router\Router();
$router->get('/', function() {
header('Location: https://mrzx.ir/');
exit;
});
$router->match('GET|POST','/connection', function() {
apiSuccessHeaders();
die(json_encode(
array(
'hasError' => false,
'message' => 'welcome to D4S game!')
));
});
$router->post('/user/register', function() {
convertPhpInputToFormInput();
include __DIR__.'/api/user/register.php';
});
$router->post('/user/login', function() {
convertPhpInputToFormInput();
include __DIR__.'/api/user/login.php';
});
$router->post('/user/players', function() {
convertPhpInputToFormInput();
include __DIR__.'/api/user/players.php';
});
$router->get('/user/{user_id}', function($user_id) {
$_GET['user_id']=Tools::safeReadInput($user_id);
include __DIR__.'/api/user/info.php';
});
$router->post('/game/start', function() {
convertPhpInputToFormInput();
include __DIR__.'/api/game/start_random.php';
});
$router->post('/game/startrobot', function() {
convertPhpInputToFormInput();
include __DIR__.'/api/game/start_robot.php';
});
$router->post('/game/play', function() {
convertPhpInputToFormInput();
include __DIR__.'/api/game/play.php';
});
$router->post('/game/content', function() {
convertPhpInputToFormInput();
include __DIR__.'/api/game/content.php';
});
$router->post('/game/contentrobot', function() {
convertPhpInputToFormInput();
include __DIR__.'/api/game/content_robot.php';
});
$router->get('/install', function() {
include __DIR__.'/install.php';
});
$router->set404(function() {
header('HTTP/1.1 404 Not Found');
echo " ERROR 404 : PAGE NOT FOUND !!!";
});
$router->run();