source: trunk/inc/server.php

Last change on this file was 712, checked in by chronos, 11 years ago
  • Upraveno: Aktualizace inicializačního skriptu pro sql databázi na revizi 710.
  • Upraveno: Aktualizována třída Database na novější využívající třídu PDO a generující výjímky při chybě, které je pak nutno očetřit.
File size: 16.6 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/module.php');
4
5function NullErrorHandler()
6{
7}
8
9class Server extends Module
10{
11 function __construct($System, $Id)
12 {
13 parent::__construct($System);
14 $this->Id = $Id;
15 $DbResult = $this->Database->query('SELECT * FROM Logon WHERE Id='.$Id.' AND Enabled=1' );
16 if($DbResult->num_rows == 1)
17 {
18 $this->Data = $DbResult->fetch_assoc();
19 $this->ServerDatabase = new Database();
20 $this->ServerDatabase->Connect($this->Data['DatabaseHost'], $this->Data['DatabaseUser'], $this->Data['DatabasePassword'], $this->Data['DatabaseRealmd']);
21 $this->ServerDatabase->select_db($this->Data['DatabaseRealmd']);
22 //if($this->ServerDatabase->connect_error)
23 //{
24 // die('Přihlášení k databázi serveru '.$this->Id.' selhalo: '.$this->ServerDatabase->connect_error);
25 //}
26 $this->ServerDatabase->charset($this->Config['Database']['Charset']);
27 } else throw new Exception('Záznam pro přihlašovací server id '.$Id.' nenalezen!');
28 }
29
30 function HumanDate($date, $time = 1)
31 {
32 // input date is 0000-00-00 00:00:00
33 $date_arr = explode(' ', $date);
34 $date = explode('-', $date_arr[0]);
35 if(count($date_arr) > 1) $time_stp = explode(':', $date_arr[1]);
36 else $time_stp = array(0, 0, 0);
37 $time = mktime($time_stp[0], $time_stp[1], $time_stp[2], $date[1], $date[2], $date[0]);
38 if($time == 1) $human_date = date('d.m.Y H:i:s', $time);
39 else $human_date = date('d.m.Y', $time);
40 return($human_date);
41 }
42
43 function ParseCopper($copper_in)
44 {
45 global $html;
46
47 $copper = $copper_in;
48 $golds = floor($copper / 10000);
49 $num = $copper - $golds * 10000;
50 $silver = floor($num / 100);
51 $copper = $num - $silver * 100;
52 $show_golds = '<font size="4">'.$golds.'</font>&nbsp;<img src="'.$html->Link('/imgs/inc/g.gif').'">';
53 $show_silver = '<font size="4">'.$silver.'</font>&nbsp;<img src="'.$html->Link('/imgs/inc/s.gif').'">';
54 $show_copper = '<font size="4">'.$copper.'</font>&nbsp;<img src="'.$html->Link('/imgs/inc/c.gif').'">';
55 return($show_golds.'&nbsp;'.$show_silver.'&nbsp;'.$show_copper);
56 }
57
58 function OnlineCharactersCount()
59 {
60 $TotalCount = 0;
61 $DbResult = $this->Database->query('SELECT Id FROM Realm WHERE Enabled=1');
62 while($DbRow = $DbResult->fetch_assoc())
63 {
64 $Realm = new Realm($this->System, $DbRow['Id']);
65 $TotalCount += $Realm->OnlineCharactersCount();
66 }
67 return($TotalCount);
68 }
69
70 function OnlineStateImage($Status)
71 {
72 global $html;
73
74 if($Status) return('<img src="'.$html->Link('/imgs/inc/on.gif').'" alt="online" />&nbsp;<span style="text-color: #234303; text-size: 4;">Online</span>');
75 else return('<img src="'.$html->Link('/imgs/inc/off.gif').'" alt="offline" />&nbsp;<span style="text-color: #990000; text-size: 4;">Offline</span>');
76 }
77
78 function CharacterCount()
79 {
80 $TotalCount = 0;
81 $DbResult = $this->Database->query('SELECT Id FROM Realm WHERE Enabled=1');
82 while($DbRow = $DbResult->fetch_assoc())
83 {
84 $Realm = new Realm($this->System, $DbRow['Id']);
85 $TotalCount += $Realm->CharacterCount($DbRow['Id']);
86 }
87 return($TotalCount);
88 }
89
90 public function AccountCount()
91 {
92 $row = $this->ServerDatabase->query('SELECT COUNT(*) FROM account')->fetch_row();
93 return($row[0]);
94 }
95
96 public function MapName($id)
97 {
98 $map_id = Array
99 (
100 0 => array(0,"Azeroths"),
101 1 => array(1,"Kalimdor"),
102 13 => array(13,"Testing"),
103 17 => array(17,"Kalidar"),
104 25 => array(25,"Scott Test"),
105 30 => array(30,"Alterac Valley"),
106 33 => array(33,"Shadowfang Keep Instance"),
107 34 => array(34,"The Stockade Instance"),
108 35 => array(35,"Stormwind Prison"),
109 36 => array(36,"Deadmines Instance"),
110 37 => array(37,"Azshara Crater"),
111 42 => array(42,"Collins Test"),
112 43 => array(43,"Wailing Caverns Instance"),
113 44 => array(44,"Monastery Interior"),
114 47 => array(47,"Razorfen Kraul Instance"),
115 48 => array(48,"Blackfathom Deeps Instance"),
116 70 => array(70,"Uldaman Instance"),
117 90 => array(90,"Gnomeregan Instance"),
118 109 => array(109,"Sunken Temple Instance"),
119 129 => array(129,"Razorfen Downs Instance"),
120 169 => array(169,"Emerald Forest"),
121 189 => array(189,"Scarlet Monastery Instance"),
122 209 => array(209,"Zul Farrak Instance"),
123 229 => array(229,"Blackrock Spire Instance"),
124 230 => array(230,"Blackrock Depths Instance"),
125 249 => array(249,"Onyxias Lair Instance"),
126 269 => array(269,"Opening of the Dark Portal Instance"),
127 289 => array(289,"Scholomance Instance"),
128 309 => array(309,"ZulGurub Instance"),
129 329 => array(329,"Stratholme Instance"),
130 349 => array(349,"Maraudon Instance"),
131 369 => array(369,"Deeprun Tram"),
132 389 => array(389,"Ragefire Chasm Instance"),
133 409 => array(409,"The Molten Core Instance"),
134 429 => array(429,"Dire Maul Instance"),
135 449 => array(449,"Alliance PvP Barracks"),
136 450 => array(450,"Horde PvP Barracks"),
137 451 => array(451,"Development Land"),
138 469 => array(469,"BlackwingLair Instance"),
139 489 => array(489,"PvP Warsong Gulch"),
140 509 => array(509,"Ruins of Ahn Qiraj Instance"),
141 529 => array(529,"PvP Arathi Basin"),
142 530 => array(530,"Outland"),
143 531 => array(531,"Temple of Ahn Qiraj Instance"),
144 532 => array(532,"Karazhan Instance"),
145 533 => array(533,"Naxxramas Instance"),
146 534 => array(534,"The Battle for Mount Hyjal Instance"),
147 540 => array(540,"Hellfire Citadel The Shattered Halls Instance"),
148 542 => array(542,"Hellfire Citadel The Blood Furnace Instance"),
149 543 => array(543,"Hellfire Citadel Ramparts Instance"),
150 544 => array(544,"Maghtheridons Lair Instance"),
151 545 => array(545,"Coilfang The Steamvault Instance"),
152 546 => array(546,"Coilfang The Underbog Instance"),
153 547 => array(547,"Coilfang The Slave Pens Instance"),
154 548 => array(548,"Coilfang Serpentshrine Cavern Instance"),
155 550 => array(550,"Tempest Keep Instance"),
156 552 => array(552,"Tempest Keep The Alcatraz Instance"),
157 553 => array(553,"Tempest Keep The Botanica Instance"),
158 554 => array(554,"Tempest Keep The Mechanar Instance"),
159 555 => array(555,"Auchindoun Shadow Labyrinth Instance"),
160 556 => array(556,"Auchindoun Sethekk Halls Instance"),
161 557 => array(557,"Auchindoun Mana Tombs Instance"),
162 558 => array(558,"Auchindoun Auchenai Crypts Instance"),
163 559 => array(559,"Nagrand Arena"),
164 560 => array(560,"The Escape From Durnholde Instance"),
165 562 => array(562,"Blades Edge Arena"),
166 564 => array(564,"Black Temple Instance"),
167 565 => array(565,"Gruuls Lair Instance"),
168 566 => array(566,"Netherstorm Arena"),
169 568 => array(568,"ZulAman Instance"),
170 571 => array(571,"Northrend"),
171 572 => array(572,"PvP Ruins of Lordaeron"),
172 573 => array(573,"ExteriorTest"),
173 574 => array(574,"Utgarde Keep Instance"),
174 575 => array(575,"Utgarde Pinnacle Instance"),
175 576 => array(576,"The Nexus Instance"),
176 578 => array(578,"The Oculus Instance"),
177 580 => array(580,"The Sunwell Instance"),
178 585 => array(585,"Magisters Terrace Instance"),
179 595 => array(595,"The Culling of Stratholme Instance"),
180 597 => array(597,"Craig Test"),
181 599 => array(599,"Halls of Stone Instance"),
182 600 => array(600,"Drak Tharon Keep Instance"),
183 601 => array(601,"Azjol-Nerub Instance"),
184 602 => array(602,"Halls of Lightning Instance"),
185 603 => array(603,"Ulduar Instance"),
186 604 => array(604,"Gundrak Instance"),
187 605 => array(605,"Development Land"),
188 606 => array(606,"QA and DVD"),
189 607 => array(607,"PvP Strand of the Ancients"),
190 608 => array(608,"Violet Hold Instance"),
191 609 => array(609,"Ebon Hold"),
192 615 => array(615,"Obsidian Sanctum Instance"),
193 616 => array(616,"The Eye of Eternity Instance"),
194 617 => array(617,"PvP Dalaran Sewers"),
195 618 => array(618,"PvP The Ring of Valor"),
196 619 => array(619,"Ahn kahet The Old Kingdom Instance"),
197 624 => array(624,"Vault of Archavon Instance"),
198 650 => array(650,"Trial of the Champion Instance")
199 );
200 if(isset($map_id[$id])) return($map_id[$id][1]);
201 else return("Neznámá");
202 }
203
204 public function ZoneName($id)
205 {
206 $zone_id = Array
207 (
208 1 => Array("Dun Morogh",1),
209 3 => Array("Badlands",3),
210 4 => Array("Blasted Lands",4),
211 8 => Array("Swamp of Sorrows",8),
212 10 => Array("Duskwood",10),
213 11 => Array("Wetlands",11),
214 12 => Array("Elwynn Forest",12),
215 14 => Array("Durotar",14),
216 15 => Array("Dustwallow Marsh",15),
217 16 => Array("Azshara",16),
218 17 => Array("The Barrens",17),
219 19 => Array("Zul Gurub",19),
220 25 => Array("Blackrock Mountain",25),
221 28 => Array("Western Plaguelands",28),
222 33 => Array("Stranglethorn Vale",33),
223 36 => Array("Alterac Mountains",36),
224 38 => Array("Loch Modan",38),
225 40 => Array("Westfall",40),
226 41 => Array("Deadwind Pass",41),
227 44 => Array("Redridge Mountains",44),
228 45 => Array("Arathi Highlands",45),
229 46 => Array("Burning Steppes",46),
230 47 => Array("The Hinterlands",47),
231 51 => Array("Searing Gorge",51),
232 65 => Array("Dragonblight",65),
233 66 => Array("Zul Drak",66),
234 67 => Array("The Storm Peaks",67),
235 85 => Array("Tirisfal Glades",85),
236 130 => Array("Silverpine Forest",130),
237 133 => Array("Gnomeregan",133),
238 139 => Array("Eastern Plaguelands",139),
239 141 => Array("Teldrassil",141),
240 148 => Array("Darkshore",148),
241 206 => Array("Utgarde Keep",206),
242 209 => Array("Shadowfang Keep",209),
243 210 => Array("Icecrown",210),
244 215 => Array("Mulgore",215),
245 267 => Array("Hillsbrad Foothills",267),
246 331 => Array("Ashenvale",331),
247 357 => Array("Feralas",357),
248 361 => Array("Felwood",361),
249 394 => Array("Grizzly Hills",394),
250 400 => Array("Thousand Needles",400),
251 405 => Array("Desolace",405),
252 406 => Array("Stonetalon Mountains",406),
253 440 => Array("Tanaris",440),
254 457 => Array("The Veiled Sea",457),
255 490 => Array("Un Goro Crater",490),
256 491 => Array("Razorfen Kraul",491),
257 493 => Array("Moonglade",493),
258 495 => Array("Howling Fjord",495),
259 618 => Array("Winterspring",618),
260 717 => Array("The Stockade",717),
261 718 => Array("Wailing Caverns",718),
262 719 => Array("Blackfathom Deeps",719),
263 722 => Array("Razorfen Downs",722),
264 796 => Array("Scarlet Monastery",796),
265 978 => Array("Zul Farrak",978),
266 1176 => Array("Zul Farrak",1176),
267 1196 => Array("Utgarde Pinnacle",1196),
268 1337 => Array("Uldaman",1337),
269 1377 => Array("Silithus",1377),
270 1417 => Array("Sunken Temple",1417),
271 1497 => Array("Undercity",1497),
272 1519 => Array("Stormwind City",1519),
273 1537 => Array("Ironforge",1537),
274 1581 => Array("The Deadmines",1581),
275 1583 => Array("Blackrock Spire",1583),
276 1584 => Array("Blackrock Depths",1584),
277 1637 => Array("Orgrimmar",1637),
278 1638 => Array("Thunder Bluff",1638),
279 1657 => Array("Darnassus",1657),
280 2017 => Array("Stratholme",2017),
281 2057 => Array("Scholomance",2057),
282 2100 => Array("Maraudon",2100),
283 2158 => Array("Onyxias Lair",2158),
284 2257 => Array("Deeprun Tram",2257),
285 2366 => Array("The Black Morass",2366),
286 2367 => Array("Old Hillsbrad Foothills",2367),
287 2557 => Array("Dire Maul",2557),
288 2562 => Array("Karazhan",2562),
289 2597 => Array("PvP Alterac Valley",2597),
290 2677 => Array("Blackwing Lair",2677),
291 2717 => Array("Molten Core",2717),
292 2817 => Array("Crystalsong Forest",2817),
293 3277 => Array("PvP Warsong Gulch",3277),
294 3358 => Array("PvP Arathi Basin",3358),
295 3428 => Array("Temple of Ahn Qiraj",3428),
296 3429 => Array("Ruins of Ahn Qiraj",3429),
297 3430 => Array("Eversong Woods",3430),
298 3433 => Array("Ghostlands",3433),
299 3437 => Array("Ragefire Chasm",3437),
300 3456 => Array("Naxxramas",3456),
301 3477 => Array("Azjol Nerub",3477),
302 3483 => Array("Hellfire Peninsula",3483),
303 3487 => Array("Silvermoon city",3487),
304 3518 => Array("Nagrand",3518),
305 3519 => Array("Terokkar Forest",3519),
306 3520 => Array("Shadowmoon Valley",3520),
307 3521 => Array("Zangarmarsh",3521),
308 3522 => Array("Blades Edge Mountains",3522),
309 3523 => Array("Netherstorm",3523),
310 3524 => Array("Azuremyst Isle",3524),
311 3525 => Array("Bloodmyst Isle",3525),
312 3537 => Array("Borean Tundra",3537),
313 3557 => Array("The Exodar",3557),
314 3562 => Array("Hellfire Ramparts",3562),
315 3606 => Array("Hyjal Summit",3606),
316 3607 => Array("Serpentshrine Cavern",3607),
317 3618 => Array("Gruuls Lair",3618),
318 3698 => Array("The Ring of Trials",3698),
319 3702 => Array("PvP The Circle of Blood",3702),
320 3703 => Array("Shattrath City",3703),
321 3711 => Array("Sholazar Basin",3711),
322 3713 => Array("The Blood Furnace",3713),
323 3714 => Array("The Shattered Halls",3714),
324 3715 => Array("The Steamvault",3715),
325 3716 => Array("The Underbog",3716),
326 3717 => Array("The Slave Pens",3717),
327 3789 => Array("Shadow Labyrinth",3789),
328 3790 => Array("Auchenai Crypts",3790),
329 3791 => Array("Sethekk Halls",3791),
330 3792 => Array("Mana Tombs",3792),
331 3805 => Array("Zul Aman",3805),
332 3817 => Array("Testing",3817),
333 3820 => Array("PvP Eye of the Storm",3820),
334 3836 => Array("Magtheridons Lair",3836),
335 3842 => Array("The Eye",3842),
336 3846 => Array("The Arcatraz",3846),
337 3847 => Array("The Botanica",3847),
338 3849 => Array("The Mechanar",3849),
339 3959 => Array("Black Temple",3959),
340 3968 => Array("PvP Ruins of Lordaeron",3968),
341 4075 => Array("Sunwell Plateau",4075),
342 4080 => Array("Isle of Quel Danas",4080),
343 4095 => Array("Magisters Terrace",4095),
344 4100 => Array("The Culling of Stratholme",4100),
345 4120 => Array("The Nexus",4120),
346 4131 => Array("Magisters Terrace",4131),
347 4196 => Array("Drak Tharon Keep",4196),
348 4197 => Array("Wintergrasp",4197),
349 4228 => Array("The Oculus",4228),
350 4264 => Array("Halls of Stone",4264),
351 4272 => Array("Halls of Lightning",4272),
352 4273 => Array("Ulduar",4273),
353 4277 => Array("Azjol-Nerub",4277),
354 4298 => Array("The Scarlet Enclave",4298),
355 4375 => Array("Gundrak",4375),
356 4378 => Array("PvP Dalaran Sewers",4378),
357 4384 => Array("PvP Strand of the Ancients",4384),
358 4395 => Array("Dalaran",4395),
359 4406 => Array("PvP The Ring of Valor",4406),
360 4415 => Array("The Violet Hold Instance",4415),
361 4416 => Array("Gundrak Instance",4416),
362 4493 => Array("The Obsidian Sanctum",4493),
363 4494 => Array("Ahn kahet The Old Kingdom",4494),
364 4500 => Array("The Eye of Eternity",4500),
365 4603 => Array("Vault of Archavon",4603),
366 4710 => Array("PvP Isle of Conquest",4710),
367 4722 => Array("Trial of the Crusader",4722),
368 4723 => Array("Trial of the Champion",4723),
369 4742 => Array("Hrothgars Landing",4742),
370 4809 => Array("The Forge of Souls",4809),
371 4812 => Array("Icecrown Citadel",4812),
372 4813 => Array("Pit of Saron",4813),
373 4820 => Array("Halls of Reflection",4820)
374 );
375 if(isset($zone_id[$id])) return($zone_id[$id][0]);
376 else return('-');
377 }
378
379 function RealmSelection($FormNameSufix = '')
380 {
381 global $html, $QueryItems, $System;
382
383 $Output = '';
384 $DbResult = $this->Database->query('SELECT COUNT(*) FROM Realm WHERE Enabled=1');
385 $DbRow = $DbResult->fetch_row();
386 $RealmCount = $DbRow[0];
387
388 if($RealmCount > 1)
389 {
390 if(array_key_exists('page', $_GET)) $Target = '?page='.$_GET['page'];
391 else $Target = '';
392 $Output .= '<div style="text-align: center;"><form name="realm_selection">'.
393 '<div>Výběr světa <select onchange="loadPage(this.form.elements[0])">';
394
395 $DbResult = $this->Database->query('SELECT *, '.$System->SQLURLName('Name').' AS URLName FROM Realm WHERE Enabled=1');
396 while($Realm = $DbResult->fetch_assoc())
397 {
398 if($QueryItems[1] == $Realm['URLName']) $Selected = ' selected="selected"';
399 else $Selected = '';
400 $NewQueryItems = $QueryItems;
401 $NewQueryItems[0] = 'svety';
402 $NewQueryItems[1] = $Realm['URLName'];
403 $NewURL = $html->Link('/'.implode('/', $NewQueryItems).'/');
404 $Output .= '<option value="'.$NewURL.'"'.$Selected.'>'.$Realm['Name'].'</option>';
405 }
406 $Output .= '</select></div>'.
407 '</form></div>';
408 }
409 return($Output);
410 }
411}
412
413?>
Note: See TracBrowser for help on using the repository browser.