首页 > 代码库 > GS连接事件
GS连接事件
GS网络连接事件//网络事件//这个事件是在libevent里面的收到的事件就是在那个listen里面,就是客户端打开,服务器收到通知link_stat stat = (link_stat)rPkt.size;if (stat == link_stat::link_connected){ GameChannel* pNewGC = new GameChannel(); m_vecChannel[rPkt.channel_id] = pNewGC;//m_vecChannel玩家channel,GS是控制所有玩家即channel的 pNewGC->m_nChannelId = rPkt.channel_id; pNewGC->m_pDataLayer = m_spDataLayer.get();//channel有可能直接向网络层发数据 pNewGC->m_pShare = this;//channel需要这个,难道是需要其他用户的一些信息? pNewGC->m_pAsynDBC = this->m_spAsynDBC.get();//channel需要访问数据库 //gc->m_db = this->m_asyndb->getSynDBptr();//把地址复制一份给GameChannel::m_db,让其具有数据库操作权 m_LiveMgr.Add(rPkt.channel_id);}GameChannel::GameChannel(){ //namespace ph = ph; m_UserId = -1; m_ActorId = -1; m_pUserInfo = NULL; m_pActiveActor = NULL; m_pMap = NULL; m_eGameState = eGameState_OnlyConnect; m_uDBGetAskRefCount = 0; //数据库绑定,数据库通过function回调这里面的函数 m_fnGetUserID = std::bind(&GameChannel::ProcessGetUserID, this, ph::_1); m_fnGetUserInfo = std::bind(&GameChannel::ProcessGetUserInfo, this, ph::_1); m_fnGetActorInfos = std::bind(&GameChannel::ProcessGetActorInfos, this, ph::_1); m_fnGetActorInfoEx = std::bind(&GameChannel::ProcessGetActorInfoEx, this, ph::_1, ph::_2); m_fnGetActorInfo = std::bind(&GameChannel::ProcessGetActorInfo, this, ph::_1, ph::_2); m_fnGetRobotID = ([this](int robotID) { m_UserId = 999;//注意:压测的机器人专用。 m_pAsynDBC->GetActorInfoEx(&m_fnGetActorInfoEx, robotID); ++m_uDBGetAskRefCount; }); m_fnAddActor = std::bind(&GameChannel::ProcessAddActor, this, ph::_1, ph::_2, ph::_3); //通过function调用本模块的函数,其实也是函数指针的用法 m_mapPktAnalysis[c2s_start] = std::bind(&GameChannel::OnStart, this, ph::_1, ph::_2); m_mapPktAnalysis[c2s_json] = std::bind(&GameChannel::OnJson, this, ph::_1, ph::_2); m_mapPktAnalysis[c2s_on_live] = [this](void* pData, int nLen){return true;}; m_mapPktAnalysis[c2s_login] = std::bind(&GameChannel::OnLogin, this, ph::_1, ph::_2); m_mapPktAnalysis[c2s_select_actor] = [this](void* data, int len){return OnStart(data, len);}; m_mapPktAnalysis[c2s_message_talk] = std::bind(&GameChannel::OnMessageTalk, this, ph::_1, ph::_2); m_mapPktAnalysis[c2s_check_version] = std::bind(&GameChannel::OnCheckVersion, this, ph::_1, ph::_2);}
GS连接事件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。