Пример #1
0
		internal void Reset()
		{
			m_incomingMessageType = NetIncomingMessageType.Error;
			m_readPosition = 0;
			m_receivedMessageType = NetMessageType.LibraryError;
			m_senderConnection = null;
			m_bitLength = 0;
			m_isFragment = false;
		}
Пример #2
0
 internal NetIncomingMessage CreateIncomingMessage(NetIncomingMessageType tp, byte[] useStorageData)
 {
     NetIncomingMessage retval;
     if (m_incomingMessagesPool == null || !m_incomingMessagesPool.TryDequeue(out retval))
         retval = new NetIncomingMessage(tp);
     else
         retval.m_incomingMessageType = tp;
     retval.m_data = useStorageData;
     return retval;
 }
Пример #3
0
 internal NetIncomingMessage CreateIncomingMessage(NetIncomingMessageType tp, int minimumByteSize)
 {
     NetIncomingMessage retval;
     if (m_incomingMessagesPool == null || !m_incomingMessagesPool.TryDequeue(out retval))
         retval = new NetIncomingMessage(tp);
     else
         retval.m_incomingMessageType = tp;
     retval.m_data = GetStorage(minimumByteSize);
     return retval;
 }
Пример #4
0
		/// <summary>
		/// NetPeerConfiguration constructor
		/// </summary>
		public NetPeerConfiguration(string appIdentifier)
		{
			if (string.IsNullOrEmpty(appIdentifier))
				throw new NetException("App identifier must be at least one character long");
			m_appIdentifier = appIdentifier.ToString(System.Globalization.CultureInfo.InvariantCulture);

			//
			// default values
			//
			m_disabledTypes = NetIncomingMessageType.ConnectionApproval | NetIncomingMessageType.UnconnectedData | NetIncomingMessageType.VerboseDebugMessage | NetIncomingMessageType.ConnectionLatencyUpdated;
			m_networkThreadName = "Lidgren network thread";
			m_localAddress = IPAddress.Any;
			m_broadcastAddress = IPAddress.Broadcast;
			var ip = NetUtility.GetBroadcastAddress();
			if (ip != null)
			{
				m_broadcastAddress = ip;
			}
			m_port = 0;
			m_receiveBufferSize = 131071;
			m_sendBufferSize = 131071;
			m_acceptIncomingConnections = false;
			m_maximumConnections = 32;
			m_defaultOutgoingMessageCapacity = 16;
			m_pingInterval = 4.0f;
			m_connectionTimeout = 25.0f;
			m_useMessageRecycling = true;
			m_resendHandshakeInterval = 3.0f;
			m_maximumHandshakeAttempts = 5;
			m_autoFlushSendQueue = true;

			// Maximum transmission unit
			// Ethernet can take 1500 bytes of payload, so lets stay below that.
			// The aim is for a max full packet to be 1440 bytes (30 x 48 bytes, lower than 1468)
			// -20 bytes IP header
			//  -8 bytes UDP header
			//  -4 bytes to be on the safe side and align to 8-byte boundary
			// Total 1408 bytes
			// Note that lidgren headers (5 bytes) are not included here; since it's part of the "mtu payload"
			m_maximumTransmissionUnit = 1408;
			m_autoExpandMTU = false;
			m_expandMTUFrequency = 2.0f;
			m_expandMTUFailAttempts = 5;

			m_loss = 0.0f;
			m_minimumOneWayLatency = 0.0f;
			m_randomOneWayLatency = 0.0f;
			m_duplicates = 0.0f;

			m_isLocked = false;
		}
Пример #5
0
        /// <summary>
        /// Creates an incoming message with the required capacity for releasing to the application
        /// </summary>
        internal NetIncomingMessage CreateIncomingMessage(NetIncomingMessageType tp, string text)
        {
            NetIncomingMessage retval;

            if (string.IsNullOrEmpty(text))
            {
                retval = CreateIncomingMessage(tp, 1);
                retval.Write("");
                return(retval);
            }

            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(text);
            retval = CreateIncomingMessage(tp, bytes.Length + (bytes.Length > 127 ? 2 : 1));
            retval.Write(text);

            return(retval);
        }
Пример #6
0
        /// <summary>
        /// NetPeerConfiguration constructor
        /// </summary>
        public NetPeerConfiguration(string appIdentifier)
        {
            if (string.IsNullOrEmpty(appIdentifier))
            {
                throw new NetException("App identifier must be at least one character long");
            }
            m_appIdentifier = appIdentifier;

            //
            // default values
            //
            m_disabledTypes     = NetIncomingMessageType.ConnectionApproval | NetIncomingMessageType.UnconnectedData | NetIncomingMessageType.VerboseDebugMessage | NetIncomingMessageType.ConnectionLatencyUpdated | NetIncomingMessageType.NatIntroductionSuccess;
            m_networkThreadName = "Lidgren network thread";
            m_localAddress      = IPAddress.Any;
            m_broadcastAddress  = IPAddress.Broadcast;
            var ip = NetUtility.GetBroadcastAddress();

            if (ip != null)
            {
                m_broadcastAddress = ip;
            }
            m_port = 0;
            m_receiveBufferSize              = 131071;
            m_sendBufferSize                 = 131071;
            m_acceptIncomingConnections      = false;
            m_maximumConnections             = 32;
            m_defaultOutgoingMessageCapacity = 16;
            m_pingInterval             = 4.0f;
            m_connectionTimeout        = 25.0f;
            m_useMessageRecycling      = true;
            m_resendHandshakeInterval  = 3.0f;
            m_maximumHandshakeAttempts = 5;
            m_autoFlushSendQueue       = true;

            m_maximumTransmissionUnit = kDefaultMTU;
            m_autoExpandMTU           = false;
            m_expandMTUFrequency      = 2.0f;
            m_expandMTUFailAttempts   = 5;

            m_loss = 0.0f;
            m_minimumOneWayLatency = 0.0f;
            m_randomOneWayLatency  = 0.0f;
            m_duplicates           = 0.0f;

            m_isLocked = false;
        }
