Exemplo n.º 1
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);
        }
    }
Exemplo n.º 2
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);
        }
    }
Exemplo n.º 3
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);
    }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
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;
        }
    }
Exemplo n.º 6
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);
        }
    }
Exemplo n.º 7
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);
             }
         }
     }
 }
Exemplo n.º 8
0
 private void OnActAndNoticeMsgSyn(PacketBase msg)
 {
     if (msg.code == 0)
     {
         ActAndNoticeMsgSyn response = NetSerilizer.DeSerialize <ActAndNoticeMsgSyn>(msg.data);
         Game.Instance.SetActAndNoticeMsg(response);
     }
 }
Exemplo n.º 9
0
 private void OnNewMailMsgSyn(PacketBase msg)
 {
     if (msg.code == 0)
     {
         NewMailMsgSyn response = NetSerilizer.DeSerialize <NewMailMsgSyn>(msg.data);
         Game.Instance.SetNewMailMsg(response);
     }
 }
Exemplo n.º 10
0
 private void OnMarqueeMsgSyn(PacketBase msg)
 {
     if (msg.code == 0)
     {
         MarqueeMsgSyn response = NetSerilizer.DeSerialize <MarqueeMsgSyn>(msg.data);
         Game.Instance.SetMarqueeMsg(response);
     }
 }
Exemplo n.º 11
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();
        }));
    }
Exemplo n.º 12
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);
    }
Exemplo n.º 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);
    }
Exemplo n.º 14
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);
     }
 }
Exemplo n.º 15
0
 void OnVipRoomListSyn(PacketBase msg)
 {
     if (0 == msg.code)
     {
         result = NetSerilizer.DeSerialize <VipRoomListSyn>(msg.data);
         SetupUI();
     }
     else
     {
         Game.DialogMgr.PushDialog(UIDialog.SingleBtnDialog, msg.msg);
     }
 }
Exemplo n.º 16
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);
        });
    }
Exemplo n.º 17
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);
        });
    }
Exemplo n.º 18
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;
        });
    }
Exemplo n.º 19
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();
        });
    }
Exemplo n.º 20
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);
            }
        }
    }
Exemplo n.º 21
0
    public void DoRankRequest()
    {
        PacketBase msg = new PacketBase()
        {
            packetType = PacketType.RankRequest
        };

        SocketNetTools.SendMsg(msg, PacketType.RankSyn, (data) =>
        {
            RankSyn response      = NetSerilizer.DeSerialize <RankSyn>(data.data);
            Game.Instance.RankSyn = response;

            EventDispatcher.DispatchEvent(MessageCommand.Update_Rank);
        });
    }
Exemplo n.º 22
0
 void OnREADY_SYN(PacketBase msg)
 {
     if (msg.code == 0)
     {
         ReadySyn response = NetSerilizer.DeSerialize <ReadySyn>(msg.data);
         Player   player   = Game.MJMgr.GetPlayerById(response.playerId);
         if (null != player)
         {
             player.isReady = (response.state == 1);
             EventDispatcher.DispatchEvent(MessageCommand.MJ_UpdatePlayPage);
         }
     }
     else if (msg.code == (int)ErrCode.NotEnoughCoins)
     {
         // TODO 金币不足  无法准备
     }
 }
Exemplo n.º 23
0
    public void DoGenOrderRequest(int platformId, string productId, Action <GenOrderResponse> callback)
    {
        PacketBase msg = new PacketBase()
        {
            packetType = PacketType.GenOrderRequest
        };
        GenOrderRequest request = new GenOrderRequest()
        {
            platformId = platformId, productId = productId
        };

        msg.data = NetSerilizer.Serialize(request);
        SocketNetTools.SendMsg(msg, PacketType.GenOrderResponse, (data) =>
        {
            GenOrderResponse response = NetSerilizer.DeSerialize <GenOrderResponse>(data.data);
            callback(response);
        });
    }
Exemplo n.º 24
0
    void OnPlayerReconnectSyn(PacketBase msg)
    {
        if (msg.code == 0)
        {
            PlayerReconnectSyn response = NetSerilizer.DeSerialize <PlayerReconnectSyn>(msg.data);
            Player             player   = Game.MJMgr.GetPlayerById(response.playerId);

            if (null != player)
            {
                Game.MJMgr.MjData[player.position].player.offline = false;
                EventDispatcher.DispatchEvent(MessageCommand.MJ_UpdatePlayPage);
            }
            else
            {
                Debug.LogWarningFormat("Game.MJMgr.GetPlayerById == null! playerId={0}", response.playerId);
            }
        }
    }
Exemplo n.º 25
0
 void OnPLAYER_COMEBACK(PacketBase msg)
 {
     if (msg.code == 0)
     {
         //TODO wxd away的时候,game.Instance会reset。为什么comeback的时候不用还原。
         PlayerComebackSyn response = NetSerilizer.DeSerialize <PlayerComebackSyn>(msg.data);
         Player            player   = Game.MJMgr.GetPlayerById(response.playerId);
         if (null != player)
         {
             Game.MJMgr.MjData[player.position].player.leave   = false;
             Game.MJMgr.MjData[player.position].player.offline = false;
             EventDispatcher.DispatchEvent(MessageCommand.MJ_UpdatePlayPage);
         }
         else
         {
             Debug.LogWarningFormat("Game.MJMgr.GetPlayerById == null! playerId={0}", response.playerId);
         }
     }
 }
