zoukankan      html  css  js  c++  java
  • 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);
    }
  • 相关阅读:
    如何使页面中的INPUT按指定的顺序移动焦点{转}
    Eclipse把包引入到项目中的方法
    mssqlserver和sqlexpress的区别{转}
    WPF中动态加载XAML中的控件
    修改Eclipse的智能感知设置
    格式化包括字符串, 数字, 日期, 枚举等类型数据的格式化
    ASP.NET身份验证机制membership入门——配置篇(1){转}
    JAVA基础总结{转}
    asp.net mvc的生命周期{转}
    使用开源免费类库在.net中操作Excel{转}
  • 原文地址:https://www.cnblogs.com/zzyoucan/p/4115735.html
Copyright © 2011-2022 走看看