public bool Unpack(NetIncomingMessage msg)
        {
            NetworkSessionType       sessionType;
            NetworkSessionProperties sessionProperties = new NetworkSessionProperties();
            string hostGamertag;
            int    maxGamers, privateGamerSlots, currentGamerCount, openPrivateGamerSlots, openPublicGamerSlots;

            try
            {
                sessionType = (NetworkSessionType)msg.ReadByte();
                if (!sessionProperties.Unpack(msg))
                {
                    return(false);
                }
                hostGamertag          = msg.ReadString();
                maxGamers             = msg.ReadInt32();
                privateGamerSlots     = msg.ReadInt32();
                currentGamerCount     = msg.ReadInt32();
                openPrivateGamerSlots = msg.ReadInt32();
                openPublicGamerSlots  = msg.ReadInt32();
            }
            catch
            {
                return(false);
            }

            if (this.sessionProperties == null)
            {
                // NetworkSessionProperties sent over the network are read-only
                this.sessionProperties = new NetworkSessionProperties(true);
            }
            this.sessionType = sessionType;
            this.sessionProperties.CopyValuesFrom(sessionProperties);
            this.hostGamertag          = hostGamertag;
            this.maxGamers             = maxGamers;
            this.privateGamerSlots     = privateGamerSlots;
            this.currentGamerCount     = currentGamerCount;
            this.openPrivateGamerSlots = openPrivateGamerSlots;
            this.openPublicGamerSlots  = openPublicGamerSlots;

            initialized = true;
            return(true);
        }
Example #2
0
        private bool ReceiveSessionStateChanged(NetBuffer msg, NetworkMachine originMachine)
        {
            if (!originMachine.isHost)
            {
                return(false);
            }

            bool allowHostMigration, allowJoinInProgress;
            int  maxGamers, privateGamerSlots;
            NetworkSessionState      state;
            NetworkSessionProperties properties = new NetworkSessionProperties();

            try
            {
                allowHostMigration  = msg.ReadBoolean();
                allowJoinInProgress = msg.ReadBoolean();
                maxGamers           = msg.ReadInt32();
                privateGamerSlots   = msg.ReadInt32();
                state = (NetworkSessionState)msg.ReadByte();
                if (!properties.Unpack(msg))
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }

            this.allowHostMigration  = allowHostMigration;
            this.allowJoinInProgress = allowJoinInProgress;
            this.maxGamers           = maxGamers;
            this.privateGamerSlots   = privateGamerSlots;
            this.state = state;
            this.properties.CopyValuesFrom(properties);
            return(true);
        }