[手游新项目历程]第10天-角色登陆流程
2016-03-10 14:39
411 查看
管理容器
//References :
typedef std::map<std::string, int> clientMapT;
clientMapT clientMap;
LogicalConnection* ClientFactoryImpl::AddLogicalConnection( LogicalConnection* pClient )
{
std::string key(pClient->getKey());
ScopedLock csLock(cs);
//
LogicalConnection* pRet = pClient;
clientMapT::iterator it = clientMap.find(key);
if(it!=clientMap.end())
{
pRet = it->second;
}
else
{
clientMap[key] = pClient;
nClientsCount++;
}
pRet->IncrementUsage();
return pRet;
}
LogicalConnection* ClientFactoryImpl::FindLogicalConnection( const char* _key )
{
std::string key(_key);
//
ScopedLock csLock(cs);
clientMapT::iterator it = clientMap.find(key);
if(it==clientMap.end())
return NULL;
LogicalConnection* pClient = it->second;
pClient->IncrementUsage();
return pClient;
}
LogicalConnection* pRecipient = FindClient(request.GetArg1().c_str());
if (pRecipient)
{
WebsocketDataMessage response(Routedcommunication);
response.SetArguments(request.GetEncodedData());
pRecipient->PushPacket(&response);
ReturnClient(pRecipient);
}
std::map<Tint32, LogicalConnection*> m_PlayerConnectionIdMap; //错误的方式
如果自己存一个连接的指针取出来发送回报错,
std::map<Tint32, CLIENT_KEY> m_PlayerConnectionIdMap; //正确的方式
LogicalConnection* pRecipient = FindClient(CLIENT_KEY);
只能存一个key的容器,通过key去自带的容器取连接来发送包
//References :
typedef std::map<std::string, int> clientMapT;
clientMapT clientMap;
LogicalConnection* ClientFactoryImpl::AddLogicalConnection( LogicalConnection* pClient )
{
std::string key(pClient->getKey());
ScopedLock csLock(cs);
//
LogicalConnection* pRet = pClient;
clientMapT::iterator it = clientMap.find(key);
if(it!=clientMap.end())
{
pRet = it->second;
}
else
{
clientMap[key] = pClient;
nClientsCount++;
}
pRet->IncrementUsage();
return pRet;
}
LogicalConnection* ClientFactoryImpl::FindLogicalConnection( const char* _key )
{
std::string key(_key);
//
ScopedLock csLock(cs);
clientMapT::iterator it = clientMap.find(key);
if(it==clientMap.end())
return NULL;
LogicalConnection* pClient = it->second;
pClient->IncrementUsage();
return pClient;
}
LogicalConnection* pRecipient = FindClient(request.GetArg1().c_str());
if (pRecipient)
{
WebsocketDataMessage response(Routedcommunication);
response.SetArguments(request.GetEncodedData());
pRecipient->PushPacket(&response);
ReturnClient(pRecipient);
}
std::map<Tint32, LogicalConnection*> m_PlayerConnectionIdMap; //错误的方式
如果自己存一个连接的指针取出来发送回报错,
std::map<Tint32, CLIENT_KEY> m_PlayerConnectionIdMap; //正确的方式
LogicalConnection* pRecipient = FindClient(CLIENT_KEY);
只能存一个key的容器,通过key去自带的容器取连接来发送包
角色登陆流程 GAME_MSG_LOGIN_REQ = 1001, //登陆 client发送登陆包 -> webServer 产生链接ConIdid写进包->gate Tint32 NetGate::OnRecvHandle( t_ConnID ConnectionId,tagNetMsg *pMsg ) 消息派发 Tint32 NetClient::OnAcceptHandle( t_ConnID ConnectionId ) void GatePlayerMgr::AddPlayerConnIdMap( t_ConnID nConnId, GatePlayer* pGatePlayer ) TBool NetDBCache::PlayerRetLogin( t_ConnID ConnectionId,tagNetMsg &Msg ) void NetWorld::SendToWholeWorld(Tint32 msgID,char *buff, unsigned int buffLen , ePlayerFilter eFilter, Tint64 nFilterValue) { Debug_Assert(buffLen < enMaxMsgDataBufferSize, ); tagNetMsg msgToSend; memcpy(msgToSend.buff, buff, buffLen); msgToSend.BuffLen = buffLen; msgToSend.MsgID = msgID; SendToWholeWorld(msgToSend, eFilter, nFilterValue); } void NetWorld::SendToWholeWorld( tagNetMsg& msg,ePlayerFilter eFilter /*= ePlayerFilter_All*/, Tint64 nFilterValue /*= -1*/ ) { tagNetMsg MsgToSend; Stream stream(MsgToSend.buff, sizeof(MsgToSend.buff)); stream.Write(eFilter); stream.Write(nFilterValue); stream.Write(msg); MsgToSend.MsgID = GAME_SERVER_MSG_BROCAST_WHOLE_WORLD; MsgToSend.BuffLen = stream.GetPos(); SendSingle(MsgToSend.MsgID, MsgToSend.BuffLen, MsgToSend); } struct MsgLoginReq { void Serialize(Stream& stream) { unsigned short nLen = (unsigned short)m_Account.GetRealStrLen(); stream.Write(nLen); stream.WriteBuffer(m_Account.GetName(),nLen); stream.Write(m_SerVerId); nLen = (unsigned short)m_Platform.GetRealStrLen(); stream.Write(nLen); stream.WriteBuffer(m_Platform.GetName(),nLen); } bool DeSerialize(Stream& stream) { unsigned short nLen = 0; //玩家账号 if (!stream.Read(nLen)) return false; if(nLen >= MAX_ACCOUNT_LEN) return false; if (!stream.ReadBuffer(m_Account.GetName(), nLen)) return false; //服务器id if (!stream.Read(m_SerVerId)) return false; //平台标识 if (!stream.Read(nLen)) return false; if(nLen >= MAX_PLATFORM_LEN) return false; if (!stream.ReadBuffer(m_Platform.GetName(), nLen)) return false; return true; } CommonAccountName m_Account; CommonString<255> m_Token; Tint32 m_SerVerId; CommonPlatform m_Platform; }; TBool NetGate::PlayerLoginResService DB_MSG_ACCOUNT_LOGIN, //登录 DB_MSG_ACCOUNT_LOGIN_RET, //登录返回 GAME_MSG_LOGIN_RES void NetGate::SendToClientWithClientConnId GAME_SERVER_MSG_DBCACHE_TO_GATE , //从DBCACHE发给GATE TBool NetDBCache::PlayerRetLogin( t_ConnID ConnectionId,tagNetMsg &Msg )
相关文章推荐
- Android 开发系列(6) - 使用 winrar 和 dex2jar 对 apk 反编译成 jar
- 分享Android 蓝牙4.0(ble)开发的解决方案
- 谷歌浏览器 调试ajax
- Android常见inputType
- 解决cell复用问题引起的cell上控件状态被复用
- vc6.0 ocx开发
- 多线程大全
- 通过Javacv摄像头连续抓图
- Android中BroadCast与Activity之间的通信
- ng-blur失去焦点执行事件
- datagridview随窗体的大小而变,表格填满控件
- 淘宝开店-新手卖家上哪找货源
- Chrome插件
- java连接mogodb
- 三年过去了
- MySql查询优化 百万级记录查询优化 limit分页查询
- Java是最基本的数据类型吗?
- 写博客的原因
- Unity: PointerInputModule.cs
- 足以说服你跟程序员约会的10个理由