Пример #7
0
        /// <summary>
        /// NetPeerConfiguration constructor
        /// </summary>
        public NetPeerConfiguration(string appIdentifier)
        {
            if (string.IsNullOrEmpty(appIdentifier))
            {
                throw new NetException("App identifier must be at least one character long");
            }
            m_appIdentifier = appIdentifier.ToString(System.Globalization.CultureInfo.InvariantCulture);

            //
            // default values
            //
            m_disabledTypes     = NetIncomingMessageType.ConnectionApproval | NetIncomingMessageType.UnconnectedData | NetIncomingMessageType.VerboseDebugMessage | NetIncomingMessageType.ConnectionLatencyUpdated;
            m_networkThreadName = "Lidgren network thread";
            m_localAddress      = IPAddress.Any;
            m_port = 0;
            m_receiveBufferSize              = 131071;
            m_sendBufferSize                 = 131071;
            m_acceptIncomingConnections      = false;
            m_maximumConnections             = 32;
            m_defaultOutgoingMessageCapacity = 16;
            m_pingInterval             = 4.0f;
            m_connectionTimeout        = 25.0f;
            m_useMessageRecycling      = true;
            m_resendHandshakeInterval  = 3.0f;
            m_maximumHandshakeAttempts = 5;

            // Maximum transmission unit
            // Ethernet can take 1500 bytes of payload, so lets stay below that.
            // The aim is for a max full packet to be 1440 bytes (30 x 48 bytes, lower than 1468)
            // -20 bytes IP header
            //  -8 bytes UDP header
            //  -4 bytes to be on the safe side and align to 8-byte boundary
            // Total 1408 bytes
            // Note that lidgren headers (5 bytes) are not included here; since it's part of the "mtu payload"
            m_maximumTransmissionUnit = 1408;
            m_autoExpandMTU           = false;
            m_expandMTUFrequency      = 2.0f;
            m_expandMTUFailAttempts   = 5;

            m_loss = 0.0f;
            m_minimumOneWayLatency = 0.0f;
            m_randomOneWayLatency  = 0.0f;
            m_duplicates           = 0.0f;

            m_isLocked = false;
        }
Пример #8
0
        public override void receiveMessages()
        {
            NetIncomingMessage netIncomingMessage;

            while ((netIncomingMessage = this.client.ReadMessage()) != null)
            {
                NetIncomingMessageType messageType = netIncomingMessage.MessageType;
                if (messageType <= NetIncomingMessageType.DiscoveryResponse)
                {
                    if (messageType != NetIncomingMessageType.Data)
                    {
                        if (messageType == NetIncomingMessageType.DiscoveryResponse)
                        {
                            Console.WriteLine("Found server at " + netIncomingMessage.SenderEndPoint);
                            this.serverName = netIncomingMessage.ReadString();
                            this.receiveHandshake(netIncomingMessage);
                        }
                    }
                    else
                    {
                        LidgrenClient.parseDataMessageFromServer(netIncomingMessage);
                    }
                }
                else if (messageType != NetIncomingMessageType.WarningMessage)
                {
                    if (messageType != NetIncomingMessageType.ErrorMessage)
                    {
                        if (messageType != NetIncomingMessageType.ConnectionLatencyUpdated)
                        {
                        }
                    }
                    else
                    {
                        Game1.debugOutput = netIncomingMessage.ReadString();
                    }
                }
                else
                {
                    Game1.debugOutput = netIncomingMessage.ReadString();
                }
            }
            if (this.client.ServerConnection != null && DateTime.Now.Second % 2 == 0)
            {
                Game1.debugOutput = "Ping: " + this.client.ServerConnection.AverageRoundtripTime * 1000f + "ms";
            }
        }
Пример #9
0
        /// <summary>
        /// Creates an incoming message with the required capacity for releasing to the application
        /// </summary>
        internal NetIncomingMessage CreateIncomingMessage(NetIncomingMessageType tp, string text)
        {
            NetIncomingMessage retval;

            if (string.IsNullOrEmpty(text))
            {
                retval = CreateIncomingMessage(tp, 1);
                retval.Write(string.Empty);
                return(retval);
            }

            int numBytes = System.Text.Encoding.UTF8.GetByteCount(text);

            retval = CreateIncomingMessage(tp, numBytes + (numBytes > 127 ? 2 : 1));
            retval.Write(text);

            return(retval);
        }
Пример #10
0
        /// <summary>
        /// <see cref="NetPeerConfiguration"/> constructor.
        /// </summary>
        public NetPeerConfiguration(string appIdentifier)
        {
            if (string.IsNullOrEmpty(appIdentifier))
            {
                throw new LidgrenException("App identifier must be at least one character long.");
            }
            AppIdentifier = appIdentifier;

            _disabledTypes =
                NetIncomingMessageType.ConnectionApproval |
                NetIncomingMessageType.UnconnectedData |
                NetIncomingMessageType.ConnectionLatencyUpdated |
                NetIncomingMessageType.NatIntroductionSuccess;

            _networkThreadName = "Lidgren Network Thread";
            _localAddress      = IPAddress.Any;
            _broadcastAddress  = NetUtility.RetrieveBroadcastAddress() ?? IPAddress.Broadcast;
            _storagePool       = ArrayPool <byte> .Create();

            _port = 0;
            _receiveBufferSize         = 131071;
            _sendBufferSize            = 131071;
            _acceptIncomingConnections = false;
            _pingInterval             = TimeSpan.FromSeconds(4);
            _connectionTimeout        = TimeSpan.FromSeconds(25);
            _fragmentGroupTimeout     = TimeSpan.FromSeconds(8);
            _useMessageRecycling      = true;
            _resendHandshakeInterval  = TimeSpan.FromSeconds(3);
            _maximumHandshakeAttempts = 5;
            _autoFlushSendQueue       = true;

            _maximumTransmissionUnit = DefaultMTU;
            _autoExpandMTU           = false;
            _expandMTUFrequency      = TimeSpan.FromSeconds(2);
            _expandMTUFailAttempts   = 5;
            UnreliableSizeBehaviour  = NetUnreliableSizeBehaviour.NormalFragmentation;

            _loss = 0f;
            _minimumOneWayLatency = TimeSpan.Zero;
            _randomOneWayLatency  = TimeSpan.Zero;
            _duplicates           = 0f;

            _isLocked = false;
        }
Пример #11
0
        // Token: 0x06000B3D RID: 2877 RVA: 0x000E3E60 File Offset: 0x000E2060
        public override void receiveMessages()
        {
            NetIncomingMessage inc;

            while ((inc = this.server.ReadMessage()) != null)
            {
                NetIncomingMessageType messageType = inc.MessageType;
                if (messageType <= NetIncomingMessageType.Data)
                {
                    if (messageType != NetIncomingMessageType.ConnectionApproval)
                    {
                        if (messageType != NetIncomingMessageType.Data)
                        {
                            goto IL_62;
                        }
                        LidgrenServer.parseDataMessageFromClient(inc);
                    }
                    else
                    {
                        inc.SenderConnection.Approve();
                        this.addNewFarmer(inc.SenderConnection.RemoteUniqueIdentifier);
                    }
                }
                else if (messageType != NetIncomingMessageType.DiscoveryRequest)
                {
                    if (messageType != NetIncomingMessageType.ErrorMessage)
                    {
                        goto IL_62;
                    }
                    Game1.debugOutput = inc.ToString();
                }
                else
                {
                    this.handshakeWithPlayer(inc);
                }
IL_6D:
                this.server.Recycle(inc);
                continue;
IL_62:
                Game1.debugOutput = inc.ToString();
                goto IL_6D;
            }
        }
