<?php /** * 异步同步服务(sql, function) * Created by PhpStorm. * User: chengt * Date: 2015/5/5 * Time: 23:27 */ require dirname(__FILE__) . '/../global.php'; TenYear::getInstance(); ini_set('default_socket_timeout', -1); Com_AdCache::factory()->set_timeout(0); //设置background echo "register_background\r\n"; Com_Replication::register_background(); //开始接收 echo "start receive \r\n"; Com_Queued::receive_all();
<?php /** * 异步GloryShop日志备份服务 * @author wanghui@uuzu.com * @date 2015-4-20 */ require dirname(__FILE__) . '/../global.php'; TenYear::getInstance(); ini_set('default_socket_timeout', -1); Com_AdCache::factory()->set_timeout(0); Com_Replication::set_interval_time(300); //注册player_detail同步方法 $objPlayerDetail = new Data_GloryShop(); Com_Replication::register('player_glory_shop', array($objPlayerDetail, 'get_player_log'), array($objPlayerDetail, 'replace_to_mysql')); //开始执行同步 Com_Replication::start();
/** * @Purpose: * 设置英雄出战状态 * @Method Name: hero_talent_upgrade() * @Parameter: $player_id 玩家ID * @Parameter: $hero_id 英雄 ID * @Parameter: $type 英雄状态(1:出战 2:后补(取消后补功能)) * @Return: 返回英雄出战状态 */ public function set_hero_state($player_id, $hero_id, $type) { $player_id = intval($player_id); $hero_id = strval($hero_id); $type = intval($type); //参数错误 if (empty($hero_id) || $type != 1) { $this->throw_error('10107'); } $obj_player_hero_data = $this->get_data('PlayerHero'); $data = $obj_player_hero_data->get_player_hero_info($player_id, $hero_id); if (!$data) { $this->throw_error('10106'); } //获取可后补英雄数量 $player_info = $this->get_data('Player')->get_player_info($player_id, array('after_hero_hole', 'silver', 'crystal', 'level', 'fame_level', 'career_type', 'gold', 'online_time')); $after_fight_hero_limit = $player_info['after_hero_hole']; //获取出战的英雄 $fight_hero_list = $obj_player_hero_data->get_fight_hero($player_id); $fight_hero_num = count($fight_hero_list); $is_full_hero = false; if ($type == 2) { //英雄已出战 if ($data['state'] == 1) { $this->throw_error('50113'); } if ($data['state'] != 2) { if ($after_fight_hero_limit < 2) { $this->throw_error('50119'); //后补位不足 } //获取后补英雄数据 $after_fight_hero = $obj_player_hero_data->get_after_fight_hero($player_id); if ($after_fight_hero) { if (count($after_fight_hero) > 0) { $is_full_hero = true; } } } } else { //英雄已后补 if ($data['state'] == 2) { $this->throw_error('50114'); } if ($data['state'] != 1) { if (in_array($data['hero_code'], $fight_hero_list)) { $this->throw_error('51301'); //已有同类英雄出战 } } } $this->start_trans(); if ($type == 2) { $hero_state = $data['state'] ? 0 : 2; if ($hero_state) { if ($is_full_hero) { $after_hero_id = reset($after_fight_hero); if (!$after_hero_id) { $this->throw_error('10101'); //reset()获取数据错误 } $hero_data = $obj_player_hero_data->get_player_hero_info($player_id, $after_hero_id); if (!$hero_data) { $this->throw_error('10106'); } $hero_data['state'] = 0; //删除后补英雄 $obj_player_hero_data->del_after_fight_hero($player_id, $after_hero_id); $exist_update_res = $this->update_hero_state($player_id, $after_hero_id, $hero_data['state'], $hero_data); if (!$exist_update_res) { $this->throw_error('10104'); } } //更新英雄状态 $obj_player_hero_data->updata_after_fight_hero($player_id, array($hero_id => $hero_id)); } else { //删除后补英雄 $obj_player_hero_data->del_after_fight_hero($player_id, $hero_id); } } else { $hero_state = $data['state'] ? 0 : 1; if ($hero_state) { if ($fight_hero_num == 0) { $obj_player_hero_data->updata_fight_hero($player_id, $hero_id, $data['hero_code'], 'hero1'); } else { if ($fight_hero_num == 1) { if ($after_fight_hero_limit < 1) { $fight_hero = array_slice($fight_hero_list, 0, 1, true); $fight_hero_id = key($fight_hero); $hero_data = $obj_player_hero_data->get_player_hero_info($player_id, $fight_hero_id); if (!$hero_data) { $this->throw_error('10106'); } $hero_data['state'] = 0; $exist_update_res = $this->update_hero_state($player_id, $hero_data['hero_id'], $hero_data['state'], $hero_data); if (!$exist_update_res) { $this->throw_error('10104'); } $obj_player_hero_data->del_fight_hero($player_id, 'hero1'); $obj_player_hero_data->updata_fight_hero($player_id, $hero_id, $data['hero_code'], 'hero1'); } else { $obj_player_hero_data->updata_fight_hero($player_id, $hero_id, $data['hero_code'], 'hero2'); } } else { $fight_hero = array_slice($fight_hero_list, 0, 1, true); $fight_hero_id = key($fight_hero); $hero_data = $obj_player_hero_data->get_player_hero_info($player_id, $fight_hero_id); if (!$hero_data) { $this->throw_error('10106'); } $hero_data['state'] = 0; $exist_update_res = $this->update_hero_state($player_id, $hero_data['hero_id'], $hero_data['state'], $hero_data); if (!$exist_update_res) { $this->throw_error('10104'); } $fight_hero = array_slice($fight_hero_list, 1, 1, true); $fight_hero_id = key($fight_hero); $obj_player_hero_data->updata_fight_hero($player_id, $fight_hero_id, $fight_hero[$fight_hero_id], 'hero1'); $obj_player_hero_data->updata_fight_hero($player_id, $hero_id, $data['hero_code'], 'hero2'); } } } else { $pos = 0; foreach ($fight_hero_list as $id => $code) { if ($id == $hero_id) { $del_hero_key = 'hero1'; if ($pos > 0) { $del_hero_key = 'hero2'; } //删除出战英雄 $obj_player_hero_data->del_fight_hero($player_id, $del_hero_key); if ($del_hero_key == 'hero1' && $fight_hero_num > 1) { $fight_hero = array_slice($fight_hero_list, 1, 1, true); $fight_hero_id = key($fight_hero); $obj_player_hero_data->updata_fight_hero($player_id, $fight_hero_id, $fight_hero[$fight_hero_id], 'hero1'); $obj_player_hero_data->del_fight_hero($player_id, 'hero2'); } break; } $pos++; } } } $data['state'] = $hero_state; $update_res = $this->update_hero_state($player_id, $hero_id, $hero_state, $data); if (!$update_res) { $this->throw_error('10104'); } $this->commit(); if ($hero_state == 1) { $this->get_game('TaskTrigger')->async_trigger_task($player_id, 17, 17, 1); #英雄出战任务触发 } #红点 Com_Replication::asyn_call_func('PlayerFunc', 'game', 'pack_red_icon', array($player_id, $player_info)); return $this->get_player_hero_info($player_id); //return array(0 => $data['hero_id'], 1 => $data['state']); }
/** * 注册同步队列 * * @param unknown_type $player_id 玩家id或者数组array(玩家id,附加数据例如道具id) * @param unknown_type $class 注册类标识 * @param unknown_type $reptime 同步时间 设置会记录最后数据修改的时间 * @param unknown_type $reptype 同步方式 set, add, del 对应更新 插入 删除三种原子操作 */ protected function register_repaction($player_id, $class, $reptime = 0, $reptype = 'set') { if ($this->is_trans()) { return $this->set_redis_pre_action((is_array($player_id) ? implode('_', $player_id) : $player_id) . '_' . $class . '_' . $reptype, array('Com_Replication', 'push_queue'), array($player_id, $class, $reptime, $reptype)); } else { return Com_Replication::push_queue($player_id, $class, $reptime, $reptype); } }
/** * 注册需要同步的回调方法 * * @param unknown_type $class 需要操作的class * @param unknown_type $getFunc 获取redis数据的方法 * @param unknown_type $setFunc 更新redis数据至mysql方法 * @param unknown_type $addFunc 插入redis数据至mysql方法 * @param unknown_type $delFunc 删除redis数据至mysql方法 */ public static function register($class, $getFunc, $setFunc, $addFunc = null, $delFunc = null) { self::$registers[$class] = array('getFunc' => $getFunc, 'setFunc' => $setFunc, 'addFunc' => $addFunc, 'delFunc' => $delFunc); self::$register_class = $class; }
public function CMD2_741() { // try{ $player_info = $this->get_data('Player')->get_player_info($this->_authuser['player_id'], array('is_online', 'career_type', 'level', 'vip', 'vip_exp', 'last_offline_time', 'offline_reward_status', 'silver', 'crystal', 'fame_level', 'gold', 'bag_num', 'storage_num', 'online_time', 'heart_time', 'login_time', 'cz_status', 'fame', 'fame_level_exp', 'privilege_level')); $player_detail = $this->get_data('PlayerDetail')->get_player_detail($this->_authuser['player_id'], array('guide', 'fashion_fit', 'fashion_info', 'player_settings', 'func_open', 'train_info', 'train_attr_info', 'equip_wing', 'wing_info', 'skill_info', 'skill_rune_info', 'skill_rune_cote_info', 'dower_info', 'equip_attr', 'fairy_attr_1', 'fairy_attr_2', 'fashion_attr', 'union_achieve_attr', 'achieve_attr_1', 'achieve_attr_2', 'player_grade_attr', 'union_player_attr', 'fame_attr', 'vip_special_attr', 'buff_attr', 'buff_attr_per')); if ($player_info['level'] >= 44) { #翅膀装备数据修复 $this->get_game('PlayerWing')->data_repair($this->_authuser['player_id'], $player_detail); } if ($player_info['level'] >= 9) { #修复英雄属性 $this->get_game('Hero')->hero_repair($this->_authuser['player_id']); Protocol_Player::p2c_part_update($this->_authuser['player_id'], array('hero_info' => array(), 'attr' => array())); } $data = $this->get_game('PlayerFunc')->get_player_func($this->_authuser['player_id'], $player_info, $player_detail); Protocol::input($this->_authuser['player_id'], 3, 7, 741, $data); $data = $this->get_game('PlayerBag')->get_player_item($this->_authuser['player_id'], "1:3"); Protocol::input($this->_authuser['player_id'], 3, 8, 831, $data); try { $data = $this->get_game('PlayerBag')->get_player_bag_extend($this->_authuser['player_id'], 1, $player_info); Protocol::input($this->_authuser['player_id'], 3, 8, 833, $data); } catch (Exception $e) { } $data = $this->get_game('PlayerGuid')->get_guid($this->_authuser['player_id'], $player_detail); Protocol::input($this->_authuser['player_id'], 3, 7, 797, $data); $data = $this->get_game('PlayerSettings')->get_player_settings($this->_authuser['player_id']); Protocol::input($this->_authuser['player_id'], 3, 7, 725, $data); # 推送玩家人物面板培养信息 $data = $this->get_game('Train')->get_player_train_info($this->_authuser['player_id'], $player_info, $player_detail); Protocol::input($this->_authuser['player_id'], 3, 14, 1403, $data); $data = $this->get_game('PlayerFashion')->get_player_fashion($this->_authuser['player_id'], $player_detail); Protocol::input($this->_authuser['player_id'], 3, 8, 838, $data); if ($player_info['level'] >= 9) { # 获取开启的功能列表前,刷新全民问卷功能的开启状态 try { # 条件问卷查询推送 $this->get_game('ActivityQuestions')->get_cond_ids($this->_authuser['player_id'], 0, $player_info); } catch (Exception $e) { } try { //发送守护雅典娜奖励 $this->get_game('Athena')->send_mail_for_reward($this->_authuser['player_id']); } catch (Exception $e) { } #更新vip $this->get_game('VipReward')->check_vip_level($this->_authuser['player_id'], $player_info); $unread_num = $this->get_game('Mail')->get_unread_num($this->_authuser['player_id']); if ($unread_num > 0) { Protocol::input($this->_authuser['player_id'], 8, 7, 706, array($unread_num)); } //推送玩家好友 $data = $this->get_game('PlayerFriend')->get_friend_detail_by_type($this->_authuser['player_id'], 1); Protocol::input($this->_authuser['player_id'], 8, 7, 754, $data); //推送玩家黑名单 $data = $this->get_game('PlayerFriend')->get_friend_detail_by_type($this->_authuser['player_id'], 5); Protocol::input($this->_authuser['player_id'], 8, 7, 754, $data); //推送玩家仇人 $data = $this->get_game('PlayerFriend')->get_friend_detail_by_type($this->_authuser['player_id'], 4); Protocol::input($this->_authuser['player_id'], 8, 7, 754, $data); $this->get_data('NewsTips')->push_player_tips($this->_authuser['player_id'], 0, $player_info); $data = $this->get_game('Quit')->get_close_info($this->_authuser['player_id']); Protocol::input($this->_authuser['player_id'], 3, 7, 792, $data); #更新vip特权等级 $this->get_game('VipSpecial')->update_my_level($this->_authuser['player_id']); #红点 $data = $this->get_game('PlayerFunc')->red_icon($this->_authuser['player_id'], $player_info, $player_detail); Protocol::input($this->_authuser['player_id'], 3, 70, 7002, array(0 => $data, 1 => 1)); #修复成就 if ($player_info['level'] > 19) { $this->get_game('PlayerAchieve')->achieve_repair($this->_authuser['player_id']); } // Com_Replication::asyn_call_func('PlayerFashion','game','check_fashion_timer',array($this->_authuser['player_id'], $player_detail)); if ($player_info['level'] >= 37) { Com_Replication::asyn_call_func('TaskChain', 'game', 'fix_chain_task', array($this->_authuser['player_id'])); #修复环任务类型错误 } } #累计登录天数 $this->get_game('PlayerAchieve')->async_trigger_achieve_target($this->_authuser['player_id'], 33, 1, 6); #同步声望配置变化 $sync_times = $this->get_data("Player")->get_sync_fame_config_times($this->_authuser['player_id']); if (intval($sync_times) < 1) { $this->get_game('PlayerUpgrade')->fame_upgrade($this->_authuser['player_id'], $player_info); $this->get_data("Player")->set_sync_fame_config_times($this->_authuser['player_id'], 1); } }
/** * @Purpose: * 精灵升级 * @Param $player_id 玩家ID * @param $fairy_id 精灵ID * @param $up_type 升级方式(0:手动进阶1:自动进阶) * @param $auto_buy 自动购买(0:不自动购买1:自动购买) * @return 精灵下级数据 */ public function fairy_upgrade($player_id, $fairy_id, $up_type, $auto_buy) { $player_id = intval($player_id); //获取玩家精灵数据 $obj_player_fairy_data = $this->get_data('Fairy'); $data = $obj_player_fairy_data->get_player_fairy_info($fairy_id); if (!$data) { $this->throw_error('10112'); //获取精灵信息失败 } $fairy_level_table = $this->get_fairy_lvl_tabel_data($data['fairy_code'], $data['star']); if (!$fairy_level_table) { $this->throw_error('10109'); //配置表读取错误 } #$player_info = $this->get_data('Player')->get_player_info($player_id, array('level', 'vip', 'ticket', 'gold', 'silver', 'fame_level', 'ad_info', 'privilege_level')); $player_info = $this->get_data('Player')->get_player_info($player_id, Com_Util::get_player_fields(array('crystal', 'career_type', 'online_time', 'currency', 'level', 'vip', 'ticket', 'gold', 'silver', 'fame_level', 'ad_info', 'privilege_level'))); #获取玩家声望等级 $player_fame_level = $player_info['fame_level']; if ($fairy_level_table['fame'] > 0 && $player_fame_level < $fairy_level_table['fame']) { $this->throw_error('50308'); //声望不足 } $data['grow'] = $obj_player_fairy_data->get_fairy_grow($fairy_id, 'grow'); $data['auto_buy'] = $auto_buy; $log_front_star = $data['star']; $log_front_grow = $data['grow']; $add_grow = 0; $out_prop = array(); $log_data = array(); $result = 0; $this->start_trans(); $update_times = $up_type ? 10 : 1; for ($i = 0; $i < $update_times; $i++) { $fairy_code = $data['fairy_code']; $fairy_star = $data['star']; //精灵是否满级 $is_level = $this->is_next_level($data, false); if ($is_level === true) { if ($update_times == 10 && $i > 0) { break; } $rtn_data['result'] = $this->return_code['level_error']; return Struct_Fairy::get_fairy_upgrade_struct($rtn_data); //return 'ERROR_FAIRY_4'; } else { if ($is_level !== false) { $this->throw_error($is_level); } } //检验所需道具是否足够 $check_res = $this->check_prop_enough($player_id, $fairy_code, $fairy_star, $auto_buy, $out_data, $player_info, $log_data); if ($check_res !== true) { if ($check_res === false) { return Struct_Fairy::get_fairy_upgrade_struct($out_data); } $this->throw_error($check_res); } //精灵升级结果 $is_upgrade_res = $this->is_upgrade($data); if ($up_type) { $add_grow += $data['add_grow']; } //升级 if ($is_upgrade_res === true) { //更新精灵数据 $update_fairy_res = $this->update_fairy_data($data); if ($update_fairy_res !== true) { $this->throw_error($update_fairy_res); } $this->get_data('RankList')->update_fairy_rank($fairy_id, $data['fpower']); //升级结果更新为1 $result = $data['result']; } else { if ($is_upgrade_res === false) { $data['grow'] += $data['add_grow']; $fairy_level_table = $this->get_fairy_lvl_tabel_data($data['fairy_code'], $data['star']); if (!$fairy_level_table) { $this->throw_error('10109'); //配置表读取错误 } #$expire_time = $obj_player_fairy_data->get_fairy_grow_expire($fairy_id); //记录购买状态 $affectedRows = $obj_player_fairy_data->update_player_fairy($fairy_id, array('auto_buy' => $data['auto_buy'])); if (!$affectedRows) { $this->throw_error('10104'); } $grow_clear_time = $fairy_level_table['grow_clear_time']; if (isset($data['is_set_expire']) && $data['is_set_expire'] == 1) { $grow_clear_time = 0; } $update_fairy_grow_res = $this->update_fairy_grow($fairy_id, $data['grow'], $grow_clear_time); if (!$update_fairy_grow_res) { $this->throw_error('10104'); } //升级结果0:普通6:暴击 $result = $data['result']; } else { $this->throw_error($is_upgrade_res); } } //删除临时数据中的道具,金币,元宝数据 $settle_accounts_temporary_prop_res = $this->settle_accounts_temporary_prop($player_id, $fairy_code, $fairy_star, $out_data, $out_prop); if ($settle_accounts_temporary_prop_res !== true) { $this->throw_error($settle_accounts_temporary_prop_res); } //print_r('lvl:');print_r($data['level']);print_r(' star:');print_r($data['star']);print_r(' grow:');print_r($data['grow']);print_r(' add_grow:');print_r($data['add_grow']);print_r(' grow_max:');print_r($data['grow_max']); //echo '<br />'; } //删除缓存数据中的道具,金币,元宝数据 $settle_accounts_prop_res = $this->settle_accounts_prop($player_id, $out_prop, $player_info); if ($settle_accounts_prop_res !== true) { $this->throw_error($settle_accounts_prop_res); } if ($up_type) { //升级结果更新为0 $result = $this->return_code['fail']; } $this->commit(); #红点 Com_Replication::asyn_call_func('PlayerFunc', 'game', 'pack_red_icon', array($player_id, $player_info)); # 若有购买缺少材料,记录虚假商城购买日志 if (!empty($log_data) && $log_data['deduct_gold_num'] > 0) { $this->get_game('Shop')->add_dummy_shop_log($player_id, $player_info, $log_data['prop_id'], $log_data['prop_num'], $log_data['cur_idx'], $log_data['deduct_gold_num'], 525); } //更新成就 $this->get_game('PlayerAchieve')->async_trigger_achieve_target($player_id, 9, $data['level'], 8); #每日活跃度更新 $this->get_game('DailyBoon')->async_trigger_daily_boon_task($player_id, 2100); #更新日常任务 $this->get_game('TaskTrigger')->async_trigger_task($player_id, 114, 114, 1); #更新主线任务 $this->get_game('TaskTrigger')->async_trigger_task($player_id, 19, 19, 1); #引导任务 $this->get_game('TaskTrigger')->async_trigger_guide_task($player_id, 3, $data['level'], $data['type']); #更新日志 $log_data = array('player_id' => $player_id, 'channel' => 53, 'server_id' => SERVER_ID, 'operator_id' => OPERATOR_ID, 'player_level' => $player_info['level'], 'vip_level' => $player_info['vip'], 'vip_special_level' => $player_info['privilege_level'], 'ad_info' => $player_info['ad_info'], 'cmd_id' => 525, 'type' => $data['type'], 'level' => $data['level'], 'amount_star' => $log_front_star, 'after_amount_star' => $data['star'], 'amount_grow' => $log_front_grow, 'after_amount_grow' => $data['grow'], 'change_num' => $data['grow'] > 0 ? $data['grow'] - $log_front_grow : $data['grow_max'] - $log_front_grow, 'add_time' => time()); Log_Common::getInstance()->add_log_by_table($log_data, 'log_fairy_upgrade'); //是否满级 $is_level = $this->is_next_level($data, false); if ($is_level === true) { $rtn_data['result'] = $result; $rtn_data['next_level'] = $data['level']; $rtn_data['grow_value'] = 100; $rtn_data['shield_limit'] = 0; $rtn_data['Attr_id'] = 0; $rtn_data['open_hole'] = 0; $rtn_data['next_star'] = 0; $rtn_data['fairy_code'] = 0; return Struct_Fairy::get_fairy_upgrade_struct($rtn_data); } else { if ($is_level !== false) { $this->throw_error($is_level); } } //获取下级精灵数据 $get_fairy_res = $this->get_next_fairy_data($data, $new_fairy_data, false); if ($get_fairy_res !== true) { $this->throw_error($get_fairy_res); } $rtn_data['result'] = $result; $rtn_data['next_level'] = $new_fairy_data['lvl']; $rtn_data['grow_value'] = $data['grow']; $rtn_data['shield_limit'] = $new_fairy_data['shield_lvl']; $rtn_data['Attr_id'] = $new_fairy_data['attribute']; $rtn_data['open_hole'] = $new_fairy_data['skill_hole']; $rtn_data['cur_grow'] = $up_type ? $add_grow : $data['add_grow']; $rtn_data['next_star'] = $new_fairy_data['star']; $rtn_data['fairy_code'] = $new_fairy_data['sid']; return Struct_Fairy::get_fairy_upgrade_struct($rtn_data); }