This repository has been archived by the owner on Jan 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
masterserver3.php
55 lines (50 loc) · 1.96 KB
/
masterserver3.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
<?php
define('NON_DIRECT', true);
require 'database.php';
$action = $_GET['action'];
switch($action) {
case 'addserver':
if($stmt = $db->prepare("REPLACE INTO server_list(servername, serverip, serverport, currplayers, maxplayers, password, version, contentpackage) VALUES(?, ?, ?, ?, ?, ?, ?, ?)")) {
$stmt->bind_param('ssiiiiss', $servername, $serverip, $serverport, $currplayers, $maxplayers, $password, $version, $contentpackage);
$servername = $_GET['servername'] ?? 'Untitled Server';
$serverip = $_SERVER['REMOTE_ADDR'];
$serverport = $_GET['serverport'] ?? 14242;
$currplayers = $_GET['currplayers'] ?? 0;
$maxplayers = $_GET['maxplayers'] ?? 10;
$password = $_GET['password'] ?? 0;
$version = $_GET['version'] ?? 'Unknown';
$contentpackage = $_GET['contentpackage'] ?? 'Unknown';
if($stmt->execute()) {
http_response_code(200);
} else {
http_response_code(422);
}
} else {
http_response_code(500);
}
break;
case 'refreshserver':
if($stmt = $db->prepare('UPDATE server_list SET gamestarted=?, currplayers=?, maxplayers=?, timelisted=CURRENT_TIMESTAMP WHERE serverip=? AND serverport=?')) {
$stmt->bind_param('iiisi', $gamestarted, $currplayers, $maxplayers, $serverip, $serverport);
$gamestarted = $_GET['gamestarted'] ?? 0;
$currplayers = $_GET['currplayers'] ?? 0;
$maxplayers = $_GET['maxplayers'] ?? 10;
$serverip = $_SERVER['REMOTE_ADDR'];
$serverport = $_GET['serverport'] ?? 14242;
if($stmt->execute()) {
if($stmt->affected_rows == 0) {
echo 'Error: server not found';
}
http_response_code(200);
} else {
http_response_code(422);
}
} else {
http_response_code(500);
}
break;
default:
http_response_code(400);
break;
}
?>