diff --git a/src/DiIiS-NA/BGS-Server/Battle/BattleClient.cs b/src/DiIiS-NA/BGS-Server/Battle/BattleClient.cs index 60ad517..77fdd9a 100644 --- a/src/DiIiS-NA/BGS-Server/Battle/BattleClient.cs +++ b/src/DiIiS-NA/BGS-Server/Battle/BattleClient.cs @@ -46,7 +46,6 @@ namespace DiIiS_NA.LoginServer.Battle public readonly object ServiceLock = new(); public object MessageLock = new(); private ulong _listenerId; // last targeted rpc object. - public bool MotdSent { get; private set; } private ConcurrentDictionary MappedObjects { get; set; } public bool GuildChannelsRevealed = false; public string GameTeamTag = ""; @@ -139,9 +138,8 @@ namespace DiIiS_NA.LoginServer.Battle SocketConnection = socketChannel; Services = new Dictionary(); MappedObjects = new ConcurrentDictionary(); - MotdSent = false; if (SocketConnection.Active) - Logger.Trace("Client - {0} - successfully encrypted the connection", socketChannel.RemoteAddress); + Logger.Trace("Client - $[green]$ {0} $[/]$ - successfully encrypted the connection", socketChannel.RemoteAddress); } protected override void ChannelRead0(IChannelHandlerContext ctx, BNetPacket msg) @@ -263,16 +261,9 @@ namespace DiIiS_NA.LoginServer.Battle ListenerId = 0 }; #if DEBUG - if (method.Name == "KeepAlive") - { - Logger.Debug( - $"Call: $[olive]${service.GetType().Name}$[/]$, Service hash: $[olive]${header.ServiceHash}$[/]$, Method: $[olive]${method.Name}$[/]$, ID: $[olive]${header.MethodId}$[/]$"); - } - else - { - Logger.Trace( - $"Call: $[olive]${service.GetType().Name}$[/]$, Service hash: $[olive]${header.ServiceHash}$[/]$, Method: $[olive]${method.Name}$[/]$, ID: $[olive]${header.MethodId}$[/]$"); - } + Logger.Debug( + $"Call: $[underline white]${service.GetType().Name}$[/]$, Service hash: $[underline white]${header.ServiceHash}$[/]$, Method: $[underline white]${method.Name}$[/]$, ID: $[olive]${header.MethodId}$[/]$"); + #endif service.CallMethod(method, controller, message, @@ -281,7 +272,7 @@ namespace DiIiS_NA.LoginServer.Battle } catch (NotImplementedException) { - Logger.Warn("Unimplemented service method: {0}.{1}", service.GetType().Name, method.Name); + Logger.Warn("Unimplemented service method:$[red]$ {0}.{1} $[/]$", service.GetType().Name, method.Name); } } else @@ -391,7 +382,8 @@ namespace DiIiS_NA.LoginServer.Battle { if (SocketConnection == null || !SocketConnection.Active) return; var listenerId = GetRemoteObjectId(targetObject.DynamicId); - Logger.Debug("[RPC: {0}] Method: {1} Target: {2} [localId: {3}, remoteId: {4}].", GetType().Name, rpc.Method.Name, + Logger.Debug("[$[underline yellow]$RPC: {0}$[/]$] Method: $[underline white]${1}$[/]$ Target: $[underline white]${2}$[/]$ " + + "[localId: $[underline white]${3}$[/]$, remoteId: $[underline white]${4}$[/]$].", GetType().Name, rpc.Method.Name, targetObject.ToString(), targetObject.DynamicId, listenerId); rpc(listenerId); @@ -409,7 +401,7 @@ namespace DiIiS_NA.LoginServer.Battle try { if (SocketConnection == null || !SocketConnection.Active) return; - Logger.Debug("[RPC: {0}] Method: {1} Target: N/A", GetType().Name, rpc.Method.Name); + Logger.Debug("[$[underline yellow]$RPC: {0}$[/]$] Method: $[underline yellow]${1}$[/]$ Target: $[underline red]$N/A$[/]$", GetType().Name, rpc.Method.Name); rpc(0); } catch { } @@ -429,17 +421,17 @@ namespace DiIiS_NA.LoginServer.Battle if (!Services.ContainsKey(serviceHash)) { - Logger.Warn("Service not found for client {0} [0x{1}].", serviceName, serviceHash.ToString("X8")); + Logger.Warn("Service not found for client {0} [$[underline blue]$0x{1}$[/]$].", serviceName, serviceHash.ToString("X8")); // in english: "Service not found for client {0} [0x{1}]." return; } uint status = 0; - if (controller is HandlerController) + if (controller is HandlerController handlerController) { - status = ((HandlerController) controller).Status; - _listenerId = ((HandlerController) controller).ListenerId; + status = handlerController.Status; + _listenerId = handlerController.ListenerId; } var serviceId = Services[serviceHash]; @@ -514,13 +506,10 @@ namespace DiIiS_NA.LoginServer.Battle } public void SendMotd() { - if (MotdSent) + if (string.IsNullOrWhiteSpace(Config.Instance.Motd) || !Config.Instance.MotdEnabled) return; - - var motd = "Welcome to BlizzLess.Net Alpha-Build Server!"; - - SendServerWhisper(motd); - MotdSent = true; + Logger.Debug($"Motd sent to {Account.BattleTag}."); + SendServerWhisper(Config.Instance.Motd); } public override void ChannelInactive(IChannelHandlerContext context) diff --git a/src/DiIiS-NA/BGS-Server/ChannelSystem/ChannelInvitationManager.cs b/src/DiIiS-NA/BGS-Server/ChannelSystem/ChannelInvitationManager.cs index d521151..c6906a5 100644 --- a/src/DiIiS-NA/BGS-Server/ChannelSystem/ChannelInvitationManager.cs +++ b/src/DiIiS-NA/BGS-Server/ChannelSystem/ChannelInvitationManager.cs @@ -114,9 +114,9 @@ namespace DiIiS_NA.LoginServer.ChannelSystem #region - string GAME_SERVER_IP = Program.GAMESERVERIP; + string gameServerIp = Program.GameServerIp; if (GameServer.NATConfig.Instance.Enabled) - GAME_SERVER_IP = Program.PUBLICGAMESERVERIP; + gameServerIp = Program.PublicGameServerIp; uint GAME_SERVER_PORT = 2001; var member = bgs.protocol.account.v1.GameAccountHandle.CreateBuilder(); @@ -124,7 +124,7 @@ namespace DiIiS_NA.LoginServer.ChannelSystem var notification = bgs.protocol.matchmaking.v1.MatchmakingResultNotification.CreateBuilder(); var connectInfo = bgs.protocol.matchmaking.v1.ConnectInfo.CreateBuilder(); - connectInfo.SetAddress(Address.CreateBuilder().SetAddress_(GAME_SERVER_IP).SetPort(GAME_SERVER_PORT)); + connectInfo.SetAddress(Address.CreateBuilder().SetAddress_(gameServerIp).SetPort(GAME_SERVER_PORT)); connectInfo.AddAttribute(bgs.protocol.v2.Attribute.CreateBuilder().SetName("GameAccount").SetValue(bgs.protocol.v2.Variant.CreateBuilder().SetBlobValue(member.Build().ToByteString()))); connectInfo.AddAttribute(bgs.protocol.v2.Attribute.CreateBuilder().SetName("Token").SetValue(bgs.protocol.v2.Variant.CreateBuilder().SetUintValue(0xEEF4364684EE186E))); // FIXME //connectInfo.AddAttribute(AttributeOfServer); // Game settings diff --git a/src/DiIiS-NA/BGS-Server/Config.cs b/src/DiIiS-NA/BGS-Server/Config.cs index 6566c45..19d8a07 100644 --- a/src/DiIiS-NA/BGS-Server/Config.cs +++ b/src/DiIiS-NA/BGS-Server/Config.cs @@ -9,14 +9,60 @@ namespace DiIiS_NA.LoginServer { public sealed class Config : Core.Config.Config { - public bool Enabled { get { return this.GetBoolean("Enabled", true); } set { this.Set("Enabled", value); } } - public string BindIP { get { return this.GetString("BindIP", "127.0.0.1"); } set { this.Set("BindIP", value); } } - public int WebPort { get { return this.GetInt("WebPort", 9000); } set { this.Set("WebPort", value); } } - public int Port { get { return this.GetInt("Port", 1119); } set { this.Set("Port", value); } } - public string BindIPv6 { get { return this.GetString("BindIPv6", "::1"); } set { this.Set("BindIPv6", value); } } + public bool Enabled + { + get => GetBoolean(nameof(Enabled), true); + set => Set(nameof(Enabled), value); + } - private static readonly Config _instance = new Config(); - public static Config Instance { get { return _instance; } } - private Config() : base("Battle-Server") { } + public string BindIP + { + get => GetString(nameof(BindIP), "127.0.0.1"); + set => Set(nameof(BindIP), value); + } + + public int WebPort + { + get => GetInt(nameof(WebPort), 9000); + set => Set(nameof(WebPort), value); + } + + public int Port + { + get => GetInt(nameof(Port), 1119); + set => Set(nameof(Port), value); + } + + [Obsolete] + public string BindIPv6 + { + get => GetString(nameof(BindIPv6), "::1"); + set => Set(nameof(BindIPv6), value); + } + + /// + /// Whether Motd should be displayed on login. + /// + public bool MotdEnabled + { + get => GetBoolean(nameof(MotdEnabled), true); + set => Set(nameof(MotdEnabled), value); + } + + /// + /// Motd text + /// + public string Motd + { + get => GetString(nameof(Motd), + $"Welcome to Blizzless Server Build {Program.Build} - Stage: {Program.Stage} [{Program.TypeBuild}]!"); + set => Set(nameof(Motd), value); + } + + public static Config Instance => new(); + + private Config() : base("Battle-Server") + { + } } } diff --git a/src/DiIiS-NA/BGS-Server/ServicesSystem/Services/AuthenticationService.cs b/src/DiIiS-NA/BGS-Server/ServicesSystem/Services/AuthenticationService.cs index 9c485c9..556c540 100644 --- a/src/DiIiS-NA/BGS-Server/ServicesSystem/Services/AuthenticationService.cs +++ b/src/DiIiS-NA/BGS-Server/ServicesSystem/Services/AuthenticationService.cs @@ -119,10 +119,10 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services builder.SetPayloadType("web_auth_url"); if (REST.Config.Instance.Public) builder.SetPayload(ByteString.CopyFromUtf8( - $"http://{REST.Config.Instance.PublicIP}:{REST.Config.Instance.PORT}/battlenet/login")); + $"http://{REST.Config.Instance.PublicIP}:{REST.Config.Instance.Port}/battlenet/login")); else builder.SetPayload(ByteString.CopyFromUtf8( - $"http://{Program.RESTSERVERIP}:{REST.Config.Instance.PORT}/battlenet/login")); + $"http://{Program.RestServerIp}:{REST.Config.Instance.Port}/battlenet/login")); ((HandlerController)controller).Client.MakeRpc((lid) => ChallengeListener.CreateStub(((HandlerController)controller).Client).OnExternalChallenge(controller, builder.Build(), callback => { })); #endregion diff --git a/src/DiIiS-NA/BGS-Server/ServicesSystem/Services/GameRequestService.cs b/src/DiIiS-NA/BGS-Server/ServicesSystem/Services/GameRequestService.cs index e0edd97..9b0854f 100644 --- a/src/DiIiS-NA/BGS-Server/ServicesSystem/Services/GameRequestService.cs +++ b/src/DiIiS-NA/BGS-Server/ServicesSystem/Services/GameRequestService.cs @@ -84,9 +84,9 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services #endregion - string gameServerIp = Program.GAMESERVERIP; + string gameServerIp = Program.GameServerIp; if (GameServer.NATConfig.Instance.Enabled) - gameServerIp = Program.PUBLICGAMESERVERIP; + gameServerIp = Program.PublicGameServerIp; uint gameServerPort = 2001; MatchmakingResultNotification.Builder notification = MatchmakingResultNotification.CreateBuilder(); @@ -94,7 +94,7 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services connectInfo.SetAddress(Address.CreateBuilder().SetAddress_(gameServerIp).SetPort(gameServerPort)); connectInfo.AddAttribute(bgs.protocol.v2.Attribute.CreateBuilder().SetName("GameAccount").SetValue(bgs.protocol.v2.Variant.CreateBuilder().SetBlobValue(member.Build().ToByteString()))); connectInfo.AddAttribute(bgs.protocol.v2.Attribute.CreateBuilder().SetName("Token").SetValue(bgs.protocol.v2.Variant.CreateBuilder().SetUintValue(0xEEF4364684EE186E))); // FIXME - connectInfo.AddAttribute(attributeOfServer); // Настройки игры + connectInfo.AddAttribute(attributeOfServer); // GameCreateParams GameHandle.Builder gh = GameHandle.CreateBuilder(); gh.SetMatchmaker(MatchmakerHandle.CreateBuilder() diff --git a/src/DiIiS-NA/D3-GameServer/ClientSystem/GameServer.cs b/src/DiIiS-NA/D3-GameServer/ClientSystem/GameServer.cs index 1b957f0..e518b84 100644 --- a/src/DiIiS-NA/D3-GameServer/ClientSystem/GameServer.cs +++ b/src/DiIiS-NA/D3-GameServer/ClientSystem/GameServer.cs @@ -35,8 +35,8 @@ namespace DiIiS_NA.GameServer.ClientSystem { int Port = 2001; - if (!Listen(Program.GAMESERVERIP, Port)) return; - Logger.Info("Game Server Started - {0}:{1}...", Program.GAMESERVERIP, Port); + if (!Listen(Program.GameServerIp, Port)) return; + Logger.Info("Game Server Started - {0}:{1}...", Program.GameServerIp, Port); } } } diff --git a/src/DiIiS-NA/Program.cs b/src/DiIiS-NA/Program.cs index fb0e5c9..e6fc47e 100644 --- a/src/DiIiS-NA/Program.cs +++ b/src/DiIiS-NA/Program.cs @@ -46,7 +46,7 @@ namespace DiIiS_NA public static BattleBackend BattleBackend { get; set; } public bool GameServersAvailable = true; - public static int MaxLevel = 70; + public const int MaxLevel = 70; public static GameServer.ClientSystem.GameServer GameServer; public static Watchdog Watchdog; @@ -54,24 +54,24 @@ namespace DiIiS_NA public static Thread GameServerThread; public static Thread WatchdogThread; - public static string LOGINSERVERIP = DiIiS_NA.LoginServer.Config.Instance.BindIP; - public static string GAMESERVERIP = DiIiS_NA.GameServer.Config.Instance.BindIP; - public static string RESTSERVERIP = DiIiS_NA.REST.Config.Instance.IP; - public static string PUBLICGAMESERVERIP = DiIiS_NA.GameServer.NATConfig.Instance.PublicIP; + public static string LoginServerIp = DiIiS_NA.LoginServer.Config.Instance.BindIP; + public static string GameServerIp = DiIiS_NA.GameServer.Config.Instance.BindIP; + public static string RestServerIp = DiIiS_NA.REST.Config.Instance.IP; + public static string PublicGameServerIp = DiIiS_NA.GameServer.NATConfig.Instance.PublicIP; - public static int Build = 30; - private static readonly int Stage = 1; - private static readonly string TypeBuild = "BETA"; + public static int Build => 30; + public static int Stage => 1; + public static string TypeBuild => "BETA"; private static bool D3CoreEnabled = DiIiS_NA.GameServer.Config.Instance.CoreActive; - - + static async Task LoginServer() { + AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; + #if DEBUG D3CoreEnabled = true; #endif DbProviderFactories.RegisterFactory("Npgsql", NpgsqlFactory.Instance); - AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; string name = $"Blizzless: Build {Build}, Stage: {Stage} - {TypeBuild}"; @@ -192,13 +192,13 @@ namespace DiIiS_NA } var restSocketServer = new SocketManager(); - if (!restSocketServer.StartNetwork(RESTSERVERIP, REST.Config.Instance.PORT)) + if (!restSocketServer.StartNetwork(RestServerIp, REST.Config.Instance.Port)) { Logger.Fatal("REST socket server can't start."); Shutdown(); return; } - Logger.Success($"REST server started - {REST.Config.Instance.IP}:{REST.Config.Instance.PORT}"); + Logger.Success($"REST server started - {REST.Config.Instance.IP}:{REST.Config.Instance.Port}"); //BGS diff --git a/src/DiIiS-NA/REST/Http/Http.cs b/src/DiIiS-NA/REST/Http/Http.cs index ed04903..dc49d19 100644 --- a/src/DiIiS-NA/REST/Http/Http.cs +++ b/src/DiIiS-NA/REST/Http/Http.cs @@ -40,7 +40,7 @@ namespace DiIiS_NA.REST.Http { var sb = new StringBuilder(); - using (var sw = new StringWriter(sb)) + using (var sw = new StringWriter(sb)) { sw.WriteLine($"HTTP/1.1 {(int)httpCode} {httpCode}"); sw.WriteLine("Connection: close"); ; @@ -54,7 +54,7 @@ namespace DiIiS_NA.REST.Http { var sb = new StringBuilder(); - using (var sw = new StringWriter(sb)) + using (var sw = new StringWriter(sb)) { sw.WriteLine($"HTTP/1.1 {(int)httpCode} {httpCode}"); sw.WriteLine($"Content-Length: {content.Length}"); @@ -75,7 +75,7 @@ namespace DiIiS_NA.REST.Http var headerValues = new Dictionary(); var header = new HttpHeader(); - using (var sr = new StreamReader(new MemoryStream(data, 0, length))) + using (var sr = new StreamReader(new MemoryStream(data, 0, length))) { var info = sr.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); diff --git a/src/DiIiS-NA/REST/Manager/SessionManager.cs b/src/DiIiS-NA/REST/Manager/SessionManager.cs index 8e93bc6..4304ed0 100644 --- a/src/DiIiS-NA/REST/Manager/SessionManager.cs +++ b/src/DiIiS-NA/REST/Manager/SessionManager.cs @@ -14,7 +14,7 @@ namespace DiIiS_NA.REST.Manager public bool Initialize() { - int _port = Config.Instance.PORT; + int _port = Config.Instance.Port; if (_port < 0 || _port > 0xFFFF) { _port = 8081;