Esempio n. 1
0
        private void ServiceLidgrenMessage(NetIncomingMessage msg)
        {
            if (msg == null)
            {
                return;
            }

            switch (msg.MessageType)
            {
            case NetIncomingMessageType.StatusChanged:
                try
                {
                    HandleStatusChange((NetConnectionStatus)msg.ReadByte());
                }
                catch (NetException e)
                {
#if UNITYDEBUG
                    ClassLogger.LogError("Malformed packet recieved. Packet indicated that it was a status change but had no info.");
#else
                    //TODO: What shall we do when the packet is malformed here?
#endif
                }
                catch (LoggableException e)
                {
                    //Checking this because it can cause some nasty GC to make these string adds.
                    if (ClassLogger.isStateEnabled(LogType.Debug))
                    {
                        ClassLogger.LogDebug(e.Message + " Inner: " + e.InnerException != null ? e.InnerException.Message : "");
                    }
                }
                break;

            //We can take advantage of using the same logic for both cases.
            //All that changes is we till the handler it is an internal message for a Data message type.
            case NetIncomingMessageType.ExternalHighlevelMessage:
            case NetIncomingMessageType.Data:
                try
                {
                    this.NetworkMessageHandler.DispatchMessage(this, msg, msg.MessageType == NetIncomingMessageType.Data);
                }
                catch (LoggableException e)
                {
                    //Checking this because it can cause some nasty GC to make these string adds.
                    if (ClassLogger.isStateEnabled(LogType.Debug))
                    {
                        ClassLogger.LogDebug(e.Message + " Inner: " + e.InnerException != null ? e.InnerException.Message : "");
                    }
                }
                break;
            }
        }