예제 #1
0
 //得到了场景里所有人的信息.有位置的.
 void OnEnterLevel(OnEnterLevelRsp rsp)
 {
     if (rsp.result == 1)
     {
         FrameSyncLocal.Ins.OnEnterLevel(rsp);
     }
     else
     {
         if (rsp.reason == EResult.CampMax)
         {
             U3D.PopupTip("阵营人数已满,无法进入");
             if (WeaponSelectDialogState.Exist)
             {
                 WeaponSelectDialogState.Instance.ShowBack();
             }
         }
         else if (rsp.reason == EResult.Timeup)
         {
             U3D.PopupTip("当前轮次即将结束,请稍后再进入");
             if (WeaponSelectDialogState.Exist)
             {
                 WeaponSelectDialogState.Instance.ShowTimeup((int)rsp.result);
             }
         }
     }
 }
예제 #2
0
 //TCP拉取场景玩家信息
 public void OnEnterLevel(OnEnterLevelRsp fr)
 {
     if (FrameReplay.Ins.Started)
     {
         netPlayers = fr;
         SyncNetPlayer();
     }
     else
     {
         netPlayers = fr;
     }
 }
예제 #3
0
 public void SyncNetPlayer()
 {
     if (netPlayers != null)
     {
         for (int i = 0; i < netPlayers.players.Count; i++)
         {
             PlayerSync player = netPlayers.players[i];
             MeteorUnit unit   = U3D.GetUnit((int)player.playerId);
             if (unit == null)
             {
                 U3D.OnCreateNetPlayer(player);
             }
         }
     }
     if (WeaponSelectDialogState.Exist)
     {
         Main.Ins.DialogStateManager.ChangeState(null);
     }
     FightState.State.Open();
     FrameSyncServer.Ins.Resume();
     netPlayers = null;
 }
예제 #4
0
 public void Reset()
 {
     mainPlayer = null;
     netPlayers = null;
     comingPlayers.Clear();
 }
예제 #5
0
    //套接口消息.
    public static void Update()
    {
        //处理网络消息
        lock (ClientProxy.Packet)
        {
            MemoryStream ms = null;
            foreach (var each in ClientProxy.Packet)
            {
                switch (each.Key)
                {
                case (int)MeteorMsg.MsgType.GetRoomRsp:
                    ms = new MemoryStream(each.Value);
                    GetRoomRsp rspG = ProtoBuf.Serializer.Deserialize <GetRoomRsp>(ms);
                    OnGetRoomRsp(rspG);
                    break;

                case (int)MeteorMsg.MsgType.JoinRoomRsp:
                    ms = new MemoryStream(each.Value);
                    JoinRoomRsp rspJ = ProtoBuf.Serializer.Deserialize <JoinRoomRsp>(ms);
                    OnJoinRoomRsp(rspJ);
                    break;

                case (int)MeteorMsg.MsgType.OnJoinRoomRsp:
                    ms = new MemoryStream(each.Value);
                    OnEnterRoomRsp rspE = ProtoBuf.Serializer.Deserialize <OnEnterRoomRsp>(ms);
                    OnEnterRoomRsp_(rspE);
                    break;

                case (int)MeteorMsg.MsgType.CreateRoomRsp:
                    ms = new MemoryStream(each.Value);
                    CreateRoomRsp rspC = ProtoBuf.Serializer.Deserialize <CreateRoomRsp>(ms);
                    OnCreateRoomRsp(rspC);
                    break;

                case (int)MeteorMsg.MsgType.EnterLevelRsp:
                    ms = new MemoryStream(each.Value);
                    EnterLevelRsp rspER = ProtoBuf.Serializer.Deserialize <EnterLevelRsp>(ms);
                    EnterLevelRsp_(rspER);
                    break;

                case (int)MeteorMsg.MsgType.OnEnterLevelRsp:
                    ms = new MemoryStream(each.Value);
                    OnEnterLevelRsp rspOE = ProtoBuf.Serializer.Deserialize <OnEnterLevelRsp>(ms);
                    OnEnterLevelRsp_(rspOE);
                    break;

                case (int)MeteorMsg.MsgType.OnLeaveRoomRsp:
                    ms = new MemoryStream(each.Value);
                    OnLeaveRoomRsp rspL = ProtoBuf.Serializer.Deserialize <OnLeaveRoomRsp>(ms);
                    OnLevvaRoomRsp_(rspL);
                    break;

                case (int)MeteorMsg.MsgType.SyncInput:
                    ms = new MemoryStream(each.Value);
                    InputReq InputRsp = ProtoBuf.Serializer.Deserialize <InputReq>(ms);
                    OnSyncInputRsp(InputRsp);
                    break;

                case (int)MeteorMsg.MsgType.SyncKeyFrame:
                    ms = new MemoryStream(each.Value);
                    KeyFrame KeyFrameRsp = ProtoBuf.Serializer.Deserialize <KeyFrame>(ms);
                    OnSyncKeyFrame(KeyFrameRsp);
                    break;
                }
            }
            ClientProxy.Packet.Clear();
        }

        lock (messageQueue)
        {
            int length = messageQueue.Count;
            for (int i = 0; i < length; i++)
            {
                switch (messageQueue[i].Message)
                {
                case (short)LocalMsgType.Connect: OnConnect(messageQueue[i].Result); break;

                case (short)LocalMsgType.DisConnect: OnDisconnect(); break;

                case (short)LocalMsgType.SendFTPLogComplete: OnSendComplete(messageQueue[i].Result, messageQueue[i].Param); break;
                }
            }
            messageQueue.Clear();
        }
    }
