Changeset 6 for trunk/www/server.php
- Timestamp:
- Jun 10, 2009, 4:57:51 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/www/server.php
r5 r6 1 1 <?php 2 2 3 function ErrorHandler() 4 { 5 } 6 3 7 class Server extends Module 4 8 { … … 15 19 $this->Server = $DbResult->fetch_assoc(); 16 20 $DbResult = $this->Database->query('SELECT * FROM `Database` WHERE `Id`='.$this->Server['Database']); 17 $this->Server['Database'] = $DbResult->fetch_assoc(); 21 if($DbResult->num_rows > 0) $this->Server['Database'] = $DbResult->fetch_assoc(); 22 else $this->Server['Database'] = array('Emulator' => 0); 18 23 $DbResult = $this->Database->query('SELECT * FROM `Emulator` WHERE `Id`='.$this->Server['Database']['Emulator']); 19 $this->Server['Database']['Emulator'] = $DbResult->fetch_assoc(); 24 if($DbResult->num_rows > 0) $this->Server['Database']['Emulator'] = $DbResult->fetch_assoc(); 25 else $this->Server['Database']['Emulator'] = array('ClientVersion' => 0); 20 26 $DbResult = $this->Database->query('SELECT * FROM `ClientVersion` WHERE `Id`='.$this->Server['Database']['Emulator']['ClientVersion']); 21 $this->Server['Database']['Emulator']['ClientVersion'] = $DbResult->fetch_assoc(); 27 if($DbResult->num_rows > 0) $this->Server['Database']['Emulator']['ClientVersion'] = $DbResult->fetch_assoc(); 28 else $this->Server['Database']['Emulator']['ClientVersion'] = array(); 22 29 } 23 30 … … 27 34 } 28 35 29 function ImportDatabase()36 function CreateDatabase() 30 37 { 31 $DbResult = $this->Database->query('SELECT * FROM `Database` WHERE `Id`='.$this->Server['Database']); 32 $Database = $DbResult->fetch_assoc(); 33 $DbResult = $this->Database->query('SELECT `Revision` FROM `Emulator` WHERE `Id`='.$Database['Emulator']); 34 $Emulator = $DbResult->fetch_assoc(); 35 $this->AddTask('Inicializace databáze', array( 36 'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_mangos < emu/mangos/'.$Emulator['Revision'].'/udb/'.$Database['SourceFileName'], 37 'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_scriptdev2 < emu/mangos/'.$Emulator['Revision'].'/source/src/bindings/ScriptDev2/sql/scriptdev2_create_structure.sql', 38 'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_scriptdev2 < emu/mangos/'.$Emulator['Revision'].'/source/src/bindings/ScriptDev2/sql/scriptdev2_script_full.sql', 39 'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_mangos < emu/mangos/'.$Emulator['Revision'].'/source/src/bindings/ScriptDev2/sql/mangos_scriptname_full.sql', 40 'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_realmd < emu/mangos/'.$Emulator['Revision'].'/mangos/sql/realmd.sql', 41 'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_characters < emu/mangos/'.$Emulator['Revision'].'/mangos/sql/characters.sql')); 38 $this->Database->query('CREATE DATABASE `server'.$this->Id.'_realmd`'); 39 $this->Database->query('CREATE DATABASE `server'.$this->Id.'_mangos`'); 40 $this->Database->query('CREATE DATABASE `server'.$this->Id.'_characters`'); 41 $this->Database->query('CREATE DATABASE `server'.$this->Id.'_scriptdev2`'); 42 $this->Database->query('CREATE USER "server'.$this->Id.'"@"localhost" IDENTIFIED BY "server'.$this->Id.'"'); 43 $this->Database->query('GRANT ALL PRIVILEGES ON `server'.$this->Id.'\_realmd` . * TO "server'.$this->Id.'"@"localhost" WITH GRANT OPTION'); 44 $this->Database->query('GRANT ALL PRIVILEGES ON `server'.$this->Id.'\_mangos` . * TO "server'.$this->Id.'"@"localhost" WITH GRANT OPTION'); 45 $this->Database->query('GRANT ALL PRIVILEGES ON `server'.$this->Id.'\_characters` . * TO "server'.$this->Id.'"@"localhost" WITH GRANT OPTION'); 46 $this->Database->query('GRANT ALL PRIVILEGES ON `server'.$this->Id.'\_scriptdev2` . * TO "server'.$this->Id.'"@"localhost" WITH GRANT OPTION'); 47 } 48 49 function DeleteDatabase() 50 { 51 $this->Database->query('DROP DATABASE `server'.$this->Id.'_realmd`'); 52 $this->Database->query('DROP DATABASE `server'.$this->Id.'_mangos`'); 53 $this->Database->query('DROP DATABASE `server'.$this->Id.'_characters`'); 54 $this->Database->query('DROP DATABASE `server'.$this->Id.'_scriptdev2`'); 55 $this->Database->query('DROP USER "server'.$this->Id.'"@"localhost"'); 56 } 57 58 function ImportDatabase($Delete = false) 59 { 60 $CommandList = array( 61 'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_mangos < database/'.$this->Server['Database']['Id'].'/'.$this->Server['Database']['SourceFileName'], 62 'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_scriptdev2 < emulator/'.$this->Server['Database']['Emulator']['Id'].'/source/src/bindings/ScriptDev2/sql/scriptdev2_create_structure.sql', 63 'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_scriptdev2 < emulator/'.$this->Server['Database']['Emulator']['Id'].'/source/src/bindings/ScriptDev2/sql/scriptdev2_script_full.sql', 64 'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_mangos < emulator/'.$this->Server['Database']['Emulator']['Id'].'/source/src/bindings/ScriptDev2/sql/mangos_scriptname_full.sql', 65 'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_realmd < emulator/'.$this->Server['Database']['Emulator']['Id'].'/mangos/sql/realmd.sql', 66 'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_characters < emulator/'.$this->Server['Database']['Emulator']['Id'].'/mangos/sql/characters.sql', 67 ); 68 if($Delete = true) 69 { 70 array_unshift($CommandList, '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'); 71 array_unshift($CommandList, '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'); 72 array_unshift($CommandList, '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'); 73 array_unshift($CommandList, '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'); 74 } 75 $this->AddTask('Inicializace databáze', $CommandList); 42 76 } 43 77 … … 50 84 { 51 85 $this->AddTask('Start emulátoru', array( 52 'screen -A -m -d -S server'.$this->Id.'-realmd "emu /mangos/'.$this->Server['Database']['Emulator']['Revision'].'/bin/mangos-realmd -c server/'.$this->Id.'/etc/realmd.conf"',53 'screen -A -m -d -S server'.$this->Id.'-worldd emu /mangos/'.$this->Server['Database']['Emulator']['Revision'].'/bin/mangos-worldd -c server/'.$this->Id.'/etc/mangosd.conf',86 '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"', 87 'screen -A -m -d -S server'.$this->Id.'-worldd emulator/'.$this->Server['Database']['Emulator']['Id'].'/bin/mangos-worldd -c server/'.$this->Id.'/etc/mangosd.conf', 54 88 )); 55 89 return('Požadavek na start serveru zařazen.'); … … 67 101 function NetworkPortState($Address, $Port, $Timeout = 1) 68 102 { 103 set_error_handler('ErrorHandler'); 69 104 if($Socket = @fsockopen($Address, $Port, $ERROR_NO, $ERROR_STR, (float)$Timeout)) 70 105 { 71 106 fclose($Socket); 72 return(true); 73 } else return(false); 107 $Result = true; 108 } else $Result = false; 109 restore_error_handler(); 110 return($Result); 74 111 } 75 112 … … 79 116 $State['RealmdPortState'] = $this->NetworkPortState('localhost', $this->RealmdBaseNetworkPort + $this->Server['Id']); 80 117 $State['WorlddPortState'] = $this->NetworkPortState('localhost', $this->WorlddBaseNetworkPort + $this->Server['Id']); 118 $State['Online'] = $State['RealmdPortState'] and $State['WorlddPortState']; 119 $DbResult = $this->Database->query('SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = "server'.$this->Id.'_characters"'); 120 $DbRow = $DbResult->fetch_row(); 121 if($DbRow[0] > 0) 122 { 123 $DbResult = $this->Database->query('SELECT COUNT(*) FROM server'.$this->Id.'_characters.characters AS T WHERE T.online = 1'); 124 $DbRow = $DbResult->fetch_row(); 125 $State['OnlinePlayerCount'] = $DbRow[0]; 126 $DbResult = $this->Database->query('SELECT COUNT(*) FROM server'.$this->Id.'_characters.characters AS T'); 127 $DbRow = $DbResult->fetch_row(); 128 $State['CharacterCount'] = $DbRow[0]; 129 $DbResult = $this->Database->query('SELECT COUNT(*) FROM server'.$this->Id.'_realmd.account AS T'); 130 $DbRow = $DbResult->fetch_row(); 131 $State['AccountCount'] = $DbRow[0]; 132 } else 133 { 134 $State['OnlinePlayerCount'] = 0; 135 $State['CharacterCount'] = 0; 136 $State['AccountCount'] = 0; 137 } 81 138 return($State); 139 } 140 141 function UpdateRealmlist() 142 { 143 global $Config; 144 145 $this->Database->query('UPDATE server'.$this->Id.'_realmd.realmlist SET name="'.addslashes($this->Server['Name']).'", address="'.$Config['Web']['Host'].'", port='.($this->WorlddBaseNetworkPort + $this->Id)); 146 } 147 148 function SaveConfiguration() 149 { 150 $this->SetupConfigurationFiles(); 151 $this->UpdateRealmlist(); 82 152 } 83 153 84 154 function SetupConfigurationFiles() 85 155 { 156 $EmulatorEtcDir = '../emulator/'.$this->Server['Database']['Emulator']['Id'].'/etc/'; 157 $ServerEtcDir = '../server/'.$this->Id.'/etc/'; 158 $ServerLogDir = '../server/'.$this->Id.'/log/'; 159 if(!file_exists($ServerEtcDir)) mkdir($ServerEtcDir, 0777, true); 160 if(!file_exists($ServerLogDir)) mkdir($ServerLogDir, 0777, true); 161 86 162 // mangosd.conf 87 163 $Config = new MangosConfigurationFile($this->Database); 88 $Config->Load( '../emu/mangos/'.$this->Server['Database']['Emulator']['Revision'].'/etc/mangosd.conf');164 $Config->Load($EmulatorEtcDir.'mangosd.conf'); 89 165 $Config->ParameterList['LoginDatabaseInfo'] = 'localhost;3306;server'.$this->Id.';server'.$this->Id.';server'.$this->Id.'_realmd'; 90 166 $Config->ParameterList['WorldDatabaseInfo'] = 'localhost;3306;server'.$this->Id.';server'.$this->Id.';server'.$this->Id.'_mangos'; … … 94 170 $Config->ParameterList['Motd'] = $this->Server['Motd']; 95 171 $Config->ParameterList['DataDir'] = 'wowclient/'.$this->Server['Database']['Emulator']['ClientVersion']['Version']; 96 $Config->Save('../server/'.$this->Id.'/etc/mangosd.conf'); 172 $Config->ParameterList['LogsDir'] = 'server/'.$this->Id.'/log'; 173 $ServerTypes = array(0 => 0, 1 => 1, 2 => 6, 3 => 8); 174 $Config->ParameterList['GameType'] = $ServerTypes[$this->Server['Type']]; 175 $Config->Save($ServerEtcDir.'mangosd.conf'); 97 176 98 177 // realmd.conf 99 178 $Config = new MangosConfigurationFile($this->Database); 100 $Config->Load( '../emu/mangos/'.$this->Server['Database']['Emulator']['Revision'].'/etc/realmd.conf');179 $Config->Load($EmulatorEtcDir.'realmd.conf'); 101 180 $Config->ParameterList['LoginDatabaseInfo'] = 'localhost;3306;server'.$this->Id.';server'.$this->Id.';server'.$this->Id.'_realmd'; 102 181 $Config->ParameterList['RealmServerPort'] = $this->RealmdBaseNetworkPort + $this->Id; 103 $Config->Save('../server/'.$this->Id.'/etc/realmd.conf'); 182 $Config->ParameterList['LogsDir'] = 'server/'.$this->Id.'/log'; 183 $Config->Save($ServerEtcDir.'realmd.conf'); 104 184 105 185 // scriptdev2.conf 106 186 $Config = new MangosConfigurationFile($this->Database); 107 $Config->Load( '../emu/mangos/'.$this->Server['Database']['Emulator']['Revision'].'/etc/scriptdev2.conf');187 $Config->Load($EmulatorEtcDir.'scriptdev2.conf'); 108 188 $Config->ParameterList['ScriptDev2DatabaseInfo'] = 'localhost;3306;server'.$this->Id.';server'.$this->Id.';server'.$this->Id.'_scriptdev2'; 109 $Config->Save( '../server/'.$this->Id.'/etc/scriptdev2.conf');189 $Config->Save($ServerEtcDir.'scriptdev2.conf'); 110 190 } 111 191 }
Note:
See TracChangeset
for help on using the changeset viewer.