-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunc.php
More file actions
176 lines (137 loc) · 3.87 KB
/
Copy pathfunc.php
File metadata and controls
176 lines (137 loc) · 3.87 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
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
<?php
class DBLayer
{
public $link_id;
public $query_result;
public $saved_queries = array();
public $num_queries = 0;
public function __construct($db_host, $db_username, $db_password, $db_name)
{
$db_port = 3306;
// Accept both "host" and "host:port" in the config file.
// Required when PlayerMap runs inside the PHP-FPM Docker container:
// 127.0.0.1 is the container itself, not the host MySQL server.
if (strpos($db_host, ':') !== false) {
list($db_host, $db_port) = explode(':', $db_host, 2);
$db_port = (int) $db_port;
}
$this->link_id = mysqli_connect($db_host, $db_username, $db_password, $db_name, $db_port);
if ($this->link_id) {
mysqli_set_charset($this->link_id, 'utf8');
} else {
$this->link_id = false;
}
}
public function isValid()
{
return $this->link_id;
}
public function query($sql)
{
if (!$this->link_id) {
return false;
}
$this->query_result = mysqli_query($this->link_id, $sql);
if ($this->query_result) {
++$this->num_queries;
return $this->query_result;
} else {
return false;
}
}
public function result($query_id = 0, $row = 0)
{
return ($query_id) ? mysqli_result($query_id, $row) : false;
}
public function fetch_assoc($query_id = 0)
{
return ($query_id) ? mysqli_fetch_assoc($query_id) : false;
}
public function fetch_row($query_id = 0)
{
return ($query_id) ? mysqli_fetch_row($query_id) : false;
}
public function num_rows($query_id = 0)
{
return ($query_id) ? mysqli_num_rows($query_id) : false;
}
public function affected_rows()
{
return ($this->link_id) ? mysqli_affected_rows($this->link_id) : false;
}
public function insert_id()
{
return ($this->link_id) ? mysqli_insert_id($this->link_id) : false;
}
public function get_num_queries()
{
return $this->num_queries;
}
public function get_saved_queries()
{
return $this->saved_queries;
}
public function free_result($query_id = false)
{
return ($query_id) ? mysqli_free_result($query_id) : false;
}
public function escape($str)
{
if (function_exists('mysqli_real_escape_string')) {
return mysqli_real_escape_string($str, $this->link_id);
} else {
return mysqli_escape_string($str);
}
}
public function error()
{
$result['error_sql'] = @current(@end($this->saved_queries));
$result['error_no'] = $this->link_id ? mysqli_errno($this->link_id) : mysqli_errno();
$result['error_msg'] = $this->link_id ? mysqli_error($this->link_id) : mysqli_error();
return $result;
}
public function close()
{
if ($this->link_id) {
if ($this->query_result) {
mysqli_free_result($this->query_result);
}
return mysqli_close($this->link_id);
} else {
return false;
}
}
}
function error($message)
{
$s = 'Error: <strong>'.$message.'.</strong>';
echo $s;
}
function sort_players($a, $b)
{
if ($a['leaderGuid'] == $b['leaderGuid']) {
return strcmp($a['name'], $b['name']);
}
return ($a['leaderGuid'] < $b['leaderGuid']) ? -1 : 1;
}
function get_zone_name($zone_id)
{
global $zones;
$zname = 'Unknown zone';
if (isset($zones[$zone_id])) {
$zname = $zones[$zone_id];
}
return $zname;
}
function test_realm()
{
//return true; //always run
global $server, $port;
$s = @fsockopen("$server", $port, $ERROR_NO, $ERROR_STR, (float)0.5);
if ($s) {
@fclose($s);
return true;
} else {
return false;
}
}