From 29a08f20d594908ba3139be8159e9066736ceff7 Mon Sep 17 00:00:00 2001 From: Richard Leek Date: Sat, 15 Jun 2024 21:18:54 +0000 Subject: [PATCH] Reboot handler (#362) Add Message_Close handler, reboot event notifier, and reboot sound effect id --- .../Domain/Notifiers/IServerRebootNotifier.cs | 15 +++++++ .../Message/MessageCloseHandler.cs | 39 +++++++++++++++++++ EndlessClient/Audio/SoundEffectID.cs | 1 + .../ServerRebootEventSubscriber.cs | 34 ++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 EOLib/Domain/Notifiers/IServerRebootNotifier.cs create mode 100644 EOLib/PacketHandlers/Message/MessageCloseHandler.cs create mode 100644 EndlessClient/Subscribers/ServerRebootEventSubscriber.cs diff --git a/EOLib/Domain/Notifiers/IServerRebootNotifier.cs b/EOLib/Domain/Notifiers/IServerRebootNotifier.cs new file mode 100644 index 000000000..51fe93f7c --- /dev/null +++ b/EOLib/Domain/Notifiers/IServerRebootNotifier.cs @@ -0,0 +1,15 @@ +using AutomaticTypeMapper; + +namespace EOLib.Domain.Notifiers +{ + public interface IServerRebootNotifier + { + void NotifyServerReboot(); + } + + [AutoMappedType] + public class NoOpServerRebootNotifier : IServerRebootNotifier + { + public void NotifyServerReboot() { } + } +} diff --git a/EOLib/PacketHandlers/Message/MessageCloseHandler.cs b/EOLib/PacketHandlers/Message/MessageCloseHandler.cs new file mode 100644 index 000000000..203c66633 --- /dev/null +++ b/EOLib/PacketHandlers/Message/MessageCloseHandler.cs @@ -0,0 +1,39 @@ +using AutomaticTypeMapper; +using EOLib.Domain.Login; +using EOLib.Domain.Notifiers; +using EOLib.Net.Handlers; +using Moffat.EndlessOnline.SDK.Protocol.Net; +using Moffat.EndlessOnline.SDK.Protocol.Net.Server; +using System.Collections.Generic; + +namespace EOLib.PacketHandlers.Message +{ + /// + /// Shows the server reboot message + /// + [AutoMappedType] + public class MessageCloseHandler : InGameOnlyPacketHandler + { + private readonly IEnumerable _serverRebootNotifiers; + + public override PacketFamily Family => PacketFamily.Message; + + public override PacketAction Action => PacketAction.Close; + + public MessageCloseHandler(IPlayerInfoProvider playerInfoProvider, + IEnumerable serverRebootNotifiers) + : base(playerInfoProvider) + { + _serverRebootNotifiers = serverRebootNotifiers; + } + + + public override bool HandlePacket(MessageCloseServerPacket packet) + { + foreach (var notifier in _serverRebootNotifiers) + notifier.NotifyServerReboot(); + + return true; + } + } +} diff --git a/EndlessClient/Audio/SoundEffectID.cs b/EndlessClient/Audio/SoundEffectID.cs index c0275e276..e115d387f 100644 --- a/EndlessClient/Audio/SoundEffectID.cs +++ b/EndlessClient/Audio/SoundEffectID.cs @@ -19,6 +19,7 @@ public enum SoundEffectID DeleteCharacter, MapMutation = DeleteCharacter, Banned, + Reboot = Banned, ScreenCapture = 8, PrivateMessageReceived, PunchAttack, diff --git a/EndlessClient/Subscribers/ServerRebootEventSubscriber.cs b/EndlessClient/Subscribers/ServerRebootEventSubscriber.cs new file mode 100644 index 000000000..6f0e3b946 --- /dev/null +++ b/EndlessClient/Subscribers/ServerRebootEventSubscriber.cs @@ -0,0 +1,34 @@ +using AutomaticTypeMapper; +using EndlessClient.Audio; +using EndlessClient.HUD; +using EndlessClient.HUD.Chat; +using EOLib.Domain.Notifiers; +using EOLib.Localization; + +namespace EndlessClient.Subscribers +{ + [AutoMappedType] + public class ServerRebootEventNotifier : IServerRebootNotifier + { + private readonly ILocalizedStringFinder _localizedStringFinder; + private readonly IServerMessageHandler _serverMessageHandler; + private readonly IStatusLabelSetter _statusLabelSetter; + + public ServerRebootEventNotifier(ILocalizedStringFinder localizedStringFinder, + IServerMessageHandler serverMessageHandler, + IStatusLabelSetter statusLabelSetter, + ISfxPlayer sfxPlayer) + { + _localizedStringFinder = localizedStringFinder; + _serverMessageHandler = serverMessageHandler; + _statusLabelSetter = statusLabelSetter; + } + + public void NotifyServerReboot() + { + var message = _localizedStringFinder.GetString(EOResourceID.REBOOT_SEQUENCE_STARTED); + _serverMessageHandler.AddServerMessage(message, SoundEffectID.Reboot); + _statusLabelSetter.ShowWarning(message); + } + } +}