Changeset 5 for trunk/www/server.php


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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.