Created remote motd and updated base config.ini

Changed Motd settings locations to `LoginServerConfig.cs`
 - `MotdEnabledWhenWorldLoads`: if true, motd will be displayed whenever a player enters another world.
  - `MotdEnabledRemote`: if true, a POST will be sent to `MotdRemoteUrl` with the body `{ "GameAccountId": ulong, "ToonName": string, "WorldGlobalId": uint }`
   - `MotdRemoteUrl`: the callback URL to POST.
This commit is contained in:
Lucca Faria Ferri 2023-06-18 20:53:56 -07:00
parent 37932bd09b
commit d49282653d
5 changed files with 150 additions and 57 deletions

View File

@ -16,6 +16,8 @@ using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Net.Security;
using System.Threading.Tasks;
using DiIiS_NA.GameServer.MessageSystem.Message.Definitions.Text;
@ -501,10 +503,41 @@ namespace DiIiS_NA.LoginServer.Battle
}
public void SendMotd()
{
if (string.IsNullOrWhiteSpace(LoginServerConfig.Instance.Motd) || !LoginServerConfig.Instance.MotdEnabled)
return;
Logger.Debug($"Motd sent to {Account.BattleTag}.");
SendServerWhisper(LoginServerConfig.Instance.Motd);
if (LoginServerConfig.Instance.MotdEnabled)
{
if (LoginServerConfig.Instance.MotdEnabledRemote)
{
if (string.IsNullOrWhiteSpace(LoginServerConfig.Instance.MotdRemoteUrl))
{
Logger.Warn("No Motd remote URL defined, falling back to normal motd.");
}
else
{
var url = LoginServerConfig.Instance.MotdRemoteUrl.Trim();
HttpClient client = new();
var post = client.PostAsJsonAsync(url, new
{
GameAccountId = InGameClient.Player?.Toon?.GameAccountId ?? 0,
ToonName = InGameClient.Player?.Toon?.Name ?? string.Empty,
WorldGlobalId = InGameClient.Player?.World?.GlobalID ?? 0
}).Result;
if (post.IsSuccessStatusCode)
{
var text = post.Content.ReadAsStringAsync().Result;
SendServerWhisper(text);
Logger.Info("Remote Motd sent successfully.");
return;
}
Logger.Warn("Could not POST to $[red]$" + url + "$[/]$. Please ensure the URL is correct. Falling back to normal MotD if available.");
}
}
if (!string.IsNullOrWhiteSpace(LoginServerConfig.Instance.Motd))
{
Logger.Debug($"Motd sent to {Account.BattleTag}.");
SendServerWhisper(LoginServerConfig.Instance.Motd);
}
}
}
public override void ChannelInactive(IChannelHandlerContext context)

View File

@ -47,6 +47,12 @@ namespace DiIiS_NA.LoginServer
get => GetBoolean(nameof(MotdEnabled), true);
set => Set(nameof(MotdEnabled), value);
}
public bool MotdEnabledWhenWorldLoads
{
get => GetBoolean(nameof(MotdEnabledWhenWorldLoads), false);
set => Set(nameof(MotdEnabledWhenWorldLoads), value);
}
/// <summary>
/// Motd text
@ -58,6 +64,18 @@ namespace DiIiS_NA.LoginServer
set => Set(nameof(Motd), value);
}
public bool MotdEnabledRemote
{
get => GetBoolean(nameof(MotdEnabledRemote), false);
set => Set(nameof(MotdEnabledRemote), value);
}
public string MotdRemoteUrl
{
get => GetString(nameof(MotdRemoteUrl), "");
set => Set(nameof(MotdRemoteUrl), value);
}
public static readonly LoginServerConfig Instance = new();
private LoginServerConfig() : base("Battle-Server")

View File

@ -60,6 +60,7 @@ using DiIiS_NA.GameServer.MessageSystem.Message.Definitions.Encounter;
using DiIiS_NA.D3_GameServer.Core.Types.SNO;
using DiIiS_NA.D3_GameServer.GSSystem.ActorSystem.Implementations.Artisans;
using DiIiS_NA.D3_GameServer.GSSystem.PlayerSystem;
using DiIiS_NA.LoginServer;
using NHibernate.Util;
namespace DiIiS_NA.GameServer.GSSystem.PlayerSystem;
@ -3607,7 +3608,7 @@ public class Player : Actor, IMessageConsumer, IUpdateable
if (!_motdSent && LoginServer.LoginServerConfig.Instance.MotdEnabled)
{
if (GameServerConfig.Instance.MotdWhenWorldLoads)
if (!LoginServerConfig.Instance.MotdEnabledWhenWorldLoads)
_motdSent = true;
InGameClient.BnetClient.SendMotd();
}

View File