예제 #6
0
 static void OnEnterLevelRsp_(OnEnterLevelRsp rsp)
 {
 }
예제 #7
0
    public override void Update()
    {
        for (int i = 0; i < packets.Count; i++)
        {
            SortedDictionary <int, byte[]> pack = packets[i];
            lock (pack) {
                try {
                    foreach (var each in pack)
                    {
                        ms.SetLength(0);
                        ms.Write(each.Value, 0, each.Value.Length);
                        ms.Seek(0, SeekOrigin.Begin);
                        TcpClientProxy.Ins.endPing = Time.time;
                        TcpClientProxy.Ins.ping    = Mathf.FloorToInt(1000 * (TcpClientProxy.Ins.endPing - TcpClientProxy.Ins.startPing));
                        Main.Ins.EventBus.Fire(EventId.PingChanged);
                        switch (each.Key)
                        {
                        case (int)MeteorMsg.MsgType.ProtocolVerify:
                            //ms = new MemoryStream(each.Value);
                            ProtocolVerifyRsp rspVer = Serializer.Deserialize <ProtocolVerifyRsp>(ms);
                            OnVerifyResult(rspVer);
                            break;

                        case (int)MeteorMsg.MsgType.AliveUpdate:
                            TcpClientProxy.Ins.HeartBeat();
                            break;

                        case (int)MeteorMsg.MsgType.GetRoomRsp:
                            //ms = new MemoryStream(each.Value);
                            GetRoomRsp rspG = Serializer.Deserialize <GetRoomRsp>(ms);
                            OnGetRoomRsp(rspG);
                            break;

                        case (int)MeteorMsg.MsgType.JoinRoomRsp:
                            //ms = new MemoryStream(each.Value);
                            JoinRoomRsp rspJ = Serializer.Deserialize <JoinRoomRsp>(ms);
                            ClientJoinRoomRsp(rspJ);
                            break;

                        case (int)MeteorMsg.MsgType.CreateRoomRsp:
                            //ms = new MemoryStream(each.Value);
                            CreateRoomRsp rspC = Serializer.Deserialize <CreateRoomRsp>(ms);
                            OnCreateRoomRsp(rspC);
                            break;

                        case (int)MeteorMsg.MsgType.OnPlayerJoinRoom:
                            //ms = new MemoryStream(each.Value);
                            OnPlayerJoinRoom rspOE = Serializer.Deserialize <OnPlayerJoinRoom>(ms);
                            OnPlayerEnterRoomRsp(rspOE);
                            break;

                        //case (int)MeteorMsg.MsgType.UserRebornSB2C:
                        //    ms = new MemoryStream(each.Value);
                        //    OnEnterLevelRsp rspReborn = ProtoBuf.Serializer.Deserialize<OnEnterLevelRsp>(ms);
                        //    OnUserRebornRsp_(rspReborn);
                        //    break;
                        //case (int)MeteorMsg.MsgType.OnLeaveRoomRsp:
                        //    ms = new MemoryStream(each.Value);
                        //    OnLeaveRoomRsp rspL = ProtoBuf.Serializer.Deserialize<OnLeaveRoomRsp>(ms);
                        //    OnLeaveRoomRsp_(rspL);
                        //    break;
                        case (int)MeteorMsg.MsgType.OnPlayerEnterLevel:    //其他玩家进入关卡
                            //ms = new MemoryStream(each.Value);
                            PlayerEvent rspEnterLevel = Serializer.Deserialize <PlayerEvent>(ms);
                            OnPlayerEnterLevel(rspEnterLevel);
                            break;

                        case (int)MeteorMsg.MsgType.EnterLevelRsp:    //自己进入关卡,拉取到场景里所有已知角色
                            //ms = new MemoryStream(each.Value);
                            OnEnterLevelRsp EnterLevel = Serializer.Deserialize <OnEnterLevelRsp>(ms);
                            OnEnterLevel(EnterLevel);
                            break;

                        case (int)MeteorMsg.MsgType.ChatInRoomRsp:
                            //ms = new MemoryStream(each.Value);
                            ChatMsg chatRsp = Serializer.Deserialize <ChatMsg>(ms);
                            OnReceiveChatMsg(chatRsp);
                            break;

                        //case (int)MeteorMsg.MsgType.AudioChat:
                        //    //ms = new MemoryStream(each.Value);
                        //    AudioChatMsg audioRsp = Serializer.Deserialize<AudioChatMsg>(ms);
                        //    OnReceiveAudioMsg(audioRsp);
                        //    break;
                        case (int)MeteorMsg.MsgType.OnPlayerLeaveLevel:    //其他玩家离开关卡
                            //ms = new MemoryStream(each.Value);
                            PlayerEvent rspLeaveLevel = Serializer.Deserialize <PlayerEvent>(ms);
                            OnPlayerLeaveLevel(rspLeaveLevel);
                            break;

                        case (int)MeteorMsg.MsgType.SyncRate:    //KCP识别出错,关闭旧的KCP,创建新的
                            SyncMsg syncRate = Serializer.Deserialize <SyncMsg>(ms);
                            FrameSyncServer.Ins.ChangeSyncRate(syncRate.syncrate);
                            break;
                        }
                    }
                } catch (Exception exp) {
                    UnityEngine.Debug.LogError(exp.Message + exp.StackTrace);
                } finally {
                    pack.Clear();
                }
            }
        }

        lock (messageQueue) {
            int length = messageQueue.Count;
            for (int i = 0; i < length; i++)
            {
                switch (messageQueue[i].Message)
                {
                case (short)LocalMsgType.TimeOut: OnTimeOut(messageQueue[i].Result, messageQueue[i].message); break;

                case (short)LocalMsgType.Connect: OnConnect(messageQueue[i].Result, messageQueue[i].message); break;

                case (short)LocalMsgType.DisConnect: OnDisconnect(); break;

                case (short)LocalMsgType.SendFTPLogComplete: OnSendComplete(messageQueue[i].Result, messageQueue[i].Param); break;

                case (short)LocalMsgType.SaveRecord: OnSaveRecord(messageQueue[i]); break;
                }
            }
            messageQueue.Clear();
        }
    }