Пример #12
0
 public NetMessageView(
     NetIncomingMessageType messageType,
     NetMessageType baseMessageType,
     bool isFragment,
     TimeSpan time,
     int sequenceNumber,
     IPEndPoint?endPoint,
     NetConnection?connection,
     NetBuffer?message,
     ReadOnlySpan <byte> span,
     int bitLength)
 {
     MessageType     = messageType;
     BaseMessageType = baseMessageType;
     IsFragment      = isFragment;
     Time            = time;
     SequenceNumber  = sequenceNumber;
     EndPoint        = endPoint;
     Connection      = connection;
     Buffer          = message;
     Span            = span;
     BitLength       = bitLength;
 }
Пример #13
0
        public void Update()
        {
            // Recieve messages from the server.
            while ((_msgBuffer = _client.ReadMessage()) != null)
            {
                NetIncomingMessageType msgType = _msgBuffer.MessageType;

                switch (msgType)
                {
                case NetIncomingMessageType.StatusChanged:
                {
                    NetConnectionStatus status = (NetConnectionStatus)_msgBuffer.ReadByte();

                    if (status == NetConnectionStatus.Disconnected)
                    {
                        string reason = _msgBuffer.ReadString();
                        switch (reason)
                        {
                        case "kicked":
                        {
                            _pbag.GameManager.SetErrorState(ErrorMsg.Kicked);
                            break;
                        }

                        case "banned":
                        {
                            _pbag.GameManager.SetErrorState(ErrorMsg.Banned);
                            break;
                        }

                        case "serverfull":
                        {
                            _pbag.GameManager.SetErrorState(ErrorMsg.ServerFull);
                            break;
                        }

                        case "versionmismatch":
                        {
                            _pbag.GameManager.SetErrorState(ErrorMsg.VersionMismatch);
                            break;
                        }

                        case "shutdown":
                        {
                            _pbag.GameManager.SetErrorState(ErrorMsg.ServerShutdown);
                            break;
                        }

                        case "restart":
                        {
                            _pbag.GameManager.SetErrorState(ErrorMsg.ServerRestart);
                            break;
                        }

                        case "exit":
                        {
                            //Todo need to find more info about this case in the disconnect switch
                            break;
                        }

                        default:
                        {
                            _pbag.GameManager.Temperrormsg(reason);
                            //Pbag.GameManager.SetErrorState(ErrorMsg.Unkown);
                            break;
                        }
                        }
                    }
                    break;
                }

                case NetIncomingMessageType.DiscoveryResponse:
                {
                    string            name        = _msgBuffer.ReadString();
                    int               playercount = _msgBuffer.ReadInt32();
                    int               playermax   = _msgBuffer.ReadInt32();
                    bool              lan         = _msgBuffer.ReadBoolean();
                    string            ip          = _msgBuffer.SenderEndpoint.Address.ToString();
                    ServerInformation newserver   = new ServerInformation(name, ip, playercount, playermax, lan);
                    _pbag.GameManager.AddServer(newserver);
                    break;
                }

                case NetIncomingMessageType.ConnectionApproval:
                {
                    break;
                }

                case NetIncomingMessageType.Data:
                {
                    PacketType dataType = (PacketType)_msgBuffer.ReadByte();
                    switch (dataType)
                    {
                    case PacketType.WorldMapSize:
                    {
                        _pbag.WorldManager.Mapsize = _msgBuffer.ReadInt32();
                        _pbag.WorldManager.Start();
                        break;
                    }

                    case PacketType.PlayerInitialUpdate:
                    {
                        _pbag.Player.Myid     = _msgBuffer.ReadInt32();
                        _pbag.Player.Name     = _msgBuffer.ReadString();
                        _pbag.Player.Position = _msgBuffer.ReadVector3();
                        break;
                    }

                    case PacketType.PlayerJoined:
                    {
                        ClientPlayer dummy = new ClientPlayer(_pbag.GameManager.Conmanager);
                        dummy.Id       = _msgBuffer.ReadInt32();
                        dummy.Name     = _msgBuffer.ReadString();
                        dummy.Position = _msgBuffer.ReadVector3();
                        dummy.Heading  = _msgBuffer.ReadVector3();
                        _pbag.WorldManager.Playerlist.Add(dummy.Id, dummy);
                        break;
                    }

                    case PacketType.PlayerLeft:
                    {
                        int id = _msgBuffer.ReadInt32();
                        _pbag.WorldManager.Playerlist.Remove(id);
                        break;
                    }

                    case PacketType.PlayerMovementUpdate:
                    {
                        int id = _msgBuffer.ReadInt32();
                        if (_pbag.WorldManager.Playerlist.ContainsKey(id))
                        {
                            _pbag.WorldManager.Playerlist[id].Position = _msgBuffer.ReadVector3();
                        }
                        break;
                    }

                    case PacketType.PlayerNameSet:
                    {
                        int id = _msgBuffer.ReadInt32();
                        //Lets see if its my id or someones else id
                        if (_pbag.Player.Myid == id)
                        {
                            _pbag.Player.Name = _msgBuffer.ReadString();
                        }
                        else
                        {
                            //Then its someones else its id
                            if (_pbag.WorldManager.Playerlist.ContainsKey(id))
                            {
                                _pbag.WorldManager.Playerlist[id].Position = _msgBuffer.ReadVector3();
                            }
                        }
                        break;
                    }

                    default:
                    {
                        break;
                    }
                    }
                }
                break;
                }
            }
        }
