Пример #1
0
    // 处理客户端的请求
    void doAskCilentReq(object obj)
    {
        ReceiveObj receiveObj = (ReceiveObj)obj;
        string     text       = receiveObj.m_data;

        // 日志
        {
            PlayerData playerData = GameUtil.getPlayerDataByConnId(receiveObj.m_connId);
            if (playerData != null)
            {
                RoomData room = GameUtil.getRoomByUid(playerData.m_uid);
                if (room != null)
                {
                    LogUtil.getInstance().writeRoomLog(room, "收到客户端消息:" + text);
                }
                else
                {
                    LogUtil.getInstance().addDebugLog("收到客户端消息:" + text);
                }
            }
            else
            {
                LogUtil.getInstance().addDebugLog("收到客户端消息:" + text);
            }
        }

        JObject jo;

        try
        {
            jo = JObject.Parse(text);
        }
        catch (JsonReaderException ex)
        {
            // 传过来的数据不是json格式的,一律不理
            // 日志
            {
                PlayerData playerData = GameUtil.getPlayerDataByConnId(receiveObj.m_connId);
                if (playerData != null)
                {
                    RoomData room = GameUtil.getRoomByUid(playerData.m_uid);
                    if (room != null)
                    {
                        LogUtil.getInstance().writeRoomLog(room, "客户端传来非json数据:" + text);
                    }
                    else
                    {
                        LogUtil.getInstance().addDebugLog("客户端传来非json数据:" + text);
                    }
                }
                else
                {
                    LogUtil.getInstance().addDebugLog("客户端传来非json数据:" + text);
                }
            }

            m_endStr = "";

            return;
        }

        if (jo.GetValue("tag") != null)
        {
            string tag = jo.GetValue("tag").ToString();

            // 休闲场相关
            if (tag.CompareTo(TLJCommon.Consts.Tag_XiuXianChang) == 0)
            {
                PlayLogic_Relax.getInstance().OnReceive(receiveObj.m_connId, text);
            }
            // 比赛场相关
            else if (tag.CompareTo(TLJCommon.Consts.Tag_JingJiChang) == 0)
            {
                PlayLogic_PVP.getInstance().OnReceive(receiveObj.m_connId, text);
            }
            // 获取pvp场次信息
            else if (tag.CompareTo(TLJCommon.Consts.Tag_GetPVPGameRoom) == 0)
            {
                NetRespond_GetPVPGameRoom.doAskCilentReq_GetPVPGameRoom(receiveObj.m_connId, text);
            }
            // 请求服务器在线玩家信息接口
            else if (tag.CompareTo(TLJCommon.Consts.Tag_OnlineInfo) == 0)
            {
                NetRespond_OnlineInfo.doAskCilentReq_OnlineInfo(receiveObj.m_connId, text);
            }
            // 使用buff
            else if (tag.CompareTo(TLJCommon.Consts.Tag_UseBuff) == 0)
            {
                NetRespond_UseBuff.doAskCilentReq_UseBuff(receiveObj.m_connId, text);
            }
            // 是否已经加入游戏
            else if (tag.CompareTo(TLJCommon.Consts.Tag_IsJoinGame) == 0)
            {
                NetRespond_IsJoinGame.doAskCilentReq_IsJoinGame(receiveObj.m_connId, text);
            }
            // 请求恢复房间
            else if (tag.CompareTo(TLJCommon.Consts.Tag_RetryJoinGame) == 0)
            {
                NetRespond_RetryJoinGame.doAskCilentReq_RetryJoinGame(receiveObj.m_connId, text);
            }
            // 自定义牌型
            else if (tag.CompareTo(TLJCommon.Consts.Tag_DebugSetPoker) == 0)
            {
                NetRespond_DebugSetPoker.doAskCilentReq_DebugSetPoker(receiveObj.m_connId, text);
            }
            // 心跳
            else if (tag.CompareTo(TLJCommon.Consts.Tag_HeartBeat_Play) == 0)
            {
                NetRespond_HeartBeat_Play.doAskCilentReq_HeartBeat_Play(receiveObj.m_connId, text);
            }
            // 解散房间
            else if (tag.CompareTo(TLJCommon.Consts.Tag_BreakRoom) == 0)
            {
                NetRespond_BreakRoom.doAskCilentReq_BreakRoom(receiveObj.m_connId, text);
            }
            // 斗地主相关
            else if (tag.CompareTo(TLJCommon.Consts.Tag_DouDiZhu_Game) == 0)
            {
                PlayLogic_DDZ.getInstance().OnReceive(receiveObj.m_connId, text);
            }
            // 未知Tag
            else
            {
                LogUtil.getInstance().addDebugLog("未知Tag:" + tag);
            }
        }
        else
        {
            // 传过来的数据没有tag字段的,一律不理
            // 日志
            {
                PlayerData playerData = GameUtil.getPlayerDataByConnId(receiveObj.m_connId);
                if (playerData != null)
                {
                    RoomData room = GameUtil.getRoomByUid(playerData.m_uid);
                    if (room != null)
                    {
                        LogUtil.getInstance().writeRoomLog(room, "客户端传来的数据没有Tag:" + text);
                    }
                    else
                    {
                        LogUtil.getInstance().addDebugLog("客户端传来的数据没有Tag:" + text);
                    }
                }
                else
                {
                    LogUtil.getInstance().addDebugLog("客户端传来的数据没有Tag:" + text);
                }
            }
            return;
        }
    }
    // 处理客户端的请求
    void doAskCilentReq(object obj)
    {
        // 模拟耗时操作,比如数据库操作,IO操作
        // Thread.Sleep(3000);

        ReceiveObj receiveObj = (ReceiveObj)obj;
        string     text       = receiveObj.m_data;

        LogUtil.getInstance().addDebugLog("收到客户端消息:" + text);

        JObject jo;

        try
        {
            jo = JObject.Parse(text);
        }
        catch (JsonReaderException ex)
        {
            // 传过来的数据不是json格式的,一律不理
            LogUtil.getInstance().addDebugLog("客户端传来非json数据:" + text);

            m_endStr = "";

            return;
        }

        if (jo.GetValue("tag") != null)
        {
            string tag = jo.GetValue("tag").ToString();

            // 请求登录接口
            if (tag.CompareTo(TLJCommon.Consts.Tag_Login) == 0)
            {
                NetRespond_Login.doAskCilentReq_Login(receiveObj.m_connId, text);
            }
            // 请求第三方登录
            else if (tag.CompareTo(TLJCommon.Consts.Tag_Third_Login) == 0)
            {
                NetRespond_ThirdLogin.doAskCilentReq_ThirdLogin(receiveObj.m_connId, text);
            }
            // 请求快速注册接口
            else if (tag.CompareTo(TLJCommon.Consts.Tag_QuickRegister) == 0)
            {
                NetRespond_QuickRegister.doAskCilentReq_QuickRegister(receiveObj.m_connId, text);
            }
            // 请求服务器在线玩家信息接口
            else if (tag.CompareTo(TLJCommon.Consts.Tag_OnlineInfo) == 0)
            {
                NetRespond_OnlineInfo.doAskCilentReq_OnlineInfo(receiveObj.m_connId, text);
            }
            // 检查版本
            else if (tag.CompareTo(TLJCommon.Consts.Tag_CheckVerisionCode) == 0)
            {
                NetRespond_CheckVerisionCode.doAskCilentReq_CheckVerisionCode(receiveObj.m_connId, text);
            }
            // 检查版本
            else if (tag.CompareTo(TLJCommon.Consts.Tag_LoginDataStatistics) == 0)
            {
                NetRespond_LoginDataStatistics.doAskCilentReq_LoginDataStatistics(receiveObj.m_connId, text);
            }
            else
            {
                LogUtil.getInstance().addDebugLog("未知Tag:" + tag);
            }
        }
        else
        {
            // 传过来的数据没有tag字段的,一律不理
            LogUtil.getInstance().addDebugLog("客户端传来的数据没有Tag:" + text);
            return;
        }
    }