-
Notifications
You must be signed in to change notification settings - Fork 11
/
addGameStats.php
276 lines (233 loc) · 17.5 KB
/
addGameStats.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<?php
// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke and Tom Reynolds
// The MegaGlest Team, under GNU GPL v3.0
// ==============================================================
define( 'INCLUSION_PERMITTED', true );
require_once( 'registry.php' );
require_once( 'config.php' );
require_once( 'functions.php' );
// Consider using HTTP POST instead of HTTP GET here, data should always be sent via POST for privacy and security reasons
// Alternatively, do not retrieve (and transmit) this data at all via HTTP (other than the IP address the game servers advertises) but fetch it from the game server instead
// consider replacing this by a cron job
// cleanupServerList();
// Representation starts here (but it should really be starting much later, there is way too much logic behind this point)
header( 'Content-Type: text/plain; charset=utf-8' );
//echo '#0 ' . $_GET['gameUUID'];
if ( isset( $_GET['gameUUID'] ) ) {
define( 'DB_LINK', db_connect() );
$gameUUID = (string) clean_str( $_GET['gameUUID'] );
$whereClause = 'gameUUID=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $gameUUID ) . '\'';
$gameDuration = 0;
$framesToCalculatePlaytime = 0;
if ( isset( $_GET['framesToCalculatePlaytime'] ) ) {
$framesToCalculatePlaytime = (string) clean_str( $_GET['framesToCalculatePlaytime'] );
$gameDuration = $framesToCalculatePlaytime / 40 / 60;
}
if($gameDuration < MAX_MINS_OLD_COMPLETED_GAMES)
{
$game_completed = @mysqli_query( Registry::$mysqliLink, 'SELECT COUNT(*) FROM glestserver WHERE ' . $whereClause . ' AND status=3;' );
$game_completed_status = @mysqli_fetch_row( $game_completed );
if( $game_completed_status[0] > 0 )
{
mysqli_query( Registry::$mysqliLink, 'DELETE FROM glestserver WHERE ' . $whereClause . ';');
mysqli_query( Registry::$mysqliLink, 'DELETE FROM glestgamestats WHERE ' . $whereClause . ';');
mysqli_query( Registry::$mysqliLink, 'DELETE FROM glestgameplayerstats WHERE ' . $whereClause . ';');
echo 'OK - ' . $gameDuration;
return;
}
}
$stats_in_db = @mysqli_query( Registry::$mysqliLink, 'SELECT COUNT(*) FROM glestgamestats WHERE ' . $whereClause . ';' );
$statsCount = @mysqli_fetch_row( $stats_in_db );
$player_stats_in_db = @mysqli_query( Registry::$mysqliLink, 'SELECT COUNT(*) FROM glestgameplayerstats WHERE ' . $whereClause . ';');
$player_statsCount = @mysqli_fetch_row( $player_stats_in_db );
$gameUUID = (string) clean_str( $_GET['gameUUID'] );
$tech = (string) clean_str( $_GET['tech'] );
$factionCount = 0;
if ( isset( $_GET['factionCount'] ) ) {
$factionCount = (string) clean_str( $_GET['factionCount'] );
}
$framesPlayed = 0;
if ( isset( $_GET['framesPlayed'] ) ) {
$framesPlayed = (string) clean_str( $_GET['framesPlayed'] );
}
$maxConcurrentUnitCount = 0;
if ( isset( $_GET['maxConcurrentUnitCount'] ) ) {
$maxConcurrentUnitCount = (string) clean_str( $_GET['maxConcurrentUnitCount'] );
}
$totalEndGameConcurrentUnitCount = 0;
if ( isset( $_GET['totalEndGameConcurrentUnitCount'] ) ) {
$totalEndGameConcurrentUnitCount = (string) clean_str( $_GET['totalEndGameConcurrentUnitCount'] );
}
$isHeadlessServer = 0;
if ( isset( $_GET['isHeadlessServer'] ) ) {
$isHeadlessServer = (string) clean_str( $_GET['isHeadlessServer'] );
}
//echo '#1 ' . $whereClause;
//echo '#2 ' . $statsCount[0];
if ( $statsCount[0] > 0 ) // this game is contained in the database
{
// update database info on this game server; no checks are performed
$result = mysqli_query( Registry::$mysqliLink, 'UPDATE glestgamestats SET ' .
'gameUUID=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $gameUUID ) . '\', ' .
'tech=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $tech ) . '\', ' .
'factionCount=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $factionCount ) . '\', ' .
'framesPlayed=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $framesPlayed ) . '\', ' .
'framesToCalculatePlaytime=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $framesToCalculatePlaytime ) . '\', ' .
'maxConcurrentUnitCount=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $maxConcurrentUnitCount ) . '\', ' .
'totalEndGameConcurrentUnitCount=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $totalEndGameConcurrentUnitCount ) . '\', ' .
'isHeadlessServer=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $isHeadlessServer ) . '\', ' .
'lasttime=' . 'now()' . ' ' .
'WHERE ' . $whereClause . ';');
if (!$result) {
die('part 1a: Invalid query: ' . mysql_error());
}
echo 'OK1a';
}
else // this game server is not listed in the database, yet
{ // check whether this game server is available from the Internet; if it is, add it to the database
// update database info on this game server; no checks are performed
$result = mysqli_query( Registry::$mysqliLink, 'INSERT INTO glestgamestats SET ' .
'gameUUID=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $gameUUID ) . '\', ' .
'tech=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $tech ) . '\', ' .
'factionCount=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $factionCount ) . '\', ' .
'framesPlayed=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $framesPlayed ) . '\', ' .
'framesToCalculatePlaytime=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $framesToCalculatePlaytime ) . '\', ' .
'maxConcurrentUnitCount=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $maxConcurrentUnitCount ) . '\', ' .
'totalEndGameConcurrentUnitCount=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $totalEndGameConcurrentUnitCount ) . '\', ' .
'isHeadlessServer=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $isHeadlessServer ) . '\';');
if (!$result) {
die('part 2a: Invalid query: ' . mysql_error());
}
echo 'OK2b';
}
for ( $factionNumber = 0; $factionNumber < $factionCount ; $factionNumber++)
{
// Player details
$factionIndex = 0;
if ( isset( $_GET['factionIndex_' . $factionNumber ] ) ) {
$factionIndex = clean_str( $_GET['factionIndex_' . $factionNumber] );
}
$controlType = 0;
if ( isset( $_GET['controlType_' . $factionNumber] ) ) {
$controlType = clean_str( $_GET['controlType_' . $factionNumber] );
}
$resourceMultiplier = 0;
if ( isset( $_GET['resourceMultiplier_' . $factionNumber] ) ) {
$resourceMultiplier = clean_str( $_GET['resourceMultiplier_' . $factionNumber] );
}
$factionTypeName = "";
if ( isset( $_GET['factionTypeName_' . $factionNumber] ) ) {
$factionTypeName = (string) clean_str( $_GET['factionTypeName_' . $factionNumber] );
}
$personalityType = 0;
if ( isset( $_GET['personalityType_' . $factionNumber] ) ) {
$personalityType = clean_str( $_GET['personalityType_' . $factionNumber] );
}
$teamIndex = 0;
if ( isset( $_GET['teamIndex_' . $factionNumber] ) ) {
$teamIndex = clean_str( $_GET['teamIndex_' . $factionNumber] );
}
$wonGame = 0;
if ( isset( $_GET['wonGame_' . $factionNumber] ) ) {
$wonGame = clean_str( $_GET['wonGame_' . $factionNumber] );
}
$killCount = 0;
if ( isset( $_GET['killCount_' . $factionNumber] ) ) {
$killCount = clean_str( $_GET['killCount_' . $factionNumber] );
}
$enemyKillCount = 0;
if ( isset( $_GET['enemyKillCount_' . $factionNumber] ) ) {
$enemyKillCount = clean_str( $_GET['enemyKillCount_' . $factionNumber] );
}
$deathCount = 0;
if ( isset( $_GET['deathCount_' . $factionNumber] ) ) {
$deathCount = clean_str( $_GET['deathCount_' . $factionNumber] );
}
$unitsProducedCount = 0;
if ( isset( $_GET['unitsProducedCount_' . $factionNumber] ) ) {
$unitsProducedCount = clean_str( $_GET['unitsProducedCount_' . $factionNumber] );
}
$resourceHarvestedCount = 0;
if ( isset( $_GET['resourceHarvestedCount_' . $factionNumber] ) ) {
$resourceHarvestedCount = clean_str( $_GET['resourceHarvestedCount_' . $factionNumber] );
}
$playerName = "";
if ( isset( $_GET['playerName_' . $factionNumber] ) ) {
$playerName = (string) clean_str( $_GET['playerName_' . $factionNumber] );
}
$quitBeforeGameEnd = 0;
if ( isset( $_GET['quitBeforeGameEnd_' . $factionNumber] ) ) {
$quitBeforeGameEnd = clean_str( $_GET['quitBeforeGameEnd_' . $factionNumber] );
}
$quitTime = 0;
if ( isset( $_GET['quitTime_' . $factionNumber] ) ) {
$quitTime = clean_str( $_GET['quitTime_' . $factionNumber] );
}
$playerUUID = "";
if ( isset( $_GET['playerUUID_' . $factionNumber] ) ) {
$playerUUID = (string) clean_str( $_GET['playerUUID_' . $factionNumber] );
}
$playerPlatform = "";
if ( isset( $_GET['platform_' . $factionNumber] ) ) {
$playerPlatform = (string) clean_str( $_GET['platform_' . $factionNumber] );
}
if($player_statsCount[0] > 0)
{
$result = mysqli_query( Registry::$mysqliLink, 'UPDATE glestgameplayerstats SET ' .
'gameUUID=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $gameUUID ) . '\', ' .
'factionIndex=' . $factionIndex . ', ' .
'controlType=' . $controlType . ', ' .
'resourceMultiplier=' . $resourceMultiplier . ', ' .
'factionTypeName=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $factionTypeName ) . '\', ' .
'personalityType=' . $personalityType . ', ' .
'teamIndex=' . $teamIndex . ', ' .
'wonGame=' . $wonGame . ', ' .
'killCount=' . $killCount . ', ' .
'enemyKillCount=' . $enemyKillCount . ', ' .
'deathCount=' . $deathCount . ', ' .
'unitsProducedCount=' . $unitsProducedCount . ', ' .
'resourceHarvestedCount=' . $resourceHarvestedCount . ', ' .
'playerName=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $playerName ) . '\', ' .
'quitBeforeGameEnd=' . $quitBeforeGameEnd . ', ' .
'quitTime=' . $quitTime . ', ' .
'playerUUID=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $playerUUID ) . '\', ' .
'platform=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $playerPlatform ) . '\', ' .
'lasttime=' . 'now()' . ' ' .
'WHERE ' . $whereClause . ' AND factionIndex = ' . $factionIndex . ';');
if (!$result) {
die('part 1b: Invalid query: ' . mysql_error());
}
//echo 'OK1 $factionNumber = ' . $factionNumber;
echo 'OK1b' . $factionNumber;
}
else
{
$result = mysqli_query( Registry::$mysqliLink, 'INSERT INTO glestgameplayerstats SET ' .
'gameUUID=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $gameUUID ) . '\', ' .
'factionIndex=' . $factionIndex . ', ' .
'controlType=' . $controlType . ', ' .
'resourceMultiplier=' . $resourceMultiplier . ', ' .
'factionTypeName=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $factionTypeName ) . '\', ' .
'personalityType=' . $personalityType . ', ' .
'teamIndex=' . $teamIndex . ', ' .
'wonGame=' . $wonGame . ', ' .
'killCount=' . $killCount . ', ' .
'enemyKillCount=' . $enemyKillCount . ', ' .
'deathCount=' . $deathCount . ', ' .
'unitsProducedCount=' . $unitsProducedCount . ', ' .
'resourceHarvestedCount=' . $resourceHarvestedCount . ', ' .
'playerName=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $playerName ) . '\', ' .
'quitBeforeGameEnd=' . $quitBeforeGameEnd . ', ' .
'quitTime=' . $quitTime . ', ' .
'platform=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $playerPlatform ) . '\', ' .
'playerUUID=\'' . mysqli_real_escape_string(Registry::$mysqliLink, $playerUUID ) . '\';');
if (!$result) {
die('part 2b: Invalid query: ' . mysql_error());
}
//echo 'OK2 $factionNumber = ' . $factionNumber;
echo 'OK2b' . $factionNumber;
}
}
db_disconnect( Registry::$mysqliLink );
}
?>