@ -65,16 +65,7 @@ namespace DiIiS_NA.GameServer
#endif
set => Set(nameof(AfkDisconnect), value);
}
/// <summary>
/// Always send motd when world loads for player.
/// </summary>
public bool MotdWhenWorldLoads
{
get => GetBoolean(nameof(MotdWhenWorldLoads), true);
set => Set(nameof(MotdWhenWorldLoads), value);
}
#region Game Mods
/// <summary>
@ -327,6 +318,7 @@ namespace DiIiS_NA.GameServer
}
#endregion
public static GameServerConfig Instance { get; } = new();
private GameServerConfig() : base("Game-Server")

View File

@ -1,69 +1,118 @@
; Settings for Bnet
[Battle-Server]
Enabled = true
BindIP = 127.0.0.1
WebPort = 9800
Port = 1119
BindIPv6 = ::1
MotdEnabled = true
Motd = Welcome to Blizzless Diablo 3!
; ==========
; Configuration File Template
; ==========
; This is a template configuration file which can be modified as desired. The following branches are available for your convenience:
; - Community branch (recommended): https://github.com/blizzless/blizzless-diiis/tree/community
; - Test-stable branch: https://github.com/blizzless/blizzless-diiis/
; - Master branch: https://github.com/blizzless/blizzless-diiis/tree/master
; ------------------------
; Battle Server Settings
[Battle-Server]
; Enable or disable the Battle Server
Enabled = true
; IP address on which the server will be bound
BindIP = 127.0.0.1
; Port for web interactions
WebPort = 9800
; Port for the server
Port = 1119
; Message of the Day (MotD) Settings
; - MotdEnabled: Toggles whether the Message of The Day (MotD) is enabled or not
; - MotdEnabledWhenWorldLoads: Determines if MotD should be displayed every time a new world is loaded for a player
; - Motd: Text displayed as the MotD
MotdEnabled = true
MotdEnabledWhenWorldLoads = false
Motd = Welcome to Blizzless D3!
; - Remote MotD Enabled: Enable receiving MotD from a remote URL via POST request with payload: { "GameAccountId": ulong, "ToonName": string, "WorldGlobalId": uint }
; - MotdRemoteUrl: Remote URL to send payload and receive string; falls back to Motd string if unavailable
MotdEnabledRemote = false
MotdRemoteUrl = https://your-site.local/yourmotd
; IWServer Setting (Currently inactive)
; [IWServer]
; IWServer = false
; ------------------------
; REST services for login (and others)
; REST Service Settings for Login and Other Functions
[REST]
IP = 127.0.0.1
Public = true
PublicIP = 127.0.0.1
PORT = 80
Public = true
; ------------------------
; Game server options and game-mods.
; Game Server Settings
[Game-Server]
; Enable or disable the game server
Enabled = true
; Activate game server core functionality
CoreActive = true
; IP address on which the game server will be bound
BindIP = 127.0.0.1
; Port for web interactions
WebPort = 9001
; Port for game server connections
Port = 1345
; IP address for IPv6 bindings
BindIPv6 = ::1
; DRLG Emulation status
DRLGemu = true
; Modding of game
; NAT (Network Address Translation) Settings
[NAT]
; Toggles the NAT functionality
Enabled = True
; Your public IP address to enable NAT
PublicIP = 127.0.0.1
; ==========
; Game Modding Configuration
; For documentation, please check https://github.com/blizzless/blizzless-diiis/blob/community/docs/game-world-settings.md
; Multipliers for various gameplay rates
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
; Quality and identification chances for items
ChanceHighQualityUnidentified = 30
ChanceNormalUnidentified = 5
; Amount of times user can resurrect at corpse
ResurrectionCharges = 5
BossHealthMultiplier = 2
BossDamageMultiplier = 1
AutoSaveQuests = true
; ------------------------
; Network address translation
[NAT]
Enabled = True
PublicIP = 127.0.0.1
; Boss health and damage multipliers
BossHealthMultiplier = 6
BossDamageMultiplier = 3
; ------------------------
; 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)
; Nephalem Rift progress multiplier
NephalemRiftProgressMultiplier = 1
; Health potion mechanics
HealthPotionRestorePercentage = 60
HealthPotionCooldown = 30
ResurrectionCharges = 3
; Waypoint settings
UnlockAllWaypoints = false
; Player attribute modifiers
StrengthMultiplier = 1
StrengthParagonMultiplier = 1
DexterityMultiplier = 1
DexterityParagonMultiplier = 1
IntelligenceMultiplier = 1
IntelligenceParagonMultiplier = 1
VitalityMultiplier = 1
VitalityParagonMultiplier = 1
; Quest saving behavior
AutoSaveQuests = false
; Minimap visibility settings
ForceMinimapVisibility = false
; ===================
; Log Output Settings
; AnsiLog for visualization, ConsoleLog for debugging, and PacketLog for packet analysis
[AnsiLog]
Enabled = true
@ -76,8 +125,8 @@ MaximumLevel = Fatal
Enabled = false
Target = Console
IncludeTimeStamps = true
MinimumLevel = Debug
MaximumLevel = PacketDump
MinimumLevel = MethodTrace
MaximumLevel = Fatal
[PacketLog]
Enabled = true