This repository was archived by the owner on Nov 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
104 lines (85 loc) · 4.71 KB
/
index.php
File metadata and controls
104 lines (85 loc) · 4.71 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
101
102
103
104
<?php
// Security headers
header('X-Content-Type-Options: nosniff');
header("Content-Security-Policy: default-src 'none'; style-src 'self'; img-src 'self'; base-uri 'none'; frame-ancestors 'none'; form-action 'none'");
header('Cross-Origin-Embedder-Policy: require-corp');
header('Cross-Origin-Opener-Policy: same-origin');
header('Cross-Origin-Resource-Policy: same-origin');
// Privacy headers
header('Referrer-Policy: no-referrer');
header('X-DNS-Prefetch-Control: off');
// Shared code
require 'all_shared.php';
// https://stackoverflow.com/a/37213574
$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
// Set the server URL. HTTP_HOST will contain both the host and port if the port is not the default for the protocol
$server_url = $protocol.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
// Before going through servers delete the old ones
delete_old_servers();
// Initialize current_servers and current_players
$current_servers = 0;
$current_players = 0;
$server_list = '';
// Select ip, port, name, game_started, current_players, max_players, password_required from all servers in database https://www.phptutorial.net/php-pdo/php-fetchall/
$stmt = $db->prepare('SELECT ip, port, name, game_started, current_players, max_players, password_required FROM servers');
$stmt->execute();
$servers = $stmt->fetchAll();
// For each server we process increment current_servers and add the server's current_players to the current_players variable
foreach ($servers as $row)
{
$current_servers++;
$current_players += $row['current_players'];
/* If password is required or the game is started set then set their states to " checked" so the checkbox is checked and has a space between it and disabled.
If they aren't then set the state to an empty string so that box is unchecked.
https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary */
$password_required_state = ($row['password_required'] == 1) ? ' checked' : '';
$game_started_state = ($row['game_started'] == 1) ? ' checked' : '';
// PHP_EOL and \t (tab) are there to keep the HTML nicely formatted
// htmlspecialchars() prevents XSS
$server_list .= '<tr><td><input type="checkbox" disabled'.$password_required_state.'></td><td>'.htmlspecialchars($row['name']).'</td><td>'.$row['current_players'].'/'.$row['max_players'].'</td><td>'.'<input type="checkbox" disabled'.$game_started_state.'></td><td>'.$row['ip'].':'.$row['port'].'</td></tr>'.PHP_EOL."\t";
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>BaroMaster</title>
<meta name="description" content="A Barotrauma Legacy Master Server replacement.">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Discord embeds https://stackoverflow.com/questions/59335731/how-to-create-own-embed-site-for-discord -->
<meta content="BaroMaster" property="og:title" />
<meta content="A Barotrauma Legacy Master Server replacement." property="og:description" />
<meta content="<?=$server_url?>" property="og:url" />
<!-- Preload our stylesheet -->
<link rel="preload" href="style.css?v=1.1.0" as="style">
<!-- Our stylesheet -->
<link rel="stylesheet" href="style.css?v=1.1.0">
</head>
<body>
<main>
<h1>Barotrauma Legacy Master Server</h1>
<div><p>The master server controls the in game server list, without it you need an outside way of discovering servers to know the IP and the port to join. To use this master server replacement and discover servers through the game, edit <strong>config.xml</strong> inside of your Barotrauma Legacy folder and change the value of <strong>masterserverurl</strong> so that it looks like <strong>masterserverurl=<?=$server_url?></strong></p></div>
<div><p>There are currently <?=$current_servers?> online servers that contain a total of <?=$current_players?> players.</p></div>
<div id="server_list">
<table>
<tr>
<th>Password</th>
<th>Name</th>
<th>Players</th>
<th>Round started</th>
<th>Connection info</th>
</tr>
<?php
/* If we have servers echo them, otherwise echo that there's none.
PHP_EOL and \t (tab) are there to keep the HTML nicely formatted */
if ($current_servers > 0) {
echo $server_list.'</table>'.PHP_EOL;
} else {
echo '</table>'.PHP_EOL."\t<p>Could not find any servers.</p>".PHP_EOL;
}
?>
</div>
<div><p>This master server's source code can be found at <a href="https://github.com/ButteredCats/BaroMaster" target="_blank">https://github.com/ButteredCats/BaroMaster</a></p></div>
</main>
</body>
</html>