Changeset 630 for trunk/inc/server.php


Ignore:
Timestamp:
Aug 26, 2009, 3:07:07 PM (15 years ago)
Author:
george
Message:
  • Přidáno: Podpora pro umístění světů na oddělených serverech. Vzdálené připojení k databázi.
  • Přidáno: Třída Realm pro sadu funkcí týkajících se světů.
  • Přidáno: Třída System pro reprezentaci obecných funkcí.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/inc/server.php

    r627 r630  
    55}
    66
    7 class Server
     7class Server extends Module
    88{
    9   private $db;
    10  
    11   public function __construct($db)
    12   {
    13     $this->db = $db;
    14   }
    15  
    16   public function HumanDate($date, $time = 1)
     9  function __construct($System, $Id)
     10  {
     11    parent::__construct($System);
     12    $this->Id = $Id;
     13  }
     14
     15  function HumanDate($date, $time = 1)
    1716  {
    1817    // input date is 0000-00-00 00:00:00
     
    2726  }
    2827
    29   public function RealmOnline()
    30   {
    31     global $Config;
    32    
    33     $this->db->select_db($Config['Mangos']['DatabaseRealmd']);
    34     $DbResult = $this->db->query('SELECT COUNT(*) FROM `account` WHERE `online` = 1');
     28  function OnlineAccountCount()
     29  {
     30    $this->Database->select_db($this->Config['Mangos']['DatabaseRealmd']);
     31    $DbResult = $this->Database->query('SELECT COUNT(*) FROM `account` WHERE `online` = 1');
    3532    $DbRow = $DbResult->fetch_row();
    3633    return($DbRow[0]);
    3734  }
    3835
    39   public function ParseCopper($copper_in)
     36  function ParseCopper($copper_in)
    4037  {
    4138    $copper = $copper_in;
     
    5047  }
    5148     
    52   public function MangosOnline($RealmId)
    53   {
    54     global $Config;
    55    
    56     $this->db->select_db($Config['Mangos']['RealmList'][$RealmId]['DatabaseCharacters']);   
    57     $DbResult = $this->db->query('SELECT COUNT(*) FROM `characters` WHERE `online` = 1');
    58     $DbRow = $DbResult->fetch_row();
    59     return($DbRow[0]);
    60   }
    61 
    62   public function ServerMangosOnline()
    63   {
    64     global $Config;
    65    
     49  function OnlineCharactersCount()
     50  {
    6651    $TotalCount = 0;
    67     foreach($Config['Mangos']['RealmList'] as $Index => $Realm)
     52    foreach($this->Config['Mangos']['RealmList'] as $Index => $Realm)
    6853    {
    69       $TotalCount += $this->MangosOnline($Index);
     54      $Realm = new Realm($this->System, $Index);
     55      $TotalCount += $Realm->OnlineCharactersCount();
    7056    }
    7157    return($TotalCount);
    7258  } 
    7359
    74   public function ServerOnline($Address, $Port, $Timeout = 0.5)
    75   {
    76     set_error_handler('NullErrorHandler');
    77     if($Socket = @fsockopen($Address, $Port, $ERROR_NO, $ERROR_STR, (float)$Timeout))
     60  function OnlineStateImage($Status)
     61  {
     62    if($Status) return('<img src="imgs/inc/on.gif" alt="online" />&nbsp;<span style="text-color: #234303; text-size: 4;">Online</span>');
     63      else return('<img src="imgs/inc/off.gif" alt="offline" />&nbsp;<span style="text-color: #990000; text-size: 4;">Offline</span>');
     64  }
     65
     66  function CharacterCount()
     67  {
     68    $TotalCount = 0;
     69    foreach($this->Config['Mangos']['RealmList'] as $Index => $Realm)
    7870    {
    79       fclose($Socket);
    80       $Result = true;
    81     } else $Result = false;
    82     restore_error_handler();
    83     return($Result);  }
    84 
    85   public function ServerImg($status)
    86   {
    87     if($status) return('<img src="imgs/inc/on.gif" alt="online" />&nbsp;<span style="text-color: #234303; text-size: 4;">Online</span>');
    88       else return('<img src="imgs/inc/off.gif" alt="offline" />&nbsp;<span style="text-color: #990000; text-size: 4;">Offline</span>');
    89   }
    90 
    91   public function ServerUptime()
    92   {
    93     global $Config;
    94 
    95     $this->db->select_db($Config['Mangos']['DatabaseRealmd']);
    96     $row = $this->db->query('SELECT `starttime`, `uptime` FROM `uptime` ORDER BY `starttime` DESC LIMIT 1')
    97   ->fetch_array();
    98     $uptime = round($row['uptime'] / 3600);
    99     return($uptime);
    100   }
    101 
    102   public function CharacterCount($RealmId)
    103   {
    104     global $Config;
    105 
    106     $this->db->select_db($Config['Mangos']['RealmList'][$RealmId]['DatabaseCharacters']);   
    107     $DbResult = $this->db->query('SELECT COUNT(*) FROM `characters`');
    108     $DbRow = $DbResult->fetch_row();
    109     return($DbRow[0]);
    110   }
    111 
    112   public function ServerCharacterCount()
    113   {
    114     global $Config;
    115    
    116     $TotalCount = 0;
    117     foreach($Config['Mangos']['RealmList'] as $Index => $Realm)
    118     {
    119       $TotalCount += $this->CharacterCount($Index);
     71      $Realm = new Realm($this->System, $Index);
     72      $TotalCount += $Realm->CharacterCount($Index);
    12073    }
    12174    return($TotalCount);
     
    12477  public function AccountCount()
    12578  {
    126     global $Config;
    127 
    128     $this->db->select_db($Config['Mangos']['DatabaseRealmd']);
    129     $row = $this->db->query('SELECT COUNT(*) FROM account')->fetch_row();
     79    $this->Database->select_db($this->Config['Mangos']['DatabaseRealmd']);
     80    $row = $this->Database->query('SELECT COUNT(*) FROM account')->fetch_row();
    13081    return($row[0]);
    131   }
    132 
    133   public function GuidToCharName($guid)
    134   {
    135     global $Config;
    136 
    137     $this->db->select_db($Config['Mangos']['RealmList'][$_COOKIE['RealmIndex']]['DatabaseCharacters']);
    138     $row = $this->db->query('SELECT `name` FROM `characters` WHERE `guid` = "'.$guid.'" LIMIT 1')->fetch_array();
    139     return($row['name']);
    140   }
    141  
    142   public function ShowGmLog($log)
    143   {
    144     echo('<table border="1" width="540">'.
    145       '<tr>
    146             <th>Čas</th>
    147             <th>GM</th>
    148             <th>Příkaz</th>
    149             <th>Vybrán</th>
    150           </tr>');
    151     $gm_log = ereg_replace("\n",";",$log);
    152     $gm_log = explode(";",$gm_log);
    153     $gm_log = array_reverse($gm_log);
    154     foreach($gm_log as $row)
    155     {
    156       if (strpos($row,"Command:") == true)
    157       {
    158         $edited = str_replace(" Command: ", ";", $row);     // 0 - time
    159         $edited = str_replace(" (Account: ", ";", $edited); // 1 - command
    160         $edited = str_replace(" [Player: ", ";", $edited);  // 2 - gm
    161         $edited = str_replace(" Selected: ", ";", $edited); // 3 - position
    162         $edited = str_replace(" (GUID: ", ";", $edited);    // 4 - selected
    163         $edited = str_replace(")]", ";", $edited);          // 5 - selected guid
    164         $edited_arr = explode(";",$edited);
    165         if($edited_arr[4] == "player") $sel_name = " - ".$this -> GuidToCharName($edited_arr[5]);
    166           else $sel_name = '';
    167         $human_date = $this -> HumanDate ($edited_arr[0]);
    168         echo('<tr>
    169             <td><font size="2">'.$human_date.'</font></td>
    170             <td>'.$edited_arr[2].'</td>
    171             <td>'.$edited_arr[1].'</td>
    172             <td>'.$edited_arr[4].$sel_name.'</td>
    173           </tr>');
    174       }
    175       if(strpos($row, 'mail item:') == true)
    176       {
    177         $edited = str_replace(" GM ", ";", $row);
    178         $edited = str_replace(" (Account: ", ";", $edited);
    179         $edited = str_replace(") mail item: ", ";", $edited);
    180         $edited = str_replace(" (Account: ", ";", $edited);
    181         $edited = str_replace(")", "", $edited);
    182         $edited_arr = explode(";",$edited);
    183         $human_date = $this -> HumanDate ($edited_arr[0]);
    184         echo('<tr>
    185             <td><font size="2">'.$human_date.'</font></td>
    186             <td>'.$edited_arr[1].'</td>
    187             <td>Send : '.$edited_arr[3].')</td>
    188             <td>-</td>
    189           </tr>');
    190       }
    191       if(strpos($row,"trade:") == true)
    192       {
    193         $edited = str_replace(" GM ", ";", $row);
    194         $edited = str_replace(" (Account: ", ";", $edited);
    195         $edited = str_replace(") trade: ", ";", $edited);
    196         $edited = str_replace(" (Account: ", ";", $edited);
    197         $edited = str_replace(")", "", $edited);
    198         $edited_arr = explode(";",$edited);
    199            
    200         $human_date = $this -> HumanDate ($edited_arr[0]);
    201         echo('<tr>
    202             <td><font size="2">'.$human_date.'</font></td>
    203             <td>'.$edited_arr[1].'</td>
    204             <td>Trade : '.$edited_arr[3].')</td>
    205             <td>-</td>
    206           </tr>');
    207       }
    208     }
    209     echo('</table>');
    210   }
    211 
    212   public function SeoUrl($title)
    213   { 
    214     $address = $title; 
    215     $diakritika = array("á","ä","č","ď","é","ě","ë","í","ň","ó","ö","ř","š","ť","ú","ů","ü","ý","ž","Á","Ä","Č","Ď","É","Ě","Ë","Í","Ň","Ó","Ö","Ř","Š","Ť","Ú","Ů","Ü","Ý","Ž");
    216     $nediakritika = array("a","a","c","d","e","e","e","i","n","o","o","r","s","t","u","u","u","y","z","A","A","C","D","E","E","E","I","N","O","O","R","S","T","U","U","U","Y","Z");
    217     $address = str_replace($diakritika, $nediakritika, $address);
    218     $address = strtolower ($address);   
    219     $address = preg_replace ("/[^[:alpha:][:digit:]]/", "-", $address); 
    220     $address = trim ($address, "-"); 
    221     $address = preg_replace ("/[-]+/", "-", $address); 
    222     return($address); 
    22382  }
    22483
     
    372231  function RealmSelection($FormNameSufix = '')
    373232  {
    374     global $Config;
    375    
    376    
    377233    $Output = '';
    378     if(count($Config['Mangos']['RealmList']) > 1)
     234    if(count($this->Config['Mangos']['RealmList']) > 1)
    379235    {
    380236      if(array_key_exists('page', $_GET)) $Target = '?page='.$_GET['page'];
     
    382238      $Output .= '<div style="text-align: center;"><form name="RealmSelection'.$FormNameSufix.'" action="'.$Target.'" method="post">'.
    383239      '<div>Výběr světa <select name="RealmIndex" onchange="document.RealmSelection'.$FormNameSufix.'.submit()">';
    384       foreach($Config['Mangos']['RealmList'] as $Index => $Realm)
     240      foreach($this->Config['Mangos']['RealmList'] as $Index => $Realm)
    385241      {
    386242        if($_COOKIE['RealmIndex'] == $Index) $Selected = ' selected="selected"';
Note: See TracChangeset for help on using the changeset viewer.