// 检查游戏是否可以开始
        private void CheckGameStart()
        {
            bool flag = this.replayMode == ReplayMode.LOAD_REPLAY;

            if (flag) // 加载回放模式
            {
                this.RunSimulation(false);
            }
            else // 非加载回放模式
            {
                bool flag2 = true;
                int  i     = 0;
                int  count = this.activePlayers.Count;
                while (i < count)
                {
                    flag2 &= this.activePlayers[i].sentSyncedStart;
                    i++;
                }
                bool flag3 = /*flag2*/ true;
                if (flag3)
                {
                    this.RunSimulation(false);
                    SyncedData.pool.FillStack(this.activePlayers.Count * (this.syncWindow + this.rollbackWindow));
                }
                else
                {
                    this.RaiseEvent(196, SyncedInfo.Encode(new SyncedInfo
                    {
                        playerId = this.localPlayer.ID
                    }));
                }
            }
        }
        private void SendInfoChecksum(int tick)
        {
            bool flag = this.replayMode == ReplayMode.LOAD_REPLAY;

            if (!flag)
            {
                SyncedInfo syncedInfo = this.bufferSyncedInfo.Current();
                syncedInfo.playerId = this.localPlayer.ID;
                syncedInfo.tick     = tick;
                syncedInfo.checksum = this.GetChecksumForSyncedInfo();
                this.bufferSyncedInfo.MoveNext();
                this.RaiseEvent(198, SyncedInfo.Encode(syncedInfo));
            }
        }
예제 #3
0
        public static byte[] Encode(SyncedInfo info)
        {
            List <byte> list = new List <byte>();

            list.Add(info.playerId);
            bool flag = info.checksum != null;

            if (flag)
            {
                list.AddRange(BitConverter.GetBytes(info.tick));
                list.AddRange(Encoding.ASCII.GetBytes(info.checksum));
            }
            return(list.ToArray());
        }
예제 #4
0
        public static SyncedInfo Decode(byte[] infoBytes)
        {
            SyncedInfo syncedInfo = new SyncedInfo();
            int        num        = 0;

            syncedInfo.playerId = infoBytes[num++];
            bool flag = num < infoBytes.Length;

            if (flag)
            {
                syncedInfo.tick     = BitConverter.ToInt32(infoBytes, num);
                num                += 4;
                syncedInfo.checksum = Encoding.ASCII.GetString(infoBytes, num, 32);
            }
            return(syncedInfo);
        }
        private void OnChecksumReceived(SyncedInfo syncedInfo)
        {
            bool dropped = this.players[syncedInfo.playerId].dropped;

            if (!dropped)
            {
                this.checksumOk = true;
                SyncedInfo[] buffer = this.bufferSyncedInfo.buffer;
                for (int i = 0; i < buffer.Length; i++)
                {
                    SyncedInfo syncedInfo2 = buffer[i];
                    bool       flag        = syncedInfo2.tick == syncedInfo.tick && syncedInfo2.checksum != syncedInfo.checksum;
                    if (flag)
                    {
                        this.checksumOk = false;
                        break;
                    }
                }
            }
        }
        private void OnEventDataReceived(byte eventCode, object content)
        {
            bool flag = eventCode == 199;

            if (flag)             // 接收操作数据
            {
                byte[]            data = content as byte[];
                List <SyncedData> list = SyncedData.Decode(data);                // 解码
                bool flag2             = list.Count > 0;
                if (flag2)                                                       // 有数据
                {
                    FPPlayer tSPlayer = this.players[list[0].inputData.ownerID]; // 找到对应的玩家
                    bool     flag3    = !tSPlayer.dropped;
                    if (flag3)                                                   // 该玩家没有掉线
                    {
                        this.OnSyncedDataReceived(tSPlayer, list);               // 处理同步数据
                        bool flag4 = list[0].dropPlayer && tSPlayer.ID != this.localPlayer.ID && !this.players[list[0].dropFromPlayerId].dropped;
                        if (flag4)
                        {
                            tSPlayer.dropCount++;                             // 统计掉线玩家数量
                        }
                    }
                    else                     // 该玩家掉线了,回收数据对象
                    {
                        int i     = 0;
                        int count = list.Count;
                        while (i < count)
                        {
                            SyncedData.pool.GiveBack(list[i]);
                            i++;
                        }
                    }
                    SyncedData.poolList.GiveBack(list);
                }
            }
            else
            {
                bool flag5 = eventCode == 198;
                if (flag5)
                {
                    byte[] infoBytes = content as byte[];
                    this.OnChecksumReceived(SyncedInfo.Decode(infoBytes));
                }
                else
                {
                    bool flag6 = eventCode == 197;
                    if (flag6)
                    {
                        byte[] array = content as byte[];
                        bool   flag7 = array.Length != 0;
                        if (flag7)
                        {
                            bool flag8 = array[0] == 0;
                            if (flag8)
                            {
                                this.Pause();
                            }
                            else
                            {
                                bool flag9 = array[0] == 1;
                                if (flag9)
                                {
                                    this.Run();
                                }
                                else
                                {
                                    bool flag10 = array[0] == 3;
                                    if (flag10)
                                    {
                                        this.End();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        bool flag11 = eventCode == 196;
                        if (flag11)
                        {
                            byte[]     infoBytes2 = content as byte[];
                            SyncedInfo syncedInfo = SyncedInfo.Decode(infoBytes2);
                            this.players[syncedInfo.playerId].sentSyncedStart = true;
                        }
                    }
                }
            }
        }