Example #1
0
 protected function db($db = '')
 {
     if (!$db) {
         $db = $this->db;
     }
     return Com_Db::factory($db);
 }
Example #2
0
 public function run()
 {
     $sessions = $this->redis()->keys("sess:sid:*");
     $online_num = count($sessions);
     #临时
     $cc = shell_exec("netstat -natp |grep :19707 |grep -c ESTABLISHED");
     $cc = trim($cc);
     $online_num = (int) $cc;
     #
     $ip = array();
     if ($sessions) {
         foreach ($sessions as $val) {
             $data = $this->redis()->hash_get($val);
             $ip[$data['client_ip']] = 1;
         }
     }
     #上报在线人数
     $arrData = array();
     $arrData['gameid'] = GAME_ID;
     $arrData['type'] = 'online';
     $arrData['appid'] = 3248;
     $arrData['appkey'] = 'd2f83a02a38e0a7c027b8bc7dccf4628';
     $arrData['timeline'] = time();
     $arrData['value'][] = array('opid' => OPERATOR_ID, 'server' => SERVER_ID ? SERVER_ID : 0, 'area' => AREA_ID ? AREA_ID : 0, 'value' => $online_num);
     $url = "http://monitor.uuzuonline.com/onlineReport";
     Com_System::open_url($url, 'post', json_encode(array($arrData)));
     $ip_num = count($ip);
     $now = time();
     $sql = "INSERT INTO `log_online` (`num`, `ip_num`, `add_time`) VALUES ( '{$online_num}', '{$ip_num}', '{$now}')";
     $result = Com_Db::factory('log')->query($sql);
     echo "time:{$now} result:" . var_export($result, true) . "\n";
     Com_DataCenter::getInstance()->publish_data(0, 'ser', array('time' => $now, 'online_num' => $online_num));
 }
Example #3
0
 public static function close()
 {
     foreach (self::$_dbs as $k => $db) {
         //	$db->free();
         $db->close();
     }
     self::$_dbs = array();
 }
Example #4
0
 /**
  * 释放所有DB连接
  *
  * @return void
  */
 public static function disconnect()
 {
     if (self::$_dbs && is_array(self::$_dbs)) {
         foreach (self::$_dbs as $db) {
             $db->disconnect();
         }
         self::$_dbs = null;
     }
 }
Example #5
0
 protected function db()
 {
     if (!isset($this->_dbs[$this->_dbName])) {
         if (!$this->_dbName) {
             throws(get_class($this) . ' 没有定义数据库,无法使用 Com_Dao', 'sql');
         }
         $this->_dbs[$this->_dbName] = Com_Db::get($this->_dbName);
     }
     return $this->_dbs[$this->_dbName];
 }
