예제 #1
0
        void OnNet_ReqMissFrame(Player player, BaseFormater data)
        {
            var reqMsg        = data as Msg_ReqMissFrame;
            var nextCheckTick = reqMsg.StartTick;

            Debug.Log($"OnNet_ReqMissFrame nextCheckTick id:{player.localId}:{nextCheckTick}");
            var msg   = new Msg_RepMissFrame();
            int count = Math.Min(Math.Min((Tick - 1), allHistoryFrames.Count) - nextCheckTick,
                                 MaxRepMissFrameCountPerPack);

            if (count <= 0)
            {
                return;
            }
            var frames = new ServerFrame[count];

            for (int i = 0; i < count; i++)
            {
                frames[i] = allHistoryFrames[nextCheckTick + i];
                Debug.Assert(frames[i] != null);
            }

            msg.StartTick = frames[0].Tick;
            msg.Frames    = frames;
            SendTo(player, EMsgSC.G2C_RepMissFrame, msg, true);
        }
예제 #2
0
        void OnNet_PlayerInput(Player player, BaseFormater data)
        {
            if (State != ERoomState.PartLoaded && State != ERoomState.Playing)
            {
                return;
            }
            if (State == ERoomState.PartLoaded)
            {
                State = ERoomState.Playing;
            }

            var input = data as Msg_PlayerInput;

            //Debug.Log($"RecvInput actorID:{input.ActorId} inputTick:{input.Tick} Tick{Tick} count = {input.Commands.Length}");
            if (input.Tick < Tick)
            {
                return;
            }

            var tick  = input.Tick;
            var iTick = (int)tick;
            //扩充帧队列
            var frameCount = allHistoryFrames.Count;

            if (frameCount <= iTick)
            {
                var count = iTick - allHistoryFrames.Count + 1;
                for (int i = 0; i < count; i++)
                {
                    allHistoryFrames.Add(null);
                }
            }

            if (allHistoryFrames[iTick] == null)
            {
                allHistoryFrames[iTick] = new ServerFrame()
                {
                    Tick = tick
                };
            }

            var frame = allHistoryFrames[iTick];

            if (frame.Inputs == null || frame.Inputs.Length != MaxPlayerCount)
            {
                frame.Inputs = new Msg_PlayerInput[MaxPlayerCount];
            }

            var id = input.ActorId;

            if (!allNeedWaitInputPlayerIds.Contains(id))
            {
                allNeedWaitInputPlayerIds.Add(id);
            }

            frame.Inputs[id] = input;
            //if (input.Commands.Count > 0) {
            //    Debug.Log($"RecvInput actorID:{input.ActorId}  inputTick:{input.Tick}  cmd:{(ECmdType)(input.Commands[0].type)}");
            //}
        }
예제 #3
0
        public void SendMsg(object type, BaseFormater data)
        {
            var writer = new Serializer();

            writer.PutInt16((short)(object)type);
            data.Serialize(writer);
            var bytes = Compressor.Compress(writer.Data);

            SendMsg(bytes);
        }
예제 #4
0
        public void Border(TMsgType type, BaseFormater msg)
        {
            var writer = new Serializer();

            writer.PutInt16((short)(object)type);
            msg.Serialize(writer);
            var bytes = Compressor.Compress(writer.CopyData());
            var peers = _peers;

            foreach (var peer in peers)
            {
                peer.SendMsg(bytes);
            }
        }
