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.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Net.Security; using System.Net.Security;
using System.Threading.Tasks; using System.Threading.Tasks;
using DiIiS_NA.GameServer.MessageSystem.Message.Definitions.Text; using DiIiS_NA.GameServer.MessageSystem.Message.Definitions.Text;
@ -501,11 +503,42 @@ namespace DiIiS_NA.LoginServer.Battle
} }
public void SendMotd() public void SendMotd()
{ {
if (string.IsNullOrWhiteSpace(LoginServerConfig.Instance.Motd) || !LoginServerConfig.Instance.MotdEnabled) 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; 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}."); Logger.Debug($"Motd sent to {Account.BattleTag}.");
SendServerWhisper(LoginServerConfig.Instance.Motd); SendServerWhisper(LoginServerConfig.Instance.Motd);
} }
}
}
public override void ChannelInactive(IChannelHandlerContext context) public override void ChannelInactive(IChannelHandlerContext context)
{ {

View File

@ -48,6 +48,12 @@ namespace DiIiS_NA.LoginServer
set => Set(nameof(MotdEnabled), value); set => Set(nameof(MotdEnabled), value);
} }
public bool MotdEnabledWhenWorldLoads
{
get => GetBoolean(nameof(MotdEnabledWhenWorldLoads), false);
set => Set(nameof(MotdEnabledWhenWorldLoads), value);
}
/// <summary> /// <summary>
/// Motd text /// Motd text
/// </summary> /// </summary>
@ -58,6 +64,18 @@ namespace DiIiS_NA.LoginServer
set => Set(nameof(Motd), value); 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(); public static readonly LoginServerConfig Instance = new();
private LoginServerConfig() : base("Battle-Server") 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.Core.Types.SNO;
using DiIiS_NA.D3_GameServer.GSSystem.ActorSystem.Implementations.Artisans; using DiIiS_NA.D3_GameServer.GSSystem.ActorSystem.Implementations.Artisans;
using DiIiS_NA.D3_GameServer.GSSystem.PlayerSystem; using DiIiS_NA.D3_GameServer.GSSystem.PlayerSystem;
using DiIiS_NA.LoginServer;
using NHibernate.Util; using NHibernate.Util;
namespace DiIiS_NA.GameServer.GSSystem.PlayerSystem; namespace DiIiS_NA.GameServer.GSSystem.PlayerSystem;
@ -3607,7 +3608,7 @@ public class Player : Actor, IMessageConsumer, IUpdateable
if (!_motdSent && LoginServer.LoginServerConfig.Instance.MotdEnabled) if (!_motdSent && LoginServer.LoginServerConfig.Instance.MotdEnabled)
{ {
if (GameServerConfig.Instance.MotdWhenWorldLoads) if (!LoginServerConfig.Instance.MotdEnabledWhenWorldLoads)
_motdSent = true; _motdSent = true;
InGameClient.BnetClient.SendMotd(); InGameClient.BnetClient.SendMotd();
} }

View File

@ -66,15 +66,6 @@ namespace DiIiS_NA.GameServer
set => Set(nameof(AfkDisconnect), value); 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 #region Game Mods
/// <summary> /// <summary>
@ -327,6 +318,7 @@ namespace DiIiS_NA.GameServer
} }
#endregion #endregion
public static GameServerConfig Instance { get; } = new(); public static GameServerConfig Instance { get; } = new();
private GameServerConfig() : base("Game-Server") private GameServerConfig() : base("Game-Server")

View File

@ -1,69 +1,118 @@
; Settings for Bnet ; ==========
[Battle-Server] ; Configuration File Template
Enabled = true ; ==========
BindIP = 127.0.0.1 ; This is a template configuration file which can be modified as desired. The following branches are available for your convenience:
WebPort = 9800 ; - Community branch (recommended): https://github.com/blizzless/blizzless-diiis/tree/community
Port = 1119 ; - Test-stable branch: https://github.com/blizzless/blizzless-diiis/
BindIPv6 = ::1 ; - Master branch: https://github.com/blizzless/blizzless-diiis/tree/master
MotdEnabled = true
Motd = Welcome to Blizzless Diablo 3!
; ------------------------ ; 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]
; IWServer = false ; IWServer = false
; ------------------------ ; REST Service Settings for Login and Other Functions
; REST services for login (and others)
[REST] [REST]
IP = 127.0.0.1 IP = 127.0.0.1
Public = true
PublicIP = 127.0.0.1 PublicIP = 127.0.0.1
PORT = 80 PORT = 80
Public = true
; ------------------------ ; Game Server Settings
; Game server options and game-mods.
[Game-Server] [Game-Server]
; Enable or disable the game server
Enabled = true Enabled = true
; Activate game server core functionality
CoreActive = true CoreActive = true
; IP address on which the game server will be bound
BindIP = 127.0.0.1 BindIP = 127.0.0.1
; Port for web interactions
WebPort = 9001 WebPort = 9001
; Port for game server connections
Port = 1345 Port = 1345
; IP address for IPv6 bindings
BindIPv6 = ::1 BindIPv6 = ::1
; DRLG Emulation status
DRLGemu = true 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 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 ; Quality and identification chances for items
; Percentage that normal item created is unidentified ChanceHighQualityUnidentified = 30
ChanceNormalUnidentified = 5 ChanceNormalUnidentified = 5
; Amount of times user can resurrect at corpse
ResurrectionCharges = 5
BossHealthMultiplier = 2
BossDamageMultiplier = 1
AutoSaveQuests = true
; ------------------------ ; Boss health and damage multipliers
; Network address translation BossHealthMultiplier = 6
[NAT] BossDamageMultiplier = 3
Enabled = True
PublicIP = 127.0.0.1
; ------------------------ ; Nephalem Rift progress multiplier
; Where the outputs should be. NephalemRiftProgressMultiplier = 1
; Best for visualization (default): AnsiLog (target: Ansi)
; Best for debugging: ConsoleLog (target: console) ; Health potion mechanics
; Best for packet analysis: PacketLog (target: file) HealthPotionRestorePercentage = 60
; Logging level (ordered): HealthPotionCooldown = 30
; Rarely used: RenameAccountLog (0), ChatMessage (1), BotCommand (2), ResurrectionCharges = 3
; Useful: Debug (3), MethodTrace (4), Trace (5),
; Normal and human-readable: Info (6), Success (7), ; Waypoint settings
; Errors: Warn (8), Error (9), Fatal (10), UnlockAllWaypoints = false
; Network Logs: PacketDump (11)
; 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] [AnsiLog]
Enabled = true Enabled = true
@ -76,8 +125,8 @@ MaximumLevel = Fatal
Enabled = false Enabled = false
Target = Console Target = Console
IncludeTimeStamps = true IncludeTimeStamps = true
MinimumLevel = Debug MinimumLevel = MethodTrace
MaximumLevel = PacketDump MaximumLevel = Fatal
[PacketLog] [PacketLog]
Enabled = true Enabled = true