Example #6
0
    define("STDIN", fopen('php://stdin', 'r'));
}
require dirname(__FILE__) . '/../global.php';
TenYear::getInstance();
// || strtotime(SERVER_START_TIME) < $time
$time = time();
echo "当前服务器开服时间为" . SERVER_FIRST_START_TIME . ",请先检测是否修改Gm后台开服时间,同时检查是否设置正确数据中心配置! 如果正确请输入 yes进行清档 | no退出\n";
fscanf(STDIN, "%s", $input);
if ($input != 'yes') {
    exit;
}
if (strtotime(SERVER_FIRST_START_TIME) < $time) {
    exit("请先检测是否修改Gm后台开服时间, 同时检查是否设置正确数据中心配置!\n");
}
$dbConfig = TenYear::get_val('dbConfig');
$db = Com_Db::factory('game');
$db->query("select count(*) pnum from player");
if ($db->nextrecord()) {
    $pData = $db->record;
    $playerNum = $pData['pnum'];
} else {
    $playerNum = 0;
}
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)) {
Example #7
0
//初始化数据库
foreach($files as $base => $file){
	if(is_file($file)){
		echo "mysql -hlocalhost -u{$dbConfig[$base]['user']} -p{$dbConfig[$base]['pass']} -e \" use {$dbConfig[$base]['name']}; source {$file};\"\n";
		shell_exec("mysql -hlocalhost -u{$dbConfig[$base]['user']} -p{$dbConfig[$base]['pass']} -e \" use {$dbConfig[$base]['name']}; source {$file};\"");
	}
}
sleep(1);
*/
//初始化随机姓名库
// shell_exea("/usr/local/webserver/php/bin/php " . CRONTAB_PATH.'/Player/Name.php');
require CRONTAB_PATH . '/Player/PlayerNameBase.php';
$objName = new Player_PlayerNameBase();
$objName->start();
//同步黑白名单
$db_global = Com_Db::factory('global_game');
$db_global->query("select * from global_ip where id =1");
$ip_white = "";
$ip_black = "";
if ($db_global->nextrecord()) {
    $pData = $db_global->record;
    $ip_white = $pData['ip_white'];
    $ip_black = $pData['ip_black'];
}
file_put_contents($logFile, "获取黑白名单 white:" . $ip_white . " black:" . $ip_black . "···\n", FILE_APPEND);
Com_AdCache::factory()->hash_set('data|server_status', 'status', "0");
Com_AdCache::factory()->hash_set('data|server_status', 'black_id', $ip_black);
Com_AdCache::factory()->hash_set('data|server_status', 'write_ip', $ip_white);
# ----------------------------------------------------------------------------
# 生成天梯与竞技场假人数据
# ----------------------------------------------------------------------------
Example #8
0
 protected function rollback()
 {
     return Com_Db::factory($this->db)->rollback();
 }
Example #9
0
 public function db_close()
 {
     Com_Db::close();
 }
Example #10
0
 protected function db()
 {
     return Com_Db::factory('cross');
 }
Example #11
0
 /**
  * 把带参数的 SQL 的转换为可记录的 Log
  *
  * @param string $sql
  * @param array $params
  * @return string
  */
 protected function _formatLogSql($sql, $params)
 {
     return array('sql' => $sql, 'params' => $params, 'realSql' => Com_Db::getRealSql($sql, $params), 'host' => isset($this->_db->dsn['host']) ? $this->_db->dsn['host'] : '', 'dbName' => isset($this->_db->dsn['path']) ? $this->_db->dsn['path'] : '');
 }
Example #12
0
 /**
  * 从所有队列接收消息
  *
  */
 public static function receive_all($force = false)
 {
     //需要强制执行超时回调者
     $forceCalls = array();
     foreach (self::$queues as $queue => $forceTime) {
         if ($forceTime) {
             $forceCalls[$queue] = 0;
         }
     }
     $queues = array_keys(self::$queues);
     $start_time = time();
     if ($force) {
         self::$waittime = 1;
     }
     while (true) {
         //			Com_Db::ping();
         Com_Db::factory('game')->clear_trans();
         //	echo "get ".var_export($queues,true)." queues | wailt ".self::$waittime."\r\n";
         $return = Com_AdCache::factory(self::$group)->brPop($queues, self::$waittime);
         if (empty($return)) {
             if ($force) {
                 break;
             }
             if (empty($forceCalls)) {
                 continue;
             } else {
                 $exec_time = time();
                 $run_time = $exec_time - $start_time;
                 $start_time = $exec_time;
                 foreach ($forceCalls as $queue => $forceTime) {
                     $forceCalls[$queue] += $run_time;
                     echo "{$queue} now wait time {$forceCalls[$queue]}\r\n";
                     //当前无消息时 会根据次数强制回调注册方法
                     if ($forceCalls[$queue] >= self::$queues[$queue]) {
                         $forceCalls[$queue] = 0;
                         echo "force call func {$queue}\r\n";
                         call_user_func_array(self::$callBacks[$queue], array());
                         //	break;
                     }
                 }
                 continue;
             }
         }
         if (isset($forceCalls[$return[0]])) {
             $forceCalls[$return[0]] = 0;
         }
         echo "receive call func {$return[0]} time=" . date('Y-m-d H:i:s', time()) . "\r\n";
         $callstarttime = microtime(true);
         call_user_func_array(self::$callBacks[$return[0]], array($return[1]));
         echo "call func run " . (microtime(true) - $callstarttime) . "\n";
     }
 }
Example #13
0
 /**
  * 预处理队列回调方法
  * @param $data
  */
 public function do_async_online_stat($data)
 {
     if (empty($data)) {
         return;
     }
     $data = json_decode($data, true);
     #上报在线人数
     $arrData = array();
     $arrData['gameid'] = GAME_ID;
     $arrData['type'] = 'online';
     $arrData['appid'] = 3248;
     $arrData['appkey'] = 'd2f83a02a38e0a7c027b8bc7dccf4628';
     $arrData['timeline'] = $data['add_time'];
     $arrData['value'][] = array('opid' => OPERATOR_ID, 'server' => SERVER_ID ? SERVER_ID : 0, 'area' => AREA_ID ? AREA_ID : 0, 'value' => $data['num']);
     $url = "http://monitor.uuzuonline.com/onlineReport";
     Com_System::open_url($url, 'post', json_encode(array($arrData)));
     $sql = "INSERT INTO `log_online` (`num`, `ip_num`, `add_time`) VALUES ( '" . $data['num'] . "', '" . $data['ip_num'] . "', '" . $data['add_time'] . "')";
     $result = Com_Db::factory('log')->query($sql);
 }
Example #14
0
    public static function insert_to_mysql($log_string)
    {
        if (empty($log_string)) {
            return false;
        }
        $log_arr = explode("\t", $log_string);
        $sql = <<<SQL
\t\tinsert into log_economy (player_id, timestamp, player_name, user_account, cmd0, cmd1, cmd2, json_content) 
\t\tvalues ({$log_arr['1']}, {$log_arr['2']}, '', '', {$log_arr['3']}, {$log_arr['4']}, {$log_arr['5']}, '{$log_arr['6']}')
SQL;
        $ret = Com_Db::factory('log')->query($sql);
        # 插入失败,记入失败日志,尽管mysqlerror.log中已有错误记录,此处单独将日志漏记数据保存
        if ($ret === false) {
        }
        return $ret;
    }
Example #15
0
 public static function bg_insert($sql = '')
 {
     if (!$sql) {
         echo 'continue';
         return;
     }
     if (!Com_Db::factory('game')->query($sql)) {
         self::backup($sql);
     } else {
         self::backup($sql, 'sucess');
     }
 }
Example #16
0
 public function run()
 {
     $achieve_configs = Cache_AchieveConfig::getInstance()->get_achieve_config();
     $arr_ids = array();
     foreach ($achieve_configs as $value) {
         $arr_ids[] = $value['achieve_id'];
     }
     $this->_achieve_ids = $arr_ids;
     $this->db = Com_Db::factory('game');
     while (true) {
         $begin_time = time();
         $player_list = $this->get_data('Online')->get_online_list();
         if (empty($player_list)) {
             sleep($this->_sleep_time);
             //waiting
             continue;
         }
         $this->arr_union_ids = array();
         $this->arr_player_union = array();
         $time = $this->get_data('Online')->get_backup_time();
         if ($time) {
             $logout_start_time = $time - $this->_offset_time;
         } else {
             $logout_start_time = $begin_time - $this->_offset_time;
         }
         foreach ($player_list as $player_id => $v) {
             if (empty($player_id)) {
                 continue;
             }
             if (1 == $v) {
                 continue;
             }
             $arr_time = json_decode($v, true);
             if ($arr_time['login_time'] > $arr_time['logout_time'] || $arr_time['logout_time'] >= $logout_start_time) {
                 $this->db->start_trans();
                 try {
                     if (!$this->backup($player_id)) {
                         throw new Exception('error1!');
                     }
                     if (!$this->backup_player_tables($player_id)) {
                         throw new Exception('error2!');
                     }
                     $this->db->commit();
                 } catch (Exception $e) {
                     $this->db->rollback();
                 }
             } else {
                 unset($player_list[$player_id]);
             }
             unset($arr_time);
         }
         sleep(1);
         //waiting
         foreach ($this->arr_union_ids as $union_id => $v) {
             if (!$union_id) {
                 continue;
             }
             $this->db->start_trans();
             try {
                 if (!$this->backup_union($union_id)) {
                     throw new Exception('error3!');
                 }
                 if (!$this->backup_union_tables($union_id)) {
                     throw new Exception('error4!');
                 }
                 $this->db->commit();
             } catch (Exception $e) {
                 $this->db->rollback();
             }
         }
         //单独处理
         $this->backup_alone();
         $end_time = time();
         $used_time = $end_time - $begin_time;
         $this->get_data('Online')->set_backup_time($begin_time);
         if (!$time) {
             sleep($this->_delay_time);
             //waiting
         } else {
             sleep($this->_sleep_time);
             //waiting
         }
         echo "sync end!";
     }
 }