-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVoxelTurfStatus.php
More file actions
40 lines (33 loc) · 1.01 KB
/
VoxelTurfStatus.php
File metadata and controls
40 lines (33 loc) · 1.01 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
<?php
class VoxelTurfStatus {
public function fromFile($file) {
$handle = fopen($file, 'r');
if (!$handle)
throw new Exception('File does not exist or could not be read');
while (($line = fgets($handle)) !== false) {
// Return the first line that isn't a comment
if (substr($line, 0, 1) != '#') {
fclose($handle);
return $this->fromString($line);
}
}
throw new Exception('Incorrect file format');
}
public function fromString($status) {
$status = explode(' ; ', $status);
if (count($status) != 8)
throw new Exception('Incorrect format: number of columns is ' . count($status) . ' when it should be 8');
$this->timestamp = $status[0];
$this->serverId = $status[1];
$this->players = $status[2];
$this->maxPlayers = $status[3];
$this->public = $status[4] == 'true';
$this->serverName = trim($status[5], '" ');
$this->gameMode = trim($status[6], '" ');
$this->version = $status[7];
return $this;
}
public function isOnline() {
return time() - $this->timestamp < 35;
}
}