示例#1
0
文件: Utils.cs 项目: gitshuaidong/MJ
 public static object DeSerialize(PacketBase msg)
 {
     if (null != msg && null != msg.data)
     {
         string className = msg.packetType.ToString();
         Type   type      = Type.GetType("packet.game." + className);
         if (null == type)
         {
             type = Type.GetType("packet.mj." + className);
             if (null == type)
             {
                 type = Type.GetType("packet.task." + className);
                 if (null == type)
                 {
                     type = Type.GetType("packet.user." + className);
                 }
             }
         }
         if (null == type)
         {
             Debug.LogFormat("DeSerialize GetType Err! packetType:{0}", msg.packetType.ToString());
             return(null);
         }
         object obj = NetSerilizer.DeSerialize(msg.data, type);
         if (null == obj)
         {
             Debug.LogFormat("DeSerialize Err! packetType:{0}", msg.packetType.ToString());
             return(null);
         }
         return(obj);
     }
     return(null);
 }
示例#2
0
    private void OnHangupSyn(PacketBase msg)
    {
        HangupSyn response = NetSerilizer.DeSerialize <HangupSyn>(msg.data);

        Game.MJMgr.HangUp = response.status == 1;// 1 托管  2 正常
        EventDispatcher.DispatchEvent(MessageCommand.MJ_UpdatePlayPage);
    }
示例#3
0
    private void OnUserInfoSyn(PacketBase msg)
    {
        if (msg.code == 0)
        {
            UserInfoSyn response = NetSerilizer.DeSerialize <UserInfoSyn>(msg.data);
            this.playerId = response.userId;
            this.nickname = response.nickName;
            this.coins    = response.coin;
            this.cards    = response.fanka;
            this.face     = response.headImg;
            //this.sex = response.sex;//性别 值为1时是男性,值为2时是女性,值为0时是未知
            this.sex = IconManager.GetSexByFace(response.sex, response.headImg);
            this.continueWinCount = response.continueWinCount;
            this.totalGameCount   = response.totalGameCount;
            this.winRate          = (float)response.winRate;
            this.ip              = response.ip;
            this.maxFanType      = response.maxFanType;
            this.handcard        = response.handcard;
            this.downcard        = response.downcard;
            this.createMultiRoom = response.createMultiRoom;

            Debug.LogFormat("OnUserInfoSyn playerId:{0};nickname:{1};face:{2};", playerId, nickname, face);

            EventDispatcher.DispatchEvent(MessageCommand.Update_UserInfo);
        }
    }
示例#4
0
    public void DoGameOperPlayerActionSyn(int action, params int[] card)
    {
        Debug.LogFormat("=>DoActionSyn action:{0},card1:{1},card2:{2}", ActionStr(action), card.Length > 0 ? GetCardStr(card[0]) : GetCardStr(-1), card.Length > 1 ? GetCardStr(card[1]) : GetCardStr(-1));
        RoomMgr.actionNotify.actions = 0;

        GameOperPlayerActionSyn content = new GameOperPlayerActionSyn();

        content.action = action;
        content.cardValue.AddRange(card);

        GameOperation request = new GameOperation()
        {
            operType = GameOperType.GameOperPlayerActionSyn
        };

        request.content = NetSerilizer.Serialize <GameOperPlayerActionSyn>(content);

        PacketBase msg = new PacketBase()
        {
            packetType = PacketType.GameOperation
        };

        msg.data = NetSerilizer.Serialize <GameOperation>(request);
        SocketNetTools.SendMsg(msg);
    }
示例#5
0
    void OnLogin(PacketBase msg)
    {
        //Game.LoadingPage.Hide();
        if (msg.code == 0)
        {
            GDM.Save(SAVE_DATA_TYPE.GameData);

            LoginResponse response = NetSerilizer.DeSerialize <LoginResponse>(msg.data);
            Game.Instance.playerId = response.userId;
            Game.Instance.token    = response.token;

            Game.InitHallSocket(response.hallServerAddr);
            Game.InitMsgSocket(response.msgServerAddr);
            Game.InitGameSocket(response.gameServerAddr);

            //EventDispatcher.DispatchEvent(MessageCommand.LoginSucess);

            //Game.StateMachine.SetNext(Game.StateMachine.MenuState);
            Game.Reset();

            Game.SocketHall.DoRoomConfigRequest();
            //Game.SocketHall.DoRankRequest();

            Game.UIMgr.PushScene(UIPage.MainPage);
        }
        else
        {
            Game.DialogMgr.PushDialog(UIDialog.SingleBtnDialog, msg.msg);
        }
    }
