This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
realmstatus.php
295 lines (242 loc) · 9.75 KB
/
realmstatus.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
294
295
<?php
/**
* WoWRoster.net WoWRoster
*
* Realmstatus Image generator
*
* @copyright 2002-2011 WoWRoster.net
* @license http://www.gnu.org/licenses/gpl.html Licensed under the GNU General Public License v3.
* @package WoWRoster
* @subpackage RealmStatus
*/
// WOW Server Status
// Version 3.2
// Copyright 2005 Nick Schaffner
// http://53x11.com
// EDITED BY: http://www.wowroster.net for use in wowroster
// Most other changes by Zanix
if( !defined('IN_ROSTER') )
{
define('IN_ROSTER', true);
}
$roster_root_path = dirname(__FILE__) . DIRECTORY_SEPARATOR;
require_once ($roster_root_path . 'settings.php');
require_once(ROSTER_LIB . 'simpleparser.class.php');
function statussw($status)
{
switch ($status)
{
case '0':
$q = 'error';
break;
case '1':
$q = 'up';
break;
case '2':
$q = 'down';
break;
case 'false':
$q = 'error';
break;
default:
break;
}
return $q;
}
//==========[ GET FROM CONF.PHP ]====================================================
if( isset($_GET['r']) )
{
list($region, $realmname) = explode('-', urldecode(trim(stripslashes($_GET['r']))), 2);
$region = strtoupper($region);
}
elseif( isset($realmname) )
{
list($region, $realmname) = explode('-', trim(stripslashes($realmname)), 2);
$region = strtoupper($region);
}
else
{
$realmname = '';
}
if( isset($_GET['d']) )
{
$generate_image = ($_GET['d'] == '0' ? false : true);
}
elseif( isset($roster->config['rs_display']) )
{
$generate_image = ($roster->config['rs_display'] == 'image' ? true : false);
}
else
{
$generate_image = true;
}
//piss the xml noise we are going json
//$xmlsource = 'http://wowfeeds.wipeitau.com/RealmStatus.php?location=' . $region . '&rn=' . $realmname . '&output=XML';
//$xmlsource = 'http://wowfeeds.wipeitau.com/RealmStatus.php?location=' . $region . '&rn=' . $realmname . '&callback=?';//'http://www.wowroster.net/realmstatus/'.$realmname.'.xml';
//'http://' . $region . '.battle.net/api/wow/realm/status?realm=' . $realmname . '';
//==========[ OTHER SETTINGS ]=========================================================
// Path to image folder
$image_path = ROSTER_BASE . 'img' . DIR_SEP . 'realmstatus' . DIR_SEP;
#--[ MYSQL CONNECT AND STORE ]=========================================================
// Read info from Database
$querystr = "SELECT * FROM `" . $roster->db->table('realmstatus') . "`"
. " WHERE `server_region` = '" . $roster->db->escape($region) . "'"
. " AND `server_name` = '" . $roster->db->escape($realmname) . "';";
$sql = $roster->db->query($querystr);
if( $sql && $roster->db->num_rows($sql) > 0 )
{
$realmData = $roster->db->fetch($sql, SQL_ASSOC);
}
else
{
$realmData['server_name'] = '';
$realmData['server_region'] = '';
$realmData['servertype'] = '';
$realmData['serverstatus'] = '';
$realmData['serverpop'] = '';
$realmData['timestamp'] = '0';
}
//==========[ STATUS GENERATION CODE ]=================================================
// Check timestamp, update when ready
$current_time = time();
if( $current_time >= ($realmData['timestamp'] + ($roster->config['rs_timer'] * 600)) )
{
//updating to the new api
//$xmlsource = $roster->api->Realm->getRealmStatus($realmname);
$xmlsource = $roster->api2->fetch('realmstatus',array('realm'=>$realmname));
$r = $xmlsource;
$d = $r['realms']['0'];
if( $d !== false )
{
$realmType = str_replace('(', '',$d['type']);
$realmType = str_replace(')', '',$realmType);
$realmData['server_region'] = $region;
$realmData['servertype'] = strtoupper($realmType);
$realmData['serverstatus'] = strtoupper(statussw($d['status']));
$realmData['serverpop'] = strtoupper($d['population']);
$err = 0;
}
else
{
$err = 1;
}
//==========[ WRITE INFO TO DATABASE ]=================================================
if( !$err ) // Don't write to DB if there has been an error
{
$values['servertype'] = $realmData['servertype'];
$values['serverstatus'] = $realmData['serverstatus'];
$values['serverpop'] = $realmData['serverpop'];
$values['timestamp'] = $current_time;
if( $realmname == $realmData['server_name'] )
{
$querystr = "UPDATE `" . $roster->db->table('realmstatus') . "`"
. " SET " . $roster->db->build_query('UPDATE', $values)
. " WHERE `server_name` = '" . $roster->db->escape($realmname) . "';";
}
else
{
$values['server_name'] = $realmname;
$values['server_region'] = $region;
$querystr = "INSERT INTO `" . $roster->db->table('realmstatus') . "` "
. $roster->db->build_query('INSERT', $values) . ";";
$realmData['server_name'] = $realmname;
}
$roster->db->query($querystr);
}
}
//==========[ "NOW, WHAT TO DO NEXT?" ]================================================
// Error control
if( $realmData['serverstatus'] == 'DOWN' || $realmData['serverstatus'] == 'MAINTENANCE' || $realmData['serverpop'] == 'N/A')
{
$realmData['serverstatus'] = 'DOWN';
$realmData['serverpop'] = 'OFFLINE';
$realmData['serverpopcolor'] = $roster->config['rs_color_error'];
}
// Check to see if data from the DB is non-existant
if( empty($realmData['serverstatus']) || empty($realmData['serverpop']) )
{
$err = 1;
}
else
{
$err = 0;
}
// Set to Unknown values upon error
if( $err )
{
$realmData['servertype'] = 'UNKNOWN';
$realmData['serverstatus'] = 'UNKNOWN';
$realmData['serverpop'] = 'NOSTATUS';
$realmData['serverpopcolor'] = $roster->config['rs_color_error'];
$realmData['servertypecolor'] = $roster->config['rs_color_error'];
$realmData['servertype'] = ($realmData['servertype'] != '' ? $realmData['servertype'] : '');
}
else
{
if( $realmData['serverpop'] == ' ' )
{
$realmData['serverpopcolor'] = $roster->config['rs_color_low'];
}
else
{
$realmData['serverpopcolor'] = $roster->config['rs_color_' . strtolower($realmData['serverpop'])];
}
$realmData['servertypecolor'] = $roster->config['rs_color_' . strtolower($realmData['servertype'])];
$realmData['serverpop'] = $realmData['serverpop'];
$realmData['servertype'] = ($realmData['servertype'] != '' ? $realmData['servertype'] : '');
}
// Generate image or text?
if( $generate_image )
{
img_output($realmData, $err, $image_path);
}
else
{
echo text_output($realmData);
}
return;
//==========[ TEXT OUTPUT MODE ]=======================================================
function text_output( $realmData )
{
global $roster;
// If there is no data, then we want to output blank text
$realmData['servertype'] = $realmData['servertype'] != '' ? $roster->locale->act['rs'][$realmData['servertype']] : $realmData['servertype'];
$outtext = '
<div style="position:relative;width:272px;height:35px;font-family:arial;font-weight:bold;background:transparent url(' . ROSTER_URL . $roster->config['img_url'] . 'realmstatus/background.png) no-repeat;">
<div style="position:absolute;width:272px;height:35px;background:transparent url(' . ROSTER_URL . $roster->config['img_url'] . 'realmstatus/' . strtolower($realmData['serverpop']) . '.png) no-repeat;">
<div style="position:absolute;bottom:-1px;left:30px;color:' . $roster->config['rs_color_server'] . ';' . ($roster->config['rs_color_shadow'] ? 'text-shadow:' . $roster->config['rs_color_shadow'] . ' 1px 1px 0;' : '') . 'font-size:24px;">' . $realmData['server_name'] . '</div>
<div style="position:absolute;bottom:3px;right:5px;color:' . $realmData['serverpopcolor'] . ';' . ($roster->config['rs_color_shadow'] ? 'text-shadow:' . $roster->config['rs_color_shadow'] . ' 1px 1px 0;' : '') . 'font-size:10px;">' . $roster->locale->act['rs'][$realmData['serverpop']] . '</div>
<div style="position:absolute;bottom:22px;left:35px;color:' . $realmData['servertypecolor'] . ';' . ($roster->config['rs_color_shadow'] ? 'text-shadow:' . $roster->config['rs_color_shadow'] . ' 1px 1px 0;' : '') . 'font-size:10px;">' . $realmData['servertype'] . '</div>
<div style="position:absolute;bottom:2px;left:1px;width:32px;height:32px;background:transparent url(' . ROSTER_URL . $roster->config['img_url'] . 'realmstatus/' . strtolower($realmData['serverstatus']) . '-icon.png) no-repeat;"></div>
</div>
</div>
';
return $outtext;
}
//==========[ IMAGE GENERATOR ]========================================================
function img_output( $realmData , $err , $image_path )
{
global $roster;
$vadj = 0;
$serverfont = $roster->config['rs_font_server'];
$typefont = $roster->config['rs_font_type'];
$serverpopfont = $roster->config['rs_font_pop'];
require(ROSTER_LIB . 'roster_gd.php');
$roster_gd = new RosterGD();
$shadow = array('color' => $roster->config['rs_color_shadow'], 'distance' => 1, 'direction' => 45, 'spread' => 1);
$bkg_img = ROSTER_BASE . 'img' . DIR_SEP . 'realmstatus' . DIR_SEP . 'background.png';
$pop_img = ROSTER_BASE . 'img' . DIR_SEP . 'realmstatus' . DIR_SEP . strtolower($realmData['serverpop']) . '.png';
$arrow_img = ROSTER_BASE . 'img' . DIR_SEP . 'realmstatus' . DIR_SEP . strtolower($realmData['serverstatus']) . '-icon.png';
$bkg_img_info = getimagesize($bkg_img);
$roster_gd->make_image($bkg_img_info[0], $bkg_img_info[1]);
$roster_gd->combine_image($bkg_img, 0, 0);
// If there is no data, then we want to output blank text
$realmData['servertype'] = $realmData['servertype'] != '' ? $roster->locale->act['rs'][$realmData['servertype']] : $realmData['servertype'];
$roster_gd->write_text($roster->config['rs_size_type'], 0, 30, 8, $realmData['servertypecolor'], 0, $typefont, $realmData['servertype'], 'left', array(), $shadow);
$roster_gd->write_text($roster->config['rs_size_pop'], 0, 267, 30, $realmData['serverpopcolor'], 0, $serverpopfont, $roster->locale->act['rs'][$realmData['serverpop']], 'right', array(), $shadow);
$roster_gd->write_text($roster->config['rs_size_server'], 0, 30, 30, $roster->config['rs_color_server'], 0, $serverfont, $realmData['server_name'], 'left', array(), $shadow);
$roster_gd->combine_image($pop_img, 0, 0);
$roster_gd->combine_image($arrow_img, 1, 1);
$roster_gd->get_image('png');
$roster_gd->finish();
}