Download src/SilkroadBot.Core/Configuration/ProtocolAdapterRegistry.cs from Ahmedramadan24/SilkroadBot: direct link, hf CLI and curl.
- Browser
- Download file 2.37 kB
-
https://huggingface.co/Ahmedramadan24/SilkroadBot/resolve/main/src/SilkroadBot.Core/Configuration/ProtocolAdapterRegistry.cs
- Command line
-
hf download hf://Ahmedramadan24/SilkroadBot/src/SilkroadBot.Core/Configuration/ProtocolAdapterRegistry.cs
-
curl -L -o ProtocolAdapterRegistry.cs https://huggingface.co/Ahmedramadan24/SilkroadBot/resolve/main/src/SilkroadBot.Core/Configuration/ProtocolAdapterRegistry.cs
2.37 kB
| using SilkroadBot.Domain.Enums; | |
| using SilkroadBot.Domain.Interfaces; | |
| using SilkroadBot.Domain.Adapters; | |
| namespace SilkroadBot.Core.Configuration; | |
| /// <summary> | |
| /// Registry and factory for protocol adapters. | |
| /// Configuration-driven: adapters are selected based on game client type. | |
| /// </summary> | |
| public class ProtocolAdapterRegistry | |
| { | |
| private readonly Dictionary<GameClientType, IProtocolAdapter> _adapters = new(); | |
| private readonly Dictionary<string, CustomServerConfig> _customServers = new(); | |
| public ProtocolAdapterRegistry() | |
| { | |
| // Register built-in adapters | |
| Register(new ISROProtocolAdapter()); | |
| Register(new TRSROProtocolAdapter()); | |
| Register(new VSROProtocolAdapter()); | |
| } | |
| /// <summary> | |
| /// Register a protocol adapter. | |
| /// </summary> | |
| public void Register(IProtocolAdapter adapter) | |
| { | |
| _adapters[adapter.ClientType] = adapter; | |
| } | |
| /// <summary> | |
| /// Get adapter for a specific client type. | |
| /// </summary> | |
| public IProtocolAdapter GetAdapter(GameClientType clientType) | |
| { | |
| if (_adapters.TryGetValue(clientType, out var adapter)) | |
| return adapter; | |
| throw new NotSupportedException($"No adapter registered for {clientType}"); | |
| } | |
| /// <summary> | |
| /// Register a custom private server configuration. | |
| /// </summary> | |
| public void RegisterCustomServer(string name, CustomServerConfig config) | |
| { | |
| _customServers[name] = config; | |
| } | |
| /// <summary> | |
| /// Get all registered adapters. | |
| /// </summary> | |
| public IReadOnlyList<IProtocolAdapter> GetAllAdapters() => _adapters.Values.ToList(); | |
| /// <summary> | |
| /// Get all custom server configurations. | |
| /// </summary> | |
| public IReadOnlyDictionary<string, CustomServerConfig> GetCustomServers() => _customServers; | |
| } | |
| /// <summary> | |
| /// Configuration for a custom/private server. | |
| /// </summary> | |
| public record CustomServerConfig | |
| { | |
| public string Name { get; init; } = string.Empty; | |
| public string Host { get; init; } = "localhost"; | |
| public int GatewayPort { get; init; } = 15779; | |
| public int AgentPort { get; init; } = 15780; | |
| public GameClientType BaseProtocol { get; init; } = GameClientType.VSRO; | |
| public string ProtocolVersion { get; init; } = "vSRO_188"; | |
| public Dictionary<string, string> CustomOpcodes { get; init; } = new(); | |
| } | |