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); } }
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; }
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); } }
public async override void ConnectionDisconnected() { await _eventAggregator.PublishOnCurrentThreadAsync(new ConnectionLostEvent()); LidgrenPeer.Shutdown("Connection lost..."); }