source: trunk/www/Application/Model/MangosDebug.php@ 78

Last change on this file since 78 was 78, checked in by george, 16 years ago
  • Upraveno: Zrušeny samostatné include soubory a správně vloženy přímé závislosti pomocí include_once do všech souborů. Takto se budou načítat jen ty třídy, které jsou skutenčě potřeba.
  • Upraveno: Aplikace se nyní inicializuje přes soubor Application.php, kde je vložena třída odvozená z třídy System. Hlavní soubor index.php se pak odkazuje na soubor aplikace.
  • Objekty Database, Config a Translation jsou nyní lokální v rámci třídy System.
  • Přidáno: Třída pro odesílání pošty. Použita v třídě User.
File size: 3.7 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/../../Base/Model.php');
4
5class MangosDebug extends Model
6{
7 var $ItemPerPage = 35;
8 var $MaxMangosThreadCount = 12;
9
10 function __construct($Database)
11 {
12 $this->Database = $Database;
13 }
14
15 function ProcessLog($RealmId)
16 {
17 global $Config;
18
19 $Output = '';
20 // Read server Id from first parameter
21 $Realm = new Realm($this->Database, $RealmId);
22
23 $LogDir = '../realm/'.$RealmId.'/log/';
24 $MangosConfFile = '../realm/'.$RealmId.'/etc/mangosd.conf';
25 $StdOutLogFile = $LogDir.'mangos-worldd.log';
26 $ErrOutLogFile = $LogDir.'mangos-worldd.err';
27 $MangosLogFile = $LogDir.'Server.log';
28 $MangosDbErrorsLogFile = $LogDir.'DBErrors.log';
29
30 if(!file_exists($StdOutLogFile)) exit;
31
32 $Content = file_get_contents($StdOutLogFile);
33 $Lines = explode("\n", $Content);
34 $Content = ''; // Free unused memory
35
36 // Separate information from log file
37 $Line = 0;
38 while(($Line < count($Lines)) and (substr($Lines[$Line], 0, 6) != 'MaNGOS')) $Line++;
39 $MangosVersion = $Lines[$Line];
40
41 // Try to find start of backtrace
42 while(($Line < count($Lines)) and (substr($Lines[$Line], 0, 16) != 'Program received')) $Line++;
43 $Backtrace = array_slice($Lines, $Line, count($Lines) - $Line); // Assume rest of file to be backtrace
44 $Backtrace = addslashes(implode("\n", $Backtrace));
45 $Lines = '';
46
47 //$Log = array_slice($Lines, 0, $Line);
48 //$Log = addslashes(implode("\n", $Log));
49
50 // Get used database version from database
51 $DbResult = $this->Database->query('SELECT * FROM `realm'.$RealmId.'_mangos`.`db_version`');
52 $DbRow = $DbResult->fetch_array();
53 $DbVersion = $DbRow['version'];
54
55 // Get last uptime info
56 $DbResult = $this->Database->query('SELECT * FROM `server'.$Realm->Data['Server'].'_realmd`.`uptime` ORDER BY `starttime` DESC LIMIT 1');
57 //$Output = $this->Database->error;
58 $DbRow = $DbResult->fetch_array();
59 $MaxPlayerCount = $DbRow['maxplayers'];
60 $Uptime = $DbRow['uptime'];
61
62 // Insert data to database
63 $this->Database->query('INSERT INTO `Debug` (`Realm`, `Time`, `MangosVersion`, `DbVersion`, `Uptime`, `MaxPlayerCount`) VALUES ('.$RealmId.', NOW(), "'.$MangosVersion.'", "'.$DbVersion.'", '.$Uptime.', '.$MaxPlayerCount.')');
64 $InsertId = $this->Database->insert_id;
65
66 // Insert data in separate query to partly avoid too long query packet error
67 $this->Database->query('UPDATE `Debug` SET Backtrace="'.$Backtrace.'" WHERE Id='.$InsertId);
68 $Backtrace = '';
69
70 if(file_exists($MangosLogFile))
71 {
72 $Log = addslashes(file_get_contents($MangosLogFile));
73 $this->Database->query('UPDATE `Debug` SET Log="'.$Log.'" WHERE Id='.$InsertId);
74 unlink($MangosLogFile);
75 }
76
77 if(file_exists($MangosDbErrorsLogFile))
78 {
79 $Log = addslashes(file_get_contents($MangosDbErrorsLogFile));
80 $this->Database->query('UPDATE `Debug` SET DbErrors="'.$Log.'" WHERE Id='.$InsertId);
81 unlink($MangosDbErrorsLogFile);
82 }
83
84 if(file_exists($MangosConfFile))
85 {
86 $Configuration = array();
87 $Log = addslashes(file_get_contents($MangosConfFile));
88 $LogLines = explode("\n", $Log);
89 foreach($LogLines as $LogLine)
90 {
91 if(substr($LogLine, 0, 1) != '#') $Configuration[] = $LogLine;
92 }
93 $this->Database->query('UPDATE `Debug` SET Configuration="'.implode("\n", $Configuration).'" WHERE Id='.$InsertId);
94 }
95
96 if(file_exists($ErrOutLogFile))
97 {
98 $Log = addslashes(file_get_contents($ErrOutLogFile));
99 $this->Database->query('UPDATE `Debug` SET ErrorLog="'.$Log.'" WHERE Id='.$InsertId);
100 unlink($ErrOutLogFile);
101 }
102 unlink($StdOutLogFile);
103 return($Output);
104 }
105}
106
107?>
Note: See TracBrowser for help on using the repository browser.