Skip to content

Commit

Permalink
Reboot handler (#362)
Browse files Browse the repository at this point in the history
Add Message_Close handler, reboot event notifier, and reboot sound effect id
  • Loading branch information
sorokya authored Jun 15, 2024
1 parent d5f2181 commit 29a08f2
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
15 changes: 15 additions & 0 deletions EOLib/Domain/Notifiers/IServerRebootNotifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using AutomaticTypeMapper;

namespace EOLib.Domain.Notifiers
{
public interface IServerRebootNotifier
{
void NotifyServerReboot();
}

[AutoMappedType]
public class NoOpServerRebootNotifier : IServerRebootNotifier
{
public void NotifyServerReboot() { }
}
}
39 changes: 39 additions & 0 deletions EOLib/PacketHandlers/Message/MessageCloseHandler.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Shows the server reboot message
/// </summary>
[AutoMappedType]
public class MessageCloseHandler : InGameOnlyPacketHandler<MessageCloseServerPacket>
{
private readonly IEnumerable<IServerRebootNotifier> _serverRebootNotifiers;

public override PacketFamily Family => PacketFamily.Message;

public override PacketAction Action => PacketAction.Close;

public MessageCloseHandler(IPlayerInfoProvider playerInfoProvider,
IEnumerable<IServerRebootNotifier> serverRebootNotifiers)
: base(playerInfoProvider)
{
_serverRebootNotifiers = serverRebootNotifiers;
}


public override bool HandlePacket(MessageCloseServerPacket packet)
{
foreach (var notifier in _serverRebootNotifiers)
notifier.NotifyServerReboot();

return true;
}
}
}
1 change: 1 addition & 0 deletions EndlessClient/Audio/SoundEffectID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum SoundEffectID
DeleteCharacter,
MapMutation = DeleteCharacter,
Banned,
Reboot = Banned,
ScreenCapture = 8,
PrivateMessageReceived,
PunchAttack,
Expand Down
34 changes: 34 additions & 0 deletions EndlessClient/Subscribers/ServerRebootEventSubscriber.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit 29a08f2

Please sign in to comment.