Пример #14
0
 internal NetIncomingMessage(NetIncomingMessageType tp)
 {
     m_incomingMessageType = tp;
 }
 /// <summary>
 /// Disables receiving of the specified type of message
 /// </summary>
 public void DisableMessageType(NetIncomingMessageType type)
 {
     m_disabledTypes |= type;
 }
        /// <summary>
        /// NetPeerConfiguration constructor
        /// </summary>
        public NetPeerConfiguration(string appIdentifier)
        {
            if (string.IsNullOrEmpty(appIdentifier))
                throw new NetException("App identifier must be at least one character long");
            m_appIdentifier = appIdentifier.ToString(System.Globalization.CultureInfo.InvariantCulture);

            //
            // default values
            //
            m_disabledTypes = NetIncomingMessageType.ConnectionApproval | NetIncomingMessageType.UnconnectedData | NetIncomingMessageType.VerboseDebugMessage | NetIncomingMessageType.ConnectionLatencyUpdated | NetIncomingMessageType.NatIntroductionSuccess;
            m_networkThreadName = "Lidgren network thread";
            m_localAddress = IPAddress.Any;
            m_broadcastAddress = IPAddress.Broadcast;
            var ip = NetUtility.GetBroadcastAddress();
            if (ip != null)
            {
                m_broadcastAddress = ip;
            }
            m_port = 0;
            m_receiveBufferSize = 131071;
            m_sendBufferSize = 131071;
            m_acceptIncomingConnections = false;
            m_maximumConnections = 32;
            m_defaultOutgoingMessageCapacity = 16;
            m_pingInterval = 4.0f;
            m_connectionTimeout = 25.0f;
            m_useMessageRecycling = true;
            m_resendHandshakeInterval = 3.0f;
            m_maximumHandshakeAttempts = 5;
            m_autoFlushSendQueue = true;

            m_maximumTransmissionUnit = kDefaultMTU;
            m_autoExpandMTU = false;
            m_expandMTUFrequency = 2.0f;
            m_expandMTUFailAttempts = 5;

            m_loss = 0.0f;
            m_minimumOneWayLatency = 0.0f;
            m_randomOneWayLatency = 0.0f;
            m_duplicates = 0.0f;

            m_isLocked = false;
        }
 /// <summary>
 /// Gets if receiving of the specified type of message is enabled
 /// </summary>
 public bool IsMessageTypeEnabled(NetIncomingMessageType type)
 {
     return !((m_disabledTypes & type) == type);
 }
 /// <summary>
 /// Disables receiving of the specified type of message
 /// </summary>
 public void DisableMessageType(NetIncomingMessageType type)
 {
     m_disabledTypes |= type;
 }
		/// <summary>
		/// Creates an incoming message with the required capacity for releasing to the application
		/// </summary>
		internal NetIncomingMessage CreateIncomingMessage(NetIncomingMessageType tp, int requiredCapacity)
		{
			NetIncomingMessage retval;
			if (m_incomingMessagesPool.TryDequeue(out retval))
				retval.Reset();
			else
				retval = new NetIncomingMessage();

			NetException.Assert(retval.m_status == NetIncomingMessageReleaseStatus.NotReleased);

			retval.m_incomingType = tp;
			retval.m_senderConnection = null;
			retval.m_senderEndpoint = null;
			retval.m_status = NetIncomingMessageReleaseStatus.NotReleased;

			if (requiredCapacity > 0)
			{
				byte[] storage = GetStorage(requiredCapacity);
				retval.m_data = storage;
			}
			else
			{
				retval.m_data = null;
			}

			return retval;
		}
Пример #20
0
		/// <summary>
		/// Creates an incoming message with the required capacity for releasing to the application
		/// </summary>
		internal NetIncomingMessage CreateIncomingMessage(NetIncomingMessageType tp, string text)
		{
			NetIncomingMessage retval;
			if (string.IsNullOrEmpty(text))
			{
				retval = CreateIncomingMessage(tp, 1);
				retval.Write(string.Empty);
				return retval;
			}

			int numBytes = System.Text.Encoding.UTF8.GetByteCount(text);
			retval = CreateIncomingMessage(tp, numBytes + (numBytes > 127 ? 2 : 1));
			retval.Write(text);

			return retval;
		}
Пример #21
0
 public bool CanCreateContext(NetIncomingMessageType messageType)
 {
     return(messageType == NetIncomingMessageType.StatusChanged || messageType == NetIncomingMessageType.Data);
 }
Пример #22
0
        internal static void Find(NetworkSessionType sessionType)
        {
            NetPeerConfiguration peerConfiguration = new NetPeerConfiguration(MonoGamerPeer.applicationIdentifier);

            if (sessionType == NetworkSessionType.PlayerMatch)
            {
                peerConfiguration.EnableMessageType((NetIncomingMessageType)2);
                peerConfiguration.EnableMessageType((NetIncomingMessageType)2048);
            }
            else
            {
                peerConfiguration.EnableMessageType((NetIncomingMessageType)32);
            }
            if (MonoGameNetworkConfiguration.Broadcast != IPAddress.None)
            {
                peerConfiguration.set_BroadcastAddress(MonoGameNetworkConfiguration.Broadcast);
            }
            MonoGamerPeer.netPeer = new NetPeer(peerConfiguration);
            MonoGamerPeer.netPeer.Start();
            if (sessionType == NetworkSessionType.PlayerMatch)
            {
                MonoGamerPeer.GetServerList(MonoGamerPeer.netPeer);
            }
            else
            {
                MonoGamerPeer.netPeer.DiscoverLocalPeers(MonoGamerPeer.port);
            }
            DateTime now = DateTime.Now;

            MonoGamerPeer.discoveryMsgs = new List <NetIncomingMessage>();
            do
            {
                NetIncomingMessage netIncomingMessage;
                while ((netIncomingMessage = MonoGamerPeer.netPeer.ReadMessage()) != null)
                {
                    NetIncomingMessageType messageType = netIncomingMessage.get_MessageType();
                    if (messageType <= 128)
                    {
                        if (messageType != 2)
                        {
                            if (messageType != 64)
                            {
                                if (messageType == 128)
                                {
                                    ;
                                }
                            }
                            else
                            {
                                MonoGamerPeer.discoveryMsgs.Add(netIncomingMessage);
                            }
                        }
                        else if (netIncomingMessage.get_SenderEndpoint().Equals((object)MonoGamerPeer.m_masterServer))
                        {
                            MonoGamerPeer.discoveryMsgs.Add(netIncomingMessage);
                        }
                    }
                    else if (messageType == 256 || messageType == 512 || messageType == 1024)
                    {
                        ;
                    }
                }
            }while ((DateTime.Now - now).Seconds <= 2);
            MonoGamerPeer.netPeer.Shutdown("Find shutting down");
        }
