Skip to content

Commit

Permalink
Guild creation request (#363)
Browse files Browse the repository at this point in the history
* Implement Guild_Request packet handler

* Remove GuildCreationRequest type
Fix formatting on CreateMessageBox
Use member initialization syntax for packet
  • Loading branch information
sorokya authored Jul 27, 2024
1 parent efd8591 commit 59fcd7b
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 1 deletion.
3 changes: 2 additions & 1 deletion EOLib.Localization/DialogResourceID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions EOLib.Localization/EOResourceID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions EOLib/Domain/Notifiers/IGuildNotifier.cs
Original file line number Diff line number Diff line change
@@ -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) { }
}
}
38 changes: 38 additions & 0 deletions EOLib/PacketHandlers/Guild/GuildRequestHandler.cs
Original file line number Diff line number Diff line change
@@ -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<GuildRequestServerPacket>
{
private readonly IEnumerable<IGuildNotifier> _guildNotifiers;

public override PacketFamily Family => PacketFamily.Guild;

public override PacketAction Action => PacketAction.Request;

public GuildRequestHandler(IPlayerInfoProvider playerInfoProvider,
IEnumerable<IGuildNotifier> guildNotifiers)
: base(playerInfoProvider)
{
_guildNotifiers = guildNotifiers;
}

public override bool HandlePacket(GuildRequestServerPacket packet)
{
foreach(var notifier in _guildNotifiers)
{
notifier.NotifyGuildCreationRequest(packet.PlayerId, packet.GuildIdentity);
}

return true;
}
}
}
55 changes: 55 additions & 0 deletions EndlessClient/Subscribers/GuildEventSubscriber.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}

0 comments on commit 59fcd7b

Please sign in to comment.