Changeset 57 for trunk/www/model
- Timestamp:
- Aug 4, 2009, 5:32:06 PM (16 years ago)
- Location:
- trunk/www/model
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/www/model/realm.php
r54 r57 14 14 $DbResult = $this->Database->query('SELECT * FROM `Realm` WHERE `Id`='.$Id); 15 15 if($DbResult->num_rows > 0) 16 { 16 17 $this->Data = $DbResult->fetch_assoc(); 18 $DbResult = $this->Database->query('SELECT * FROM `Database` WHERE `Id`='.$this->Data['Database']); 19 if($DbResult->num_rows > 0) $this->Data['Database'] = $DbResult->fetch_assoc(); 20 else $this->Data['Database'] = array('Emulator' => 0); 21 $DbResult = $this->Database->query('SELECT * FROM `Emulator` WHERE `Id`='.$this->Data['Database']['Emulator']); 22 if($DbResult->num_rows > 0) $this->Data['Database']['Emulator'] = $DbResult->fetch_assoc(); 23 else $this->Data['Database']['Emulator'] = array('Client' => 0); 24 $DbResult = $this->Database->query('SELECT * FROM `Client` WHERE `Id`='.$this->Data['Database']['Emulator']['Client']); 25 if($DbResult->num_rows > 0) $this->Data['Database']['Emulator']['Client'] = $DbResult->fetch_assoc(); 26 else $this->Data['Database']['Emulator']['Client'] = array(); 27 } 17 28 } 18 29 19 30 function GetState() 20 31 { 32 global $System; 33 21 34 $State = array(); 22 $State['WorlddPortState'] = $ this->NetworkPortState('localhost', $this->Server['NetworkPortWorldd']);35 $State['WorlddPortState'] = $System->NetworkPortState('localhost', $this->Data['NetworkPortWorldd']); 23 36 $State['Online'] = $State['WorlddPortState']; 24 37 $DbResult = $this->Database->query('SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = "realm'.$this->Id.'_characters"'); … … 39 52 return($State); 40 53 } 54 55 function CreateDatabase() 56 { 57 $this->Database->query('CREATE DATABASE `realm'.$this->Id.'_mangos`'); 58 $this->Database->query('CREATE DATABASE `realm'.$this->Id.'_characters`'); 59 $this->Database->query('CREATE DATABASE `realm'.$this->Id.'_scriptdev2`'); 60 $this->Database->query('GRANT ALL PRIVILEGES ON `realm'.$this->Id.'\_mangos` . * TO "server'.$this->Data['Server'].'"@"localhost" WITH GRANT OPTION'); 61 $this->Database->query('GRANT ALL PRIVILEGES ON `realm'.$this->Id.'\_characters` . * TO "server'.$this->Data['Server'].'"@"localhost" WITH GRANT OPTION'); 62 $this->Database->query('GRANT ALL PRIVILEGES ON `realm'.$this->Id.'\_scriptdev2` . * TO "server'.$this->Data['Server'].'"@"localhost" WITH GRANT OPTION'); 63 } 64 65 function DeleteDatabase() 66 { 67 $this->Database->query('DROP DATABASE `realm'.$this->Id.'_mangos`'); 68 $this->Database->query('DROP DATABASE `realm'.$this->Id.'_characters`'); 69 $this->Database->query('DROP DATABASE `realm'.$this->Id.'_scriptdev2`'); 70 } 71 72 function ImportDatabase($Delete = false) 73 { 74 $this->Lock(); 75 $CommandList = array( 76 'php www/shell.php RealmLock '.$this->Id, 77 ); 78 if($Delete == true) 79 { 80 $CommandList = array_merge($CommandList, array( 81 'mysql --silent --skip-column-names -u server'.$this->Data['Server'].' -pserver'.$this->Data['Server'].' realm'.$this->Id.'_mangos -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$this->Data['Server'].' -pserver'.$this->Data['Server'].' realm'.$this->Id.'_mangos', 82 'mysql --silent --skip-column-names -u server'.$this->Data['Server'].' -pserver'.$this->Data['Server'].' realm'.$this->Id.'_characters -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$this->Data['Server'].' -pserver'.$this->Data['Server'].' realm'.$this->Id.'_characters', 83 'mysql --silent --skip-column-names -u server'.$this->Data['Server'].' -pserver'.$this->Data['Server'].' realm'.$this->Id.'_scriptdev2 -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$this->Data['Server'].' -pserver'.$this->Data['Server'].' realm'.$this->Id.'_scriptdev2', 84 )); 85 } 86 // Lookup nearest database with full import 87 $DbResult = $this->Database->query('SELECT * FROM `Database` WHERE (`Emulator` <> 0) AND (`Revision` <= '.$this->Server['Database']['Revision'].') AND (`SourceFileName` <> "") ORDER BY `Revision` DESC'); 88 $Database = $DbResult->fetch_assoc(); 89 90 $CommandList = array_merge($CommandList, array( 91 'mysql --user=server'.$this->Data['Server'].' --password=server'.$this->Data['Server'].' realm'.$this->Id.'_mangos < database/'.$Database['Id'].'/'.$Database['SourceFileName'], 92 'mysql --user=server'.$this->Data['Server'].' --password=server'.$this->Data['Server'].' realm'.$this->Id.'_scriptdev2 < emulator/'.$Database['Emulator']['Id'].'/source/src/bindings/ScriptDev2/sql/scriptdev2_create_structure.sql', 93 'mysql --user=server'.$this->Data['Server'].' --password=server'.$this->Data['Server'].' realm'.$this->Id.'_scriptdev2 < emulator/'.$Database['Emulator']['Id'].'/source/src/bindings/ScriptDev2/sql/scriptdev2_script_full.sql', 94 'mysql --user=server'.$this->Data['Server'].' --password=server'.$this->Data['Server'].' realm'.$this->Id.'_mangos < emulator/'.$Database['Emulator']['Id'].'/source/src/bindings/ScriptDev2/sql/mangos_scriptname_full.sql', 95 'mysql --user=server'.$this->Data['Server'].' --password=server'.$this->Data['Server'].' realm'.$this->Id.'_characters < emulator/'.$Database['Emulator']['Id'].'/share/mangos/sql/characters.sql', 96 'php www/shell.php RealmDatabaseChange '.$this->Id.' '.$Database['Id'], 97 'php www/shell.php RealmUnLock '.$this->Id, 98 )); 99 $this->Task->Add('Inicializace databáze', $CommandList); 100 101 if($Database['Id'] != $this->Server['Database']['Id']) 102 { 103 $NewDatabaseId = $this->Server['Database']['Id']; 104 $this->Server['Database']['Id'] = $Database['Id']; 105 $this->Update($NewDatabaseId, false, false); 106 } 107 return('Úloha načtení nové databáze zařazena do fronty.'); 108 } 109 110 function Start() 111 { 112 $this->Lock(); 113 $this->SaveConfiguration(); 114 $this->Task->Add('Start světa', array( 115 'php www/shell.php RealmLock '.$this->Id, 116 'realm/'.$this->Id.'/bin/start.sh', 117 'php www/shell.php RealmUnLock '.$this->Id, 118 )); 119 return('Požadavek na start světa zařazen.'); 120 } 121 122 function Stop() 123 { 124 $this->Lock(); 125 $this->Task->Add('Zastavení světa', array( 126 'php www/shell.php RealmLock '.$this->Id, 127 'realm/'.$this->Id.'/bin/stop.sh', 128 'php www/shell.php RealmUnLock '.$this->Id, 129 )); 130 return('Požadavek na zastavení světa zařazen.'); 131 } 132 133 function UpdateRealmlist() 134 { 135 $Server = new Server($this->Database, $this->Data['Server']); 136 $Server->UpdateRealmList(); 137 } 138 139 function SaveConfiguration() 140 { 141 $this->SetupConfigurationFiles(); 142 $this->UpdateRealmlist(); 143 $this->UpdateScripts(); 144 } 145 146 function UpdateScripts() 147 { 148 global $Config; 149 150 $RealmBinDir = '../realm/'.$this->Id.'/bin/'; 151 if(!file_exists($RealmBinDir)) mkdir($RealmBinDir, 0777, true); 152 153 // GDB script 154 $ScriptFileName = '../realm/'.$this->Id.'/bin/mangos.gdb'; 155 $Content = array 156 ( 157 'run -c realm/'.$this->Id.'/etc/mangosd.conf', 158 'info thread', 159 ); 160 for($I = 1; $I < $Config['MangosWorlddThreadCountMax']; $I++) 161 $Content[] = 'thread apply '.$I.' bt full'; 162 file_put_contents($ScriptFileName, implode("\n", $Content)); 163 chmod($ScriptFileName, 0666); 164 165 // Start script 166 $ScriptFileName = '../realm/'.$this->Id.'/bin/start.sh'; 167 $Content = array 168 ( 169 '#!/bin/sh', 170 'if [ -z `ps -ef | grep \'SCREEN -A -m -d -S realm'.$this->Id.'-worldd\' | grep -v grep | awk \'{print $2}\'` ]', 171 'then', 172 'screen -A -m -d -S realm'.$this->Id.'-worldd realm/'.$this->Id.'/bin/worldd_restarter.sh', 173 'fi', 174 ); 175 file_put_contents($ScriptFileName, implode("\n", $Content)); 176 chmod($ScriptFileName, 0777); 177 178 $ScriptFileName = '../realm/'.$this->Id.'/bin/worldd_restarter.sh'; 179 $Content = array 180 ( 181 '#!/bin/sh', 182 'while [ 1=1 ] ; do', 183 'gdb emulator/'.$this->Data['Database']['Emulator']['Id'].'/bin/mangos-worldd -x realm/'.$this->Id.'/bin/mangos.gdb --batch >>realm/'.$this->Id.'/log/mangos-worldd.log 2>>realm/'.$this->Id.'/log/mangos-worldd.err', 184 'cd www', 185 'php shell.php ServerProcessLog '.$this->Id.' >>realm/'.$this->Id.'/log/mangos_debug.log 2>>realm/'.$this->Id.'/log/mangos_debug.err', 186 'cd ..', 187 'sleep 3', 188 'done', 189 ); 190 file_put_contents($ScriptFileName, implode("\n", $Content)); 191 chmod($ScriptFileName, 0777); 192 193 // Stop script 194 $ScriptFileName = '../realm/'.$this->Id.'/bin/stop.sh'; 195 $Content = array 196 ( 197 '#!/bin/sh', 198 'ps -ef | grep \'SCREEN -A -m -d -S realm'.$this->Id.'-worldd\' | grep -v grep | awk \'{print $2}\' | xargs -i kill {}', 199 ); 200 file_put_contents($ScriptFileName, implode("\n", $Content)); 201 chmod($ScriptFileName, 0777); 202 } 203 204 function SetupConfigurationFiles() 205 { 206 global $Config; 207 208 $EmulatorEtcDir = '../emulator/'.$this->Data['Database']['Emulator']['Id'].'/etc/'; 209 $RealmEtcDir = '../realm/'.$this->Id.'/etc/'; 210 $RealmLogDir = '../realm/'.$this->Id.'/log/'; 211 if(!file_exists($RealmEtcDir)) mkdir($RealmEtcDir, 0777, true); 212 if(!file_exists($RealmLogDir)) mkdir($RealmLogDir, 0777, true); 213 214 // mangosd.conf 215 $EmulatorConfig = new MangosConfigurationFile($this->Database); 216 $EmulatorConfig->Load($EmulatorEtcDir.'mangosd.conf.dist'); 217 $EmulatorConfig->ParameterList['LoginDatabaseInfo'] = 'localhost;3306;server'.$this->Id.';server'.$this->Id.';server'.$this->Id.'_realmd'; 218 $EmulatorConfig->ParameterList['WorldDatabaseInfo'] = 'localhost;3306;server'.$this->Id.';server'.$this->Id.';server'.$this->Id.'_mangos'; 219 $EmulatorConfig->ParameterList['CharacterDatabaseInfo'] = 'localhost;3306;server'.$this->Data['Server'].';server'.$this->Data['Server'].';realm'.$this->Id.'_characters'; 220 $EmulatorConfig->ParameterList['ScriptDev2DatabaseInfo'] = 'localhost;3306;server'.$this->Data['Server'].';server'.$this->Data['Server'].';realm'.$this->Id.'_scriptdev2'; 221 $EmulatorConfig->ParameterList['WorldServerPort'] = $this->Data['NetworkPortWorldd']; 222 $EmulatorConfig->ParameterList['Motd'] = $this->Data['Motd']; 223 print_r($this->Data); 224 $EmulatorConfig->ParameterList['DataDir'] = 'wowclient/'.$this->Data['Database']['Emulator']['Client']['Version']; 225 $EmulatorConfig->ParameterList['LogsDir'] = 'server/'.$this->Id.'/log'; 226 $EmulatorConfig->ParameterList['LogLevel'] = 1; 227 $EmulatorConfig->ParameterList['PlayerLimit'] = $Config['MaxOnlinePlayerCountPerServer']; 228 $EmulatorConfig->ParameterList['PlayerSaveInterval'] = 300000; 229 $EmulatorConfig->ParameterList['LogSQL'] = 0; 230 $ServerTypes = array(0 => 0, 1 => 1, 2 => 6, 3 => 8); 231 $EmulatorConfig->ParameterList['GameType'] = $ServerTypes[$this->Data['Type']]; 232 $EmulatorConfig->Save($RealmEtcDir.'mangosd.conf'); 233 234 // scriptdev2.conf 235 $EmulatorConfig = new MangosConfigurationFile($this->Database); 236 $EmulatorConfig->Load($EmulatorEtcDir.'scriptdev2.conf'); 237 $EmulatorConfig->ParameterList['ScriptDev2DatabaseInfo'] = 'localhost;3306;server'.$this->Data['Server'].';server'.$this->Data['Server'].';realm'.$this->Id.'_scriptdev2'; 238 $EmulatorConfig->Save($RealmEtcDir.'scriptdev2.conf'); 239 } 240 241 function Update($DatabaseId, $DoBackup = true, $DoStop = true) 242 { 243 $this->Lock(); 244 $Output = ''; 245 246 // Stop server before update 247 if($DoStop) 248 { 249 $Output .= $this->Stop(); 250 } 251 252 // Backup current 253 if($DoBackup) 254 { 255 $Backup = new Backup($this->Database, 0); 256 $Output .= '<br />'.$Backup->Create($this->Id); 257 } 258 259 // Do update 260 $Commands = array( 261 'php www/shell.php RealmLock '.$this->Id, 262 ); 263 $DbResult = $this->Database->query('SELECT `Revision` FROM `Database` WHERE `Id` = '.$this->Server['Database']['Id']); 264 $DbRow = $DbResult->fetch_assoc(); 265 $DatabaseRevisionStart = $DbRow['Revision']; 266 $DbResult = $this->Database->query('SELECT `Revision` FROM `Database` WHERE `Id` = '.$DatabaseId); 267 $DbRow = $DbResult->fetch_assoc(); 268 $DatabaseRevisionEnd = $DbRow['Revision']; 269 $DbResult = $this->Database->query('SELECT * FROM `Database` WHERE (`Revision` > '.$DatabaseRevisionStart.') AND (`Revision` <= '.$DatabaseRevisionEnd.') ORDER BY `Revision`'); 270 while($DbRow = $DbResult->fetch_assoc()) 271 { 272 $Updates = explode("\n", $DbRow['Update']); 273 foreach($Updates as $Update) 274 if($Update != '') 275 { 276 $Parts = explode('|', $Update); 277 $Command = 'mysql --user=server'.$this->Data['Server'].' --password=server'.$this->Data['Server'].' realm'.$this->Id.'_'.$Parts[0].' < database/'.$DbRow['Id'].'/'.$Parts[1]; 278 $Commands[] = $Command; 279 } 280 } 281 $Commands = array_merge($Commands, array( 282 'php www/shell.php RealmDatabaseChange '.$this->Id.' '.$DatabaseId, 283 'php www/shell.php RealmUnLock '.$this->Id, 284 )); 285 286 $this->Task->Add('Aktualizace databáze', $Commands); 287 $Output .= '<br />Úloha aktualizace serveru byla přidána do fronty.'; 288 return($Output); 289 } 290 291 function Lock() 292 { 293 $this->Database->update('Realm', 'Id='.$this->Id, array('Lock' => 1)); 294 } 295 296 function UnLock() 297 { 298 $this->Database->update('Realm', 'Id='.$this->Id, array('Lock' => 0)); 299 } 300 301 function ChangeDatabaseId($Id) 302 { 303 $this->Database->update('Realm', 'Id='.$this->Id, array('Database' => $Id)); 304 $this->SaveConfiguration(); 305 } 306 307 function GetUsedMemory() 308 { 309 $Output = array(); 310 if(isset($this->Server['Database']['Emulator']['Id'])) 311 exec('ps -aux|grep "emulator/'.$this->Server['Database']['Emulator']['Id'].'/bin/mangos-worldd -c realm/'.$this->Id.'/etc/mangosd.conf"| grep -v grep', $Output); 312 if(count($Output) > 0) 313 { 314 while(strpos($Output[0], ' ') > 0) $Output[0] = str_replace(' ', ' ', $Output[0]); 315 $Parts = explode(' ', $Output[0]); 316 return($Parts[4]); 317 } else return(0); 318 } 319 320 function ProcessLog() 321 { 322 $File = fopen('../realm/'.$this->Id.'/log/mangos-worldd.log', 'r'); 323 while(true) 324 { 325 $Reders = array($File); 326 if(stream_select($Reders, $Writers=null, $Except=null, 0, 15) < 1) 327 { 328 continue; 329 } else 330 { 331 // read data from the fifo 332 $Data = fread($File, 1024); 333 echo($Data); 334 $this->Database->insert('RealmLog', array('Time' => 'NOW()', 'Realm' => $this->Id, 'Text' => $Data)); 335 } 336 sleep(1); 337 } 338 fclose($File); 339 } 340 341 function GetUser() 342 { 343 $DbResult = $this->Database->select('Server', 'User', 'Id='.$this->Data['Server']); 344 $DbRow = $DbResult->fetch_assoc(); 345 return($DbRow['User']); 346 } 41 347 } 42 348 -
trunk/www/model/server.php
r54 r57 1 1 <?php 2 2 3 function ErrorHandler()4 {5 }6 7 3 class Server extends Module 8 4 { … … 35 31 { 36 32 $this->Database->query('CREATE DATABASE `server'.$this->Id.'_realmd`'); 37 $this->Database->query('CREATE DATABASE `server'.$this->Id.'_mangos`');38 $this->Database->query('CREATE DATABASE `server'.$this->Id.'_characters`');39 $this->Database->query('CREATE DATABASE `server'.$this->Id.'_scriptdev2`');40 33 $this->Database->query('CREATE USER "server'.$this->Id.'"@"localhost" IDENTIFIED BY "server'.$this->Id.'"'); 41 34 $this->Database->query('GRANT ALL PRIVILEGES ON `server'.$this->Id.'\_realmd` . * TO "server'.$this->Id.'"@"localhost" WITH GRANT OPTION'); 42 $this->Database->query('GRANT ALL PRIVILEGES ON `server'.$this->Id.'\_mangos` . * TO "server'.$this->Id.'"@"localhost" WITH GRANT OPTION');43 $this->Database->query('GRANT ALL PRIVILEGES ON `server'.$this->Id.'\_characters` . * TO "server'.$this->Id.'"@"localhost" WITH GRANT OPTION');44 $this->Database->query('GRANT ALL PRIVILEGES ON `server'.$this->Id.'\_scriptdev2` . * TO "server'.$this->Id.'"@"localhost" WITH GRANT OPTION');45 35 } 46 36 … … 48 38 { 49 39 $this->Database->query('DROP DATABASE `server'.$this->Id.'_realmd`'); 50 $this->Database->query('DROP DATABASE `server'.$this->Id.'_mangos`');51 $this->Database->query('DROP DATABASE `server'.$this->Id.'_characters`');52 $this->Database->query('DROP DATABASE `server'.$this->Id.'_scriptdev2`');53 40 $this->Database->query('DROP USER "server'.$this->Id.'"@"localhost"'); 54 41 } … … 63 50 { 64 51 $CommandList = array_merge($CommandList, array( 65 'mysql --silent --skip-column-names -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_mangos -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_mangos',66 'mysql --silent --skip-column-names -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_characters -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_characters',67 52 'mysql --silent --skip-column-names -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_realmd -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_realmd', 68 'mysql --silent --skip-column-names -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_scriptdev2 -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_scriptdev2',69 53 )); 70 54 } … … 74 58 75 59 $CommandList = array_merge($CommandList, array( 76 'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_mangos < database/'.$Database['Id'].'/'.$Database['SourceFileName'],77 'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_scriptdev2 < emulator/'.$Database['Emulator']['Id'].'/source/src/bindings/ScriptDev2/sql/scriptdev2_create_structure.sql',78 'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_scriptdev2 < emulator/'.$Database['Emulator']['Id'].'/source/src/bindings/ScriptDev2/sql/scriptdev2_script_full.sql',79 'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_mangos < emulator/'.$Database['Emulator']['Id'].'/source/src/bindings/ScriptDev2/sql/mangos_scriptname_full.sql',80 60 'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_realmd < emulator/'.$Database['Emulator']['Id'].'/share/mangos/sql/realmd.sql', 81 'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_characters < emulator/'.$Database['Emulator']['Id'].'/share/mangos/sql/characters.sql',82 61 'php www/shell.php ServerDatabaseChange '.$this->Id.' '.$Database['Id'], 83 62 'php www/shell.php ServerUnLock '.$this->Id, … … 116 95 return('Požadavek na zastavení serveru zařazen.'); 117 96 } 118 119 function NetworkPortState($Address, $Port, $Timeout = 1) 120 { 121 set_error_handler('ErrorHandler'); 122 if($Socket = @fsockopen($Address, $Port, $ERROR_NO, $ERROR_STR, (float)$Timeout)) 123 { 124 fclose($Socket); 125 $Result = true; 126 } else $Result = false; 127 restore_error_handler(); 128 return($Result); 129 } 130 97 131 98 function GetState() 132 99 { 100 global $System; 101 133 102 $State = array(); 134 $State['RealmdPortState'] = $ this->NetworkPortState('localhost', $this->Server['NetworkPortRealmd']);103 $State['RealmdPortState'] = $System->NetworkPortState('localhost', $this->Server['NetworkPortRealmd']); 135 104 $State['Online'] = $State['RealmdPortState']; 136 105 $DbResult = $this->Database->query('SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = "server'.$this->Id.'_realmd"'); … … 160 129 global $Config; 161 130 162 $this->Database->query('UPDATE server'.$this->Id.'_realmd.realmlist SET name="'.addslashes($this->Server['Name']).'", address="'.$Config['Web']['Host'].'", port='.($this->Server['NetworkPortWorldd'])); 131 $this->Database->query('TRUNCATE TABLE server'.$this->Id.'_realmd.realmlist'); 132 $DbResult = $this->Database->select('Realm', '*', 'Server = '.$this->Id); 133 while($Realm = $DbResult->fetch_assoc()) 134 { 135 $this->Database->insert('server'.$this->Id.'_realmd`.`realmlist', array('name' => addslashes($Realm['Name']), 'address' => $Config['Web']['Host'], 'port' => $Realm['NetworkPortWorldd'])); 136 } 163 137 } 164 138 … … 175 149 176 150 $ServerBinDir = '../server/'.$this->Id.'/bin/'; 177 if(!file_exists($ServerBinDir)) mkdir($ServerBinDir, 0777, true); 178 179 // GDB script 180 $ScriptFileName = '../server/'.$this->Id.'/bin/mangos.gdb'; 181 $Content = array 182 ( 183 'run -c server/'.$this->Id.'/etc/mangosd.conf', 184 'info thread', 185 ); 186 for($I = 1; $I < $Config['MangosWorlddThreadCountMax']; $I++) 187 $Content[] = 'thread apply '.$I.' bt full'; 188 file_put_contents($ScriptFileName, implode("\n", $Content)); 189 chmod($ScriptFileName, 0666); 151 if(!file_exists($ServerBinDir)) mkdir($ServerBinDir, 0777, true); 190 152 191 153 // Start script … … 198 160 'screen -A -m -d -S server'.$this->Id.'-realmd emulator/'.$this->Server['Database']['Emulator']['Id'].'/bin/mangos-realmd -c server/'.$this->Id.'/etc/realmd.conf', 199 161 'fi', 200 'if [ -z `ps -ef | grep \'SCREEN -A -m -d -S server'.$this->Id.'-worldd\' | grep -v grep | awk \'{print $2}\'` ]',201 'then',202 'screen -A -m -d -S server'.$this->Id.'-worldd server/'.$this->Id.'/bin/worldd_restarter.sh',203 'fi',204 );205 file_put_contents($ScriptFileName, implode("\n", $Content));206 chmod($ScriptFileName, 0777);207 208 $ScriptFileName = '../server/'.$this->Id.'/bin/worldd_restarter.sh';209 $Content = array210 (211 '#!/bin/sh',212 'while [ 1=1 ] ; do',213 'gdb emulator/'.$this->Server['Database']['Emulator']['Id'].'/bin/mangos-worldd -x server/'.$this->Id.'/bin/mangos.gdb --batch >>server/'.$this->Id.'/log/mangos-worldd.log 2>>server/'.$this->Id.'/log/mangos-worldd.err',214 'cd www',215 'php shell.php ServerProcessLog '.$this->Id.' >>server/'.$this->Id.'/log/mangos_debug.log 2>>server/'.$this->Id.'/log/mangos_debug.err',216 'cd ..',217 'sleep 3',218 'done',219 162 ); 220 163 file_put_contents($ScriptFileName, implode("\n", $Content)); … … 227 170 '#!/bin/sh', 228 171 'ps -ef | grep \'SCREEN -A -m -d -S server'.$this->Id.'-realmd\' | grep -v grep | awk \'{print $2}\' | xargs -i kill {}', 229 'ps -ef | grep \'SCREEN -A -m -d -S server'.$this->Id.'-worldd\' | grep -v grep | awk \'{print $2}\' | xargs -i kill {}',230 172 ); 231 173 file_put_contents($ScriptFileName, implode("\n", $Content)); … … 243 185 if(!file_exists($ServerLogDir)) mkdir($ServerLogDir, 0777, true); 244 186 245 // mangosd.conf246 $EmulatorConfig = new MangosConfigurationFile($this->Database);247 $EmulatorConfig->Load($EmulatorEtcDir.'mangosd.conf.dist');248 $EmulatorConfig->ParameterList['LoginDatabaseInfo'] = 'localhost;3306;server'.$this->Id.';server'.$this->Id.';server'.$this->Id.'_realmd';249 $EmulatorConfig->ParameterList['WorldDatabaseInfo'] = 'localhost;3306;server'.$this->Id.';server'.$this->Id.';server'.$this->Id.'_mangos';250 $EmulatorConfig->ParameterList['CharacterDatabaseInfo'] = 'localhost;3306;server'.$this->Id.';server'.$this->Id.';server'.$this->Id.'_characters';251 $EmulatorConfig->ParameterList['ScriptDev2DatabaseInfo'] = 'localhost;3306;server'.$this->Id.';server'.$this->Id.';server'.$this->Id.'_scriptdev2';252 $EmulatorConfig->ParameterList['WorldServerPort'] = $this->Server['NetworkPortWorldd'];253 $EmulatorConfig->ParameterList['Motd'] = $this->Server['Motd'];254 $EmulatorConfig->ParameterList['DataDir'] = 'wowclient/'.$this->Server['Database']['Emulator']['Client']['Version'];255 $EmulatorConfig->ParameterList['LogsDir'] = 'server/'.$this->Id.'/log';256 $EmulatorConfig->ParameterList['LogLevel'] = 1;257 $EmulatorConfig->ParameterList['PlayerLimit'] = $Config['MaxOnlinePlayerCountPerServer'];258 $EmulatorConfig->ParameterList['PlayerSaveInterval'] = 300000;259 $EmulatorConfig->ParameterList['LogSQL'] = 0;260 $ServerTypes = array(0 => 0, 1 => 1, 2 => 6, 3 => 8);261 $EmulatorConfig->ParameterList['GameType'] = $ServerTypes[$this->Server['Type']];262 $EmulatorConfig->Save($ServerEtcDir.'mangosd.conf');263 264 187 // realmd.conf 265 188 $EmulatorConfig = new MangosConfigurationFile($this->Database); … … 269 192 $EmulatorConfig->ParameterList['LogsDir'] = 'server/'.$this->Id.'/log'; 270 193 $EmulatorConfig->Save($ServerEtcDir.'realmd.conf'); 271 272 // scriptdev2.conf273 $EmulatorConfig = new MangosConfigurationFile($this->Database);274 $EmulatorConfig->Load($EmulatorEtcDir.'scriptdev2.conf');275 $EmulatorConfig->ParameterList['ScriptDev2DatabaseInfo'] = 'localhost;3306;server'.$this->Id.';server'.$this->Id.';server'.$this->Id.'_scriptdev2';276 $EmulatorConfig->Save($ServerEtcDir.'scriptdev2.conf');277 194 } 278 195 … … 379 296 function GetUsedMemory() 380 297 { 381 $Output = array(); 382 if(isset($this->Server['Database']['Emulator']['Id'])) 383 exec('ps -aux|grep "emulator/'.$this->Server['Database']['Emulator']['Id'].'/bin/mangos-worldd -c server/'.$this->Id.'/etc/mangosd.conf"| grep -v grep', $Output); 384 if(count($Output) > 0) 385 { 386 while(strpos($Output[0], ' ') > 0) $Output[0] = str_replace(' ', ' ', $Output[0]); 387 $Parts = explode(' ', $Output[0]); 388 return($Parts[4]); 389 } else return(0); 298 $UsedMemory = 0; 299 $DbResult = $this->Database->select('Realm', 'Id', 'Server='.$this->Id); 300 while($DbRow = $DbResult->fetch_assoc()) 301 { 302 $Realm = new Realm($this->Database, $DbRow['Id']); 303 $UsedMemory += $Realm->GetUsedMemory(); 304 } 305 return($UsedMemory); 390 306 } 391 307 … … 400 316 } 401 317 return(implode("\n", $Output)); 402 } 403 404 function ProcessLog() 405 { 406 $File = fopen('../server/'.$this->Id.'/log/mangos-worldd.log', 'r'); 407 while(true) 408 { 409 $Reders = array($File); 410 if(stream_select($Reders, $Writers=null, $Except=null, 0, 15) < 1) 411 { 412 continue; 413 } else 414 { 415 // read data from the fifo 416 $Data = fread($File, 1024); 417 echo($Data); 418 $this->Database->insert('ServerLog', array('Time' => 'NOW()', 'Server' => $this->Id, 'Text' => $Data)); 419 } 420 sleep(1); 421 } 422 fclose($File); 423 } 318 } 319 320 function RealmCount() 321 { 322 $DbResult = $this->Database->query('SELECT COUNT(*) FROM Realm WHERE Server='.$this->Id); 323 $DbRow = $DbResult->fetch_row(); 324 return($DbRow[0]); 325 } 424 326 } 425 327 -
trunk/www/model/shell.php
r54 r57 1 1 <?php 2 3 include('global.php');4 2 5 3 class Shell extends Module … … 54 52 $Server->UnLock(); 55 53 } else $Output = 'Jako druhý parameter je nutno zadat Id serveru.'; 54 } else 55 if($Command == 'RealmLock') 56 { 57 if((count($_SERVER['argv']) > 2) and is_numeric($_SERVER['argv'][2])) 58 { 59 $Realm = new Realm($this->Database, $_SERVER['argv'][2]); 60 $Realm->Lock(); 61 } else $Output = 'Jako druhý parameter je nutno zadat Id světa.'; 62 } else 63 if($Command == 'RealmUnLock') 64 { 65 if((count($_SERVER['argv']) > 2) and is_numeric($_SERVER['argv'][2])) 66 { 67 $Realm = new Realm($this->Database, $_SERVER['argv'][2]); 68 $Realm->UnLock(); 69 } else $Output = 'Jako druhý parameter je nutno zadat Id světa.'; 56 70 } else 57 71 if($Command == 'EmulatorLock') … … 131 145 $Server->ChangeDatabaseId($_SERVER['argv'][3]); 132 146 } else $Output = 'Jako druhý parameter je nutno zadat Id serveru, jako třetí Id databáze.'; 147 } else 148 if($Command == 'RealmDatabaseChange') 149 { 150 if((count($_SERVER['argv']) > 3) and is_numeric($_SERVER['argv'][2]) and is_numeric($_SERVER['argv'][3])) 151 { 152 $Realm = new Realm($this->Database, $_SERVER['argv'][2]); 153 $Realm->ChangeDatabaseId($_SERVER['argv'][3]); 154 } else $Output = 'Jako druhý parameter je nutno zadat Id světa, jako třetí Id databáze.'; 133 155 } else 134 156 $Output = 'Neznámý příkaz '.$Command; … … 138 160 } 139 161 140 $Shell = new Shell($Database);141 echo($Shell->Show());142 143 162 ?> -
trunk/www/model/user.php
r54 r57 148 148 else 149 149 { 150 $this->Database->update('User', 'Id='.$Row['Id'], array('LastLoginTime' => 'NOW()', 'LastIpAddress' => GetRemoteAddress())); 150 $this->Database->update('User', 'Id='.$Row['Id'], array('LastLoginTime' => 'NOW()', 'LastIpAddress' => GetRemoteAddress())); 151 151 $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('User' => $Row['Id'])); 152 152 // načtení stavu stromu … … 216 216 function CheckPermission($Module, $Operation, $ItemType = '', $ItemIndex = 0) 217 217 { 218 218 $DbResult = $this->Database->select('PermissionOperation', 'Id', '`Module`="'.$Module.'" AND `Item`="'.$ItemType.'" AND `ItemId`='.$ItemIndex.' AND `Operation`="'.$Operation.'"'); 219 219 if($DbResult->num_rows > 0) 220 220 { … … 272 272 return($Output); 273 273 } 274 275 function ServerCount() 276 { 277 $DbResult = $this->Database->query('SELECT COUNT(*) FROM Server WHERE User='.$this->User['Id']); 278 $DbRow = $DbResult->fetch_row(); 279 return($DbRow[0]); 280 } 281 282 function RealmCount() 283 { 284 $Total = 0; 285 $DbResult = $this->Database->query('SELECT Id FROM Server WHERE User='.$this->User['Id']); 286 while($DbRow = $DbResult->fetch_assoc()) 287 { 288 $Server = new Server($this->Database, $DbRow['Id']); 289 $Total += $Server->RealmCount(); 290 } 291 return($Total); 292 } 274 293 } 275 294
Note:
See TracChangeset
for help on using the changeset viewer.