示例#6
0
 void OnPlayerExitSyn(PacketBase msg)
 {
     if (msg.code == 0)
     {
         PlayerExitSyn response = NetSerilizer.DeSerialize <PlayerExitSyn>(msg.data);
         if (Game.IsSelf(response.playerId))
         {
             Game.Instance.state = GameState.Hall;
             Game.UIMgr.PushScene(UIPage.MainPage);
             return;
         }
         else
         {
             Player player = Game.MJMgr.GetPlayerById(response.playerId);
             if (null != player)
             {
                 Game.MJMgr.MjData[player.position].player = null;
                 EventDispatcher.DispatchEvent(MessageCommand.MJ_UpdatePlayPage);
             }
             else
             {
                 Debug.LogWarningFormat("Game.MJMgr.GetPlayerById == null! playerId={0}", response.playerId);
             }
         }
     }
 }
示例#7
0
    // 读取数据
    private void ReadData()
    {
        byte[] data = NetEncode.Decode(ref receiveCache);
        //说明获取到一条完整数据
        if (data != null)
        {
            PacketBase msg = NetSerilizer.DeSerialize <PacketBase>(data);
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
            string dataStr = Utils.ToStr(Utils.DeSerialize(msg));
            Debug.LogFormat("<<=:{0}; code:{1}; msg:{2};data:[{3}]", msg.packetType, msg.code, msg.msg, dataStr);
            //Debug.LogFormat("<<=:{0}; code:{1}; msg:{2};data:[{3}]", msg.packetType, msg.code, msg.msg, dataStr);
#endif

            //if(msg.code != 0 && string.IsNullOrEmpty(msg.msg) == false)
            //{
            //    Game.DialogMgr.ShowDialog1Btn(msg.msg);
            //}

            if (receiveCallBack != null)
            {
                receiveCallBack(msg);
            }
            //尾递归,继续读取数据
            ReadData();
        }
        else
        {
            isReceiving = false;
        }
    }
示例#8
0
    void OnPLAYER_SIT_SYN(PacketBase msg)
    {
        if (msg.code == 0)
        {
            PlayerSitSyn response = NetSerilizer.DeSerialize <PlayerSitSyn>(msg.data);

            Debug.LogFormat("===OnPLAYER_SIT_SYN:" + Utils.ToStr(response));

            Player player = new Player();
            player.position   = response.position;
            player.playerId   = response.playerId;
            player.sex        = IconManager.GetSexByFace(response.sex, response.headImg);
            player.nickName   = response.nickName;
            player.headImg    = response.headImg;
            player.coin       = response.coin;
            player.score      = response.score;
            player.offline    = (response.online == 0);
            player.isReady[0] = (response.state == 1);
            player.leave      = (response.away == 1);
            player.ip         = response.ip;

            Game.MJMgr.MjData[player.position].player = player;

            if (player.playerId == Game.Instance.playerId)
            {
                Game.MJMgr.IntPosition(player.position);
                Game.MJTable.SetDirection(player.position);
            }

            int index = Game.MJMgr.GetIndexByPosition(response.position);
            Game.MJMgr.players[index].postion = response.position;

            EventDispatcher.DispatchEvent(MessageCommand.MJ_UpdatePlayPage);
        }
    }
示例#9
0
 private void OnActAndNoticeMsgSyn(PacketBase msg)
 {
     if (msg.code == 0)
     {
         ActAndNoticeMsgSyn response = NetSerilizer.DeSerialize <ActAndNoticeMsgSyn>(msg.data);
         Game.Instance.SetActAndNoticeMsg(response);
     }
 }
示例#10
0
 private void OnMarqueeMsgSyn(PacketBase msg)
 {
     if (msg.code == 0)
     {
         MarqueeMsgSyn response = NetSerilizer.DeSerialize <MarqueeMsgSyn>(msg.data);
         Game.Instance.SetMarqueeMsg(response);
     }
 }
示例#11
0
 private void OnNewMailMsgSyn(PacketBase msg)
 {
     if (msg.code == 0)
     {
         NewMailMsgSyn response = NetSerilizer.DeSerialize <NewMailMsgSyn>(msg.data);
         Game.Instance.SetNewMailMsg(response);
     }
 }
示例#12
0
    private void OnLogoutSyn(PacketBase msg)
    {
        LogoutSyn response = NetSerilizer.DeSerialize <LogoutSyn>(msg.data);

        Game.DialogMgr.PushDialogImmediately(UIDialog.SingleBtnDialog, response.reason, new System.Action(() =>
        {
            Game.Logout();
        }));
    }
