public static function factory($db = 'game', $reload = false, $remote_settings = array()) { if (!isset(self::$_dbs[$db]) || $reload) { $dbConfig = TenYear::get_val('dbConfig'); switch ($db) { case 'setting': self::$_dbs[$db] = new DbClient($dbConfig['setting']['host'], $dbConfig['setting']['user'], $dbConfig['setting']['pass'], $dbConfig['setting']['name'], $dbConfig['pconnect']); break; case 'game': self::$_dbs[$db] = new DbClient($dbConfig['game']['host'], $dbConfig['game']['user'], $dbConfig['game']['pass'], $dbConfig['game']['name'], $dbConfig['pconnect']); break; case 'log': self::$_dbs[$db] = new DbClient($dbConfig['log']['host'], $dbConfig['log']['user'], $dbConfig['log']['pass'], $dbConfig['log']['name'], $dbConfig['pconnect']); break; case 'cross': // 跨服配置 self::$_dbs[$db] = new DbClient($dbConfig['cross']['host'], $dbConfig['cross']['user'], $dbConfig['cross']['pass'], $dbConfig['cross']['name'], $dbConfig['pconnect']); break; case 'global_game': #全局playerid self::$_dbs[$db] = new DbClient($dbConfig['global_game']['host'], $dbConfig['global_game']['user'], $dbConfig['global_game']['pass'], $dbConfig['global_game']['name'], $dbConfig['pconnect']); break; default: return false; } } return self::$_dbs[$db]; }
public static function getMongoUtilObject() { $mongoConfig = TenYear::get_val('mongoConfig'); $config = array('host' => $mongoConfig['host'], 'port' => $mongoConfig['port'], 'option' => array('connect' => true), 'db_name' => $mongoConfig['db'], 'username' => $mongoConfig['user'], 'password' => $mongoConfig['pass']); $mongoUtilObj = new MongoUtil(); $mongoUtilObj->init($config); $mongoUtilObj->selectCollection($mongoConfig['collection']); return $mongoUtilObj; }
public static function factory($group = 'game', $reload = false) { if (!REDIS_CLUSTER) { $group = 'game'; } if (!isset(self::$_cache[$group]) || $reload) { $settings = TenYear::get_val('redisConfig'); if (empty($settings) || !isset($settings[$group])) { return false; } self::$_cache[$group] = new RedisClient($settings[$group]); } return self::$_cache[$group]; }
public static function factory($group = 'setting', $reload = false) { if (!isset(self::$_mems[$group]) || $reload) { if (isset(self::$_mems[$group])) { unset(self::$_mems[$group]); } $settings = TenYear::get_val('memcachedConfig'); if (!isset($settings[$group])) { // return false; } self::$_mems[$group] = new MMemcached($settings, $group); } return self::$_mems[$group]; }
public function flush_memcache() { $settings = TenYear::get_val('memcachedConfig'); #var_export($settings); if (!empty($settings['game']['host']) && !empty($settings['game']['port'])) { $cmd = "echo 'flush_all' | nc {$settings['game']['host']} {$settings['game']['port']}"; echo "{$cmd} ...\n"; $last_line = system($cmd, $retval); if ($retval !== 0) { $this->throw_exception(array('message' => 'Failed to flush memcache ...', 'code' => 3)); } } else { $this->throw_exception(array('message' => 'Failed to get memcache configuration ...', 'code' => 4)); } }
public function update_day() { if (!Com_Db::factory($this->db)->ping()) { echo "ping log db fail\n"; return false; } $time = time(); $logsDir = DATA_PATH . "/logsdata"; $logsBackupDir = DATA_PATH . "/logsbackup"; $dbConfig = TenYear::get_val('dbConfig'); $dirhandle = opendir($logsDir); if ($dirhandle) { while (($file = readdir($dirhandle)) !== false) { if ($file != '.' && $file != '..') { $backfile = $logsBackupDir . '/' . $file; $file = $logsDir . '/' . $file; if (filemtime($file) < strtotime(date('Y-m-d 04:00:00', $time))) { $status = 0; $shell = "/data/mysql/bin/mysql -h{$dbConfig['log']['host']} -u{$dbConfig['log']['user']} -p{$dbConfig['log']['pass']} -e \"use {$dbConfig['log']['name']}; source {$file};\""; echo $shell . "\n"; passthru($shell, $status); if ($status == 0) { echo "source sucess\n"; unlink($file); } else { echo "source fail status {$status}\n"; if (!is_dir($logsBackupDir)) { mkdir($logsBackupDir); } shell_exec("mv {$file} {$backfile}"); echo "mv {$file} {$backfile}\n"; } } } } } }
public function clear_challenge() { $settings = TenYear::get_val('redisConfig'); if (!empty($settings['game']['host']) && !empty($settings['game']['port'])) { # 虚拟玩家存在game库的缓存域空间中 $cmd1 = "redis-cli -h {$settings['game']['host']} keys 'data|player_challenge_*' | xargs redis-cli -h {$settings['game']['host']} del"; $cmd2 = "redis-cli -h {$settings['game']['host']} set auto_challenge_rank 0"; $cmd3 = "redis-cli -h {$settings['game']['host']} set auto_challenge_battle_seq 0"; $cmd4 = "redis-cli -h {$settings['game']['host']} hset daily_time:global challenge_monster_flush_seq 0"; echo "{$cmd1} ...\n"; echo "{$cmd2} ...\n"; echo "{$cmd3} ...\n"; echo "{$cmd4} ...\n"; $last_line = system($cmd1, $retval1); $last_line = system($cmd2, $retval2); $last_line = system($cmd3, $retval3); $last_line = system($cmd4, $retval4); if ($retval1 !== 0 || $retval2 !== 0 || $retval3 !== 0 || $retval4 !== 0) { $this->throw_exception(array('message' => 'Failed to clear challenge...', 'code' => 3)); } } else { $this->throw_exception(array('message' => 'Failed to get redis configuration ...', 'code' => 4)); } }
} echo "游戏数据库:{$dbConfig['game']['name']}, 服务器id:" . SERVER_ID . ", 当前玩家数量:{$playerNum}, 确认清档请输入yes | no退出\n"; fscanf(STDIN, "%s", $input); if ($input != 'yes') { exit; } $dataFiles = array(DATA_PATH . '/cache', DATA_PATH . '/fightreport', DATA_PATH . '/logs', DATA_PATH . '/logsdata', DATA_PATH . '/replicationdata'); foreach ($dataFiles as $file) { if (!is_dir($file)) { mkdir($file, 755); } shell_exec("chown -R nobody:nobody {$file}"); sleep(1); } sleep(1); $dbConfig = TenYear::get_val('dbConfig'); $truncate_file = dirname(__FILE__) . '/../Server/truncate.sql'; if (is_file($truncate_file)) { echo "mysql -hlocalhost -u{$dbConfig['game']['user']} -p{$dbConfig['game']['pass']} -e \" use {$dbConfig['game']['name']}; source {$truncate_file};\""; shell_exec("mysql -hlocalhost -u{$dbConfig['game']['user']} -p{$dbConfig['game']['pass']} -e \" use {$dbConfig['game']['name']}; source {$truncate_file};\""); } ini_set('default_socket_timeout', -1); Com_AdCache::factory()->set_timeout(0); $auto_player_id = Com_AdCache::factory()->get('auto_player_id'); $auto_player_max_id = Com_AdCache::factory()->get('auto_player_max_id'); $auto_union_id = Com_AdCache::factory()->get('auto_union_id'); $auto_union_max_id = Com_AdCache::factory()->get('auto_union_max_id'); Com_AdCache::factory()->flushAll(); Com_AdCache::factory('queue')->flushAll(); sleep(1); if ($auto_player_id) {
/** * 获取玩家基本信息 * * @param array $objDataInfo * @return unknown */ public function get_userInfo($objDataInfo) { $page = $objDataInfo['page'] ? $objDataInfo['page'] : '1'; $page_size = $objDataInfo['page_size'] ? $objDataInfo['page_size'] : '10'; $server_id = $objDataInfo['server_id']; $player_id = $objDataInfo['player_id']; $user_account = $objDataInfo['user_account']; $name = $objDataInfo['name']; $gm = $objDataInfo['gm']; $created_at = $objDataInfo['created_at']; $cash = $objDataInfo['cash']; $vip = $objDataInfo['vip']; $level = $objDataInfo['level']; $serverId = $objDataInfo['serverId']; $condition = ''; if ($player_id) { $condition .= " player_id like '%" . $player_id . "%' AND"; } if ($user_account) { $condition .= " user_account like '%" . $user_account . "%' AND"; } if (is_numeric($gm)) { $condition .= " gm =" . $gm . " AND"; } if ($name) { $condition .= " name like '%" . $name . "%' AND"; } if ($created_at[0]) { $condition .= " reg_time >= " . strtotime($created_at[0]) . " AND"; } if ($created_at[1]) { $condition .= " reg_time <= " . strtotime($created_at[1]) . " AND"; } if ($level[0]) { $condition .= " level >= " . $level[0] . " AND"; } if ($level[1]) { $condition .= " level <= " . $level[1] . " AND"; } if ($vip[0]) { $condition .= " vip >= " . $vip[0] . " AND"; } if ($vip[1]) { $condition .= " vip <= " . $vip[1] . " AND"; } if ($condition) { $condition = 'where ' . $condition; $condition = substr($condition, 0, -3); } $page_total_num_sql = 'select count(`player_id`) as total from player ' . $condition; $page_total_num = $this->get_one($page_total_num_sql, null); $page_num = ceil($page_total_num['total'] / $page_size); $page_num_sql = 'select * from player ' . $condition . ' limit ' . ($page * $page_size - $page_size) . ',' . $page_size; $userInfoData = $this->select_all($page_num_sql); foreach ($userInfoData as $k => $v) { $data_player = $this->get_data('Player'); $player_info = $data_player->get_player_info($v['player_id']); if (!$player_info) { continue; } foreach ($player_info as $field => $val) { if (!array_key_exists($field, $v)) { continue; } if ($field == "reg_time") { $userInfoData[$k]['reg_time'] = date('Y-m-d H:i:s', $player_info['reg_time']); } elseif ($field == "login_time") { $userInfoData[$k]['login_time'] = date('Y-m-d H:i:s', $player_info['login_time']); } else { $userInfoData[$k][$field] = $val; } } /* $userInfoData[$k]['reg_time'] = date('Y-m-d H:i:s',$player_info['reg_time']); $userInfoData[$k]['login_time'] = date('Y-m-d H:i:s',$player_info['login_time']); unset($player_info['reg_time'],$player_info['login_time']); $userInfoData[$k] = $userInfoData[$k] + $player_info; */ //获取声望等级 if (isset($v['fame_level'])) { $fame_level = isset($player_info['fame_level']) ? $player_info['fame_level'] : $v['fame_level']; $fameInfo = Cache_PlayerFame::getInstance()->get_player_fame_info($fame_level); if (!empty($fameInfo)) { $userInfoData[$k]['fame_level'] = $fameInfo['title']; } else { $userInfoData[$k]['fame_level'] = '无名'; } } //VIP特权 $vip_special_info = $this->get_data('VipSpecial')->get_vip_special_info($v['player_id']); $privilege_left_date = 0; $privilege_level = 0; if (!empty($vip_special_info)) { $privilege_level = $vip_special_info['vip_special_level']; $privilege_left_date = $vip_special_info['left_date']; } $userInfoData[$k]['privilege_level'] = $privilege_level; $userInfoData[$k]['privilege_left_date'] = $privilege_left_date; //获取公会贡献值 if (!empty($player_info['union_id'])) { $gh_con = $this->get_data('UnionPlayer')->get_union_player_info($player_info['union_id'], $v['player_id']); $userInfoData[$k]['gh_con'] = $gh_con['total_dedicate']; } else { $userInfoData[$k]['gh_con'] = 0; } } $dbConfig = TenYear::get_val("dbConfig"); $tableFieldsSql = "SELECT COLUMN_NAME as `field`, COLUMN_COMMENT as `comment` FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'player' AND TABLE_SCHEMA = '" . $dbConfig["game"]["name"] . "'"; $tableFields = $this->get_list($tableFieldsSql); $fields = array(); if (!empty($tableFields)) { foreach ($tableFields as $comments) { $fields[$comments['field']] = $comments['comment']; } $fields['gh_con'] = "公会贡献值"; } $userInfoData['all_page'] = $page_total_num['total']; $userInfoData['fields'] = $fields; return $userInfoData; }
public function __construct() { $this->_settings = TenYear::get_val('remote_server'); }