Skip to content
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

Feature: auto party join #663

Merged
merged 5 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion Code/encoding/Structs/ServerSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using TiltedPhoques::Serialization;

bool ServerSettings::operator==(const ServerSettings& acRhs) const noexcept
{
return Difficulty == acRhs.Difficulty && GreetingsEnabled == acRhs.GreetingsEnabled && PvpEnabled == acRhs.PvpEnabled && SyncPlayerHomes == acRhs.SyncPlayerHomes && DeathSystemEnabled == acRhs.DeathSystemEnabled;
return Difficulty == acRhs.Difficulty && GreetingsEnabled == acRhs.GreetingsEnabled && PvpEnabled == acRhs.PvpEnabled && SyncPlayerHomes == acRhs.SyncPlayerHomes && DeathSystemEnabled == acRhs.DeathSystemEnabled && AutoPartyJoin == acRhs.AutoPartyJoin;
}

bool ServerSettings::operator!=(const ServerSettings& acRhs) const noexcept
Expand All @@ -21,6 +21,7 @@ void ServerSettings::Serialize(TiltedPhoques::Buffer::Writer& aWriter) const noe
Serialization::WriteBool(aWriter, SyncPlayerHomes);
Serialization::WriteBool(aWriter, DeathSystemEnabled);
Serialization::WriteBool(aWriter, SyncPlayerCalendar);
Serialization::WriteBool(aWriter, AutoPartyJoin);
}

void ServerSettings::Deserialize(TiltedPhoques::Buffer::Reader& aReader) noexcept
Expand All @@ -31,4 +32,5 @@ void ServerSettings::Deserialize(TiltedPhoques::Buffer::Reader& aReader) noexcep
SyncPlayerHomes = Serialization::ReadBool(aReader);
DeathSystemEnabled = Serialization::ReadBool(aReader);
SyncPlayerCalendar = Serialization::ReadBool(aReader);
AutoPartyJoin = Serialization::ReadBool(aReader);
}
1 change: 1 addition & 0 deletions Code/encoding/Structs/ServerSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ struct ServerSettings
bool SyncPlayerHomes{};
bool DeathSystemEnabled{};
bool SyncPlayerCalendar{};
bool AutoPartyJoin{};
};
4 changes: 4 additions & 0 deletions Code/server/GameServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ Console::Setting uTimeScale{
Console::Setting bSyncPlayerCalendar{
"Gameplay:bSyncPlayerCalendar",
"Syncs up all player calendars to be the same day, month, and year. This uses the date of the player with the furthest ahead date at connection.", false};
Console::Setting bAutoPartyJoin{
"Gameplay:bAutoPartyJoin",
"Join parties automatically, as long as there is only one party in the server", true};
// ModPolicy Stuff
Console::Setting bEnableModCheck{"ModPolicy:bEnableModCheck", "Bypass the checking of mods on the server", false,
Console::SettingsFlags::kLocked};
Expand Down Expand Up @@ -142,6 +145,7 @@ ServerSettings GetSettings()
settings.SyncPlayerHomes = bSyncPlayerHomes;
settings.DeathSystemEnabled = bEnableDeathSystem;
settings.SyncPlayerCalendar = bSyncPlayerCalendar;
settings.AutoPartyJoin = bAutoPartyJoin;
return settings;
}

Expand Down
45 changes: 44 additions & 1 deletion Code/server/Services/PartyService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#include <Messages/PartyKickRequest.h>
#include <Messages/NotifyPlayerJoined.h>

namespace
{
Console::Setting bAutoPartyJoin{"Gameplay:bAutoPartyJoin", "Join parties automatically, as long as there is only one party in the server", true};
}

PartyService::PartyService(World& aWorld, entt::dispatcher& aDispatcher) noexcept
: m_world(aWorld)
, m_updateEvent(aDispatcher.sink<UpdateEvent>().connect<&PartyService::OnUpdate>(this))
Expand Down Expand Up @@ -115,6 +120,22 @@ void PartyService::OnPartyCreate(const PacketEvent<PartyCreateRequest>& acPacket

spdlog::debug("[PartyService]: Created party for {}", player->GetId());
SendPartyJoinedEvent(party, player);

if (m_parties.size() == 1 && bAutoPartyJoin)
{
for (Player* otherPlayer : m_world.GetPlayerManager())
{
if (otherPlayer->GetId() != player->GetId())
{
party.Members.push_back(otherPlayer);
otherPlayer->GetParty().JoinedPartyId = partyId;

SendPartyJoinedEvent(party, otherPlayer);
}
}

BroadcastPartyInfo(partyId);
}
}
}

Expand Down Expand Up @@ -179,7 +200,7 @@ void PartyService::OnPartyKick(const PacketEvent<PartyKickRequest>& acPacket) no
}
}

void PartyService::OnPlayerJoin(const PlayerJoinEvent& acEvent) const noexcept
void PartyService::OnPlayerJoin(const PlayerJoinEvent& acEvent) noexcept
{
BroadcastPlayerList();

Expand All @@ -195,6 +216,28 @@ void PartyService::OnPlayerJoin(const PlayerJoinEvent& acEvent) const noexcept
spdlog::debug("[Party] New notify player {:x} {}", notify.PlayerId, notify.Username.c_str());

GameServer::Get()->SendToPlayers(notify, acEvent.pPlayer);

if (m_parties.size() == 1 && bAutoPartyJoin)
{
for (Player* player : m_world.GetPlayerManager())
{
if (IsPlayerInParty(player))
{
auto& playerPartyComponent = player->GetParty();
Party& party = m_parties[*playerPartyComponent.JoinedPartyId];

party.Members.push_back(acEvent.pPlayer);
acEvent.pPlayer->GetParty().JoinedPartyId = *playerPartyComponent.JoinedPartyId;

SendPartyJoinedEvent(party, acEvent.pPlayer);

BroadcastPartyInfo(*playerPartyComponent.JoinedPartyId);

break;
}
}

}
}

void PartyService::OnPartyInvite(const PacketEvent<PartyInviteRequest>& acPacket) noexcept
Expand Down
2 changes: 1 addition & 1 deletion Code/server/Services/PartyService.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct PartyService

protected:
void OnUpdate(const UpdateEvent& acEvent) noexcept;
void OnPlayerJoin(const PlayerJoinEvent& acEvent) const noexcept;
void OnPlayerJoin(const PlayerJoinEvent& acEvent) noexcept;
void OnPlayerLeave(const PlayerLeaveEvent& acEvent) noexcept;
void OnPartyInvite(const PacketEvent<PartyInviteRequest>& acPacket) noexcept;
void OnPartyAcceptInvite(const PacketEvent<PartyAcceptInviteRequest>& acPacket) noexcept;
Expand Down
Loading