source: branches/posledni/inc/realm.php

Last change on this file was 695, checked in by george, 15 years ago
  • Upraveno: Použití názvů světů v URL namísto RealmIndex.
  • Přidáno: Stránka zobrazující informace o jednotlivých světech.
  • Odebráno: Nezobrazovat kategorie aktualit. Stačí jen jedna.
  • Přidáno: Funkce pro generování XML seznamu hráčů ve stylu WoWEmu pro wowstatus.
File size: 7.3 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/module.php');
4
5class Realm extends Module
6{
7 var $Id;
8
9 function __construct($System, $Id)
10 {
11 parent::__construct($System);
12 $this->Id = $Id;
13 $DbResult = $this->Database->query('SELECT * FROM Realm WHERE Id='.$Id.' AND Enabled=1');
14 $this->Data = $DbResult->fetch_assoc();
15 $this->CharactersDatabase = new Database($this->Data['DatabaseHost'], $this->Data['DatabaseUser'], $this->Data['DatabasePassword'], $this->Data['DatabaseCharacters']);
16 $this->CharactersDatabase->select_db($this->Data['DatabaseCharacters']);
17 if($this->CharactersDatabase->connect_error)
18 {
19 die('Přihlášení k databázi realmu '.$this->Id.' selhalo: '.$this->Database->connect_error);
20 }
21 $this->CharactersDatabase->charset($this->Config['Database']['Charset']);
22
23 $this->MangosDatabase = new Database($this->Data['DatabaseHost'], $this->Data['DatabaseUser'], $this->Data['DatabasePassword'], $this->Data['DatabaseMangos']);
24 $this->MangosDatabase->select_db($this->Data['DatabaseMangos']);
25 if($this->MangosDatabase->connect_error)
26 {
27 die('Přihlášení k databázi realmu '.$this->Id.' selhalo: '.$this->MangosDatabase->connect_error);
28 }
29 $this->MangosDatabase->charset($this->Config['Database']['Charset']);
30 }
31
32 function OnlineCharactersCount()
33 {
34 if($this->CharactersDatabase->connect_error) return(0);
35 else {
36 $DbResult = $this->CharactersDatabase->query('SELECT COUNT(*) FROM `characters` WHERE `online` = 1');
37 $DbRow = $DbResult->fetch_row();
38 return($DbRow[0]);
39 }
40 }
41
42 function OnlineStateImage($Status)
43 {
44 global $html;
45
46 if($Status) return('<img src="'.$html->Link('/imgs/inc/on.gif').'" alt="online" />&nbsp;<span style="text-color: #234303; text-size: 4;">Mimo provoz</span>');
47 else return('<img src="'.$html->Link('/imgs/inc/off.gif').'" alt="offline" />&nbsp;<span style="text-color: #990000; text-size: 4;">V provozu</span>');
48 }
49
50 function Uptime()
51 {
52 $Database->OpenLogonServerDatabase();
53 $row = $Database->query('SELECT `starttime`, `uptime` FROM `uptime` WHERE `realmid`='.$this->Id.' ORDER BY `starttime` DESC LIMIT 1')
54 ->fetch_array();
55 $uptime = round($row['uptime'] / 3600);
56 return($uptime);
57 }
58
59 public function CharacterCount()
60 {
61 if($this->CharactersDatabase->connect_error) return('');
62 else {
63 $DbResult = $this->CharactersDatabase->query('SELECT COUNT(*) FROM `characters`');
64 $DbRow = $DbResult->fetch_row();
65 return($DbRow[0]);
66 }
67 }
68
69 public function GuidToCharName($guid)
70 {
71 if($this->CharactersDatabase->connect_error) return(0);
72 else {
73 $row = $this->CharactersDatabase->query('SELECT `name` FROM `characters` WHERE `guid` = "'.$guid.'" LIMIT 1')->fetch_array();
74 return($row['name']);
75 }
76 }
77
78 public function ShowGmLog($log)
79 {
80 echo('<table border="1" width="540">'.
81 '<tr>
82 <th>Čas</th>
83 <th>GM</th>
84 <th>Příkaz</th>
85 <th>Vybrán</th>
86 </tr>');
87 $gm_log = ereg_replace("\n",";",$log);
88 $gm_log = explode(";",$gm_log);
89 $gm_log = array_reverse($gm_log);
90 foreach($gm_log as $row)
91 {
92 if (strpos($row,"Command:") == true)
93 {
94 $edited = str_replace(" Command: ", ";", $row); // 0 - time
95 $edited = str_replace(" (Account: ", ";", $edited); // 1 - command
96 $edited = str_replace(" [Player: ", ";", $edited); // 2 - gm
97 $edited = str_replace(" Selected: ", ";", $edited); // 3 - position
98 $edited = str_replace(" (GUID: ", ";", $edited); // 4 - selected
99 $edited = str_replace(")]", ";", $edited); // 5 - selected guid
100 $edited_arr = explode(";",$edited);
101 if($edited_arr[4] == "player") $sel_name = " - ".$this->GuidToCharName($edited_arr[5]);
102 else $sel_name = '';
103 $human_date = $this -> HumanDate($edited_arr[0]);
104 echo('<tr>
105 <td><font size="2">'.$human_date.'</font></td>
106 <td>'.$edited_arr[2].'</td>
107 <td>'.$edited_arr[1].'</td>
108 <td>'.$edited_arr[4].$sel_name.'</td>
109 </tr>');
110 }
111 if(strpos($row, 'mail item:') == true)
112 {
113 $edited = str_replace(" GM ", ";", $row);
114 $edited = str_replace(" (Account: ", ";", $edited);
115 $edited = str_replace(") mail item: ", ";", $edited);
116 $edited = str_replace(" (Account: ", ";", $edited);
117 $edited = str_replace(")", "", $edited);
118 $edited_arr = explode(";",$edited);
119 $human_date = $this -> HumanDate($edited_arr[0]);
120 echo('<tr>
121 <td><font size="2">'.$human_date.'</font></td>
122 <td>'.$edited_arr[1].'</td>
123 <td>Send : '.$edited_arr[3].')</td>
124 <td>-</td>
125 </tr>');
126 }
127 if(strpos($row,"trade:") == true)
128 {
129 $edited = str_replace(" GM ", ";", $row);
130 $edited = str_replace(" (Account: ", ";", $edited);
131 $edited = str_replace(") trade: ", ";", $edited);
132 $edited = str_replace(" (Account: ", ";", $edited);
133 $edited = str_replace(")", "", $edited);
134 $edited_arr = explode(";",$edited);
135
136 $human_date = $this -> HumanDate ($edited_arr[0]);
137 echo('<tr>
138 <td><font size="2">'.$human_date.'</font></td>
139 <td>'.$edited_arr[1].'</td>
140 <td>Trade : '.$edited_arr[3].')</td>
141 <td>-</td>
142 </tr>');
143 }
144 }
145 echo('</table>');
146 }
147
148 function WoWEmuStat()
149 {
150 global $Config;
151
152 $Result =
153'<?xml version="1.0" encoding="UTF-8"'."?>\r\n".
154" <stats>\r\n".
155" <server>\r\n".
156" <version>0.16</version>\r\n".
157" <owner>Admin</owner>\r\n".
158" <servername>Server</servername>\r\n".
159" <uptime>0 weeks 1 days 0 hours 0 mins</uptime>\r\n".
160" </server>\r\n".
161" <serverload>\r\n".
162" <network>\r\n".
163" <configsleep>200</configsleep>\r\n".
164" <loops>0</loops>\r\n".
165" <totaltime>0</totaltime>\r\n".
166" <load>0.00%</load>\r\n".
167" </network>\r\n".
168" <world>\r\n".
169" <configsleep>600</configsleep>\r\n".
170" <loops>95222</loops>\r\n".
171" <totaltime>7594525</totaltime>\r\n".
172" <load>1.50%</load>\r\n".
173" </world>\r\n".
174" </serverload>\r\n".
175" <players>\r\n";
176 if($this->CharactersDatabase->connect_error) return(0);
177 else {
178 $DbResult = $this->CharactersDatabase->query('SELECT *, CAST( SUBSTRING_INDEX(SUBSTRING_INDEX(`data`, " ", '.$Config['Mangos']['CharacterDataOffset']['Level'].' + 1), " ", -1) AS UNSIGNED) AS level FROM `characters` WHERE `online` = 1');
179 while($DbRow = $DbResult->fetch_assoc())
180 {
181 $Result .= " <player>\r\n".
182 " <name>".$DbRow['name']."</name>\r\n".
183 " <race>".$DbRow['race']."</race>\r\n".
184 " <class>".$DbRow['class']."</class>\r\n".
185 " <level>".$DbRow['level']."</level>\r\n".
186 " <map>".$DbRow['map']."</map>\r\n".
187 " <zone>xxx</zone>\r\n".
188 " <ping>10</ping>\r\n".
189 " <plevel>0</plevel>\r\n".
190 " <ip>178.12.14.2</ip>\r\n".
191 " </player>\r\n";
192 }
193 }
194 $Result .= " </players>\r\n".
195 " </stats>\r\n";
196 return($Result);
197 }
198}
199
200?>
Note: See TracBrowser for help on using the repository browser.