예제 #1
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";
            }
        }
예제 #2
0
        public override void receiveMessages()
        {
            NetIncomingMessage msg;

            while ((msg = this.client.ReadMessage()) != null)
            {
                switch (msg.MessageType)
                {
                case NetIncomingMessageType.WarningMessage:
                    Game1.debugOutput = msg.ReadString();
                    continue;

                case NetIncomingMessageType.ErrorMessage:
                    Game1.debugOutput = msg.ReadString();
                    continue;

                case NetIncomingMessageType.Data:
                    LidgrenClient.parseDataMessageFromServer(msg);
                    continue;

                case NetIncomingMessageType.DiscoveryResponse:
                    Console.WriteLine("Found server at " + (object)msg.SenderEndPoint);
                    this.serverName = msg.ReadString();
                    this.receiveHandshake(msg);
                    continue;

                default:
                    continue;
                }
            }
            if (this.client.ServerConnection == null || DateTime.Now.Second % 2 != 0)
            {
                return;
            }
            Game1.debugOutput = "Ping: " + (object)(float)((double)this.client.ServerConnection.AverageRoundtripTime * 1000.0) + "ms";
        }