-
Notifications
You must be signed in to change notification settings - Fork 22
Fix guild invite acceptance handling #227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
0047fcc
add6b80
e873186
02b67c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2204,12 +2204,32 @@ void LobbyNetworkHandler::HandleAcceptInviteToGuild( | |
| const ClientId clientId, | ||
| const protocol::AcCmdLCInviteGuildJoinOK& command) | ||
| { | ||
| // TODO: command data check | ||
|
|
||
| const auto& clientContext = GetClientContext(clientId); | ||
|
|
||
| // Basic sanity check: command character must match connected character | ||
| if (command.characterUid != clientContext.characterUid) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| { | ||
| spdlog::warn( | ||
| "HandleAcceptInviteToGuild: character UID mismatch (command: {}, context: {})", | ||
| command.characterUid, | ||
| clientContext.characterUid); | ||
| return; | ||
| } | ||
|
|
||
| // Check that the guild instance exists in lobby state | ||
| auto& guildInstances = _serverInstance.GetLobbyDirector().GetGuilds(); | ||
| const auto guildInstanceIt = guildInstances.find(command.guild.uid); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to verify the |
||
| if (guildInstanceIt == guildInstances.end()) | ||
| { | ||
| spdlog::warn( | ||
| "HandleAcceptInviteToGuild: guild {} not found for character {}", | ||
| command.guild.uid, | ||
| clientContext.characterUid); | ||
| return; | ||
| } | ||
|
|
||
| // Pending invites for guild | ||
| auto& pendingGuildInvites = _serverInstance.GetLobbyDirector().GetGuilds()[command.guild.uid].invites; | ||
| auto& pendingGuildInvites = guildInstanceIt->second.invites; | ||
|
|
||
| // Check if the guild has outstanding character invite. | ||
| const auto& guildInvite = std::ranges::find( | ||
|
|
@@ -2230,16 +2250,9 @@ void LobbyNetworkHandler::HandleAcceptInviteToGuild( | |
| } | ||
|
|
||
| std::string inviteeCharacterName; | ||
| _serverInstance.GetDataDirector().GetCharacter(clientContext.characterUid).Mutable( | ||
| [&inviteeCharacterName, guildUid = command.guild.uid](data::Character& character) | ||
| { | ||
| inviteeCharacterName = character.name(); | ||
| character.guildUid() = guildUid; | ||
| }); | ||
|
|
||
| bool guildAddSuccess = false; | ||
| _serverInstance.GetDataDirector().GetGuild(command.guild.uid).Mutable( | ||
| [&guildAddSuccess, inviteeCharacterUid = command.characterUid](data::Guild& guild) | ||
| [&guildAddSuccess, inviteeCharacterUid = clientContext.characterUid](data::Guild& guild) | ||
| { | ||
| // Check if invitee who accepted is in the guild | ||
| if (std::ranges::contains(guild.members(), inviteeCharacterUid) || | ||
|
|
@@ -2261,9 +2274,17 @@ void LobbyNetworkHandler::HandleAcceptInviteToGuild( | |
| return; | ||
| } | ||
|
|
||
| // Now that the character has been added to the guild, update its guild UID | ||
| _serverInstance.GetDataDirector().GetCharacter(clientContext.characterUid).Mutable( | ||
| [&inviteeCharacterName, guildUid = command.guild.uid](data::Character& character) | ||
| { | ||
| inviteeCharacterName = character.name(); | ||
| character.guildUid() = guildUid; | ||
| }); | ||
|
|
||
| _serverInstance.GetRanchDirector().SendGuildInviteAccepted( | ||
| command.guild.uid, | ||
| command.characterUid, | ||
| clientContext.characterUid, | ||
| inviteeCharacterName | ||
| ); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.