-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathserver.php
executable file
·293 lines (260 loc) · 9.11 KB
/
server.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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<?php
include 'core/init.php';
include 'includes/overall/header.php';
$server_id = (INT)$_GET['id'];
$user_id = id_to_user_id($server_id);
$addedBy = username_from_user_id($user_id);
if(empty($_GET['id']) == true || $addedBy == false){
echo "<h2>Server not found.</h2>";
include 'includes/overall/footer.php';
die();
}
$result = $database->query("SELECT `id`, `game`, `country`, `user_id`, `ip`, `port`, `vip`, `status`, `cache_time`, `votes` FROM `servers` WHERE `id` = '$server_id'");
$server_data = $result->fetch_assoc();
$last_update = time() - $server_data['cache_time'];
$last_updateM = intval($last_update/60);
try {
$Query = new LiveStats($server_data['ip'], $server_data['port']);
$info = $Query->GetServer();
}
catch (LSError $e) {}
if(empty($e)){ $status = 1; } else { $status = 0; }
if($status == 1) {
$database->query("UPDATE `servers` SET `map` = '{$info->Map}', `players` = '{$info->PlayerCount}', `maxPlayers` = '{$info->MaxPlayers}' WHERE `id` = '$server_id'");
}
$database->query("UPDATE `servers` SET `cache_time` = unix_timestamp(), `status` = '$status' WHERE `id` = '$server_id'");
?>
<div id="sid" data-sid="<?php echo $server_data['id']; ?>" style='margin:auto;'>
<?php
if($status == 0){
echo "<h2>" . $server_data['ip'] . " is offline!<h2>";
} else { ?>
<center><h2><?php echo $server_data['ip']; ?></h2></center>
<ul class="nav nav-pills" id="tabs" >
<li class="active"><a href="#info"><i class="icon-signal"></i> Server Informations</a></li>
<li><a href="#banners"><i class="icon-picture"></i> Banners</a></li>
<li><a href="#rules"><i class="icon-tag"></i> Rules</a></li>
<li><a href="#players"><i class="icon-user"></i> Players</a></li>
</ul>
<div class="tab-content" >
<div class="tab-pane active" id="info">
<table class="table table-striped" style="background:white;">
<tr>
<td><strong>Status</strong></td>
<td><span class="badge badge-success"><i class="icon-ok icon-white"></i></span></td>
</tr>
<tr>
<td><strong>Hostname</strong></td>
<td><?php echo $info->Hostname; ?></td>
</tr>
<tr>
<td><strong>IP Address</strong></td>
<td><?php echo gethostbyname($server_data['ip']); ?></td>
</tr>
<tr>
<td><strong>Port</strong></td>
<td><?php echo $server_data['port']; ?></td>
</tr>
<tr>
<td><strong>Online Players</strong></td>
<td><?php echo $info->PlayerCount . "/" . $info->MaxPlayers; ?></td>
</tr>
<?php if($server_data['game'] !== "samp") { ?>
<tr>
<td><strong>Protocol</strong></td>
<td><?php echo $info->ProtocolVersion; ?></td>
</tr>
<tr>
<td><strong>Game</strong></td>
<td><?php echo $info->Description; ?></td>
</tr>
<tr>
<td><strong>Bots</strong></td>
<td><?php echo $info->BotCount; ?></td>
</tr>
<tr>
<td><strong>OS</strong></td>
<td><?php echo $info->OS; ?></td>
</tr>
<tr>
<td><strong>Secured</strong></td>
<td><?php echo ($info->Secured == 1) ? "Yes":"No"; ?></td>
</tr>
<tr>
<td><strong>Connect</strong></td>
<td><a href="steam://connect/<?php echo $server_data['ip'] . ":" . $server_data['port']; ?>"><img src="includes/img/steam.png" alt="Connect" /> Steam</a></td>
</tr>
<?php } ?>
<tr>
<td><strong>Map</strong></td>
<td><?php echo $info->Map; ?></td>
</tr>
<tr>
<td><strong>Country</strong></td>
<td><img src="includes/locations/<?php echo $server_data['country']; ?>.png" title="<?php echo $server_data['country']; ?>" alt="country"/></td>
</tr>
<tr>
<td><strong>Added by</strong></td>
<td><a href="profile-<?php echo $addedBy; ?>"><?php echo $addedBy; ?></a></td>
</tr>
<tr>
<td><strong>Last update</strong></td>
<td><?php echo $last_updateM; ?> minutes ago</td>
</tr>
<tr>
<td><strong>Votes</strong></td>
<td>
<div id="votes" style="display:inline;"><?php echo $server_data['votes']; ?></div> <input type="button" class="btn" id="vote" value="Vote server !">
</td>
</tr>
</table>
</div>
<div class="tab-pane" id="banners">
<?php
$domain = $_SERVER['HTTP_HOST'];
$folder = basename(dirname(__FILE__));
$link = "http://" . $domain ."/".$folder;
?>
<img src="dynamic_image.php?s=<?php echo $server_id; ?>&type=background" />
<h3>BB/HTML Code </h3>
<textarea id="bb_small_code" rows="3" style="width: 95%;">[url=<?php echo $link; ?>/server.php?id=<?php echo $id; ?>][img]<?php echo $link; ?>/dynamic_image.php?s=<?php echo $id; ?>&type=background[/img][/url]</textarea>
<textarea id="html_small_code" rows="3" style="width: 95%;"><a href="<?php echo $link; ?>/server.php?id=<?php echo $id; ?>"><img src="<?php echo $link; ?>/dynamic_image.php?s=<?php echo $id; ?>&type=background"></a></textarea>
</div>
<div class="tab-pane" id="rules">
<table class="table table-bordered" style="background:white;">
<thead>
<th>Name</th>
<th>Value</th>
</thead>
<tbody>
<?php
foreach($info->Rules as $key => $value) {
echo "<tr><td><strong>" . $key . "</strong></td><td>" . $value . "</td></tr>";
}
?>
</tbody>
</table>
</div>
<div class="tab-pane" id="players">
<table class="table table-condensed">
<thead>
<th>Name</th>
<th>Score</th>
<th>Time</th>
</thead>
<tbody>
<?php
foreach($info->Players as $player){
echo "
<tr>
<td>{$player->Name}</td>
<td>{$player->Score}</td>
<td>{$player->TimePlayed}</td>
</tr>";
}
?>
</tbody>
</table>
</div>
</div>
<?php } ?>
</div>
<h2>Comments</h2>
<?php
$query = $database->query("SELECT * FROM `comments` WHERE `server_id` = '$server_id'");
if($query->num_rows){
echo "<p>This server doesn't have any comments added</p>";
}
while($row = $query->fetch_assoc()){
$comment_user_id = $row['user_id'];
@$comment_added_by = $database->query("SELECT `username` FROM `users` WHERE `user_id` = '$comment_user_id'")->fetch_object()->username ? $database->query("SELECT `username` FROM `users` WHERE `user_id` = '$comment_user_id'")->fetch_object()->username : "Unknown User";
?>
<table class="table table-bordered" style="background:white;">
<tr>
<td>
<strong>Comment by:</strong> <?php echo $comment_added_by; ?>
<?php if(logged_in() == true && is_admin($session_user_id)){ ?>
<div class="pull-right">
<a href="server.php?id=<?php echo $server_id; ?>&delete=<?php echo $row['id']; ?>">
<img alt='' src='includes/img/delete.png' title='Delete comment' />
</a>
</div>
<?php } ?>
</td>
</tr>
<tr>
<td><?php echo $row['comment']; ?></td>
</tr>
</table>
<?php } ?>
<br /><br />
<?php
if(empty($_POST) == false){
//captcha
include_once "core/functions/securimage.php";
$securimage = new Securimage();
$valid = $securimage->check($_POST['captchavar']);
//-------
if($valid == false) {
$errors[] = 'Please enter the correct captcha code!';
}
if(strlen($_POST['comment']) > 254){
$errors[] = 'Comment too long, maximum 255 characters!';
}
if(strlen(trim($_POST['comment'])) < 10){
$errors[] = 'Comment too short, minimum 10 characters!';
}
if(empty($errors) == true){
$comment = htmlspecialchars($_POST['comment'], ENT_QUOTES);
$database->query("INSERT INTO `comments` (`server_id`, `user_id`, `comment`) VALUES ('$server_id', '$session_user_id', '$comment')");
echo "Congratulations, your comment was submitted !";
}else{
echo output_errors($errors);
}
}
?>
<?php if(logged_in() == true){ ?>
<form action="" method="post">
<textarea style="width:100%;height:100px;" name="comment"></textarea><br />
<img class="img-polaroid" id="captcha" title="Captcha" src="core/functions/securimage_show.php" alt="CAPTCHA Image" />
<input class="span2" type="text" style="text-transform:uppercase;" name="captchavar" id="captchavar" size="11" maxlength="4" placeholder="captcha" /><br /><br />
<input type="submit" class="btn btn-primary" value="Add comment" />
</form>
<?php } ?>
<?php
if(empty($_GET['delete']) == false && logged_in() && is_admin($session_user_id)){
$comment_id = (INT)$_GET['delete'];
$database->query("DELETE FROM `comments` WHERE `id` = '$comment_id'");
header('Location: server.php?id=' . $server_id);
}
?>
<script type="text/javascript">
$(document).ready(function(){
$('#vote').click(function(){
$.ajax({
url : 'vote_updater.php',
type : 'POST',
data : {
action : 'vote_server',
sid : $('#sid').data('sid')
},
dataType : 'JSON',
success : function(result) {
if (result.xhr == 'success') {
$('#vote').attr('disabled','true');
$('#votes').html(parseInt($('#votes').html()) + 1);
alert('Succesfully voted !');
} else if (result.xhr == 'voted_already')
alert('You already voted this server !')
else if (result.xhr == 'not_logged_in')
alert('You must be logged in to vote !')
}
});
});
});
$('#tabs a').click(function (e) {
e.preventDefault();
$(this).tab('show');
})
</script>
<?php include 'includes/overall/footer.php'; ?>