├── Silkroad.Framework.Common ├── packages.config ├── Network │ ├── SessionState.cs │ ├── PacketSource.cs │ ├── PacketResultAction.cs │ ├── SessionPoolWorkItem.cs │ ├── SessionManager.cs │ ├── Service.cs │ ├── ServiceListener.cs │ ├── PacketManager.cs │ ├── PacketResult.cs │ ├── SessionPool.cs │ └── Session.cs ├── Objects │ ├── IKeyStructure.cs │ ├── SecurityDesc │ │ ├── srSecurityDescriptionGroupAssign.cs │ │ ├── srSecurityDescription.cs │ │ └── srSecurityDescriptionGroup.cs │ ├── Certification │ │ ├── srOperationType.cs │ │ ├── srGlobalService.cs │ │ ├── srGlobalOperation.cs │ │ ├── srServiceType.cs │ │ ├── srUnknown.cs │ │ ├── srNodeType.cs │ │ ├── srNodeLink.cs │ │ ├── srShard.cs │ │ └── srNodeData.cs │ └── CertifiactionManager.cs ├── IPlugin.cs ├── Security │ ├── PacketWriter.cs │ ├── PacketReader.cs │ ├── PacketException.cs │ ├── SecurityException.cs │ ├── TransferBuffer.cs │ ├── ByteArrayExtensions.cs │ └── Blowfish.cs ├── Config │ ├── ServiceCertificator.cs │ ├── ServiceSecurity.cs │ ├── ServiceRedirect.cs │ └── ServiceSettings.cs ├── ServiceType.cs ├── Properties │ └── AssemblyInfo.cs ├── PluginBase.cs └── Silkroad.Framework.Common.csproj ├── Silkroad.Plugin.Gateway ├── packages.config ├── Plugin.cs ├── Properties │ └── AssemblyInfo.cs └── Silkroad.Plugin.Gateway.csproj ├── Silkroad.Plugin.Global ├── packages.config ├── Plugin.cs ├── Properties │ └── AssemblyInfo.cs └── Silkroad.Plugin.Global.csproj ├── Silkroad.Framework.Security ├── packages.config ├── Properties │ └── AssemblyInfo.cs └── Silkroad.Framework.Security.csproj ├── Silkroad.Tools.ModuleFilter ├── packages.config ├── App.config ├── ServiceCollection.cs ├── Properties │ └── AssemblyInfo.cs ├── PluginManager.cs ├── Config │ ├── FilterConfig.cs │ └── Filter.xml ├── Silkroad.Tools.ModuleFilter.csproj └── Program.cs ├── Silkroad.Framework.Utility ├── packages.config ├── Caller.cs ├── Unmanaged.cs ├── Properties │ └── AssemblyInfo.cs ├── StaticLogger.cs ├── NLog.config └── Silkroad.Framework.Utility.csproj ├── Silkroad.Plugin.Certification ├── Plugin.cs ├── Properties │ └── AssemblyInfo.cs └── Silkroad.Plugin.Certification.csproj ├── Silkroad.Plugin.Agent ├── Plugin.cs ├── Properties │ └── AssemblyInfo.cs └── Silkroad.Plugin.Agent.csproj ├── Silkroad.Plugin.Farm ├── Plugin.cs ├── Properties │ └── AssemblyInfo.cs └── Silkroad.Plugin.Farm.csproj ├── Silkroad.Plugin.Game ├── Plugin.cs ├── Properties │ └── AssemblyInfo.cs └── Silkroad.Plugin.Game.csproj ├── Silkroad.Plugin.SMC ├── Plugin.cs ├── Properties │ └── AssemblyInfo.cs └── Silkroad.Plugin.SMC.csproj ├── Silkroad.Plugin.Shard ├── Plugin.cs ├── Properties │ └── AssemblyInfo.cs └── Silkroad.Plugin.Shard.csproj ├── Silkroad.Plugin.Machine ├── Plugin.cs ├── Properties │ └── AssemblyInfo.cs └── Silkroad.Plugin.Machine.csproj ├── Silkroad.Plugin.Download ├── Plugin.cs ├── Properties │ └── AssemblyInfo.cs └── Silkroad.Plugin.Download.csproj ├── .gitattributes ├── README.md ├── .gitignore └── Silkroad.Tools.ModuleFilter.sln /Silkroad.Framework.Common/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Silkroad.Plugin.Gateway/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Silkroad.Plugin.Global/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Silkroad.Framework.Security/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Silkroad.Tools.ModuleFilter/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Network/SessionState.cs: -------------------------------------------------------------------------------- 1 | namespace Silkroad.Framework.Common 2 | { 3 | public class SessionState 4 | { 5 | public int ID { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Objects/IKeyStructure.cs: -------------------------------------------------------------------------------- 1 | namespace Silkroad.Framework.Common.Objects 2 | { 3 | public interface IKeyStruct 4 | { 5 | dynamic Key { get; } 6 | } 7 | } -------------------------------------------------------------------------------- /Silkroad.Tools.ModuleFilter/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Network/PacketSource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Silkroad.Framework.Common 4 | { 5 | [Flags] 6 | public enum PacketSource 7 | { 8 | Certificator, 9 | Module, 10 | } 11 | } -------------------------------------------------------------------------------- /Silkroad.Tools.ModuleFilter/ServiceCollection.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Common; 2 | using System.Collections.Generic; 3 | 4 | namespace Silkroad.Tools.ModuleProxy 5 | { 6 | public class ServiceCollection : List 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Network/PacketResultAction.cs: -------------------------------------------------------------------------------- 1 | namespace Silkroad.Framework.Common 2 | { 3 | public enum PacketResultAction 4 | { 5 | None, 6 | Ignore, 7 | Disconnect, 8 | Replace, 9 | Response, 10 | } 11 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/IPlugin.cs: -------------------------------------------------------------------------------- 1 | namespace Silkroad.Framework.Common 2 | { 3 | public interface IPlugin 4 | { 5 | string Name { get; } 6 | 7 | Service Service { get; } 8 | 9 | void Register(string Name, Service service); 10 | } 11 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Utility/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Silkroad.Plugin.Certification/Plugin.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Common; 2 | 3 | namespace Silkroad.Plugin.Certification 4 | { 5 | public class Plugin : PluginBase 6 | { 7 | public override void Register(string name, Service service) 8 | { 9 | base.Register(name, service); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Silkroad.Plugin.Agent/Plugin.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Common; 2 | 3 | namespace Silkroad.Plugin.Agent 4 | { 5 | public class Plugin : PluginBase 6 | { 7 | public override void Register(string name, Service service) 8 | { 9 | base.Register(name, service); 10 | 11 | //Add plugin related packet handlers here... 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Silkroad.Plugin.Farm/Plugin.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Common; 2 | 3 | namespace Silkroad.Plugin.Farm 4 | { 5 | public class Plugin : PluginBase 6 | { 7 | public override void Register(string name, Service service) 8 | { 9 | base.Register(name, service); 10 | 11 | //Add plugin related packet handlers here... 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Silkroad.Plugin.Game/Plugin.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Common; 2 | 3 | namespace Silkroad.Plugin.Game 4 | { 5 | public class Plugin : PluginBase 6 | { 7 | public override void Register(string name, Service service) 8 | { 9 | base.Register(name, service); 10 | 11 | //Add plugin related packet handlers here... 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Silkroad.Plugin.SMC/Plugin.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Common; 2 | 3 | namespace Silkroad.Plugin.SMC 4 | { 5 | public class Plugin : PluginBase 6 | { 7 | public override void Register(string name, Service service) 8 | { 9 | base.Register(name, service); 10 | 11 | //Add plugin related packet handlers here... 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Silkroad.Plugin.Shard/Plugin.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Common; 2 | 3 | namespace Silkroad.Plugin.Shard 4 | { 5 | public class Plugin : PluginBase 6 | { 7 | public override void Register(string name, Service service) 8 | { 9 | base.Register(name, service); 10 | 11 | //Add plugin related packet handlers here... 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Silkroad.Plugin.Gateway/Plugin.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Common; 2 | 3 | namespace Silkroad.Plugin.Gateway 4 | { 5 | public class Plugin : PluginBase 6 | { 7 | public override void Register(string name, Service service) 8 | { 9 | base.Register(name, service); 10 | 11 | //Add plugin related packet handlers here... 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Silkroad.Plugin.Global/Plugin.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Common; 2 | 3 | namespace Silkroad.Plugin.Global 4 | { 5 | public class Plugin : PluginBase 6 | { 7 | public override void Register(string name, Service service) 8 | { 9 | base.Register(name, service); 10 | 11 | //Add plugin related packet handlers here... 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Silkroad.Plugin.Machine/Plugin.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Common; 2 | 3 | namespace Silkroad.Plugin.Machine 4 | { 5 | public class Plugin : PluginBase 6 | { 7 | public override void Register(string name, Service service) 8 | { 9 | base.Register(name, service); 10 | 11 | //Add plugin related packet handlers here... 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Silkroad.Plugin.Download/Plugin.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Common; 2 | 3 | namespace Silkroad.Plugin.Download 4 | { 5 | public class Plugin : PluginBase 6 | { 7 | public override void Register(string name, Service service) 8 | { 9 | base.Register(name, service); 10 | 11 | //Add plugin related packet handlers here... 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Security/PacketWriter.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace Silkroad.Framework.Common.Security 4 | { 5 | internal class PacketWriter : BinaryWriter 6 | { 7 | public PacketWriter() : base(new MemoryStream()) 8 | { 9 | } 10 | 11 | public byte[] GetBytes() 12 | { 13 | return ((MemoryStream)base.OutStream).ToArray(); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Config/ServiceCertificator.cs: -------------------------------------------------------------------------------- 1 | using System.Xml; 2 | 3 | namespace Silkroad.Framework.Common.Config 4 | { 5 | public class ServiceCertificator 6 | { 7 | public ServiceCertificator(XmlNode node) 8 | { 9 | this.IP = node.Attributes[nameof(this.IP)].Value; 10 | this.Port = ushort.Parse(node.Attributes[nameof(this.Port)].Value); 11 | } 12 | 13 | public string IP { get; private set; } 14 | public ushort Port { get; private set; } 15 | } 16 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Network/SessionPoolWorkItem.cs: -------------------------------------------------------------------------------- 1 | namespace Silkroad.Framework.Common 2 | { 3 | internal struct SessionPoolWorkItem 4 | { 5 | //Session thats needs to run 6 | public Session Session; 7 | 8 | //Index of thread in which session will run 9 | public int ThreadIndex; 10 | 11 | public SessionPoolWorkItem(Session session, int threadIndex) 12 | { 13 | this.Session = session; 14 | this.ThreadIndex = threadIndex; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Objects/SecurityDesc/srSecurityDescriptionGroupAssign.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Utility; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Silkroad.Framework.Common.Objects.SecurityDesc 5 | { 6 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 7 | public struct SecurityDescriptionGroupAssign : Unmanaged.IUnmanagedStruct 8 | { 9 | [MarshalAs(UnmanagedType.U1)] 10 | public byte nGroupID; 11 | 12 | [MarshalAs(UnmanagedType.U4)] 13 | public uint nDescriptionID; 14 | } 15 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Security/PacketReader.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace Silkroad.Framework.Common.Security 4 | { 5 | internal class PacketReader : BinaryReader 6 | { 7 | private byte[] _input; 8 | 9 | public PacketReader(byte[] input) 10 | : base(new MemoryStream(input, false)) 11 | { 12 | _input = input; 13 | } 14 | 15 | public PacketReader(byte[] input, int index, int count) 16 | : base(new MemoryStream(input, index, count, false)) 17 | { 18 | _input = input; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Config/ServiceSecurity.cs: -------------------------------------------------------------------------------- 1 | using System.Xml; 2 | 3 | namespace Silkroad.Framework.Common.Config 4 | { 5 | public class ServiceSecurity 6 | { 7 | public ServiceSecurity(XmlNode node) 8 | { 9 | this.Blowfish = bool.Parse(node.Attributes[nameof(this.Blowfish)].Value); 10 | this.CRC = bool.Parse(node.Attributes[nameof(this.CRC)].Value); 11 | this.Handshake = bool.Parse(node.Attributes[nameof(this.Handshake)].Value); 12 | } 13 | 14 | public bool Blowfish { get; private set; } 15 | public bool CRC { get; private set; } 16 | public bool Handshake { get; private set; } 17 | } 18 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/ServiceType.cs: -------------------------------------------------------------------------------- 1 | namespace Silkroad.Framework.Common 2 | { 3 | public enum ServiceType : byte 4 | { 5 | None = 0, 6 | Certification = 1, 7 | GlobalManager = 2, 8 | DownloadServer = 3, 9 | GatewayServer = 4, 10 | FarmManager = 5, 11 | AgentServer = 6, 12 | SR_ShardManager = 7, 13 | SR_GameServer = 8, 14 | SR_Client = 9, 15 | ServiceManager = 10, 16 | MachineManager = 11, 17 | JmxMsgSvr = 12, 18 | JmxMessenger = 13, 19 | SMC = 14, 20 | CPRJ_Client = 15, 21 | CPRJ_GameServer = 16, 22 | CPRJ_ShardManager = 17, 23 | } 24 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Utility/Caller.cs: -------------------------------------------------------------------------------- 1 | namespace Silkroad.Framework.Utility 2 | { 3 | public static class Caller 4 | { 5 | public static string GetMemberName([System.Runtime.CompilerServices.CallerMemberName] string memberName = null) 6 | { 7 | return memberName; 8 | } 9 | 10 | public static string GetFilePath([System.Runtime.CompilerServices.CallerFilePath] string filePath = null) 11 | { 12 | return filePath; 13 | } 14 | 15 | public static int GetLineNumber([System.Runtime.CompilerServices.CallerLineNumber] int lineNumber = 0) 16 | { 17 | return lineNumber; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Config/ServiceRedirect.cs: -------------------------------------------------------------------------------- 1 | using System.Xml; 2 | 3 | namespace Silkroad.Framework.Common.Config 4 | { 5 | public class ServiceRedirect 6 | { 7 | public ServiceRedirect(XmlNode node) 8 | { 9 | this.CoordID = uint.Parse(node.Attributes[nameof(this.CoordID)].Value); 10 | this.MachineID = uint.Parse(node.Attributes[nameof(this.MachineID)].Value); 11 | this.Port = ushort.Parse(node.Attributes[nameof(this.Port)].Value); 12 | } 13 | 14 | public uint CoordID { get; private set; } 15 | public uint MachineID { get; private set; } 16 | public ushort Port { get; private set; } 17 | } 18 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Objects/SecurityDesc/srSecurityDescription.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Utility; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Silkroad.Framework.Common.Objects.SecurityDesc 5 | { 6 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 7 | public struct SecurityDescription : Unmanaged.IUnmanagedStruct, IKeyStruct 8 | { 9 | [MarshalAs(UnmanagedType.U4)] 10 | public uint nID; 11 | 12 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 13 | public string szName; 14 | 15 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 16 | public string szDesc; 17 | 18 | public dynamic Key { get { return nID; } } 19 | } 20 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Objects/Certification/srOperationType.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Utility; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Silkroad.Framework.Common.Objects.Certification 5 | { 6 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 7 | public struct srOperationType : Unmanaged.IUnmanagedStruct, IKeyStruct 8 | { 9 | [MarshalAs(UnmanagedType.U1)] 10 | public byte ID; 11 | 12 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 13 | public string Name; 14 | 15 | public dynamic Key { get { return ID; } } 16 | 17 | public override string ToString() 18 | { 19 | return $"{ID} - {Name}"; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Objects/SecurityDesc/srSecurityDescriptionGroup.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Utility; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Silkroad.Framework.Common.Objects.SecurityDesc 5 | { 6 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 7 | public struct SecurityDescriptionGroup : Unmanaged.IUnmanagedStruct, IKeyStruct 8 | { 9 | [MarshalAs(UnmanagedType.U1)] 10 | public byte nID; 11 | 12 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 13 | public string szName; 14 | 15 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 16 | public string szDesc; 17 | 18 | public dynamic Key { get { return nID; } } 19 | } 20 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Security/PacketException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace Silkroad.Framework.Common.Security 5 | { 6 | [Serializable] 7 | public class PacketException : Exception 8 | { 9 | public PacketException() 10 | { 11 | } 12 | 13 | public PacketException(string message) : base(message) 14 | { 15 | } 16 | 17 | public PacketException(string message, Exception inner) : base(message, inner) 18 | { 19 | } 20 | 21 | protected PacketException( 22 | SerializationInfo info, 23 | StreamingContext context) 24 | : base(info, context) 25 | { } 26 | } 27 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Objects/Certification/srGlobalService.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Utility; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Silkroad.Framework.Common.Objects.Certification 5 | { 6 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 7 | public struct srGlobalService : Unmanaged.IUnmanagedStruct 8 | { 9 | [MarshalAs(UnmanagedType.U1)] 10 | public byte OperationType; 11 | 12 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 13 | public string Name; 14 | 15 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 16 | public string Query; 17 | 18 | [MarshalAs(UnmanagedType.U2)] 19 | public ushort GlobalManagerNodeID; 20 | } 21 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Objects/Certification/srGlobalOperation.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Utility; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Silkroad.Framework.Common.Objects.Certification 5 | { 6 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 7 | public struct srGlobalOperation : Unmanaged.IUnmanagedStruct, IKeyStruct 8 | { 9 | [MarshalAs(UnmanagedType.U1)] 10 | public byte ID; 11 | 12 | [MarshalAs(UnmanagedType.U1)] 13 | public byte OperationType; 14 | 15 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 16 | public string Name; 17 | 18 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 19 | public string Query; 20 | 21 | public dynamic Key { get { return ID; } } 22 | } 23 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Objects/Certification/srServiceType.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Utility; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Silkroad.Framework.Common.Objects.Certification 5 | { 6 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 7 | public class srServiceType : Unmanaged.IUnmanagedStruct, IKeyStruct 8 | { 9 | [MarshalAs(UnmanagedType.U1)] 10 | public byte ID; 11 | 12 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 13 | public string Name; 14 | 15 | public dynamic Key 16 | { 17 | get 18 | { 19 | return ID; 20 | } 21 | } 22 | 23 | public override string ToString() 24 | { 25 | return $"{ID} - {Name}"; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Objects/Certification/srUnknown.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Utility; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Silkroad.Framework.Common.Objects.Certification 5 | { 6 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 7 | public struct srUnknown : Unmanaged.IUnmanagedStruct 8 | { 9 | [MarshalAs(UnmanagedType.U1)] 10 | public byte GlobalOperationID; 11 | 12 | [MarshalAs(UnmanagedType.U1)] 13 | public byte OperationType; 14 | 15 | [MarshalAs(UnmanagedType.U1)] 16 | public byte u3; 17 | 18 | [MarshalAs(UnmanagedType.U1)] 19 | public byte u4; 20 | 21 | [MarshalAs(UnmanagedType.U1)] 22 | public byte u5; 23 | 24 | [MarshalAs(UnmanagedType.U1)] 25 | public byte u6; 26 | } 27 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Security/SecurityException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace Silkroad.Framework.Common.Security 5 | { 6 | public class SecurityException : Exception, ISerializable 7 | { 8 | public SecurityException() 9 | { 10 | // Add implementation. 11 | } 12 | 13 | public SecurityException(string message) 14 | : base(message) 15 | { 16 | // Add implementation. 17 | } 18 | 19 | public SecurityException(string message, Exception inner) 20 | : base(message, inner) 21 | { 22 | // Add implementation. 23 | } 24 | 25 | // This constructor is needed for serialization. 26 | protected SecurityException(SerializationInfo info, StreamingContext context) 27 | : base(info, context) 28 | { 29 | // Add implementation. 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Objects/Certification/srNodeType.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Utility; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Silkroad.Framework.Common.Objects.Certification 5 | { 6 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 7 | public struct srNodeType : Unmanaged.IUnmanagedStruct, IKeyStruct 8 | { 9 | [MarshalAs(UnmanagedType.U4)] 10 | public uint ID; 11 | 12 | [MarshalAs(UnmanagedType.U1)] 13 | public byte OperationType; 14 | 15 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 16 | public string Name; 17 | 18 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] 19 | public string WIP; 20 | 21 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] 22 | public string NIP; 23 | 24 | [MarshalAs(UnmanagedType.U2)] 25 | public ushort MachineManagerNodeID; 26 | 27 | public dynamic Key { get { return this.ID; } } 28 | } 29 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Utility/Unmanaged.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Silkroad.Framework.Utility 5 | { 6 | public class Unmanaged 7 | { 8 | public interface IUnmanagedStruct 9 | { 10 | } 11 | 12 | public static T BufferToStruct(byte[] buffer, int offset = 0) where T : IUnmanagedStruct 13 | { 14 | unsafe 15 | { 16 | fixed (byte* ptr = &buffer[offset]) 17 | { 18 | return (T)Marshal.PtrToStructure((IntPtr)ptr, typeof(T)); 19 | } 20 | } 21 | } 22 | 23 | public static byte[] StructToBuffer(T structure) where T : IUnmanagedStruct 24 | { 25 | var buffer = new byte[Marshal.SizeOf(typeof(T))]; 26 | unsafe 27 | { 28 | fixed (byte* ptr = &buffer[0]) 29 | { 30 | Marshal.StructureToPtr(structure, (IntPtr)ptr, false); 31 | return buffer; 32 | } 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Objects/Certification/srNodeLink.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Utility; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Silkroad.Framework.Common.Objects.Certification 5 | { 6 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 7 | public struct srNodeLink : Unmanaged.IUnmanagedStruct, IKeyStruct 8 | { 9 | [MarshalAs(UnmanagedType.U4)] 10 | public uint ID; 11 | 12 | [MarshalAs(UnmanagedType.U2)] 13 | public ushort ChildNodeID; 14 | 15 | [MarshalAs(UnmanagedType.U2)] 16 | public ushort ParentNodeID; 17 | 18 | [MarshalAs(UnmanagedType.U4)] 19 | public int PLabel; 20 | 21 | [MarshalAs(UnmanagedType.U1)] 22 | public byte u1; 23 | 24 | [MarshalAs(UnmanagedType.U1)] 25 | public byte u2; 26 | 27 | [MarshalAs(UnmanagedType.U1)] 28 | public byte u3; 29 | 30 | [MarshalAs(UnmanagedType.U1)] 31 | public byte u4; 32 | 33 | [MarshalAs(UnmanagedType.U1)] 34 | public byte u5; 35 | 36 | public dynamic Key { get { return ID; } } 37 | } 38 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ModuleFilter 2 | XFilter based port of VSRO-Module-Sniffer 3 | 4 | ## Configuration 5 | 6 | ### Loggers 7 | > Work in progress 8 | 9 | ### Plugins 10 | `Name` specifies the assembly name of your plugin dll 11 | `ServiceType` represents the services the plugin will be added to. 12 | 13 | ```xml 14 | 15 | ``` 16 | 17 | ### Services 18 | `Security` should not be touched. 19 | `Certificator` represents the end point the service certifying against which the module would normally do. 20 | 21 | It's possible to have none or also multiple redirections. 22 | `CoordID` is the NodeLinkID between module and certificator. 23 | `MachineID` is not yet supported. 24 | `Port` for service to be redirected (self or dedicated-service) 25 | 26 | ```xml 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | ``` 35 | 36 | ### Service Overview 37 | (Click for fullscreen) 38 | ![ModuleFilter](https://rawgit.com/DummkopfOfHachtenduden/ModuleFilter/master/Documentation/ModuleFilter.svg) 39 | -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Network/SessionManager.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Net.Sockets; 3 | using System.Threading; 4 | 5 | namespace Silkroad.Framework.Common 6 | { 7 | public class SessionManager 8 | { 9 | private readonly object _syncLock; 10 | 11 | private Service _service; 12 | 13 | private int _sessionCounter; 14 | private List _sessions; 15 | 16 | public IReadOnlyList Sessions 17 | { 18 | get 19 | { 20 | return _sessions; 21 | } 22 | } 23 | 24 | public SessionManager(Service service) 25 | { 26 | _syncLock = new object(); 27 | _service = service; 28 | 29 | _sessions = new List(); 30 | } 31 | 32 | internal bool Create(Socket client) 33 | { 34 | lock (_syncLock) 35 | { 36 | var id = Interlocked.Increment(ref _sessionCounter); 37 | 38 | var session = new Session(_service, client, id); 39 | 40 | _sessions.Add(session); 41 | 42 | _service.SessionPool.RunInThread(session); 43 | } 44 | return true; 45 | } 46 | 47 | internal void Destroy(Session session) 48 | { 49 | lock (_syncLock) 50 | { 51 | session.Disconnect(true); 52 | _sessions.Remove(session); 53 | } 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /Silkroad.Plugin.SMC/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("Silkroad.Plugin.SMC")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("Silkroad.Plugin.SMC")] 12 | [assembly: AssemblyCopyright("Copyright © 2016")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("5c1434fe-1f3b-40b2-ab5f-fb63afd0c6d6")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Silkroad.Plugin.Agent/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("Silkroad.Plugin.Agent")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("Silkroad.Plugin.Agent")] 12 | [assembly: AssemblyCopyright("Copyright © 2016")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("7d67d19f-ff25-4c15-93b4-2a24939ef4ba")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Silkroad.Plugin.Farm/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("Silkroad.Plugin.Farm")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("Silkroad.Plugin.Farm")] 12 | [assembly: AssemblyCopyright("Copyright © 2016")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("23d72432-60f5-4dc2-8c26-8866b9d7a194")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Silkroad.Plugin.Game/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("Silkroad.Plugin.Game")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("Silkroad.Plugin.Game")] 12 | [assembly: AssemblyCopyright("Copyright © 2016")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("52831e76-6223-4203-92e3-9e96c5ffdf44")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Silkroad.Plugin.Shard/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("Silkroad.Plugin.Shard")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("Silkroad.Plugin.Shard")] 12 | [assembly: AssemblyCopyright("Copyright © 2016")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("888cbf82-6f8c-42e8-8a5e-d14ac795a5a6")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Silkroad.Plugin.Global/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("Silkroad.Plugin.Global")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("Silkroad.Plugin.Global")] 12 | [assembly: AssemblyCopyright("Copyright © 2016")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("933dcc5b-c9a8-4493-9274-1f527a363a30")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Silkroad.Plugin.Download/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("Silkroad.Plugin.Download")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("Silkroad.Plugin.Download")] 12 | [assembly: AssemblyCopyright("Copyright © 2016")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("2f31e286-005b-48db-9d4c-b8a6702ad66d")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Silkroad.Plugin.Certification/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Silkroad.Plugin.Certification")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Silkroad.Plugin.Certification")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("9f535242-cb0a-4040-aa68-209f050cd9ce")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Silkroad.Plugin.Gateway/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // Allgemeine Informationen über eine Assembly werden über die folgenden 5 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, 6 | // die einer Assembly zugeordnet sind. 7 | [assembly: AssemblyTitle("Silkroad.Plugin.Gateway")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("Silkroad.Plugin.Gateway")] 12 | [assembly: AssemblyCopyright("Copyright © 2016")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar 17 | // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von 18 | // COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. 19 | [assembly: ComVisible(false)] 20 | 21 | // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird 22 | [assembly: Guid("6e338c76-6cee-41a0-8eb4-ce32608097b7")] 23 | 24 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: 25 | // 26 | // Hauptversion 27 | // Nebenversion 28 | // Buildnummer 29 | // Revision 30 | // 31 | // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern 32 | // übernehmen, indem Sie "*" eingeben: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Silkroad.Plugin.Machine/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // Allgemeine Informationen über eine Assembly werden über die folgenden 5 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, 6 | // die einer Assembly zugeordnet sind. 7 | [assembly: AssemblyTitle("Silkroad.Plugin.Machine")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("Silkroad.Plugin.Machine")] 12 | [assembly: AssemblyCopyright("Copyright © 2016")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar 17 | // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von 18 | // COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. 19 | [assembly: ComVisible(false)] 20 | 21 | // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird 22 | [assembly: Guid("15d14b64-6b0c-4287-a5ba-5e38fdf04f47")] 23 | 24 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: 25 | // 26 | // Hauptversion 27 | // Nebenversion 28 | // Buildnummer 29 | // Revision 30 | // 31 | // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern 32 | // übernehmen, indem Sie "*" eingeben: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // Allgemeine Informationen über eine Assembly werden über die folgenden 5 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, 6 | // die einer Assembly zugeordnet sind. 7 | [assembly: AssemblyTitle("Silkroad.Framework.Common")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("Silkroad.Framework.Common")] 12 | [assembly: AssemblyCopyright("Copyright © 2016")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar 17 | // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von 18 | // COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. 19 | [assembly: ComVisible(false)] 20 | 21 | // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird 22 | [assembly: Guid("846181e6-0314-4be3-8e6b-45db6e25f957")] 23 | 24 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: 25 | // 26 | // Hauptversion 27 | // Nebenversion 28 | // Buildnummer 29 | // Revision 30 | // 31 | // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern 32 | // übernehmen, indem Sie "*" eingeben: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Silkroad.Framework.Utility/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // Allgemeine Informationen über eine Assembly werden über die folgenden 5 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, 6 | // die einer Assembly zugeordnet sind. 7 | [assembly: AssemblyTitle("Silkroad.Framework.Utility")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("Silkroad.Framework.Utility")] 12 | [assembly: AssemblyCopyright("Copyright © 2016")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar 17 | // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von 18 | // COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. 19 | [assembly: ComVisible(false)] 20 | 21 | // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird 22 | [assembly: Guid("b68f9d08-d251-4a1b-911d-6f19ca38dccd")] 23 | 24 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: 25 | // 26 | // Hauptversion 27 | // Nebenversion 28 | // Buildnummer 29 | // Revision 30 | // 31 | // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern 32 | // übernehmen, indem Sie "*" eingeben: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Network/Service.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Common.Config; 2 | using Silkroad.Framework.Utility; 3 | 4 | namespace Silkroad.Framework.Common 5 | { 6 | public class Service 7 | { 8 | public ServiceSettings Settings { get; private set; } 9 | 10 | public ServiceListener ServiceListener { get; private set; } 11 | public SessionPool SessionPool { get; private set; } 12 | public SessionManager SessionManager { get; private set; } 13 | public PacketManager PacketManager { get; private set; } 14 | 15 | public Service(ServiceSettings settings) 16 | { 17 | this.Settings = settings; 18 | 19 | this.ServiceListener = new ServiceListener(this); 20 | this.SessionPool = new SessionPool(this); 21 | this.SessionManager = new SessionManager(this); 22 | this.PacketManager = new PacketManager(this); 23 | } 24 | 25 | public bool Start() 26 | { 27 | var listenerResult = this.ServiceListener.Start(); 28 | if (listenerResult) 29 | StaticLogger.Instance.Info($"{this.Settings.Name} is listening on {this.Settings.IP}:{this.Settings.Port}"); 30 | 31 | var poolResult = this.SessionPool.Start(); 32 | if (poolResult) 33 | StaticLogger.Instance.Info($"{this.Settings.Name} started with {this.SessionPool.ThreadCount} thread(s)"); 34 | 35 | return listenerResult && poolResult; 36 | } 37 | 38 | public void Stop() 39 | { 40 | this.ServiceListener.Stop(); 41 | this.SessionPool.Stop(); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Objects/Certification/srShard.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Utility; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Silkroad.Framework.Common.Objects.Certification 5 | { 6 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 7 | public struct srShard : Unmanaged.IUnmanagedStruct, IKeyStruct 8 | { 9 | [MarshalAs(UnmanagedType.U2)] 10 | public ushort ID; 11 | 12 | [MarshalAs(UnmanagedType.U1)] 13 | public byte GlobalOperationID; 14 | 15 | [MarshalAs(UnmanagedType.U1)] 16 | public byte OperationType; 17 | 18 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 19 | public string Name; 20 | 21 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 22 | public string Query; 23 | 24 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 25 | public string QueryLog; 26 | 27 | [MarshalAs(UnmanagedType.U2)] 28 | public ushort Capacity; 29 | 30 | [MarshalAs(UnmanagedType.U2)] 31 | public ushort ShardManagerNodeID; 32 | 33 | [MarshalAs(UnmanagedType.U1)] 34 | public byte u1; 35 | 36 | [MarshalAs(UnmanagedType.U1)] 37 | public byte u2; 38 | 39 | [MarshalAs(UnmanagedType.U1)] 40 | public byte u3; 41 | 42 | [MarshalAs(UnmanagedType.U1)] 43 | public byte u4; 44 | 45 | [MarshalAs(UnmanagedType.U1)] 46 | public byte u5; 47 | 48 | [MarshalAs(UnmanagedType.U1)] 49 | public byte u6; 50 | 51 | [MarshalAs(UnmanagedType.U1)] 52 | public byte u7; 53 | 54 | public dynamic Key { get { return ID; } } 55 | } 56 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Security/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // Allgemeine Informationen über eine Assembly werden über die folgenden 6 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, 7 | // die einer Assembly zugeordnet sind. 8 | [assembly: AssemblyTitle("Silkroad.Framework.Security")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Silkroad.Framework.Security")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar 18 | // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von 19 | // COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. 20 | [assembly: ComVisible(false)] 21 | 22 | // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird 23 | [assembly: Guid("e79d2072-08f0-469d-b56f-eaef700c71ab")] 24 | 25 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: 26 | // 27 | // Hauptversion 28 | // Nebenversion 29 | // Buildnummer 30 | // Revision 31 | // 32 | // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern 33 | // übernehmen, indem Sie "*" eingeben: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Silkroad.Tools.ModuleFilter/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // Allgemeine Informationen über eine Assembly werden über die folgenden 5 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, 6 | // die einer Assembly zugeordnet sind. 7 | [assembly: AssemblyTitle("Silkroad.Tools.ModuleFilter")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("Debug")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("Silkroad.Tools.ModuleFilter")] 12 | [assembly: AssemblyCopyright("Copyright © 2016")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar 17 | // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von 18 | // COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. 19 | [assembly: ComVisible(false)] 20 | 21 | // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird 22 | [assembly: Guid("033b4f41-890b-4523-998c-a049c41149fe")] 23 | 24 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: 25 | // 26 | // Hauptversion 27 | // Nebenversion 28 | // Buildnummer 29 | // Revision 30 | // 31 | // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern 32 | // übernehmen, indem Sie "*" eingeben: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | [assembly: AssemblyInformationalVersion("Development")] -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Config/ServiceSettings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Xml; 4 | 5 | namespace Silkroad.Framework.Common.Config 6 | { 7 | public class ServiceSettings 8 | { 9 | public string Name { get; private set; } 10 | public ServiceType Type { get; private set; } 11 | public string IP { get; private set; } 12 | public ushort Port { get; private set; } 13 | 14 | public ServiceSecurity Security { get; private set; } 15 | public ServiceCertificator Certificator { get; private set; } 16 | 17 | private List _redirections; 18 | public IReadOnlyList Redirections { get { return _redirections; } } 19 | 20 | public ServiceSettings(XmlNode node) 21 | { 22 | this.Name = node.Attributes["Name"].Value; 23 | this.Type = (ServiceType)Enum.Parse(typeof(ServiceType), node.Attributes[nameof(this.Type)].Value); 24 | this.IP = node.Attributes[nameof(this.IP)].Value; 25 | this.Port = ushort.Parse(node.Attributes[nameof(this.Port)].Value); 26 | 27 | this.Security = new ServiceSecurity(node["Security"]); 28 | this.Certificator = new ServiceCertificator(node["Certificator"]); 29 | 30 | _redirections = new List(); 31 | var redirectionNode = node["redirections"]; 32 | if (redirectionNode == null) 33 | return; 34 | 35 | foreach (XmlNode redirectNode in redirectionNode) 36 | { 37 | if (redirectNode.NodeType != XmlNodeType.Element) 38 | continue; 39 | 40 | _redirections.Add(new ServiceRedirect(redirectNode)); 41 | } 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Network/ServiceListener.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Utility; 2 | using System; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | 6 | namespace Silkroad.Framework.Common 7 | { 8 | public class ServiceListener 9 | { 10 | private const int MAX_BACKLOG = 10; 11 | 12 | private Service _service; 13 | private Socket _listener; 14 | 15 | public ServiceListener(Service service) 16 | { 17 | _service = service; 18 | } 19 | 20 | public bool Start() 21 | { 22 | _listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 23 | try 24 | { 25 | var localEP = new IPEndPoint(IPAddress.Parse(_service.Settings.IP), _service.Settings.Port); 26 | _listener.Bind(localEP); 27 | _listener.Listen(MAX_BACKLOG); 28 | 29 | _listener.BeginAccept(BeginAcceptCallback, null); 30 | return true; 31 | } 32 | catch (Exception ex) 33 | { 34 | StaticLogger.Instance.Fatal(ex, $"{nameof(ServiceListener)}->{Caller.GetMemberName()}:"); 35 | return false; 36 | } 37 | } 38 | 39 | public void Stop() 40 | { 41 | if (_listener != null) 42 | _listener.Close(); 43 | } 44 | 45 | private void BeginAcceptCallback(IAsyncResult ar) 46 | { 47 | try 48 | { 49 | var client = _listener.EndAccept(ar); 50 | var result = _service.SessionManager.Create(client); 51 | if (!result && client != null) 52 | client.Close(); 53 | 54 | _listener.BeginAccept(BeginAcceptCallback, _listener); 55 | } 56 | catch (Exception ex) 57 | { 58 | StaticLogger.Instance.Fatal(ex, $"{nameof(ServiceListener)}->{Caller.GetMemberName()}:"); 59 | } 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Utility/StaticLogger.cs: -------------------------------------------------------------------------------- 1 | using NLog; 2 | using System.Collections.Generic; 3 | 4 | namespace Silkroad.Framework.Utility 5 | { 6 | public class StaticLogger 7 | { 8 | public static Logger Instance { get; set; } 9 | 10 | private static Dictionary _logger = new Dictionary(); 11 | 12 | public static IReadOnlyDictionary Logger 13 | { 14 | get { return _logger; } 15 | } 16 | 17 | private static void ConfigRule(NLog.Config.LoggingRule rule, int minLevel) 18 | { 19 | //Disable all loglevel rules 20 | for (int i = 0; i < 6; i++) 21 | { 22 | rule.DisableLoggingForLevel(LogLevel.FromOrdinal(i)); 23 | } 24 | 25 | //Enable present loglevel rules up to maxLevel 26 | if (minLevel > 0) 27 | { 28 | for (int i = 0; i <= minLevel; i++) 29 | { 30 | var logLevel = LogLevel.FromOrdinal(6 - i); 31 | if (logLevel != LogLevel.Off) 32 | rule.EnableLoggingForLevel(logLevel); 33 | } 34 | } 35 | } 36 | 37 | public static void SetInstance() 38 | { 39 | Instance = _logger["Instance"]; 40 | } 41 | 42 | public static void Create(string key) 43 | { 44 | _logger.Add(key, LogManager.GetLogger(key)); 45 | } 46 | 47 | public static void SetLogLevel(int minLevel, Logger logger) 48 | { 49 | SetLogLevel(minLevel, logger.Name); 50 | } 51 | 52 | public static void SetLogLevel(int minLevel, string logger) 53 | { 54 | foreach (var rule in LogManager.Configuration.LoggingRules) 55 | { 56 | if (rule.NameMatches(logger)) 57 | { 58 | ConfigRule(rule, 6 - minLevel); 59 | } 60 | } 61 | LogManager.ReconfigExistingLoggers(); 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Network/PacketManager.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Common.Security; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Silkroad.Framework.Common 6 | { 7 | public class PacketManager 8 | { 9 | private Service _container; 10 | 11 | private Dictionary> _moduleHandler; 12 | private Dictionary> _certificatorHandler; 13 | 14 | public PacketManager(Service container) 15 | { 16 | _container = container; 17 | _moduleHandler = new Dictionary>(); 18 | _certificatorHandler = new Dictionary>(); 19 | } 20 | 21 | public void AddModuleHandler(ushort opcode, Func func) 22 | { 23 | _moduleHandler.Add(opcode, func); 24 | } 25 | 26 | public void AddCertificatorHandler(ushort opcode, Func func) 27 | { 28 | _certificatorHandler.Add(opcode, func); 29 | } 30 | 31 | internal PacketResult Handle(PacketSource source, Session session, Packet packet) 32 | { 33 | switch (source) 34 | { 35 | case PacketSource.Certificator: 36 | if (_certificatorHandler.ContainsKey(packet.Opcode)) 37 | return _certificatorHandler[packet.Opcode].Invoke(session, packet); 38 | break; 39 | 40 | case PacketSource.Module: 41 | if (_moduleHandler.ContainsKey(packet.Opcode)) 42 | return _moduleHandler[packet.Opcode].Invoke(session, packet); 43 | break; 44 | } 45 | 46 | //if (StaticLogger.Instance.IsTraceEnabled) 47 | // StaticLogger.Instance.Warn("[{7}][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", packet.Opcode, packet.Length, packet.Encrypted ? "[Encrypted]" : "", packet.Massive ? "[Massive]" : "", Environment.NewLine, packet.GetBytes().HexDump(), Environment.NewLine, source); 48 | return PacketResult.None; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Network/PacketResult.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Common.Security; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | namespace Silkroad.Framework.Common 6 | { 7 | public struct PacketResult : IEnumerable 8 | { 9 | #region Fields (Static) 10 | 11 | public static PacketResult None = new PacketResult(PacketResultAction.None); 12 | public static PacketResult Ignore = new PacketResult(PacketResultAction.Ignore); 13 | public static PacketResult Disconnect = new PacketResult(PacketResultAction.Disconnect); 14 | 15 | #endregion Fields (Static) 16 | 17 | #region Fields 18 | 19 | private PacketResultAction _action; 20 | private List _packets; 21 | 22 | #endregion Fields 23 | 24 | #region Properties 25 | 26 | public PacketResultAction Action 27 | { 28 | get 29 | { 30 | return _action; 31 | } 32 | } 33 | 34 | #endregion Properties 35 | 36 | #region Constructor 37 | 38 | public PacketResult(PacketResultAction action) 39 | { 40 | _action = action; 41 | _packets = new List(); 42 | } 43 | 44 | public PacketResult(PacketResultAction action, IEnumerable packets) 45 | { 46 | _action = action; 47 | _packets = new List(packets); 48 | } 49 | 50 | #endregion Constructor 51 | 52 | #region IEnumerable 53 | 54 | public Packet this[int index] 55 | { 56 | get 57 | { 58 | return _packets[index]; 59 | } 60 | } 61 | 62 | public IEnumerator GetEnumerator() 63 | { 64 | return _packets.GetEnumerator(); 65 | } 66 | 67 | IEnumerator IEnumerable.GetEnumerator() 68 | { 69 | return this.GetEnumerator(); 70 | } 71 | 72 | #endregion IEnumerable 73 | 74 | #region Methods 75 | 76 | public void Add(Packet packet) 77 | { 78 | _packets.Add(packet); 79 | } 80 | 81 | public void Add(IEnumerable packets) 82 | { 83 | _packets.AddRange(packets); 84 | } 85 | 86 | #endregion Methods 87 | } 88 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Objects/Certification/srNodeData.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Utility; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Silkroad.Framework.Common.Objects.Certification 5 | { 6 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 7 | public struct srNodeData : Unmanaged.IUnmanagedStruct, IKeyStruct 8 | { 9 | [MarshalAs(UnmanagedType.U2)] 10 | public ushort NodeID; 11 | 12 | [MarshalAs(UnmanagedType.U1)] 13 | public byte OperationType; 14 | 15 | [MarshalAs(UnmanagedType.U1)] 16 | public byte GlobalOperationID; 17 | 18 | [MarshalAs(UnmanagedType.U2)] 19 | public ushort AssociatedShardID; 20 | 21 | [MarshalAs(UnmanagedType.U4)] 22 | public uint NodeType; 23 | 24 | [MarshalAs(UnmanagedType.U2)] 25 | public ushort ServiceType; 26 | 27 | [MarshalAs(UnmanagedType.U2)] 28 | public ushort CertificationNodeID; 29 | 30 | [MarshalAs(UnmanagedType.U2)] 31 | public ushort Port; 32 | 33 | [MarshalAs(UnmanagedType.U4)] 34 | public uint NodeIcon; 35 | 36 | [MarshalAs(UnmanagedType.U1)] 37 | public byte u1; 38 | 39 | [MarshalAs(UnmanagedType.U1)] 40 | public byte u2; 41 | 42 | [MarshalAs(UnmanagedType.U1)] 43 | public byte u3; 44 | 45 | [MarshalAs(UnmanagedType.U1)] 46 | public byte u4; 47 | 48 | [MarshalAs(UnmanagedType.U1)] 49 | public byte u5; 50 | 51 | [MarshalAs(UnmanagedType.U1)] 52 | public byte u6; 53 | 54 | [MarshalAs(UnmanagedType.U1)] 55 | public byte u7; 56 | 57 | [MarshalAs(UnmanagedType.U1)] 58 | public byte u8; 59 | 60 | [MarshalAs(UnmanagedType.U1)] 61 | public byte u9; 62 | 63 | [MarshalAs(UnmanagedType.U1)] 64 | public byte u10; 65 | 66 | [MarshalAs(UnmanagedType.U1)] 67 | public byte u11; 68 | 69 | [MarshalAs(UnmanagedType.U1)] 70 | public byte u12; 71 | 72 | [MarshalAs(UnmanagedType.U1)] 73 | public byte u13; 74 | 75 | [MarshalAs(UnmanagedType.U1)] 76 | public byte u14; 77 | 78 | [MarshalAs(UnmanagedType.U1)] 79 | public byte u15; 80 | 81 | [MarshalAs(UnmanagedType.U1)] 82 | public byte u16; 83 | 84 | [MarshalAs(UnmanagedType.U1)] 85 | public byte u17; 86 | 87 | [MarshalAs(UnmanagedType.U1)] 88 | public byte u18; 89 | 90 | [MarshalAs(UnmanagedType.U1)] 91 | public byte u19; 92 | 93 | [MarshalAs(UnmanagedType.U1)] 94 | public byte u20; 95 | 96 | public dynamic Key { get { return NodeID; } } 97 | } 98 | } -------------------------------------------------------------------------------- /Silkroad.Tools.ModuleFilter/PluginManager.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Common; 2 | using Silkroad.Framework.Utility; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Reflection; 7 | 8 | namespace Silkroad.Tools.ModuleProxy 9 | { 10 | internal class PluginManager 11 | { 12 | private Dictionary _plugins; 13 | private List _services; 14 | 15 | private AppDomain _domain; 16 | 17 | public PluginManager(Dictionary plugins) 18 | { 19 | _plugins = plugins; 20 | _services = new List(); 21 | _domain = AppDomain.CreateDomain("FilterDomain"); 22 | } 23 | 24 | internal void RegisterService(Service service) 25 | { 26 | _services.Add(service); 27 | } 28 | 29 | internal int Load() 30 | { 31 | var loadedModuleCount = 0; 32 | foreach (var kvp in _plugins) 33 | { 34 | var file = new FileInfo(kvp.Key + ".dll"); 35 | 36 | if (!file.Exists) 37 | { 38 | StaticLogger.Instance.Fatal($"{nameof(PluginManager)}:->{Caller.GetMemberName()}: {file.Name} not found."); 39 | continue; 40 | } 41 | 42 | try 43 | { 44 | var asmName = new AssemblyName 45 | { 46 | CodeBase = file.Name 47 | }; 48 | var asm = _domain.Load(asmName); 49 | var type = asm.GetType(kvp.Key + ".Plugin"); 50 | 51 | StaticLogger.Instance.Info("{0} ({1}) successfully loaded", file.Name, asm.GetCustomAttribute()?.Version ?? "0.0.0.0"); 52 | foreach (var service in _services) 53 | { 54 | if (service.Settings.Type == kvp.Value) 55 | { 56 | var instance = Activator.CreateInstance(type) as IPlugin; 57 | instance.Register(kvp.Key, service); 58 | 59 | StaticLogger.Instance.Info($"{kvp.Key} [{kvp.Value}] registered for {service.Settings.Name}"); 60 | 61 | loadedModuleCount++; 62 | } 63 | } 64 | } 65 | catch (Exception ex) 66 | { 67 | StaticLogger.Instance.Fatal(ex, $"{kvp.Key} [{kvp.Value}] failed to load"); 68 | } 69 | } 70 | return loadedModuleCount; 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /Silkroad.Tools.ModuleFilter/Config/FilterConfig.cs: -------------------------------------------------------------------------------- 1 | using NLog; 2 | using Silkroad.Framework.Common; 3 | using Silkroad.Framework.Common.Config; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Xml; 7 | 8 | namespace Silkroad.Tools.ModuleProxy.Config 9 | { 10 | public class FilterConfig 11 | { 12 | public Dictionary Logger { get; private set; } 13 | public Dictionary Services { get; private set; } 14 | public Dictionary Plugins { get; private set; } 15 | 16 | public FilterConfig(string fileName) 17 | { 18 | this.Logger = new Dictionary(); 19 | this.Services = new Dictionary(); 20 | this.Plugins = new Dictionary(); 21 | 22 | var xml = new XmlDocument(); 23 | try 24 | { 25 | xml.Load(fileName); 26 | var root = xml["filter"]; 27 | foreach (XmlNode node in root) 28 | { 29 | if (node.NodeType != XmlNodeType.Element) 30 | continue; 31 | 32 | var name = node.Name.ToLowerInvariant(); 33 | switch (name) 34 | { 35 | case "logger": 36 | this.ParseLogger(node); 37 | break; 38 | 39 | case "plugin": 40 | this.ParsePlugin(node); 41 | break; 42 | 43 | case "service": 44 | this.ParseService(node); 45 | break; 46 | } 47 | } 48 | } 49 | catch (Exception) 50 | { 51 | throw; 52 | } 53 | } 54 | 55 | private void ParseLogger(XmlNode node) 56 | { 57 | var name = node.Attributes["Name"].Value; 58 | var logLevel = LogLevel.FromString(node.Attributes["LogLevel"].Value); 59 | Logger.Add(name, logLevel); 60 | } 61 | 62 | private void ParseService(XmlNode node) 63 | { 64 | var name = node.Attributes["Name"].Value; 65 | var settings = new ServiceSettings(node); 66 | Services.Add(name, settings); 67 | } 68 | 69 | private void ParsePlugin(XmlNode node) 70 | { 71 | var name = node.Attributes["Name"].Value; 72 | var serviceType = (ServiceType)Enum.Parse(typeof(ServiceType), node.Attributes["ServiceType"].Value); 73 | Plugins.Add(name, serviceType); 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Security/Silkroad.Framework.Security.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {E79D2072-08F0-469D-B56F-EAEF700C71AB} 8 | Library 9 | Properties 10 | Silkroad.Framework.Security 11 | Silkroad.Framework.Security 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\packages\NLog.4.3.5\lib\net45\NLog.dll 35 | True 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 60 | -------------------------------------------------------------------------------- /Silkroad.Framework.Utility/NLog.config: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 12 | 13 | 14 | 18 | 19 | 20 | 21 | 22 | 23 | false 24 | 25 | 26 | 27 | 28 | 29 | 37 | 38 | 39 | 43 | 44 | 45 | 46 | 47 | false 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Silkroad.Framework.Common/PluginBase.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Common.Objects; 2 | using Silkroad.Framework.Common.Security; 3 | using Silkroad.Framework.Utility; 4 | 5 | namespace Silkroad.Framework.Common 6 | { 7 | public class PluginBase : IPlugin 8 | { 9 | #region Fields 10 | 11 | private CertifiactionManager _certificationManager; 12 | 13 | #endregion Fields 14 | 15 | #region Properties 16 | 17 | public string Name { get; private set; } 18 | 19 | public Service Service { get; private set; } 20 | 21 | #endregion Properties 22 | 23 | public PluginBase() 24 | { 25 | _certificationManager = new CertifiactionManager(); 26 | } 27 | 28 | #region Methods 29 | 30 | public virtual void Register(string name, Service service) 31 | { 32 | this.Name = name; 33 | this.Service = service; 34 | 35 | this.Service.PacketManager.AddModuleHandler(0x6003, CertificationReq); 36 | this.Service.PacketManager.AddCertificatorHandler(0xA003, CertificationAck); 37 | 38 | //Add packet handlers used in all plugins here... 39 | } 40 | 41 | private PacketResult CertificationReq(Session arg1, Packet arg2) 42 | { 43 | var result = new PacketResult(PacketResultAction.Replace); 44 | var response = new Packet(arg2.Opcode, arg2.Encrypted, arg2.Massive); 45 | 46 | _certificationManager.ReadReq(arg2); 47 | 48 | //_certificationManager.RequestIP = "192.168.178.10"; 49 | 50 | _certificationManager.WriteReq(response); 51 | 52 | result.Add(response); 53 | return result; 54 | } 55 | 56 | private PacketResult CertificationAck(Session arg1, Packet arg2) 57 | { 58 | var result = new PacketResult(PacketResultAction.Replace); 59 | 60 | _certificationManager.ReadAck(arg2); 61 | 62 | foreach (var redirect in this.Service.Settings.Redirections) 63 | { 64 | if (_certificationManager.NodeLinks.ContainsKey(redirect.CoordID)) 65 | { 66 | var link = _certificationManager.NodeLinks[redirect.CoordID]; 67 | 68 | var parentNode = _certificationManager.NodeData[link.ParentNodeID]; 69 | 70 | //SPOOF 71 | //parentNode.NodeType = redirect.MachineID; 72 | parentNode.Port = redirect.Port; 73 | 74 | _certificationManager.NodeData[link.ParentNodeID] = parentNode; 75 | } 76 | else 77 | { 78 | StaticLogger.Logger[this.Name].Fatal($"Coord({redirect.CoordID}) not found. Redirect impossible, please check Filter.xml!"); 79 | } 80 | } 81 | 82 | var packet = new Packet(arg2.Opcode, arg2.Encrypted, arg2.Massive); 83 | _certificationManager.WriteAck(packet, true, true); 84 | 85 | result.Add(packet); 86 | 87 | return result; 88 | } 89 | 90 | #endregion Methods 91 | } 92 | } -------------------------------------------------------------------------------- /Silkroad.Plugin.SMC/Silkroad.Plugin.SMC.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {5C1434FE-1F3B-40B2-AB5F-FB63AFD0C6D6} 8 | Library 9 | Properties 10 | Silkroad.Plugin.SMC 11 | Silkroad.Plugin.SMC 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | ..\bin\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | {846181e6-0314-4be3-8e6b-45db6e25f957} 49 | Silkroad.Framework.Common 50 | 51 | 52 | {b68f9d08-d251-4a1b-911d-6f19ca38dccd} 53 | Silkroad.Framework.Utility 54 | 55 | 56 | 57 | 64 | -------------------------------------------------------------------------------- /Silkroad.Plugin.Farm/Silkroad.Plugin.Farm.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {23D72432-60F5-4DC2-8C26-8866B9D7A194} 8 | Library 9 | Properties 10 | Silkroad.Plugin.Farm 11 | Silkroad.Plugin.Farm 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | ..\bin\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | {846181e6-0314-4be3-8e6b-45db6e25f957} 49 | Silkroad.Framework.Common 50 | 51 | 52 | {b68f9d08-d251-4a1b-911d-6f19ca38dccd} 53 | Silkroad.Framework.Utility 54 | 55 | 56 | 57 | 64 | -------------------------------------------------------------------------------- /Silkroad.Plugin.Game/Silkroad.Plugin.Game.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {52831E76-6223-4203-92E3-9E96C5FFDF44} 8 | Library 9 | Properties 10 | Silkroad.Plugin.Game 11 | Silkroad.Plugin.Game 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | ..\bin\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | {846181e6-0314-4be3-8e6b-45db6e25f957} 49 | Silkroad.Framework.Common 50 | 51 | 52 | {b68f9d08-d251-4a1b-911d-6f19ca38dccd} 53 | Silkroad.Framework.Utility 54 | 55 | 56 | 57 | 64 | -------------------------------------------------------------------------------- /Silkroad.Plugin.Agent/Silkroad.Plugin.Agent.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {7D67D19F-FF25-4C15-93B4-2A24939EF4BA} 8 | Library 9 | Properties 10 | Silkroad.Plugin.Agent 11 | Silkroad.Plugin.Agent 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | ..\bin\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | {846181e6-0314-4be3-8e6b-45db6e25f957} 49 | Silkroad.Framework.Common 50 | 51 | 52 | {b68f9d08-d251-4a1b-911d-6f19ca38dccd} 53 | Silkroad.Framework.Utility 54 | 55 | 56 | 57 | 64 | -------------------------------------------------------------------------------- /Silkroad.Plugin.Shard/Silkroad.Plugin.Shard.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {888CBF82-6F8C-42E8-8A5E-D14AC795A5A6} 8 | Library 9 | Properties 10 | Silkroad.Plugin.Shard 11 | Silkroad.Plugin.Shard 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | ..\bin\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | {846181e6-0314-4be3-8e6b-45db6e25f957} 49 | Silkroad.Framework.Common 50 | 51 | 52 | {b68f9d08-d251-4a1b-911d-6f19ca38dccd} 53 | Silkroad.Framework.Utility 54 | 55 | 56 | 57 | 64 | -------------------------------------------------------------------------------- /Silkroad.Plugin.Download/Silkroad.Plugin.Download.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {2F31E286-005B-48DB-9D4C-B8A6702AD66D} 8 | Library 9 | Properties 10 | Silkroad.Plugin.Download 11 | Silkroad.Plugin.Download 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | ..\bin\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | {846181e6-0314-4be3-8e6b-45db6e25f957} 49 | Silkroad.Framework.Common 50 | 51 | 52 | {b68f9d08-d251-4a1b-911d-6f19ca38dccd} 53 | Silkroad.Framework.Utility 54 | 55 | 56 | 57 | 64 | -------------------------------------------------------------------------------- /Silkroad.Plugin.Machine/Silkroad.Plugin.Machine.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {15D14B64-6B0C-4287-A5BA-5E38FDF04F47} 8 | Library 9 | Properties 10 | Silkroad.Plugin.Machine 11 | Silkroad.Plugin.Machine 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | ..\bin\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | {846181e6-0314-4be3-8e6b-45db6e25f957} 49 | Silkroad.Framework.Common 50 | 51 | 52 | {b68f9d08-d251-4a1b-911d-6f19ca38dccd} 53 | Silkroad.Framework.Utility 54 | 55 | 56 | 57 | 64 | -------------------------------------------------------------------------------- /Silkroad.Plugin.Certification/Silkroad.Plugin.Certification.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {9F535242-CB0A-4040-AA68-209F050CD9CE} 8 | Library 9 | Properties 10 | Silkroad.Plugin.Certification 11 | Silkroad.Plugin.Certification 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | ..\bin\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | {846181e6-0314-4be3-8e6b-45db6e25f957} 49 | Silkroad.Framework.Common 50 | 51 | 52 | {b68f9d08-d251-4a1b-911d-6f19ca38dccd} 53 | Silkroad.Framework.Utility 54 | 55 | 56 | 57 | 64 | -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Security/TransferBuffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Silkroad.Framework.Common.Security 4 | { 5 | public class TransferBuffer : IDisposable 6 | { 7 | private byte[] m_buffer; 8 | private int m_offset; 9 | private int m_size; 10 | private object m_lock; 11 | 12 | public byte[] Buffer 13 | { 14 | get { return m_buffer; } 15 | set { lock (m_lock) { m_buffer = value; } } 16 | } 17 | 18 | public int Offset 19 | { 20 | get { return m_offset; } 21 | set { lock (m_lock) { m_offset = value; } } 22 | } 23 | 24 | public int Size 25 | { 26 | get { return m_size; } 27 | set { lock (m_lock) { m_size = value; } } 28 | } 29 | 30 | public TransferBuffer(TransferBuffer rhs) 31 | { 32 | lock (rhs.m_lock) 33 | { 34 | m_buffer = new byte[rhs.m_buffer.Length]; 35 | System.Buffer.BlockCopy(rhs.m_buffer, 0, m_buffer, 0, m_buffer.Length); 36 | m_offset = rhs.m_offset; 37 | m_size = rhs.m_size; 38 | m_lock = new object(); 39 | } 40 | } 41 | 42 | public TransferBuffer() 43 | { 44 | m_buffer = null; 45 | m_offset = 0; 46 | m_size = 0; 47 | m_lock = new object(); 48 | } 49 | 50 | public TransferBuffer(int length, int offset, int size) 51 | { 52 | m_buffer = new byte[length]; 53 | m_offset = offset; 54 | m_size = size; 55 | m_lock = new object(); 56 | } 57 | 58 | public TransferBuffer(int length) 59 | { 60 | m_buffer = new byte[length]; 61 | m_offset = 0; 62 | m_size = 0; 63 | m_lock = new object(); 64 | } 65 | 66 | public TransferBuffer(byte[] buffer, int offset, int size, bool assign) 67 | { 68 | if (assign) 69 | { 70 | m_buffer = buffer; 71 | } 72 | else 73 | { 74 | m_buffer = new byte[buffer.Length]; 75 | System.Buffer.BlockCopy(buffer, 0, m_buffer, 0, buffer.Length); 76 | } 77 | m_offset = offset; 78 | m_size = size; 79 | m_lock = new object(); 80 | } 81 | 82 | #region Dispose 83 | 84 | private bool disposed = false; 85 | 86 | //Implement IDisposable. 87 | public void Dispose() 88 | { 89 | Dispose(true); 90 | GC.SuppressFinalize(this); 91 | } 92 | 93 | protected virtual void Dispose(bool disposing) 94 | { 95 | if (!disposed) 96 | { 97 | m_buffer = null; 98 | m_lock = null; 99 | 100 | disposed = true; 101 | } 102 | } 103 | 104 | // Use C# destructor syntax for finalization code. 105 | ~TransferBuffer() 106 | { 107 | // Simply call Dispose(false). 108 | Dispose(false); 109 | } 110 | 111 | #endregion Dispose 112 | } 113 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Utility/Silkroad.Framework.Utility.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {B68F9D08-D251-4A1B-911D-6F19CA38DCCD} 8 | Library 9 | Properties 10 | Silkroad.Framework.Utility 11 | Silkroad.Framework.Utility 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | ..\bin\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | true 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | ..\packages\NLog.4.3.5\lib\net45\NLog.dll 36 | True 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | Always 56 | 57 | 58 | Designer 59 | 60 | 61 | 62 | 63 | 70 | -------------------------------------------------------------------------------- /Silkroad.Plugin.Gateway/Silkroad.Plugin.Gateway.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {6E338C76-6CEE-41A0-8EB4-CE32608097B7} 8 | Library 9 | Properties 10 | Silkroad.Plugin.Gateway 11 | Silkroad.Plugin.Gateway 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | ..\bin\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\packages\NLog.4.3.5\lib\net45\NLog.dll 35 | True 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | {846181e6-0314-4be3-8e6b-45db6e25f957} 53 | Silkroad.Framework.Common 54 | 55 | 56 | {b68f9d08-d251-4a1b-911d-6f19ca38dccd} 57 | Silkroad.Framework.Utility 58 | 59 | 60 | 61 | 62 | 63 | 64 | 71 | -------------------------------------------------------------------------------- /Silkroad.Plugin.Global/Silkroad.Plugin.Global.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {933DCC5B-C9A8-4493-9274-1F527A363A30} 8 | Library 9 | Properties 10 | Silkroad.Plugin.Global 11 | Silkroad.Plugin.Global 12 | v4.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | ..\bin\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | ..\packages\NLog.4.3.5\lib\net45\NLog.dll 36 | True 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | {846181e6-0314-4be3-8e6b-45db6e25f957} 54 | Silkroad.Framework.Common 55 | 56 | 57 | {b68f9d08-d251-4a1b-911d-6f19ca38dccd} 58 | Silkroad.Framework.Utility 59 | 60 | 61 | 62 | 63 | 64 | 65 | 72 | -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Security/ByteArrayExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Silkroad.Framework.Common.Security 6 | { 7 | public static class ByteArrayExtensions 8 | { 9 | public static string HexDump(this byte[] buffer) 10 | { 11 | return HexDump(buffer, 0, buffer.Length); 12 | } 13 | 14 | public static string HexDump(this byte[] buffer, int offset, int count) 15 | { 16 | const int bytesPerLine = 16; 17 | StringBuilder output = new StringBuilder(); 18 | StringBuilder ascii_output = new StringBuilder(); 19 | int length = count; 20 | if (length % bytesPerLine != 0) 21 | { 22 | length += bytesPerLine - length % bytesPerLine; 23 | } 24 | for (int x = 0; x <= length; ++x) 25 | { 26 | if (x % bytesPerLine == 0) 27 | { 28 | if (x > 0) 29 | { 30 | output.AppendFormat(" {0}{1}", ascii_output.ToString(), Environment.NewLine); 31 | ascii_output.Clear(); 32 | } 33 | if (x != length) 34 | { 35 | output.AppendFormat("{0:d10} ", x); 36 | } 37 | } 38 | if (x < count) 39 | { 40 | output.AppendFormat("{0:X2} ", buffer[offset + x]); 41 | char ch = (char)buffer[offset + x]; 42 | if (!Char.IsControl(ch)) 43 | { 44 | ascii_output.AppendFormat("{0}", ch); 45 | } 46 | else 47 | { 48 | ascii_output.Append("."); 49 | } 50 | } 51 | else 52 | { 53 | output.Append(" "); 54 | ascii_output.Append("."); 55 | } 56 | } 57 | return output.ToString(); 58 | } 59 | 60 | public static byte[] Replace(this byte[] input, byte[] pattern, byte[] replacement) 61 | { 62 | //TODO: CLEAN 63 | 64 | if (pattern.Length == 0) 65 | { 66 | return input; 67 | } 68 | 69 | List result = new List(); 70 | 71 | int i; 72 | 73 | for (i = 0; i <= input.Length - pattern.Length; i++) 74 | { 75 | bool foundMatch = true; 76 | for (int j = 0; j < pattern.Length; j++) 77 | { 78 | if (input[i + j] != pattern[j]) 79 | { 80 | foundMatch = false; 81 | break; 82 | } 83 | } 84 | 85 | if (foundMatch) 86 | { 87 | result.AddRange(replacement); 88 | i += pattern.Length - 1; 89 | } 90 | else 91 | { 92 | result.Add(input[i]); 93 | } 94 | } 95 | 96 | for (; i < input.Length; i++) 97 | { 98 | result.Add(input[i]); 99 | } 100 | 101 | return result.ToArray(); 102 | } 103 | } 104 | } -------------------------------------------------------------------------------- /Silkroad.Tools.ModuleFilter/Silkroad.Tools.ModuleFilter.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {033B4F41-890B-4523-998C-A049C41149FE} 8 | Exe 9 | Properties 10 | Silkroad.Tools.ModuleFilter 11 | Silkroad.Tools.ModuleFilter 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | ..\bin\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | ..\packages\NLog.4.3.5\lib\net45\NLog.dll 37 | True 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | {846181e6-0314-4be3-8e6b-45db6e25f957} 62 | Silkroad.Framework.Common 63 | 64 | 65 | {b68f9d08-d251-4a1b-911d-6f19ca38dccd} 66 | Silkroad.Framework.Utility 67 | 68 | 69 | {6e338c76-6cee-41a0-8eb4-ce32608097b7} 70 | Silkroad.Plugin.Gateway 71 | 72 | 73 | {933dcc5b-c9a8-4493-9274-1f527a363a30} 74 | Silkroad.Plugin.Global 75 | 76 | 77 | {15d14b64-6b0c-4287-a5ba-5e38fdf04f47} 78 | Silkroad.Plugin.Machine 79 | 80 | 81 | 82 | 83 | PreserveNewest 84 | 85 | 86 | 87 | 94 | -------------------------------------------------------------------------------- /Silkroad.Tools.ModuleFilter/Program.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Common; 2 | using Silkroad.Framework.Utility; 3 | using Silkroad.Tools.ModuleProxy.Config; 4 | using System; 5 | using System.Reflection; 6 | 7 | namespace Silkroad.Tools.ModuleProxy 8 | { 9 | internal class Program 10 | { 11 | private static ServiceCollection _serviceCollection; 12 | 13 | private static void Main(string[] args) 14 | { 15 | SetupConsole(); 16 | try 17 | { 18 | var config = new FilterConfig("Config\\Filter.xml"); 19 | 20 | //Logger 21 | foreach (var logger in config.Logger) 22 | { 23 | StaticLogger.Create(logger.Key); 24 | StaticLogger.SetLogLevel(logger.Value.Ordinal, logger.Key); 25 | } 26 | StaticLogger.SetInstance(); 27 | 28 | //StaticLogger.Instance.Trace("Trace"); 29 | //StaticLogger.Instance.Debug("Debug"); 30 | //StaticLogger.Instance.Info("Info"); 31 | //StaticLogger.Instance.Warn("Warn"); 32 | //StaticLogger.Instance.Error("Error"); 33 | //StaticLogger.Instance.Fatal("Fatal"); 34 | 35 | //Services 36 | _serviceCollection = new ServiceCollection(); 37 | foreach (var serviceSettings in config.Services) 38 | { 39 | var service = new Service(serviceSettings.Value); 40 | _serviceCollection.Add(service); 41 | } 42 | 43 | //Plugins 44 | var pluginManager = new PluginManager(config.Plugins); 45 | foreach (var service in _serviceCollection) 46 | { 47 | pluginManager.RegisterService(service); 48 | } 49 | var pluginCount = pluginManager.Load(); 50 | StaticLogger.Instance.Info($"{pluginCount} plugins registered."); 51 | 52 | //Start services 53 | foreach (var service in _serviceCollection) 54 | { 55 | var result = service.Start(); 56 | if (result == false) 57 | StaticLogger.Instance.Fatal($"Failed to start {service.Settings.Name}, check Filter.xml and prev. errors"); 58 | } 59 | 60 | StaticLogger.Instance.Info("Successfully initilized."); 61 | Console.Beep(); 62 | 63 | while (true) 64 | { 65 | var line = Console.ReadLine(); 66 | if (line == "exit" || line == "quit") 67 | break; 68 | } 69 | foreach (var service in _serviceCollection) 70 | { 71 | service.Stop(); 72 | } 73 | } 74 | catch (Exception ex) 75 | { 76 | Console.Beep(); 77 | Console.WriteLine("Something fucked up really hard, please check Filter.xml"); 78 | Console.WriteLine(ex.Message); 79 | Console.WriteLine(ex.StackTrace); 80 | Console.Beep(); 81 | Console.ReadLine(); 82 | } 83 | } 84 | 85 | private static void SetupConsole() 86 | { 87 | #region GetAssemblyInformation 88 | 89 | var asm = Assembly.GetExecutingAssembly(); 90 | var title = asm.GetCustomAttribute()?.Title; 91 | var version = asm.GetCustomAttribute()?.Version; 92 | var configuration = asm.GetCustomAttribute()?.Configuration; 93 | var informationalVersion = asm.GetCustomAttribute()?.InformationalVersion; 94 | //var product = asm.GetCustomAttribute()?.Product; 95 | var copyright = asm.GetCustomAttribute()?.Copyright; 96 | 97 | //Display 98 | Console.WindowWidth = 140; 99 | Console.BufferHeight = 5000; 100 | Console.Title = string.Format("{0} {1} ({2}) [{3}] {4}", 101 | title, 102 | version, 103 | System.IO.File.GetLastWriteTime(asm.Location), 104 | string.IsNullOrEmpty(configuration) ? "Undefined" : string.Format("{0}", configuration), 105 | string.IsNullOrEmpty(informationalVersion) ? "" : string.Format("<{0}>", informationalVersion)); 106 | 107 | Console.WriteLine(copyright); 108 | 109 | #endregion GetAssemblyInformation 110 | } 111 | } 112 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Network/SessionPool.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Utility; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Threading; 5 | 6 | namespace Silkroad.Framework.Common 7 | { 8 | public sealed class SessionPool 9 | { 10 | private Service _service; 11 | 12 | private int _threadCount; 13 | 14 | public int ThreadCount 15 | { 16 | get 17 | { 18 | return _threadCount; 19 | } 20 | } 21 | 22 | private Thread[] _sessionThreads; 23 | 24 | private List _workItems; 25 | 26 | private bool _running; 27 | 28 | private Random _rand; 29 | 30 | private readonly object _syncRoot; 31 | 32 | public SessionPool(Service service) 33 | { 34 | _syncRoot = new object(); 35 | _service = service; 36 | _running = false; 37 | _rand = new Random(); 38 | } 39 | 40 | public bool Start() 41 | { 42 | if (_running) 43 | return false; 44 | 45 | //1 session processing thread for each CPU core 46 | //_threadCount = Environment.ProcessorCount; 47 | _threadCount = 1; 48 | 49 | _sessionThreads = new Thread[_threadCount]; 50 | 51 | //Contains numbers which describe current count of sessions which 52 | //were processed by specific thread. Thread with lowest should be chosen 53 | //for accepting new work. 54 | 55 | //Needs synchronization (!!!) 56 | _workItems = new List(); 57 | 58 | //Threads loop while _running is true, so, it has to be 59 | //assigned BEFORE we start them 60 | _running = true; 61 | 62 | //Initialize 63 | for (int i = 0; i < _threadCount; i++) 64 | { 65 | _sessionThreads[i] = new Thread(SessionWorker); 66 | 67 | //Allow aborting those threads on application exit with no problem 68 | _sessionThreads[i].IsBackground = true; 69 | 70 | //i = threadIndex 71 | _sessionThreads[i].Start(i); 72 | } 73 | 74 | //_threadTickPoller = new Timer(ThreadPollTimerTickHandler, null, 0, 1000); 75 | return true; 76 | } 77 | 78 | public void Stop() 79 | { 80 | if (!_running) 81 | return; 82 | 83 | _running = false; 84 | 85 | lock (_syncRoot) 86 | { 87 | _workItems.Clear(); 88 | } 89 | 90 | for (int i = 0; i < _threadCount; i++) 91 | { 92 | try 93 | { 94 | _sessionThreads[i].Abort(); 95 | } 96 | catch (Exception ex) 97 | { 98 | StaticLogger.Instance.Fatal(ex, $"{nameof(SessionPool)}->{Caller.GetMemberName()}:"); 99 | } 100 | } 101 | } 102 | 103 | public void RunInThread(Session session) 104 | { 105 | SessionPoolWorkItem workItem = new SessionPoolWorkItem(session, _rand.Next(0, _threadCount)); 106 | 107 | lock (_syncRoot) 108 | { 109 | _workItems.Add(workItem); 110 | } 111 | } 112 | 113 | //NOTE: Work items returned are deleted from _workItems collection 114 | //since they are considered as dispatched to thread 115 | private List GetWorkForThreadIndex(int threadIndex) 116 | { 117 | List result = new List(); 118 | 119 | List toDelete = new List(); 120 | 121 | lock (_syncRoot) 122 | { 123 | for (int i = 0; i < _workItems.Count; i++) 124 | { 125 | if (_workItems[i].ThreadIndex == threadIndex) 126 | { 127 | result.Add(_workItems[i].Session); 128 | toDelete.Add(_workItems[i]); 129 | } 130 | } 131 | 132 | for (int i = 0; i < toDelete.Count; i++) 133 | { 134 | _workItems.Remove(toDelete[i]); 135 | } 136 | } 137 | return result; 138 | } 139 | 140 | private void SessionWorker(object threadIndex) 141 | { 142 | int myThreadIndex = (int)(threadIndex); 143 | 144 | //List myWorkItems; 145 | while (_running) 146 | { 147 | var myWorkItems = GetWorkForThreadIndex(myThreadIndex); 148 | if (myWorkItems.Count != 0) 149 | { 150 | for (int i = 0; i < myWorkItems.Count; i++) 151 | { 152 | bool result = myWorkItems[i].Run(); 153 | } 154 | } 155 | else 156 | { 157 | Thread.Sleep(1); 158 | } 159 | } 160 | } 161 | } 162 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Silkroad.Framework.Common.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {846181E6-0314-4BE3-8E6B-45DB6E25F957} 8 | Library 9 | Properties 10 | Silkroad.Framework.Common 11 | Silkroad.Framework.Common 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | ..\bin\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\packages\NLog.4.3.5\lib\net45\NLog.dll 35 | True 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | {b68f9d08-d251-4a1b-911d-6f19ca38dccd} 93 | Silkroad.Framework.Utility 94 | 95 | 96 | 97 | 98 | Designer 99 | 100 | 101 | 102 | 103 | 110 | -------------------------------------------------------------------------------- /Silkroad.Tools.ModuleFilter/Config/Filter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /Silkroad.Tools.ModuleFilter.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silkroad.Tools.ModuleFilter", "Silkroad.Tools.ModuleFilter\Silkroad.Tools.ModuleFilter.csproj", "{033B4F41-890B-4523-998C-A049C41149FE}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silkroad.Framework.Common", "Silkroad.Framework.Common\Silkroad.Framework.Common.csproj", "{846181E6-0314-4BE3-8E6B-45DB6E25F957}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silkroad.Framework.Utility", "Silkroad.Framework.Utility\Silkroad.Framework.Utility.csproj", "{B68F9D08-D251-4A1B-911D-6F19CA38DCCD}" 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{3C89E165-65C9-48BB-B5F0-591CFC509792}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silkroad.Plugin.Gateway", "Silkroad.Plugin.Gateway\Silkroad.Plugin.Gateway.csproj", "{6E338C76-6CEE-41A0-8EB4-CE32608097B7}" 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silkroad.Plugin.Global", "Silkroad.Plugin.Global\Silkroad.Plugin.Global.csproj", "{933DCC5B-C9A8-4493-9274-1F527A363A30}" 17 | EndProject 18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silkroad.Plugin.Machine", "Silkroad.Plugin.Machine\Silkroad.Plugin.Machine.csproj", "{15D14B64-6B0C-4287-A5BA-5E38FDF04F47}" 19 | EndProject 20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silkroad.Plugin.Download", "Silkroad.Plugin.Download\Silkroad.Plugin.Download.csproj", "{2F31E286-005B-48DB-9D4C-B8A6702AD66D}" 21 | EndProject 22 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silkroad.Plugin.Farm", "Silkroad.Plugin.Farm\Silkroad.Plugin.Farm.csproj", "{23D72432-60F5-4DC2-8C26-8866B9D7A194}" 23 | EndProject 24 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silkroad.Plugin.SMC", "Silkroad.Plugin.SMC\Silkroad.Plugin.SMC.csproj", "{5C1434FE-1F3B-40B2-AB5F-FB63AFD0C6D6}" 25 | EndProject 26 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silkroad.Plugin.Agent", "Silkroad.Plugin.Agent\Silkroad.Plugin.Agent.csproj", "{7D67D19F-FF25-4C15-93B4-2A24939EF4BA}" 27 | EndProject 28 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silkroad.Plugin.Game", "Silkroad.Plugin.Game\Silkroad.Plugin.Game.csproj", "{52831E76-6223-4203-92E3-9E96C5FFDF44}" 29 | EndProject 30 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silkroad.Plugin.Shard", "Silkroad.Plugin.Shard\Silkroad.Plugin.Shard.csproj", "{888CBF82-6F8C-42E8-8A5E-D14AC795A5A6}" 31 | EndProject 32 | Global 33 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 34 | Debug|Any CPU = Debug|Any CPU 35 | Release|Any CPU = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 38 | {033B4F41-890B-4523-998C-A049C41149FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {033B4F41-890B-4523-998C-A049C41149FE}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {033B4F41-890B-4523-998C-A049C41149FE}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {033B4F41-890B-4523-998C-A049C41149FE}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {846181E6-0314-4BE3-8E6B-45DB6E25F957}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {846181E6-0314-4BE3-8E6B-45DB6E25F957}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {846181E6-0314-4BE3-8E6B-45DB6E25F957}.Release|Any CPU.ActiveCfg = Release|Any CPU 45 | {846181E6-0314-4BE3-8E6B-45DB6E25F957}.Release|Any CPU.Build.0 = Release|Any CPU 46 | {B68F9D08-D251-4A1B-911D-6F19CA38DCCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {B68F9D08-D251-4A1B-911D-6F19CA38DCCD}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {B68F9D08-D251-4A1B-911D-6F19CA38DCCD}.Release|Any CPU.ActiveCfg = Release|Any CPU 49 | {B68F9D08-D251-4A1B-911D-6F19CA38DCCD}.Release|Any CPU.Build.0 = Release|Any CPU 50 | {6E338C76-6CEE-41A0-8EB4-CE32608097B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {6E338C76-6CEE-41A0-8EB4-CE32608097B7}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {6E338C76-6CEE-41A0-8EB4-CE32608097B7}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {6E338C76-6CEE-41A0-8EB4-CE32608097B7}.Release|Any CPU.Build.0 = Release|Any CPU 54 | {933DCC5B-C9A8-4493-9274-1F527A363A30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 55 | {933DCC5B-C9A8-4493-9274-1F527A363A30}.Debug|Any CPU.Build.0 = Debug|Any CPU 56 | {933DCC5B-C9A8-4493-9274-1F527A363A30}.Release|Any CPU.ActiveCfg = Release|Any CPU 57 | {933DCC5B-C9A8-4493-9274-1F527A363A30}.Release|Any CPU.Build.0 = Release|Any CPU 58 | {15D14B64-6B0C-4287-A5BA-5E38FDF04F47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 59 | {15D14B64-6B0C-4287-A5BA-5E38FDF04F47}.Debug|Any CPU.Build.0 = Debug|Any CPU 60 | {15D14B64-6B0C-4287-A5BA-5E38FDF04F47}.Release|Any CPU.ActiveCfg = Release|Any CPU 61 | {15D14B64-6B0C-4287-A5BA-5E38FDF04F47}.Release|Any CPU.Build.0 = Release|Any CPU 62 | {2F31E286-005B-48DB-9D4C-B8A6702AD66D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 63 | {2F31E286-005B-48DB-9D4C-B8A6702AD66D}.Debug|Any CPU.Build.0 = Debug|Any CPU 64 | {2F31E286-005B-48DB-9D4C-B8A6702AD66D}.Release|Any CPU.ActiveCfg = Release|Any CPU 65 | {2F31E286-005B-48DB-9D4C-B8A6702AD66D}.Release|Any CPU.Build.0 = Release|Any CPU 66 | {23D72432-60F5-4DC2-8C26-8866B9D7A194}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 67 | {23D72432-60F5-4DC2-8C26-8866B9D7A194}.Debug|Any CPU.Build.0 = Debug|Any CPU 68 | {23D72432-60F5-4DC2-8C26-8866B9D7A194}.Release|Any CPU.ActiveCfg = Release|Any CPU 69 | {23D72432-60F5-4DC2-8C26-8866B9D7A194}.Release|Any CPU.Build.0 = Release|Any CPU 70 | {5C1434FE-1F3B-40B2-AB5F-FB63AFD0C6D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 71 | {5C1434FE-1F3B-40B2-AB5F-FB63AFD0C6D6}.Debug|Any CPU.Build.0 = Debug|Any CPU 72 | {5C1434FE-1F3B-40B2-AB5F-FB63AFD0C6D6}.Release|Any CPU.ActiveCfg = Release|Any CPU 73 | {5C1434FE-1F3B-40B2-AB5F-FB63AFD0C6D6}.Release|Any CPU.Build.0 = Release|Any CPU 74 | {7D67D19F-FF25-4C15-93B4-2A24939EF4BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 75 | {7D67D19F-FF25-4C15-93B4-2A24939EF4BA}.Debug|Any CPU.Build.0 = Debug|Any CPU 76 | {7D67D19F-FF25-4C15-93B4-2A24939EF4BA}.Release|Any CPU.ActiveCfg = Release|Any CPU 77 | {7D67D19F-FF25-4C15-93B4-2A24939EF4BA}.Release|Any CPU.Build.0 = Release|Any CPU 78 | {52831E76-6223-4203-92E3-9E96C5FFDF44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 79 | {52831E76-6223-4203-92E3-9E96C5FFDF44}.Debug|Any CPU.Build.0 = Debug|Any CPU 80 | {52831E76-6223-4203-92E3-9E96C5FFDF44}.Release|Any CPU.ActiveCfg = Release|Any CPU 81 | {52831E76-6223-4203-92E3-9E96C5FFDF44}.Release|Any CPU.Build.0 = Release|Any CPU 82 | {888CBF82-6F8C-42E8-8A5E-D14AC795A5A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 83 | {888CBF82-6F8C-42E8-8A5E-D14AC795A5A6}.Debug|Any CPU.Build.0 = Debug|Any CPU 84 | {888CBF82-6F8C-42E8-8A5E-D14AC795A5A6}.Release|Any CPU.ActiveCfg = Release|Any CPU 85 | {888CBF82-6F8C-42E8-8A5E-D14AC795A5A6}.Release|Any CPU.Build.0 = Release|Any CPU 86 | EndGlobalSection 87 | GlobalSection(SolutionProperties) = preSolution 88 | HideSolutionNode = FALSE 89 | EndGlobalSection 90 | GlobalSection(NestedProjects) = preSolution 91 | {6E338C76-6CEE-41A0-8EB4-CE32608097B7} = {3C89E165-65C9-48BB-B5F0-591CFC509792} 92 | {933DCC5B-C9A8-4493-9274-1F527A363A30} = {3C89E165-65C9-48BB-B5F0-591CFC509792} 93 | {15D14B64-6B0C-4287-A5BA-5E38FDF04F47} = {3C89E165-65C9-48BB-B5F0-591CFC509792} 94 | {2F31E286-005B-48DB-9D4C-B8A6702AD66D} = {3C89E165-65C9-48BB-B5F0-591CFC509792} 95 | {23D72432-60F5-4DC2-8C26-8866B9D7A194} = {3C89E165-65C9-48BB-B5F0-591CFC509792} 96 | {5C1434FE-1F3B-40B2-AB5F-FB63AFD0C6D6} = {3C89E165-65C9-48BB-B5F0-591CFC509792} 97 | {7D67D19F-FF25-4C15-93B4-2A24939EF4BA} = {3C89E165-65C9-48BB-B5F0-591CFC509792} 98 | {52831E76-6223-4203-92E3-9E96C5FFDF44} = {3C89E165-65C9-48BB-B5F0-591CFC509792} 99 | {888CBF82-6F8C-42E8-8A5E-D14AC795A5A6} = {3C89E165-65C9-48BB-B5F0-591CFC509792} 100 | EndGlobalSection 101 | EndGlobal 102 | -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Objects/CertifiactionManager.cs: -------------------------------------------------------------------------------- 1 | using Silkroad.Framework.Common.Objects.Certification; 2 | using Silkroad.Framework.Common.Objects.SecurityDesc; 3 | using Silkroad.Framework.Common.Security; 4 | using Silkroad.Framework.Utility; 5 | using System.Collections.Generic; 6 | 7 | namespace Silkroad.Framework.Common.Objects 8 | { 9 | public class CertifiactionManager 10 | { 11 | public string RequestName { get; set; } 12 | public string RequestIP { get; set; } 13 | 14 | public Dictionary ServiceTypes { get; private set; } 15 | public Dictionary OperationTypes { get; private set; } 16 | public List GlobalServices { get; private set; } 17 | public Dictionary GlobalOperations { get; private set; } 18 | public List Unknown { get; private set; } 19 | public Dictionary Shards { get; private set; } 20 | public Dictionary NodeTypes { get; private set; } 21 | public Dictionary NodeData { get; private set; } 22 | public Dictionary NodeLinks { get; private set; } 23 | 24 | public Dictionary SecurityDescriptionGroups { get; private set; } 25 | public Dictionary SecurityDescriptions { get; private set; } 26 | public List SecurityDescriptionGroupAssigns { get; private set; } 27 | 28 | public CertifiactionManager() 29 | { 30 | ServiceTypes = new Dictionary(); 31 | OperationTypes = new Dictionary(); 32 | GlobalServices = new List(); 33 | GlobalOperations = new Dictionary(); 34 | Unknown = new List(); 35 | Shards = new Dictionary(); 36 | NodeTypes = new Dictionary(); 37 | NodeData = new Dictionary(); 38 | NodeLinks = new Dictionary(); 39 | 40 | SecurityDescriptionGroups = new Dictionary(); 41 | SecurityDescriptions = new Dictionary(); 42 | SecurityDescriptionGroupAssigns = new List(); 43 | } 44 | 45 | public void ReadReq(Packet packet) 46 | { 47 | this.RequestName = packet.ReadAscii(); 48 | this.RequestIP = packet.ReadAscii(); 49 | } 50 | 51 | public void WriteReq(Packet packet) 52 | { 53 | packet.WriteAscii(this.RequestName); 54 | packet.WriteAscii(this.RequestIP); 55 | } 56 | 57 | public void ReadAck(Packet packet) 58 | { 59 | var result = packet.ReadBool(); 60 | if (result) 61 | { 62 | this.ReadDict(packet, ServiceTypes); 63 | this.ReadDict(packet, OperationTypes); 64 | this.ReadList(packet, GlobalServices); 65 | this.ReadDict(packet, GlobalOperations); 66 | this.ReadList(packet, Unknown); 67 | this.ReadDict(packet, Shards); 68 | this.ReadDict(packet, NodeTypes); 69 | this.ReadDict(packet, NodeData); 70 | this.ReadDict(packet, NodeLinks); 71 | 72 | var hasSecurityDescription = packet.ReadBool(); 73 | if (hasSecurityDescription) 74 | { 75 | this.ReadDict(packet, SecurityDescriptionGroups); 76 | this.ReadDict(packet, SecurityDescriptions); 77 | this.ReadList(packet, SecurityDescriptionGroupAssigns); 78 | } 79 | } 80 | } 81 | 82 | public void ReadDict(Packet packet, IDictionary dict) where TStruct : Unmanaged.IUnmanagedStruct, IKeyStruct 83 | { 84 | dict.Clear(); 85 | 86 | var unkByte0 = packet.ReadByte(); 87 | while (true) 88 | { 89 | var entryFlag = packet.ReadByte(); 90 | if (entryFlag == 1) 91 | { 92 | var structure = packet.ReadStruct(); 93 | dict.Add(structure.Key, structure); 94 | } 95 | else if (entryFlag == 2) 96 | { 97 | break; 98 | } 99 | else 100 | { 101 | //TODO: Proper exception 102 | StaticLogger.Instance.Error($"{nameof(CertifiactionManager)}->{Caller.GetMemberName()}: entry missmatch!"); 103 | break; 104 | } 105 | } 106 | } 107 | 108 | public void ReadList(Packet packet, IList list) where TStruct : Unmanaged.IUnmanagedStruct 109 | { 110 | list.Clear(); 111 | 112 | var unkByte0 = packet.ReadByte(); 113 | while (true) 114 | { 115 | var entryFlag = packet.ReadByte(); 116 | if (entryFlag == 1) 117 | { 118 | list.Add(packet.ReadStruct()); 119 | } 120 | else if (entryFlag == 2) 121 | { 122 | break; 123 | } 124 | else 125 | { 126 | //TODO: Proper exception 127 | StaticLogger.Instance.Error($"{nameof(CertifiactionManager)}->{Caller.GetMemberName()}: entry missmatch!"); 128 | break; 129 | } 130 | } 131 | } 132 | 133 | public void WriteAck(Packet packet, bool writeCertification, bool writeSecurityDesc) 134 | { 135 | packet.WriteBool(writeCertification); 136 | if (writeCertification) 137 | { 138 | this.WriteDict(packet, ServiceTypes); 139 | this.WriteDict(packet, OperationTypes); 140 | this.WriteList(packet, GlobalServices); 141 | this.WriteDict(packet, GlobalOperations); 142 | this.WriteList(packet, Unknown); 143 | this.WriteDict(packet, Shards); 144 | this.WriteDict(packet, NodeTypes); 145 | this.WriteDict(packet, NodeData); 146 | this.WriteDict(packet, NodeLinks); 147 | } 148 | 149 | packet.WriteBool(writeSecurityDesc); 150 | if (writeSecurityDesc) 151 | { 152 | this.WriteDict(packet, SecurityDescriptionGroups); 153 | this.WriteDict(packet, SecurityDescriptions); 154 | this.WriteList(packet, SecurityDescriptionGroupAssigns); 155 | } 156 | } 157 | 158 | public void WriteDict(Packet packet, IDictionary dict) where TStruct : Unmanaged.IUnmanagedStruct 159 | { 160 | packet.WriteByte(0); //unkByte1 161 | foreach (KeyValuePair kvp in dict) 162 | { 163 | packet.WriteByte(1); 164 | packet.WriteStruct(kvp.Value); 165 | } 166 | packet.WriteByte(2); 167 | } 168 | 169 | public void WriteList(Packet packet, IList list) where TStruct : Unmanaged.IUnmanagedStruct 170 | { 171 | packet.WriteByte(0); //unkByte1 172 | foreach (TStruct structure in list) 173 | { 174 | packet.WriteByte(1); 175 | packet.WriteStruct(structure); 176 | } 177 | packet.WriteByte(2); 178 | } 179 | } 180 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Network/Session.cs: -------------------------------------------------------------------------------- 1 | #define DEBUG_NET 2 | 3 | using Silkroad.Framework.Common.Security; 4 | using Silkroad.Framework.Utility; 5 | using System; 6 | using System.Net.Sockets; 7 | using System.Threading; 8 | 9 | namespace Silkroad.Framework.Common 10 | { 11 | public class Session 12 | { 13 | //NOTE: 14 | //CERTIFICATOR = SERVER 15 | //MODULE = CLIENT 16 | 17 | private const int MAX_BUFFER = 4096; 18 | 19 | #region Fields 20 | 21 | private readonly object _syncLock; 22 | private bool _destroyed; 23 | 24 | private Service _service; 25 | 26 | private Socket _clientSocket; 27 | private Socket _certificatorSocket; 28 | 29 | private byte[] _clientBuffer; 30 | private byte[] _certificatorBuffer; 31 | 32 | private SecurityManager _clientSecurity; 33 | private SecurityManager _certificatorSecurity; 34 | 35 | private SessionState _state; 36 | 37 | #endregion Fields 38 | 39 | #region Properties 40 | 41 | public SessionState State 42 | { 43 | get { return _state; } 44 | set { _state = value; } 45 | } 46 | 47 | #endregion Properties 48 | 49 | public Session(Service service, Socket moduleSocket, int sessionID) 50 | { 51 | _syncLock = new object(); 52 | 53 | //pass container 54 | _service = service; 55 | 56 | //pass socket 57 | _clientSocket = moduleSocket; 58 | 59 | //create buffers 60 | _clientBuffer = new byte[MAX_BUFFER]; 61 | _certificatorBuffer = new byte[MAX_BUFFER]; 62 | 63 | //create security 64 | _clientSecurity = new SecurityManager(); 65 | 66 | //generate module security 67 | _clientSecurity.GenerateSecurity(_service.Settings.Security.Blowfish, 68 | _service.Settings.Security.CRC, 69 | _service.Settings.Security.Handshake); 70 | 71 | _certificatorSecurity = new SecurityManager(); 72 | _certificatorSecurity.ChangeIdentity(_service.Settings.Type.ToString(), 0); 73 | 74 | //create state 75 | _state = new SessionState(); 76 | _state.ID = sessionID; 77 | } 78 | 79 | public bool Run() 80 | { 81 | while (!_destroyed) 82 | { 83 | try 84 | { 85 | _certificatorSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 86 | _certificatorSocket.Connect(_service.Settings.Certificator.IP, _service.Settings.Certificator.Port); 87 | if (_certificatorSocket.Connected) 88 | { 89 | this.BeginReceiveFromCertificator(); 90 | this.BeginReceiveFromClient(); 91 | 92 | StaticLogger.Instance.Info($"{nameof(Session)}->{Caller.GetMemberName()}: server coord established: {_state.ID}({_service.Settings.Certificator.IP}:{_service.Settings.Certificator.Port})"); 93 | 94 | return true; 95 | } 96 | else 97 | { 98 | this.Disconnect(); 99 | return false; 100 | } 101 | } 102 | catch (Exception ex) 103 | { 104 | StaticLogger.Instance.Error(ex, $"{nameof(Session)}->{Caller.GetMemberName()}:"); 105 | } 106 | Thread.Sleep(2000); 107 | } 108 | return false; 109 | } 110 | 111 | internal void Disconnect(bool suppressDestroy = false) 112 | { 113 | lock (_syncLock) 114 | { 115 | if (!_destroyed) 116 | { 117 | _destroyed = true; 118 | 119 | if (_clientSocket != null) 120 | _clientSocket.Close(); 121 | 122 | if (_certificatorSocket != null) 123 | _certificatorSocket.Close(); 124 | } 125 | 126 | if (!suppressDestroy) 127 | { 128 | _service.SessionManager.Destroy(this); 129 | } 130 | } 131 | } 132 | 133 | #region Certificator 134 | 135 | private void BeginReceiveFromCertificator() 136 | { 137 | try 138 | { 139 | _certificatorSocket.BeginReceive(_certificatorBuffer, 0, _certificatorBuffer.Length, SocketFlags.None, BeginReceiveFromCertificatorCallback, null); 140 | } 141 | catch (Exception ex) 142 | { 143 | StaticLogger.Instance.Error(ex, $"{nameof(Session)}->{Caller.GetMemberName()}:"); 144 | this.Disconnect(); 145 | } 146 | } 147 | 148 | private void BeginReceiveFromCertificatorCallback(IAsyncResult ar) 149 | { 150 | try 151 | { 152 | var nReceived = _certificatorSocket.EndReceive(ar); 153 | if (nReceived == 0) 154 | { 155 | StaticLogger.Instance.Fatal($"{Caller.GetMemberName()}: 0 bytes received!"); 156 | this.Disconnect(); 157 | return; 158 | } 159 | 160 | _certificatorSecurity.Recv(_certificatorBuffer, 0, nReceived); 161 | var packets = _certificatorSecurity.TransferIncoming(); 162 | if (packets != null) 163 | { 164 | for (int i = 0; i < packets.Count; i++) 165 | { 166 | var packet = packets[i]; 167 | #if DEBUG_NET 168 | if (StaticLogger.Instance.IsTraceEnabled) 169 | StaticLogger.Instance.Trace("[S->P][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", packet.Opcode, packet.Length, packet.Encrypted ? "[Encrypted]" : "", packet.Massive ? "[Massive]" : "", Environment.NewLine, packet.GetBytes().HexDump(), Environment.NewLine); 170 | #endif 171 | if (packet.Opcode == 0x5000 || packet.Opcode == 0x9000) 172 | continue; 173 | 174 | var result = _service.PacketManager.Handle(PacketSource.Certificator, this, packet); 175 | switch (result.Action) 176 | { 177 | case PacketResultAction.Ignore: 178 | return; 179 | 180 | case PacketResultAction.Disconnect: 181 | this.Disconnect(); 182 | return; 183 | 184 | case PacketResultAction.Replace: 185 | foreach (var replacedPacket in result) 186 | _clientSecurity.Send(replacedPacket); 187 | continue; 188 | 189 | case PacketResultAction.Response: 190 | foreach (var replacedPacket in result) 191 | _certificatorSecurity.Send(replacedPacket); 192 | continue; 193 | } 194 | 195 | _clientSecurity.Send(packet); 196 | } 197 | } 198 | 199 | this.TransferToClient(); 200 | //this.TransferTo(_clientSecurity, _clientSocket); 201 | this.BeginReceiveFromCertificator(); 202 | } 203 | catch (Exception ex) 204 | { 205 | StaticLogger.Instance.Error(ex, $"{nameof(Session)}->{Caller.GetMemberName()}:"); 206 | this.Disconnect(); 207 | } 208 | } 209 | 210 | private void TransferToCertificator() 211 | { 212 | try 213 | { 214 | var kvp = _certificatorSecurity.TransferOutgoing(); 215 | if (kvp != null) 216 | { 217 | for (int i = 0; i < kvp.Count; i++) 218 | { 219 | if (_destroyed) 220 | return; 221 | 222 | #if DEBUG_NET 223 | var packet = kvp[i].Value; 224 | if (StaticLogger.Instance.IsTraceEnabled) 225 | StaticLogger.Instance.Trace("[P->S][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", packet.Opcode, packet.Length, packet.Encrypted ? "[Encrypted]" : "", packet.Massive ? "[Massive]" : "", Environment.NewLine, packet.GetBytes().HexDump(), Environment.NewLine); 226 | #endif 227 | 228 | _certificatorSocket.BeginSend(kvp[i].Key.Buffer, 0, kvp[i].Key.Buffer.Length, SocketFlags.None, BeginSendToCertificatorCallback, null); 229 | } 230 | } 231 | } 232 | catch (Exception ex) 233 | { 234 | StaticLogger.Instance.Error(ex, $"{nameof(Session)}->{Caller.GetMemberName()}:"); 235 | this.Disconnect(); 236 | } 237 | } 238 | 239 | private void BeginSendToCertificatorCallback(IAsyncResult ar) 240 | { 241 | try 242 | { 243 | _certificatorSocket.EndSend(ar); 244 | } 245 | catch (Exception ex) 246 | { 247 | StaticLogger.Instance.Error(ex, $"{nameof(Session)}->{Caller.GetMemberName()}:"); 248 | this.Disconnect(); 249 | } 250 | } 251 | 252 | public void SendToCertificator(Packet packet) 253 | { 254 | if (_destroyed) 255 | return; 256 | 257 | try 258 | { 259 | _certificatorSecurity.Send(packet); 260 | TransferToCertificator(); 261 | } 262 | catch (Exception ex) 263 | { 264 | StaticLogger.Instance.Error(ex, $"{nameof(Session)}->{Caller.GetMemberName()}:"); 265 | this.Disconnect(); 266 | } 267 | } 268 | 269 | #endregion Certificator 270 | 271 | #region Module 272 | 273 | private void BeginReceiveFromClient() 274 | { 275 | try 276 | { 277 | _clientSocket.BeginReceive(_clientBuffer, 0, _clientBuffer.Length, SocketFlags.None, BeginReceiveFromClientCallback, null); 278 | } 279 | catch (Exception ex) 280 | { 281 | StaticLogger.Instance.Error(ex, $"{nameof(Session)}->{Caller.GetMemberName()}:"); 282 | this.Disconnect(); 283 | } 284 | } 285 | 286 | private void BeginReceiveFromClientCallback(IAsyncResult ar) 287 | { 288 | try 289 | { 290 | var nReceived = _clientSocket.EndReceive(ar); 291 | if (nReceived == 0) 292 | { 293 | StaticLogger.Instance.Fatal($"{Caller.GetMemberName()}: 0 bytes received!"); 294 | this.Disconnect(); 295 | return; 296 | } 297 | 298 | _clientSecurity.Recv(_clientBuffer, 0, nReceived); 299 | var packets = _clientSecurity.TransferIncoming(); 300 | if (packets != null) 301 | { 302 | for (int i = 0; i < packets.Count; i++) 303 | { 304 | var packet = packets[i]; 305 | #if DEBUG_NET 306 | if (StaticLogger.Instance.IsTraceEnabled) 307 | StaticLogger.Instance.Trace("[C->P][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", packet.Opcode, packet.Length, packet.Encrypted ? "[Encrypted]" : "", packet.Massive ? "[Massive]" : "", Environment.NewLine, packet.GetBytes().HexDump(), Environment.NewLine); 308 | #endif 309 | if (packet.Opcode == 0x5000 || packet.Opcode == 0x9000 || packet.Opcode == 0x2001) 310 | continue; 311 | 312 | var result = _service.PacketManager.Handle(PacketSource.Module, this, packet); 313 | switch (result.Action) 314 | { 315 | case PacketResultAction.Ignore: 316 | continue; 317 | 318 | case PacketResultAction.Disconnect: 319 | this.Disconnect(); 320 | return; 321 | 322 | case PacketResultAction.Replace: 323 | foreach (var replacedPacket in result) 324 | _certificatorSecurity.Send(replacedPacket); 325 | continue; 326 | 327 | case PacketResultAction.Response: 328 | foreach (var replacedPacket in result) 329 | _clientSecurity.Send(replacedPacket); 330 | continue; 331 | } 332 | 333 | _certificatorSecurity.Send(packet); 334 | } 335 | } 336 | 337 | this.TransferToCertificator(); 338 | //this.TransferTo(_certificatorSecurity, _certificatorSocket); 339 | this.BeginReceiveFromClient(); 340 | } 341 | catch (Exception ex) 342 | { 343 | StaticLogger.Instance.Error(ex, $"{nameof(Session)}->{Caller.GetMemberName()}:"); 344 | this.Disconnect(); 345 | } 346 | } 347 | 348 | private void TransferToClient() 349 | { 350 | try 351 | { 352 | var kvp = _clientSecurity.TransferOutgoing(); 353 | if (kvp != null) 354 | { 355 | for (int i = 0; i < kvp.Count; i++) 356 | { 357 | if (_destroyed) 358 | return; 359 | 360 | #if DEBUG_NET 361 | var packet = kvp[i].Value; 362 | if (StaticLogger.Instance.IsTraceEnabled) 363 | StaticLogger.Instance.Trace("[P->C][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", packet.Opcode, packet.Length, packet.Encrypted ? "[Encrypted]" : "", packet.Massive ? "[Massive]" : "", Environment.NewLine, packet.GetBytes().HexDump(), Environment.NewLine); 364 | #endif 365 | 366 | _clientSocket.BeginSend(kvp[i].Key.Buffer, 0, kvp[i].Key.Buffer.Length, SocketFlags.None, BeginSendToClientCallback, null); 367 | } 368 | } 369 | } 370 | catch (Exception ex) 371 | { 372 | StaticLogger.Instance.Error(ex, $"{nameof(Session)}->{Caller.GetMemberName()}:"); 373 | this.Disconnect(); 374 | } 375 | } 376 | 377 | private void BeginSendToClientCallback(IAsyncResult ar) 378 | { 379 | try 380 | { 381 | _clientSocket.EndSend(ar); 382 | } 383 | catch (Exception ex) 384 | { 385 | StaticLogger.Instance.Error(ex, $"{nameof(Session)}->{Caller.GetMemberName()}:"); 386 | this.Disconnect(); 387 | } 388 | } 389 | 390 | public void SendToClient(Packet packet) 391 | { 392 | if (_destroyed) 393 | return; 394 | 395 | try 396 | { 397 | _clientSecurity.Send(packet); 398 | TransferToClient(); 399 | } 400 | catch (Exception ex) 401 | { 402 | StaticLogger.Instance.Error(ex, $"{nameof(Session)}->{Caller.GetMemberName()}:"); 403 | this.Disconnect(); 404 | } 405 | } 406 | 407 | #endregion Module 408 | 409 | #region Generic 410 | 411 | private void TransferTo(SecurityManager manager, Socket socket) 412 | { 413 | try 414 | { 415 | var kvp = manager.TransferOutgoing(); 416 | if (kvp != null) 417 | { 418 | for (int i = 0; i < kvp.Count; i++) 419 | { 420 | if (_destroyed) 421 | return; 422 | 423 | #if DEBUG_NET 424 | var packet = kvp[i].Value; 425 | if (StaticLogger.Instance.IsTraceEnabled) 426 | StaticLogger.Instance.Trace("[P->{7}][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", packet.Opcode, packet.Length, packet.Encrypted ? "[Encrypted]" : "", packet.Massive ? "[Massive]" : "", Environment.NewLine, packet.GetBytes().HexDump(), Environment.NewLine, manager.IdentityName); 427 | #endif 428 | 429 | socket.BeginSend(kvp[i].Key.Buffer, 0, kvp[i].Key.Buffer.Length, SocketFlags.None, BeginSendCallback, socket); 430 | } 431 | } 432 | } 433 | catch (Exception ex) 434 | { 435 | StaticLogger.Instance.Error(ex, $"{nameof(Session)}->{Caller.GetMemberName()}:"); 436 | this.Disconnect(); 437 | } 438 | } 439 | 440 | private void BeginSendCallback(IAsyncResult ar) 441 | { 442 | try 443 | { 444 | var socket = ar.AsyncState as Socket; 445 | socket.EndSend(ar); 446 | } 447 | catch (Exception ex) 448 | { 449 | StaticLogger.Instance.Error(ex, $"{nameof(Session)}->{Caller.GetMemberName()}:"); 450 | this.Disconnect(); 451 | } 452 | } 453 | 454 | #endregion Generic 455 | } 456 | } -------------------------------------------------------------------------------- /Silkroad.Framework.Common/Security/Blowfish.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Silkroad.Framework.Common.Security 4 | { 5 | public class Blowfish 6 | { 7 | private static uint[] bf_P = 8 | { 9 | 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 10 | 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 11 | 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 12 | 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 13 | 0x9216d5d9, 0x8979fb1b, 14 | }; 15 | 16 | private static uint[,] bf_S = 17 | { 18 | { 19 | 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 20 | 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, 21 | 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, 22 | 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, 23 | 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, 24 | 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, 25 | 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, 26 | 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, 27 | 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, 28 | 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, 29 | 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, 30 | 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, 31 | 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, 32 | 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, 33 | 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, 34 | 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, 35 | 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, 36 | 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, 37 | 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, 38 | 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, 39 | 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, 40 | 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, 41 | 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, 42 | 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, 43 | 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, 44 | 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, 45 | 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, 46 | 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, 47 | 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, 48 | 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, 49 | 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, 50 | 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a 51 | }, 52 | 53 | { 54 | 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, 55 | 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, 56 | 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, 57 | 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, 58 | 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, 59 | 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, 60 | 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, 61 | 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, 62 | 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, 63 | 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, 64 | 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, 65 | 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, 66 | 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, 67 | 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, 68 | 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, 69 | 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, 70 | 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, 71 | 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, 72 | 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, 73 | 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, 74 | 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, 75 | 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, 76 | 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, 77 | 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, 78 | 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, 79 | 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, 80 | 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, 81 | 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, 82 | 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, 83 | 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, 84 | 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, 85 | 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7 86 | }, 87 | 88 | { 89 | 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, 90 | 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, 91 | 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, 92 | 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, 93 | 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, 94 | 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, 95 | 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, 96 | 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, 97 | 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, 98 | 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, 99 | 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, 100 | 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, 101 | 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, 102 | 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, 103 | 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, 104 | 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, 105 | 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, 106 | 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, 107 | 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, 108 | 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, 109 | 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, 110 | 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, 111 | 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, 112 | 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, 113 | 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, 114 | 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, 115 | 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, 116 | 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, 117 | 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, 118 | 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, 119 | 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, 120 | 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0 121 | }, 122 | 123 | { 124 | 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, 125 | 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, 126 | 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, 127 | 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, 128 | 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, 129 | 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, 130 | 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, 131 | 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, 132 | 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, 133 | 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, 134 | 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, 135 | 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, 136 | 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, 137 | 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, 138 | 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, 139 | 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, 140 | 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, 141 | 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, 142 | 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, 143 | 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, 144 | 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, 145 | 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, 146 | 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, 147 | 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, 148 | 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, 149 | 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, 150 | 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, 151 | 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, 152 | 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, 153 | 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, 154 | 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, 155 | 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 156 | } 157 | }; 158 | 159 | private uint[] PArray; 160 | private uint[,] SBoxes; 161 | 162 | public Blowfish() 163 | { 164 | PArray = new uint[18]; 165 | SBoxes = new uint[4, 256]; 166 | } 167 | 168 | private uint S(uint x, int i) 169 | { 170 | if (i < 0 || i > 3) 171 | { 172 | throw (new Exception(String.Format("[Blowfish::S] Invalid i index of [{0}].", i))); 173 | } 174 | 175 | x >>= (24 - (8 * i)); 176 | x &= 0xFF; 177 | 178 | return SBoxes[i, x]; 179 | } 180 | 181 | private uint bf_F(uint x) 182 | { 183 | return (((S(x, 0) + S(x, 1)) ^ S(x, 2)) + S(x, 3)); 184 | } 185 | 186 | private void ROUND(ref uint a, uint b, int n) 187 | { 188 | a ^= (bf_F(b) ^ PArray[n]); 189 | } 190 | 191 | private void Blowfish_encipher(ref uint xl, ref uint xr) 192 | { 193 | uint Xl = xl; 194 | uint Xr = xr; 195 | 196 | Xl ^= PArray[0]; 197 | ROUND(ref Xr, Xl, 1); ROUND(ref Xl, Xr, 2); 198 | ROUND(ref Xr, Xl, 3); ROUND(ref Xl, Xr, 4); 199 | ROUND(ref Xr, Xl, 5); ROUND(ref Xl, Xr, 6); 200 | ROUND(ref Xr, Xl, 7); ROUND(ref Xl, Xr, 8); 201 | ROUND(ref Xr, Xl, 9); ROUND(ref Xl, Xr, 10); 202 | ROUND(ref Xr, Xl, 11); ROUND(ref Xl, Xr, 12); 203 | ROUND(ref Xr, Xl, 13); ROUND(ref Xl, Xr, 14); 204 | ROUND(ref Xr, Xl, 15); ROUND(ref Xl, Xr, 16); 205 | Xr ^= PArray[17]; 206 | 207 | xr = Xl; 208 | xl = Xr; 209 | } 210 | 211 | private void Blowfish_decipher(ref uint xl, ref uint xr) 212 | { 213 | uint Xl = xl; 214 | uint Xr = xr; 215 | 216 | Xl ^= PArray[17]; 217 | ROUND(ref Xr, Xl, 16); ROUND(ref Xl, Xr, 15); 218 | ROUND(ref Xr, Xl, 14); ROUND(ref Xl, Xr, 13); 219 | ROUND(ref Xr, Xl, 12); ROUND(ref Xl, Xr, 11); 220 | ROUND(ref Xr, Xl, 10); ROUND(ref Xl, Xr, 9); 221 | ROUND(ref Xr, Xl, 8); ROUND(ref Xl, Xr, 7); 222 | ROUND(ref Xr, Xl, 6); ROUND(ref Xl, Xr, 5); 223 | ROUND(ref Xr, Xl, 4); ROUND(ref Xl, Xr, 3); 224 | ROUND(ref Xr, Xl, 2); ROUND(ref Xl, Xr, 1); 225 | Xr ^= PArray[0]; 226 | 227 | xl = Xr; 228 | xr = Xl; 229 | } 230 | 231 | // Sets up the blowfish object with this specific key. 232 | public void Initialize(byte[] key_ptr) 233 | { 234 | Initialize(key_ptr, 0, key_ptr.Length); 235 | } 236 | 237 | // Sets up the blowfish object with this specific key. 238 | public void Initialize(byte[] key_ptr, int offset, int length) 239 | { 240 | uint i, j; 241 | uint data, datal, datar; 242 | 243 | for (i = 0; i < 18; ++i) 244 | { 245 | PArray[i] = bf_P[i]; 246 | } 247 | 248 | for (i = 0; i < 4; ++i) 249 | { 250 | for (j = 0; j < 256; ++j) 251 | { 252 | SBoxes[i, j] = bf_S[i, j]; 253 | } 254 | } 255 | 256 | byte[] temp = new byte[4]; 257 | j = 0; 258 | for (i = 0; i < 16 + 2; ++i) 259 | { 260 | temp[3] = key_ptr[j]; 261 | temp[2] = key_ptr[(j + 1) % length]; 262 | temp[1] = key_ptr[(j + 2) % length]; 263 | temp[0] = key_ptr[(j + 3) % length]; 264 | data = BitConverter.ToUInt32(temp, 0); 265 | PArray[i] ^= data; 266 | j = (j + 4) % (uint)length; 267 | } 268 | 269 | datal = 0; 270 | datar = 0; 271 | 272 | for (i = 0; i < 16 + 2; i += 2) 273 | { 274 | Blowfish_encipher(ref datal, ref datar); 275 | PArray[i] = datal; 276 | PArray[i + 1] = datar; 277 | } 278 | 279 | for (i = 0; i < 4; ++i) 280 | { 281 | for (j = 0; j < 256; j += 2) 282 | { 283 | Blowfish_encipher(ref datal, ref datar); 284 | SBoxes[i, j] = datal; 285 | SBoxes[i, j + 1] = datar; 286 | } 287 | } 288 | } 289 | 290 | // Returns the output length based on the size. This can be used to 291 | // determine how many bytes of output space is needed for data that 292 | // is about to be encoded or decoded. 293 | public int GetOutputLength(int length) 294 | { 295 | return (length % 8) == 0 ? length : length + (8 - (length % 8)); 296 | } 297 | 298 | // Encodes a stream of data and returns a new array of the encoded data. 299 | // Returns null if length is 0. 300 | public byte[] Encode(byte[] stream) 301 | { 302 | return Encode(stream, 0, stream.Length); 303 | } 304 | 305 | // Encodes a stream of data and returns a new array of the encoded data. 306 | // Returns null if length is 0. 307 | public byte[] Encode(byte[] stream, int offset, int length) 308 | { 309 | if (length == 0) 310 | { 311 | return null; 312 | } 313 | 314 | byte[] workspace = new byte[GetOutputLength(length)]; 315 | 316 | Buffer.BlockCopy(stream, offset, workspace, 0, length); 317 | for (int x = length; x < workspace.Length; ++x) 318 | { 319 | workspace[x] = 0; 320 | } 321 | 322 | for (int x = 0; x < workspace.Length; x += 8) 323 | { 324 | uint l = BitConverter.ToUInt32(workspace, x + 0); 325 | uint r = BitConverter.ToUInt32(workspace, x + 4); 326 | Blowfish_encipher(ref l, ref r); 327 | Buffer.BlockCopy(BitConverter.GetBytes(l), 0, workspace, x + 0, 4); 328 | Buffer.BlockCopy(BitConverter.GetBytes(r), 0, workspace, x + 4, 4); 329 | } 330 | 331 | return workspace; 332 | } 333 | 334 | // Decodes a stream of data and returns an array of the decoded data. 335 | // Returns null if length is not % 8. 336 | public byte[] Decode(byte[] stream) 337 | { 338 | return Decode(stream, 0, stream.Length); 339 | } 340 | 341 | // Decodes a stream of data and returns an array of the decoded data. 342 | // Returns null if length is not % 8. 343 | public byte[] Decode(byte[] stream, int offset, int length) 344 | { 345 | if (length % 8 != 0 || length == 0) 346 | { 347 | return null; 348 | } 349 | 350 | byte[] workspace = new byte[length]; 351 | Buffer.BlockCopy(stream, offset, workspace, 0, length); 352 | 353 | for (int x = 0; x < workspace.Length; x += 8) 354 | { 355 | uint l = BitConverter.ToUInt32(workspace, x + 0); 356 | uint r = BitConverter.ToUInt32(workspace, x + 4); 357 | Blowfish_decipher(ref l, ref r); 358 | Buffer.BlockCopy(BitConverter.GetBytes(l), 0, workspace, x + 0, 4); 359 | Buffer.BlockCopy(BitConverter.GetBytes(r), 0, workspace, x + 4, 4); 360 | } 361 | 362 | return workspace; 363 | } 364 | } 365 | } --------------------------------------------------------------------------------