Exemplo n.º 1
0
        protected override void ProcessForwardHostData(byte[] data)
        {
            // [8: CMD] [8:seq] [16: SessionID] [4: UserID] [12: SessionSecret]

            UserConn[0].LastResponse = MonoSAMGame.CurrentTime.TotalElapsedSeconds;

            bool err = false;

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data)))
            {
                reader.ReadByte();                 // CMD
                reader.ReadByte();                 // SEQ
                reader.ReadByte();                 // SID
                reader.ReadByte();                 // SID
                reader.ReadByte();                 // SSC
                reader.ReadByte();                 // SSC

                LevelID = new Guid(reader.ReadBytes(16));

                var bspeed = reader.ReadByte();
                MusicIndex        = reader.ReadByte();
                ServerGameVersion = reader.ReadUInt64();
                ServerLevelHash   = reader.ReadUInt64();


                if (ServerGameVersion == GDConstants.IntVersion)
                {
                    Speed = GameSpeedModeHelper.FromByte(bspeed);
                    if (bspeed != 0x70 && bspeed != 0x78 && bspeed != 0x80 && bspeed != 0x88 && bspeed != 0x90)
                    {
                        err = true;
                    }
                    if (MusicIndex > MainGame.Inst.GDSound.LevelMusic.Length)
                    {
                        err = true;
                    }
                }
            }

            if (ServerGameVersion != GDConstants.IntVersion)
            {
                ErrorStop(ErrorType.GameVersionMismatch, null);
                return;
            }

            if (err)
            {
                SAMLog.Error("SNSC::PFHD", "data error\r\nData:\n" + ByteUtils.CompressBytesForStorage(data));
            }

            RecieveMsg(0, data[1]);

            LevelBlueprint blueprint;

            if (!Levels.LEVELS.TryGetValue(LevelID.Value, out blueprint))
            {
                LevelID = null;
            }
        }
Exemplo n.º 2
0
        protected override void ProcessForwardLobbySync(byte[] data)
        {
            // [8: CMD] [8:seq] [16: SessionID] [4: UserID] [12: SessionSecret]

            UserConn[0].LastResponse = MonoSAMGame.CurrentTime.TotalElapsedSeconds;

            var err = false;

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data)))
            {
                reader.ReadByte();                 // CMD
                reader.ReadByte();                 // SEQ
                reader.ReadByte();                 // SID
                reader.ReadByte();                 // SID
                reader.ReadByte();                 // SSC
                reader.ReadByte();                 // SSC

                LevelID = new Guid(reader.ReadBytes(16));
                var bspeed = reader.ReadByte();
                MusicIndex        = reader.ReadByte();
                ServerGameVersion = reader.ReadUInt64();
                ServerLevelHash   = reader.ReadUInt64();

                if (ServerGameVersion == GDConstants.IntVersion)
                {
                    Speed = GameSpeedModeHelper.FromByte(bspeed);
                    if (bspeed != 0x70 && bspeed != 0x78 && bspeed != 0x80 && bspeed != 0x88 && bspeed != 0x90)
                    {
                        err = true;
                    }
                    if (MusicIndex > MainGame.Inst.GDSound.LevelMusic.Length)
                    {
                        err = true;
                    }
                }
            }


            if (err)
            {
                SAMLog.Error("SNSC::PFLS", "data error\r\nData:\n" + ByteUtils.CompressBytesForStorage(data));
            }

            SAMLog.Debug($"[[CMD_FORWARDLOBBYSYNC]]: {LevelID} | {Speed} | {MusicIndex}");

            if (ServerGameVersion != GDConstants.IntVersion)
            {
                ErrorStop(ErrorType.GameVersionMismatch, null);
                return;
            }

            LevelBlueprint blueprint;

            if (!Levels.LEVELS.TryGetValue(LevelID.Value, out blueprint))
            {
                ErrorStop(ErrorType.LevelNotFound, null);
                SAMLog.Error("GDMC::LNF", "ProcessForwardLobbySync -> LevelNotFound: " + LevelID + "\r\nData:\n" + ByteUtils.CompressBytesForStorage(data));
                return;
            }

            var correctCS = blueprint.CalcCheckSum();

            if (ServerLevelHash != correctCS)
            {
                ErrorStop(ErrorType.LevelVersionMismatch, null);
                SAMLog.Error("GDMC::LVM", "ProcessForwardLobbySync -> LevelVersionMismatch: " + ServerLevelHash + " <> " + correctCS + "\r\nData:\n" + ByteUtils.CompressBytesForStorage(data));
                return;
            }

            RecieveMsg(0, data[1]);

            byte[] answer = new byte[8];

            answer[0] = ANS_FORWARDLOBBYSYNC;
            SetSequenceCounter(ref answer[1]);
            answer[2] = (byte)((SessionID >> 8) & 0xFF);
            answer[3] = (byte)(SessionID & 0xFF);
            answer[4] = (byte)(((SessionUserID & 0xF) << 4) | ((SessionSecret >> 8) & 0x0F));
            answer[5] = (byte)(SessionSecret & 0xFF);
            answer[6] = (byte)SessionUserID;
            Send(answer);
        }