Пример #23
0
        private void MGServer_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker     backgroundWorker  = sender as BackgroundWorker;
            NetPeerConfiguration peerConfiguration = new NetPeerConfiguration(MonoGamerPeer.applicationIdentifier);

            peerConfiguration.EnableMessageType((NetIncomingMessageType)32);
            peerConfiguration.EnableMessageType((NetIncomingMessageType)64);
            peerConfiguration.EnableMessageType((NetIncomingMessageType)2048);
            if (this.availableSession == null)
            {
                peerConfiguration.set_Port(MonoGamerPeer.port);
            }
            this.peer = new NetServer(peerConfiguration);
            ((NetPeer)this.peer).Start();
            this.myLocalAddress  = MonoGamerPeer.GetMyLocalIpAddress();
            this.myLocalEndPoint = new IPEndPoint(IPAddress.Parse(this.myLocalAddress), MonoGamerPeer.port);
            while (this.session.LocalGamers.Count <= 0)
            {
                Thread.Sleep(10);
            }
            if (this.availableSession != null)
            {
                if (!this.online)
                {
                    ((NetPeer)this.peer).Connect(this.availableSession.EndPoint);
                }
                else
                {
                    MonoGamerPeer.RequestNATIntroduction(this.availableSession.EndPoint, (NetPeer)this.peer);
                }
            }
            else if (this.online)
            {
                IPAddress address = NetUtility.Resolve(MonoGamerPeer.masterServer);
                if (address == null)
                {
                    throw new Exception("Could not resolve live host");
                }
                MonoGamerPeer.m_masterServer = new IPEndPoint(address, MonoGamerPeer.masterserverport);
                LocalNetworkGamer  localNetworkGamer = this.session.LocalGamers[0];
                NetOutgoingMessage message           = ((NetPeer)this.peer).CreateMessage();
                message.Write((byte)0);
                message.Write(this.session.AllGamers.Count);
                message.Write(localNetworkGamer.Gamertag);
                message.Write(this.session.PrivateGamerSlots);
                message.Write(this.session.MaxGamers);
                message.Write(localNetworkGamer.IsHost);
                message.Write(this.myLocalEndPoint);
                message.Write(((NetPeer)this.peer).get_Configuration().get_AppIdentifier());
                int[] propertyData = new int[this.session.SessionProperties.Count * 2];
                NetworkSessionProperties.WriteProperties(this.session.SessionProperties, propertyData);
                for (int index = 0; index < propertyData.Length; ++index)
                {
                    message.Write(propertyData[index]);
                }
                ((NetPeer)this.peer).SendUnconnectedMessage(message, MonoGamerPeer.m_masterServer);
            }
            do
            {
                NetIncomingMessage netIncomingMessage;
                while ((netIncomingMessage = ((NetPeer)this.peer).ReadMessage()) != null)
                {
                    NetIncomingMessageType messageType = netIncomingMessage.get_MessageType();
                    if (messageType <= 128)
                    {
                        if (messageType <= 8)
                        {
                            switch (messageType - 1)
                            {
                            case 0:
                                NetConnectionStatus connectionStatus = (NetConnectionStatus)(int)netIncomingMessage.ReadByte();
                                if (connectionStatus == 5)
                                {
                                    this.session.commandQueue.Enqueue(new CommandEvent((ICommand) new CommandGamerLeft(netIncomingMessage.get_SenderConnection().get_RemoteUniqueIdentifier())));
                                }
                                if (connectionStatus == 3 && !this.pendingGamers.ContainsKey(netIncomingMessage.get_SenderConnection().get_RemoteUniqueIdentifier()))
                                {
                                    this.pendingGamers.Add(netIncomingMessage.get_SenderConnection().get_RemoteUniqueIdentifier(), netIncomingMessage.get_SenderConnection());
                                    this.SendProfileRequest(netIncomingMessage.get_SenderConnection());
                                    break;
                                }
                                else
                                {
                                    break;
                                }

                            case 1:
                                break;

                            default:
                                if (messageType == 8)
                                {
                                    switch (netIncomingMessage.ReadByte())
                                    {
                                    case (byte)0:
                                        byte[] data = new byte[netIncomingMessage.get_LengthBytes() - 1];
                                        netIncomingMessage.ReadBytes(data, 0, data.Length);
                                        this.session.commandQueue.Enqueue(new CommandEvent((ICommand) new CommandReceiveData(netIncomingMessage.get_SenderConnection().get_RemoteUniqueIdentifier(), data)));
                                        break;

                                    case (byte)3:
                                        string endPoint1 = netIncomingMessage.ReadString();
                                        try
                                        {
                                            IPEndPoint endPoint2 = MonoGamerPeer.ParseIPEndPoint(endPoint1);
                                            if (this.myLocalEndPoint.ToString() != endPoint2.ToString() && !this.AlreadyConnected(endPoint2))
                                            {
                                                ((NetPeer)this.peer).Connect(endPoint2);
                                                break;
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            break;
                                        }

                                    case (byte)4:
                                        if (this.pendingGamers.ContainsKey(netIncomingMessage.get_SenderConnection().get_RemoteUniqueIdentifier()))
                                        {
                                            this.pendingGamers.Remove(netIncomingMessage.get_SenderConnection().get_RemoteUniqueIdentifier());
                                            netIncomingMessage.ReadInt32();
                                            string str = netIncomingMessage.ReadString();
                                            netIncomingMessage.ReadInt32();
                                            netIncomingMessage.ReadInt32();
                                            GamerStates gamerStates = (GamerStates)(netIncomingMessage.ReadInt32() & -2);
                                            this.session.commandQueue.Enqueue(new CommandEvent((ICommand) new CommandGamerJoined(netIncomingMessage.get_SenderConnection().get_RemoteUniqueIdentifier())
                                            {
                                                GamerTag = str,
                                                State    = gamerStates
                                            }));
                                            break;
                                        }
                                        else
                                        {
                                            break;
                                        }

                                    case (byte)5:
                                        this.SendProfile(netIncomingMessage.get_SenderConnection());
                                        break;

                                    case (byte)6:
                                        GamerStates gamerStates1 = (GamerStates)(netIncomingMessage.ReadInt32() & -2);
                                        using (IEnumerator <NetworkGamer> enumerator = this.session.RemoteGamers.GetEnumerator())
                                        {
                                            while (enumerator.MoveNext())
                                            {
                                                NetworkGamer current = enumerator.Current;
                                                if (current.RemoteUniqueIdentifier == netIncomingMessage.get_SenderConnection().get_RemoteUniqueIdentifier())
                                                {
                                                    current.State = gamerStates1;
                                                }
                                            }
                                            break;
                                        }

                                    case (byte)7:
                                        NetworkSessionState networkSessionState = (NetworkSessionState)netIncomingMessage.ReadInt32();
                                        using (IEnumerator <NetworkGamer> enumerator = this.session.RemoteGamers.GetEnumerator())
                                        {
                                            while (enumerator.MoveNext())
                                            {
                                                NetworkGamer current = enumerator.Current;
                                                if (current.RemoteUniqueIdentifier == netIncomingMessage.get_SenderConnection().get_RemoteUniqueIdentifier() && (current.IsHost && networkSessionState == NetworkSessionState.Playing))
                                                {
                                                    this.session.StartGame();
                                                }
                                            }
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else if (messageType != 32)
                        {
                            if (messageType == 128)
                            {
                                ;
                            }
                        }
                        else
                        {
                            LocalNetworkGamer  localNetworkGamer = this.session.LocalGamers[0];
                            NetOutgoingMessage message           = ((NetPeer)this.peer).CreateMessage();
                            message.Write(this.session.RemoteGamers.Count);
                            message.Write(localNetworkGamer.Gamertag);
                            message.Write(this.session.PrivateGamerSlots);
                            message.Write(this.session.MaxGamers);
                            message.Write(localNetworkGamer.IsHost);
                            int[] propertyData = new int[this.session.SessionProperties.Count * 2];
                            NetworkSessionProperties.WriteProperties(this.session.SessionProperties, propertyData);
                            for (int index = 0; index < propertyData.Length; ++index)
                            {
                                message.Write(propertyData[index]);
                            }
                            ((NetPeer)this.peer).SendDiscoveryResponse(message, netIncomingMessage.get_SenderEndpoint());
                        }
                    }
                    else if (messageType <= 512)
                    {
                        if (messageType == 256 || messageType == 512)
                        {
                            ;
                        }
                    }
                    else if (messageType != 1024 && messageType == 2048)
                    {
                        ((NetPeer)this.peer).Connect(netIncomingMessage.get_SenderEndpoint());
                    }
                }
                Thread.Sleep(1);
                if (backgroundWorker.CancellationPending)
                {
                    e.Cancel  = true;
                    this.done = true;
                }
            }while (!this.done);
        }
Пример #24
0
        private INSTANCE_TYPE PrivInitialize()
        {
            Console.WriteLine("\n****************\nEnter IP Address\n****************\n");
            Console.ForegroundColor = ConsoleColor.Yellow;
            _server_ip = Console.ReadLine();

            NetPeerConfiguration config = new NetPeerConfiguration("ServerClientClient");

            config.AcceptIncomingConnections = true;

            config.MaximumConnections = 100;

            config.MaximumHandshakeAttempts = 3;

            config.ResendHandshakeInterval = 0.5f;

            config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);

            _connection = new NetClient(config);
            Debug.Assert(_connection != null);

            _connection.Start();

            System.Net.IPEndPoint ep = NetUtility.Resolve(_server_ip, _server_port);

            NetIncomingMessage pInMsg;

            _connection.Connect(ep);

            bool connected = false;

            while (connected == false)
            {
                if ((pInMsg = _connection.ReadMessage()) != null)
                {
                    NetIncomingMessageType type = pInMsg.MessageType;
                    switch (type)
                    {
                    case NetIncomingMessageType.DebugMessage:
                        string debug1 = pInMsg.ReadString();
                        Debug.WriteLine(debug1);
                        break;

                    case NetIncomingMessageType.VerboseDebugMessage:
                        string debug2 = pInMsg.ReadString();
                        Debug.WriteLine(debug2);
                        break;

                    case NetIncomingMessageType.WarningMessage:
                        string warning = pInMsg.ReadString();
                        Debug.WriteLine(warning);
                        break;

                    case NetIncomingMessageType.ErrorMessage:
                        Debug.WriteLine(pInMsg.ReadString());
                        break;

                    case NetIncomingMessageType.StatusChanged:
                        NetConnectionStatus status = (NetConnectionStatus)pInMsg.ReadByte();
                        string reason = pInMsg.ReadString();
                        Debug.WriteLine(status.ToString() + ": " + reason);

                        if (status == NetConnectionStatus.Disconnected)
                        {
                            Debug.WriteLine("Server timeout. Becoming Server.");
                            _connection.Shutdown("");
                            InitializeServer();
                            connected = true;
                        }
                        else if (status == NetConnectionStatus.Connected)
                        {
                            Debug.WriteLine("Server found.");
                            InitializeClient();
                            connected = true;
                        }

                        break;

                    case NetIncomingMessageType.UnconnectedData:
                        Debug.WriteLine("Recv(" + pInMsg.SenderEndPoint + "): " + pInMsg.ReadString());
                        break;

                    case NetIncomingMessageType.DiscoveryResponse:
                        Debug.WriteLine("Found server at " + pInMsg.SenderEndPoint + " name: " + pInMsg.ReadString());
                        _connection.Connect(pInMsg.SenderEndPoint);
                        break;
                    }
                }

                _connection.Recycle(pInMsg);
            }

            return(_connection_type);
        }
Пример #25
0
        private void PrivProcessData()
        {
            NetIncomingMessage buff;

            while ((_connection.ReadMessage(out buff)) == true)
            {
                NetIncomingMessageType type = buff.MessageType;
                switch (type)
                {
                case NetIncomingMessageType.DebugMessage:
                    string debug1 = buff.ReadString();
                    Debug.WriteLine(debug1);
                    break;

                case NetIncomingMessageType.VerboseDebugMessage:
                    string debug2 = buff.ReadString();
                    Debug.WriteLine(debug2);
                    break;

                case NetIncomingMessageType.WarningMessage:
                    string warning = buff.ReadString();
                    Debug.WriteLine(warning);
                    break;

                case NetIncomingMessageType.ErrorMessage:
                    Debug.WriteLine(buff.ReadString());
                    break;

                case NetIncomingMessageType.StatusChanged:
                    NetConnectionStatus status = (NetConnectionStatus)buff.ReadByte();
                    string reason = buff.ReadString();
                    Debug.WriteLine(status.ToString() + ": " + reason);
                    break;

                case NetIncomingMessageType.Data:

                    int t;

                    if (buff.ReadInt32(out t))
                    {
                        switch ((DataItem.DATA_TYPE)t)
                        {
                        case DataItem.DATA_TYPE.ACK_TYPE:

                            break;

                        case DataItem.DATA_TYPE.EVENT_TYPE:
                            EventData event_d = new EventData();
                            event_d.Deserialize(ref buff);
                            DataManager.PushToIn(new DataItem(DataItem.DATA_TYPE.EVENT_TYPE, event_d));
                            break;

                        case DataItem.DATA_TYPE.INPUT_TYPE:
                            InputData input = new InputData();
                            input.Deserialize(ref buff);
                            DataManager.PushToIn(new DataItem(DataItem.DATA_TYPE.INPUT_TYPE, input));
                            break;

                        case DataItem.DATA_TYPE.SIM_DATA:
                            SimData sim = new SimData();
                            sim.Deserialize(ref buff);
                            DataManager.PushToIn(new DataItem(DataItem.DATA_TYPE.SIM_DATA, sim));
                            break;

                        case DataItem.DATA_TYPE.STATE_TYPE:
                            StateData state = new StateData();
                            state.Deserialize(ref buff);
                            DataManager.PushToIn(new DataItem(DataItem.DATA_TYPE.STATE_TYPE, state));
                            break;
                        }
                    }

                    break;

                case NetIncomingMessageType.UnconnectedData:
                    Debug.WriteLine("Recv(" + buff.SenderEndPoint + "): " + buff.ReadString());
                    break;

                case NetIncomingMessageType.DiscoveryResponse:
                    Debug.WriteLine("Found server at " + buff.SenderEndPoint + " name: " + buff.ReadString());
                    _connection.Connect(buff.SenderEndPoint);
                    break;
                }

                _connection.Recycle(buff);
            }
        }
		/// <summary>
		/// Creates an incoming message with the required capacity for releasing to the application
		/// </summary>
		internal NetIncomingMessage CreateIncomingMessage(NetIncomingMessageType tp, string contents)
		{
			NetIncomingMessage retval;
			if (string.IsNullOrEmpty(contents))
			{
				retval = CreateIncomingMessage(tp, 1);
				retval.Write("");
				return retval;
			}

			byte[] bytes = System.Text.Encoding.UTF8.GetBytes(contents);
			retval = CreateIncomingMessage(tp, bytes.Length + (bytes.Length > 127 ? 2 : 1));
			retval.Write(contents);

			return retval;
		}
Пример #27
0
        public override void Core()
        {
            if (this._state > MPPeer.PeerState.Inited)
            {
                NetIncomingMessage message;
                while ((message = this._lidgrenPeer.ReadMessage()) != null)
                {
                    byte num;
                    int  num2;
                    NetConnectionStatus status;
                    bool flag;
                    int  num3;
                    NetIncomingMessageType messageType = message.MessageType;
                    switch (messageType)
                    {
                    case NetIncomingMessageType.VerboseDebugMessage:
                    case NetIncomingMessageType.DebugMessage:
                    case NetIncomingMessageType.WarningMessage:
                    case NetIncomingMessageType.ErrorMessage:
                        Debug.LogError(message.ReadString());
                        break;
                    }
                    if (this._state != MPPeer.PeerState.ServerListening)
                    {
                        goto Label_024D;
                    }
                    messageType = message.MessageType;
                    switch (messageType)
                    {
                    case NetIncomingMessageType.StatusChanged:
                        status = (NetConnectionStatus)message.ReadByte();
                        Debug.Log(message.ReadString());
                        if (status != NetConnectionStatus.Disconnected)
                        {
                            goto Label_01C2;
                        }
                        flag = false;
                        num3 = 2;
                        goto Label_01AE;

                    case NetIncomingMessageType.ConnectionApproval:
                        if (!(message.ReadString() == "ng"))
                        {
                            goto Label_0130;
                        }
                        num  = 0;
                        num2 = 2;
                        goto Label_00D2;

                    case NetIncomingMessageType.Data:
                        this.ServerDispatchDataEvent(message);
                        goto Label_0498;

                    default:
                        goto Label_0498;
                    }
Label_00B9:
                    if (this._peerMap[num2] == null)
                    {
                        num = (byte)num2;
                        goto Label_00E0;
                    }
                    num2++;
Label_00D2:
                    if (num2 < this._peerMap.Length)
                    {
                        goto Label_00B9;
                    }
Label_00E0:
                    this._peerMap[num] = message.SenderConnection;
                    NetOutgoingMessage localHail = this._lidgrenPeer.CreateMessage();
                    localHail.Data[0]     = base.PackHeader(num, 1);
                    localHail.Data[1]     = num;
                    localHail.LengthBytes = 2;
                    message.SenderConnection.Approve(localHail);
                    goto Label_0498;
Label_0130:
                    message.SenderConnection.Deny();
                    goto Label_0498;
Label_016A:
                    if (this._peerMap[num3].RemoteUniqueIdentifier == message.SenderConnection.RemoteUniqueIdentifier)
                    {
                        flag = true;
                        this._peerMap[num3] = null;
                        this._serverConnectedPeerCount--;
                        goto Label_0498;
                    }
                    num3++;
Label_01AE:
                    if (num3 < this._peerMap.Length)
                    {
                        goto Label_016A;
                    }
                    goto Label_0498;
Label_01C2:
                    if (status == NetConnectionStatus.Connected)
                    {
                        int connID = 0;
                        for (int i = 2; i < this._peerMap.Length; i++)
                        {
                            if (this._peerMap[i].RemoteUniqueIdentifier == message.SenderConnection.RemoteUniqueIdentifier)
                            {
                                connID = i;
                                break;
                            }
                        }
                        this._serverConnectedPeerCount++;
                        if (base.onConnected != null)
                        {
                            base.onConnected(connID);
                        }
                    }
                    goto Label_0498;
Label_024D:
                    if (this._state == MPPeer.PeerState.ClientConnecting)
                    {
                        if (message.MessageType == NetIncomingMessageType.StatusChanged)
                        {
                            NetConnectionStatus status2 = (NetConnectionStatus)message.ReadByte();
                            string str3 = message.ReadString();
                            Debug.Log(string.Format("{0}, {1}", status2, str3));
                            if (status2 == NetConnectionStatus.Connected)
                            {
                                NetIncomingMessage remoteHailMessage = message.SenderConnection.RemoteHailMessage;
                                int num6 = base.ParsePeerID(remoteHailMessage.Data);
                                int num7 = base.ParseMessageType(remoteHailMessage.Data);
                                int num8 = remoteHailMessage.Data[1];
                                this._peerID = num6;
                                this._state  = MPPeer.PeerState.ClientConnected;
                                if (base.onConnected != null)
                                {
                                    base.onConnected(this._peerID);
                                }
                            }
                        }
                        else if (message.MessageType != NetIncomingMessageType.Data)
                        {
                        }
                    }
                    else
                    {
                        if (this._state != MPPeer.PeerState.ClientConnected)
                        {
                            goto Label_03F7;
                        }
                        messageType = message.MessageType;
                        if (messageType == NetIncomingMessageType.StatusChanged)
                        {
                            NetConnectionStatus status3 = (NetConnectionStatus)message.ReadByte();
                            Debug.Log(message.ReadString());
                            if (status3 == NetConnectionStatus.Disconnected)
                            {
                                if (base.onDisconnected != null)
                                {
                                    base.onDisconnected(this._peerID);
                                }
                                this._state = MPPeer.PeerState.ClientDropped;
                            }
                        }
                        else if (messageType == NetIncomingMessageType.Data)
                        {
                            goto Label_037C;
                        }
                    }
                    goto Label_0498;
Label_037C:
                    if (base.ParseMessageType(message.Data) == 2)
                    {
                        this._totalPeerCount = message.Data[1];
                        this._state          = MPPeer.PeerState.Established;
                        if (base.onEstablished != null)
                        {
                            base.onEstablished();
                        }
                    }
                    else if (base.onPacket != null)
                    {
                        base.onPacket(message.Data, message.LengthBytes - 1, 1, (int)message.DeliveryMethod);
                    }
                    goto Label_0498;
Label_03F7:
                    if (this._state == MPPeer.PeerState.Established)
                    {
                        if (this.isServer)
                        {
                            messageType = message.MessageType;
                            if ((messageType != NetIncomingMessageType.StatusChanged) && (messageType == NetIncomingMessageType.Data))
                            {
                                this.ServerDispatchDataEvent(message);
                            }
                        }
                        else
                        {
                            messageType = message.MessageType;
                            if (((messageType != NetIncomingMessageType.StatusChanged) && (messageType == NetIncomingMessageType.Data)) && (base.onPacket != null))
                            {
                                base.onPacket(message.Data, message.LengthBytes - 1, 1, (int)message.DeliveryMethod);
                            }
                        }
                    }
Label_0498:
                    this._lidgrenPeer.Recycle(message);
                }
            }
        }
		internal NetIncomingMessage CreateIncomingMessage(NetIncomingMessageType tp, byte[] copyFrom, int offset, int copyLength)
		{
			NetIncomingMessage retval;
			if (m_incomingMessagesPool.TryDequeue(out retval))
				retval.Reset();
			else
				retval = new NetIncomingMessage();

			NetException.Assert(retval.m_status == NetIncomingMessageReleaseStatus.NotReleased);

			retval.m_data = GetStorage(copyLength);
			Buffer.BlockCopy(copyFrom, offset, retval.m_data, 0, copyLength);

			retval.m_bitLength = copyLength * 8;
			retval.m_incomingType = tp;
			retval.m_senderConnection = null;
			retval.m_senderEndpoint = null;

			return retval;
		}
Пример #29
0
 public IDisposable OnMessage(NetIncomingMessageType type, Func <NetIncomingMessage, Task> handler)
 {
     return(messageHandlers.Add(type, handler));
 }
 /// <summary>
 /// Enables receiving of the specified type of message
 /// </summary>
 public void EnableMessageType(NetIncomingMessageType type)
 {
     m_disabledTypes &= (~type);
 }
Пример #31
0
        internal virtual void ProcessRawMessage(NetIncomingMessage msg)
        {
            // Read message type.
            NetIncomingMessageType type = msg.MessageType;

            try
            {
                switch (type)
                {
                case NetIncomingMessageType.Error:
                    bool worked = msg.ReadString(out string text);
                    LogError("Unexpected network message error: {0}", worked ? text : "no info given");
                    break;

                case NetIncomingMessageType.StatusChanged:
                    byte statusByte            = msg.ReadByte();
                    NetConnectionStatus status = (NetConnectionStatus)statusByte;
                    ProcessStatusChanged(msg, status);
                    break;

                case NetIncomingMessageType.UnconnectedData:
                    ProcessUnconnectedData(msg);
                    break;

                case NetIncomingMessageType.ConnectionApproval:
                    ProcessConnectionRequest(msg);
                    break;

                case NetIncomingMessageType.Data:
                    JNet.Playback.LogIncoming(msg);
                    ProcessData(msg);
                    break;

                case NetIncomingMessageType.DiscoveryRequest:
                    throw new System.NotImplementedException();

                case NetIncomingMessageType.DiscoveryResponse:
                    throw new NotImplementedException();

                case NetIncomingMessageType.VerboseDebugMessage:
                    ProcessLogMessage(msg, type);
                    break;

                case NetIncomingMessageType.DebugMessage:
                    ProcessLogMessage(msg, type);
                    break;

                case NetIncomingMessageType.WarningMessage:
                    ProcessLogMessage(msg, type);
                    break;

                case NetIncomingMessageType.ErrorMessage:
                    ProcessLogMessage(msg, type);
                    break;

                case NetIncomingMessageType.NatIntroductionSuccess:
                    throw new NotImplementedException();

                default:
                    Log("Unhandled incoming message type: {0}", type);
                    break;
                }
            }
            catch (Exception e)
            {
                JNetMsgReadException ex = new JNetMsgReadException("Unhandled expception while handling message of type: " + type, e);
                ex.NetMessage = msg;

                throw ex;
            }
        }
 /// <summary>
 /// Enables or disables receiving of the specified type of message
 /// </summary>
 public void SetMessageTypeEnabled(NetIncomingMessageType type, bool enabled)
 {
     if (enabled)
         m_disabledTypes &= (~type);
     else
         m_disabledTypes |= type;
 }
Пример #33
0
 public void DisableMessageType(NetIncomingMessageType type)
 {
     base.Configuration.DisableMessageType(type);
 }
 /// <summary>
 /// Enables receiving of the specified type of message
 /// </summary>
 public void EnableMessageType(NetIncomingMessageType type)
 {
     m_disabledTypes &= (~type);
 }
Пример #35
0
 public UnhandledMessageEventArgs(NetIncomingMessageType myMessageType, int myLengthBytes)
 {
     messageType = myMessageType;
     lengthBytes = myLengthBytes;
 }
 /// <summary>
 /// Gets if receiving of the specified type of message is enabled
 /// </summary>
 public bool IsMessageTypeEnabled(NetIncomingMessageType type)
 {
     return(!((m_disabledTypes & type) == type));
 }
 internal NetIncomingMessage(NetIncomingMessageType tp)
 {
     m_incomingMessageType = tp;
 }
		public bool CanCreateContext(NetIncomingMessageType messageType)
		{
			return messageType == NetIncomingMessageType.StatusChanged || messageType == NetIncomingMessageType.Data;
		}
 /// <summary>
 /// Enables receiving of the specified type of message.
 /// </summary>
 public void EnableMessageType(NetIncomingMessageType type)
 {
     _disabledTypes &= ~type;
 }