Updated default config, and shutdown

This commit is contained in:
Lucca Faria Ferri 2023-02-02 05:18:27 -08:00
parent 591c2845ac
commit 282b990ae4
2 changed files with 118 additions and 169 deletions

View File

@ -39,7 +39,13 @@ using Environment = System.Environment;
namespace DiIiS_NA namespace DiIiS_NA
{ {
public enum TypeBuildEnum
{
Alpha,
Beta,
Test,
Release
}
class Program class Program
{ {
private static readonly Logger Logger = LogManager.CreateLogger("BZ.Net"); private static readonly Logger Logger = LogManager.CreateLogger("BZ.Net");
@ -57,21 +63,18 @@ namespace DiIiS_NA
public static string LoginServerIp = DiIiS_NA.LoginServer.Config.Instance.BindIP; public static string LoginServerIp = DiIiS_NA.LoginServer.Config.Instance.BindIP;
public static string GameServerIp = DiIiS_NA.GameServer.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 RestServerIp = REST.Config.Instance.IP;
public static string PublicGameServerIp = DiIiS_NA.GameServer.NATConfig.Instance.PublicIP; public static string PublicGameServerIp = DiIiS_NA.GameServer.NATConfig.Instance.PublicIP;
public static int Build => 30; public static int Build => 30;
public static int Stage => 1; public static int Stage => 1;
public static string TypeBuild => "BETA"; public static TypeBuildEnum TypeBuild => TypeBuildEnum.Beta;
private static bool D3CoreEnabled = DiIiS_NA.GameServer.Config.Instance.CoreActive; private static bool DiabloCoreEnabled = DiIiS_NA.GameServer.Config.Instance.CoreActive;
static async Task LoginServer() static async Task LoginServer()
{ {
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
#if DEBUG
D3CoreEnabled = true;
#endif
DbProviderFactories.RegisterFactory("Npgsql", NpgsqlFactory.Instance); DbProviderFactories.RegisterFactory("Npgsql", NpgsqlFactory.Instance);
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
@ -89,6 +92,10 @@ namespace DiIiS_NA
Console.Title = name; Console.Title = name;
InitLoggers(); InitLoggers();
#if DEBUG
DiabloCoreEnabled = true;
Logger.Warn("Diablo III Core forced enable on $[underline white on olive]$ DEBUG $[/]$");
#endif
#pragma warning disable CS4014 #pragma warning disable CS4014
Task.Run(async () => Task.Run(async () =>
@ -121,6 +128,7 @@ namespace DiIiS_NA
} }
catch (Exception e) catch (Exception e)
{ {
await Task.Delay(TimeSpan.FromMinutes(5));
} }
} }
}); });
@ -163,7 +171,7 @@ namespace DiIiS_NA
if (DBSessions.SessionQuery<DBAccount>().Any()) if (DBSessions.SessionQuery<DBAccount>().Any())
{ {
Logger.Success("Connection with database established."); Logger.Success("Database connection has been $[underline bold italic]$successfully established$[/]$.");
} }
//*/ //*/
StartWatchdog(); StartWatchdog();
@ -174,13 +182,11 @@ namespace DiIiS_NA
GuildManager.PreLoadGuilds(); GuildManager.PreLoadGuilds();
Logger.Info("Loading Diablo III - Core..."); Logger.Info("Loading Diablo III - Core...");
if (D3CoreEnabled) if (DiabloCoreEnabled)
{ {
if (!MPQStorage.Initialized) if (!MPQStorage.Initialized)
{ {
Logger.Fatal("MPQ archives not found..."); throw new Exception("MPQ archives not found...");
Shutdown();
return;
} }
Logger.Info("Loaded - {0} items.", ItemGenerator.TotalItems); Logger.Info("Loaded - {0} items.", ItemGenerator.TotalItems);
Logger.Info("Diablo III Core - Loaded"); Logger.Info("Diablo III Core - Loaded");
@ -188,44 +194,42 @@ namespace DiIiS_NA
else else
{ {
Logger.Fatal("Diablo III Core - Disabled"); Logger.Fatal("Diablo III Core - Disabled");
Shutdown(); throw new Exception("Diablo III Core - Disabled");
return;
} }
var restSocketServer = new SocketManager<RestSession>(); var restSocketServer = new SocketManager<RestSession>();
if (!restSocketServer.StartNetwork(RestServerIp, REST.Config.Instance.Port)) if (!restSocketServer.StartNetwork(RestServerIp, REST.Config.Instance.Port))
{ {
Logger.Fatal("REST socket server can't start."); throw new Exception("Diablo III Core - Disabled");
Shutdown();
return;
} }
Logger.Success($"REST server started - {REST.Config.Instance.IP}:{REST.Config.Instance.Port}"); Logger.Success($"$[underline darkgreen]$REST$[/]$ server started - {REST.Config.Instance.IP}:{REST.Config.Instance.Port}");
//BGS //BGS
ServerBootstrap b = new ServerBootstrap(); var loginConfig = DiIiS_NA.LoginServer.Config.Instance;
IEventLoopGroup boss = new MultithreadEventLoopGroup(1); ServerBootstrap serverBootstrap = new ServerBootstrap();
IEventLoopGroup worker = new MultithreadEventLoopGroup(); IEventLoopGroup boss = new MultithreadEventLoopGroup(1),
b.LocalAddress(DiIiS_NA.LoginServer.Config.Instance.BindIP, DiIiS_NA.LoginServer.Config.Instance.Port); worker = new MultithreadEventLoopGroup();
Logger.Info( serverBootstrap.LocalAddress(loginConfig.BindIP, loginConfig.Port);
$"Blizzless server started - {DiIiS_NA.LoginServer.Config.Instance.BindIP}:{DiIiS_NA.LoginServer.Config.Instance.Port}"); Logger.Success(
BattleBackend = new BattleBackend(DiIiS_NA.LoginServer.Config.Instance.BindIP, DiIiS_NA.LoginServer.Config.Instance.WebPort); $"Blizzless server $[underline]$started$[/]$ - $[lightseagreen]${loginConfig.BindIP}:{loginConfig.Port}$[/]$");
BattleBackend = new BattleBackend(loginConfig.BindIP, loginConfig.WebPort);
//Diablo 3 Game-Server //Diablo 3 Game-Server
if (D3CoreEnabled) if (DiabloCoreEnabled)
StartGS(); StartGameServer();
try try
{ {
b.Group(boss, worker) serverBootstrap.Group(boss, worker)
.Channel<TcpServerSocketChannel>() .Channel<TcpServerSocketChannel>()
.Handler(new LoggingHandler(LogLevel.DEBUG)) .Handler(new LoggingHandler(LogLevel.DEBUG))
.ChildHandler(new ConnectHandler()); .ChildHandler(new ConnectHandler());
IChannel boundChannel = await b.BindAsync(DiIiS_NA.LoginServer.Config.Instance.Port); IChannel boundChannel = await serverBootstrap.BindAsync(loginConfig.Port);
Logger.Info("$[bold red3_1]$Tip:$[/]$ graceful shutdown with $[red3_1]$CTRL+C$[/]$ or $[red3_1]$!q[uit]$[/]$ or $[red3_1]$!exit$[/]$."); Logger.Info("$[bold red3_1]$Tip:$[/]$ graceful shutdown with $[red3_1]$CTRL+C$[/]$ or $[red3_1]$!q[uit]$[/]$ or $[red3_1]$!exit$[/]$.");
Logger.Info("$[bold red3_1]$Tip:$[/]$ SNO breakdown with $[red3_1]$!sno$[/]$ $[red]$<fullSnoBreakdown(true:false)>$[/]$."); Logger.Info("$[bold red3_1]$" +
"Tip:$[/]$ SNO breakdown with $[red3_1]$!sno$[/]$ $[red3_1]$<fullSnoBreakdown(true:false)>$[/]$.");
while (true) while (true)
{ {
var line = Console.ReadLine(); var line = Console.ReadLine();
@ -233,7 +237,8 @@ namespace DiIiS_NA
break; break;
if (line is "!cls" or "!clear" or "cls" or "clear") if (line is "!cls" or "!clear" or "cls" or "clear")
{ {
Console.Clear(); AnsiConsole.Clear();
AnsiConsole.Cursor.SetPosition(0, 0);
continue; continue;
} }
if (line.ToLower().StartsWith("!sno")) if (line.ToLower().StartsWith("!sno"))
@ -257,7 +262,7 @@ namespace DiIiS_NA
} }
catch (Exception e) catch (Exception e)
{ {
Logger.Info(e.Message); Shutdown(e, delay: 200);
} }
finally finally
{ {
@ -267,10 +272,16 @@ namespace DiIiS_NA
} }
} }
public static void Shutdown(int delay = 50) private static void Shutdown(Exception? exception = null, int delay = 200)
{ {
if (!IsTargetEnabled("ansi")) // if (!IsTargetEnabled("ansi"))
{ {
AnsiTarget.StopIfRunning();
if (exception is { } ex)
{
AnsiConsole.WriteLine("An unhandled exception occured at initialization. Please report this to the developers.");
AnsiConsole.WriteException(ex);
}
AnsiConsole.Progress().Start(ctx => AnsiConsole.Progress().Start(ctx =>
{ {
var task = ctx.AddTask("[red]Shutting down...[/]"); var task = ctx.AddTask("[red]Shutting down...[/]");
@ -286,9 +297,16 @@ namespace DiIiS_NA
[HandleProcessCorruptedStateExceptions] [HandleProcessCorruptedStateExceptions]
[SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)] [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)]
static void Main() static async Task Main()
{ {
LoginServer().Wait(); try
{
await LoginServer();
}
catch (Exception ex)
{
Shutdown(ex);
}
} }
[SecurityCritical] [SecurityCritical]
@ -299,9 +317,7 @@ namespace DiIiS_NA
if (e.IsTerminating) if (e.IsTerminating)
{ {
Logger.Error(ex.StackTrace); Shutdown(ex);
Logger.FatalException(ex, "A root error of the server was detected, disconnection.");
Shutdown();
} }
else else
Logger.ErrorException(ex, "A root error of the server was detected but was handled."); Logger.ErrorException(ex, "A root error of the server was detected but was handled.");
@ -353,21 +369,20 @@ namespace DiIiS_NA
LogManager.AttachLogTarget(target); LogManager.AttachLogTarget(target);
} }
} }
public static bool StartWatchdog() public static void StartWatchdog()
{ {
Watchdog = new Watchdog(); Watchdog = new Watchdog();
WatchdogThread = new Thread(Watchdog.Run) { Name = "Watchdog", IsBackground = true }; WatchdogThread = new Thread(Watchdog.Run) { Name = "Watchdog", IsBackground = true };
WatchdogThread.Start(); WatchdogThread.Start();
return true;
} }
public static bool StartGS() public static void StartGameServer()
{ {
if (GameServer != null) return false; if (GameServer != null) return;
GameServer = new DiIiS_NA.GameServer.ClientSystem.GameServer(); GameServer = new DiIiS_NA.GameServer.ClientSystem.GameServer();
GameServerThread = new Thread(GameServer.Run) { Name = "GameServerThread", IsBackground = true }; GameServerThread = new Thread(GameServer.Run) { Name = "GameServerThread", IsBackground = true };
GameServerThread.Start(); GameServerThread.Start();
if (DiIiS_NA.Core.Discord.Config.Instance.Enabled) if (Core.Discord.Config.Instance.Enabled)
{ {
Logger.Info("Starting Discord bot handler.."); Logger.Info("Starting Discord bot handler..");
GameServer.DiscordBot = new Core.Discord.Bot(); GameServer.DiscordBot = new Core.Discord.Bot();
@ -379,7 +394,6 @@ namespace DiIiS_NA
} }
DiIiS_NA.GameServer.GSSystem.GeneratorsSystem.SpawnGenerator.RegenerateDensity(); DiIiS_NA.GameServer.GSSystem.GeneratorsSystem.SpawnGenerator.RegenerateDensity();
DiIiS_NA.GameServer.ClientSystem.GameServer.GSBackend = new GsBackend(DiIiS_NA.LoginServer.Config.Instance.BindIP, DiIiS_NA.LoginServer.Config.Instance.WebPort); DiIiS_NA.GameServer.ClientSystem.GameServer.GSBackend = new GsBackend(DiIiS_NA.LoginServer.Config.Instance.BindIP, DiIiS_NA.LoginServer.Config.Instance.WebPort);
return true;
} }
static bool SetTitle(string text) static bool SetTitle(string text)

View File

@ -1,153 +1,88 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Settings for Bnet
; ;
; blizzless Configuration File ;
; ;
;-----------------------------------------------------------------------------------------------------------------;
; ;
; This file is an example configuration and may require modification to suit your needs. ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Settings for Bnet
[Battle-Server] [Battle-Server]
Enabled = true Enabled = true
BindIP = 127.0.0.1 BindIP = 127.0.0.1
WebPort = 9800 WebPort = 9800
Port = 1119 Port = 1119
BindIPv6 = ::1 BindIPv6 = ::1
MOTD = Welcome to Diablo 3! MotdEnabled = true
Motd = Welcome to Blizzless Diablo 3!
[IWServer] ; ------------------------
IWServer = false ; [IWServer]
; IWServer = false
; Settings for REST ; ------------------------
; REST services for login (and others)
[REST] [REST]
IP = 127.0.0.1 IP = 127.0.0.1
Public = true Public = true
PublicIP = 127.0.0.1 PublicIP = 127.0.0.1
PORT = 8081 PORT = 80
; Settings for game ; ------------------------
; Game server options and game-mods.
[Game-Server] [Game-Server]
Enabled = true Enabled = true
CoreActive = true CoreActive = true
BindIP = 127.0.0.1 BindIP = 127.0.0.1
WebPort = 9100 WebPort = 9001
Port = 2001 Port = 1345
BindIPv6 = ::1 BindIPv6 = ::1
DRLGemu = true DRLGemu = true
;Modding of game ; Modding of game
RateExp = 1 RateExp = 1
RateMoney = 1 RateMoney = 1
RateDrop = 1 RateDrop = 1
RateChangeDrop = 1 RateChangeDrop = 1
RateMonsterHP = 1 RateMonsterHP = 1
RateMonsterDMG = 1 RateMonsterDMG = 1
; Percentage that a unique, legendary, set or special item created is unidentified
ChanceHighQualityUnidentified = 80
; Percentage that normal item created is unidentified
ChanceNormalUnidentified = 5
; Amount of times user can resurrect at corpse
ResurrectionCharges = 5
BossHealthMultiplier = 2
BossDamageMultiplier = 1
AutoSaveQuests = true
; ------------------------
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Network address translation
; Authentication settings
[Authentication]
DisablePasswordChecks=true
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Discord bot settings
[Discord]
Enabled=true
MonitorEnabled=false
Token=sectret token
GuildId=0
AnnounceChannelId=0
StatsChannelId=0
EventsChannelId=0
BaseRoleId=0
PremiumRoleId=0
CollectorRoleId=0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; You can set here the command-prefix. Note: You can't use slash as a prefix.
[Commands]
CommandPrefix = !
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Networking settings.
[Networking]
EnableIPv6 = false ; experimental!!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Network address translation settings.
; You only need to change this if you're running behind a dsl router or so.
; Important: If you enable NAT, LAN-clients will not able to connect in gs.
; (Will be fixed later with a proper implementation similar to one in pvpgn).
[NAT] [NAT]
Enabled = false Enabled = True
PublicIP = 101.185.137.121 ; You need to change this to your router's public interface IP if you'd like to use NAT. PublicIP = 127.0.0.1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ------------------------
; Where the outputs should be.
; Best for visualization (default): AnsiLog (target: Ansi)
; Best for debugging: ConsoleLog (target: console)
; Best for packet analysis: PacketLog (target: file)
; Logging level (ordered):
; Rarely used: RenameAccountLog (0), ChatMessage (1), BotCommand (2),
; Useful: Debug (3), MethodTrace (4), Trace (5),
; Normal and human-readable: Info (6), Success (7),
; Errors: Warn (8), Error (9), Fatal (10),
; Network Logs: PacketDump (11)
; General logging settings [AnsiLog]
[Logging] Enabled = true
Root=logs Target = Ansi
IncludeTimeStamps = true
MinimumLevel = MethodTrace
MaximumLevel = Fatal
; Settings for console logger
[ConsoleLog] [ConsoleLog]
Enabled=true Enabled = false
Target=Console Target = Console
IncludeTimeStamps=true IncludeTimeStamps = true
MinimumLevel=Trace MinimumLevel = Debug
MaximumLevel=Fatal MaximumLevel = PacketDump
; Settings for server log file.
[ServerLog]
Enabled=true
Target=File
FileName="blizzless.log"
IncludeTimeStamps=true
MinimumLevel=Trace
MaximumLevel=Fatal
ResetOnStartup=true
; Settings for chat log file.
[ChatLog]
Enabled=true
Target=File
FileName="blizzless-chat.log"
IncludeTimeStamps=true
MinimumLevel=ChatMessage
MaximumLevel=ChatMessage
ResetOnStartup=true
; Settings for discord log file.
[DiscordLog]
Enabled=false
Target=File
FileName="discord-bot.log"
IncludeTimeStamps=true
MinimumLevel=BotCommand
MaximumLevel=BotCommand
ResetOnStartup=true
; Settings for renames log file.
[RenameAccountLog]
Enabled=true
Target=File
FileName="blizzless-btag-rename.log"
IncludeTimeStamps=true
MinimumLevel=RenameAccountLog
MaximumLevel=RenameAccountLog
ResetOnStartup=true
; Settings for packet logger, only recommended for developers!
[PacketLog] [PacketLog]
Enabled=true Enabled = true
Target=File Target = file
FileName="packet-dump.log" FileName = packet.log
IncludeTimeStamps=true IncludeTimeStamps = true
MinimumLevel=PacketDump MinimumLevel = Debug
MaximumLevel=PacketDump MaximumLevel = PacketDump
ResetOnStartup=true