示例#13
0
    public static void OnServerChangeSyn(PacketBase msg)
    {
        ServerChangeSyn response = NetSerilizer.DeSerialize <ServerChangeSyn>(msg.data);

        Game.InitHallSocket(response.hallServerAddr);
        Game.InitMsgSocket(response.msgServerAddr);
        Game.InitGameSocket(response.gameServerAddr);

        Debug.LogFormat("hallServerAddr:{0}; msgServerAddr:{1}; gameServerAddr:{2}", response.hallServerAddr, response.msgServerAddr, response.gameServerAddr);
    }
示例#14
0
    private void OnLogoutSyn(PacketBase msg)
    {
        LogoutSyn response = NetSerilizer.DeSerialize <LogoutSyn>(msg.data);
        Action    callback = () =>
        {
            Game.Logout();
        };

        Game.DialogMgr.PushDialog(UIDialog.SingleBtnDialog, response.reason, "提示", callback);
    }
示例#15
0
    public void DoLoadVipRoom(Action <VipRoomListSyn> callback)
    {
        PacketBase msg = new PacketBase()
        {
            packetType = PacketType.VipRoomListReuqest
        };

        SocketNetTools.SendMsg(msg, PacketType.VipRoomListSyn, (data) => {
            VipRoomListSyn result = NetSerilizer.DeSerialize <VipRoomListSyn>(data.data);
            callback(result);
        });
    }
示例#16
0
 void OnVipRoomListSyn(PacketBase msg)
 {
     if (0 == msg.code)
     {
         result = NetSerilizer.DeSerialize <VipRoomListSyn>(msg.data);
         SetupUI();
     }
     else
     {
         Game.DialogMgr.PushDialog(UIDialog.SingleBtnDialog, msg.msg);
     }
 }
示例#17
0
 private void OnDissmissVoteSyn(PacketBase msg)
 {
     if (msg.code == 0)
     {
         DissmissVoteSyn response = NetSerilizer.DeSerialize <DissmissVoteSyn>(msg.data);
         MjData          player   = Game.MJMgr.MjData[response.position];
         Action <bool>   callback = (ok) => {
             DoDissmissVoteSyn(ok);
         };
         Game.DialogMgr.PushDialog(UIDialog.DoubleBtnDialog, player.player.nickName + "申请解散房间", "提示", callback);
     }
 }
示例#18
0
    public void DoShareRequest()
    {
        PacketBase msg = new PacketBase()
        {
            packetType = PacketType.ShareRequest
        };
        ShareRequest request = new ShareRequest()
        {
        };

        msg.data = NetSerilizer.Serialize(request);
        SocketNetTools.SendMsg(msg);
    }
示例#19
0
    public void DoRoomConfigRequest()
    {
        PacketBase msg = new PacketBase()
        {
            packetType = PacketType.RoomConfigRequest
        };

        SocketNetTools.SendMsg(msg, PacketType.RoomConfigResponse, (data) =>
        {
            RoomConfigResponse response = NetSerilizer.DeSerialize <RoomConfigResponse>(data.data);
            Game.Instance.RoomConfig    = response;
        });
    }
示例#20
0
    public void DoPlayerGamingSynInquire(Action <bool> callback)
    {
        PacketBase msg = new PacketBase()
        {
            packetType = PacketType.PlayerGamingSynInquire
        };

        SocketNetTools.SendMsg(msg, PacketType.PlayerGamingSynInquire, (data) =>
        {
            PlayerGamingSynInquire result = NetSerilizer.DeSerialize <PlayerGamingSynInquire>(data.data);
            callback(result.isGaming);
        });
    }
示例#21
0
    public void Auth(int userId, string token)
    {
        PacketBase msg = new PacketBase()
        {
            packetType = PacketType.AuthRequest
        };
        AuthRequest request = new AuthRequest()
        {
            userId = userId, token = token, version = GlobalConfig.GetVersion
        };

        msg.data = NetSerilizer.Serialize(request);
        SocketNetTools.SendMsg(msg);
    }
示例#22
0
    public void DoDissmissVoteSyn(bool ok)
    {
        PacketBase msg = new PacketBase()
        {
            packetType = PacketType.DissmissVoteSyn
        };
        DissmissVoteSyn request = new DissmissVoteSyn()
        {
            agree = ok
        };

        msg.data = NetSerilizer.Serialize(request);
        SocketNetTools.SendMsg(msg);
    }
示例#23
0
    public void DoReceiveMailAttachRequest(long msgId)
    {
        PacketBase msg = new PacketBase()
        {
            packetType = PacketType.ReceiveMailAttachRequest
        };
        ReadMailMsgRequest request = new ReadMailMsgRequest()
        {
            msgId = msgId
        };

        msg.data = NetSerilizer.Serialize(request);
        SocketNetTools.SendMsg(msg);
    }
