int SvCon::doRegister(){ int ret = 0; LoginRequest lgr; lgr.set_type(m_sv_type); lgr.set_id(ef::itostr(m_svid)); string reqbody; lgr.SerializeToString(&reqbody); head h; h.cmd = LOGIN_REQ; h.magic = MAGIC_NUMBER; string req; constructPacket(h, reqbody, req); ALogError(m_serv->getConfig().LogName) << "<action:server_register> " "<event_loop:" << getEventLoop() << "> <conid:" << getId() << "> <con_serv_id:" << m_con_serv_id << ">"; ret = sendMessage(req); return ret; }
int32 login(const std::string& cid, const std::string& version, const std::string& token){ int32 ret = 0; LoginRequest lgr; string enctk; if(token.size()){ ef::encrypt(token, enctk); } lgr.set_id(cid); lgr.set_type(-1); lgr.set_version(version); lgr.set_token(enctk); m_cid = cid; m_token = token; LoginResponse lgresp; std::string req; lgr.SerializeToString(&req); std::string rsp; ret = send_req(100, req); if(ret < 0){ LOG_OUT << "test_login send fail, cid:" << m_cid << std::endl; return ret; } int32 cmd = 0; ret = recv_resp(cmd, rsp); if(ret <= 0){ LOG_OUT << "login recv_resp fail, cid:" << m_cid << std::endl; return ret; } //redirect if(cmd == 1001){ RedirectResponse rdresp; rdresp.ParseFromString(rsp); disconnect(); if(rdresp.status() != 0 || !rdresp.addrs_size()){ return -1; } int i = 0; for(; i < rdresp.addrs_size(); ++i){ const Address& a = rdresp.addrs(i); LOG_OUT << "test_login redirect, cid:" << m_cid << ", addr:" << a.ip() << ", port:" << a.port() << std::endl; ret = bind_connect(a.ip(), a.port(), m_local_ip, m_local_port); if(ret < 0){ LOG_OUT << "test_login redirect fail, cid:" << m_cid << std::endl; }else{ break; } } if(i < rdresp.addrs_size()) return login(m_cid, version, token); } lgresp.ParseFromString(rsp); if(lgresp.status() == 0){ LOG_OUT << "test_login success: cid:" << m_cid << ", sessid:" << lgresp.sessid() << std::endl; }else{ LOG_OUT << "test_login fail: cid:" << m_cid << ", status:" << lgresp.status() << std::endl; return -1; } m_sessid = lgresp.sessid(); ++success_count; if(token.size()){ m_key = token + m_sessid; } return ret; }