Exemplo n.º 1
0
        private void OnMessage(string message)
        {
            ;
            var msgObj = MessageSerializer.Deserailize(Regex.Unescape(message));

            switch (msgObj.FrameCommand)
            {
            case "CONNECTED":
                this.IsConnected = true;
                OnConntected?.Invoke();
                break;

            case "MESSAGE":
                OnMessageReceived?.Invoke(msgObj);
                break;

            case "RECEIPT":
                OnReceipt?.Invoke(msgObj);
                break;

            case "ERROR":
                OnError?.Invoke(msgObj.Headers["message"], msgObj);
                this.IsConnected = false;
                break;
            }
        }
Exemplo n.º 2
0
        public static void Update(GameTime time)
        {
            NetIncomingMessage message;

            while ((message = ReadMessage()) != null)
            {
                if (message.MessageType == NetIncomingMessageType.Data)
                {
                    OnData.Invoke(message);
                }
                else if (message.MessageType == NetIncomingMessageType.ConnectionLatencyUpdated)
                {
                    OnLatencyUpdated.Invoke(message);
                }
                else if (message.MessageType == NetIncomingMessageType.StatusChanged)
                {
                    OnStatusChanged.Invoke(message);
                }
                else if (message.MessageType == NetIncomingMessageType.ConnectionApproval)
                {
                    OnConnectionApproval.Invoke(message);
                }
                else if (message.MessageType == NetIncomingMessageType.UnconnectedData)
                {
                    OnUnconnectedData.Invoke(message);
                }
                else if (message.MessageType == NetIncomingMessageType.DiscoveryRequest)
                {
                    OnDiscoveryRequest.Invoke(message);
                }
                else if (message.MessageType == NetIncomingMessageType.DiscoveryResponse)
                {
                    OnDiscoveryResponse.Invoke(message);
                }
                else if (message.MessageType == NetIncomingMessageType.NatIntroductionSuccess)
                {
                    OnNatIntroSuccess.Invoke(message);
                }
                else if (message.MessageType == NetIncomingMessageType.Receipt)
                {
                    OnReceipt.Invoke(message);
                }
                else if (message.MessageType == NetIncomingMessageType.VerboseDebugMessage)
                {
                    OnVerboseDebugmessage.Invoke(message);
                }
                else if (message.MessageType == NetIncomingMessageType.WarningMessage)
                {
                    OnWarning.Invoke(message);
                }
                else if (message.MessageType == NetIncomingMessageType.Error)
                {
                    OnError.Invoke(message);
                }
                else if (message.MessageType == NetIncomingMessageType.ErrorMessage)
                {
                    OnErrormessage.Invoke(message);
                }
                else if (message.MessageType == NetIncomingMessageType.DebugMessage)
                {
                    OnDebugmessage.Invoke(message);
                }
            }
            Statistics.trafficTimer += time.ElapsedGameTime.TotalSeconds;
            if (Statistics.trafficTimer >= 1)
            {
                Statistics.UploadBytesPerSec       = Statistics.uploadBytesPerSecLast;
                Statistics.uploadBytesPerSecLast   = 0;
                Statistics.DownloadBytesPerSec     = Statistics.downloadBytesPerSecLast;
                Statistics.downloadBytesPerSecLast = 0;
                Statistics.trafficTimer           -= 1;
            }
        }