Skip to content
Closed
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: 2 additions & 2 deletions Code/client/Services/Generic/OverlayService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ struct D3D11RenderProvider final : OverlayApp::RenderProvider, OverlayRenderHand
[[nodiscard]] HWND GetWindow() override { return m_pRenderSystem->GetWindow(); }

[[nodiscard]] IDXGISwapChain* GetSwapChain() const noexcept override { return m_pRenderSystem->GetSwapChain(); }
[[nodiscard]] ID3D11Device* GetDevice() const noexcept override { return m_pRenderSystem->GetDevice(); }
[[nodiscard]] ID3D11DeviceContext* GetDeviceContext() const noexcept override { return m_pRenderSystem->GetDeviceContext(); }
[[nodiscard]] ID3D11Device* GetDevice() const noexcept { return m_pRenderSystem->GetDevice(); }
[[nodiscard]] ID3D11DeviceContext* GetDeviceContext() const noexcept { return m_pRenderSystem->GetDeviceContext(); }

private:
RenderSystemD3D11* m_pRenderSystem;
Expand Down
16 changes: 16 additions & 0 deletions Code/client/Services/Generic/PartyService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <Messages/PartyCreateRequest.h>
#include <Messages/PartyChangeLeaderRequest.h>
#include <Messages/PartyKickRequest.h>
#include <Messages/PartyAutoJoinToggleRequest.h>

#include <OverlayApp.hpp>

Expand Down Expand Up @@ -80,6 +81,12 @@ void PartyService::ChangePartyLeader(const uint32_t aPlayerId) const noexcept
m_transport.Send(changeMessage);
}

void PartyService::ToggleAutoJoinParty() const noexcept
{
PartyAutoJoinToggleRequest request;
m_transport.Send(request);
}

void PartyService::OnUpdate(const UpdateEvent& acEvent) noexcept
{
const auto cCurrentTick = m_transport.GetClock().GetCurrentTick();
Expand Down Expand Up @@ -117,6 +124,9 @@ void PartyService::OnPartyInfo(const NotifyPartyInfo& acPartyInfo) noexcept
m_isLeader = acPartyInfo.IsLeader;
m_leaderPlayerId = acPartyInfo.LeaderPlayerId;
m_partyMembers = acPartyInfo.PlayerIds;
m_allowAutoJoin = acPartyInfo.AllowAutoJoin;
m_serverAutoJoin = acPartyInfo.ServerAutoJoin;
m_partyCount = acPartyInfo.PartyCount;

// TODO: this can be done a bit prettier
if (m_isLeader)
Expand All @@ -133,6 +143,9 @@ void PartyService::OnPartyInfo(const NotifyPartyInfo& acPartyInfo) noexcept

pArguments->SetList(0, pPlayerIds);
pArguments->SetInt(1, acPartyInfo.LeaderPlayerId);
pArguments->SetBool(2, acPartyInfo.AllowAutoJoin);
pArguments->SetBool(3, acPartyInfo.ServerAutoJoin);
pArguments->SetInt(4, acPartyInfo.PartyCount);

m_world.GetOverlayService().GetOverlayApp()->ExecuteAsync("partyInfo", pArguments);
}
Expand Down Expand Up @@ -174,6 +187,9 @@ void PartyService::DestroyParty() noexcept
{
m_inParty = false;
m_isLeader = false;
m_allowAutoJoin = false;
m_serverAutoJoin = false;
m_partyCount = 0;
m_leaderPlayerId = -1;
m_partyMembers.clear();
}
6 changes: 6 additions & 0 deletions Code/client/Services/PartyService.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct PartyService

[[nodiscard]] bool IsInParty() const noexcept { return m_inParty; }
[[nodiscard]] bool IsLeader() const noexcept { return m_isLeader; }
[[nodiscard]] bool AllowAutoJoin() const noexcept { return m_allowAutoJoin; }
[[nodiscard]] bool ServerAutoJoin() const noexcept { return m_serverAutoJoin; }
[[nodiscard]] uint32_t GetLeaderPlayerId() const noexcept { return m_leaderPlayerId; }

