public function query($str) { if (!$str || !$this->connect()) { return false; } if ($this->queryid) { $this->free(); } if ($this->trans && !$this->realTrans) { $this->start_trans(true); } $this->querystr = $str; $this->queryid = @mysql_query($this->querystr, $this->linkid); if (!$this->queryid) { $this->errstr = mysql_error(); if ($_POST['debug'] && SERVER_ID == 1 && $this->errstr) { echo '数据执行错误,请稍后重试!<br><br>'; echo '<font color="#ffffff">' . "sql: " . $this->querystr . '</font><br>'; echo '<font color="#ffffff">' . "mysql error: " . $this->errstr . '</font>'; } $error_front = IS_FRONT ? 1 : 0; $error_db = $this->database; $error_debug = ''; $error_file = $_SERVER['SCRIPT_FILENAME']; file_put_contents(LOG_PATH . '/mysqlerror.log', "[" . date("Y-m-d H:i:s") . "]errno:" . mysql_errno() . ";error:{$this->errstr};sql:{$this->querystr};File:{$error_file};Front:{$error_front};DB:{$error_db};debug:{$error_debug}\n", FILE_APPEND); if ($this->errstr == 'MySQL server has gone away') { $this->close(); if (!IS_FRONT) { Com_Log::log('MySQL server has gone away, reTry to query' . $str, 'mysqlgoneaway', 1); return $this->query($str); } } else { if (!IS_FRONT && $this->ping()) { // 后端进程则PING后再试一次 $this->queryid = mysql_query($this->querystr, $this->linkid); if ($this->queryid) { return $this->queryid; } } } return false; } return $this->queryid; }
/** * 过期红包清除 * @param unknown $union_id */ public function expire_red_envelopes($player_id, $union_id) { Com_Log::log($union_id, 'expire_red_envelopes.log', 1); $player_id = intval($player_id); $union_id = intval($union_id); //加锁 if (!Com_Lock::lock('lock|union_player|expire_red_envelopes|union_id=' . $union_id)) { //系统繁忙 return array(50401, $union_id); } $objRedEnvelopesData = $this->get_data('UnionRedEnvelopes'); $redEnvelopesInfo = $objRedEnvelopesData->get_union_red_envelopes_info($union_id); if (empty($redEnvelopesInfo)) { return array(50403, $union_id); } if (intval($redEnvelopesInfo['player_id']) != $player_id) { return array(50405, $union_id); } $objRedReceiveData = $this->get_data('UnionReceiveRedEnvelopes'); $redReceiveInfo = $objRedReceiveData->get_receive_red_envelopes_info($union_id); $revert_gold = 0; if ($redEnvelopesInfo['red_envelopes']) { foreach ($redEnvelopesInfo['red_envelopes'] as $val) { if (!isset($redReceiveInfo[$val['sid']])) { $revert_gold += $val['gold']; } else { $receive_gold = intval($val['gold']); $redReceiveInfo[$val['sid']]['gold'] = $receive_gold; } } } if ($revert_gold > 0 && time() < $redEnvelopesInfo['add_time'] + $this->red_packet_duration) { return array(50404, $union_id); } $this->start_trans(); $redEnvelopesInfo['union_id'] = $union_id; $retMail = true; if ($revert_gold) { $phrase_config = Cache_FuncPhraseConfig::getInstance()->get_phrase_config_info(9004); $attachment = array(); $attachment[] = array('prop_id' => 2, 'prop_num' => $revert_gold); $retMail = $this->get_game('Mail')->async_trigger_mail($player_id, $phrase_config['title'], $phrase_config['content'], $attachment, $phrase_config['sender'], 1, 503); } $retReceiveRedEnvelopes = $objRedReceiveData->delete_receive_red_envelopes($union_id); $retRedEnvelopes = $objRedEnvelopesData->delete_red_envelopes($union_id); if ($retReceiveRedEnvelopes && $retRedEnvelopes && $retMail) { $this->commit(); $this->get_game('Union')->Sync_Union_msg($union_id); if ($revert_gold < $redEnvelopesInfo['send_gold']) { $this->sys_add_red_envelopes_his($redEnvelopesInfo, $redReceiveInfo); } } else { $this->rollback(); return array(50406, $union_id); } return array(0, $union_id); }
protected function log($msg) { Com_Log::log($msg, 'memcache', 1); }
protected function log($message) { Com_Log::log($message, 'redis', 1); }
/** * 主动向指定玩家抛出异常 * @param $player_id 玩家ID * @param $data 错误得id 或一个错误得数组 * @param $is_exit 抛出异常是否终止逻辑继续执行(true:终止false:继续) */ protected function initiative_throw_error($player_id, $data, $is_exit = true) { if ($this->is_trans()) { $this->rollback(); } Com_Lock::unLock(); if (is_array($data)) { $msg = Language_Message::make_message($data['code'], $data['params'], 1, $data['content']); } else { $msg = Language_Message::make_message($data); } Com_Log::log($player_id, 'z_fb_res', 1); Com_Log::log(array(0 => array($msg)), 'z_fb_res', 1); Protocol::input($player_id, 8, 7, 742, array(0 => array($msg))); Protocol::out(); if ($is_exit) { exit; } }
public function do_sys_set_data($data) { if (empty($data)) { return; } $data = json_decode($data, true); Com_Log::log($data, 'like_news.log', 1); $friend_id = intval($data['friend_id']); $objlike = $this->get_data('PlayerLike'); $objfrined = $this->get_data('PlayerFriend'); $objtips = $this->get_data('NewsTips'); $objplayer = $this->get_data('Player'); $friend_basic_info = $objplayer->get_player_info($friend_id, array('vip', 'level_exp', 'name', 'like_times')); $like_max_times = $this->like_default_times; #vip点赞与被点赞总次数增加 if (intval($friend_basic_info['vip']) > 0) { $vip_set = Cache_VipLevelLimit::getInstance()->get_limit_info($friend_basic_info['vip'], 10069); $like_max_times = $this->like_default_times + $vip_set['max_times']; } $friend_data = $objfrined->get_player_friend($friend_id, array('like_times')); #今日点赞与被点次数 if ($friend_data['like_times']['today_times'] + $friend_data['like_times']['today_like_friend_times'] >= $like_max_times) { return false; } $friend_add_exp = $this->add_default_exp; $this->start_trans(); #被点赞今日次数增加 $friend_data['like_times']['upts'] = time(); $friend_data['like_times']['today_times'] += 1; $friend_ret = $objfrined->update_player_friend($friend_id, $friend_data); if (!$friend_ret) { return false; } #被点赞总次数增加 $friend_basic_info['like_times'] += 1; $ret_friend_basic = $objplayer->update_player_info($friend_id, $friend_basic_info); if (!$ret_friend_basic) { return false; } #被点赞奖励消息详细 $language_config = Cache_Language::getInstance()->get_language_info(71612); $content = sprintf($language_config['content'], $friend_add_exp); $content = "<FONT COLOR='#c6c6c6'> {$content}</FONT>"; $set_like_data = array('news_id' => $data['news_id'], 'player_id' => $data['player_id'], 'exp' => $friend_add_exp, 'name' => $data['name'], 'content' => $content, 'create_time' => time()); $sid = $data['news_id'] . $data['player_id']; $ret_like = $objlike->update_like_data_by_likeid($friend_id, $sid, $set_like_data); if (!$ret_like) { return false; } #被点赞奖励提醒数量更新 $set_tips_data = $objtips->get_player_newstips($friend_id, self::$_like_tips_type); $set_tips_data['num'] += 1; $ret_tips = $objtips->update_player_tips($friend_id, self::$_like_tips_type, $set_tips_data); if (!$ret_tips) { return false; } $this->commit(); #提醒被点赞数量 $objtips->push_player_tips($friend_id, self::$_like_tips_type); if (!IS_FRONT) { Protocol::out(); } return true; }
/** * 删除一周前动态 * return array */ public function del_his_player_news() { $sql = sprintf("select count(*) counts from `player_friend_news` where `create_time`<%d", time() - 86400); $data = $this->select_one($sql); $counts = intval($data['counts']); if ($counts > 1) { //避免数据太大,分批次删除 $times = $counts > 5000 ? ceil($counts / 5000) : 1; for ($i = 1; $i <= $times; $i++) { $delSql = sprintf("delete from `player_friend_news` where `create_time`< %d limit 5000", time() - 86400); $this->query($delSql); usleep(300); } Com_Log::log($delSql, 'player_friend.log', 1); } return true; }
/** * @Purpose: * 创建单个翅膀数据 * @Param $player_id 玩家ID * @Param $wing_id 翅膀ID */ private function create_wing($data) { $id = $data['id']; $wing['id'] = $data['id']; $wing['lvl'] = $data['level']; $wing['attr'] = $this->format_table_field($data['attr_add']); Com_Log::log("{$wing['id']} wing fight attr :" . var_export($wing['attr'], true), 'wing_fight', 1); $wing['fight'] = Formula_Fpower::calc_fpower($wing['attr']); Com_Log::log("{$wing['id']} wing fight base :{$wing['fight']}", 'wing_fight', 1); //技能分解 $skill_data = explode("|", $data['skill_id']); $wing['skill_id'] = $skill_data; #翅膀技能加上战力 if (is_array($wing['skill_id'])) { foreach ($wing['skill_id'] as $skill_id) { $max_level = Cache_Skill::getInstance()->get_skill_max_level($skill_id); $wing['fight'] += intval(Formula_SkillFpower::$wing_skill[$max_level]); } } else { $max_level = Cache_Skill::getInstance()->get_skill_max_level($wing['skill_id']); $wing['fight'] += intval(Formula_SkillFpower::$wing_skill[$max_level]); } Com_Log::log("{$wing['id']} wing fight add skill:{$wing['fight']}", 'wing_fight', 1); /* if (Com_Array::is_good_arr($skill_data)) { foreach ($skill_data as $second_layer) { $wing['skill_id'][] = explode(":", $second_layer); } } */ #$wing[$id]['attr'] = json_encode($wing[$id]['attr']); $wing['show'] = 1; $wing['activation'] = 0; $wing['synthetic'] = 1; if ($data['condition']) { list($type, $value) = explode("|", $data['condition']); if ($type == 4) { #$wing['synthetic'] = 0; $wing['activation'] = 0; $item = explode(":", $value); $wing['condition'] = array($type, $item, 0); /* $l_data = explode(":", $data['show_condition']); if ($l_data[0] != 0) { $wing['show'] = 0; } */ } else { $value = $value > 0 ? $value : 0; $wing['condition'] = array($type, array($value)); } } $wing['state'] = 0; $wing['sort'] = $data['sort']; $wing['avatar'] = $data['avatar']; $wing['name'] = strval($data['name']); $wing['repair_flag'] = $this->repair_flag; return $wing; }
/** * 挂机设置 */ public function CMD2_765() { $data = $this->get_game('HookSetting')->set_hook_settings($this->_authuser['player_id'], $this->_param[0]); Com_Log::log($data, 'hook_settings', 1); Protocol::input($this->_authuser['player_id'], 3, 7, 765, $data); }
/** * 触发公会成就任务 * @param unknown $player_id */ public function trigger_union_achieve($data) { if (empty($data)) { return; } $data = json_decode($data, true); Com_Log::log($data, 'trigger_union_achieve.log', 1); $player_id = $data["player_id"]; $task_type = $data["task_type"]; $trigger_val = $data["num"]; $update_type = $data["update_type"]; $union_id = $data["union_id"]; $objUnionAchieveData = $this->get_data('UnionAchieve'); $achieve_list = Cache_UnionAchieve::getInstance()->get_union_achieve_info(array("type" => $task_type)); foreach ($achieve_list as $val) { $achieve_id = $val['sid']; $unionAchieveInfo = $objUnionAchieveData->get_union_achieve_list($union_id, $achieve_id); if ($unionAchieveInfo['state'] == 1) { continue; } $content = explode('|', $val['content']); $total_num = count($content) > 1 ? $content[1] : $content[0]; $player_num = count($content) > 1 ? $content[0] : 0; //不同玩家达成 if ($player_num > 0) { if ($unionAchieveInfo['player_ids']) { if (in_array($player_id, $unionAchieveInfo['player_ids'])) { continue; } } $unionAchieveInfo['player_ids'][] = $player_id; } $unionAchieveInfo['sid'] = $achieve_id; $unionAchieveInfo['state'] = 0; if ($update_type == 1) { //累加 $unionAchieveInfo['num'] += $trigger_val; //成就完成 if ($unionAchieveInfo['num'] >= $total_num) { $unionAchieveInfo['state'] = 1; } } else { if ($update_type == 2) { //赋值 $unionAchieveInfo['num'] = $trigger_val; //成就完成 if ($unionAchieveInfo['num'] >= $total_num) { $unionAchieveInfo['state'] = 1; } } else { if ($update_type == 3) { //小于等于 $unionAchieveInfo['num'] = $trigger_val; //成就完成 if ($unionAchieveInfo['num'] > 0 && $unionAchieveInfo['num'] <= $total_num) { $unionAchieveInfo['state'] = 1; } } else { continue; } } } if ($player_num) { $unionAchieveInfo['state'] = 0; if (count($unionAchieveInfo['player_ids']) >= $player_num) { $unionAchieveInfo['state'] = 1; } $unionAchieveInfo['num'] = count($unionAchieveInfo['player_ids']); } $progress_task_num = 0; $medal_achieve_list = Cache_UnionAchieve::getInstance()->get_union_achieve_info(array("medal_id" => $val["medal_id"])); $medal_total_task_num = count($medal_achieve_list); foreach ($medal_achieve_list as $medal_task_info) { if ($achieve_id == $medal_task_info["sid"]) { if (!$unionAchieveInfo['state']) { break; } $progress_task_num++; } else { $achieve_info = $objUnionAchieveData->get_union_achieve_list($union_id, $medal_task_info["sid"]); if (!$achieve_info) { break; } if ($achieve_info['state'] == 1) { $progress_task_num++; } } } $this->start_trans(); $unionAchieveInfo["rep_time"] = time(); $retUnionAchieve = $objUnionAchieveData->update_union_achieve($union_id, $achieve_id, $unionAchieveInfo); //达成勋章 $retUnionInfo = true; if ($progress_task_num == $medal_total_task_num) { $objUnionInfoData = $this->get_data('UnionInfo'); $UnionInfo = $objUnionInfoData->get_union_info($union_id, array("union_medal")); $UnionInfo['union_medal'][] = $val['medal_id']; Com_Log::debug_write('update_union_info', "trigger_union_achieve|unoin_id={$union_id}" . json_encode($data)); $retUnionInfo = $objUnionInfoData->update_union_info($union_id, $UnionInfo); $medal_list = Cache_UnionMedal::getInstance()->get_union_medal_info(array("sid" => $val['medal_id'])); $medal_info = $medal_list[0]; $arr_replace = array(); $arr_replace[] = array('rep_type' => 7, 'txt' => $medal_info['name'], 'rep_color' => "ffb901"); $msg = Language_Message::make_message(174902, $arr_replace); $this->get_game('SystemNotice')->send_system_msg($player_id, $msg, 7, 7); } if ($retUnionAchieve && $retUnionInfo) { $this->commit(); if ($unionAchieveInfo['state'] == 1) { $arr_replace = array(); $arr_replace[] = array('rep_type' => 7, 'txt' => $val['name'], 'rep_color' => "ffb901"); $msg = Language_Message::make_message(174901, $arr_replace); $this->get_game('SystemNotice')->send_system_msg($player_id, $msg, 7, 7); } if ($progress_task_num >= $medal_total_task_num) { $this->union_player_add_attr($union_id, $val['medal_id']); } } else { $this->rollback(); } if (!IS_FRONT) { Protocol::out(); } } }
public function add_union_apply_todb($arr_detail) { $arr_field = array(); if ($arr_detail) { foreach ($arr_detail as $key => $value) { if (isset($this->_union_player_apply_default_field[$key])) { if (is_array($value)) { $arr_field[$key] = json_encode($value); } else { $arr_field[$key] = $value; } } } $insertSql = "insert into `union_apply`(" . implode(",", array_keys($arr_field)) . ") values('" . implode("','", $arr_field) . "')"; Com_Log::log($insertSql, 'union_apply.log', 1); return $this->query($insertSql); } }
public function CMD2_1052() { $data = $this->get_game('TaskMain')->get_task_info($this->_authuser['player_id']); Com_Log::log("player_id:{$this->_authuser['player_id']} check task status:{$data[0]['task_status']}", 'yc', 1); Protocol::input($this->_authuser['player_id'], 3, 10, 1052, array($data[0]['task_status'], 10000)); }