From 59fcd7b0d43fedba353b85ef15ffb94a5f69ea5e Mon Sep 17 00:00:00 2001 From: Richard Leek Date: Sat, 27 Jul 2024 12:16:04 -0400 Subject: [PATCH] Guild creation request (#363) * Implement Guild_Request packet handler * Remove GuildCreationRequest type Fix formatting on CreateMessageBox Use member initialization syntax for packet --- EOLib.Localization/DialogResourceID.cs | 3 +- EOLib.Localization/EOResourceID.cs | 3 + EOLib/Domain/Notifiers/IGuildNotifier.cs | 16 ++++++ .../Guild/GuildRequestHandler.cs | 38 +++++++++++++ .../Subscribers/GuildEventSubscriber.cs | 55 +++++++++++++++++++ 5 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 EOLib/Domain/Notifiers/IGuildNotifier.cs create mode 100644 EOLib/PacketHandlers/Guild/GuildRequestHandler.cs create mode 100644 EndlessClient/Subscribers/GuildEventSubscriber.cs diff --git a/EOLib.Localization/DialogResourceID.cs b/EOLib.Localization/DialogResourceID.cs index 1c0b1bf96..a316e9689 100644 --- a/EOLib.Localization/DialogResourceID.cs +++ b/EOLib.Localization/DialogResourceID.cs @@ -82,7 +82,8 @@ public enum DialogResourceID GUILD_TAG_OR_NAME_ALREADY_EXISTS = 146, GUILD_WILL_BE_CREATED = 148, GUILD_MASTER_IS_BUSY = 150, - GUILD_INVITES_YOU_TO_JOIN = 152, + GUILD_INVITATION = 152, + GUILD_INVITES_YOU_TO_JOIN = 153, GUILD_TAG_NAME_LETTER_MUST_MATCH = 154, GUILD_PROMPT_FOR_RECRUITER = 156, GUILD_PROMPT_LEAVE_GUILD = 158, diff --git a/EOLib.Localization/EOResourceID.cs b/EOLib.Localization/EOResourceID.cs index c5fb89f3f..95250f2fc 100644 --- a/EOLib.Localization/EOResourceID.cs +++ b/EOLib.Localization/EOResourceID.cs @@ -193,6 +193,9 @@ public enum EOResourceID GUILD_WITHDRAW_FUNDS_FROM_GUILD = 201, GUILD_REMOVE_MEMBER = 202, GUILD_REMOVE_A_MEMBER_FROM_GUILD = 203, + GUILD_JOINING_A_GUILD_IS_FREE = 205, + GUILD_PLEASE_CONSIDER_CAREFULLY = 207, + GUILD_DO_YOU_ACCEPT = 223, SETTING_KEYBOARD_ENGLISH = 253, SETTING_KEYBOARD_DUTCH = 254, diff --git a/EOLib/Domain/Notifiers/IGuildNotifier.cs b/EOLib/Domain/Notifiers/IGuildNotifier.cs new file mode 100644 index 000000000..847234bb2 --- /dev/null +++ b/EOLib/Domain/Notifiers/IGuildNotifier.cs @@ -0,0 +1,16 @@ +using AutomaticTypeMapper; +using EOLib.Domain.Interact.Guild; + +namespace EOLib.Domain.Notifiers +{ + public interface IGuildNotifier + { + void NotifyGuildCreationRequest(int creatorPlayerID, string guildIdentity); + } + + [AutoMappedType] + public class NoOpGuildNotifier : IGuildNotifier + { + public void NotifyGuildCreationRequest(int creatorPlayerID, string guildIdentity) { } + } +} diff --git a/EOLib/PacketHandlers/Guild/GuildRequestHandler.cs b/EOLib/PacketHandlers/Guild/GuildRequestHandler.cs new file mode 100644 index 000000000..906304b2f --- /dev/null +++ b/EOLib/PacketHandlers/Guild/GuildRequestHandler.cs @@ -0,0 +1,38 @@ +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.Guild +{ + [AutoMappedType] + + public class GuildRequestHandler : InGameOnlyPacketHandler + { + private readonly IEnumerable _guildNotifiers; + + public override PacketFamily Family => PacketFamily.Guild; + + public override PacketAction Action => PacketAction.Request; + + public GuildRequestHandler(IPlayerInfoProvider playerInfoProvider, + IEnumerable guildNotifiers) + : base(playerInfoProvider) + { + _guildNotifiers = guildNotifiers; + } + + public override bool HandlePacket(GuildRequestServerPacket packet) + { + foreach(var notifier in _guildNotifiers) + { + notifier.NotifyGuildCreationRequest(packet.PlayerId, packet.GuildIdentity); + } + + return true; + } + } +} diff --git a/EndlessClient/Subscribers/GuildEventSubscriber.cs b/EndlessClient/Subscribers/GuildEventSubscriber.cs new file mode 100644 index 000000000..41ee22b5a --- /dev/null +++ b/EndlessClient/Subscribers/GuildEventSubscriber.cs @@ -0,0 +1,55 @@ +using AutomaticTypeMapper; +using EndlessClient.Audio; +using EndlessClient.Dialogs.Factories; +using EOLib.Domain.Notifiers; +using EOLib.Localization; +using EOLib.Net.Communication; +using Moffat.EndlessOnline.SDK.Protocol.Net.Client; + +namespace EndlessClient.Subscribers +{ + [AutoMappedType] + public class GuildEventSubscriber : IGuildNotifier + { + private readonly IEOMessageBoxFactory _messageBoxFactory; + private readonly ILocalizedStringFinder _localizedStringFinder; + private readonly IPacketSendService _packetSendService; + private readonly ISfxPlayer _sfxPlayer; + + public GuildEventSubscriber(IEOMessageBoxFactory messageBoxFactory, ILocalizedStringFinder localizedStringFinder, IPacketSendService packetSendService, ISfxPlayer sfxPlayer) + { + _messageBoxFactory = messageBoxFactory; + _localizedStringFinder = localizedStringFinder; + _packetSendService = packetSendService; + _sfxPlayer = sfxPlayer; + } + + public void NotifyGuildCreationRequest(int creatorPlayerID, string guildIdentity) + { + _sfxPlayer.PlaySfx(SoundEffectID.ServerMessage); + + var dlg = _messageBoxFactory.CreateMessageBox( + $"{guildIdentity}" + + " " + _localizedStringFinder.GetString(DialogResourceID.GUILD_INVITES_YOU_TO_JOIN) + + " " + _localizedStringFinder.GetString(EOResourceID.GUILD_JOINING_A_GUILD_IS_FREE) + + " " + _localizedStringFinder.GetString(EOResourceID.GUILD_PLEASE_CONSIDER_CAREFULLY) + + " " + _localizedStringFinder.GetString(EOResourceID.GUILD_DO_YOU_ACCEPT), + caption: _localizedStringFinder.GetString(DialogResourceID.GUILD_INVITATION), + whichButtons: Dialogs.EODialogButtons.OkCancel, + style: Dialogs.EOMessageBoxStyle.LargeDialogSmallHeader); + + dlg.DialogClosing += (_, e) => + { + if (e.Result == XNAControls.XNADialogResult.OK) + { + _packetSendService.SendPacket(new GuildAcceptClientPacket() + { + InviterPlayerId = creatorPlayerID + }); + } + }; + + dlg.ShowDialog(); + } + } +}