forked from nikkiii/gsquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gsquery.php
67 lines (60 loc) · 1.51 KB
/
gsquery.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
<?php
require_once 'protocol.php';
class GSQuery {
function create($type, $info) {
$className = ucfirst($type);
$file = dirname(__FILE__) . '/query/' . $type . '.php';
if(file_exists($file)) {
require_once $file;
$instance = new $className($info);
return $instance;
}
return false;
}
}
/**
* Subclass parent (Which handles the calls going to the protocol class)
*
* @author Nikki
*
*/
class GSQuery_Parent {
public function queryInfo() {
error_log('GSQuery subtype does not support queryInfo()');
}
public function queryPlayers() {
error_log('GSQuery subtype does not support queryPlayers()');
}
public function queryRcon($command) {
error_log('GSQuery subtype does not support queryRcon()');
}
/**
* Initialize a protocol
* @param string $name The protocol name (File name)
* @param array $data The protocol settings
*/
protected function initializeProtocol($name, $data) {
$className = ucfirst($name);
$file = dirname(__FILE__) . '/protocol/' . $name . '.php';
if(file_exists($file)) {
require_once $file;
$instance = new $className($data);
return $instance;
}
throw new Exception("Invalid protocol : " . $name);
}
/**
* Copy settings from one array to another
* @param array $arr The source
* @param array $target The target
* @param array $keys The keys to copy
*/
protected function copySettings($arr, &$target, $keys) {
foreach($keys as $key) {
if(isset($arr[$key]) && empty($target[$key])) {
$target[$key] = $arr[$key];
}
}
}
}
?>