Changeset 576 for trunk/inc/player.php


Ignore:
Timestamp:
Apr 29, 2009, 8:02:38 PM (15 years ago)
Author:
george
Message:
  • Opraveno: Kód a styl stránky registrace účtů.
  • Opraveno: Třídat player byla pročištěna a opravena pro kompatibilitu s konfiguračním souborem config.php a nastavením názvů databází.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/inc/player.php

    r510 r576  
    11<?php
    22
    3 class Player {
     3class Player
     4{
    45  var $SessionTimeout = 30;
     6 
    57  private $db;
    6       // -- done
    7       function __construct ($db)
    8       {
    9         $this -> db = &$db;
    10       }
    11       // -- done
    12       private function Msg($text,$err)
    13       {
    14         if ($err == 0)
    15         {
    16           echo "<img src=\"imgs/inc/on.gif\">&nbsp;<font color=\"#234303\" size=\"4\">".$text."</font><br />";
    17         }
    18         else
    19         {
    20           echo "<img src=\"imgs/inc/off.gif\">&nbsp;<font color=\"#990000\" size=\"4\">".$text."</font><br />";
    21         }
    22       }
    23       // -- err
    24       public function Register ($acc_name , $pass , $email , $tbc)
    25       { include("inc/db.php");
    26         $this -> db -> select_db($db_realmd);
    27         $find = $this -> db -> query("SELECT `id` FROM `account` WHERE `username` = '".$acc_name."';");
    28         if ($find -> num_rows == 0)
    29         {
    30           $sha_pass = sha1(strtoupper($acc_name).":".strtoupper($pass));
    31           $sql = $this -> db -> query("
    32           INSERT INTO `account` ( `id` , `username` , `sha_pass_hash` , `gmlevel` , `sessionkey` , `v` , `s` , `email` , `joindate` , `last_ip` , `failed_logins` , `locked` , `last_login` , `online` , `tbc` , `mutetime` , `locale` )
    33           VALUES (NULL , '".$acc_name."', '".$sha_pass."', '0', NULL , NULL , NULL , '".$email."',CURRENT_TIMESTAMP , '".$_SERVER['REMOTE_ADDR']."', '0', '0', '0000-00-00 00:00:00', '0', '".$tbc."', '0', '0');
    34           ");
    35           $this -> Msg ("Účet založen úspěšně",0);
    36           echo "<meta http-equiv=\"refresh\" content=\"0;?page=acc\">";
    37         }
    38         else
    39         {
    40           $this -> Msg ("Zadané jmnéno účtu již existuje",1);
    41           $this -> Recall(3);
    42         }
    43      
    44       }
    45       // -- done
    46       public function Login ($username,$pass)
    47       {
    48           include("inc/db.php");
    49         $this -> db -> select_db($db_realmd);
    50         $sha_pass = sha1(strtoupper($username).":".strtoupper($pass));
    51         $sql = $this -> db -> query("SELECT `id` FROM `account` WHERE `account`.`username`='".$username."' AND `account`.`sha_pass_hash`='".$sha_pass."'");
    52         if ($sql -> num_rows == 1)
    53         {
    54           $row = $sql -> fetch_array();
    55           $_SESSION["UserId"] = $row["id"];
    56           $_SESSION["UserName"] = $username;
    57           $this -> Msg ("Přihlášení úspěšné",0);
    58           $this -> Recall(1);
    59         }
    60         else
    61         {
    62           $this -> Msg ("Přihlášení neúspěšné",1);
    63           $this -> Recall(3);
    64         }
    65       }
    66       // -- done
    67       public function Logout ()
    68       {
    69         $_SESSION["UserId"] = 0;
    70         $_SESSION["UserName"] = "";
    71         $this -> Msg ("Odhlášení úspěšné",0);
    72         $this -> Recall(1);
    73       }
    74       // -- done
    75       public function Check ()
    76       {
    77         if(!array_key_exists("Time", $_SESSION)) $_SESSION['Time'] = time();
    78         if(!array_key_exists("UserId", $_SESSION)) $_SESSION['UserId'] = 0;
    79         if($_SESSION["Time"] < (time() - 60 * $this -> SessionTimeout))
    80         {
    81           $this -> Logout();
    82         }
    83         $_SESSION["Time"] = time();
    84         return($_SESSION["UserId"] != 0);
    85       }
    86       // -- done
    87       public function LoginForm()
    88       {
    89           echo "
    90             <form method=\"post\" action=\"?page=acc\">
    91               <table>
     8 
     9  function __construct ($db)
     10  {
     11    $this->db = &$db;
     12  }
     13
     14  private function Msg($text, $err)
     15  {
     16    if($err == 0) echo('<img src="imgs/inc/on.gif">&nbsp;<font color="#234303" size="4">'.$text.'</font><br />');
     17    else echo('<img src="imgs/inc/off.gif">&nbsp;<font color="#990000" size="4\">'.$text.'</font><br />');
     18  }
     19
     20  public function Register($acc_name, $pass, $email, $tbc)
     21  {
     22    global $Config;
     23
     24    $this->db->select_db($Config['Mangos']['DatabaseRealmd']);
     25
     26    $find = $this->db->query('SELECT `id` FROM `account` WHERE `username` = "'.$acc_name.'"');
     27    if($find->num_rows == 0)
     28    {
     29      $sha_pass = sha1(strtoupper($acc_name).':'.strtoupper($pass));
     30      $sql = $this->db->query('INSERT INTO `account` ( `id` , `username` , `sha_pass_hash` , `gmlevel` , `sessionkey` , `v` , `s` , `email` , `joindate` , `last_ip` , `failed_logins` , `locked` , `last_login` , `online` , `tbc` , `mutetime` , `locale` ) '.
     31        ' VALUES (NULL , "'.$acc_name.'", "'.$sha_pass.'", 0, NULL , NULL , NULL , "'.$email.'", CURRENT_TIMESTAMP , "'.$_SERVER['REMOTE_ADDR'].'", 0, 0, "0000-00-00 00:00:00", 0, "'.$tbc.'", 0, 0)');
     32      $this->Msg('Účet založen úspěšně', 0);
     33      echo('<meta http-equiv="refresh" content="0;?page=acc">');
     34    } else
     35    {
     36      $this->Msg('Zadané jmnéno účtu již existuje', 1);
     37      $this->Recall(3);
     38    }     
     39  }
     40
     41  public function Login($username, $pass)
     42  {
     43    global $Config;
     44
     45    $this->db->select_db($Config['Mangos']['DatabaseRealmd']);
     46   
     47    $sha_pass = sha1(strtoupper($username).':'.strtoupper($pass));
     48    $sql = $this->db->query('SELECT `id` FROM `account` WHERE `username`="'.$username.'" AND `sha_pass_hash`="'.$sha_pass.'"');
     49    if($sql->num_rows == 1)
     50    {
     51      $row = $sql->fetch_array();
     52      $_SESSION['UserId'] = $row['id'];
     53      $_SESSION['UserName'] = $username;
     54      $this->Msg('Přihlášení úspěšné', 0);
     55      $this->Recall(1);
     56    } else
     57    {
     58      $this->Msg('Přihlášení neúspěšné', 1);
     59      $this->Recall(3);
     60    }
     61  }
     62
     63  public function Logout()
     64  {
     65    $_SESSION['UserId'] = 0;
     66    $_SESSION['UserName'] = '';
     67    $this->Msg('Odhlášení úspěšné', 0);
     68    $this->Recall(1);
     69  }
     70
     71  public function Check()
     72  {
     73    if(!array_key_exists('Time', $_SESSION)) $_SESSION['Time'] = time();
     74    if(!array_key_exists('UserId', $_SESSION)) $_SESSION['UserId'] = 0;
     75    if($_SESSION['Time'] < (time() - 60 * $this->SessionTimeout))
     76    {
     77      $this->Logout();
     78    }
     79    $_SESSION['Time'] = time();
     80    return($_SESSION['UserId'] != 0);
     81  }
     82
     83  public function LoginForm()
     84  {
     85    echo('<form method="post" action="?page=acc">
     86     <table>
    9287                <tr>
    93                   <td><b>Jméno : </b></td><td><input type=\"text\" name=\"user\"></td>
     88                  <td><b>Jméno : </b></td><td><input type="text" name="user"></td>
    9489                </tr>
    9590                <tr>
    96                   <td><b>Heslo : </b></td><td><input type=\"password\" name=\"pass\" autocomplete=\"off\"></td>
     91                  <td><b>Heslo : </b></td><td><input type="password" name="pass" autocomplete="off"></td>
    9792                </tr>
    9893                <tr>
    99                   <td colspan=\"2\" align=\"right\"><input type=\"submit\" value=\"Příhlásit\" name=\"login\"></td>
     94                  <td colspan="2" align="right"><input type="submit" value="Příhlásit" name="login"></td>
    10095                </tr>
    10196              </table>
    10297            </form>
    103             <div align=\"left\">
    104             <a href=\"?page=register\">Registrace</a><br /><a href=\"?page=lostpass\">Obnova hesla</a>
    105             </div>
    106           ";
     98            <div align="left">
     99            <a href="?page=register">Registrace</a><br /><a href="?page=lostpass">Obnova hesla</a>
     100            </div>');
     101   }
     102
     103  public function GetPlayerLvl($guid)
     104  {
     105    global $Config;
     106
     107    $this->db->select_db($Config['Mangos']['DatabaseCharacters']);
     108      $DbResult = $this->db->query(
     109      'SELECT CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(`data`, " ", 34), " ", -1)'.
     110      ' AS UNSIGNED) AS `level` FROM `characters` WHERE `guid` = "'.$guid.'" LIMIT 1;');
     111    $row = $DbResult->fetch_assoc();
     112    return($row['level']);
     113  }
     114
     115  public function GetGmLvl()
     116  {
     117    // $this -> NumCheck($guid);
     118    $this->db->select_db($db_realmd);
     119    $row = $this->db->query('SELECT `gmlevel` FROM `account` WHERE `id` = "'.$_SESSION['UserId'].'" LIMIT 1;')->fetch_array();
     120    return($row['gmlevel']);
     121  }
     122
     123  public function GetPlayerClass($Id)
     124  {
     125    $Class = array(1 => 'warrior', 2 => 'paladin', 3 => 'hunter', 4 => 'rogue', 5 => 'priest', 6 => 'death knight', 7 => 'shaman', 8 => 'mage', 9 => 'warlock', 11 => 'druid');
     126    $Result = $Class[$Id];
     127    if($Result == '') $Result = 'unknown';
     128    return($Result);
     129  }
     130   
     131  public function GetPlayerRace($Id)
     132  {
     133    $Race = array(1 => 'human', 2 => 'orc', 4 => 'dwarf', 4 => 'nightelf', 5 => 'undead', 6 => 'tauren', 7 => 'gnome', 8 => 'troll', 9 => 'goblin', 10 => 'bloodelf', 11 => 'draenei');
     134    $Result = $Race[$Id];
     135    if($Result == '') $Result = 'unknown';
     136    return($Result);
     137  }
     138
     139  public function ResetXP($guid)
     140  {
     141    global $Config;
     142
     143    if($this->CharInAcc($guid, 0))
     144    {
     145      if(!$this->IsOnline($guid))
     146      {
     147        $this->db->select_db($Config['Mangos']['DatabaseCharacters']);
     148        $row = $this->db->query('SELECT `data` FROM `characters` WHERE `guid` = "'.$guid.'" LIMIT 1')->fetch_assoc();
     149        $data = explode(' ', $row['data']);
     150        $data[926] = 0;
     151        $data = implode(' ', $data);
     152        $this->db->query('UPDATE `characters` SET `data` = "'.$data.'" WHERE `guid` ="'.$guid.'" LIMIT 1');
     153        $this->Msg('Postavě resetováno XP.', 0);
     154      } else $this->Msg('Postava musí být offline.', 1);
     155    } else $this->Msg('Tato postava není vaše.', 1);
     156  }
     157
     158  public function ResetPosition($guid)
     159  {
     160    global $Config;
     161
     162    $this->db->select_db($Config['Mangos']['DatabaseCharacters']);
     163    if($this->CharInAcc($guid, 0))
     164    {
     165      if(!$this->IsOnline($guid))
     166      {
     167        $row = $this->db->query('SELECT * FROM `character_homebind` WHERE `guid` = "'.$guid.'" LIMIT 1;')->fetch_array();
     168        $home_char_map = $row['map'];
     169        $home_char_position_x = $row['position_x'];
     170        $home_char_position_y = $row['position_y'];
     171        $home_char_position_z = $row['position_z'];
     172        if(isset($home_char_map) and isset($home_char_position_x) and isset($home_char_position_y) and isset($home_char_position_z))
     173        {
     174          $this->db->query('UPDATE `characters` SET '.
     175            '`map` = "'.$home_char_map.'" , '.
     176            '`position_x` ="'.$home_char_position_x.'" , '.
     177            '`position_y` = "'.$home_char_position_y.'" , '.
     178            '`position_z` = "'.$home_char_position_z.'" '.
     179            ' WHERE `guid` ='.$guid.' LIMIT 1;');
     180          $this->Msg('Postava teleportována.', 0);
     181        }
     182      } else $this->Msg('Postava musí být offline.', 1);
     183    } else $this->Msg('Tato postava není vaše.', 1);
     184  }
     185
     186  public function PlayerJail($guid)
     187  {
     188    global $Config;
     189
     190    $this->db->select_db($Config['Mangos']['DatabaseCharacters']);
     191    // .go xyz -90.54 41.35 -31.71
     192    // .go xyz -91.01 100.46 -31.71
     193    // .go xyz -119.16 71.82 -31.71
     194    $defined_positions = array
     195    (
     196      'x1' => '-90.54',
     197      'y1' => '41.35',
     198      'z1' => '-31.71',
     199      'o1' => '1.4623',
     200         
     201      'x2' => '-91.01',
     202      'y2' => '100.46',
     203      'z2' => '-31.71',
     204      'o3' => '4.6282',
     205         
     206      'x3' => '-119.16',
     207      'y3' => '71.82',
     208      'z3' => '-31.71',
     209      'o3' => '6.2116',
     210    );
     211    $rand_place = rand(1, 3);
     212    if(!$this->IsOnline($guid))
     213    {
     214      $this->db->query('UPDATE `characters` SET `map` = 35 ,'.
     215        '`orientation` = "'.$defined_positions['o'.$rand_place].'" ,'.
     216        '`position_x` ="'.$defined_positions['x'.$rand_place].'" ,'.
     217        '`position_y` = "'.$defined_positions['y'.$rand_place].'" ,'.
     218        '`position_z` = "'.$defined_positions['z'.$rand_place].'"'.
     219        ' WHERE `guid` ="'.$guid.'" LIMIT 1;');
     220      $this->db->query('INSERT INTO `character_aura` (`guid`, `caster_guid`, `spell`, `effect_index`, `amount`, `maxduration`, `remaintime`, `remaincharges`) VALUES '.
     221        '('.$guid.', '.$guid.', 23775, 0, 1, -1, -1, -1), '.
     222        '('.$guid.', '.$guid.', 36558, 0, 1, -1, -1, -1);');               
     223      $this->Msg('Postava ve vězení.', 0);         
     224    } else $this->Msg('Postava musí být offline.', 1);
     225  }
     226
     227  public function IsOnline($guid)
     228  {
     229    global $Config;
     230
     231    $this->db->select_db($Config['Mangos']['DatabaseCharacters']);
     232    $row = $this->db->query('SELECT `online` FROM `characters` WHERE `guid` = "'.$guid.'" LIMIT 1;')->fetch_assoc();
     233    if($row['online'] == 1) return(true);
     234    else return(false);
     235  }
     236
     237  public function CharInAcc($char, $acc)
     238  {
     239    global $Config;
     240   
     241    if($this->Check())
     242    {
     243      if($acc == 0)
     244      {
     245        $acc = $_SESSION['UserId'];
    107246      }
    108       // --
    109       public function GetPlayerLvl ($guid)
    110       {
    111           include("inc/db.php");
    112         // $this -> NumCheck($guid);
    113         $this -> db -> select_db($db_characters);
    114         $row = $this -> db -> query("SELECT CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(`data`, ' ', 34), ' ', -1) AS UNSIGNED) AS `level` FROM `characters` WHERE `guid` = '".$guid."' LIMIT 1;") -> fetch_array();
    115         return $row["level"];
     247      $this->db->select_db($Config['Mangos']['DatabaseCharacters']);
     248      if($this->db->query('SELECT `guid` FROM `characters` WHERE `characters`.`guid`="'.$char.'" AND `account`="'.$acc.'" LIMIT 1;')->num_rows == 1)
     249      {
     250        return(true);
     251      } else
     252      {
     253        return false;
    116254      }
    117       // -- done
    118       public function GetGmLvl ()
    119       {
    120            include("inc/db.php");
    121         // $this -> NumCheck($guid);
    122         $this -> db -> select_db($db_realmd);
    123         $row = $this -> db -> query("SELECT `gmlevel` FROM `account` WHERE `id` = '".$_SESSION["UserId"]."' LIMIT 1;") -> fetch_array();
    124         return $row["gmlevel"];
     255    } else
     256    {
     257      $this->Msg('Nejste přihlášen', 1);
     258      die;
     259    }
     260  }
     261
     262  public function CharNameToGuid($name)
     263  {
     264    global $Config;
     265
     266    $this->db->select_db($Config['Mangos']['DatabaseCharacters']);
     267    $row = $this->db->query('SELECT `guid` FROM `characters` WHERE `name` LIKE "'.$name.'" LIMIT 1;')->fetch_assoc();
     268    if($row['guid'] != '')
     269    {
     270      return($row['guid']);
     271    } else
     272    {
     273      return('Nenalezen');
     274    }
     275  }
     276
     277  public function GuidToCharName($guid)
     278  {
     279    global $Config;
     280
     281    $this->db->select_db($Config['Mangos']['DatabaseCharacters']);
     282    $row = $this->db->query('SELECT `name` FROM `characters` WHERE `guid` = "'.$guid.'" LIMIT 1;')->fetch_assoc();
     283    if($row['name'] != '')
     284    {
     285      return($row['name']);
     286    } else
     287    {
     288      return('Nenalezen');
     289    }     
     290  }
     291
     292  public function AccNameToGuid($name)
     293  {
     294    global $Config;
     295
     296    $this->db->select_db($Config['Mangos']['DatabaseRealmd']);
     297    $row = $this->db->query('SELECT `id` FROM `account` WHERE `username` LIKE "'.$name.'" LIMIT 1;')->fetch_assoc();
     298    //return($row['id']);
     299    if($row['id'] != '')
     300    {
     301      return($row['id']);
     302    } else
     303    {
     304      return('Nenalezen');
     305    }
     306  }
     307
     308  public function MoveChar($acc1_name, $acc1_pass, $acc2_name, $char_name)
     309  {
     310    global $Config;
     311
     312    $this->db->select_db($Config['Mangos']['DatabaseRealmd']);
     313    $sha_pass = sha1(strtoupper($acc1_name).':'.strtoupper($acc1_pass));
     314    $sql = $this->db->query('SELECT `id` FROM `account` WHERE `username`="'.$acc1_name.'" AND `sha_pass_hash`="'.$sha_pass.'"');
     315    if($sql->num_rows == 1)
     316    {
     317      $acc1_guid = $this->AccNameToGuid($acc1_name);
     318      $acc2_guid = $this->AccNameToGuid($acc2_name);
     319      $char_guid = $this->CharNameToGuid($char_name);
     320      if($this->CharInAcc($char_guid, $acc1_guid))
     321      {
     322        $this->db->query('UPDATE `characters` SET `account` = "'.$acc2_guid.'" WHERE `guid` ="'.$char_guid.'" LIMIT 1');
     323        $this->Msg('Postava přemístěna.', 0);
     324      } else
     325      {
     326        $this->Msg('Tato postava není vaše.', 1);
    125327      }
    126       // -- done
    127       public function GetPlayerClass($id)
    128       {
    129         switch ($id)
    130         {
    131         case 1:
    132            return("warrior");
    133            break;
    134         case 2:
    135            return("paladin");
    136            break;
    137         case 3:
    138            return("hunter");
    139            break;
    140         case 4:
    141            return("rogue");
    142            break;
    143         case 5:
    144            return("priest");
    145            break;
    146         case 7:
    147            return("shaman");
    148            break;
    149         case 8:
    150            return("mage");
    151            break;
    152         case 9:
    153            return("warlock");
    154            break;
    155         case 11:
    156            return("druid");
    157            break;
    158         default:
    159             return("unknown");
    160         }
     328    }
     329  }
     330
     331  public function Recall($time)
     332  {
     333    global $Config;
     334     
     335    if(isset($_SERVER['HTTP_REFERER']))
     336    {
     337      $link = parse_url($_SERVER['HTTP_REFERER']);
     338      if(($link['host'] == $Config['Web']['WoWServerAddr']) or ($link['host'] == 'localhost'))
     339      {
     340        echo('<meta http-equiv="refresh" content="'.$time.';?'.$link['query'].'">');
     341      } else
     342      {
     343        echo('<meta http-equiv="refresh" content="'.$time.';">');
    161344      }
    162       // -- done
    163       public function GetPlayerRace($id)
    164       {
    165         switch ($id)
    166         {
    167         case 1:
    168            return("human");
    169            break;
    170         case 2:
    171            return("orc");
    172            break;
    173         case 3:
    174            return("dwarf");
    175            break;
    176         case 4:
    177            return("nightelf");
    178            break;
    179         case 5:
    180            return("undead");
    181            break;
    182         case 6:
    183            return("tauren");
    184            break;
    185         case 7:
    186            return("gnome");
    187            break;
    188         case 8:
    189            return("troll");
    190            break;
    191         case 9:
    192            return("goblin");
    193            break;
    194         case 10:
    195            return("bloodelf");
    196            break;
    197         case 11:
    198            return("draenei");
    199            break;
    200         default:
    201             return("unknown");
    202         }
    203       }
    204       // -- done
    205       public function ResetXP ($guid)
    206       {
    207         if ($this -> CharInAcc($guid,0))
    208         {
    209           if (!$this -> IsOnline($guid))
    210           {
    211                    include("inc/db.php");
    212             $this -> db -> select_db($db_characters);
    213             $row = $this -> db -> query("SELECT `data` FROM `characters` WHERE `guid` = '".$guid."' LIMIT 1;") -> fetch_array();
    214             $data = explode(" ",$row["data"]);
    215             $data[926] = 0;
    216             $this -> db -> query("UPDATE `characters` SET  `data` = '".implode(" ",$data)."' WHERE `guid` ='".$guid."' LIMIT 1");
    217             $this -> Msg ("Postavě resetováno XP.",0);
    218           }
    219           else
    220           {$this -> Msg ("Postava musí být offline.",1);}
    221         }
    222         else
    223         {$this -> Msg ("Tato postava není vaše.",1);}
    224       }
    225       // -- done
    226       public function ResetPosition ($guid)
    227       {
    228         if ($this -> CharInAcc($guid,0))
    229         {
    230           if (!$this -> IsOnline($guid))
    231           {
    232                    include("inc/db.php");
    233             $this -> db -> select_db($db_characters);
    234             $row = $this -> db -> query("SELECT * FROM `character_homebind` WHERE `guid` = '".$guid."' LIMIT 1;") -> fetch_array();
    235             $home_char_map         = $row["map"];
    236             $home_char_position_x  = $row["position_x"];
    237             $home_char_position_y  = $row["position_y"];
    238             $home_char_position_z  = $row["position_z"];
    239             if (isset($home_char_map) AND isset ($home_char_position_x) AND isset ($home_char_position_y) AND isset ($home_char_position_z))
    240             {
    241               $this -> db -> query("UPDATE `characters` SET
    242               `map` = '".$home_char_map."' ,
    243               `position_x` ='".$home_char_position_x."' ,
    244               `position_y` = '".$home_char_position_y."' ,
    245               `position_z` = '".$home_char_position_z."'
    246                WHERE `guid` ='".$guid."' LIMIT 1;");
    247                $this -> Msg ("Postava teleportována.",0);
    248             }
    249           }
    250           else
    251           {$this -> Msg ("Postava musí být offline.",1);}
    252         }
    253         else
    254         {$this -> Msg ("Tato postava není vaše.",1);}
    255       }
    256       public function PlayerJail ($guid)
    257       {
    258           // .go xyz -90.54 41.35 -31.71
    259           // .go xyz -91.01 100.46 -31.71
    260           // .go xyz -119.16 71.82 -31.71
    261           $defined_positions = array (
    262           "x1" => "-90.54",
    263           "y1" => "41.35",
    264           "z1" => "-31.71",
    265           "o1" => "1.4623",
    266          
    267           "x2" => "-91.01",
    268           "y2" => "100.46",
    269           "z2" => "-31.71",
    270           "o3" => "4.6282",
    271          
    272           "x3" => "-119.16",
    273           "y3" => "71.82",
    274           "z3" => "-31.71",
    275           "o3" => "6.2116",
    276           );
    277           $rand_place = rand (1,3);
    278           if (!$this -> IsOnline($guid))
    279           {
    280                    include("inc/db.php");
    281             $this -> db -> select_db($db_characters);
    282               $this -> db -> query("UPDATE `characters` SET
    283               `map` = '35' ,
    284               `orientation` = '".$defined_positions["o".$rand_place]."' ,
    285               `position_x` ='".$defined_positions["x".$rand_place]."' ,
    286               `position_y` = '".$defined_positions["y".$rand_place]."' ,
    287               `position_z` = '".$defined_positions["z".$rand_place]."'
    288                WHERE `guid` ='".$guid."' LIMIT 1;");
    289               $this -> db -> query("INSERT INTO `character_aura` (`guid`, `caster_guid`, `spell`, `effect_index`, `amount`, `maxduration`, `remaintime`, `remaincharges`) VALUES
    290               (".$guid.", ".$guid.", 23775, 0, 1, -1, -1, -1),
    291               (".$guid.", ".$guid.", 36558, 0, 1, -1, -1, -1);");
    292                
    293                $this -> Msg ("Postava ve vězení.",0);
    294            
    295           }
    296           else
    297           {$this -> Msg ("Postava musí být offline.",1);}
    298      
    299 
    300       }
    301       // -- done
    302       public function IsOnline ($guid)
    303       {
    304            include("inc/db.php");
    305         $this -> db -> select_db($db_characters);
    306         $row = $this -> db -> query("SELECT `online` FROM `characters` WHERE `guid` = '".$guid."' LIMIT 1;") -> fetch_array();
    307         if ($row["online"] == 1)
    308         {return true;}
    309         else
    310         {return false;}
    311       }
    312       // --
    313       public function CharInAcc ($char,$acc)
    314       {
    315         if ($this -> Check())
    316         {
    317                  include("inc/db.php");
    318           if ($acc == 0)
    319           {$acc = $_SESSION["UserId"];}
    320           $this -> db -> select_db($db_characters);
    321           if ($this -> db -> query("SELECT `guid` FROM `characters` WHERE `characters`.`guid`='".$char."' AND `characters`.`account`='".$acc."' LIMIT 1;") -> num_rows == 1)
    322           {return true;}
    323           else
    324           {return false;}
    325         }
    326         else
    327         {
    328           $this -> Msg ("Nejste přihlášen",1);
    329           die;
    330         }
    331       }
    332       // --
    333       public function CharNameToGuid ($name)
    334       {
    335            include("inc/db.php");
    336         $this -> db -> select_db($db_characters);
    337         $row = $this -> db -> query("SELECT `guid` FROM `characters` WHERE `name` LIKE '".$name."' LIMIT 1;") -> fetch_array();
    338         if ($row["guid"] != "")
    339         {
    340           return $row["guid"];
    341         }
    342         else
    343         {
    344           return "Nenalezen";
    345         }
    346        
    347       }
    348       // --
    349       public function GuidToCharName ($guid)
    350       {
    351            include("inc/db.php");
    352         $this -> db -> select_db($db_characters);
    353         $row = $this -> db -> query("SELECT `name` FROM `characters` WHERE `guid` = '".$guid."' LIMIT 1;") -> fetch_array();
    354         if ($row["name"] != "")
    355         {
    356           return $row["name"];
    357         }
    358         else
    359         {
    360           return "Nenalezen";
    361         }
    362        
    363       }
    364       // --
    365       public function AccNameToGuid ($name)
    366       {
    367            include("inc/db.php");
    368         $this -> db -> select_db($db_realmd);
    369         $row = $this -> db -> query("SELECT `id` FROM `account` WHERE `username` LIKE '".$name."' LIMIT 1;") -> fetch_array();
    370         return $row["id"];
    371         if ($row["id"] != "")
    372         {
    373           return $row["id"];
    374         }
    375         else
    376         {
    377           return "Nenalezen";
    378         }
    379       }
    380       // --
    381       public function MoveChar($acc1_name,$acc1_pass,$acc2_name,$char_name)
    382       {
    383            include("inc/db.php");
    384         $this -> db -> select_db($db_realmd);
    385         $sha_pass = sha1(strtoupper($acc1_name).":".strtoupper($acc1_pass));
    386         $sql = $this -> db -> query("SELECT `id` FROM `account` WHERE `account`.`username`='".$acc1_name."' AND `account`.`sha_pass_hash`='".$sha_pass."'");
    387         if ($sql -> num_rows == 1)
    388         {
    389           $acc1_guid = $this -> AccNameToGuid($acc1_name);
    390           $acc2_guid = $this -> AccNameToGuid($acc2_name);
    391           $char_guid = $this -> CharNameToGuid($char_name);
    392            if ($this -> CharInAcc($char_guid,$acc1_guid))
    393            {
    394            $this -> db -> select_db("realm1_characters");
    395            $this -> db -> query("UPDATE `characters` SET  `account` = '".$acc2_guid."' WHERE `guid` ='".$char_guid."' LIMIT 1;");
    396            $this -> Msg ("Postava přemístěna.",0);
    397            }
    398            else
    399            {
    400            $this -> Msg ("Tato postava není vaše.",1);
    401            }
    402         }
    403       }
    404       // --
    405       public function Recall($time)
    406       {
    407         if (isset($_SERVER["HTTP_REFERER"]))
    408         {
    409           $link = parse_url($_SERVER["HTTP_REFERER"]);
    410           if ($link["host"] == "wow.zdechov.net" OR $link["host"] == "localhost")
    411           {
    412             echo "<meta http-equiv=\"refresh\" content=\"".$time.";?".$link["query"]."\">";
    413           }
    414           else
    415           {
    416             echo "<meta http-equiv=\"refresh\" content=\"".$time.";\">";
    417           }
    418         }
    419       }
    420       // --
    421       // done
    422       public function CharsOnAcc ($accid)
    423       {
    424            include("inc/db.php");
    425         echo "
    426         <table>
     345    }
     346  }
     347
     348  public function CharsOnAcc($accid)
     349  {
     350    global $Config;
     351   
     352    echo('<table>
    427353          <tr>
    428             <th align=\"center\">Jméno</th>
    429             <th align=\"center\">Úroveň</th>
    430             <th align=\"center\">Rasa</th>
    431             <th align=\"center\">Class</th>
    432             <th align=\"center\">Nahráno</th>
    433           </tr>
    434         ";
    435         $this -> db -> select_db($db_characters);
    436         $sql = $this -> db -> query("SELECT `guid`,`name`,`race`,`totaltime`,`class`,mid(lpad( hex( CAST(substring_index(substring_index(data,' ',37),' ',-1) as unsigned) ),8,'0'),4,1) AS gender FROM `characters` WHERE `characters`.`account`='".$accid."' ORDER BY `totaltime` DESC LIMIT 0,10;");
    437         while ($row = $sql -> fetch_array())
    438         {
    439         $gender = ($row["gender"] == 0)?"m":"f";
    440         echo "
    441           <tr>
    442             <td align=\"center\">".$row["name"]."</td>
    443             <td align=\"center\">".$this -> GetPlayerLvl($row["guid"])."</td>
    444             <td align=\"center\"><img src=\"imgs/icons/".$this -> GetPlayerRace($row["race"])."-".$gender.".gif\"></td>
    445             <td align=\"center\"><img src=\"imgs/icons/".$this -> GetPlayerClass($row["class"]).".gif\"></td>
    446             <td align=\"center\">".round($row["totaltime"]/3600)." h</td>
    447           </tr>
    448         ";
    449         }
    450         echo "</table>";
    451       }
    452       // --
    453       // prihlaseni se ke generaci signatury
    454       public function SignatureOn ($guid)
    455       {
    456       $this -> db -> select_db($db_webu);
    457       }
    458       // lol
    459       private function NumCheck ($number)
    460       {
    461         if (!is_numeric($number))
    462         {
    463           die("Input Error");
    464         }
    465       }
     354            <th align="center">Jméno</th>
     355            <th align="center">Úroveň</th>
     356            <th align="center">Rasa</th>
     357            <th align="center">Třída</th>
     358            <th align="center">Nahráno</th>
     359          </tr>');
     360    $this->db->select_db($Config['Mangos']['DatabaseCharacters']);
     361    echo($this->db->error);
     362    $sql = $this->db->query('SELECT `guid`,`name`,`race`,`totaltime`,`class`, mid(lpad( hex( CAST(substring_index(substring_index(data, " ", 37), " ",-1) AS unsigned) ), 8, 0), 4, 1) AS gender FROM `characters` WHERE `account`='.$accid.' ORDER BY `totaltime` DESC LIMIT 0, 10');
     363    echo($this->db->error);
     364    while($row = $sql->fetch_array())
     365    {
     366      $gender = ($row['gender'] == 0) ? 'm' : 'f';
     367      echo('<tr>'.
     368        '<td align="center">'.$row['name'].'</td>'.
     369        '<td align="center">'.$this->GetPlayerLvl($row['guid']).'</td>'.
     370        '<td align="center"><img src="imgs/icons/'.$this->GetPlayerRace($row['race']).'-'.$gender.'.gif"></td>'.
     371        '<td align="center"><img src="imgs/icons/'.$this->GetPlayerClass($row['class']).'.gif"</td>'.
     372        '<td align="center">'.round($row['totaltime'] / 3600).' h</td>'.
     373        '</tr>');
     374    }
     375    echo('</table>');
     376  }
    466377}
     378
    467379?>
Note: See TracChangeset for help on using the changeset viewer.