-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathend_game.php
More file actions
95 lines (81 loc) · 2.7 KB
/
end_game.php
File metadata and controls
95 lines (81 loc) · 2.7 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
<?php
session_start();
$account = $_SESSION["account"];
$game = $_GET["x"];
$obj = json_decode($game);
$score = $obj->sc;
$game_id = $obj->id;
$servername = "site-db";
$username = "game_user";
$password = "5DtNfLKdPdU1y6AL";
$db_name = "goaskme_game";
$conn = new mysqli($servername, $username, $password, $db_name);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if($score != NULL){
if($game_id == 1){
$stmt = $conn->prepare("SELECT * FROM game_snake WHERE account = ?");
$stmt->bind_param("s", $_SESSION["account"]);
$stmt->execute();
$res = $stmt->get_result();
$row = $res->fetch_array(MYSQLI_ASSOC);
$stmt->close();
if($row == NULL){
$st = $conn->prepare("INSERT INTO game_snake(account, score, last_game_time) VALUES (?, ?, DEFAULT)");
$st->bind_param("si", $account, $score);
$st->execute();
$st->close();
}else{
$st = $conn->prepare("UPDATE game_snake SET score = score + ? WHERE account = ?");
$st->bind_param("is", $score, $account);
$st->execute();
$st->close();
}
$sql = "UPDATE game_bonus_pool SET cumulative_points = cumulative_points + 5 WHERE game_id = 1";
$conn->query($sql);
}elseif ($game_id == 2) {
$stmt = $conn->prepare("SELECT * FROM game_2048 WHERE account = ?");
$stmt->bind_param("s", $_SESSION["account"]);
$stmt->execute();
$res = $stmt->get_result();
$row = $res->fetch_array(MYSQLI_ASSOC);
$stmt->close();
if($row == NULL){
$st = $conn->prepare("INSERT INTO game_2048(account, score, last_game_time) VALUES (?, ?, DEFAULT)");
$st->bind_param("si", $account, $score);
$st->execute();
$st->close();
}else{
$st = $conn->prepare("UPDATE game_2048 SET score = score + ? WHERE account = ?");
$st->bind_param("is", $score, $account);
$st->execute();
$st->close();
}
$sql = "UPDATE game_bonus_pool SET cumulative_points = cumulative_points + 5 WHERE game_id = 2";
$conn->query($sql);
}elseif ($game_id == 3){
$stmt = $conn->prepare("SELECT * FROM game_hitball WHERE account = ?");
$stmt->bind_param("s", $_SESSION["account"]);
$stmt->execute();
$res = $stmt->get_result();
$row = $res->fetch_array(MYSQLI_ASSOC);
$stmt->close();
if($row == NULL){
$st = $conn->prepare("INSERT INTO game_hitball(account, score, last_game_time) VALUES (?, ?, DEFAULT)");
$st->bind_param("si", $account, $score);
$st->execute();
$st->close();
}else{
$st = $conn->prepare("UPDATE game_hitball SET score = score + ? WHERE account = ?");
$st->bind_param("is", $score, $account);
$st->execute();
$st->close();
}
$sql = "UPDATE game_bonus_pool SET cumulative_points = cumulative_points + 5 WHERE game_id = 3";
$conn->query($sql);
}
}
$conn->close();
?>