source: trunk/inc/server.php@ 624

Last change on this file since 624 was 624, checked in by george, 16 years ago
  • Opraveno: Posunutý dolní obrázek pozadí v prohlížeči IE.
  • Přidáno: Tabulka seznamu odměn za dotace se načítá nyní z databáze.
File size: 14.2 KB
Line 
1<?php
2
3function NullErrorHandler()
4{
5}
6
7class Server
8{
9 private $db;
10
11 public function __construct($db)
12 {
13 $this->db = $db;
14 }
15
16 public function HumanDate($date, $time = 1)
17 {
18 // input date is 0000-00-00 00:00:00
19 $date_arr = explode(' ', $date);
20 $date = explode('-', $date_arr[0]);
21 $time_stp = explode(':', $date_arr[1]);
22 $time = mktime($time_stp[0], $time_stp[1], $time_stp[2], $date[1], $date[2], $date[0]);
23 if($time == 1) $human_date = date('d.m.Y H:i:s', $time);
24 else $human_date = date('d.m.Y', $time);
25 return($human_date);
26 }
27
28 public function RealmOnline()
29 {
30 global $Config;
31
32 $this->db->select_db($Config['Mangos']['DatabaseRealmd']);
33 $DbResult = $this->db->query('SELECT COUNT(*) FROM `account` WHERE `online` = 1');
34 $DbRow = $DbResult->fetch_row();
35 return($DbRow[0]);
36 }
37
38 public function ParseCopper($copper_in)
39 {
40 $copper = $copper_in;
41 $golds = floor($copper / 10000);
42 $num = $copper - $golds * 10000;
43 $silver = floor($num / 100);
44 $copper = $num - $silver * 100;
45 $show_golds = '<font size="4">'.$golds.'</font>&nbsp;<img src="imgs/inc/g.gif">';
46 $show_silver = '<font size="4">'.$silver.'</font>&nbsp;<img src="imgs/inc/s.gif">';
47 $show_copper = '<font size="4">'.$copper.'</font>&nbsp;<img src="imgs/inc/c.gif">';
48 return($show_golds.'&nbsp;'.$show_silver.'&nbsp;'.$show_copper);
49 }
50
51 public function MangosOnline($RealmId)
52 {
53 global $Config;
54
55 $this->db->select_db($Config['Mangos']['RealmList'][$RealmId]['DatabaseCharacters']);
56 $DbResult = $this->db->query('SELECT COUNT(*) FROM `characters` WHERE `online` = 1');
57 $DbRow = $DbResult->fetch_row();
58 return($DbRow[0]);
59 }
60
61 public function ServerMangosOnline()
62 {
63 global $Config;
64
65 $TotalCount = 0;
66 foreach($Config['Mangos']['RealmList'] as $Index => $Realm)
67 {
68 $TotalCount += $this->MangosOnline($Index);
69 }
70 return($TotalCount);
71 }
72
73 public function ServerOnline($Address, $Port, $Timeout = 0.5)
74 {
75 set_error_handler('NullErrorHandler');
76 if($Socket = @fsockopen($Address, $Port, $ERROR_NO, $ERROR_STR, (float)$Timeout))
77 {
78 fclose($Socket);
79 $Result = true;
80 } else $Result = false;
81 restore_error_handler();
82 return($Result); }
83
84 public function ServerImg($status)
85 {
86 if($status) return('<img src="imgs/inc/on.gif" alt="online" />&nbsp;<span style="text-color: #234303; text-size: 4;">Online</span>');
87 else return('<img src="imgs/inc/off.gif" alt="offline" />&nbsp;<span style="text-color: #990000; text-size: 4;">Offline</span>');
88 }
89
90 public function ServerUptime()
91 {
92 global $Config;
93
94 $this->db->select_db($Config['Mangos']['DatabaseRealmd']);
95 $row = $this->db->query('SELECT `starttime`, `uptime` FROM `uptime` ORDER BY `starttime` DESC LIMIT 1')
96 ->fetch_array();
97 $uptime = round($row['uptime'] / 3600);
98 return($uptime);
99 }
100
101 public function CharacterCount($RealmId)
102 {
103 global $Config;
104
105 $this->db->select_db($Config['Mangos']['RealmList'][$RealmId]['DatabaseCharacters']);
106 $DbResult = $this->db->query('SELECT COUNT(*) FROM `characters`');
107 $DbRow = $DbResult->fetch_row();
108 return($DbRow[0]);
109 }
110
111 public function ServerCharacterCount()
112 {
113 global $Config;
114
115 $TotalCount = 0;
116 foreach($Config['Mangos']['RealmList'] as $Index => $Realm)
117 {
118 $TotalCount += $this->CharacterCount($Index);
119 }
120 return($TotalCount);
121 }
122
123 public function AccountCount()
124 {
125 global $Config;
126
127 $this->db->select_db($Config['Mangos']['DatabaseRealmd']);
128 $row = $this->db->query('SELECT COUNT(*) FROM account')->fetch_row();
129 return($row[0]);
130 }
131
132 public function GuidToCharName($guid)
133 {
134 global $Config;
135
136 $this->db->select_db($Config['Mangos']['RealmList'][$_COOKIE['RealmIndex']]['DatabaseCharacters']);
137 $row = $this->db->query('SELECT `name` FROM `characters` WHERE `guid` = "'.$guid.'" LIMIT 1')->fetch_array();
138 return($row['name']);
139 }
140
141 public function ShowGmLog($log)
142 {
143 echo('<table border="1" width="540">'.
144 '<tr>
145 <th>Čas</th>
146 <th>GM</th>
147 <th>Příkaz</th>
148 <th>Vybrán</th>
149 </tr>');
150 $gm_log = ereg_replace("\n",";",$log);
151 $gm_log = explode(";",$gm_log);
152 $gm_log = array_reverse($gm_log);
153 foreach($gm_log as $row)
154 {
155 if (strpos($row,"Command:") == true)
156 {
157 $edited = str_replace(" Command: ", ";", $row); // 0 - time
158 $edited = str_replace(" (Account: ", ";", $edited); // 1 - command
159 $edited = str_replace(" [Player: ", ";", $edited); // 2 - gm
160 $edited = str_replace(" Selected: ", ";", $edited); // 3 - position
161 $edited = str_replace(" (GUID: ", ";", $edited); // 4 - selected
162 $edited = str_replace(")]", ";", $edited); // 5 - selected guid
163 $edited_arr = explode(";",$edited);
164 if($edited_arr[4] == "player") $sel_name = " - ".$this -> GuidToCharName($edited_arr[5]);
165 else $sel_name = '';
166 $human_date = $this -> HumanDate ($edited_arr[0]);
167 echo('<tr>
168 <td><font size="2">'.$human_date.'</font></td>
169 <td>'.$edited_arr[2].'</td>
170 <td>'.$edited_arr[1].'</td>
171 <td>'.$edited_arr[4].$sel_name.'</td>
172 </tr>');
173 }
174 if(strpos($row, 'mail item:') == true)
175 {
176 $edited = str_replace(" GM ", ";", $row);
177 $edited = str_replace(" (Account: ", ";", $edited);
178 $edited = str_replace(") mail item: ", ";", $edited);
179 $edited = str_replace(" (Account: ", ";", $edited);
180 $edited = str_replace(")", "", $edited);
181 $edited_arr = explode(";",$edited);
182 $human_date = $this -> HumanDate ($edited_arr[0]);
183 echo('<tr>
184 <td><font size="2">'.$human_date.'</font></td>
185 <td>'.$edited_arr[1].'</td>
186 <td>Send : '.$edited_arr[3].')</td>
187 <td>-</td>
188 </tr>');
189 }
190 if(strpos($row,"trade:") == true)
191 {
192 $edited = str_replace(" GM ", ";", $row);
193 $edited = str_replace(" (Account: ", ";", $edited);
194 $edited = str_replace(") trade: ", ";", $edited);
195 $edited = str_replace(" (Account: ", ";", $edited);
196 $edited = str_replace(")", "", $edited);
197 $edited_arr = explode(";",$edited);
198
199 $human_date = $this -> HumanDate ($edited_arr[0]);
200 echo('<tr>
201 <td><font size="2">'.$human_date.'</font></td>
202 <td>'.$edited_arr[1].'</td>
203 <td>Trade : '.$edited_arr[3].')</td>
204 <td>-</td>
205 </tr>');
206 }
207 }
208 echo('</table>');
209 }
210
211 public function SeoUrl($title)
212 {
213 $address = $title;
214 $diakritika = array("á","ä","č","ď","é","ě","ë","í","ň","ó","ö","ř","š","ť","ú","ů","ü","ý","ž","Á","Ä","Č","Ď","É","Ě","Ë","Í","Ň","Ó","Ö","Ř","Š","Ť","Ú","Ů","Ü","Ý","Ž");
215 $nediakritika = array("a","a","c","d","e","e","e","i","n","o","o","r","s","t","u","u","u","y","z","A","A","C","D","E","E","E","I","N","O","O","R","S","T","U","U","U","Y","Z");
216 $address = str_replace($diakritika, $nediakritika, $address);
217 $address = strtolower ($address);
218 $address = preg_replace ("/[^[:alpha:][:digit:]]/", "-", $address);
219 $address = trim ($address, "-");
220 $address = preg_replace ("/[-]+/", "-", $address);
221 return($address);
222 }
223
224 public function MapName($id)
225 {
226 $map_id = Array
227 (
228 0 => array(0,"Azeroths"),
229 1 => array(1,"Kalimdor"),
230 13 => array(13,"Test Zone"),
231 17 => array(17,"Kalidar"),
232 30 => array(30,"Alterac Valley"),
233 33 => array(33,"Shadowfang Keep Instance"),
234 34 => array(34,"The Stockade Instance"),
235 35 => array(35,"Stormwind Prison"),
236 36 => array(36,"Deadmines Instance"),
237 37 => array(37,"Plains of Snow"),
238 43 => array(43,"Wailing Caverns Instance"),
239 44 => array(44,"Monastery Interior"),
240 47 => array(47,"Razorfen Kraul Instance"),
241 48 => array(48,"Blackfathom Deeps Instance"),
242 70 => array(70,"Uldaman Instance"),
243 90 => array(90,"Gnomeregan Instance"),
244 109 => array(109,"Sunken Temple Instance"),
245 129 => array(129,"Razorfen Downs Instance"),
246 150 => array(150,"Outland"),
247 169 => array(169,"Emerald Forest"),
248 189 => array(189,"Scarlet Onastery Instance"),
249 209 => array(209,"Zul farrak Instance"),
250 229 => array(229,"Blackrock Spire Instance"),
251 230 => array(230,"Blackrock Depths Instance"),
252 249 => array(249,"Onyxia s Lair Instance"),
253 269 => array(269,"Cot Black Morass"),
254 289 => array(289,"Scholomance Instance"),
255 309 => array(309,"Zul Gurub Instance"),
256 329 => array(329,"Stratholme Instance"),
257 349 => array(349,"Maraudon Instance"),
258 369 => array(369,"Deeprun Tram"),
259 389 => array(389,"Ragefire Chasm Instance"),
260 409 => array(409,"The Molten Core Instance"),
261 429 => array(429,"dire_maul Instance"),
262 449 => array(449,"Alliance pvp Barracks"),
263 450 => array(450,"Horde pvp Barracks"),
264 451 => array(451,"Development Land"),
265 469 => array(469,"BlackwingLair Instance"),
266 489 => array(489,"Warsong Gulch"),
267 509 => array(509,"Ruins of ahn Qiraj Instance"),
268 529 => array(529,"Arathi Basin"),
269 530 => array(530,"Outland"),
270 531 => array(531,"Temple of ahn Qiraj Instance"),
271 532 => array(532,"Karazahn"),
272 533 => array(533,"Naxxramas Instance"),
273 534 => array(534,"Cot_hyjal Past"),
274 540 => array(540,"Hellfire Military"),
275 542 => array(542,"Hellfire Demon"),
276 543 => array(543,"Hellfire Rampart"),
277 544 => array(544,"Hellfire Raid"),
278 545 => array(545,"Coilfang Pumping"),
279 546 => array(546,"Coilfang Marsh"),
280 547 => array(547,"Coilfang Draenei"),
281 548 => array(548,"Coilfang Raid"),
282 550 => array(550,"Tempest Keep Raid"),
283 552 => array(552,"Tempest Keep Arcane"),
284 553 => array(553,"Tempest Keep Atrium"),
285 554 => array(554,"Tempest Keep Factory"),
286 555 => array(555,"Auchindoun Shadow"),
287 556 => array(556,"Auchindoun Srakkoa"),
288 557 => array(557,"Auchindoun Ethereal"),
289 558 => array(558,"Auchindoun Draenei"),
290 559 => array(559,"Nagrand Arena"),
291 560 => array(560,"Cot Hillsbrad Past"),
292 562 => array(562,"Blades Edge Arena"),
293 564 => array(564,"Black Temple"),
294 565 => array(565,"Gruuls Lair"),
295 566 => array(566,"Netherstorm Arena"),
296 568 => array(568,"Zulaman")
297 );
298 if(isset($map_id[$id])) return($map_id[$id][1]);
299 else return("Neznámá");
300 }
301
302 public function ZoneName($id)
303 {
304 $zone_id = Array
305 (
306 1497 => Array("Undercity",1497),
307 1537 => Array("Ironforge",1537),
308 1519 => Array("Stormwind city",1519),
309 3 => Array("Badlands",3),
310 11 => Array("Wetlands",11),
311 33 => Array("Stranglethorn Vale",33),
312 44 => Array("Redridge Mountains",44),
313 38 => Array("Loch Modan",38),
314 10 => Array("Duskwood",10),
315 41 => Array("Deadwind Pass",41),
316 12 => Array("Elwynn Forest",12),
317 46 => Array("Burning Steppes",46),
318 51 => Array("Searing Gorge",51),
319 1 => Array("Dun Morogh",1),
320 47 => Array("The Hinterlands",47),
321 40 => Array("Westfall",40),
322 267 => Array("Hillsbrad Foothills",267),
323 139 => Array("Eastern Plaguelands",139),
324 28 => Array("Western Plaguelands",28),
325 130 => Array("Silverpine Forest",130),
326 85 => Array("Tirisfal Glades",85),
327 4 => Array("Blasted Lands",4),
328 8 => Array("Swamp of Sorrows",8),
329 45 => Array("Arathi Highlands",45),
330 36 => Array("Alterac Mountains",36),
331 1657 => Array("Darnassus",1657),
332 1638 => Array("Thunder_bluff",1638),
333 1637 => Array("Orgrimmar",1637),
334 493 => Array("Moonglade",493),
335 1377 => Array("Silithus",1377),
336 618 => Array("Winterspring",618),
337 490 => Array("Un Goro Crater",490),
338 361 => Array("Felwood",361),
339 16 => Array("Azshara",16),
340 440 => Array("Tanaris",440),
341 15 => Array("Dustwallow Marsh",15),
342 215 => Array("Mulgore",215),
343 357 => Array("Feralas",357),
344 405 => Array("Desolace",405),
345 400 => Array("Thousand Needles",400),
346 14 => Array("Durotar",14),
347 331 => Array("Ashenvale",331),
348 148 => Array("Darkshore",148),
349 141 => Array("Teldrassil",141),
350 406 => Array("Stonetalon Mountains",406),
351 17 => Array("She Barrens",17),
352 3703 => Array("Shattrath city",3703),
353 3487 => Array("Silvermoon city",3487),
354 3523 => Array("Netherstorm",3523),
355 3519 => Array("Terokkar Forest",3519),
356 3518 => Array("Nagrand",3518),
357 3525 => Array("Bloodmyst Isle",3525),
358 3522 => Array("Blades Edge Mountains",3522),
359 3520 => Array("Shadowmoon Valley",3520),
360 3557 => Array("The Exodar",3557),
361 3521 => Array("Zangarmarsh",3521),
362 3483 => Array("Hellfire Peninsula",3483),
363 3524 => Array("Azuremyst Isle",3524),
364 3433 => Array("Ghostlands",3433),
365 3430 => Array("Eversong Woods",3430)
366 );
367 if(isset($zone_id[$id])) return($zone_id[$id][0]);
368 else return('-');
369 }
370
371 function RealmSelection($FormNameSufix = '')
372 {
373 global $Config;
374
375
376 $Output = '';
377 if(count($Config['Mangos']['RealmList']) > 1)
378 {
379 if(array_key_exists('page', $_GET)) $Target = '?page='.$_GET['page'];
380 else $Target = '';
381 $Output .= '<div style="text-align: center;"><form name="RealmSelection'.$FormNameSufix.'" action="'.$Target.'" method="post">'.
382 '<div>Svět <select name="RealmIndex" onchange="document.RealmSelection'.$FormNameSufix.'.submit()">';
383 foreach($Config['Mangos']['RealmList'] as $Index => $Realm)
384 {
385 if($_COOKIE['RealmIndex'] == $Index) $Selected = ' selected="selected"';
386 else $Selected = '';
387 $Output .= '<option value="'.$Index.'"'.$Selected.'>'.$Realm['Name'].'</option>';
388 }
389 $Output .= '</select></div>'.
390 '</form></div>';
391 }
392 return($Output);
393 }
394}
395
396?>
Note: See TracBrowser for help on using the repository browser.