-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathQ3.class.php
87 lines (80 loc) · 1.75 KB
/
Q3.class.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
<?php
namespace phpRcon\games;
use phpRcon\games\engine\Quake3Engine;
/**
* Quake 3
*
* @author Jan Altensen (Stricted)
* @copyright 2013-2014 Jan Altensen (Stricted)
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/
class Q3 extends Quake3Engine {
/**
* get players from gameserver
*
* @return array
*/
public function getPlayers () {
if (empty($this->data2)) {
$this->data2 = $this->command("\xFF\xFF\xFF\xFFgetstatus\x00");
}
$data = $this->data2;
$players = array();
for ($i=2; $i<=count($data); $i++) {
if (!empty($data[$i])) {
$tmp = explode(" ", $data[$i], 3);
$player = array();
preg_match('/"([\s\S]+)"/i', $tmp[2], $match);
$player['name'] = $this->stripColors($match[1]);
$player['score'] = $tmp[0];
$player['ping'] = $tmp[1];
$players[] = $player;
}
}
return $players;
}
/**
* get maxplayers from gameserver
*
* @return integer
*/
public function getMaxPlayers () {
$data = $this->getServerData();
return $data['sv_maxclients'];
}
/**
* get player count from server
*
* @return integer
*/
public function getCurrentPlayerCount () {
return count($this->getPlayers());
}
/**
* get current map from gameserver
*
* @return string
*/
public function getCurrentMap () {
$data = $this->getServerData();
return $data['mapname'];
}
/**
* get current game mode from gameserver
*
* @return string
*/
public function getCurrentMode () {
$data = $this->getServerData();
return $data['g_gametype'];
}
/**
* get server name from gameserver
*
* @return string
*/
public function getServerName () {
$data = $this->getServerData();
return $this->stripColors($data['sv_hostname']);
}
}