int32_t Register::InitProfile(int32_t uid) { int32_t ret = 0; PPlayerId init_id; init_id.set_uid(uid); init_id.set_zone_id(_req.zone_id()); __BEGIN_PROC__ PlayerID id; id.Init(init_id); bool exist; _p_profile = PlayerDataMgr::getInstance().Add(id, exist); if(NULL == _p_profile) { LOG_ERROR(_ctx, "alloc profile failed"); ret = -1; break; } else if(exist) { LOG_ERROR(_ctx, "profile exist. %s", id.ToString().c_str()); ret = -1; break; } time_t now = YAC_TimeProvider::getInstance()->getNow(); //玩家id PPlayerId *player_id = _p_profile->mutable_player_id(); player_id->set_uid(uid); player_id->set_zone_id(_req.zone_id()); //账户充值消费信息 PAccount *account = _p_profile->mutable_account(); account->set_history_total(0); account->set_balance(0); account->set_last_recharge_time(0); account->set_last_consume_time(0); //游戏内代币 PTokenMoney *token_money = _p_profile->mutable_token_money(); token_money->set_gold(0); //玩家基础信息 PBaseInfo *base_info = _p_profile->mutable_base_info(); base_info->set_name(_req.name()); base_info->set_register_time(now); base_info->set_login_time(now); base_info->set_gender(0); __END_PROC__ return ret; }
void Register::SetProfile(int32_t uid) { //初始化账号信息 PReginfo reginfo; InitReginfo(reginfo, uid); string reginfo_key = REGINFOPREFIX + _req.account(); string reginfo_value = reginfo.SerializeAsString(); //初始化profile InitProfile(uid); PPlayerId *player_id = _p_profile->mutable_player_id(); //string profile_key = PROFILEPREFIX + I2S(player_id->uid()) + "_" + I2S(player_id->zone_id()); string profile_key = CommFunc::getProfileKey(player_id->uid(), player_id->zone_id()); string profile_value = _p_profile->SerializeAsString(); auto got_reply = [&](Command<string>& c) { if(c.ok()) { _pkg_head.ret = RET_OK; PProfile *rsp_profile = _rsp.mutable_profile(); *rsp_profile = *_p_profile; //给客户端回包,流程结束 Send2Client(_pkg_head, _rsp); } else { PPlayerId *player_id = _p_profile->mutable_player_id(); PlayerID id; id.Init(*player_id); PlayerDataMgr::getInstance().Del(id); LOG_ERROR(_ctx, "SetProfile failed. cmd:%s status:%d", c.cmd().c_str(), c.status()); //给客户端回包,流程结束 _pkg_head.ret = RET_REDIS_ERR_SET; Send2Client(_pkg_head, _rsp); } }; ServerEnv::getInstance().getRdx().command<string>({"MSET", reginfo_key, reginfo_value, profile_key, profile_value}, got_reply); }