forked from vivit-jc/cauldron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.php
More file actions
100 lines (90 loc) · 2.21 KB
/
main.php
File metadata and controls
100 lines (90 loc) · 2.21 KB
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
<?php
require("./mod.php");
require("./game.php");
require("./player.php");
require("./define.php");
define("ADMINPASS", "adminpass");
session_start();
#ロック開始 ゲーム的に衝突するとアレなのでひとりずつ処理する
$lock_fp = fopen("lockfile","r+");
flock($lock_fp,LOCK_EX);
$game = new Game();
if(isset($_SESSION["id"])){
$game->setPlayer($_SESSION["id"]);
}
if(isset($_POST["mode"])){
switch($_POST["mode"]) {
case "login":
if(!isset($_POST["id"]) || !isset($_POST["pass"])){
printLogin("不正なデータが送信されました");
} else if(($loginres = $game->checkLogin($_POST["id"], $_POST["pass"])) != "ok"){
printLogin($loginres);
} else {
$game->setPlayer($_POST["id"]);
printActMain("");
}
break;
case "select":
if(!isset($_SESSION["id"])){
printLogin("ログインし直してください");
} else if(!isset($_POST["act"])){
printActMain("行動を選択してください");
} else {
$mes = $game->setAction($_POST["act"]);
printActMain($mes);
}
break;
case "reload":
printActMain("");
break;
case "logout":
session_destroy();
printLogin("");
break;
case "signup":
if(!isset($_POST["id"]) || !isset($_POST["pass"]) || !isset($_POST["name"])){
printLogin("不正なデータが送信されました");
} else if(($signupres = $game->checkSignUp($_POST["id"], $_POST["pass"], $_POST["name"])) != "ok"){
printLogin($signupres);
} else {
$game->makeNewPlayer($_POST["id"],$_POST["pass"],$_POST["name"]);
$game->setPlayer($_POST["id"]);
printActMain("");
}
break;
case "admin":
if(!isset($_POST["pass"]) || $_POST["pass"] != ADMINPASS){
printAdmin();
} else {
printAdminMode();
}
break;
case "adminmode":
if(!isset($_POST["act"])){
printAdmin();
} else {
switch($_POST["act"]){
case "start":
$game->startGame();
session_destroy();
printLogin("");
break;
case "reset":
$game->resetGame();
session_destroy();
printLogin("");
break;
}
}
break;
}
} else {
if(isset($_SESSION["id"])){
printActMain("");
} else {
printLogin("");
}
}
#ロック解除
fclose($lock_fp);
?>