示例#24
0
    public void DoKickPlayer(string code, int playerId)
    {
        PacketBase msg = new PacketBase()
        {
            packetType = PacketType.KickPlayerRequest
        };
        KickPlayerRequest request = new KickPlayerRequest()
        {
            code = code, playerId = playerId
        };

        msg.data = NetSerilizer.Serialize(request);
        SocketNetTools.SendMsg(msg);
    }
示例#25
0
    public void DoDismissVipRoom(string code)
    {
        PacketBase msg = new PacketBase()
        {
            packetType = PacketType.DismissVipRoomRequest
        };
        DismissVipRoomRequest request = new DismissVipRoomRequest()
        {
            code = code
        };

        msg.data = NetSerilizer.Serialize(request);
        SocketNetTools.SendMsg(msg);
    }
示例#26
0
    public void DoModifyUserInfoRequest(string headImg, string nickName)
    {
        PacketBase msg = new PacketBase()
        {
            packetType = PacketType.ModifyUserInfoRequest
        };
        ModifyUserInfoRequest request = new ModifyUserInfoRequest()
        {
            headImg = headImg, nickName = nickName
        };

        msg.data = NetSerilizer.Serialize(request);
        SocketNetTools.SendMsg(msg);
    }
示例#27
0
    public void DoMallProductRequest(Action callback)
    {
        PacketBase msg = new PacketBase()
        {
            packetType = PacketType.MallProductRequest
        };

        SocketNetTools.SendMsg(msg, PacketType.MallProductResponse, (data) =>
        {
            MallProductResponse response = NetSerilizer.DeSerialize <MallProductResponse>(data.data);
            Game.Instance.MallProduct    = response;
            callback();
        });
    }
示例#28
0
    public void DoREADYL(int state, int phase) //TODO WXD send ready
    {
        PacketBase msg = new PacketBase()
        {
            packetType = PacketType.ReadyRequest
        };
        ReadyRequest request = new ReadyRequest()
        {
            state = state, phase = phase
        };

        msg.data = NetSerilizer.Serialize(request);
        SocketNetTools.SendMsg(msg);
    }
示例#29
0
    void OnGAMING_SYN(PacketBase msg)
    {
        if (msg.code == 0)
        {
            PlayerGamingSyn response = NetSerilizer.DeSerialize <PlayerGamingSyn>(msg.data);

            Game.Instance.state = GameState.Waitting;

            Debug.Log("===OnGAMING_SYN [" + GetWanfa(response.wanfa) + "]");
            Game.MJMgr.targetFlag.gameObject.SetActive(false);

            RoomMgr.Reset();
            RoomMgr.playerGamingSyn = response;

            Game.MJTable.roomNum.text   = "";
            Game.MJTable.baseScore.text = "";
            if (!RoomMgr.IsSingeRoom())
            {
                if (!RoomMgr.IsVipRoom())
                {
                    RoomConfigModel config = Game.Instance.GetRoomInfo(response.matchId);
                    if (null != config)
                    {
                        Game.MJTable.baseScore.text = string.Format("底分:{0}", config.baseScore);
                        Game.Instance.baseScore     = config.baseScore;
                    }
                }
                else
                {
                    Game.MJTable.roomNum.text = string.Format("房间号:{0}", response.deskId);
                }
            }

            int col = RoomMgr.IsVip2Room() ? 10 : 6;
            Game.MJMgr.players[0].dropCardLayout.col = col;
            Game.MJMgr.players[1].dropCardLayout.col = col;
            Game.MJMgr.players[2].dropCardLayout.col = col;
            Game.MJMgr.players[3].dropCardLayout.col = col;

            if (Game.UIMgr.IsSceneActive(UIPage.PlayPage))
            {
                EventDispatcher.DispatchEvent(MessageCommand.MJ_UpdatePlayPage);
            }
            else
            {
                Game.UIMgr.PushScene(UIPage.PlayPage);
            }
        }
    }
示例#30
0
    public void DoGameChatMsgRequest(byte[] content)
    {
        int        contentType = 3;//类型 1 文字 2图片 3语音
        PacketBase msg         = new PacketBase()
        {
            packetType = PacketType.GameChatMsgRequest
        };
        GameChatMsgRequest request = new GameChatMsgRequest()
        {
            contentType = contentType, content = content
        };

        msg.data = NetSerilizer.Serialize(request);
        SocketNetTools.SendMsg(msg);
    }