Changeset 5


Ignore:
Timestamp:
Jun 9, 2009, 10:39:27 AM (15 years ago)
Author:
george
Message:
  • Přidáno: Třída Emulator pro zastřešení funkcí kolem emulátorů.
  • Přidáno: Metody pro spuštění a zastavení emulátoru.
Location:
trunk/www
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/index.php

    r4 r5  
    2323  function ShowServer($Id)
    2424  {
    25     $DbResult = $this->Database->query('SELECT * FROM Server WHERE Id='.$Id);
    26     $Server = $DbResult->fetch_assoc();
     25    $Server = new Server($this->Database, $Id);
    2726    $Output = '<h4>Podrobnosti serveru</h4>';
    2827    $Output .= '<table class="WideTable"><tr><th>Položka</th><th>Hodnota</th></tr>';
    29     $Output .= '<tr><td>Jméno</td><td>'.$Server['Name'].'</td></tr>'.
    30       '<tr><td>Síťový port realmd</td><td>'.$Server['NetworkPortRealmd'].'</td></tr>'.
    31       '<tr><td>Síťový port mangosd</td><td>'.$Server['NetworkPortMangosd'].'</td></tr>'.
    32       '<tr><td>Emulátor</td><td>'.$Server['NetworkPortMangosd'].'</td></tr>'.
    33       '<tr><td>Databáze</td><td>'.$this->System->Config['Web']['Host'].':'.$Server['NetworkPortRealmd'].'</td></tr>';
     28    $Output .= '<tr><td>Jméno</td><td>'.$Server->Server['Name'].'</td></tr>'.
     29      '<tr><td>Zpráva dne</td><td>'.$Server->Server['Motd'].'</td></tr>'.
     30      '<tr><td>Síťový port realmd</td><td>'.($Server->RealmdBaseNetworkPort + $Server->Id).'</td></tr>'.
     31      '<tr><td>Síťový port mangosd</td><td>'.($Server->WorlddBaseNetworkPort + $Server->Id).'</td></tr>'.
     32      '<tr><td>Emulátor</td><td>'.$Server->Server['Database']['Emulator']['Name'].'</td></tr>'.
     33      '<tr><td>Databáze</td><td>'.$Server->Server['Database']['Name'].'</td></tr>';
    3434    $Output .= '</table>';
    35     $Output .= '<br /><a hreg="'.$this->System->Config['Web']['Host'].'/mysql/">Správa databáze</a><br />';
     35    $Output .= '<br /><a href="'.$this->System->Config['Web']['Host'].'/mysql/">Správa databáze</a> ';
     36    $ServerStatus = $Server->GetState();
     37    if($ServerStatus['RealmdPortState'] == true) $Output .= ' <a href="?Action=ServerStop">Zastavit server</a>  <a href="?Action=ServerRestart">RestartovatServer</a>';
     38      else $Output .= ' <a href="?Action=ServerStart">Spustit server</a>';
     39   
    3640    return($Output);
    3741  }
     
    167171        $Output .= $UserOptions->ShowEditForm();
    168172      } else
    169       if($_GET['Action'] == 'NewServer')
     173      if($_GET['Action'] == 'ServerAdd')
    170174      {
    171175        $Form = new Form('NewServer');
     
    183187        $Output .= $UserOptions->ShowEditForm();
    184188      } else
    185       if($_GET['Action'] == 'EditServer')
     189      if($_GET['Action'] == 'ServerShow')
     190      {
     191        $DbResult = $this->Database->query('SELECT Id FROM Server WHERE User='.$this->System->Modules['User']->User['Id']);
     192        $Server = $DbResult->fetch_assoc();
     193        $Output .= $this->ShowServer($Server['Id']);
     194      } else
     195      if($_GET['Action'] == 'ServerEdit')
    186196      {
    187197        $Form = new Form('EditServer');
     
    200210        $DbResult = $this->Database->query('SELECT Id FROM Server WHERE User='.$this->System->Modules['User']->User['Id']);
    201211        $Server = $DbResult->fetch_assoc();
    202         $ServerId = $Server['Id'];
    203         $Server = new Server($this->Database, $ServerId);
    204 
    205         // Setup mangosd.conf
    206         $Config = new MangosConfigurationFile($this->Database);
    207         $Config->Load('../emu/mangos/'.$Server->Server['Database']['Emulator']['Revision'].'/etc/mangosd.conf');
    208         $Config->ParameterList['LoginDatabaseInfo'] = 'localhost:3306:server'.$ServerId.':server'.$ServerId.':server'.$ServerId.'_realmd';
    209         $Config->ParameterList['WorldDatabaseInfo'] = 'localhost:3306:server'.$ServerId.':server'.$ServerId.':server'.$ServerId.'_mangos';
    210         $Config->ParameterList['CharacterDatabaseInfo'] = 'localhost:3306:server'.$ServerId.':server'.$ServerId.':server'.$ServerId.'_characters';
    211         $Config->ParameterList['WorldServerPort'] = 8085 + $ServerId;
    212         $Config->ParameterList['Motd'] = $Server->Server['Motd'];
    213         $Config->Save('../server/'.$ServerId.'/etc/mangosd.conf');
    214         // Setup realmd.conf
    215         $Config = new MangosConfigurationFile($this->Database);
    216         $Config->Load('../emu/mangos/'.$Server->Server['Database']['Emulator']['Revision'].'/etc/realmd.conf');
    217         $Config->ParameterList['LoginDatabaseInfo'] = 'localhost:3306:server'.$ServerId.':server'.$ServerId.':server'.$ServerId.'_realmd';
    218         $Config->ParameterList['RealmServerPort'] = 3724 + $ServerId;
    219         $Config->Save('../server/'.$ServerId.'/etc/realmd.conf');
    220         // Setup realmd.conf
    221         $Config = new MangosConfigurationFile($this->Database);
    222         $Config->Load('../emu/mangos/'.$Server->Server['Database']['Emulator']['Revision'].'/etc/scriptdev2.conf');
    223         $Config->ParameterList['ScriptDev2DatabaseInfo'] = 'localhost:3306:server'.$ServerId.':server'.$ServerId.':server'.$ServerId.'_scriptdev2';
    224         $Config->Save('../server/'.$ServerId.'/etc/scriptdev2.conf');
    225 
    226         $Output .= $UserOptions->ShowEditForm();
     212        $Server = new Server($this->Database, $Server['Id']);
     213        $Server->SetupConfigurationFiles();
     214
     215        $Output .= $UserOptions->ShowEditForm();
     216      } else
     217      if($_GET['Action'] == 'ServerStart')
     218      {
     219        $DbResult = $this->Database->query('SELECT Id FROM Server WHERE User='.$this->System->Modules['User']->User['Id']);
     220        $Server = $DbResult->fetch_assoc();
     221        $Server = new Server($this->Database, $Server['Id']);
     222        $Output .= $this->SystemMessage('Spuštění serveru', $Server->Start());
     223      } else
     224      if($_GET['Action'] == 'ServerStop')
     225      {
     226        $DbResult = $this->Database->query('SELECT Id FROM Server WHERE User='.$this->System->Modules['User']->User['Id']);
     227        $Server = $DbResult->fetch_assoc();
     228        $Server = new Server($this->Database, $Server['Id']);
     229        $Output .= $this->SystemMessage('Zastavení serveru', $Server->Stop());
    227230      } else
    228231      if($_GET['Action'] == 'Test')
     
    236239      {
    237240        $Output = $this->ShowServerList();
    238         $Output .= '<br /><a href="?Action=NewServer">Nový server</a>';     
     241        $Output .= '<br /><a href="?Action=ServerAdd">Nový server</a>';     
    239242      }
    240243    } else
    241244    {
    242245      $Output = $this->ShowServerList();
    243       $Output .= '<br /><a href="?Action=NewServer">Nový server</a>';     
     246      $Output .= '<br /><a href="?Action=ServerAdd">Nový server</a>';     
    244247    }
    245248    return($Output);
  • trunk/www/process_tasks.php

    r4 r5  
    88while($Task = $DbResult->fetch_assoc())
    99{
    10   echo('Provádím '.$Task['Command']."...\n");
     10  echo('Provádím '.$Task['Title']."...\n");
    1111  foreach(explode("\n", $Task['CommandList']) as $Command)
    1212  {
    1313    $Output = array();
     14    echo($Command."\n");
    1415    exec($Command, $Output);
    1516    echo(implode("\n", $Output));
  • trunk/www/server.php

    r4 r5  
    55  var $Id;
    66  var $Server;
     7  var $WorlddBaseNetworkPort = 8085;
     8  var $RealmdBaseNetworkPort = 3724;
    79 
    810  function __construct($Database, $Id)
     
    1618    $DbResult = $this->Database->query('SELECT * FROM `Emulator` WHERE `Id`='.$this->Server['Database']['Emulator']);
    1719    $this->Server['Database']['Emulator'] = $DbResult->fetch_assoc();
     20    $DbResult = $this->Database->query('SELECT * FROM `ClientVersion` WHERE `Id`='.$this->Server['Database']['Emulator']['ClientVersion']);
     21    $this->Server['Database']['Emulator']['ClientVersion'] = $DbResult->fetch_assoc();
    1822  }
    1923 
     
    4549  function Start()
    4650  {
    47     AddTask('Start emulátoru', array(
    48       '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',
    49       'screen -A -m -d -S server'.$this->Id.'-realmd emu/mangos/'.$this->Server['Database']['Emulator']['Revision'].'/bin/mangos-worldd -c server/'.$this->Id.'/etc/mangosd.conf',
     51    $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',
    5054    ));
     55    return('Požadavek na start serveru zařazen.');
    5156  }
    5257 
    5358  function Stop()
    5459  {
    55     AddTask('Zastavení emulátoru', array(
     60    $this->AddTask('Zastavení emulátoru', array(
    5661      'ps -ef | grep \'SCREEN -A -m -d -S server'.$this->Id.'-realmd\' | grep -v grep | awk \'{print $2}\' | xargs -i kill {}',
    5762      'ps -ef | grep \'SCREEN -A -m -d -S server'.$this->Id.'-worldd\' | grep -v grep | awk \'{print $2}\' | xargs -i kill {}',
    5863    ));
     64    return('Požadavek na zastavení serveru zařazen.');
     65  }
     66 
     67  function NetworkPortState($Address, $Port, $Timeout = 1)
     68  {
     69    if($Socket = @fsockopen($Address, $Port, $ERROR_NO, $ERROR_STR, (float)$Timeout))
     70    {
     71      fclose($Socket);
     72      return(true);
     73    } else return(false);
     74  }
     75 
     76  function GetState()
     77  {
     78    $State = array();
     79    $State['RealmdPortState'] = $this->NetworkPortState('localhost', $this->RealmdBaseNetworkPort + $this->Server['Id']);
     80    $State['WorlddPortState'] = $this->NetworkPortState('localhost', $this->WorlddBaseNetworkPort + $this->Server['Id']);
     81    return($State);
     82  }
     83 
     84  function SetupConfigurationFiles()
     85  {
     86    // mangosd.conf
     87    $Config = new MangosConfigurationFile($this->Database);
     88    $Config->Load('../emu/mangos/'.$this->Server['Database']['Emulator']['Revision'].'/etc/mangosd.conf');
     89    $Config->ParameterList['LoginDatabaseInfo'] = 'localhost;3306;server'.$this->Id.';server'.$this->Id.';server'.$this->Id.'_realmd';
     90    $Config->ParameterList['WorldDatabaseInfo'] = 'localhost;3306;server'.$this->Id.';server'.$this->Id.';server'.$this->Id.'_mangos';
     91    $Config->ParameterList['CharacterDatabaseInfo'] = 'localhost;3306;server'.$this->Id.';server'.$this->Id.';server'.$this->Id.'_characters';
     92    $Config->ParameterList['ScriptDev2DatabaseInfo'] = 'localhost;3306;server'.$this->Id.';server'.$this->Id.';server'.$this->Id.'_scriptdev2';
     93    $Config->ParameterList['WorldServerPort'] = $this->WorlddBaseNetworkPort + $this->Id;
     94    $Config->ParameterList['Motd'] = $this->Server['Motd'];
     95    $Config->ParameterList['DataDir'] = 'wowclient/'.$this->Server['Database']['Emulator']['ClientVersion']['Version'];
     96    $Config->Save('../server/'.$this->Id.'/etc/mangosd.conf');
     97   
     98    // realmd.conf
     99    $Config = new MangosConfigurationFile($this->Database);
     100    $Config->Load('../emu/mangos/'.$this->Server['Database']['Emulator']['Revision'].'/etc/realmd.conf');
     101    $Config->ParameterList['LoginDatabaseInfo'] = 'localhost;3306;server'.$this->Id.';server'.$this->Id.';server'.$this->Id.'_realmd';
     102    $Config->ParameterList['RealmServerPort'] = $this->RealmdBaseNetworkPort + $this->Id;
     103    $Config->Save('../server/'.$this->Id.'/etc/realmd.conf');
     104   
     105    // scriptdev2.conf
     106    $Config = new MangosConfigurationFile($this->Database);
     107    $Config->Load('../emu/mangos/'.$this->Server['Database']['Emulator']['Revision'].'/etc/scriptdev2.conf');
     108    $Config->ParameterList['ScriptDev2DatabaseInfo'] = 'localhost;3306;server'.$this->Id.';server'.$this->Id.';server'.$this->Id.'_scriptdev2';
     109    $Config->Save('../server/'.$this->Id.'/etc/scriptdev2.conf'); 
    59110  }
    60111}
  • trunk/www/sql/full.sql

    r2 r5  
    44--
    55-- Počítač: localhost
    6 -- Vygenerováno: Sobota 06. června 2009, 22:34
     6-- Vygenerováno: Úterý 09. června 2009, 09:32
    77-- Verze MySQL: 5.0.77
    88-- Verze PHP: 5.2.9
     
    8282  `ACIDRevision` int(11) NOT NULL,
    8383  `SourceFileName` varchar(255) NOT NULL,
     84  `Emulator` int(11) NOT NULL,
     85  PRIMARY KEY  (`Id`)
     86) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
     87
     88--
     89-- Vypisuji data pro tabulku `Database`
     90--
     91
     92INSERT INTO `Database` (`Id`, `Name`, `Version`, `Revision`, `ScriptDev2Revision`, `ACIDRevision`, `SourceFileName`, `Emulator`) VALUES
     93(1, 'UDB', '0.11.5', 380, 1012, 0, 'UDB_0.11.5_Core_7681_SD2_1012.sql', 1);
     94
     95-- --------------------------------------------------------
     96
     97--
     98-- Struktura tabulky `Debug`
     99--
     100
     101CREATE TABLE IF NOT EXISTS `Debug` (
     102  `Id` int(11) NOT NULL auto_increment,
     103  `Time` datetime NOT NULL,
     104  `Server` int(11) NOT NULL,
     105  `Backtrace` mediumtext NOT NULL,
     106  `Log` text NOT NULL,
     107  `MangosVersion` varchar(255) NOT NULL,
     108  `DbVersion` varchar(255) NOT NULL,
     109  `MaxPlayerCount` int(11) NOT NULL,
     110  `Uptime` int(11) NOT NULL,
     111  `ErrorLog` text NOT NULL,
     112  `DbErrors` text NOT NULL,
     113  `Configuration` text NOT NULL,
    84114  PRIMARY KEY  (`Id`)
    85115) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
    86116
    87117--
    88 -- Vypisuji data pro tabulku `Database`
     118-- Vypisuji data pro tabulku `Debug`
    89119--
    90120
     
    99129  `Id` int(11) NOT NULL auto_increment,
    100130  `Name` varchar(255) NOT NULL,
    101   `Emulator` int(11) NOT NULL,
     131  `ClientVersion` int(11) NOT NULL,
     132  `Revision` int(11) NOT NULL,
     133  PRIMARY KEY  (`Id`)
     134) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
     135
     136--
     137-- Vypisuji data pro tabulku `Emulator`
     138--
     139
     140INSERT INTO `Emulator` (`Id`, `Name`, `ClientVersion`, `Revision`) VALUES
     141(1, 'MaNGOS', 6, 7681);
     142
     143-- --------------------------------------------------------
     144
     145--
     146-- Struktura tabulky `Server`
     147--
     148
     149CREATE TABLE IF NOT EXISTS `Server` (
     150  `Id` int(11) NOT NULL auto_increment,
     151  `Name` varchar(255) NOT NULL,
     152  `NetworkPortRealmd` int(11) NOT NULL,
     153  `NetworkPortWorldd` int(11) NOT NULL,
     154  `User` int(11) NOT NULL,
    102155  `Database` int(11) NOT NULL,
    103   `ClientVersion` int(11) NOT NULL,
    104   `User` int(11) NOT NULL,
     156  `Motd` varchar(255) NOT NULL,
     157  PRIMARY KEY  (`Id`)
     158) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
     159
     160--
     161-- Vypisuji data pro tabulku `Server`
     162--
     163
     164INSERT INTO `Server` (`Id`, `Name`, `NetworkPortRealmd`, `NetworkPortWorldd`, `User`, `Database`, `Motd`) VALUES
     165(1, 'Test', 3127, 8085, 2, 1, '');
     166
     167-- --------------------------------------------------------
     168
     169--
     170-- Struktura tabulky `Task`
     171--
     172
     173CREATE TABLE IF NOT EXISTS `Task` (
     174  `Id` int(11) NOT NULL auto_increment,
     175  `Time` datetime NOT NULL,
     176  `Title` varchar(255) NOT NULL,
     177  `CommandList` text NOT NULL,
     178  `Server` int(11) NOT NULL,
     179  `Executed` int(11) NOT NULL,
    105180  PRIMARY KEY  (`Id`)
    106181) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
    107182
    108183--
    109 -- Vypisuji data pro tabulku `Emulator`
    110 --
    111 
    112 
    113 -- --------------------------------------------------------
    114 
    115 --
    116 -- Struktura tabulky `Server`
    117 --
    118 
    119 CREATE TABLE IF NOT EXISTS `Server` (
    120   `Id` int(11) NOT NULL auto_increment,
    121   `Name` varchar(255) NOT NULL,
    122   `Port` int(11) NOT NULL,
    123   `User` int(11) NOT NULL,
    124   `MangosVersion` int(11) NOT NULL,
    125   PRIMARY KEY  (`Id`)
    126 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
    127 
    128 --
    129 -- Vypisuji data pro tabulku `Server`
     184-- Vypisuji data pro tabulku `Task`
    130185--
    131186
     
    140195  `Id` int(11) NOT NULL auto_increment,
    141196  `Name` varchar(255) NOT NULL,
     197  `Login` varchar(255) NOT NULL,
    142198  `Password` varchar(255) NOT NULL,
    143199  `Email` varchar(255) NOT NULL,
    144   PRIMARY KEY  (`Id`)
    145 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
     200  `LastIpAddress` varchar(16) NOT NULL,
     201  `LastLoginTime` datetime NOT NULL,
     202  `RegistrationTime` datetime NOT NULL,
     203  `Locked` int(11) NOT NULL,
     204  PRIMARY KEY  (`Id`)
     205) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
    146206
    147207--
     
    149209--
    150210
     211INSERT INTO `User` (`Id`, `Name`, `Login`, `Password`, `Email`, `LastIpAddress`, `LastLoginTime`, `RegistrationTime`, `Locked`) VALUES
     212(1, 'Anonym', 'anonymous', '711a5c2497eca9d90a9cb92c188c7f4b8a7bf672', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0),
     213(2, 'Administrátor', 'admin', 'd033e22ae348aeb5660fc2140aec35850c4da997', 'root@localhost', '192.168.0.3', '2009-06-08 20:56:51', '0000-00-00 00:00:00', 0);
     214
     215-- --------------------------------------------------------
     216
     217--
     218-- Struktura tabulky `UserOnline`
     219--
     220
     221CREATE TABLE IF NOT EXISTS `UserOnline` (
     222  `Id` int(11) NOT NULL auto_increment,
     223  `User` int(11) NOT NULL default '0',
     224  `ActivityTime` datetime NOT NULL default '0000-00-00 00:00:00',
     225  `LoginTime` datetime NOT NULL default '0000-00-00 00:00:00',
     226  `SessionId` varchar(255) character set utf8 collate utf8_czech_ci NOT NULL default '',
     227  `IpAddress` varchar(16) character set utf8 collate utf8_czech_ci NOT NULL default '',
     228  `HostName` varchar(255) character set utf8 collate utf8_czech_ci NOT NULL default '',
     229  `ScriptName` varchar(255) character set utf8 collate utf8_czech_ci NOT NULL,
     230  PRIMARY KEY  (`Id`),
     231  KEY `User` (`User`)
     232) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
     233
     234
Note: See TracChangeset for help on using the changeset viewer.