Exemplo n.º 26
0
    public void DoRoomResult(long roomId, Action <RoomResultResponse> callback)
    {
        PacketBase msg = new PacketBase()
        {
            packetType = PacketType.RoomResultRequest
        };
        RoomResultRequest request = new RoomResultRequest()
        {
            roomId = roomId
        };

        msg.data = NetSerilizer.Serialize(request);

        SocketNetTools.SendMsg(msg, PacketType.RoomResultResponse, (data) =>
        {
            RoomResultResponse response = NetSerilizer.DeSerialize <RoomResultResponse>(data.data);
            callback(response);
        });
    }
Exemplo n.º 27
0
    public void DoCreateVipRoom(int vipRoomType, int quanNum, int wangfa, Action <VipRoomListSyn> callback)
    {
        PacketBase msg = new PacketBase()
        {
            packetType = PacketType.CreateVipRoomRequest
        };
        CreateVipRoomRequest request = new CreateVipRoomRequest();

        request.vipRoomType = vipRoomType;
        request.quanNum     = quanNum;
        //request.vipRoomType = 0;
        request.wangfa = wangfa;

        msg.data = NetSerilizer.Serialize(request);

        SocketNetTools.SendMsg(msg, PacketType.VipRoomListSyn, (data) => {
            VipRoomListSyn result = NetSerilizer.DeSerialize <VipRoomListSyn>(data.data);
            callback(result);
        });
    }
Exemplo n.º 28
0
    void _OnGameOperation(GameOperation response)
    {
        switch (response.operType)
        {
        case GameOperType.GameOperStartSyn:
            OnGameOperStartSyn(NetSerilizer.DeSerialize <GameOperStartSyn>(response.content));
            break;

        case GameOperType.GameOperHandCardSyn:
            //OnGameOperHandCardSyn(NetSerilizer.DeSerialize<GameOperHandCardSyn>(response.content));
            break;

        case GameOperType.GameOperPublicInfoSyn:
            OnGameOperPublicInfoSyn(NetSerilizer.DeSerialize <GameOperPublicInfoSyn>(response.content));
            break;

        case GameOperType.GameOperPlayerHuSyn:
            OnGameOperPlayerHuSyn(NetSerilizer.DeSerialize <GameOperPlayerHuSyn>(response.content));
            break;

        case GameOperType.GameOperPlayerActionNotify:
            OnGameOperPlayerActionNotify(NetSerilizer.DeSerialize <GameOperPlayerActionNotify>(response.content));
            break;

        case GameOperType.GameOperActorSyn:
            OnGameOperActorSyn(NetSerilizer.DeSerialize <GameOperActorSyn>(response.content));
            break;

        case GameOperType.GameOperPlayerActionSyn:
            OnGameOperPlayerActionSyn(NetSerilizer.DeSerialize <GameOperPlayerActionSyn>(response.content));
            break;

        case GameOperType.GameOperBaoChangeSyn:
            OnGameOperBaoChangeSyn(NetSerilizer.DeSerialize <GameOperBaoChangeSyn>(response.content));
            break;

        case GameOperType.GameOperFinalSettleSyn:
            OnGameOperFinalSettleSyn(NetSerilizer.DeSerialize <GameOperFinalSettleSyn>(response.content));
            break;
        }
    }
Exemplo n.º 29
0
 private void OnGameChatMsgSyn(PacketBase msg)
 {
     if (msg.code == 0)
     {
         GameChatMsgSyn response = NetSerilizer.DeSerialize <GameChatMsgSyn>(msg.data);
         Debug.LogFormat("===OnGameChatMsgSyn:" + Utils.ToStr(response));
         //类型 1 文字 2图片 3语音
         if (response.contentType == 1)
         {
             string str = System.Text.Encoding.Default.GetString(response.data);
             if (null != str && str.StartsWith("[") && str.EndsWith("]"))
             {
                 string sId = str.Substring(1, str.Length - 2);
                 int    id  = 0;
                 int.TryParse(sId, out id);
                 if (id < 100)
                 {
                     // 表情
                     EventDispatcher.DispatchEvent(MessageCommand.Chat, response.position, 0, id);
                 }
                 else
                 {
                     // 短语
                     EventDispatcher.DispatchEvent(MessageCommand.Chat, response.position, 1, id);
                 }
                 print(id);
             }
             else
             {
                 // 文字
                 print(str);
                 EventDispatcher.DispatchEvent(MessageCommand.Chat, response.position, 2, str);
             }
         }
         else
         {
             // 语音
             EventDispatcher.DispatchEvent(MessageCommand.Chat, response.position, 3, response.data);
         }
     }
 }
Exemplo n.º 30
0
    /// <summary>
    /// 读取数据
    /// </summary>
    private void ReadData()
    {
        byte[] data = NetEncode.Decode(ref receiveCache);

        //如果数据读取成功
        if (null != data)
        {
            NetModel item = NetSerilizer.DeSerialize(data);
            Debug.Log(item.ID + "," + item.Commit + "," + item.Message);
            if (null != receiveCallback)
            {
                receiveCallback(item);
            }
            //尾递归,继续处理数据
            ReadData();
        }
        else
        {
            isReceiving = false;
        }
    }