const Vector<uint32_t>& GetPartyMembers() const noexcept { return m_partyMembers; }
Expand All @@ -35,6 +37,7 @@ struct PartyService
void AcceptInvite(const uint32_t aInviterId) const noexcept;
void KickPartyMember(const uint32_t aPlayerId) const noexcept;
void ChangePartyLeader(const uint32_t aPlayerId) const noexcept;
void ToggleAutoJoinParty() const noexcept;

protected:
void OnUpdate(const UpdateEvent& acEvent) noexcept;
Expand All @@ -54,6 +57,9 @@ struct PartyService

bool m_inParty = false;
bool m_isLeader = false;
bool m_allowAutoJoin = false;
bool m_serverAutoJoin = false;
uint32_t m_partyCount = 0;
uint32_t m_leaderPlayerId;
Vector<uint32_t> m_partyMembers;

Expand Down
3 changes: 2 additions & 1 deletion Code/encoding/Messages/ClientMessageFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <Messages/PartyCreateRequest.h>
#include <Messages/PartyChangeLeaderRequest.h>
#include <Messages/PartyKickRequest.h>
#include <Messages/PartyAutoJoinToggleRequest.h>
#include <Messages/PartyInviteRequest.h>
#include <Messages/RequestActorValueChanges.h>
#include <Messages/RequestActorMaxValueChanges.h>
Expand Down Expand Up @@ -67,7 +68,7 @@ struct ClientMessageFactory
{
auto s_visitor = CreateMessageVisitor<
AuthenticationRequest, AssignCharacterRequest, CancelAssignmentRequest, ClientReferencesMoveRequest, EnterInteriorCellRequest, RequestInventoryChanges, RequestFactionsChanges, RequestQuestUpdate, PartyInviteRequest, PartyAcceptInviteRequest, PartyLeaveRequest, PartyCreateRequest,
PartyChangeLeaderRequest, PartyKickRequest, RequestActorValueChanges, RequestActorMaxValueChanges, EnterExteriorCellRequest, RequestHealthChangeBroadcast, ActivateRequest, LockChangeRequest, AssignObjectsRequest, RequestDeathStateChange, ShiftGridCellRequest,
PartyChangeLeaderRequest, PartyKickRequest, PartyAutoJoinToggleRequest, RequestActorValueChanges, RequestActorMaxValueChanges, EnterExteriorCellRequest, RequestHealthChangeBroadcast, ActivateRequest, LockChangeRequest, AssignObjectsRequest, RequestDeathStateChange, ShiftGridCellRequest,
RequestOwnershipTransfer, RequestOwnershipClaim, RequestObjectInventoryChanges, SpellCastRequest, ProjectileLaunchRequest, InterruptCastRequest, AddTargetRequest, ScriptAnimationRequest, DrawWeaponRequest, MountRequest, NewPackageRequest, RequestRespawn, SyncExperienceRequest,
RequestEquipmentChanges, SendChatMessageRequest, TeleportCommandRequest, PlayerRespawnRequest, DialogueRequest, SubtitleRequest, PlayerDialogueRequest, PlayerLevelRequest, TeleportRequest, RequestPlayerHealthUpdate, RequestWeatherChange, RequestCurrentWeather, RequestSetWaypoint,
RequestRemoveWaypoint, RemoveSpellRequest, SetTimeCommandRequest>;
Expand Down
6 changes: 6 additions & 0 deletions Code/encoding/Messages/NotifyPartyInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ void NotifyPartyInfo::SerializeRaw(TiltedPhoques::Buffer::Writer& aWriter) const
{
Serialization::WriteBool(aWriter, IsLeader);
Serialization::WriteVarInt(aWriter, LeaderPlayerId);
Serialization::WriteBool(aWriter, AllowAutoJoin);
Serialization::WriteBool(aWriter, ServerAutoJoin);
Serialization::WriteVarInt(aWriter, PartyCount);
aWriter.WriteBits(PlayerIds.size() & 0xFF, 8);

for (auto player : PlayerIds)
Expand All @@ -17,6 +20,9 @@ void NotifyPartyInfo::DeserializeRaw(TiltedPhoques::Buffer::Reader& aReader) noe
{
IsLeader = Serialization::ReadBool(aReader);
LeaderPlayerId = Serialization::ReadVarInt(aReader) & 0xFFFFFFFF;
AllowAutoJoin = Serialization::ReadBool(aReader);
ServerAutoJoin = Serialization::ReadBool(aReader);
PartyCount = Serialization::ReadVarInt(aReader) & 0xFFFFFFFF;

uint64_t count = 0;
aReader.ReadBits(count, 8);
Expand Down
8 changes: 7 additions & 1 deletion Code/encoding/Messages/NotifyPartyInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ struct NotifyPartyInfo final : ServerMessage
NotifyPartyInfo()
: ServerMessage(Opcode)
, IsLeader(false)
, AllowAutoJoin{true}
, ServerAutoJoin{}
, PartyCount{}
{
}

Expand All @@ -20,9 +23,12 @@ struct NotifyPartyInfo final : ServerMessage
void SerializeRaw(TiltedPhoques::Buffer::Writer& aWriter) const noexcept override;
void DeserializeRaw(TiltedPhoques::Buffer::Reader& aReader) noexcept override;

bool operator==(const NotifyPartyInfo& acRhs) const noexcept { return GetOpcode() == acRhs.GetOpcode() && PlayerIds == acRhs.PlayerIds && LeaderPlayerId == acRhs.LeaderPlayerId; }
bool operator==(const NotifyPartyInfo& acRhs) const noexcept { return GetOpcode() == acRhs.GetOpcode() && PlayerIds == acRhs.PlayerIds && LeaderPlayerId == acRhs.LeaderPlayerId && AllowAutoJoin == acRhs.AllowAutoJoin && ServerAutoJoin == acRhs.ServerAutoJoin && PartyCount == acRhs.PartyCount; }

Vector<uint32_t> PlayerIds{};
bool IsLeader;
uint32_t LeaderPlayerId;
bool AllowAutoJoin{true};
bool ServerAutoJoin{};
uint32_t PartyCount{};
};
10 changes: 10 additions & 0 deletions Code/encoding/Messages/PartyAutoJoinToggleRequest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <Messages/PartyAutoJoinToggleRequest.h>

void PartyAutoJoinToggleRequest::SerializeRaw(TiltedPhoques::Buffer::Writer& aWriter) const noexcept
{
}

void PartyAutoJoinToggleRequest::DeserializeRaw(TiltedPhoques::Buffer::Reader& aReader) noexcept
{
ClientMessage::DeserializeRaw(aReader);
}
20 changes: 20 additions & 0 deletions Code/encoding/Messages/PartyAutoJoinToggleRequest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include "Message.h"

struct PartyAutoJoinToggleRequest final : ClientMessage
{
static constexpr ClientOpcode Opcode = kPartyAutoJoinToggleRequest;

PartyAutoJoinToggleRequest()
: ClientMessage(Opcode)
{
}

virtual ~PartyAutoJoinToggleRequest() = default;

void SerializeRaw(TiltedPhoques::Buffer::Writer& aWriter) const noexcept override;
void DeserializeRaw(TiltedPhoques::Buffer::Reader& aReader) noexcept override;

bool operator==(const PartyAutoJoinToggleRequest& achRhs) const noexcept { return GetOpcode() == achRhs.GetOpcode(); }
};
1 change: 1 addition & 0 deletions Code/encoding/Opcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum ClientOpcode : unsigned char
kPartyCreateRequest,
kPartyChangeLeaderRequest,
kPartyKickRequest,
kPartyAutoJoinToggleRequest,
kRequestActorValueChanges,
kRequestActorMaxValueChanges,
kRequestHealthChangeBroadcast,
Expand Down
40 changes: 38 additions & 2 deletions Code/server/Services/PartyService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <Messages/PartyCreateRequest.h>
#include <Messages/PartyChangeLeaderRequest.h>
#include <Messages/PartyKickRequest.h>
#include <Messages/PartyAutoJoinToggleRequest.h>
#include <Messages/NotifyPlayerJoined.h>

#include <Setting.h>
Expand All @@ -36,6 +37,7 @@ PartyService::PartyService(World& aWorld, entt::dispatcher& aDispatcher) noexcep
, m_partyCreateConnection(aDispatcher.sink<PacketEvent<PartyCreateRequest>>().connect<&PartyService::OnPartyCreate>(this))
, m_partyChangeLeaderConnection(aDispatcher.sink<PacketEvent<PartyChangeLeaderRequest>>().connect<&PartyService::OnPartyChangeLeader>(this))
, m_partyKickConnection(aDispatcher.sink<PacketEvent<PartyKickRequest>>().connect<&PartyService::OnPartyKick>(this))
, m_partyAutoJoinToggleConnection(aDispatcher.sink<PacketEvent<PartyAutoJoinToggleRequest>>().connect<&PartyService::OnPartyAutoJoinToggle>(this))
{
}

Expand Down Expand Up @@ -120,6 +122,7 @@ void PartyService::OnPartyCreate(const PacketEvent<PartyCreateRequest>& acPacket
inviterPartyComponent.JoinedPartyId = partyId;

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

if (m_parties.size() == 1 && bAutoPartyJoin)
Expand All @@ -134,9 +137,9 @@ void PartyService::OnPartyCreate(const PacketEvent<PartyCreateRequest>& acPacket
SendPartyJoinedEvent(party, otherPlayer);
}
}

BroadcastPartyInfo(partyId);
}

BroadcastPartyInfo(partyId);
}
}

