public NetIncomingMessage Receive(out IPEndPoint sender) { NetConnection c; NetIncomingMessage msg; while ((msg = client.ReadMessage()) != null) { switch (msg.MessageType) { case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.ErrorMessage: Console.WriteLine(msg.ReadString()); break; case NetIncomingMessageType.Data: //case NetIncomingMessageType.DiscoveryResponse: sender = msg.SenderEndpoint; return(compress?NetCompressor.Decompress(msg):msg); default: Console.WriteLine("Unhandled type: " + msg.MessageType); break; } client.Recycle(msg); } sender = null; return(null); }
public virtual void SendNot(NetOutgoingMessage m, IPEndPoint ep) { if (server.ConnectionsCount == 0 && Root.Instance.Recorder == null) { return; } if (ep == null) { throw new Exception("ep==null"); } if (Root.Instance.Recorder != null) { byte[] buf = m.PeekDataBuffer(); Root.Instance.Recorder.WritePacket((int)(Root.Instance.Time * 1000), buf, buf.Length); } List <NetConnection> list = new List <NetConnection>(); foreach (NetConnection s in Clients) { if (s != null) { if (ep.ToString() != s.RemoteEndpoint.ToString()) { list.Add(s); } } } server.SendMessage(compress?NetCompressor.Compress(m):m, list, NetDeliveryMethod.Unreliable, 0); }
public virtual void Send(NetOutgoingMessage m, IPEndPoint ep) { NetConnection c = FindConnection(ep); if (c != null && c.Status == NetConnectionStatus.Connected) { server.SendMessage(compress?NetCompressor.Compress(m):m, c, NetDeliveryMethod.Unreliable); } }
public virtual void Send(NetOutgoingMessage m) { client.SendMessage(compress?NetCompressor.Compress(m):m, NetDeliveryMethod.Unreliable); }
public NetIncomingMessage Receive(out IPEndPoint sender) { NetIncomingMessage m; while ((m = server.ReadMessage()) != null) { switch (m.MessageType) { case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.ErrorMessage: Console.WriteLine(m.ReadString()); break; case NetIncomingMessageType.Data: sender = m.SenderEndpoint; return(compress?NetCompressor.Decompress(m):m); case NetIncomingMessageType.DiscoveryRequest: { ISerializable info = Root.Instance.CurrentFlow.Query(); if (info != null) { NetOutgoingMessage m2 = server.CreateMessage(); m2.Write(info.ToString()); server.SendDiscoveryResponse(m2, m.SenderEndpoint); } break; } case NetIncomingMessageType.StatusChanged: { NetConnectionStatus newStatus = (NetConnectionStatus)m.ReadByte(); string statusMessage = m.ReadString(); Console.WriteLine(statusMessage); switch (newStatus) { case NetConnectionStatus.Connected: OnConnect(m.SenderConnection); break; case NetConnectionStatus.Disconnected: OnDisconnect(m.SenderConnection); break; } } break; case NetIncomingMessageType.ConnectionApproval: { int root_version = m.ReadInt32(); if (root_version != Root.Instance.Version) { Cheetah.Console.WriteLine("Client rejected: Wrong root version."); m.SenderConnection.Deny("Wrong Root Version. Need " + Root.Instance.Version + ", got " + root_version); break; } int mod_version = m.ReadInt32(); if (mod_version != Root.Instance.Mod.Version) { Cheetah.Console.WriteLine("Client rejected: Wrong mod version."); m.SenderConnection.Deny("Wrong Mod Version. Need " + Root.Instance.Mod.Version + ", got " + mod_version); break; } string password = m.ReadString(); if (password != this.Password && !string.IsNullOrEmpty(Password)) { Cheetah.Console.WriteLine("Client rejected: Wrong password."); m.SenderConnection.Deny("Wrong Password."); break; } m.SenderConnection.Approve(); } break; default: Console.WriteLine("Unhandled type: " + m.MessageType); break; } server.Recycle(m); } sender = null; return(null); }
public virtual void Send(NetOutgoingMessage m) { server.SendMessage(compress?NetCompressor.Compress(m):m, server.Connections, NetDeliveryMethod.Unreliable, 0); }