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

View File

@ -1,153 +1,88 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; blizzless Configuration File ;
; ;
;-----------------------------------------------------------------------------------------------------------------;
; ;
; This file is an example configuration and may require modification to suit your needs. ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Settings for Bnet
; Settings for Bnet
[Battle-Server]
Enabled = true
BindIP = 127.0.0.1
WebPort = 9800
Port = 1119
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]
IP = 127.0.0.1
Public = true
PublicIP = 127.0.0.1
PORT = 8081
PORT = 80
; Settings for game
; ------------------------
; Game server options and game-mods.
[Game-Server]
Enabled = true
CoreActive = true
BindIP = 127.0.0.1
WebPort = 9100
Port = 2001
WebPort = 9001
Port = 1345
BindIPv6 = ::1
DRLGemu = true
;Modding of game
; Modding of game
RateExp = 1
RateMoney = 1
RateDrop = 1
RateChangeDrop = 1
RateMonsterHP = 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 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).
; ------------------------
; Network address translation
[NAT]
Enabled = false
PublicIP = 101.185.137.121 ; You need to change this to your router's public interface IP if you'd like to use NAT.
Enabled = True
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
[Logging]
Root=logs
[AnsiLog]
Enabled = true
Target = Ansi
IncludeTimeStamps = true
MinimumLevel = MethodTrace
MaximumLevel = Fatal
; Settings for console logger
[ConsoleLog]
Enabled=true
Target=Console
IncludeTimeStamps=true
MinimumLevel=Trace
MaximumLevel=Fatal
Enabled = false
Target = Console
IncludeTimeStamps = true
MinimumLevel = Debug
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]
Enabled=true
Target=File
FileName="packet-dump.log"
IncludeTimeStamps=true
MinimumLevel=PacketDump
MaximumLevel=PacketDump
ResetOnStartup=true
Enabled = true
Target = file
FileName = packet.log
IncludeTimeStamps = true
MinimumLevel = Debug
MaximumLevel = PacketDump