Expand Down Expand Up @@ -201,6 +204,24 @@ void PartyService::OnPartyKick(const PacketEvent<PartyKickRequest>& acPacket) no
}
}

void PartyService::OnPartyAutoJoinToggle(const PacketEvent<PartyAutoJoinToggleRequest>& acPacket) noexcept
{
Player* const player = acPacket.pPlayer;

auto& partyComponent = player->GetParty();
if (!partyComponent.JoinedPartyId)
return;

Party& party = m_parties[*partyComponent.JoinedPartyId];
if (party.LeaderPlayerId != player->GetId())
return;

party.AllowAutoJoin = !party.AllowAutoJoin;
spdlog::debug("[PartyService]: Party {} AllowAutoJoin={}", *partyComponent.JoinedPartyId, party.AllowAutoJoin);

BroadcastPartyInfo(*partyComponent.JoinedPartyId);
}

void PartyService::OnPlayerJoin(const PlayerJoinEvent& acEvent) noexcept
{
BroadcastPlayerList();
Expand All @@ -220,6 +241,12 @@ void PartyService::OnPlayerJoin(const PlayerJoinEvent& acEvent) noexcept

if (m_parties.size() == 1 && bAutoPartyJoin)
{
// Skip auto-join if the party has disabled it
auto it = m_parties.begin();
if (it != m_parties.end() && !it->second.AllowAutoJoin)
{
return;
}
for (Player* player : m_world.GetPlayerManager())
{
if (IsPlayerInParty(player))
Expand Down Expand Up @@ -367,6 +394,12 @@ void PartyService::RemovePlayerFromParty(Player* apPlayer) noexcept
if (members.empty())
{
m_parties.erase(id);
// If there's exactly one party left, broadcast its info so clients
// learn the updated party count and can re-enable the auto-join checkbox
if (m_parties.size() == 1)
{
BroadcastPartyInfo(m_parties.begin()->first);
}
}
else
{
Expand Down Expand Up @@ -422,6 +455,9 @@ void PartyService::BroadcastPartyInfo(uint32_t aPartyId) const noexcept

NotifyPartyInfo message;
message.LeaderPlayerId = party.LeaderPlayerId;
message.AllowAutoJoin = party.AllowAutoJoin;
message.ServerAutoJoin = bAutoPartyJoin;
message.PartyCount = m_parties.size();

for (auto pPlayer : members)
{
Expand Down
4 changes: 4 additions & 0 deletions Code/server/Services/PartyService.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct PartyAcceptInviteRequest;
struct PartyLeaveRequest;
struct NotifyPartyInfo;
struct PartyCreateRequest;
struct PartyAutoJoinToggleRequest;
struct PartyChangeLeaderRequest;
struct PartyKickRequest;

Expand All @@ -24,6 +25,7 @@ struct PartyService
uint32_t LeaderPlayerId;
Vector<Player*> Members;
GameId CachedWeather{};
bool AllowAutoJoin{true};
};

PartyService(World& aWorld, entt::dispatcher& aDispatcher) noexcept;
Expand All @@ -46,6 +48,7 @@ struct PartyService
void OnPartyCreate(const PacketEvent<PartyCreateRequest>& acPacket) noexcept;
void OnPartyChangeLeader(const PacketEvent<PartyChangeLeaderRequest>& acPacket) noexcept;
void OnPartyKick(const PacketEvent<PartyKickRequest>& acPacket) noexcept;
void OnPartyAutoJoinToggle(const PacketEvent<PartyAutoJoinToggleRequest>& acPacket) noexcept;
void RemovePlayerFromParty(Player* apPlayer) noexcept;

void BroadcastPlayerList(Player* apPlayer = nullptr) const noexcept;
Expand All @@ -67,6 +70,7 @@ struct PartyService
entt::scoped_connection m_partyCreateConnection;
entt::scoped_connection m_partyChangeLeaderConnection;
entt::scoped_connection m_partyKickConnection;
entt::scoped_connection m_partyAutoJoinToggleConnection;

void SendPartyJoinedEvent(Party& aParty, Player* aPlayer) noexcept;
};
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
</div>
</ng-template>

<label class="autojoin-toggle" *ngIf="isPartyLeader$ | async">
<input type="checkbox" [checked]="allowAutoJoin$ | async" [disabled]="autoJoinCheckboxDisabled$ | async" (change)="toggleAutoJoinParty()">
{{ 'COMPONENT.PARTY_MENU.AUTO_JOIN' | transloco }}
</label>

<button class="party-menu-button btn" (click)="leave()">
{{ 'COMPONENT.PARTY_MENU.LEAVE_PARTY' | transloco }}
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export class PartyMenuComponent {
isLaunchPartyDisabled$: Observable<boolean>;
invitations$: Observable<Player[]>;
isPartyLeader$: Observable<boolean>;
allowAutoJoin$: Observable<boolean>;
autoJoinCheckboxDisabled$: Observable<boolean>;

constructor(
private readonly groupService: GroupService,
Expand All @@ -42,6 +44,16 @@ export class PartyMenuComponent {
group.isEnabled && group.owner == this.clientService.localPlayerId,
),
);
this.allowAutoJoin$ = this.groupService.group
.asObservable()
.pipe(
map(group => group.allowAutoJoin),
);
this.autoJoinCheckboxDisabled$ = this.groupService.group
.asObservable()
.pipe(
map(group => !group.serverAutoJoin || group.partyCount > 1),
);
this.isLaunchPartyDisabled$ = this.groupService
.selectMembersLength(false)
.pipe(map(count => count > 1));
Expand Down Expand Up @@ -70,4 +82,8 @@ export class PartyMenuComponent {
public changeLeader(playerId: number) {
this.clientService.changePartyLeader(playerId);
}

public toggleAutoJoinParty() {
this.groupService.toggleAutoJoinParty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@
<tr>
<th>{{ 'COMPONENT.PARTY_LIST.TABLE_HEADERS.LEVEL' | transloco }}</th>
<th>{{ 'COMPONENT.PARTY_LIST.TABLE_HEADERS.NAME' | transloco }}</th>
<th>
{{ 'COMPONENT.PARTY_LIST.TABLE_HEADERS.LOCATION' | transloco }}
</th>
<th></th>
</tr>
</thead>
<tbody class="listBody">
<tr *ngFor="let player of playerList$ | async">
<td>{{ player.level }}</td>
<td>{{ player.name }}</td>
<td>{{ player.cellName }}</td>
<td class="actions-col">
<button
[class.hidden]="player.isMember || !(isPartyLeader$ | async)"
Expand Down
Loading
Loading