Exemplo n.º 1
0
        public static Guid ReadGuid(this Lidgren.Network.NetBuffer target)
        {
            int guidLength = target.ReadInt32();

            byte[] guidBytes = target.ReadBytes(guidLength);
            return(new Guid(guidBytes));
        }
Exemplo n.º 2
0
        public static MatchState ReadFromMessage(Lidgren.Network.NetBuffer message)
        {
            //Clients
            int clientCount = message.ReadInt32();
            List <MatchClientState> clients = new List <MatchClientState>();

            for (int i = 0; i < clientCount; i++)
            {
                System.Guid guid = message.ReadGuid();
                string      name = message.ReadString();

                clients.Add(new MatchClientState(guid, name));
            }
            //Players
            int playerCount = message.ReadInt32();
            List <MatchPlayerState> players = new List <MatchPlayerState>();

            for (int i = 0; i < playerCount; i++)
            {
                System.Guid clientGuid  = message.ReadGuid();
                ControlType ctrlType    = (ControlType)message.ReadInt32();
                bool        readyToRace = message.ReadBoolean();
                int         characterId = message.ReadInt32();

                players.Add(new MatchPlayerState(clientGuid, ctrlType, readyToRace, characterId));
            }
            //Match settings
            MatchSettings settings = new MatchSettings()
            {
                StageId             = message.ReadInt32(),
                Laps                = message.ReadInt32(),
                AICount             = message.ReadInt32(),
                AISkill             = (AISkillLevel)message.ReadInt32(),
                AutoStartTime       = message.ReadInt32(),
                AutoStartMinPlayers = message.ReadInt32(),
                AutoReturnTime      = message.ReadInt32(),
                VoteRatio           = message.ReadFloat(),
                StageRotationMode   = (StageRotationMode)message.ReadInt32()
            };
            bool  inRace           = message.ReadBoolean();
            float curAutoStartTime = message.ReadFloat();

            return(new MatchState(clients, players, settings, inRace, curAutoStartTime));
        }