예제 #5
0
        public object DeserializeFrom(ushort opcode, byte[] bytes, int index, int count)
        {
            var type = (EMsgSC)opcode;

            switch (type)
            {
            //ping
            case EMsgSC.C2G_PlayerPing: return(BaseFormater.FromBytes <Msg_C2G_PlayerPing>(bytes, index, count));

            case EMsgSC.G2C_PlayerPing: return(BaseFormater.FromBytes <Msg_G2C_PlayerPing>(bytes, index, count));

            //login
            case EMsgSC.L2C_JoinRoomResult: return(BaseFormater.FromBytes <Msg_L2C_JoinRoomResult>(bytes, index, count));

            case EMsgSC.C2L_Test: return(BaseFormater.FromBytes <Msg_C2L_Test>(bytes, index, count));

            case EMsgSC.C2L_JoinRoom: return(BaseFormater.FromBytes <Msg_C2L_JoinRoom>(bytes, index, count));

            case EMsgSC.C2L_LeaveRoom: return(BaseFormater.FromBytes <Msg_C2L_LeaveRoom>(bytes, index, count));

            case EMsgSC.C2G_LoadingProgress: return(BaseFormater.FromBytes <Msg_C2G_LoadingProgress>(bytes, index, count));

            //room
            case EMsgSC.G2C_Hello: return(BaseFormater.FromBytes <Msg_G2C_Hello>(bytes, index, count));

            case EMsgSC.G2C_FrameData: return(BaseFormater.FromBytes <Msg_ServerFrames>(bytes, index, count));

            case EMsgSC.G2C_RepMissFrame: return(BaseFormater.FromBytes <Msg_RepMissFrame>(bytes, index, count));

            case EMsgSC.G2C_GameEvent: return(BaseFormater.FromBytes <Msg_G2C_GameEvent>(bytes, index, count));

            case EMsgSC.G2C_GameStartInfo: return(BaseFormater.FromBytes <Msg_G2C_GameStartInfo>(bytes, index, count));

            case EMsgSC.G2C_LoadingProgress: return(BaseFormater.FromBytes <Msg_G2C_LoadingProgress>(bytes, index, count));

            case EMsgSC.G2C_AllFinishedLoaded: return(BaseFormater.FromBytes <Msg_G2C_AllFinishedLoaded>(bytes, index, count));

            case EMsgSC.C2G_PlayerInput: return(BaseFormater.FromBytes <Msg_PlayerInput>(bytes, index, count));

            case EMsgSC.C2G_ReqMissFrame: return(BaseFormater.FromBytes <Msg_ReqMissFrame>(bytes, index, count));

            case EMsgSC.C2G_RepMissFrameAck: return(BaseFormater.FromBytes <Msg_RepMissFrameAck>(bytes, index, count));

            case EMsgSC.C2G_HashCode: return(BaseFormater.FromBytes <Msg_HashCode>(bytes, index, count));
            }

            return(null);
        }
예제 #6
0
        public object DeserializeFrom(ushort opcode, byte[] bytes, int index, int count)
        {
            var type = (EMsgType)opcode;

            switch (type)
            {
            case EMsgType.JoinRoom: return(BaseFormater.FromBytes <Msg_JoinRoom>(bytes, index, count));

            case EMsgType.QuitRoom: return(BaseFormater.FromBytes <Msg_QuitRoom>(bytes, index, count));

            case EMsgType.PlayerInput: return(BaseFormater.FromBytes <Msg_PlayerInput>(bytes, index, count));

            case EMsgType.FrameInput: return(BaseFormater.FromBytes <Msg_FrameInput>(bytes, index, count));

            case EMsgType.StartGame: return(BaseFormater.FromBytes <Msg_StartGame>(bytes, index, count));
            }

            return(null);
        }
예제 #7
0
        void OnNet_LoadingProgress(Player player, BaseFormater data)
        {
            if (State != ERoomState.PartLoading)
            {
                return;
            }
            var msg = data as Msg_LoadingProgress;

            if (playerLoadingProgress == null)
            {
                playerLoadingProgress = new byte[MaxPlayerCount];
            }

            playerLoadingProgress[player.localId] = msg.progress;

            Debug.Log($"palyer{player.localId} Load {msg.progress}");
            var isDone = true;

            foreach (var progress in playerLoadingProgress)
            {
                if (progress < 100)
                {
                    isDone = false;
                    break;
                }
            }

            var retmsg = new Msg_AllLoadingProgress();

            retmsg.isAllDone = isDone;
            retmsg.progress  = playerLoadingProgress;
            SendToAll(EMsgSC.G2C_LoadingProgress, retmsg);
            if (isDone)
            {
                for (int i = 0; i < playerLoadingProgress.Length; i++)
                {
                    playerLoadingProgress[i] = 0;
                }

                State = ERoomState.PartLoaded;
                Debug.Log("All Load done");
            }
        }
예제 #8
0
        void OnNet_HashCode(Player player, BaseFormater data)
        {
            var hashInfo = data as Msg_HashCode;
            var id       = player.localId;

            for (int i = 0; i < hashInfo.HashCodes.Length; i++)
            {
                var code = hashInfo.HashCodes[i];
                var tick = hashInfo.StartTick + i;
                if (_hashCodes.TryGetValue(tick, out HashCodeMatcher matcher1))
                {
                    if (matcher1 == null || matcher1.sendResult[id])
                    {
                        continue;
                    }

                    if (matcher1.hashCode != code)
                    {
                        OnHashMatchResult(tick, code, false);
                    }

                    matcher1.count          = matcher1.count + 1;
                    matcher1.sendResult[id] = true;
                    if (matcher1.IsMatchered)
                    {
                        OnHashMatchResult(tick, code, true);
                    }
                }
                else
                {
                    var matcher2 = new HashCodeMatcher(MaxPlayerCount);
                    matcher2.count          = 1;
                    matcher2.hashCode       = code;
                    matcher2.sendResult[id] = true;
                    _hashCodes.Add(tick, matcher2);
                    if (matcher2.IsMatchered)
                    {
                        OnHashMatchResult(tick, code, true);
                    }
                }
            }
        }
