Esempio n. 1
0
    public static int getGameRoomPlayerCount(string gameRoomType)
    {
        int count = 0;

        for (int i = 0; i < PlayLogic_PVP.getInstance().getRoomList().Count; i++)
        {
            RoomData tempRoom = PlayLogic_PVP.getInstance().getRoomList()[i];
            if (tempRoom.m_gameRoomType.CompareTo(gameRoomType) == 0)
            {
                for (int j = 0; j < tempRoom.getPlayerDataList().Count; j++)
                {
                    ++count;
                }
            }
        }

        return(count);
    }
Esempio n. 2
0
    public static bool checkPlayerIsInRoom(string uid)
    {
        bool b = false;

        // 先在休闲场里找
        for (int i = 0; i < PlayLogic_Relax.getInstance().getRoomList().Count; i++)
        {
            List <PlayerData> playerDataList = PlayLogic_Relax.getInstance().getRoomList()[i].getPlayerDataList();

            for (int j = 0; j < playerDataList.Count; j++)
            {
                if (playerDataList[j].m_uid.CompareTo(uid) == 0)
                {
                    b = true;
                    break;
                }
            }
        }

        // 然后在比赛场里找
        if (!b)
        {
            for (int i = 0; i < PlayLogic_PVP.getInstance().getRoomList().Count; i++)
            {
                List <PlayerData> playerDataList = PlayLogic_PVP.getInstance().getRoomList()[i].getPlayerDataList();

                for (int j = 0; j < playerDataList.Count; j++)
                {
                    if (playerDataList[j].m_uid.CompareTo(uid) == 0)
                    {
                        b = true;
                        break;
                    }
                }
            }
        }

        return(b);
    }
Esempio n. 3
0
    public static PlayerData getPlayerDataByConnId(IntPtr connId)
    {
        PlayerData playerData = null;

        // 先在休闲场里找
        for (int i = 0; i < PlayLogic_Relax.getInstance().getRoomList().Count; i++)
        {
            List <PlayerData> playerDataList = PlayLogic_Relax.getInstance().getRoomList()[i].getPlayerDataList();

            for (int j = 0; j < playerDataList.Count; j++)
            {
                if (playerDataList[j].m_connId == connId)
                {
                    playerData = playerDataList[j];

                    return(playerData);
                }
            }
        }

        // 然后在比赛场里找
        for (int i = 0; i < PlayLogic_PVP.getInstance().getRoomList().Count; i++)
        {
            List <PlayerData> playerDataList = PlayLogic_PVP.getInstance().getRoomList()[i].getPlayerDataList();

            for (int j = 0; j < playerDataList.Count; j++)
            {
                if (playerDataList[j].m_connId == connId)
                {
                    playerData = playerDataList[j];

                    return(playerData);
                }
            }
        }

        return(playerData);
    }
Esempio n. 4
0
    public static PlayerData getPlayerDataByUid(string uid)
    {
        PlayerData playerData = null;

        // 先在休闲场里找
        for (int i = 0; i < PlayLogic_Relax.getInstance().getRoomList().Count; i++)
        {
            List <PlayerData> playerDataList = PlayLogic_Relax.getInstance().getRoomList()[i].getPlayerDataList();

            for (int j = 0; j < playerDataList.Count; j++)
            {
                if (playerDataList[j].m_uid.CompareTo(uid) == 0)
                {
                    playerData = playerDataList[j];

                    return(playerData);
                }
            }
        }

        // 然后在比赛场里找
        for (int i = 0; i < PlayLogic_PVP.getInstance().getRoomList().Count; i++)
        {
            List <PlayerData> playerDataList = PlayLogic_PVP.getInstance().getRoomList()[i].getPlayerDataList();

            for (int j = 0; j < playerDataList.Count; j++)
            {
                if (playerDataList[j].m_uid.CompareTo(uid) == 0)
                {
                    playerData = playerDataList[j];

                    return(playerData);
                }
            }
        }

        return(playerData);
    }
    void hasPlayerExit(object obj)
    {
        IntPtr connId = (IntPtr)obj;

        PlayerData playerData = GameUtil.getPlayerDataByConnId(connId);

        if (playerData == null)
        {
            LogUtil.getInstance().addDebugLog("踢出玩家失败,找不到IntPtr:" + connId + "对应的玩家");
            return;
        }

        if (PlayLogic_Relax.getInstance().doTaskPlayerCloseConn(playerData.m_uid))
        {
            // 日志
            {
                if (playerData != null)
                {
                    RoomData room = GameUtil.getRoomByUid(playerData.m_uid);
                    if (room != null)
                    {
                        LogUtil.getInstance().writeRoomLog(room, "踢出玩家成功:" + connId);
                    }
                    else
                    {
                        LogUtil.getInstance().addDebugLog("踢出玩家成功:" + connId);
                    }
                }
                else
                {
                    LogUtil.getInstance().addDebugLog("踢出玩家成功:" + connId);
                }
            }
        }
        else if (PlayLogic_PVP.getInstance().doTaskPlayerCloseConn(playerData.m_uid))
        {
            // 日志
            {
                if (playerData != null)
                {
                    RoomData room = GameUtil.getRoomByUid(playerData.m_uid);
                    if (room != null)
                    {
                        LogUtil.getInstance().writeRoomLog(room, "踢出玩家成功:" + connId);
                    }
                    else
                    {
                        LogUtil.getInstance().addDebugLog("踢出玩家成功:" + connId);
                    }
                }
                else
                {
                    LogUtil.getInstance().addDebugLog("踢出玩家成功:" + connId);
                }
            }
        }
        else
        {
            LogUtil.getInstance().addDebugLog("踢出玩家失败,找不到该玩家:" + connId);
        }
    }
    // 处理客户端的请求
    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;
        }
    }