Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions src/server/lobby/LobbyNetworkHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Basic sanity check: command character must match connected character
// Sanity check the requested character matches the client character.

if (command.characterUid != clientContext.characterUid)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

characterUid is the UID of the character that is being invited, you should be checking inviterCharacterName. Can you please test the behaviour in the future before submitting PRs?

{
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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to verify the command.guild.uid as well.

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(
Expand All @@ -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) ||
Expand All @@ -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
);
}
Expand Down
Loading