diff --git a/Client/Client.csproj b/Client/Client.csproj index 0715d7ab..d6c8c5e2 100644 --- a/Client/Client.csproj +++ b/Client/Client.csproj @@ -46,7 +46,7 @@ - + diff --git a/Client/Core/Commands/ConnectionHandler.cs b/Client/Core/Commands/ConnectionHandler.cs index df70a805..da6f21ae 100644 --- a/Client/Core/Commands/ConnectionHandler.cs +++ b/Client/Core/Commands/ConnectionHandler.cs @@ -5,6 +5,7 @@ using System.Threading; using xClient.Config; using xClient.Core.Helper; +using xClient.Core.Networking; namespace xClient.Core.Commands { diff --git a/Client/Core/Commands/FileHandler.cs b/Client/Core/Commands/FileHandler.cs index 803660e5..389194b2 100644 --- a/Client/Core/Commands/FileHandler.cs +++ b/Client/Core/Commands/FileHandler.cs @@ -2,6 +2,7 @@ using System.IO; using System.Threading; using xClient.Core.Helper; +using xClient.Core.Networking; namespace xClient.Core.Commands { diff --git a/Client/Core/Commands/MiscHandler.cs b/Client/Core/Commands/MiscHandler.cs index b2e3c285..ce657594 100644 --- a/Client/Core/Commands/MiscHandler.cs +++ b/Client/Core/Commands/MiscHandler.cs @@ -5,6 +5,7 @@ using System.Threading; using System.Windows.Forms; using xClient.Core.Helper; +using xClient.Core.Networking; namespace xClient.Core.Commands { diff --git a/Client/Core/Commands/SurveillanceHandler.cs b/Client/Core/Commands/SurveillanceHandler.cs index 9ebecdc8..b73f8aae 100644 --- a/Client/Core/Commands/SurveillanceHandler.cs +++ b/Client/Core/Commands/SurveillanceHandler.cs @@ -5,6 +5,7 @@ using xClient.Core.Helper; using System.Drawing.Imaging; using System.Threading; +using xClient.Core.Networking; namespace xClient.Core.Commands { diff --git a/Client/Core/Commands/SystemHandler.cs b/Client/Core/Commands/SystemHandler.cs index fd7f51ff..c657b298 100644 --- a/Client/Core/Commands/SystemHandler.cs +++ b/Client/Core/Commands/SystemHandler.cs @@ -8,6 +8,7 @@ using xClient.Core.Information; using xClient.Core.RemoteShell; using xClient.Core.Extensions; +using xClient.Core.Networking; namespace xClient.Core.Commands { diff --git a/Client/Core/Helper/FileSplit.cs b/Client/Core/Helper/FileSplit.cs index 3f31f819..6c8d3435 100644 --- a/Client/Core/Helper/FileSplit.cs +++ b/Client/Core/Helper/FileSplit.cs @@ -6,8 +6,7 @@ namespace xClient.Core.Helper public class FileSplit { private int _maxBlocks; - - private const int MAX_PACKET_SIZE = Client.MAX_PACKET_SIZE - Client.HEADER_SIZE - (1024 * 2); + private const int MAX_BLOCK_SIZE = (1024 * 1024) * 2 - (1024 * 2); public string Path { get; private set; } public string LastError { get; private set; } @@ -24,7 +23,7 @@ public int MaxBlocks if (!fInfo.Exists) throw new FileNotFoundException(); - this._maxBlocks = (int)Math.Ceiling(fInfo.Length / (double)MAX_PACKET_SIZE); + this._maxBlocks = (int)Math.Ceiling(fInfo.Length / (double)MAX_BLOCK_SIZE); } catch (UnauthorizedAccessException) { @@ -52,7 +51,7 @@ public FileSplit(string path) private int GetSize(long length) { - return (length < MAX_PACKET_SIZE) ? (int) length : MAX_PACKET_SIZE; + return (length < MAX_BLOCK_SIZE) ? (int)length : MAX_BLOCK_SIZE; } public bool ReadBlock(int blockNumber, out byte[] readBytes) @@ -72,7 +71,7 @@ public bool ReadBlock(int blockNumber, out byte[] readBytes) } else { - fStream.Seek(blockNumber * MAX_PACKET_SIZE, SeekOrigin.Begin); + fStream.Seek(blockNumber * MAX_BLOCK_SIZE, SeekOrigin.Begin); readBytes = new byte[this.GetSize(fStream.Length - fStream.Position)]; fStream.Read(readBytes, 0, readBytes.Length); } @@ -127,7 +126,7 @@ public bool AppendBlock(byte[] block, int blockNumber) using (FileStream fStream = File.Open(this.Path, FileMode.Append, FileAccess.Write)) { - fStream.Seek(blockNumber*MAX_PACKET_SIZE, SeekOrigin.Begin); + fStream.Seek(blockNumber*MAX_BLOCK_SIZE, SeekOrigin.Begin); fStream.Write(block, 0, block.Length); } diff --git a/Client/Core/Client.cs b/Client/Core/Networking/Client.cs similarity index 92% rename from Client/Core/Client.cs rename to Client/Core/Networking/Client.cs index a18ce4c8..3436ac35 100644 --- a/Client/Core/Client.cs +++ b/Client/Core/Networking/Client.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using System.Net.Sockets; using System.Text; using ProtoBuf; @@ -9,12 +11,10 @@ using xClient.Core.Encryption; using xClient.Core.Extensions; using xClient.Core.Packets; -using xClient.Core.ReverseProxy.Packets; -using System.Collections.Generic; -using System.Linq; using xClient.Core.ReverseProxy; +using xClient.Core.ReverseProxy.Packets; -namespace xClient.Core +namespace xClient.Core.Networking { public class Client { @@ -131,14 +131,24 @@ public enum ReceiveType } /// - /// A list of all the connected proxy clients that this client holds. + /// The maximum size of one package (also the buffer size for receiving data). /// - private List _proxyClients; + public int MAX_PACKET_SIZE { get { return (1024 * 1024) * 2; } } // 2MB /// - /// Lock object for the list of proxy clients. + /// The keep-alive time in ms. /// - private readonly object _proxyClientsLock = new object(); + public uint KEEP_ALIVE_TIME { get { return 25000; } } // 25s + + /// + /// The keep-alive interval in ms. + /// + public uint KEEP_ALIVE_INTERVAL { get { return 25000; } } // 25s + + /// + /// The header size in + /// + public int HEADER_SIZE { get { return 4; } } // 4 Byte /// /// Returns an array containing all of the proxy clients of this client. @@ -154,18 +164,27 @@ public ReverseProxyClient[] ProxyClients } } - public const uint KEEP_ALIVE_TIME = 25000; - public const uint KEEP_ALIVE_INTERVAL = 25000; - - public const int HEADER_SIZE = 4; - public const int MAX_PACKET_SIZE = (1024*1024)*2; //2MB + /// + /// Handle of the Client Socket. + /// private Socket _handle; + + /// + /// A list of all the connected proxy clients that this client holds. + /// + private List _proxyClients; + + /// + /// Lock object for the list of proxy clients. + /// + private readonly object _proxyClientsLock = new object(); + private int _typeIndex; /// /// The buffer for the client's incoming and outgoing packets. /// - private byte[] _buffer = new byte[MAX_PACKET_SIZE]; + private byte[] _buffer; //receive info private int _readOffset; @@ -203,11 +222,12 @@ public void Connect(string host, ushort port) _handle.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true); _handle.NoDelay = true; + _buffer = new byte[MAX_PACKET_SIZE]; _handle.Connect(host, port); if (_handle.Connected) { - _handle.BeginReceive(this._buffer, 0, this._buffer.Length, SocketFlags.None, AsyncReceive, null); + _handle.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, AsyncReceive, null); OnClientState(true); } } @@ -273,7 +293,7 @@ private void AsyncReceive(IAsyncResult result) byte[] payload = new byte[_payloadLen]; try { - Array.Copy(this._buffer, _readOffset, payload, 0, payload.Length); + Array.Copy(_buffer, _readOffset, payload, 0, payload.Length); } catch { @@ -306,10 +326,10 @@ private void AsyncReceive(IAsyncResult result) } int len = _receiveState == ReceiveType.Header ? HEADER_SIZE : _payloadLen; - if (_readOffset + len >= this._buffer.Length) + if (_readOffset + len >= _buffer.Length) { //copy the buffer to the beginning - Array.Copy(this._buffer, _readOffset, this._buffer, 0, _readableDataLen); + Array.Copy(_buffer, _readOffset, _buffer, 0, _readableDataLen); _writeOffset = _readableDataLen; _readOffset = 0; } @@ -325,7 +345,7 @@ private void AsyncReceive(IAsyncResult result) { if (_buffer.Length - _writeOffset > 0) { - _handle.BeginReceive(this._buffer, _writeOffset, _buffer.Length - _writeOffset, SocketFlags.None, + _handle.BeginReceive(_buffer, _writeOffset, _buffer.Length - _writeOffset, SocketFlags.None, AsyncReceive, null); } else diff --git a/Client/Core/Packets/ClientPackets/DesktopResponse.cs b/Client/Core/Packets/ClientPackets/DesktopResponse.cs index 9d14ac33..46d5de4e 100644 --- a/Client/Core/Packets/ClientPackets/DesktopResponse.cs +++ b/Client/Core/Packets/ClientPackets/DesktopResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ClientPackets { diff --git a/Client/Core/Packets/ClientPackets/DirectoryResponse.cs b/Client/Core/Packets/ClientPackets/DirectoryResponse.cs index f3c8a7d2..99b99554 100644 --- a/Client/Core/Packets/ClientPackets/DirectoryResponse.cs +++ b/Client/Core/Packets/ClientPackets/DirectoryResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ClientPackets { diff --git a/Client/Core/Packets/ClientPackets/DownloadFileResponse.cs b/Client/Core/Packets/ClientPackets/DownloadFileResponse.cs index 0aa8bf83..693b559b 100644 --- a/Client/Core/Packets/ClientPackets/DownloadFileResponse.cs +++ b/Client/Core/Packets/ClientPackets/DownloadFileResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ClientPackets { diff --git a/Client/Core/Packets/ClientPackets/DrivesResponse.cs b/Client/Core/Packets/ClientPackets/DrivesResponse.cs index b1947a28..de8d2b94 100644 --- a/Client/Core/Packets/ClientPackets/DrivesResponse.cs +++ b/Client/Core/Packets/ClientPackets/DrivesResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ClientPackets { diff --git a/Client/Core/Packets/ClientPackets/GetLogsResponse.cs b/Client/Core/Packets/ClientPackets/GetLogsResponse.cs index ad2e7a1c..11acc83c 100644 --- a/Client/Core/Packets/ClientPackets/GetLogsResponse.cs +++ b/Client/Core/Packets/ClientPackets/GetLogsResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ClientPackets { diff --git a/Client/Core/Packets/ClientPackets/GetProcessesResponse.cs b/Client/Core/Packets/ClientPackets/GetProcessesResponse.cs index d5b58b0c..6c19359f 100644 --- a/Client/Core/Packets/ClientPackets/GetProcessesResponse.cs +++ b/Client/Core/Packets/ClientPackets/GetProcessesResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ClientPackets { diff --git a/Client/Core/Packets/ClientPackets/GetStartupItemsResponse.cs b/Client/Core/Packets/ClientPackets/GetStartupItemsResponse.cs index d5773a61..ff4ffca6 100644 --- a/Client/Core/Packets/ClientPackets/GetStartupItemsResponse.cs +++ b/Client/Core/Packets/ClientPackets/GetStartupItemsResponse.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ClientPackets { diff --git a/Client/Core/Packets/ClientPackets/GetSystemInfoResponse.cs b/Client/Core/Packets/ClientPackets/GetSystemInfoResponse.cs index 6960373a..8e4b89c7 100644 --- a/Client/Core/Packets/ClientPackets/GetSystemInfoResponse.cs +++ b/Client/Core/Packets/ClientPackets/GetSystemInfoResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ClientPackets { diff --git a/Client/Core/Packets/ClientPackets/Initialize.cs b/Client/Core/Packets/ClientPackets/Initialize.cs index 2134d942..4f4f6efe 100644 --- a/Client/Core/Packets/ClientPackets/Initialize.cs +++ b/Client/Core/Packets/ClientPackets/Initialize.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ClientPackets { diff --git a/Client/Core/Packets/ClientPackets/MonitorsResponse.cs b/Client/Core/Packets/ClientPackets/MonitorsResponse.cs index b10e842b..37525f67 100644 --- a/Client/Core/Packets/ClientPackets/MonitorsResponse.cs +++ b/Client/Core/Packets/ClientPackets/MonitorsResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ClientPackets { diff --git a/Client/Core/Packets/ClientPackets/ShellCommandResponse.cs b/Client/Core/Packets/ClientPackets/ShellCommandResponse.cs index 2870c2ad..81b76494 100644 --- a/Client/Core/Packets/ClientPackets/ShellCommandResponse.cs +++ b/Client/Core/Packets/ClientPackets/ShellCommandResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ClientPackets { diff --git a/Client/Core/Packets/ClientPackets/Status.cs b/Client/Core/Packets/ClientPackets/Status.cs index d649f0fa..6148542e 100644 --- a/Client/Core/Packets/ClientPackets/Status.cs +++ b/Client/Core/Packets/ClientPackets/Status.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ClientPackets { diff --git a/Client/Core/Packets/ClientPackets/UserStatus.cs b/Client/Core/Packets/ClientPackets/UserStatus.cs index 5f42a5b5..390c5fcf 100644 --- a/Client/Core/Packets/ClientPackets/UserStatus.cs +++ b/Client/Core/Packets/ClientPackets/UserStatus.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ClientPackets { diff --git a/Client/Core/Packets/IPacket.cs b/Client/Core/Packets/IPacket.cs index 79792a53..157317de 100644 --- a/Client/Core/Packets/IPacket.cs +++ b/Client/Core/Packets/IPacket.cs @@ -1,4 +1,6 @@ -namespace xClient.Core.Packets +using xClient.Core.Networking; + +namespace xClient.Core.Packets { public interface IPacket { diff --git a/Client/Core/Packets/PacketHandler.cs b/Client/Core/Packets/PacketHandler.cs index 997f8536..2fc8c670 100644 --- a/Client/Core/Packets/PacketHandler.cs +++ b/Client/Core/Packets/PacketHandler.cs @@ -1,4 +1,5 @@ using xClient.Core.Commands; +using xClient.Core.Networking; using xClient.Core.ReverseProxy; namespace xClient.Core.Packets diff --git a/Client/Core/Packets/ServerPackets/Action.cs b/Client/Core/Packets/ServerPackets/Action.cs index 3f4d0a8e..ce9fd55b 100644 --- a/Client/Core/Packets/ServerPackets/Action.cs +++ b/Client/Core/Packets/ServerPackets/Action.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/AddStartupItem.cs b/Client/Core/Packets/ServerPackets/AddStartupItem.cs index a7fc038b..f1709bc6 100644 --- a/Client/Core/Packets/ServerPackets/AddStartupItem.cs +++ b/Client/Core/Packets/ServerPackets/AddStartupItem.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/Delete.cs b/Client/Core/Packets/ServerPackets/Delete.cs index d37d2d42..c3533416 100644 --- a/Client/Core/Packets/ServerPackets/Delete.cs +++ b/Client/Core/Packets/ServerPackets/Delete.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/Desktop.cs b/Client/Core/Packets/ServerPackets/Desktop.cs index 8efbba02..02ec4573 100644 --- a/Client/Core/Packets/ServerPackets/Desktop.cs +++ b/Client/Core/Packets/ServerPackets/Desktop.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/Directory.cs b/Client/Core/Packets/ServerPackets/Directory.cs index 2a1662f3..7a22aaa8 100644 --- a/Client/Core/Packets/ServerPackets/Directory.cs +++ b/Client/Core/Packets/ServerPackets/Directory.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/Disconnect.cs b/Client/Core/Packets/ServerPackets/Disconnect.cs index 58ee9285..2d1f2f20 100644 --- a/Client/Core/Packets/ServerPackets/Disconnect.cs +++ b/Client/Core/Packets/ServerPackets/Disconnect.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/DownloadAndExecute.cs b/Client/Core/Packets/ServerPackets/DownloadAndExecute.cs index 94b6834b..68a9a67a 100644 --- a/Client/Core/Packets/ServerPackets/DownloadAndExecute.cs +++ b/Client/Core/Packets/ServerPackets/DownloadAndExecute.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/DownloadFile.cs b/Client/Core/Packets/ServerPackets/DownloadFile.cs index c7eea6c0..ecb73ae7 100644 --- a/Client/Core/Packets/ServerPackets/DownloadFile.cs +++ b/Client/Core/Packets/ServerPackets/DownloadFile.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/DownloadFileCanceled.cs b/Client/Core/Packets/ServerPackets/DownloadFileCanceled.cs index bdf6e499..2d4717ca 100644 --- a/Client/Core/Packets/ServerPackets/DownloadFileCanceled.cs +++ b/Client/Core/Packets/ServerPackets/DownloadFileCanceled.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/Drives.cs b/Client/Core/Packets/ServerPackets/Drives.cs index 9308abc7..35e96e7c 100644 --- a/Client/Core/Packets/ServerPackets/Drives.cs +++ b/Client/Core/Packets/ServerPackets/Drives.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/GetLogs.cs b/Client/Core/Packets/ServerPackets/GetLogs.cs index 427adf8b..a3c91c56 100644 --- a/Client/Core/Packets/ServerPackets/GetLogs.cs +++ b/Client/Core/Packets/ServerPackets/GetLogs.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/GetProcesses.cs b/Client/Core/Packets/ServerPackets/GetProcesses.cs index a1a3fc71..bd652e68 100644 --- a/Client/Core/Packets/ServerPackets/GetProcesses.cs +++ b/Client/Core/Packets/ServerPackets/GetProcesses.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/GetStartupItems.cs b/Client/Core/Packets/ServerPackets/GetStartupItems.cs index 34455a82..d32f1757 100644 --- a/Client/Core/Packets/ServerPackets/GetStartupItems.cs +++ b/Client/Core/Packets/ServerPackets/GetStartupItems.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/GetSystemInfo.cs b/Client/Core/Packets/ServerPackets/GetSystemInfo.cs index 1c7fc2a7..cf158bd6 100644 --- a/Client/Core/Packets/ServerPackets/GetSystemInfo.cs +++ b/Client/Core/Packets/ServerPackets/GetSystemInfo.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/InitializeCommand.cs b/Client/Core/Packets/ServerPackets/InitializeCommand.cs index 25ca3375..b80868fc 100644 --- a/Client/Core/Packets/ServerPackets/InitializeCommand.cs +++ b/Client/Core/Packets/ServerPackets/InitializeCommand.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/KillProcess.cs b/Client/Core/Packets/ServerPackets/KillProcess.cs index de3d66a8..d6bba95e 100644 --- a/Client/Core/Packets/ServerPackets/KillProcess.cs +++ b/Client/Core/Packets/ServerPackets/KillProcess.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/Monitors.cs b/Client/Core/Packets/ServerPackets/Monitors.cs index bc609734..01d736c6 100644 --- a/Client/Core/Packets/ServerPackets/Monitors.cs +++ b/Client/Core/Packets/ServerPackets/Monitors.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/MouseClick.cs b/Client/Core/Packets/ServerPackets/MouseClick.cs index 9fe5a0c3..1d57543e 100644 --- a/Client/Core/Packets/ServerPackets/MouseClick.cs +++ b/Client/Core/Packets/ServerPackets/MouseClick.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/Reconnect.cs b/Client/Core/Packets/ServerPackets/Reconnect.cs index 8f5d39a8..e2de6619 100644 --- a/Client/Core/Packets/ServerPackets/Reconnect.cs +++ b/Client/Core/Packets/ServerPackets/Reconnect.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/RemoveStartupitem.cs b/Client/Core/Packets/ServerPackets/RemoveStartupitem.cs index dd05ef79..93c32a73 100644 --- a/Client/Core/Packets/ServerPackets/RemoveStartupitem.cs +++ b/Client/Core/Packets/ServerPackets/RemoveStartupitem.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/Rename.cs b/Client/Core/Packets/ServerPackets/Rename.cs index 6363607f..8e58bf61 100644 --- a/Client/Core/Packets/ServerPackets/Rename.cs +++ b/Client/Core/Packets/ServerPackets/Rename.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/ShellCommand.cs b/Client/Core/Packets/ServerPackets/ShellCommand.cs index 39780c70..1bb3675c 100644 --- a/Client/Core/Packets/ServerPackets/ShellCommand.cs +++ b/Client/Core/Packets/ServerPackets/ShellCommand.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/ShowMessageBox.cs b/Client/Core/Packets/ServerPackets/ShowMessageBox.cs index 3bfb0bbe..e668c6a2 100644 --- a/Client/Core/Packets/ServerPackets/ShowMessageBox.cs +++ b/Client/Core/Packets/ServerPackets/ShowMessageBox.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/StartProcess.cs b/Client/Core/Packets/ServerPackets/StartProcess.cs index 99a25945..0dec04ef 100644 --- a/Client/Core/Packets/ServerPackets/StartProcess.cs +++ b/Client/Core/Packets/ServerPackets/StartProcess.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/Uninstall.cs b/Client/Core/Packets/ServerPackets/Uninstall.cs index 82cd517b..e01bdd7b 100644 --- a/Client/Core/Packets/ServerPackets/Uninstall.cs +++ b/Client/Core/Packets/ServerPackets/Uninstall.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/Update.cs b/Client/Core/Packets/ServerPackets/Update.cs index 170690b3..566ab127 100644 --- a/Client/Core/Packets/ServerPackets/Update.cs +++ b/Client/Core/Packets/ServerPackets/Update.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/UploadAndExecute.cs b/Client/Core/Packets/ServerPackets/UploadAndExecute.cs index 30fa5d1d..20da6fae 100644 --- a/Client/Core/Packets/ServerPackets/UploadAndExecute.cs +++ b/Client/Core/Packets/ServerPackets/UploadAndExecute.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/ServerPackets/VisitWebsite.cs b/Client/Core/Packets/ServerPackets/VisitWebsite.cs index 227af34e..67de631b 100644 --- a/Client/Core/Packets/ServerPackets/VisitWebsite.cs +++ b/Client/Core/Packets/ServerPackets/VisitWebsite.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets.ServerPackets { diff --git a/Client/Core/Packets/UnknownPacket.cs b/Client/Core/Packets/UnknownPacket.cs index ef0ae22a..edb723ba 100644 --- a/Client/Core/Packets/UnknownPacket.cs +++ b/Client/Core/Packets/UnknownPacket.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; namespace xClient.Core.Packets { diff --git a/Client/Core/ReverseProxy/Packets/ReverseProxyConnect.cs b/Client/Core/ReverseProxy/Packets/ReverseProxyConnect.cs index 1381cf11..d04182da 100644 --- a/Client/Core/ReverseProxy/Packets/ReverseProxyConnect.cs +++ b/Client/Core/ReverseProxy/Packets/ReverseProxyConnect.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; using xClient.Core.Packets; namespace xClient.Core.ReverseProxy.Packets diff --git a/Client/Core/ReverseProxy/Packets/ReverseProxyConnectResponse.cs b/Client/Core/ReverseProxy/Packets/ReverseProxyConnectResponse.cs index e445ff4b..ca80dc83 100644 --- a/Client/Core/ReverseProxy/Packets/ReverseProxyConnectResponse.cs +++ b/Client/Core/ReverseProxy/Packets/ReverseProxyConnectResponse.cs @@ -1,5 +1,6 @@ using ProtoBuf; using System; +using xClient.Core.Networking; using xClient.Core.Packets; namespace xClient.Core.ReverseProxy.Packets diff --git a/Client/Core/ReverseProxy/Packets/ReverseProxyData.cs b/Client/Core/ReverseProxy/Packets/ReverseProxyData.cs index 68bbcea6..51b072d3 100644 --- a/Client/Core/ReverseProxy/Packets/ReverseProxyData.cs +++ b/Client/Core/ReverseProxy/Packets/ReverseProxyData.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; using xClient.Core.Packets; namespace xClient.Core.ReverseProxy.Packets diff --git a/Client/Core/ReverseProxy/Packets/ReverseProxyDisconnect.cs b/Client/Core/ReverseProxy/Packets/ReverseProxyDisconnect.cs index 9b99b9a1..178d8595 100644 --- a/Client/Core/ReverseProxy/Packets/ReverseProxyDisconnect.cs +++ b/Client/Core/ReverseProxy/Packets/ReverseProxyDisconnect.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xClient.Core.Networking; using xClient.Core.Packets; namespace xClient.Core.ReverseProxy.Packets diff --git a/Client/Core/ReverseProxy/ReverseProxyClient.cs b/Client/Core/ReverseProxy/ReverseProxyClient.cs index b1fbce14..692381f9 100644 --- a/Client/Core/ReverseProxy/ReverseProxyClient.cs +++ b/Client/Core/ReverseProxy/ReverseProxyClient.cs @@ -1,6 +1,7 @@ using System; using System.Net; using System.Net.Sockets; +using xClient.Core.Networking; using xClient.Core.ReverseProxy.Packets; namespace xClient.Core.ReverseProxy diff --git a/Client/Core/ReverseProxy/ReverseProxyCommandHandler.cs b/Client/Core/ReverseProxy/ReverseProxyCommandHandler.cs index 0c5a9488..c1c40927 100644 --- a/Client/Core/ReverseProxy/ReverseProxyCommandHandler.cs +++ b/Client/Core/ReverseProxy/ReverseProxyCommandHandler.cs @@ -1,4 +1,5 @@ -using xClient.Core.Packets; +using xClient.Core.Networking; +using xClient.Core.Packets; using xClient.Core.ReverseProxy.Packets; namespace xClient.Core.ReverseProxy diff --git a/Client/Core/SystemCore.cs b/Client/Core/SystemCore.cs index f6b6d818..5585445e 100644 --- a/Client/Core/SystemCore.cs +++ b/Client/Core/SystemCore.cs @@ -13,6 +13,7 @@ using xClient.Core.Information; using xClient.Core.Encryption; using xClient.Core.Extensions; +using xClient.Core.Networking; namespace xClient.Core { diff --git a/Client/Program.cs b/Client/Program.cs index 2a930f0d..e2a15790 100644 --- a/Client/Program.cs +++ b/Client/Program.cs @@ -7,6 +7,7 @@ using xClient.Core; using xClient.Core.Commands; using xClient.Core.Keylogger; +using xClient.Core.Networking; using xClient.Core.Packets; namespace xClient diff --git a/Server/Core/Commands/ConnectionHandler.cs b/Server/Core/Commands/ConnectionHandler.cs index ad36541d..90778726 100644 --- a/Server/Core/Commands/ConnectionHandler.cs +++ b/Server/Core/Commands/ConnectionHandler.cs @@ -1,7 +1,7 @@ using System; using System.IO; -using System.Linq; using System.Windows.Forms; +using xServer.Core.Networking; using xServer.Core.Packets.ClientPackets; using xServer.Forms; using xServer.Settings; diff --git a/Server/Core/Commands/MiscHandler.cs b/Server/Core/Commands/MiscHandler.cs index 963f177d..0f5d157d 100644 --- a/Server/Core/Commands/MiscHandler.cs +++ b/Server/Core/Commands/MiscHandler.cs @@ -2,6 +2,7 @@ using System.IO; using System.Windows.Forms; using xServer.Core.Helper; +using xServer.Core.Networking; using xServer.Core.Packets.ClientPackets; namespace xServer.Core.Commands diff --git a/Server/Core/Commands/SurveillanceHandler.cs b/Server/Core/Commands/SurveillanceHandler.cs index 0b3a2817..94a78552 100644 --- a/Server/Core/Commands/SurveillanceHandler.cs +++ b/Server/Core/Commands/SurveillanceHandler.cs @@ -3,6 +3,7 @@ using System.Threading; using System.Windows.Forms; using xServer.Core.Helper; +using xServer.Core.Networking; using xServer.Core.Packets.ClientPackets; namespace xServer.Core.Commands diff --git a/Server/Core/Commands/SystemHandler.cs b/Server/Core/Commands/SystemHandler.cs index 680cd7dc..1080c503 100644 --- a/Server/Core/Commands/SystemHandler.cs +++ b/Server/Core/Commands/SystemHandler.cs @@ -3,6 +3,7 @@ using System.Text; using System.Threading; using System.Windows.Forms; +using xServer.Core.Networking; using xServer.Core.Packets.ClientPackets; using xServer.Forms; using xServer.Settings; diff --git a/Server/Core/Helper/FileSplit.cs b/Server/Core/Helper/FileSplit.cs index b070a20e..320cbca2 100644 --- a/Server/Core/Helper/FileSplit.cs +++ b/Server/Core/Helper/FileSplit.cs @@ -7,7 +7,7 @@ public class FileSplit { private int _maxBlocks; - private const int MAX_PACKET_SIZE = Client.MAX_PACKET_SIZE - Client.HEADER_SIZE - (1024 * 2); + private const int MAX_BLOCK_SIZE = (1024 * 1024) * 2 - (1024 * 2); public string Path { get; private set; } public string LastError { get; private set; } @@ -24,7 +24,7 @@ public int MaxBlocks if (!fInfo.Exists) throw new FileNotFoundException(); - this._maxBlocks = (int)Math.Ceiling(fInfo.Length / (double)MAX_PACKET_SIZE); + this._maxBlocks = (int)Math.Ceiling(fInfo.Length / (double)MAX_BLOCK_SIZE); } catch (UnauthorizedAccessException) { @@ -52,7 +52,7 @@ public FileSplit(string path) private int GetSize(long length) { - return (length < MAX_PACKET_SIZE) ? (int) length : MAX_PACKET_SIZE; + return (length < MAX_BLOCK_SIZE) ? (int) length : MAX_BLOCK_SIZE; } public bool ReadBlock(int blockNumber, out byte[] readBytes) @@ -72,7 +72,7 @@ public bool ReadBlock(int blockNumber, out byte[] readBytes) } else { - fStream.Seek(blockNumber*MAX_PACKET_SIZE, SeekOrigin.Begin); + fStream.Seek(blockNumber*MAX_BLOCK_SIZE, SeekOrigin.Begin); readBytes = new byte[this.GetSize(fStream.Length - fStream.Position)]; fStream.Read(readBytes, 0, readBytes.Length); } @@ -127,7 +127,7 @@ public bool AppendBlock(byte[] block, int blockNumber) using (FileStream fStream = File.Open(this.Path, FileMode.Append, FileAccess.Write)) { - fStream.Seek(blockNumber*MAX_PACKET_SIZE, SeekOrigin.Begin); + fStream.Seek(blockNumber*MAX_BLOCK_SIZE, SeekOrigin.Begin); fStream.Write(block, 0, block.Length); } diff --git a/Server/Core/Client.cs b/Server/Core/Networking/Client.cs similarity index 78% rename from Server/Core/Client.cs rename to Server/Core/Networking/Client.cs index cab5d64b..fb9975e9 100644 --- a/Server/Core/Client.cs +++ b/Server/Core/Networking/Client.cs @@ -12,7 +12,7 @@ using xServer.Core.Packets; using xServer.Settings; -namespace xServer.Core +namespace xServer.Core.Networking { public class Client { @@ -42,6 +42,8 @@ private void OnClientState(bool connected) ClientState(this, connected); } + _parentServer.BufferManager.IncreaseBufferCount(1); + if (!connected && !_parentServer.Processing) _parentServer.RemoveClient(this); } @@ -118,19 +120,10 @@ public enum ReceiveType Payload } - public const uint KEEP_ALIVE_TIME = 25000; - public const uint KEEP_ALIVE_INTERVAL = 25000; - public const int HEADER_SIZE = 4; - public const int MAX_PACKET_SIZE = (1024*1024)*2; //2MB private Socket _handle; private int _typeIndex; - /// - /// The buffer for the client's incoming and outgoing packets. - /// - private byte[] _buffer = new byte[MAX_PACKET_SIZE]; - //receive info private int _readOffset; private int _writeOffset; @@ -144,6 +137,11 @@ public enum ReceiveType public IPEndPoint EndPoint { get; private set; } private Server _parentServer; + /// + /// The buffer for the client's incoming and outgoing packets. + /// + private byte[] _buffer; + private const bool encryptionEnabled = true; private const bool compressionEnabled = true; @@ -160,11 +158,13 @@ internal Client(Server server, Socket sock, Type[] packets) Initialize(); _handle = sock; - _handle.SetKeepAliveEx(KEEP_ALIVE_INTERVAL, KEEP_ALIVE_TIME); + _handle.SetKeepAliveEx(_parentServer.KEEP_ALIVE_INTERVAL, _parentServer.KEEP_ALIVE_TIME); _handle.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true); _handle.NoDelay = true; - _handle.BeginReceive(this._buffer, 0, this._buffer.Length, SocketFlags.None, AsyncReceive, null); + _buffer = _parentServer.BufferManager.GetBuffer(); + + _handle.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, AsyncReceive, null); EndPoint = (IPEndPoint) _handle.RemoteEndPoint; OnClientState(true); } @@ -208,64 +208,64 @@ private void AsyncReceive(IAsyncResult result) switch (_receiveState) { case ReceiveType.Header: - { - process = _readableDataLen >= HEADER_SIZE; - if (process) { - _payloadLen = BitConverter.ToInt32(_buffer, _readOffset); + process = _readableDataLen >= _parentServer.HEADER_SIZE; + if (process) + { + _payloadLen = BitConverter.ToInt32(_buffer, _readOffset); - _readableDataLen -= HEADER_SIZE; - _readOffset += HEADER_SIZE; - _receiveState = ReceiveType.Payload; + _readableDataLen -= _parentServer.HEADER_SIZE; + _readOffset += _parentServer.HEADER_SIZE; + _receiveState = ReceiveType.Payload; + } + break; } - break; - } case ReceiveType.Payload: - { - process = _readableDataLen >= _payloadLen; - if (process) { - byte[] payload = new byte[_payloadLen]; - try + process = _readableDataLen >= _payloadLen; + if (process) { - Array.Copy(this._buffer, _readOffset, payload, 0, payload.Length); - } - catch - { - Disconnect(); - } - - if (encryptionEnabled) - payload = AES.Decrypt(payload, Encoding.UTF8.GetBytes(XMLSettings.Password)); - - if (payload.Length > 0) - { - if (compressionEnabled) - payload = new SafeQuickLZ().Decompress(payload, 0, payload.Length); - - using (MemoryStream deserialized = new MemoryStream(payload)) + byte[] payload = new byte[_payloadLen]; + try { - IPacket packet = Serializer.DeserializeWithLengthPrefix(deserialized, - PrefixStyle.Fixed32); - - OnClientRead(packet); + Array.Copy(_buffer, _readOffset, payload, 0, payload.Length); + } + catch + { + Disconnect(); } - } - _readOffset += _payloadLen; - _readableDataLen -= _payloadLen; - _receiveState = ReceiveType.Header; + if (encryptionEnabled) + payload = AES.Decrypt(payload, Encoding.UTF8.GetBytes(XMLSettings.Password)); + + if (payload.Length > 0) + { + if (compressionEnabled) + payload = new SafeQuickLZ().Decompress(payload, 0, payload.Length); + + using (MemoryStream deserialized = new MemoryStream(payload)) + { + IPacket packet = Serializer.DeserializeWithLengthPrefix(deserialized, + PrefixStyle.Fixed32); + + OnClientRead(packet); + } + } + + _readOffset += _payloadLen; + _readableDataLen -= _payloadLen; + _receiveState = ReceiveType.Header; + } + break; } - break; - } } } - int len = _receiveState == ReceiveType.Header ? HEADER_SIZE : _payloadLen; - if (_readOffset + len >= this._buffer.Length) + int len = _receiveState == ReceiveType.Header ? _parentServer.HEADER_SIZE : _payloadLen; + if (_readOffset + len >= _buffer.Length) { //copy the buffer to the beginning - Array.Copy(this._buffer, _readOffset, this._buffer, 0, _readableDataLen); + Array.Copy(_buffer, _readOffset, _buffer, 0, _readableDataLen); _writeOffset = _readableDataLen; _readOffset = 0; } @@ -281,7 +281,7 @@ private void AsyncReceive(IAsyncResult result) { if (_buffer.Length - _writeOffset > 0) { - _handle.BeginReceive(this._buffer, _writeOffset, _buffer.Length - _writeOffset, SocketFlags.None, + _handle.BeginReceive(_buffer, _writeOffset, _buffer.Length - _writeOffset, SocketFlags.None, AsyncReceive, null); } else @@ -361,12 +361,12 @@ public void Disconnect() if (_handle != null) { _handle.Close(); - _buffer = null; _readOffset = 0; _writeOffset = 0; _readableDataLen = 0; _payloadLen = 0; - GC.Collect(); + if (_parentServer != null && _parentServer.BufferManager != null) + _parentServer.BufferManager.ReturnBuffer(_buffer); } } @@ -397,4 +397,4 @@ public void AddTypesToSerializer(Type parent, params Type[] types) AddTypeToSerializer(parent, type); } } -} \ No newline at end of file +} diff --git a/Server/Core/Networking/PooledBufferManager.cs b/Server/Core/Networking/PooledBufferManager.cs new file mode 100644 index 00000000..7147d83d --- /dev/null +++ b/Server/Core/Networking/PooledBufferManager.cs @@ -0,0 +1,258 @@ +using System; +using System.Collections.Generic; + +namespace xServer.Core.Networking +{ + /// + /// Implements a pool of byte arrays to improve allocation performance when parsing data. + /// + /// This type is safe for multithreaded operations. + public class PooledBufferManager + { + private readonly int _bufferLength; + private int _bufferCount; + private Stack _buffers; + + #region events + /// + /// Informs listeners when a new buffer beyond the initial length has been allocated. + /// + public event EventHandler NewBufferAllocated; + /// + /// Fires the NewBufferAllocated event. + /// + /// The event arguments. + protected virtual void OnNewBufferAllocated(EventArgs e) + { + if (NewBufferAllocated != null) + NewBufferAllocated(this, e); + } + + /// + /// Informs listeners that a buffer has been allocated. + /// + public event EventHandler BufferRequested; + /// + /// Raises the BufferRequested event. + /// + /// The event arguments. + protected virtual void OnBufferRequested(EventArgs e) + { + if (BufferRequested != null) + BufferRequested(this, e); + } + + /// + /// Informs listeners that a buffer has been returned. + /// + public event EventHandler BufferReturned; + /// + /// Raises the BufferReturned event. + /// + /// The event arguments. + protected virtual void OnBufferReturned(EventArgs e) + { + if (BufferReturned != null) + BufferReturned(this, e); + } + #endregion + + #region properties + /// + /// Gets the size of the buffers allocated from this pool. + /// + public int BufferLength + { + get { return _bufferLength; } + } + + /// + /// Gets the maximum number of buffers available at any given time from this pool. + /// + public int MaxBufferCount + { + get { return _bufferCount; } + } + + /// + /// Gets the current number of buffers available for use. + /// + public int BuffersAvailable + { + get { return _buffers.Count; } + } + + /// + /// Gets or sets whether to zero the contents of a buffer when it is returned. + /// + public bool ClearOnReturn { get; set; } + #endregion + + #region constructor + /// + /// Creates a new buffer pool with the specified name, buffer sizes, and buffer count. + /// + /// The size of the preallocated buffers. + /// The number of preallocated buffers that should be available. + /// Thrown if or + /// are zero or negative. + public PooledBufferManager(int baseBufferLength, int baseBufferCount) + { + if (baseBufferLength <= 0) + throw new ArgumentOutOfRangeException("baseBufferLength", baseBufferLength, "Buffer length must be a positive integer value."); + if (baseBufferCount <= 0) + throw new ArgumentOutOfRangeException("baseBufferCount", baseBufferCount, "Buffer count must be a positive integer value."); + + _bufferLength = baseBufferLength; + _bufferCount = baseBufferCount; + + _buffers = new Stack(baseBufferCount); + + for (int i = 0; i < baseBufferCount; i++) + { + _buffers.Push(new byte[baseBufferLength]); + } + } + #endregion + + #region methods + /// + /// Gets a buffer from the available pool if one is available, or else allocates a new one. + /// + /// + /// Buffers retrieved with this method should be returned to the pool by using the + /// ReturnBuffer method. + /// + /// A byte[] from the pool. + public byte[] GetBuffer() + { + if (_buffers.Count > 0) + { + lock (_buffers) + { + if (_buffers.Count > 0) + { + byte[] buffer = _buffers.Pop(); + return buffer; + } + } + } + + return AllocateNewBuffer(); + } + + private byte[] AllocateNewBuffer() + { + byte[] newBuffer = new byte[_bufferLength]; + _bufferCount++; + OnNewBufferAllocated(EventArgs.Empty); + + return newBuffer; + } + + /// + /// Returns the specified buffer to the pool. + /// + /// if the buffer belonged to this pool and was freed; otherwise . + /// + /// If the ClearOnFree property is , then the buffer will be zeroed before + /// being restored to the pool. + /// + /// The buffer to return to the pool. + /// Thrown if is . + public bool ReturnBuffer(byte[] buffer) + { + if (buffer == null) + throw new ArgumentNullException("buffer"); + if (buffer.Length != _bufferLength) + return false; + + if (ClearOnReturn) + { + for (int i = 0; i < _bufferLength; i++) + { + buffer[i] = 0; + } + } + + lock (_buffers) + { + if (!_buffers.Contains(buffer)) + _buffers.Push(buffer); + } + return true; + } + + /// + /// Frees all buffers. + /// + public void FreeAllBuffers() + { + while (_buffers.Count != 0) + { + DecreaseBufferCount(1); + } + } + + /// + /// Increases the number of buffers available in the pool by a given size. + /// + /// The number of buffers to preallocate. + /// Thrown if the system is unable to preallocate the requested number of buffers. + /// Thrown if is less than or equal to 0. + /// + /// This method does not cause the NewBufferAllocated event to be raised. + /// + public void IncreaseBufferCount(int buffersToAdd) + { + if (buffersToAdd <= 0) + throw new ArgumentOutOfRangeException("buffersToAdd", buffersToAdd, "The number of buffers to add must be a nonnegative, nonzero integer."); + + List newBuffers = new List(buffersToAdd); + for (int i = 0; i < buffersToAdd; i++) + { + newBuffers.Add(new byte[_bufferLength]); + } + + lock (_buffers) + { + _bufferCount += buffersToAdd; + for (int i = 0; i < buffersToAdd; i++) + { + _buffers.Push(newBuffers[i]); + } + } + } + + /// + /// Removes up to the specified number of buffers from the pool. + /// + /// The number of buffers to attempt to remove. + /// The number of buffers actually removed. + /// + /// The number of buffers removed may actually be lower than the number requested if the specified number of buffers are not free. + /// For example, if the number of buffers free is 15, and the callee requests the removal of 20 buffers, only 15 will be freed, and so the + /// returned value will be 15. + /// + /// Thrown if is less than or equal to 0. + public int DecreaseBufferCount(int buffersToRemove) + { + if (buffersToRemove <= 0) + throw new ArgumentOutOfRangeException("buffersToRemove", buffersToRemove, "The number of buffers to remove must be a nonnegative, nonzero integer."); + + int numRemoved = 0; + + lock (_buffers) + { + for (int i = 0; i < buffersToRemove && _buffers.Count > 0; i++) + { + _buffers.Pop(); + numRemoved++; + } + } + + return numRemoved; + } + #endregion + } +} \ No newline at end of file diff --git a/Server/Core/Server.cs b/Server/Core/Networking/Server.cs similarity index 92% rename from Server/Core/Server.cs rename to Server/Core/Networking/Server.cs index 00bf3d56..f15fcffa 100644 --- a/Server/Core/Server.cs +++ b/Server/Core/Networking/Server.cs @@ -1,29 +1,13 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Net; using System.Net.Sockets; using xServer.Core.Packets; -namespace xServer.Core +namespace xServer.Core.Networking { public class Server { - /// - /// The port on which the server is listening. - /// - public ushort Port { get; private set; } - - /// - /// The total amount of received bytes. - /// - public long BytesReceived { get; set; } - - /// - /// The total amount of sent bytes. - /// - public long BytesSent { get; set; } - /// /// The amount of currently connected and authenticated clients. /// @@ -137,35 +121,55 @@ private void OnClientWrite(Client c, IPacket packet, long length, byte[] rawData } /// - /// Handle of the Server Socket. + /// The port on which the server is listening. /// - private Socket _handle; + public ushort Port { get; private set; } /// - /// The event to accept new connections asynchronously. + /// The total amount of received bytes. /// - private SocketAsyncEventArgs _item; + public long BytesReceived { get; set; } + + /// + /// The total amount of sent bytes. + /// + public long BytesSent { get; set; } + + /// + /// The maximum size of one package in byte (it is also the buffer size for receiving data). + /// + public int MAX_PACKET_SIZE { get { return (1024 * 1024) * 2; } } // 2MB + + /// + /// The keep-alive time in ms. + /// + public uint KEEP_ALIVE_TIME { get { return 25000; } } // 25s + + /// + /// The keep-alive interval in ms. + /// + public uint KEEP_ALIVE_INTERVAL { get { return 25000; } } // 25s + + /// + /// The header size in byte. + /// + public int HEADER_SIZE { get { return 4; } } // 4B /// /// Gets or sets if the server is currently processing data that should prevent disconnection. /// public bool Processing { get; private set; } + /// + /// The buffer manager to handle the receive buffers for the clients. + /// + public PooledBufferManager BufferManager { get; private set; } + /// /// The listening state of the server. True if listening, else False. /// public bool Listening { get; private set; } - /// - /// List of the clients connected to the server. - /// - private List _clients; - - /// - /// Lock object for the list of clients. - /// - private readonly object _clientsLock = new object(); - /// /// Gets the clients currently connected to the server, or an empty array of /// clients if the server is currently not listening. @@ -186,6 +190,26 @@ public Client[] Clients /// public Dictionary AllTimeConnectedClients { get; set; } + /// + /// Handle of the Server Socket. + /// + private Socket _handle; + + /// + /// The event to accept new connections asynchronously. + /// + private SocketAsyncEventArgs _item; + + /// + /// List of the clients connected to the server. + /// + private List _clients; + + /// + /// Lock object for the list of clients. + /// + private readonly object _clientsLock = new object(); + /// /// List of all supported Packet Types by the server. /// @@ -230,6 +254,8 @@ public void Listen(ushort port) } } + BufferManager = new PooledBufferManager(MAX_PACKET_SIZE, 1) {ClearOnReturn = true}; + _handle = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _handle.Bind(new IPEndPoint(IPAddress.Any, port)); @@ -366,6 +392,7 @@ public void Disconnect() } } + BufferManager.FreeAllBuffers(); Listening = false; OnServerState(false); } diff --git a/Server/Core/UserState.cs b/Server/Core/Networking/UserState.cs similarity index 98% rename from Server/Core/UserState.cs rename to Server/Core/Networking/UserState.cs index 7d1fb952..82b11dc9 100644 --- a/Server/Core/UserState.cs +++ b/Server/Core/Networking/UserState.cs @@ -3,7 +3,7 @@ using xServer.Core.ReverseProxy; using xServer.Forms; -namespace xServer.Core +namespace xServer.Core.Networking { public class UserState { diff --git a/Server/Core/Packets/ClientPackets/DesktopResponse.cs b/Server/Core/Packets/ClientPackets/DesktopResponse.cs index 729611fa..30101a9c 100644 --- a/Server/Core/Packets/ClientPackets/DesktopResponse.cs +++ b/Server/Core/Packets/ClientPackets/DesktopResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ClientPackets { diff --git a/Server/Core/Packets/ClientPackets/DirectoryResponse.cs b/Server/Core/Packets/ClientPackets/DirectoryResponse.cs index fe674cf2..21195f9d 100644 --- a/Server/Core/Packets/ClientPackets/DirectoryResponse.cs +++ b/Server/Core/Packets/ClientPackets/DirectoryResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ClientPackets { diff --git a/Server/Core/Packets/ClientPackets/DownloadFileResponse.cs b/Server/Core/Packets/ClientPackets/DownloadFileResponse.cs index 89ed2d6f..f00c6802 100644 --- a/Server/Core/Packets/ClientPackets/DownloadFileResponse.cs +++ b/Server/Core/Packets/ClientPackets/DownloadFileResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ClientPackets { diff --git a/Server/Core/Packets/ClientPackets/DrivesResponse.cs b/Server/Core/Packets/ClientPackets/DrivesResponse.cs index 44c9d767..dc4e8dc0 100644 --- a/Server/Core/Packets/ClientPackets/DrivesResponse.cs +++ b/Server/Core/Packets/ClientPackets/DrivesResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ClientPackets { diff --git a/Server/Core/Packets/ClientPackets/GetLogsResponse.cs b/Server/Core/Packets/ClientPackets/GetLogsResponse.cs index 277274e4..48ed87d2 100644 --- a/Server/Core/Packets/ClientPackets/GetLogsResponse.cs +++ b/Server/Core/Packets/ClientPackets/GetLogsResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ClientPackets { diff --git a/Server/Core/Packets/ClientPackets/GetProcessesResponse.cs b/Server/Core/Packets/ClientPackets/GetProcessesResponse.cs index 6f6ac901..32c39209 100644 --- a/Server/Core/Packets/ClientPackets/GetProcessesResponse.cs +++ b/Server/Core/Packets/ClientPackets/GetProcessesResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ClientPackets { diff --git a/Server/Core/Packets/ClientPackets/GetStartupItemsResponse.cs b/Server/Core/Packets/ClientPackets/GetStartupItemsResponse.cs index ed13f35b..4adcf323 100644 --- a/Server/Core/Packets/ClientPackets/GetStartupItemsResponse.cs +++ b/Server/Core/Packets/ClientPackets/GetStartupItemsResponse.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ClientPackets { diff --git a/Server/Core/Packets/ClientPackets/GetSystemInfoResponse.cs b/Server/Core/Packets/ClientPackets/GetSystemInfoResponse.cs index 561c59d8..f924a7ea 100644 --- a/Server/Core/Packets/ClientPackets/GetSystemInfoResponse.cs +++ b/Server/Core/Packets/ClientPackets/GetSystemInfoResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ClientPackets { diff --git a/Server/Core/Packets/ClientPackets/Initialize.cs b/Server/Core/Packets/ClientPackets/Initialize.cs index b48b9138..42e23a56 100644 --- a/Server/Core/Packets/ClientPackets/Initialize.cs +++ b/Server/Core/Packets/ClientPackets/Initialize.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ClientPackets { diff --git a/Server/Core/Packets/ClientPackets/MonitorsResponse.cs b/Server/Core/Packets/ClientPackets/MonitorsResponse.cs index 8962ea9c..95bd0e2a 100644 --- a/Server/Core/Packets/ClientPackets/MonitorsResponse.cs +++ b/Server/Core/Packets/ClientPackets/MonitorsResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ClientPackets { diff --git a/Server/Core/Packets/ClientPackets/ShellCommandResponse.cs b/Server/Core/Packets/ClientPackets/ShellCommandResponse.cs index 81d26954..e67bcad7 100644 --- a/Server/Core/Packets/ClientPackets/ShellCommandResponse.cs +++ b/Server/Core/Packets/ClientPackets/ShellCommandResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ClientPackets { diff --git a/Server/Core/Packets/ClientPackets/Status.cs b/Server/Core/Packets/ClientPackets/Status.cs index 9c288d7f..d9a4d6b6 100644 --- a/Server/Core/Packets/ClientPackets/Status.cs +++ b/Server/Core/Packets/ClientPackets/Status.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ClientPackets { diff --git a/Server/Core/Packets/ClientPackets/UserStatus.cs b/Server/Core/Packets/ClientPackets/UserStatus.cs index 81dad0a5..6dd92ec0 100644 --- a/Server/Core/Packets/ClientPackets/UserStatus.cs +++ b/Server/Core/Packets/ClientPackets/UserStatus.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ClientPackets { diff --git a/Server/Core/Packets/IPacket.cs b/Server/Core/Packets/IPacket.cs index 7a729d05..9cb77da2 100644 --- a/Server/Core/Packets/IPacket.cs +++ b/Server/Core/Packets/IPacket.cs @@ -1,4 +1,6 @@ -namespace xServer.Core.Packets +using xServer.Core.Networking; + +namespace xServer.Core.Packets { public interface IPacket { diff --git a/Server/Core/Packets/PacketHandler.cs b/Server/Core/Packets/PacketHandler.cs index 0fc45a44..1dcf1477 100644 --- a/Server/Core/Packets/PacketHandler.cs +++ b/Server/Core/Packets/PacketHandler.cs @@ -1,4 +1,5 @@ using xServer.Core.Commands; +using xServer.Core.Networking; using xServer.Core.ReverseProxy; namespace xServer.Core.Packets diff --git a/Server/Core/Packets/ServerPackets/Action.cs b/Server/Core/Packets/ServerPackets/Action.cs index 66d77c21..628c1b5d 100644 --- a/Server/Core/Packets/ServerPackets/Action.cs +++ b/Server/Core/Packets/ServerPackets/Action.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/AddStartupItem.cs b/Server/Core/Packets/ServerPackets/AddStartupItem.cs index 604416e8..38dc1322 100644 --- a/Server/Core/Packets/ServerPackets/AddStartupItem.cs +++ b/Server/Core/Packets/ServerPackets/AddStartupItem.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/Delete.cs b/Server/Core/Packets/ServerPackets/Delete.cs index c6168068..7f98f160 100644 --- a/Server/Core/Packets/ServerPackets/Delete.cs +++ b/Server/Core/Packets/ServerPackets/Delete.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/Desktop.cs b/Server/Core/Packets/ServerPackets/Desktop.cs index 3500747e..13db98b5 100644 --- a/Server/Core/Packets/ServerPackets/Desktop.cs +++ b/Server/Core/Packets/ServerPackets/Desktop.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/Directory.cs b/Server/Core/Packets/ServerPackets/Directory.cs index 7aa99e85..1ef38bcc 100644 --- a/Server/Core/Packets/ServerPackets/Directory.cs +++ b/Server/Core/Packets/ServerPackets/Directory.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/Disconnect.cs b/Server/Core/Packets/ServerPackets/Disconnect.cs index 64c700ee..979dae38 100644 --- a/Server/Core/Packets/ServerPackets/Disconnect.cs +++ b/Server/Core/Packets/ServerPackets/Disconnect.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/DownloadAndExecute.cs b/Server/Core/Packets/ServerPackets/DownloadAndExecute.cs index a82184a3..e451d685 100644 --- a/Server/Core/Packets/ServerPackets/DownloadAndExecute.cs +++ b/Server/Core/Packets/ServerPackets/DownloadAndExecute.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/DownloadFile.cs b/Server/Core/Packets/ServerPackets/DownloadFile.cs index 11117806..c2ec66f2 100644 --- a/Server/Core/Packets/ServerPackets/DownloadFile.cs +++ b/Server/Core/Packets/ServerPackets/DownloadFile.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/DownloadFileCanceled.cs b/Server/Core/Packets/ServerPackets/DownloadFileCanceled.cs index 934ed5d1..cc7060c7 100644 --- a/Server/Core/Packets/ServerPackets/DownloadFileCanceled.cs +++ b/Server/Core/Packets/ServerPackets/DownloadFileCanceled.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/Drives.cs b/Server/Core/Packets/ServerPackets/Drives.cs index d8d758fe..5d7aaf77 100644 --- a/Server/Core/Packets/ServerPackets/Drives.cs +++ b/Server/Core/Packets/ServerPackets/Drives.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/GetLogs.cs b/Server/Core/Packets/ServerPackets/GetLogs.cs index d527883d..33cb61c1 100644 --- a/Server/Core/Packets/ServerPackets/GetLogs.cs +++ b/Server/Core/Packets/ServerPackets/GetLogs.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/GetProcesses.cs b/Server/Core/Packets/ServerPackets/GetProcesses.cs index 7ec2a816..94e63796 100644 --- a/Server/Core/Packets/ServerPackets/GetProcesses.cs +++ b/Server/Core/Packets/ServerPackets/GetProcesses.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/GetStartupItems.cs b/Server/Core/Packets/ServerPackets/GetStartupItems.cs index 4ec36344..4f3dc4fe 100644 --- a/Server/Core/Packets/ServerPackets/GetStartupItems.cs +++ b/Server/Core/Packets/ServerPackets/GetStartupItems.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/GetSystemInfo.cs b/Server/Core/Packets/ServerPackets/GetSystemInfo.cs index 8165cca6..8c1ac8a7 100644 --- a/Server/Core/Packets/ServerPackets/GetSystemInfo.cs +++ b/Server/Core/Packets/ServerPackets/GetSystemInfo.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/InitializeCommand.cs b/Server/Core/Packets/ServerPackets/InitializeCommand.cs index b5b63138..530ef1f7 100644 --- a/Server/Core/Packets/ServerPackets/InitializeCommand.cs +++ b/Server/Core/Packets/ServerPackets/InitializeCommand.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/KillProcess.cs b/Server/Core/Packets/ServerPackets/KillProcess.cs index ce06c258..d12a9594 100644 --- a/Server/Core/Packets/ServerPackets/KillProcess.cs +++ b/Server/Core/Packets/ServerPackets/KillProcess.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/Monitors.cs b/Server/Core/Packets/ServerPackets/Monitors.cs index 947cb9d6..f33430a2 100644 --- a/Server/Core/Packets/ServerPackets/Monitors.cs +++ b/Server/Core/Packets/ServerPackets/Monitors.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/MouseClick.cs b/Server/Core/Packets/ServerPackets/MouseClick.cs index bf649567..187dcfed 100644 --- a/Server/Core/Packets/ServerPackets/MouseClick.cs +++ b/Server/Core/Packets/ServerPackets/MouseClick.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/Reconnect.cs b/Server/Core/Packets/ServerPackets/Reconnect.cs index 30e4b1a3..cf078aa1 100644 --- a/Server/Core/Packets/ServerPackets/Reconnect.cs +++ b/Server/Core/Packets/ServerPackets/Reconnect.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/RemoveStartupitem.cs b/Server/Core/Packets/ServerPackets/RemoveStartupitem.cs index 7f02edb6..1b538d20 100644 --- a/Server/Core/Packets/ServerPackets/RemoveStartupitem.cs +++ b/Server/Core/Packets/ServerPackets/RemoveStartupitem.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/Rename.cs b/Server/Core/Packets/ServerPackets/Rename.cs index fc0c8f00..833517a6 100644 --- a/Server/Core/Packets/ServerPackets/Rename.cs +++ b/Server/Core/Packets/ServerPackets/Rename.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/ShellCommand.cs b/Server/Core/Packets/ServerPackets/ShellCommand.cs index d5413123..d4ade221 100644 --- a/Server/Core/Packets/ServerPackets/ShellCommand.cs +++ b/Server/Core/Packets/ServerPackets/ShellCommand.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/ShowMessageBox.cs b/Server/Core/Packets/ServerPackets/ShowMessageBox.cs index 4ee2a903..61087c32 100644 --- a/Server/Core/Packets/ServerPackets/ShowMessageBox.cs +++ b/Server/Core/Packets/ServerPackets/ShowMessageBox.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/StartProcess.cs b/Server/Core/Packets/ServerPackets/StartProcess.cs index d49910dc..6ad87a18 100644 --- a/Server/Core/Packets/ServerPackets/StartProcess.cs +++ b/Server/Core/Packets/ServerPackets/StartProcess.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/Uninstall.cs b/Server/Core/Packets/ServerPackets/Uninstall.cs index a62fc6f4..aa09f615 100644 --- a/Server/Core/Packets/ServerPackets/Uninstall.cs +++ b/Server/Core/Packets/ServerPackets/Uninstall.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/Update.cs b/Server/Core/Packets/ServerPackets/Update.cs index 37394f5f..95e09d1e 100644 --- a/Server/Core/Packets/ServerPackets/Update.cs +++ b/Server/Core/Packets/ServerPackets/Update.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/UploadAndExecute.cs b/Server/Core/Packets/ServerPackets/UploadAndExecute.cs index 545a3e6d..bb0481fd 100644 --- a/Server/Core/Packets/ServerPackets/UploadAndExecute.cs +++ b/Server/Core/Packets/ServerPackets/UploadAndExecute.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/ServerPackets/VisitWebsite.cs b/Server/Core/Packets/ServerPackets/VisitWebsite.cs index 9616f4da..07e1c0c2 100644 --- a/Server/Core/Packets/ServerPackets/VisitWebsite.cs +++ b/Server/Core/Packets/ServerPackets/VisitWebsite.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets.ServerPackets { diff --git a/Server/Core/Packets/UnknownPacket.cs b/Server/Core/Packets/UnknownPacket.cs index 0e763449..dcff82bb 100644 --- a/Server/Core/Packets/UnknownPacket.cs +++ b/Server/Core/Packets/UnknownPacket.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; namespace xServer.Core.Packets { diff --git a/Server/Core/ReverseProxy/Packets/ReverseProxyConnect.cs b/Server/Core/ReverseProxy/Packets/ReverseProxyConnect.cs index 6b3203f0..4b7c2d52 100644 --- a/Server/Core/ReverseProxy/Packets/ReverseProxyConnect.cs +++ b/Server/Core/ReverseProxy/Packets/ReverseProxyConnect.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; using xServer.Core.Packets; namespace xServer.Core.ReverseProxy.Packets diff --git a/Server/Core/ReverseProxy/Packets/ReverseProxyConnectResponse.cs b/Server/Core/ReverseProxy/Packets/ReverseProxyConnectResponse.cs index ce961406..ba51af04 100644 --- a/Server/Core/ReverseProxy/Packets/ReverseProxyConnectResponse.cs +++ b/Server/Core/ReverseProxy/Packets/ReverseProxyConnectResponse.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; using xServer.Core.Packets; namespace xServer.Core.ReverseProxy.Packets diff --git a/Server/Core/ReverseProxy/Packets/ReverseProxyData.cs b/Server/Core/ReverseProxy/Packets/ReverseProxyData.cs index b7f10f01..f9b63685 100644 --- a/Server/Core/ReverseProxy/Packets/ReverseProxyData.cs +++ b/Server/Core/ReverseProxy/Packets/ReverseProxyData.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; using xServer.Core.Packets; namespace xServer.Core.ReverseProxy.Packets diff --git a/Server/Core/ReverseProxy/Packets/ReverseProxyDisconnect.cs b/Server/Core/ReverseProxy/Packets/ReverseProxyDisconnect.cs index ce5cc537..a2df811c 100644 --- a/Server/Core/ReverseProxy/Packets/ReverseProxyDisconnect.cs +++ b/Server/Core/ReverseProxy/Packets/ReverseProxyDisconnect.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using xServer.Core.Networking; using xServer.Core.Packets; namespace xServer.Core.ReverseProxy.Packets diff --git a/Server/Core/ReverseProxy/ReverseProxyClient.cs b/Server/Core/ReverseProxy/ReverseProxyClient.cs index 0fec783a..bbd1fdb6 100644 --- a/Server/Core/ReverseProxy/ReverseProxyClient.cs +++ b/Server/Core/ReverseProxy/ReverseProxyClient.cs @@ -3,6 +3,7 @@ using System.Net.Sockets; using System.Text; using System.Windows.Forms; +using xServer.Core.Networking; using xServer.Core.ReverseProxy.Packets; namespace xServer.Core.ReverseProxy diff --git a/Server/Core/ReverseProxy/ReverseProxyCommandHandler.cs b/Server/Core/ReverseProxy/ReverseProxyCommandHandler.cs index 286eec19..6119fc2d 100644 --- a/Server/Core/ReverseProxy/ReverseProxyCommandHandler.cs +++ b/Server/Core/ReverseProxy/ReverseProxyCommandHandler.cs @@ -2,6 +2,7 @@ using System.CodeDom; using System.Collections.Generic; using System.Text; +using xServer.Core.Networking; using xServer.Core.Packets; using xServer.Core.ReverseProxy.Packets; diff --git a/Server/Core/ReverseProxy/ReverseProxyServer.cs b/Server/Core/ReverseProxy/ReverseProxyServer.cs index 20233dfb..30d795b5 100644 --- a/Server/Core/ReverseProxy/ReverseProxyServer.cs +++ b/Server/Core/ReverseProxy/ReverseProxyServer.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Net; using System.Net.Sockets; +using xServer.Core.Networking; namespace xServer.Core.ReverseProxy { diff --git a/Server/Forms/FrmFileManager.cs b/Server/Forms/FrmFileManager.cs index c0e147e0..48cf7d03 100644 --- a/Server/Forms/FrmFileManager.cs +++ b/Server/Forms/FrmFileManager.cs @@ -5,6 +5,7 @@ using System.Windows.Forms; using xServer.Core; using xServer.Core.Misc; +using xServer.Core.Networking; namespace xServer.Forms { diff --git a/Server/Forms/FrmKeylogger.cs b/Server/Forms/FrmKeylogger.cs index ce53dc70..3207862b 100644 --- a/Server/Forms/FrmKeylogger.cs +++ b/Server/Forms/FrmKeylogger.cs @@ -3,6 +3,7 @@ using System.Windows.Forms; using xServer.Core; using xServer.Core.Misc; +using xServer.Core.Networking; namespace xServer.Forms { diff --git a/Server/Forms/FrmMain.cs b/Server/Forms/FrmMain.cs index ab405ee2..5dccfcfd 100644 --- a/Server/Forms/FrmMain.cs +++ b/Server/Forms/FrmMain.cs @@ -9,6 +9,7 @@ using xServer.Core.Extensions; using xServer.Core.Helper; using xServer.Core.Misc; +using xServer.Core.Networking; using xServer.Core.Packets; using xServer.Settings; diff --git a/Server/Forms/FrmRemoteDesktop.cs b/Server/Forms/FrmRemoteDesktop.cs index 4992158d..d5fa9ad2 100644 --- a/Server/Forms/FrmRemoteDesktop.cs +++ b/Server/Forms/FrmRemoteDesktop.cs @@ -4,6 +4,7 @@ using System.Threading; using System.Windows.Forms; using xServer.Core; +using xServer.Core.Networking; namespace xServer.Forms { diff --git a/Server/Forms/FrmRemoteShell.cs b/Server/Forms/FrmRemoteShell.cs index 9b9a6425..59418530 100644 --- a/Server/Forms/FrmRemoteShell.cs +++ b/Server/Forms/FrmRemoteShell.cs @@ -2,6 +2,7 @@ using System.Windows.Forms; using xServer.Core; using System.Drawing; +using xServer.Core.Networking; namespace xServer.Forms { diff --git a/Server/Forms/FrmReverseProxy.cs b/Server/Forms/FrmReverseProxy.cs index 8d35f54c..7c983a2a 100644 --- a/Server/Forms/FrmReverseProxy.cs +++ b/Server/Forms/FrmReverseProxy.cs @@ -3,6 +3,7 @@ using xServer.Core; using xServer.Core.ReverseProxy; using xServer.Core.Helper; +using xServer.Core.Networking; namespace xServer.Forms { diff --git a/Server/Forms/FrmSettings.cs b/Server/Forms/FrmSettings.cs index 39230cca..e129a720 100644 --- a/Server/Forms/FrmSettings.cs +++ b/Server/Forms/FrmSettings.cs @@ -3,6 +3,7 @@ using System.Windows.Forms; using xServer.Core; using xServer.Core.Misc; +using xServer.Core.Networking; using xServer.Settings; namespace xServer.Forms diff --git a/Server/Forms/FrmStartupManager.cs b/Server/Forms/FrmStartupManager.cs index b5819967..b147b8f4 100644 --- a/Server/Forms/FrmStartupManager.cs +++ b/Server/Forms/FrmStartupManager.cs @@ -3,6 +3,7 @@ using System.Windows.Forms; using xServer.Core; using xServer.Core.Misc; +using xServer.Core.Networking; namespace xServer.Forms { diff --git a/Server/Forms/FrmSystemInformation.cs b/Server/Forms/FrmSystemInformation.cs index 1139d262..07eebb1d 100644 --- a/Server/Forms/FrmSystemInformation.cs +++ b/Server/Forms/FrmSystemInformation.cs @@ -3,6 +3,7 @@ using System.Windows.Forms; using xServer.Core; using xServer.Core.Extensions; +using xServer.Core.Networking; namespace xServer.Forms { diff --git a/Server/Forms/FrmTaskManager.cs b/Server/Forms/FrmTaskManager.cs index 88fcb1ef..8d0965b1 100644 --- a/Server/Forms/FrmTaskManager.cs +++ b/Server/Forms/FrmTaskManager.cs @@ -2,6 +2,7 @@ using System.Windows.Forms; using xServer.Core; using xServer.Core.Misc; +using xServer.Core.Networking; namespace xServer.Forms { diff --git a/Server/Server.csproj b/Server/Server.csproj index 28f14179..af8b6969 100644 --- a/Server/Server.csproj +++ b/Server/Server.csproj @@ -66,7 +66,7 @@ Component - + @@ -84,6 +84,7 @@ + @@ -220,9 +221,9 @@ - + - + Form @@ -445,6 +446,7 @@ True +