예제 #1
0
        public virtual void MessageReady(object _)
        {
            NetIncomingMessage msg = LidgrenPeer.ReadMessage();

            if (msg != null)
            {
                switch (msg.MessageType)
                {
                case NetIncomingMessageType.Data:
                    Parse(msg);
                    break;

                case NetIncomingMessageType.StatusChanged:
                    HandleStatusChange(msg);
                    break;

                case NetIncomingMessageType.VerboseDebugMessage:
                case NetIncomingMessageType.DebugMessage:
                case NetIncomingMessageType.WarningMessage:
                case NetIncomingMessageType.ErrorMessage:
                    Console.WriteLine(msg.ReadString());
                    break;

                default:
                    Console.WriteLine("Unhandled type: " + msg.MessageType);
                    break;
                }
                LidgrenPeer.Recycle(msg);
            }
        }
예제 #2
0
        public void Connect(string host)
        {
            var config = new NetPeerConfiguration("fighting-game");

            Start(config);
            if (host.ToLower() == "localhost")
            {
                host = "127.0.0.1";
            }
            LidgrenPeer.Connect(host, PORT);
            Hosting = false;
        }
예제 #3
0
        private void Parse(NetIncomingMessage msg)
        {
            var command = msg.ReadString();

            var convoID = msg.ReadInt64();

            if (command == "response")
            {
                _proxyLookup[msg.SenderConnection].ProcessResponse(msg, convoID);
            }
            else
            {
                var data            = ParseMessage(command, msg);
                var responseMessage = LidgrenPeer.CreateMessage();
                responseMessage.Write("response");
                responseMessage.Write(convoID);
                responseMessage.Write(data.Length);
                responseMessage.Write(data);
                LidgrenPeer.SendMessage(responseMessage, msg.SenderConnection, NetDeliveryMethod.ReliableUnordered);
            }
        }
예제 #4
0
        public async override void ConnectionDisconnected()
        {
            await _eventAggregator.PublishOnCurrentThreadAsync(new ConnectionLostEvent());

            LidgrenPeer.Shutdown("Connection lost...");
        }