Changeset 57 for trunk/www/model/server.php
- Timestamp:
- Aug 4, 2009, 5:32:06 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.