Changeset 57
- Timestamp:
- Aug 4, 2009, 5:32:06 PM (15 years ago)
- Location:
- trunk/www
- Files:
-
- 3 added
- 2 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/www/common/global.php
r55 r57 70 70 ); 71 71 72 function ErrorHandler() 73 { 74 } 75 72 76 class System extends Module 73 77 { … … 171 175 return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit); 172 176 } 177 178 function NetworkPortState($Address, $Port, $Timeout = 1) 179 { 180 set_error_handler('ErrorHandler'); 181 if($Socket = @fsockopen($Address, $Port, $ERROR_NO, $ERROR_STR, (float)$Timeout)) 182 { 183 fclose($Socket); 184 $Result = true; 185 } else $Result = false; 186 restore_error_handler(); 187 return($Result); 188 } 173 189 } 174 190 -
trunk/www/common/page.php
r55 r57 45 45 ' | <a href="http://svn.zdechov.net/trac/wowhosting/log?verbose=on">Novinky</a>'. 46 46 ' | Správce: '.$this->System->Config['Web']['Admin']. 47 ' | E-mail: '.$this->System->Config['Web']['AdminEmail'] ;47 ' | E-mail: '.$this->System->Config['Web']['AdminEmail'].' | '; 48 48 if($this->System->Config['Web']['ShowRuntimeInfo'] == true) $Output .= ' Doba generování: '.$Time.' s / '.ini_get('max_execution_time').' s | Použitá paměť: '.HumanSize(memory_get_peak_usage(FALSE)).' / '.ini_get('memory_limit').'B |'; 49 49 $Output .= '</i></div></body></html>'; -
trunk/www/include.php
r55 r57 1 1 <?php 2 3 // Change current directory to script location 4 $BaseDir = substr($_SERVER['SCRIPT_FILENAME'], 0, strrpos($_SERVER['SCRIPT_FILENAME'], '/')); 5 if($BaseDir != '') chdir($BaseDir); 2 6 3 7 include('config.php'); … … 25 29 include('model/platform.php'); 26 30 include('model/history.php'); 31 include('model/shell.php'); 27 32 28 33 include('view/user.php'); … … 39 44 include('view/debug.php'); 40 45 46 include('init.php'); 47 41 48 ?> -
trunk/www/index.php
r55 r57 2 2 3 3 include('include.php'); 4 5 chdir(substr($_SERVER['SCRIPT_FILENAME'], 0, strrpos($_SERVER['SCRIPT_FILENAME'], '/')));6 7 $ScriptTimeStart = GetMicrotime();8 // SQL injection hack protection9 foreach($_POST as $Index => $Item) $_POST[$Index] = addslashes($Item);10 foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($Item);11 12 if(isset($_SERVER['REMOTE_ADDR'])) session_start();13 $Database = new Database($Config['Database']['Host'], $Config['Database']['User'], $Config['Database']['Password'], $Config['Database']['Database']);14 $Database->Prefix = $Config['Database']['Prefix'];15 $Database->charset($Config['Database']['Charset']);16 17 $System = new System($Database, null);18 $System->Config = $Config;19 $System->AddModule(new Log($Database, $System));20 $System->AddModule(new User($Database, $System));21 if(isset($_SERVER['REMOTE_ADDR'])) $System->Modules['User']->Check();22 else $System->Modules['User']->User['Id'] = 0;23 4 24 5 class Index extends Page … … 116 97 $Output .= $ServerView->Save(); 117 98 } else 118 if($_GET['Action'] == 'ServerEditDetailed')119 {120 $ServerView = new ServerView($this->Database, $this->System);121 $Output .= $ServerView->EditDetailed();122 } else123 if($_GET['Action'] == 'ServerSaveDetailed')124 {125 $ServerView = new ServerView($this->Database, $this->System);126 $Output .= $ServerView->SaveDetailed();127 } else128 99 if($_GET['Action'] == 'ServerStart') 129 100 { … … 161 132 $Output .= $EmulatorView->Download(); 162 133 } else 134 if($_GET['Action'] == 'EmulatorAdd') 135 { 136 $EmulatorView = new EmulatorView($this->Database, $this->System); 137 $Output .= $EmulatorView->Add(); 138 } else 139 if($_GET['Action'] == 'EmulatorAdd2') 140 { 141 $EmulatorView = new EmulatorView($this->Database, $this->System); 142 $Output .= $EmulatorView->AddFinish(); 143 } else 163 144 if($_GET['Action'] == 'ServerDebug') 164 145 { … … 196 177 $Output .= $ServerView->AccountCreateFinish(); 197 178 } else 198 if($_GET['Action'] == 'EmulatorAdd')199 {200 $EmulatorView = new EmulatorView($this->Database, $this->System);201 $Output .= $EmulatorView->Add();202 } else203 if($_GET['Action'] == 'EmulatorAdd2')204 {205 $EmulatorView = new EmulatorView($this->Database, $this->System);206 $Output .= $EmulatorView->AddFinish();207 } else208 179 if($_GET['Action'] == 'Info') 209 180 { … … 265 236 $RealmView = new RealmView($this->Database, $this->System); 266 237 $Output .= $RealmView->ItemList(); 238 } else 239 if($_GET['Action'] == 'RealmShow') 240 { 241 $RealmView = new RealmView($this->Database, $this->System); 242 $Output .= $RealmView->Item(); 243 } else 244 if($_GET['Action'] == 'RealmAdd') 245 { 246 $RealmView = new RealmView($this->Database, $this->System); 247 $Output .= $RealmView->Add(); 248 } else 249 if($_GET['Action'] == 'RealmCreate') 250 { 251 $RealmView = new RealmView($this->Database, $this->System); 252 $Output .= $RealmView->Create(); 253 } else 254 if($_GET['Action'] == 'RealmEdit') 255 { 256 $RealmView = new RealmView($this->Database, $this->System); 257 $Output .= $RealmView->Edit(); 258 } else 259 if($_GET['Action'] == 'RealmSave') 260 { 261 $RealmView = new RealmView($this->Database, $this->System); 262 $Output .= $RealmView->Save(); 263 } else 264 if($_GET['Action'] == 'RealmEditDetailed') 265 { 266 $RealmView = new RealmView($this->Database, $this->System); 267 $Output .= $RealmView->EditDetailed(); 268 } else 269 if($_GET['Action'] == 'RealmSaveDetailed') 270 { 271 $RealmView = new RealmView($this->Database, $this->System); 272 $Output .= $RealmView->SaveDetailed(); 273 } else 274 if($_GET['Action'] == 'RealmStart') 275 { 276 $RealmView = new RealmView($this->Database, $this->System); 277 $Output .= $RealmView->Start(); 278 } else 279 if($_GET['Action'] == 'RealmStop') 280 { 281 $RealmView = new RealmView($this->Database, $this->System); 282 $Output .= $RealmView->Stop(); 267 283 } else 268 284 if($_GET['Action'] == 'Test') -
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 -
trunk/www/view/base.php
r56 r57 24 24 { 25 25 $Output .= '<div><a href="?Action=ServerList&Filter=User">Moje servery</a></div>'; 26 $Output .= '<div><a href="?Action=RealmList&Filter=User">Moje světy</a></div>';26 //$Output .= '<div><a href="?Action=RealmList&Filter=User">Moje světy</a></div>'; 27 27 //$Output .= '<div><a href="?Action=DebugList&Id='.$Server['Id'].'">Ladící záznamy</a></div>'; 28 28 //$Output .= '<div><a href="?Action=BackupList&Id='.$Server['Id'].'">Zálohy</a></div>'; -
trunk/www/view/emulator.php
r56 r57 92 92 $Form->LoadValuesFromForm(); 93 93 $Form->SaveValuesToDatabase(0); 94 $Output = $this->System Message('Přidání nového emulátoru', 'Emulátor přidán.');94 $Output = $this->System->SystemMessage('Přidání nového emulátoru', 'Emulátor přidán.'); 95 95 } else $Output = USER_BAD_ROLE; 96 96 return($Output); … … 103 103 $Emulator = new Emulator($this->Database, $_GET['Id']); 104 104 $Emulator->Download(); 105 $Output = $this->SystemMessage('Stažení emulátoru', 'Úloha zařazena do fronty'); 106 $Output .= $this->ShowTaskList(); 107 } else $Output = $this->SystemMessage('Stažení emulátoru', 'Nebylo zadáno Id'); 105 $Output = $this->System->SystemMessage('Stažení emulátoru', 'Úloha zařazena do fronty'); 106 $TaskView = new TaskView($this->Database, $this->System); 107 $Output .= $TaskView->ItemList(); 108 } else $Output = $this->System->SystemMessage('Stažení emulátoru', 'Nebylo zadáno Id'); 108 109 return($Output); 109 110 } … … 115 116 $Emulator = new Emulator($this->Database, $_GET['Id']); 116 117 $Emulator->Compile(); 117 $Output = $this->SystemMessage('Překlad emulátoru', 'Úloha zařazena do fronty'); 118 $Output .= $this->ShowTaskList(); 119 } else $Output = $this->SystemMessage('Překlad emulátoru', 'Nebylo zadáno Id'); 118 $Output = $this->System->SystemMessage('Překlad emulátoru', 'Úloha zařazena do fronty'); 119 $TaskView = new TaskView($this->Database, $this->System); 120 $Output .= $TaskView->ItemList(); 121 } else $Output = $this->System->SystemMessage('Překlad emulátoru', 'Nebylo zadáno Id'); 120 122 return($Output); 121 123 } -
trunk/www/view/realm.php
r56 r57 4 4 { 5 5 var $ItemFormClass = array( 6 'Title' => 'Nastavení ',7 'Table' => ' Svět',6 'Title' => 'Nastavení světa', 7 'Table' => 'Realm', 8 8 'SubmitText' => 'Uložit', 9 9 'Items' => array( … … 31 31 ), 32 32 ); 33 33 var $CreateFormClass = array( 34 'Title' => 'Nový svět', 35 'Table' => 'Realm', 36 'SubmitText' => 'Vytvořit', 37 'Items' => array( 38 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => 'Svět'), 39 'Description' => array('Type' => 'Text', 'Caption' => 'Popis', 'Default' => ''), 40 'Homepage' => array('Type' => 'Hyperlink', 'Caption' => 'Webové stránky', 'Default' => ''), 41 'Type' => array('Type' => 'ServerType', 'Caption' => 'Typ', 'Default' => 0), 42 'Database' => array('Type' => 'Database', 'Caption' => 'Databáze', 'Default' => 0), 43 'Motd' => array('Type' => 'String', 'Caption' => 'Zpráva dne', 'Default' => 'Vítejte na free WoW serveru'), 44 ), 45 ); 46 var $EditFormClass = array( 47 'Title' => 'Nastavení', 48 'Table' => 'Realm', 49 'SubmitText' => 'Uložit', 50 'Items' => array( 51 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => 'WoW server'), 52 'Description' => array('Type' => 'Text', 'Caption' => 'Popis', 'Default' => ''), 53 'Homepage' => array('Type' => 'Hyperlink', 'Caption' => 'Webové stránky', 'Default' => ''), 54 'Type' => array('Type' => 'ServerType', 'Caption' => 'Typ', 'Default' => 0), 55 'Database' => array('Type' => 'Database', 'Caption' => 'Databáze', 'Default' => 0), 56 'Motd' => array('Type' => 'String', 'Caption' => 'Zpráva dne', 'Default' => 'Vítejte na free WoW serveru'), 57 'RealmId' => array('Type' => 'Hidden', 'Caption' => 'Id', 'Default' => 0), 58 //'TimeCreation' => array('Type' => 'DateTime', 'Caption' => 'Datum založení', 'Default' => 'NOW()'), 59 ), 60 ); 61 var $SettingDetailedFormClass = array( 62 'Title' => 'Podrobné nastavení serveru', 63 'Table' => '', 64 'Items' => array( 65 'ServerId' => array('Type' => 'Hidden', 'Caption' => 'Id', 'Default' => 0), 66 'SkipCinematics' => array('Type' => 'SkipCinematics', 'Caption' => 'Zobrazovat úvodní video', 'Default' => ''), 67 'StartPlayerLevel' => array('Type' => 'Integer', 'Caption' => 'Počáteční úroveň hráčů', 'Default' => 1), 68 'MaxPlayerLevel' => array('Type' => 'Integer', 'Caption' => 'Max. úroveň hráčů', 'Default' => 80), 69 'StartHeroicPlayerLevel' => array('Type' => 'Integer', 'Caption' => 'Počáteční úroveň hrdinských postav', 'Default' => 55), 70 'StartPlayerMoney' => array('Type' => 'Integer', 'Caption' => 'Počáteční množství peněz', 'Default' => 0), 71 'StartHonorPoints' => array('Type' => 'Integer', 'Caption' => 'Počáteční počet bodů cti', 'Default' => 0), 72 'MaxHonorPoints' => array('Type' => 'Integer', 'Caption' => 'Max. počet bodů cti', 'Default' => 75000), 73 'StartArenaPoints' => array('Type' => 'Integer', 'Caption' => 'Počáteční počet bodů arén', 'Default' => 0), 74 'MaxArenaPoints' => array('Type' => 'Integer', 'Caption' => 'Max. počet bodů arén', 'Default' => 5000), 75 'MaxArenaPoints' => array('Type' => 'Integer', 'Caption' => 'Max. počet bodů arén', 'Default' => 5000), 76 'InstantLogout' => array('Type' => 'SecurityLevel', 'Caption' => 'Povolit okamžitého odhlášení', 'Default' => 1), 77 'DisableWaterBreath' => array('Type' => 'SecurityLevel', 'Caption' => 'Zakázat dýchání pod vodou', 'Default' => 1), 78 'AllFlightPaths' => array('Type' => 'Boolean', 'Caption' => 'Povoleny všechny létací cesty', 'Default' => 0), 79 'AlwaysMaxSkillForLevel' => array('Type' => 'Boolean', 'Caption' => 'Vždy max. dovednost na úroveň', 'Default' => 0), 80 'ActivateWeather' => array('Type' => 'Boolean', 'Caption' => 'Aktivní počasí', 'Default' => 1), 81 'CastUnstuck' => array('Type' => 'Boolean', 'Caption' => 'Povolit odblokovací kouzlo pomocí .start', 'Default' => 1), 82 'MinPetitionSigns' => array('Type' => 'Integer', 'Caption' => 'Min. počet podpisů k zápisu spolku', 'Default' => 9), 83 'MaxGroupXPDistance' => array('Type' => 'Integer', 'Caption' => 'Max. rozdíl XP ve skupině', 'Default' => 74), 84 'MailDeliveryDelay' => array('Type' => 'Integer', 'Caption' => 'Zpoždění doručení pošty', 'Default' => 3600), 85 'Event.Announce' => array('Type' => 'Boolean', 'Caption' => 'Ohlašování událostí', 'Default' => 0), 86 'AllowTwoSide.Accounts' => array('Type' => 'Boolean', 'Caption' => 'Povolit účty s postavami obou stran', 'Default' => 0), 87 'AllowTwoSide.Interaction.Chat' => array('Type' => 'Boolean', 'Caption' => 'Povolit komunikaci mezi stranami', 'Default' => 0), 88 'AllowTwoSide.Interaction.Channel' => array('Type' => 'Boolean', 'Caption' => 'Povolit kanály mezi stranami', 'Default' => 0), 89 'AllowTwoSide.WhoList' => array('Type' => 'Boolean', 'Caption' => 'Povolit obě strany v seznamu přítomných', 'Default' => 0), 90 ), 91 ); 34 92 35 93 function ItemList() 36 94 { 37 95 global $Config; 96 97 if(array_key_exists('Id', $_GET)) $ServerId = $_GET['Id']; 38 98 39 99 $Realm = new Realm($this->Database, 0); … … 42 102 $Table = new Table($this->ItemListFormClass); 43 103 //$Table->OnRow = array($this, 'ShowRealmListOnRow'); 104 $Table->Definition['Table'] = substr($Table->Definition['Table'], 0, -1).' WHERE `Realm`.`Server`='.$ServerId.')'; 44 105 $Table->Definition['Items']['Id'] = array('Type' => 'Hidden', 'Caption' => '', 'Default' => ''); 45 106 $Table->LoadValuesFromDatabase($this->Database); … … 63 124 return($Output); 64 125 } 126 127 function Item() 128 { 129 global $Config; 130 131 $Id = $_GET['Id']; 132 $Realm = new Realm($this->Database, $Id); 133 //if(isset($Server->Server)) 134 //{ 135 $Output = '<h4>Podrobnosti světa</h4>'; 136 $Form = new Form($this->ItemFormClass); 137 $Form->LoadValuesFromDatabase($Id); 138 $Form->Definition['Items']['Uptime'] = array('Type' => 'String', 'Caption' => 'Doba běhu', 'Default' => ''); 139 $Form->Definition['Items']['UsedMemory'] = array('Type' => 'String', 'Caption' => 'Použitá paměť', 'Default' => ''); 140 $RealmStatus = $Realm->GetState(); 141 unset($Form->Definition['Items']['NetworkPortWorldd']); 142 //$Form->Values['Uptime'] = $this->System->AddPrefixMultipliers($RealmStatus['Uptime'], '', 4, 'Time'); 143 //$Form->Values['UsedMemory'] = $this->System->AddPrefixMultipliers($RealmStatus['UsedMemory'] * 1024, 'B', 4, 'Binary'); 144 $Output .= $Form->ShowTable(); 145 $Server = new Server($this->Database, $Realm->Data['Server']); 146 $Output .= '<div style="text-align: center">'; 147 if((($this->System->Modules['User']->User['Role'] >= USER_ROLE_USER) and ($this->System->Modules['User']->User['Id'] == $Server->Server['User'])) or ($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR)) 148 { 149 $Output .= '<br /><a href="http://'.$this->System->Config['Web']['Host'].'/mysql/">Správa databáze</a> '; 150 if(array_key_exists('Id', $Realm->Data['Database']) and ($Realm->Data['Lock'] == 0)) 151 { 152 if($ServerStatus['WorlddPortState'] == true) $Output .= ' <a href="?Action=RealmStop&Id='.$Realm->Id.'">Zastavit</a> <a href="?Action=RealmRestart&Id='.$Realm->Id.'">Restartovat</a>'; 153 else $Output .= ' <a href="?Action=RealmStart&Id='.$Realm->Id.'">Spustit</a>'; 154 } 155 if($Realm->Data['Lock'] == 0) 156 { 157 $Output .= ' <a href="?Action=RealmEdit&Id='.$Realm->Id.'">Upravit základní nastavení</a>'; 158 $Output .= ' <a href="?Action=RealmEditDetailed&Id='.$Realm->Id.'">Upravit podrobné nastavení</a>'; 159 } 160 //$Output .= ' <a href="?Action=ServerDatabaseImport&Id='.$Server->Id.'">Načtení čisté databáze</a>'; 161 } 162 $Output .= '</div>'; 163 return($Output); 164 } 165 166 function Add() 167 { 168 global $Config; 169 170 if(array_key_exists('Id', $_GET)) 171 { 172 $ServerId = $_GET['Id']; 173 $Output = ''; 174 if($this->System->Modules['User']->User['Role'] >= USER_ROLE_USER) 175 { 176 $DbResult = $this->Database->query('SELECT COUNT(*) FROM Realm'); 177 $DbRow = $DbResult->fetch_row(); 178 $RealmCount = $DbRow[0]; 179 if($RealmCount < $Config['MaxRealmCount']) 180 { 181 if($this->System->Modules['User']->RealmCount() >= $Config['MaxServerCountPerUser']) $Output .= $this->System->SystemMessage('Nový svět', 'Na jeden účet lze vytvořit maximálně '.$Config['MaxServerCountPerUser'].' světů'); 182 else 183 { 184 $Form = new Form($this->CreateFormClass); 185 $Form->LoadValuesFromForm(); 186 $Form->OnSubmit = '?Action=RealmCreate&Id='.$ServerId; 187 $Output .= 'Tento formulář vám umožní si vytvořit nový svět. Pečlivě vyplňte požadované údaje.'; 188 $Output .= $Form->ShowEditForm(); 189 } 190 } else $Output .= $this->System->SystemMessage('Nový svět', 'Nelze vytvářet další světyservery'); 191 } else $Output .= USER_BAD_ROLE; 192 } else $Output = $this->System->SystemMessage('Vytvoření světa', 'Nezadáno Id serveru'); 193 return($Output); 194 } 195 196 function Create() 197 { 198 global $Config; 199 200 if(array_key_exists('Id', $_GET)) 201 { 202 $ServerId = $_GET['Id']; 203 if($this->System->Modules['User']->User['Role'] >= USER_ROLE_USER) 204 { 205 if($this->System->Modules['User']->RealmCount() >= $Config['MaxServerCountPerUser']) $Output = $this->System->SystemMessage('Nový svět', 'Na jeden účet lze vytvořit maximálně '.$Config['MaxServerCountPerUser'].' světů'); 206 else 207 { 208 // Allocate unused network port for realm 209 $DbResult = $this->Database->query('SELECT MAX(NetworkPortWorldd) FROM Realm'); 210 $DbRow = $DbResult->fetch_row(); 211 $NewPortWorldd = $DbRow[0] + 1; 212 if($NewPortWorldd < $Config['BaseNetworkPortWorldd']) $NewPortWorldd = $Config['BaseNetworkPortWorldd']; 213 214 $Form = new Form($this->CreateFormClass, array()); 215 $Form->LoadValuesFromForm(); 216 $this->Database->insert('Realm', array('Name' => $Form->Values['Name'], 'Description' => $Form->Values['Description'], 'Server' => $ServerId, 'Motd' => $Form->Values['Motd'], 'Homepage' => $Form->Values['Homepage'], 'Type' => $Form->Values['Type'], 'Database' => $Form->Values['Database'], 'NetworkPortWorldd' => $NewPortWorldd, 'Lock' => 1, 'TimeCreate' => 'NOW()')); 217 $LastInsertId = $this->Database->insert_id; 218 $Realm = new Realm($this->Database, $LastInsertId); 219 $Realm->CreateDatabase(); 220 $Output = $this->System->SystemMessage('Vytvoření světu', $Realm->ImportDatabase(true)); 221 $TaskView = new TaskView($this->Database, $this->System); 222 $Output .= $TaskView->ItemList(); 223 //$UserOptions->LoadValuesFromDatabase($this->System->Modules['User']->User['Id']); 224 //$Form->OnSubmit = '?Action=ServerCreate'; 225 //$Output .= $Form->ShowEditForm(); 226 } 227 } else $Output = USER_BAD_ROLE; 228 } else $Output = $this->System->SystemMessage('Vytvoření světa', 'Nezadáno Id serveru'); 229 return($Output); 230 } 231 232 function Save() 233 { 234 $Output = ''; 235 $Realm = new Realm($this->Database, $_POST['RealmId']); 236 if(($this->System->Modules['User']->User['Id'] == $Realm->GetUser()) or ($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR)) 237 { 238 $Form = new Form($this->EditFormClass, array()); 239 $Form->LoadValuesFromForm(); 240 $RealmId = $_POST['RealmId']; 241 unset($Form->Values['RealmId']); 242 $Output .= $this->System->SystemMessage('Upravit svět', 'Nastavení světa uloženo.'); 243 $Form->SaveValuesToDatabase($_POST['RealmId']); 244 $Form->OnSubmit = '?Action=RealmSave'; 245 246 $Realm = new Realm($this->Database, $_POST['RealmId']); 247 $Realm->SaveConfiguration(); 248 $Form->Values['RealmId'] = $RealmId; 249 $Output .= $Form->ShowEditForm(); 250 } else $Output = $this->System->SystemMessage('Nastavení serveru', 'Nemáte oprávnění'); 251 return($Output); 252 } 253 254 function Edit() 255 { 256 $Output = ''; 257 $Realm = new Realm($this->Database, $_GET['Id']); 258 if(($this->System->Modules['User']->User['Id'] == $Realm->GetUser()) or ($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR)) 259 { 260 $Form = new Form($this->EditFormClass); 261 $Form->LoadValuesFromDatabase($_GET['Id']); 262 $Form->Values['RealmId'] = $_GET['Id']; 263 $Form->OnSubmit = '?Action=RealmSave'; 264 $Output .= $Form->ShowEditForm(); 265 } else $Output = $this->System->SystemMessage('Nastavení světa', 'Nemáte oprávnění'); 266 return($Output); 267 } 268 269 function EditDetailed() 270 { 271 $Output = ''; 272 $Realm = new Realm($this->Database, $_GET['Id']); 273 if(($this->System->Modules['User']->User['Id'] == $Realm->GetUser()) or ($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR)) 274 { 275 $Form = new Form($this->SettingDetailedFormClass); 276 $EmulatorConfig = new MangosConfigurationFile($this->Database); 277 $EmulatorConfig->Load('../realm/'.$Realm->Id.'/etc/mangosd.conf'); 278 $Form->Values = $EmulatorConfig->ParameterList; 279 $Form->Values['RealmId'] = $_GET['Id']; 280 $Form->OnSubmit = '?Action=RealmSaveDetailed'; 281 $Output .= $Form->ShowEditForm(); 282 } else $this->System->SystemMessage('Nastavení světa', 'Nemáte oprávnění'); 283 return($Output); 284 } 285 286 function SaveDetailed() 287 { 288 $Output = ''; 289 $Realm = new Realm($this->Database, $_POST['ServerId']); 290 if(($this->System->Modules['User']->User['Id'] == $Realm->GetUser()) or ($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR)) 291 { 292 $Form = new Form($this->$SettingDetailedFormClass, array()); 293 $Form->LoadValuesFromForm(); 294 $EmulatorConfig = new MangosConfigurationFile($this->Database); 295 $EmulatorConfig->Load('../realm/'.$Realm->Id.'/etc/mangosd.conf'); 296 foreach($Form->Values as $Index => $Item) 297 $EmulatorConfig->ParameterList[$Index] = $Item; 298 $EmulatorConfig->Save('../server/'.$Realm->Id.'/etc/mangosd.conf'); 299 $RealmId = $_POST['RealmId']; 300 unset($Form->Values['RealmId']); 301 $Output .= $this->System->SystemMessage('Upravit svět', 'Nastavení světa uloženo.'); 302 //$Form->SaveValuesToDatabase($_POST['ServerId']); 303 $Form->OnSubmit = '?Action=RealmSaveDetailed'; 304 305 $Realm = new Realm($this->Database, $_POST['RealmId']); 306 $Realm->SaveConfiguration(); 307 $Form->Values['RealmId'] = $RealmId; 308 $Output .= $Form->ShowEditForm(); 309 } else $this->System->SystemMessage('Nastavení světa', 'Nemáte oprávnění'); 310 return($Output); 311 } 312 313 function Start() 314 { 315 $Output = ''; 316 if($this->System->Modules['User']->User['Role'] >= USER_ROLE_USER) 317 { 318 $Realm = new Realm($this->Database, $_GET['Id']); 319 if(($this->System->Modules['User']->User['Id'] == $Realm->GetUser()) or ($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR)) 320 { 321 $Output .= $this->System->SystemMessage('Spuštění serveru', $Realm->Start()); 322 $TaskView = new TaskView($this->Database, $this->System); 323 $Output .= $TaskView->ItemList();; 324 } else $this->System->SystemMessage('Spuštění serveru', 'Nemáte oprávnění'); 325 } else $Output .= USER_BAD_ROLE; 326 return($Output); 327 } 328 329 function Stop() 330 { 331 $Output = ''; 332 if($this->System->Modules['User']->User['Role'] >= USER_ROLE_USER) 333 { 334 $Realm = new Realm($this->Database, $_GET['Id']); 335 if(($this->System->Modules['User']->User['Id'] == $Realm->GetUser()) or ($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR)) 336 { 337 $Output .= $this->System->SystemMessage('Zastavení serveru', $Realm->Stop()); 338 $TaskView = new TaskView($this->Database, $this->System); 339 $Output .= $TaskView->ItemList();; 340 } else $this->System->SystemMessage('Zastavení serveru', 'Nemáte oprávnění'); 341 } else $Output .= USER_BAD_ROLE; 342 return($Output); 343 } 65 344 } 66 345 -
trunk/www/view/server.php
r56 r57 3 3 class ServerView extends Module 4 4 { 5 var $ ViewFormClass = array(5 var $ItemFormClass = array( 6 6 'Title' => 'Nastavení', 7 7 'Table' => 'Server', … … 39 39 'Description' => array('Type' => 'Text', 'Caption' => 'Popis', 'Default' => ''), 40 40 'Homepage' => array('Type' => 'Hyperlink', 'Caption' => 'Webové stránky', 'Default' => ''), 41 'Type' => array('Type' => 'ServerType', 'Caption' => 'Typ', 'Default' => 0),41 //'Type' => array('Type' => 'ServerType', 'Caption' => 'Typ', 'Default' => 0), 42 42 'Database' => array('Type' => 'Database', 'Caption' => 'Databáze', 'Default' => 0), 43 'Motd' => array('Type' => 'String', 'Caption' => 'Zpráva dne', 'Default' => 'Vítejte na free WoW serveru'),43 //'Motd' => array('Type' => 'String', 'Caption' => 'Zpráva dne', 'Default' => 'Vítejte na free WoW serveru'), 44 44 ), 45 45 ); … … 52 52 'Description' => array('Type' => 'Text', 'Caption' => 'Popis', 'Default' => ''), 53 53 'Homepage' => array('Type' => 'Hyperlink', 'Caption' => 'Webové stránky', 'Default' => ''), 54 'Type' => array('Type' => 'ServerType', 'Caption' => 'Typ', 'Default' => 0),55 //'Database' => array('Type' => 'Database', 'Caption' => 'Databáze', 'Default' => 0),56 'Motd' => array('Type' => 'String', 'Caption' => 'Zpráva dne', 'Default' => 'Vítejte na free WoW serveru'),54 //'Type' => array('Type' => 'ServerType', 'Caption' => 'Typ', 'Default' => 0), 55 'Database' => array('Type' => 'Database', 'Caption' => 'Databáze', 'Default' => 0), 56 //'Motd' => array('Type' => 'String', 'Caption' => 'Zpráva dne', 'Default' => 'Vítejte na free WoW serveru'), 57 57 'ServerId' => array('Type' => 'Hidden', 'Caption' => 'Id', 'Default' => 0), 58 58 //'TimeCreation' => array('Type' => 'DateTime', 'Caption' => 'Datum založení', 'Default' => 'NOW()'), … … 71 71 ), 72 72 ); 73 var $SettingDetailedFormClass = array(74 'Title' => 'Podrobné nastavení serveru',75 'Table' => '',76 'Items' => array(77 'ServerId' => array('Type' => 'Hidden', 'Caption' => 'Id', 'Default' => 0),78 'SkipCinematics' => array('Type' => 'SkipCinematics', 'Caption' => 'Zobrazovat úvodní video', 'Default' => ''),79 'StartPlayerLevel' => array('Type' => 'Integer', 'Caption' => 'Počáteční úroveň hráčů', 'Default' => 1),80 'MaxPlayerLevel' => array('Type' => 'Integer', 'Caption' => 'Max. úroveň hráčů', 'Default' => 80),81 'StartHeroicPlayerLevel' => array('Type' => 'Integer', 'Caption' => 'Počáteční úroveň hrdinských postav', 'Default' => 55),82 'StartPlayerMoney' => array('Type' => 'Integer', 'Caption' => 'Počáteční množství peněz', 'Default' => 0),83 'StartHonorPoints' => array('Type' => 'Integer', 'Caption' => 'Počáteční počet bodů cti', 'Default' => 0),84 'MaxHonorPoints' => array('Type' => 'Integer', 'Caption' => 'Max. počet bodů cti', 'Default' => 75000),85 'StartArenaPoints' => array('Type' => 'Integer', 'Caption' => 'Počáteční počet bodů arén', 'Default' => 0),86 'MaxArenaPoints' => array('Type' => 'Integer', 'Caption' => 'Max. počet bodů arén', 'Default' => 5000),87 'MaxArenaPoints' => array('Type' => 'Integer', 'Caption' => 'Max. počet bodů arén', 'Default' => 5000),88 'InstantLogout' => array('Type' => 'SecurityLevel', 'Caption' => 'Povolit okamžitého odhlášení', 'Default' => 1),89 'DisableWaterBreath' => array('Type' => 'SecurityLevel', 'Caption' => 'Zakázat dýchání pod vodou', 'Default' => 1),90 'AllFlightPaths' => array('Type' => 'Boolean', 'Caption' => 'Povoleny všechny létací cesty', 'Default' => 0),91 'AlwaysMaxSkillForLevel' => array('Type' => 'Boolean', 'Caption' => 'Vždy max. dovednost na úroveň', 'Default' => 0),92 'ActivateWeather' => array('Type' => 'Boolean', 'Caption' => 'Aktivní počasí', 'Default' => 1),93 'CastUnstuck' => array('Type' => 'Boolean', 'Caption' => 'Povolit odblokovací kouzlo pomocí .start', 'Default' => 1),94 'MinPetitionSigns' => array('Type' => 'Integer', 'Caption' => 'Min. počet podpisů k zápisu spolku', 'Default' => 9),95 'MaxGroupXPDistance' => array('Type' => 'Integer', 'Caption' => 'Max. rozdíl XP ve skupině', 'Default' => 74),96 'MailDeliveryDelay' => array('Type' => 'Integer', 'Caption' => 'Zpoždění doručení pošty', 'Default' => 3600),97 'Event.Announce' => array('Type' => 'Boolean', 'Caption' => 'Ohlašování událostí', 'Default' => 0),98 'AllowTwoSide.Accounts' => array('Type' => 'Boolean', 'Caption' => 'Povolit účty s postavami obou stran', 'Default' => 0),99 'AllowTwoSide.Interaction.Chat' => array('Type' => 'Boolean', 'Caption' => 'Povolit komunikaci mezi stranami', 'Default' => 0),100 'AllowTwoSide.Interaction.Channel' => array('Type' => 'Boolean', 'Caption' => 'Povolit kanály mezi stranami', 'Default' => 0),101 'AllowTwoSide.WhoList' => array('Type' => 'Boolean', 'Caption' => 'Povolit obě strany v seznamu přítomných', 'Default' => 0),102 ),103 );104 73 105 74 function ShowListOnRow($Row) … … 119 88 $Output = '<h4>Seznam serverů</h4>'; 120 89 $Table = new Table($this->ItemListFormClass); 90 if(array_key_exists('Filter', $_GET)) 91 { 92 if($_GET['Filter'] == 'User') 93 $Table->Definition['Table'] = substr($Table->Definition['Table'], 0, -1).' WHERE User='.$this->System->Modules['User']->User['Id'].')'; 94 } 121 95 $Table->OnRow = array($this, 'ShowListOnRow'); 122 96 $Table->Definition['Items']['Id'] = array('Type' => 'Hidden', 'Caption' => '', 'Default' => ''); … … 136 110 $DbResult = $this->Database->query('SELECT COUNT(*) FROM Server WHERE User='.$this->System->Modules['User']->User['Id']); 137 111 $DbRow = $DbResult->fetch_row(); 138 if(($ServerCount < $Config['MaxServerCount']) and ($DbRow[0] == 0))112 if(($ServerCount < $Config['MaxServerCount']) and ($DbRow[0] < $Config['MaxServerCountPerUser'])) 139 113 $Output .= '<br /><div style="text-align: center;"><a href="?Action=ServerAdd">Vytvořit nový server</a></dev>'; 140 114 } … … 151 125 { 152 126 $Output = '<h4>Podrobnosti serveru</h4>'; 153 $Form = new Form($this-> ViewFormClass);127 $Form = new Form($this->ItemFormClass); 154 128 $Form->LoadValuesFromDatabase($Id); 155 129 $Form->Definition['Items']['Realmlist'] = array('Type' => 'String', 'Caption' => 'Adresa k připojení', 'Default' => ''); … … 176 150 { 177 151 $Output .= ' <a href="?Action=ServerEdit&Id='.$Server->Id.'">Upravit základní nastavení</a>'; 178 $Output .= ' <a href="?Action=ServerEditDetailed&Id='.$Server->Id.'">Upravit podrobné nastavení</a>';179 152 } 180 153 //$Output .= ' <a href="?Action=ServerDatabaseImport&Id='.$Server->Id.'">Načtení čisté databáze</a>'; 154 $Output .= ' <a href="?Action=RealmAdd&Id='.$Server->Id.'">Vytvořit nový svět</a>'; 181 155 } 182 156 $Output .= ' <a href="?Action=GameAccountRegister&Id='.$Server->Id.'">Vytvoření herního účtu</a>'; … … 204 178 $DbResult = $this->Database->query('SELECT COUNT(*) FROM Server WHERE User='.$this->System->Modules['User']->User['Id']); 205 179 $DbRow = $DbResult->fetch_row(); 206 if($DbRow[0] > 0) $Output .= $this->System->SystemMessage('Nový server', 'Lze vytvořit pouze jeden server pro každý uživatelský účet.');180 if($DbRow[0] >= $Config['MaxServerCountPerUser']) $Output .= $this->System->SystemMessage('Nový server', 'Na jeden účet lze vytvořit maximálně '.$Config['MaxServerCountPerUser'].' serverů'); 207 181 else 208 182 { … … 220 194 function Create() 221 195 { 196 global $Config; 197 222 198 $Output = ''; 223 199 if($this->System->Modules['User']->User['Role'] >= USER_ROLE_USER) … … 225 201 $DbResult = $this->Database->query('SELECT COUNT(*) FROM Server WHERE User='.$this->System->Modules['User']->User['Id']); 226 202 $DbRow = $DbResult->fetch_row(); 227 if($DbRow[0] > 0) $Output .= $this->System->SystemMessage('Nový server', 'Lze vytvořit pouze jeden server pro každý uživatelský účet.');203 if($DbRow[0] >= $Config['MaxServerCountPerUser']) $Output .= $this->System->SystemMessage('Nový server', 'Na jeden účet lze vytvořit maximálně '.$Config['MaxServerCountPerUser'].' serverů'); 228 204 else 229 205 { 230 $DbResult = $this->Database->query('SELECT MAX(NetworkPortRealmd) , MAX(NetworkPortWorldd)FROM Server');206 $DbResult = $this->Database->query('SELECT MAX(NetworkPortRealmd) FROM Server'); 231 207 $DbRow = $DbResult->fetch_row(); 232 208 $NewPortRealmd = $DbRow[0] + 1; 233 209 if($NewPortRealmd < $Config['BaseNetworkPortRealmd']) $NewPortRealmd = $Config['BaseNetworkPortRealmd']; 234 $NewPortWorldd = $DbRow[1] + 1;235 if($NewPortWorldd < $Config['BaseNetworkPortWorldd']) $NewPortWorldd = $Config['BaseNetworkPortWorldd'];236 210 237 211 $Form = new Form($this->CreateFormClass, array()); 238 212 $Form->LoadValuesFromForm(); 239 $this->Database->insert('Server', array('Name' => $Form->Values['Name'], 'Description' => $Form->Values['Description'], 'User' => $this->System->Modules['User']->User['Id'], ' Motd' => $Form->Values['Motd'], 'Homepage' => $Form->Values['Homepage'], 'Type' => $Form->Values['Type'], 'Database' => $Form->Values['Database'], 'NetworkPortWorldd' => $NewPortWorldd, 'NetworkPortRealmd' => $NewPortRealmd, 'Lock' => 1, 'TimeCreate' => 'NOW()'));213 $this->Database->insert('Server', array('Name' => $Form->Values['Name'], 'Description' => $Form->Values['Description'], 'User' => $this->System->Modules['User']->User['Id'], 'Homepage' => $Form->Values['Homepage'], 'Database' => $Form->Values['Database'], 'NetworkPortRealmd' => $NewPortRealmd, 'Lock' => 1, 'TimeCreate' => 'NOW()')); 240 214 $LastInsertId = $this->Database->insert_id; 241 215 $Server = new Server($this->Database, $LastInsertId); 242 216 $Server->CreateDatabase(); 243 217 $Output .= $this->System->SystemMessage('Vytvoření serveru', $Server->ImportDatabase(true)); 244 $Output .= $this->ShowTaskList(); 218 $TaskView = new TaskView($this->Database, $this->System); 219 $Output .= $TaskView->ItemList(); 245 220 //$UserOptions->LoadValuesFromDatabase($this->System->Modules['User']->User['Id']); 246 221 //$Form->OnSubmit = '?Action=ServerCreate'; … … 284 259 $Form->OnSubmit = '?Action=ServerSave'; 285 260 $Output .= $Form->ShowEditForm(); 286 } else $Output = $this->SystemMessage('Nastavení serveru', 'Nemáte oprávnění'); 287 return($Output); 288 } 289 290 function EditDetailed() 291 { 292 $Output = ''; 293 $Server = new Server($this->Database, $_GET['Id']); 294 if(($this->System->Modules['User']->User['Id'] == $Server->Server['User']) or ($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR)) 295 { 296 $Form = new Form($this->$SettingDetailedFormClass); 297 $EmulatorConfig = new MangosConfigurationFile($this->Database); 298 $EmulatorConfig->Load('../server/'.$Server->Id.'/etc/mangosd.conf'); 299 $Form->Values = $EmulatorConfig->ParameterList; 300 $Form->Values['ServerId'] = $_GET['Id']; 301 $Form->OnSubmit = '?Action=ServerSaveDetailed'; 302 $Output .= $Form->ShowEditForm(); 303 } else $this->System->SystemMessage('Nastavení serveru', 'Nemáte oprávnění'); 304 return($Output); 305 } 306 307 function SaveDetailed() 308 { 309 $Output = ''; 310 $Server = new Server($this->Database, $_POST['ServerId']); 311 if(($this->System->Modules['User']->User['Id'] == $Server->Server['User']) or ($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR)) 312 { 313 $Form = new Form($this->$SettingDetailedFormClass, array()); 314 $Form->LoadValuesFromForm(); 315 $EmulatorConfig = new MangosConfigurationFile($this->Database); 316 $EmulatorConfig->Load('../server/'.$Server->Id.'/etc/mangosd.conf'); 317 foreach($Form->Values as $Index => $Item) 318 $EmulatorConfig->ParameterList[$Index] = $Item; 319 $EmulatorConfig->Save('../server/'.$Server->Id.'/etc/mangosd.conf'); 320 $ServerId = $_POST['ServerId']; 321 unset($Form->Values['ServerId']); 322 $Output .= $this->System->SystemMessage('Upravit server', 'Nastavení serveru uloženo.'); 323 //$Form->SaveValuesToDatabase($_POST['ServerId']); 324 $Form->OnSubmit = '?Action=ServerSaveDetailed'; 325 326 $Server = new Server($this->Database, $_POST['ServerId']); 327 $Server->SaveConfiguration(); 328 $Form->Values['ServerId'] = $ServerId; 329 $Output .= $Form->ShowEditForm(); 330 } else $this->System->SystemMessage('Nastavení serveru', 'Nemáte oprávnění'); 331 return($Output); 332 } 261 } else $Output = $this->System->SystemMessage('Nastavení serveru', 'Nemáte oprávnění'); 262 return($Output); 263 } 333 264 334 265 function Start() … … 341 272 { 342 273 $Output .= $this->System->SystemMessage('Spuštění serveru', $Server->Start()); 343 $Output .= $this->ShowTaskList(); 274 $TaskView = new TaskView($this->Database, $this->System); 275 $Output .= $TaskView->ItemList();; 344 276 } else $this->System->SystemMessage('Spuštění serveru', 'Nemáte oprávnění'); 345 277 } else $Output .= USER_BAD_ROLE; … … 356 288 { 357 289 $Output .= $this->System->SystemMessage('Zastavení serveru', $Server->Stop()); 358 $Output .= $this->ShowTaskList(); 290 $TaskView = new TaskView($this->Database, $this->System); 291 $Output .= $TaskView->ItemList();; 359 292 } else $this->System->SystemMessage('Zastavení serveru', 'Nemáte oprávnění'); 360 293 } else $Output .= USER_BAD_ROLE;
Note:
See TracChangeset
for help on using the changeset viewer.