예제 #9
0
        void OnNet_RepMissFrameAck(Player player, BaseFormater data)
        {
            var msg = data as Msg_RepMissFrameAck;

            Debug.Log($"OnNet_RepMissFrameAck missFrameTick:{msg.MissFrameTick}");
        }
예제 #10
0
 void OnNet_PlayerReady(Player player, BaseFormater data)
 {
     OnPlayerReady(player);
 }
예제 #11
0
 public virtual void SendToMaster(EMsgMS type, BaseFormater data)
 {
 }
예제 #12
0
 public void SendMessage(TMsgType type, BaseFormater data, ResponseCallback responseCallback)
 {
     _client?.SendMessage((short)(object)type, data, responseCallback);
 }
예제 #13
0
 public void SendMsg(object type, BaseFormater data)
 {
     _peer?.SendMessage((short)type, data);
 }
예제 #14
0
        // Token: 0x06000195 RID: 405 RVA: 0x00005B38 File Offset: 0x00003D38
        public object DeserializeFrom(ushort opcode, byte[] bytes, int index, int count)
        {
            if (opcode <= 25)
            {
                switch (opcode)
                {
                case 6:
                    return(BaseFormater.FromBytes <Msg_ReqMissFrame>(bytes, index, count));

                case 7:
                    return(BaseFormater.FromBytes <Msg_RepMissFrameAck>(bytes, index, count));

                case 8:
                    return(BaseFormater.FromBytes <Msg_RepMissFrame>(bytes, index, count));

                case 9:
                    return(BaseFormater.FromBytes <Msg_HashCode>(bytes, index, count));

                case 10:
                    return(BaseFormater.FromBytes <Msg_PlayerInput>(bytes, index, count));

                case 11:
                    return(BaseFormater.FromBytes <Msg_ServerFrames>(bytes, index, count));

                case 12:
                    return(BaseFormater.FromBytes <Msg_C2G_PlayerPing>(bytes, index, count));

                case 13:
                    return(BaseFormater.FromBytes <Msg_G2C_PlayerPing>(bytes, index, count));

                default:
                    if (opcode == 25)
                    {
                        return(BaseFormater.FromBytes <Msg_C2L_JoinRoom>(bytes, index, count));
                    }
                    break;
                }
            }
            else
            {
                if (opcode == 27)
                {
                    return(BaseFormater.FromBytes <Msg_L2C_JoinRoomResult>(bytes, index, count));
                }
                if (opcode == 30)
                {
                    return(BaseFormater.FromBytes <Msg_C2L_LeaveRoom>(bytes, index, count));
                }
                switch (opcode)
                {
                case 39:
                    return(BaseFormater.FromBytes <Msg_G2C_Hello>(bytes, index, count));

                case 40:
                    return(BaseFormater.FromBytes <Msg_G2C_GameStartInfo>(bytes, index, count));

                case 41:
                    return(BaseFormater.FromBytes <Msg_C2G_LoadingProgress>(bytes, index, count));

                case 42:
                    return(BaseFormater.FromBytes <Msg_G2C_LoadingProgress>(bytes, index, count));

                case 43:
                    return(BaseFormater.FromBytes <Msg_G2C_AllFinishedLoaded>(bytes, index, count));

                case 47:
                    return(BaseFormater.FromBytes <Msg_G2C_GameEvent>(bytes, index, count));
                }
            }
            return(null);
        }
예제 #15
0
 public void BorderMessage(TMsgType type, BaseFormater msg)
 {
     _server.BorderMessage((short)(object)type, msg);
 }
예제 #16
0
 public void SendMessage(TMsgType type, BaseFormater data)
 {
     _client?.SendMessage((short)(object)type, data);
 }
예제 #17
0
 public void Write(BaseFormater value)
 {
     Write(value == null);
     value?.Serialize(this);
 }
예제 #18
0
 public void Respond(object type, BaseFormater msg, EResponseStatus responseStatus = EResponseStatus.Default)
 {
     Respond(MessageHelper.Create((short)type, msg.ToBytes()), responseStatus);
 }
예제 #19
0
 void OnNet_ReqMissPack(Player player, BaseFormater data)
 {
 }