码迷,mamicode.com
首页 > 其他好文 > 详细

GS连接事件

时间:2014-11-22 23:01:56      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   os   sp   数据   on   

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连接事件

标签:style   blog   io   ar   color   os   sp   数据   on   

原文地址:http://www.cnblogs.com/zzyoucan/p/4115735.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!