/*public Network.Packet GetOnePacket() * { * if (Parent.UserObject.IsUtilityUser()) * { * return new Network.Packet(); * } #region Receive Packet from the Client, and return.. * //Console.WriteLine("NetObject.Client Ready"); * Network.Packet InPacket = new Network.Packet(); * if (ClientSocket.Connected && Parent.HostObject.HostSocket.Connected) * { * //Console.WriteLine("NetObject.Client is waiting for data from its Client side socket."); * //Console.WriteLine("NetObject.Client Listening..."); * InPacket = Network.Sockets.GetPacket(ClientSocket); * //Console.WriteLine("NetObject.Client Got Some Data."); * if (InPacket.Type != 0) * { * PreviousPackets.Insert(0, InPacket); * while (PreviousPackets.Count > 5) * { * PreviousPackets.RemoveAt(PreviousPackets.Count - 1); * } * } * else * { * if (!(ClientSocket.Connected || Parent.HostObject.HostSocket.Connected)) * { * Parent.Close(); * } * } * } * return InPacket; #endregion #region The Client Socket has disconnected! * List<Network.Packet> PacketsCache = PreviousPackets; * foreach (Network.Packet ThisPacket in PacketsCache) * { * Logger.Log.Packet(ThisPacket); * } * //Console.WriteLine("Client Socket Closed inside NetObject.Client"); * Parent.Close(); //Let the parent handle the client closing action. #endregion * }*/ #endregion public void Send(Network.Packet InPacket) { if (!_UnSleep()) { return; } if (Parent.UserObject.IsUtilityUser()) { return; } #region Convert the packet to a byte array ready to send to the client socket. byte[] Output = InPacket.Serialise(); #endregion #region Discard dodgy packets. if (InPacket.Size > 8192 || InPacket.Type < 0 || InPacket.Type > 60 || InPacket.Size - 4 != InPacket.Data.Length) { //DODGY PACKET DO *NOT* SEND! return; } #endregion #region Send the byte array to the client socket. try { if (ClientSocket != null) { try { ClientSocket.Send(Output); } catch { } } } #endregion #region Socket closed as we tried to send data? catch (Exception e) { //Socket Closed? List <Network.Packet> PacketsCache = PreviousPackets; foreach (Network.Packet ThisPacket in PacketsCache) { Logger.Log.Packet(ThisPacket); } Logger.Log.Bug(e, "Could Not Send A Packet... Socket Closed?"); } #endregion }
public void Send(Network.Packet InPacket) { //Logger.Console.WriteLine(Parent.Username + " SEND"); if (Parent.UserObject.IsUtilityUser()) { return; } #region Convert the packet to a byte array ready to send to the client socket. byte[] Output = InPacket.Serialise(); #endregion #region Discard dodgy packets. if (InPacket.Size > 8192 || InPacket.Type < 0 || InPacket.Type > 60 || InPacket.Size - 4 != InPacket.Data.Length) { //Logger.Console.WriteLine(Parent.Username + " DODGY PACKET"); //Logger.Console.WriteLine(Parent.Username + " SIZE" + InPacket.Size.ToString()); //Logger.Console.WriteLine(Parent.Username + " TYPE" + InPacket.Type.ToString()); //Logger.Console.WriteLine(Parent.Username + " DATA" + InPacket.Data.CleanASCII()); //DODGY PACKET DO *NOT* SEND! return; } #endregion #region Send the byte array to the client socket. //Logger.Console.WriteLine(Parent.Username + " SEND FINAL"); try { if (HostSocket.Connected) { HostSocket.Send(Output); } } #endregion #region Socket closed as we tried to send data? catch (Exception e) { //Socket Closed? //Logger.Console.WriteLine(Parent.Username + " FAIL"); List <Network.Packet> PacketsCache = PreviousPackets; foreach (Network.Packet ThisPacket in PacketsCache) { Logger.Log.Packet(ThisPacket); } Logger.Log.Bug(e, "Could Not Send A Packet... Socket Closed?"); } //Logger.Console.WriteLine(Parent.Username + " DONE"); #endregion }