Guest User

Lineage_l2jserver.php

a guest
Mar 1st, 2015
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 15.90 KB | None | 0 0
  1. <?php
  2.  
  3. class Lineage_l2jserver extends CI_Driver
  4. {
  5.     public $version = 'h';
  6.     private $char_id = 'charId'; // characters
  7.  
  8.  
  9.  
  10.     public function insert_account($login, $password)
  11.     {
  12.         $data = array(
  13.             'login'    => $login,
  14.             'password' => $password,
  15.         );
  16.  
  17.         return $this->db->insert('accounts', $data);
  18.     }
  19.  
  20.     public function get_account_by_login($login)
  21.     {
  22.         return $this->get_accounts(1, NULL, array('login' => $login));
  23.     }
  24.  
  25.     public function get_accounts_by_login($login, $limit = NULL, $offset = NULL)
  26.     {
  27.         $where          = NULL;
  28.         $where_in_field = 'login';
  29.         $where_in       = NULL;
  30.  
  31.         if(is_array($login))
  32.         {
  33.             $where_in = $login;
  34.         }
  35.         else
  36.         {
  37.             $where = array('login' => $login);
  38.         }
  39.  
  40.         return $this->get_accounts($limit, $offset, $where, NULL, NULL, NULL, NULL, $where_in_field, $where_in);
  41.     }
  42.  
  43.     public function get_accounts($limit = NULL, $offset = NULL, array $where = NULL, $order_by = NULL, $order_type = 'asc', array $like = NULL, array $group_by = NULL, $where_in_field = NULL, array $where_in = NULL)
  44.     {
  45.         if(is_numeric($limit))
  46.         {
  47.             $this->db->limit($limit);
  48.         }
  49.  
  50.         if(is_numeric($offset))
  51.         {
  52.             $this->db->offset($offset);
  53.         }
  54.  
  55.         if($where != NULL)
  56.         {
  57.             $this->db->where($where);
  58.         }
  59.  
  60.         if($order_by != NULL)
  61.         {
  62.             $this->db->order_by($order_by, $order_type);
  63.         }
  64.  
  65.         if($like != NULL)
  66.         {
  67.             $this->db->like($like);
  68.         }
  69.  
  70.         if($group_by != NULL)
  71.         {
  72.             $this->db->group_by($group_by);
  73.         }
  74.  
  75.         if($where_in_field != NULL && $where_in != NULL)
  76.         {
  77.             $this->db->where_in($where_in_field, $where_in);
  78.         }
  79.  
  80.         $this->db->select('login,password,lastactive AS last_active');
  81.  
  82.         if($limit == 1)
  83.         {
  84.             return $this->db->get('accounts')->row_array();
  85.         }
  86.  
  87.         return $this->db->get('accounts')->result_array();
  88.     }
  89.  
  90.     public function get_characters($limit = NULL, $offset = NULL, array $where = NULL, $order_by = NULL, $order_type = 'asc', array $like = NULL, array $group_by = NULL, $where_in_field = NULL, array $where_in = NULL)
  91.     {
  92.         if(is_numeric($limit))
  93.         {
  94.             $this->db->limit($limit);
  95.         }
  96.  
  97.         if(is_numeric($offset))
  98.         {
  99.             $this->db->offset($offset);
  100.         }
  101.  
  102.         if($where != NULL)
  103.         {
  104.             $this->db->where($where);
  105.         }
  106.  
  107.         if($order_by != NULL)
  108.         {
  109.             $this->db->order_by($order_by, $order_type);
  110.         }
  111.  
  112.         if($like != NULL)
  113.         {
  114.             $this->db->like($like);
  115.         }
  116.  
  117.         if($group_by != NULL)
  118.         {
  119.             $this->db->group_by($group_by);
  120.         }
  121.  
  122.         if($where_in_field != NULL && $where_in != NULL)
  123.         {
  124.             $this->db->where_in($where_in_field, $where_in);
  125.         }
  126.  
  127.         $this->db->select('characters.account_name,characters.charId AS obj_Id,characters.char_name,characters.`level`,characters.maxHp,characters.curHp,characters.maxCp,characters.curCp,characters.maxMp,characters.curMp,characters.sex,characters.x,characters.y,
  128.            characters.z,characters.exp,characters.sp,characters.karma,characters.pvpkills,characters.pkkills,characters.clanid AS clan_id,characters.race,characters.classid AS class_id,characters.base_class,characters.title,characters.`online`,characters.onlinetime,
  129.            clan_data.clan_name,clan_data.clan_level,clan_data.hasCastle,clan_data.ally_id,clan_data.ally_name,clan_data.leader_id,clan_data.crest_id,clan_data.crest_large_id,clan_data.ally_crest_id');
  130.  
  131.         $this->db->join('clan_data', 'characters.clanid = clan_data.clan_id', 'left');
  132.  
  133.         if($limit == 1)
  134.         {
  135.             return $this->db->get('characters')->row_array();
  136.         }
  137.  
  138.         return $this->db->get('characters')->result_array();
  139.     }
  140.  
  141.     public function get_characters_by_login($login, $limit = NULL, $offset = NULL)
  142.     {
  143.         $where          = NULL;
  144.         $where_in_field = 'account_name';
  145.         $where_in       = NULL;
  146.  
  147.         if(is_array($login))
  148.         {
  149.             $where_in = $login;
  150.         }
  151.         else
  152.         {
  153.             $where = array('account_name' => $login);
  154.         }
  155.  
  156.         return $this->get_characters($limit, $offset, $where, NULL, NULL, NULL, NULL, $where_in_field, $where_in);
  157.     }
  158.  
  159.     public function change_password_on_account($password, $login)
  160.     {
  161.         return $this->db->update('accounts', array('password' => $password), array('login' => $login), 1);
  162.     }
  163.  
  164.     public function get_character_by_char_id($char_id)
  165.     {
  166.         return $this->get_characters(1, NULL, array($this->char_id => $char_id));
  167.     }
  168.  
  169.     public function change_coordinates($data, $char_id)
  170.     {
  171.         return $this->db->update('characters', $data, array($this->char_id => $char_id), 1);
  172.     }
  173.  
  174.     public function insert_item($item_id, $count, $char_id, $enchant = 0, $loc = 'INVENTORY')
  175.     {
  176.         $this->db->select_max('object_id', 'max_id');
  177.         $max_id = $this->db->get('items', 1)->row_array();
  178.  
  179.         $data_db = array(
  180.             'owner_id'      => $char_id,
  181.             'object_id'     => $max_id['max_id'] + 1,
  182.             'item_id'       => $item_id,
  183.             'count'         => $count,
  184.             'enchant_level' => (int) $enchant,
  185.             'loc'           => $loc,
  186.             'loc_data'      => '0',
  187.         );
  188.  
  189.         return $this->db->insert('items', $data_db);
  190.     }
  191.  
  192.     public function edit_item($object_id, $count, $char_id, $enchant = 0, $loc = 'INVENTORY')
  193.     {
  194.         $data_db_where = array(
  195.             'owner_id'  => $char_id,
  196.             'object_id' => $object_id,
  197.         );
  198.  
  199.         $data_db = array(
  200.             'count'         => $count,
  201.             'enchant_level' => (int) $enchant,
  202.             'loc'           => $loc,
  203.             'loc_data'      => '0',
  204.         );
  205.  
  206.         return $this->db->update('items', $data_db, $data_db_where, 1);
  207.     }
  208.  
  209.     public function del_item($item_id, $limit)
  210.     {
  211.         if(is_array($item_id))
  212.         {
  213.             $this->db->where($item_id);
  214.         }
  215.         else
  216.         {
  217.             $this->db->where('object_id', $item_id);
  218.         }
  219.  
  220.         $this->db->limit($limit);
  221.         return $this->db->delete('items');
  222.     }
  223.  
  224.     public function del_items_by_owner_id($owner_id)
  225.     {
  226.         return $this->db->delete('items', array('owner_id' => $owner_id));
  227.     }
  228.  
  229.     public function get_character_item_by_item_id($char_id, $item_id)
  230.     {
  231.         $data_db_where = array(
  232.             'owner_id' => $char_id,
  233.             'item_id'  => $item_id
  234.         );
  235.  
  236.         return $this->get_character_items(1, 0, $data_db_where);
  237.     }
  238.  
  239.     public function get_online_status($char_id)
  240.     {
  241.         $res = $this->get_characters(1, NULL, array($this->char_id => $char_id));
  242.  
  243.         return $res['online'];
  244.     }
  245.  
  246.     public function get_count_online()
  247.     {
  248.         return $this->get_count_row(array('online' => '1'), NULL, 'characters');
  249.     }
  250.  
  251.     public function get_count_accounts(array $where = NULL, array $like = NULL)
  252.     {
  253.         return $this->get_count_row($where, $like, 'accounts');
  254.     }
  255.  
  256.     public function get_count_characters(array $where = NULL, array $like = NULL)
  257.     {
  258.         return $this->get_count_row($where, $like, 'characters');
  259.     }
  260.  
  261.     public function get_count_clans(array $where = NULL, array $like = NULL)
  262.     {
  263.         return $this->get_count_row($where, $like, 'clan_data');
  264.     }
  265.  
  266.     public function get_count_male()
  267.     {
  268.         return $this->get_count_row(array('sex' => '0'), NULL, 'characters');
  269.     }
  270.  
  271.     public function get_count_female()
  272.     {
  273.         return $this->get_count_row(array('sex' => '1'), NULL, 'characters');
  274.     }
  275.  
  276.     public function get_count_race_by_id($race_id)
  277.     {
  278.         return $this->get_count_row(array('race' => $race_id), NULL, 'characters');
  279.     }
  280.  
  281.     public function get_count_races_group_race()
  282.     {
  283.         $this->db->select('race,SUM(characters.`online`) as `online`,COUNT(race) as `count`');
  284.         $this->db->where_in('race', range(0, 5));
  285.         $this->db->group_by('race');
  286.         return $this->db->get('characters')
  287.             ->result_array();
  288.     }
  289.  
  290.     public function get_top_pvp($limit = NULL)
  291.     {
  292.         return $this->get_characters($limit, NULL, array('pvpkills >' => '0'), 'pvpkills', 'desc');
  293.     }
  294.  
  295.     public function get_top_pk($limit = NULL)
  296.     {
  297.         return $this->get_characters($limit, NULL, array('pkkills >' => '0'), 'pkkills', 'desc');
  298.     }
  299.  
  300.     public function get_top_clans($limit = NULL)
  301.     {
  302.         return $this->db->select('clan_data.clan_id,clan_data.clan_name,clan_data.clan_level,clan_data.hasCastle,clan_data.ally_id,clan_data.ally_name,clan_data.leader_id,clan_data.crest_id,clan_data.crest_large_id,clan_data.ally_crest_id,characters.account_name,
  303.            characters.charId AS char_id,characters.char_name,characters.`level`,characters.maxHp,characters.curHp,characters.maxCp,characters.curCp,characters.maxMp,characters.curMp,characters.sex,characters.x,characters.z,characters.y,characters.exp,
  304.            characters.sp,characters.karma,characters.pvpkills,characters.pkkills,characters.clanid AS clan_id,characters.race,characters.classid AS class_id,characters.base_class,characters.title,characters.`online`,characters.onlinetime,(SELECT COUNT(0) FROM `characters` WHERE clanid = `clan_data`.`clan_id`) AS ccount')
  305.  
  306.             ->join('characters', 'clan_data.leader_id = characters.' . $this->char_id, 'left')
  307.  
  308.             ->group_by('characters.charId')
  309.             ->order_by('clan_data.clan_level', 'DESC')
  310.             ->order_by('clan_data.reputation_score', 'DESC')
  311.             ->limit($limit)
  312.             ->get('clan_data')
  313.             ->result_array();
  314.     }
  315.  
  316.     public function get_top_online($limit = 10)
  317.     {
  318.         return $this->get_characters($limit, NULL, array('online' => '1'), 'level', 'desc');
  319.     }
  320.  
  321.     public function get_top($limit = 10)
  322.     {
  323.         return $this->get_characters($limit, NULL,  NULL, 'exp', 'desc');
  324.     }
  325.  
  326.     public function get_top_rich($limit = 10)
  327.     {
  328.         $this->db->select('characters.account_name,characters.charId AS char_id,characters.char_name,characters.`level`,characters.maxHp,characters.curHp,characters.maxCp,characters.curCp,characters.maxMp,
  329.            characters.curMp,characters.sex,characters.x,characters.y,characters.z,characters.exp,characters.sp,characters.karma,characters.pvpkills,characters.pkkills,characters.clanid AS clan_id,
  330.            characters.race,characters.classid AS class_id,characters.base_class,characters.title,characters.`online`,characters.onlinetime,clan_data.clan_level,clan_data.hasCastle,
  331.            clan_data.ally_id,clan_data.ally_name,clan_data.leader_id,clan_data.crest_id,clan_data.crest_large_id,clan_data.ally_crest_id,clan_data.clan_name,SUM(items.count) as adena');
  332.  
  333.         $this->db->order_by('adena', 'desc');
  334.         $this->db->group_by('characters.' . $this->char_id);
  335.         $this->db->where('items.item_id', '57');
  336.  
  337.         $this->db->join('clan_data', 'characters.clanid = clan_data.clan_id', 'left');
  338.         $this->db->join('items', 'characters.' . $this->char_id . ' = items.owner_id', 'left');
  339.  
  340.         return $this->db->get('characters', $limit)
  341.             ->result_array();
  342.     }
  343.  
  344.     public function get_castles()
  345.     {
  346.         $this->db->select('castle.id,castle.`name`,castle.taxPercent,castle.siegeDate,clan_data.clan_id,clan_data.clan_name,clan_data.clan_level,clan_data.hasCastle,clan_data.ally_id,
  347.            clan_data.ally_name,clan_data.leader_id,clan_data.crest_id,clan_data.crest_large_id,clan_data.ally_crest_id');
  348.  
  349.         $this->db->join('clan_data', 'castle.id = clan_data.hasCastle', 'left');
  350.         $this->db->order_by('castle.id');
  351.  
  352.         return $this->db->get('castle')
  353.             ->result_array();
  354.     }
  355.  
  356.     public function get_siege()
  357.     {
  358.         $this->db->select('siege_clans.castle_id,siege_clans.clan_id,siege_clans.type,siege_clans.castle_owner,clan_data.clan_id,clan_data.clan_name,clan_data.clan_level,clan_data.hasCastle,
  359.            clan_data.ally_id,clan_data.ally_name,clan_data.leader_id,clan_data.crest_id,clan_data.crest_large_id,clan_data.ally_crest_id');
  360.  
  361.         $this->db->where_in('castle_id', range(1, 9));
  362.         $this->db->join('clan_data', 'clan_data.clan_id = siege_clans.clan_id', 'left');
  363.  
  364.         return $this->db->get('siege_clans')
  365.             ->result_array();
  366.     }
  367.  
  368.     public function get_clan_by_id($clan_id)
  369.     {
  370.         $this->db->select('clan_name,clan_level,hasCastle,leader_id,crest_id,crest_large_id,clan_id');
  371.         $this->db->where('clan_id', $clan_id);
  372.  
  373.         return $this->db->get('clan_data')
  374.             ->row_array();
  375.     }
  376.  
  377.     public function get_characters_by_clan_id($clan_id, $limit = 10)
  378.     {
  379.         return $this->get_characters($limit, NULL, array('clanid' => $clan_id), 'level', 'desc');
  380.     }
  381.  
  382.     public function get_count_character_items($char_id)
  383.     {
  384.         return $this->get_count_row(array('owner_id' => $char_id), NULL, 'items');
  385.     }
  386.  
  387.     public function get_character_items_by_char_id($char_id)
  388.     {
  389.         return $this->get_character_items(NULL, NULL, array('owner_id' => $char_id), 'count', 'desc');
  390.     }
  391.  
  392.     public function get_character_items($limit = NULL, $offset = NULL, array $where = NULL, $order_by = NULL, $order_type = 'asc', array $like = NULL, array $group_by = NULL, $where_in_field = NULL, array $where_in = NULL)
  393.     {
  394.         if(is_numeric($limit))
  395.         {
  396.             $this->db->limit($limit);
  397.         }
  398.  
  399.         if(is_numeric($offset))
  400.         {
  401.             $this->db->offset($offset);
  402.         }
  403.  
  404.         if($where != NULL)
  405.         {
  406.             $this->db->where($where);
  407.         }
  408.  
  409.         if($order_by != NULL)
  410.         {
  411.             $this->db->order_by($order_by, $order_type);
  412.         }
  413.  
  414.         if($like != NULL)
  415.         {
  416.             $this->db->like($like);
  417.         }
  418.  
  419.         if($group_by != NULL)
  420.         {
  421.             $this->db->group_by($group_by);
  422.         }
  423.  
  424.         if($where_in_field != NULL && $where_in != NULL)
  425.         {
  426.             $this->db->where_in($where_in_field, $where_in);
  427.         }
  428.  
  429.         $this->db->select('owner_id,object_id,item_id,count,enchant_level,loc,loc_data');
  430.  
  431.         if($limit == 1)
  432.         {
  433.             return $this->db->get('items')->row_array();
  434.         }
  435.  
  436.         return $this->db->get('items')->result_array();
  437.     }
  438.  
  439.     private function get_count_row(array $where = NULL, array $like = NULL, $table)
  440.     {
  441.         if($where != NULL)
  442.         {
  443.             $this->db->where($where);
  444.         }
  445.  
  446.         if($like != NULL)
  447.         {
  448.             $this->db->like($like);
  449.         }
  450.  
  451.         $this->db->from($table);
  452.         return $this->db->count_all_results();
  453.     }
  454.  
  455.     public function change_char_name($char_id, $char_name)
  456.     {
  457.         return $this->db->update('characters', array('char_name' => $char_name), array($this->char_id => $char_id), 1);
  458.     }
  459.  
  460.     public function change_sex($char_id, $sex)
  461.     {
  462.         return $this->db->update('characters', array('sex' => $sex), array($this->char_id => $char_id), 1);
  463.     }
  464.  
  465.     public function get_character_by_char_name($char_name)
  466.     {
  467.         $data_db_where = array(
  468.             'char_name' => $char_name,
  469.         );
  470.  
  471.         return $this->get_characters(1, NULL, $data_db_where);
  472.     }
  473.  
  474.     public function change_account_password($login, $new_password)
  475.     {
  476.         $data_db = array(
  477.             'login' => $login,
  478.         );
  479.  
  480.         $data_db_where = array(
  481.             'password' => $new_password,
  482.         );
  483.  
  484.         return $this->db->update('accounts', $data_db_where, $data_db, 1);
  485.     }
  486. }
Advertisement
Add Comment
Please, Sign In to add comment