source: trunk/inc/realm.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: 7.4 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();
16 $this->CharactersDatabase->Connect($this->Data['DatabaseHost'], $this->Data['DatabaseUser'], $this->Data['DatabasePassword'], $this->Data['DatabaseCharacters']);
17 $this->CharactersDatabase->select_db($this->Data['DatabaseCharacters']);
18 //if($this->CharactersDatabase->connect_error)
19 //{
20 // die('Přihlášení k databázi realmu '.$this->Id.' selhalo: '.$this->Database->connect_error);
21 //}
22 $this->CharactersDatabase->charset($this->Config['Database']['Charset']);
23
24 $this->MangosDatabase = new Database();
25 $this->MangosDatabase->Connect($this->Data['DatabaseHost'], $this->Data['DatabaseUser'], $this->Data['DatabasePassword'], $this->Data['DatabaseMangos']);
26 $this->MangosDatabase->select_db($this->Data['DatabaseMangos']);
27 //if($this->MangosDatabase->connect_error)
28 //{
29 // die('Přihlášení k databázi realmu '.$this->Id.' selhalo: '.$this->MangosDatabase->connect_error);
30 //}
31 $this->MangosDatabase->charset($this->Config['Database']['Charset']);
32 }
33
34 function OnlineCharactersCount()
35 {
36 if($this->CharactersDatabase->connect_error) return(0);
37 else {
38 $DbResult = $this->CharactersDatabase->query('SELECT COUNT(*) FROM `characters` WHERE `online` = 1');
39 $DbRow = $DbResult->fetch_row();
40 return($DbRow[0]);
41 }
42 }
43
44 function OnlineStateImage($Status)
45 {
46 global $html;
47
48 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>');
49 else return('<img src="'.$html->Link('/imgs/inc/off.gif').'" alt="offline" />&nbsp;<span style="text-color: #990000; text-size: 4;">V provozu</span>');
50 }
51
52 function Uptime()
53 {
54 $Database->OpenLogonServerDatabase();
55 $row = $Database->query('SELECT `starttime`, `uptime` FROM `uptime` WHERE `realmid`='.$this->Id.' ORDER BY `starttime` DESC LIMIT 1')
56 ->fetch_array();
57 $uptime = round($row['uptime'] / 3600);
58 return($uptime);
59 }
60
61 public function CharacterCount()
62 {
63 if($this->CharactersDatabase->connect_error) return('');
64 else {
65 $DbResult = $this->CharactersDatabase->query('SELECT COUNT(*) FROM `characters`');
66 $DbRow = $DbResult->fetch_row();
67 return($DbRow[0]);
68 }
69 }
70
71 public function GuidToCharName($guid)
72 {
73 if($this->CharactersDatabase->connect_error) return(0);
74 else {
75 $row = $this->CharactersDatabase->query('SELECT `name` FROM `characters` WHERE `guid` = "'.$guid.'" LIMIT 1')->fetch_array();
76 return($row['name']);
77 }
78 }
79
80 public function ShowGmLog($log)
81 {
82 echo('<table border="1" width="540">'.
83 '<tr>
84 <th>Čas</th>
85 <th>GM</th>
86 <th>Příkaz</th>
87 <th>Vybrán</th>
88 </tr>');
89 $gm_log = ereg_replace("\n",";",$log);
90 $gm_log = explode(";",$gm_log);
91 $gm_log = array_reverse($gm_log);
92 foreach($gm_log as $row)
93 {
94 if (strpos($row,"Command:") == true)
95 {
96 $edited = str_replace(" Command: ", ";", $row); // 0 - time
97 $edited = str_replace(" (Account: ", ";", $edited); // 1 - command
98 $edited = str_replace(" [Player: ", ";", $edited); // 2 - gm
99 $edited = str_replace(" Selected: ", ";", $edited); // 3 - position
100 $edited = str_replace(" (GUID: ", ";", $edited); // 4 - selected
101 $edited = str_replace(")]", ";", $edited); // 5 - selected guid
102 $edited_arr = explode(";",$edited);
103 if($edited_arr[4] == "player") $sel_name = " - ".$this->GuidToCharName($edited_arr[5]);
104 else $sel_name = '';
105 $human_date = $this -> HumanDate($edited_arr[0]);
106 echo('<tr>
107 <td><font size="2">'.$human_date.'</font></td>
108 <td>'.$edited_arr[2].'</td>
109 <td>'.$edited_arr[1].'</td>
110 <td>'.$edited_arr[4].$sel_name.'</td>
111 </tr>');
112 }
113 if(strpos($row, 'mail item:') == true)
114 {
115 $edited = str_replace(" GM ", ";", $row);
116 $edited = str_replace(" (Account: ", ";", $edited);
117 $edited = str_replace(") mail item: ", ";", $edited);
118 $edited = str_replace(" (Account: ", ";", $edited);
119 $edited = str_replace(")", "", $edited);
120 $edited_arr = explode(";",$edited);
121 $human_date = $this -> HumanDate($edited_arr[0]);
122 echo('<tr>
123 <td><font size="2">'.$human_date.'</font></td>
124 <td>'.$edited_arr[1].'</td>
125 <td>Send : '.$edited_arr[3].')</td>
126 <td>-</td>
127 </tr>');
128 }
129 if(strpos($row,"trade:") == true)
130 {
131 $edited = str_replace(" GM ", ";", $row);
132 $edited = str_replace(" (Account: ", ";", $edited);
133 $edited = str_replace(") trade: ", ";", $edited);
134 $edited = str_replace(" (Account: ", ";", $edited);
135 $edited = str_replace(")", "", $edited);
136 $edited_arr = explode(";",$edited);
137
138 $human_date = $this -> HumanDate ($edited_arr[0]);
139 echo('<tr>
140 <td><font size="2">'.$human_date.'</font></td>
141 <td>'.$edited_arr[1].'</td>
142 <td>Trade : '.$edited_arr[3].')</td>
143 <td>-</td>
144 </tr>');
145 }
146 }
147 echo('</table>');
148 }
149
150 function WoWEmuStat()
151 {
152 global $Config;
153
154 $Result =
155'<?xml version="1.0" encoding="UTF-8"'."?>\r\n".
156" <stats>\r\n".
157" <server>\r\n".
158" <version>0.16</version>\r\n".
159" <owner>Admin</owner>\r\n".
160" <servername>Server</servername>\r\n".
161" <uptime>0 weeks 1 days 0 hours 0 mins</uptime>\r\n".
162" </server>\r\n".
163" <serverload>\r\n".
164" <network>\r\n".
165" <configsleep>200</configsleep>\r\n".
166" <loops>0</loops>\r\n".
167" <totaltime>0</totaltime>\r\n".
168" <load>0.00%</load>\r\n".
169" </network>\r\n".
170" <world>\r\n".
171" <configsleep>600</configsleep>\r\n".
172" <loops>95222</loops>\r\n".
173" <totaltime>7594525</totaltime>\r\n".
174" <load>1.50%</load>\r\n".
175" </world>\r\n".
176" </serverload>\r\n".
177" <players>\r\n";
178 if($this->CharactersDatabase->connect_error) return(0);
179 else {
180 $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');
181 while($DbRow = $DbResult->fetch_assoc())
182 {
183 $Result .= " <player>\r\n".
184 " <name>".$DbRow['name']."</name>\r\n".
185 " <race>".$DbRow['race']."</race>\r\n".
186 " <class>".$DbRow['class']."</class>\r\n".
187 " <level>".$DbRow['level']."</level>\r\n".
188 " <map>".$DbRow['map']."</map>\r\n".
189 " <zone>xxx</zone>\r\n".
190 " <ping>10</ping>\r\n".
191 " <plevel>0</plevel>\r\n".
192 " <ip>178.12.14.2</ip>\r\n".
193 " </player>\r\n";
194 }
195 }
196 $Result .= " </players>\r\n".
197 " </stats>\r\n";
198 return($Result);
199 }
200}
201
202?>
Note: See TracBrowser for help on using the repository browser.