Skip to main content

Party

Last updated on

Overview

AccelByte Foundations’ Lobby Service includes Party features that enable multiplayer play. All Party features use WebSocket to ensure smooth communication between players. Players can interact with parties in several ways, including:

  • User Party Info shows players information about their party, including the Party ID, Leader ID, and a list of party members.
  • Create Party allows players to create a new party that other players can join.
  • Invite to Party allows players to invite their friends to join their party. Both the inviter and invitee will receive a notification when the invitation is sent.
  • Join Party allows players to join a party that they’ve been invited to join. When the player joins the party the inviter and other party members will be notified.
  • Reject Party allows players to reject a party invitation. The inviter will be notified that their invitation was rejected.
  • Promote Member allows players to set another player as the party leader.
  • Kick Party allows party leaders to remove another player from their party.
NOTE

Please click the below links to read how to implement Party in Unity and Unreal Engine.

Implementing Party Interaction using the Client SDKs

Create a Party

Players can create a party that is then used for matchmaking. A player can only create one party at a time and will become the leader of the party they create.

FRegistry::Lobby.SetCreatePartyResponseDelegate(Lobby::FPartyCreateResponse::CreateLambda([](FAccelByteModelsCreatePartyResponse result)  
{
UE_LOG(LogAccelByteLobbyTest, Log, TEXT("Create Party Success!"));
if (result.PartyId.IsEmpty())
{
UE_LOG(LogAccelByteLobbyTest, Log, TEXT("Create Party Error!"));
}
}));
FRegistry::Lobby.Connect();
FRegistry::Lobby.SendCreatePartyRequest();

Invite to a Party

Players can invite other players to their party, as long as the invited player is not already in a party. Party invitees will receive a notification that they have been invited to join a party and current party members will also receive a notification that someone has been invited to the party. Party invitees are identified by the inviteePlayerId in the Unreal Engine SDK and by the inviteeUserId parameter in the Unity SDK.

FRegistry::Lobby.SetInvitePartyResponseDelegate(Lobby::FPartyInviteResponse::CreateLambda([](FAccelByteModelsPartyInviteResponse result)  
{
UE_LOG(LogAccelByteLobbyTest, Log, TEXT("Invite Party Success!"));
})
);
const FString InvitedPlayerId = “a1b2c3d4e5”;
FRegistry::Lobby.SendInviteToPartyRequest(InvitedPlayerId);

Party Codes

Party leaders can send party codes to players so that those players can join their party. Only party leaders can use party codes. They can also refresh or revoke a party code.

Generate or Refresh a Party Code

Use the following function to generate or refresh a party code.

FRegistry::Lobby.SetPartyGenerateCodeResponseDelegate(
Api::Lobby::FPartyGenerateCodeResponse::CreateLambda([](FAccelByteModelsPartyGenerateCodeResponse Response)
{
// Handle result.PartyCode here
}));

FRegistry::Lobby.SendPartyGenerateCodeRequest();

Get a Party Code

Once a code is generated, party leaders can get the code and share it from other players. This function allows party leaders to get the party code.

FRegistry::Lobby.SetPartyGetCodeResponseDelegate(
Api::Lobby::FAccelByteModelsPartyGetCodeResponse ::CreateLambda([](FAccelByteModelsPartyGetCodeResponse Response)
{
// Handle result.PartyCode here
}));
FRegistry::Lobby.SendPartyGetCodeRequest();
tip

If the success response returns an empty party code, you need to call the GeneratePartyCode function to generate a new party code.

Revoke a Party Code

Party leaders can revoke a party code. If a party code is revoked, players will no longer be able to use it to join the party. This function allows party leaders to revoke the party code.

FRegistry::Lobby.SetPartyDeleteCodeResponseDelegate(
Api::Lobby::FAccelByteModelsPartyDeleteCodeResponse ::CreateLambda([](FAccelByteModelsPartyDeleteCodeResponse Response)
{
// Handle result here
}));
FRegistry::Lobby.SendPartyDeleteCodeRequest();

Join a Party with a Party Code

Players that have been sent a party code can use it to join a party. This function allows players to join a party using a party code.

FRegistry::Lobby.SetPartyJoinViaCodeResponseDelegate(
Api::Lobby::FPartyJoinViaCodeResponse::CreateLambda([](FPartyJoinViaCodeResponse Response)
{
// Handle result here
}));
FRegistry::Lobby.SendPartyJoinViaCodeRequest();

Join a Party

Players that are invited to a party can accept the invitation and join the party. Party invitees will receive a notification that they’ve joined the party and current party members will also receive a notification that someone is joining the party. The party is identified by the partyID parameter and the invitation by the invitationToken parameter.

FRegistry::Lobby.SetPartyGetInvitedNotifDelegate(Lobby::FPartyGetInvitedNotif::CreateLambda([](FAccelByteModelsPartyGetInvitedNotice result)  
{
UE_LOG(LogAccelByteLobbyTest, Log, TEXT("Get Party Invitation!"));
FRegistry::Lobby.SendAcceptInvitationRequest(*result.PartyId, *result.InvitationToken);
}));

FAccelByteModelsPartyJoinReponse joinPartyResponse;
FRegistry::Lobby.SetInvitePartyJoinResponseDelegate(Lobby::FPartyJoinResponse::CreateLambda([&joinPartyResponse](FAccelByteModelsPartyJoinReponse result)
{
UE_LOG(LogAccelByteLobbyTest, Log, TEXT("Join Party Success! Member : %d"), result.Members.Num());
joinPartyResponse = result;
if (result.Code != "0")
{
UE_LOG(LogAccelByteLobbyTest, Log, TEXT("Join Party Failed!"));
}
}));

Reject a Party Invitation

When a player has been invited to a party, they can choose to reject the invitation. Party invitees will receive a notification that they’ve rejected the invitation and current party members will also receive a notification that someone has rejected the party invitation. The party is identified by the partyID parameter and the invitation by the invitationToken parameter.

//Reject a Party  
lobby.RejectPartyInvitation(partyInvitation.partyID, partyInvitation.invitationToken, result =>
{
if(result.IsError)
{
Debug.Log("Error. Code: " + result.Error.Code + ", Reason: " + result.Error.Message);
}
else
{
Debug.Log("Successfully reject a party invitation");
}
});

//Notification: rejected a party invitation notification
//This notification will be received by the party leader of the party that send the invitation party
lobby.RejectedPartyInvitation += result
{
if(!result.IsError)
{
Debug.Log([Notification] Invitee reject a party invitation”);
}
};

Promote Member to Party Leader

The party leader can promote another party member to become the new party leader. All party members will be notified of the new party leader. The new party leader is identified by the memberUserId parameter.

//Promote member to be a Party Leader  
string memberUserId =987654321;
lobby.PromotePartyLeader(memberUserId, result =>
{
if(result.IsError)
{
Debug.Log("Error. Code: " + result.Error.Code + ", Reason: " + result.Error.Message);
}
else
{
Debug.Log("Successfully promote member to be a party leader");
}
});

Kick Player from a Party

The party leader has the privilege to remove a party member from their party by kicking them out of the party. Kicked party members will receive a notification that they’ve been kicked out of the party, and current party members will also receive a notification that someone has been kicked from the party. The kicked party member is identified by the KickPlayerId in Unreal Engine and by the memberUserId parameter in Unity.

FRegistry::Lobby.SetInvitePartyKickMemberResponseDelegate(Lobby::FPartyKickResponse::CreateLambda([](FAccelByteModelsKickPartyMemberResponse result)  
{
UE_LOG(LogAccelByteLobbyTest, Log, TEXT("Kick Party Member Success!"));
if (result.Code != "0")
{
UE_LOG(LogAccelByteLobbyTest, Log, TEXT("Kick Party Member Failed!"));
}
}));

const FString KickedPlayerId = “a1b2c3d4e5”;
FRegistry::Lobby.SendKickPartyMemberRequest(KickedPlayerId);

Leave a Party

Party members can choose to leave their party. If the party leader leaves the party, party leadership will be passed to another party member automatically. Party members that leave the party will receive a notification that they’ve left the party and current party members will also receive a notification that someone is leaving the party.

FRegistry::Lobby.SetLeavePartyResponseDelegate(Lobby::FPartyLeaveResponse::CreateLambda([](FAccelByteModelsLeavePartyResponse result)  
{
UE_LOG(LogAccelByteLobbyTest, Log, TEXT("Leave Party Success!"));
if (result.Code != "0")
{
UE_LOG(LogAccelByteLobbyTest, Log, TEXT("Leave Party Failed!"));
}
}));
FRegistry::Lobby.SendLeavePartyRequest();

Implementing Party Storage using the Client SDKs

Party Storage enables a party to store party attributes that can be passed from the game server to the game client. The game server will write the party’s storage to ensure that all party members get the same information or notification from the server.

Party Data Update Notification

Use this function to notify players of any updates to party data. Party members will be notified if an event occurs in the party, such as when a player accepts a party invitation, joins the party, or leaves a party.

FRegistry::Lobby.Connect();
FRegistry::Lobby.SetPartyDataUpdateNotifDelegate(AccelByte::Api::Lobby::FPartyDataUpdateNotif::CreateLambda([](const FAccelByteModelsPartyDataNotif& Result)
{
// Do something if PartyDataUpdateNotifDelegate has been successful
}));

Get Party Data (Client-Side)

Use this function to retrieve specific party data from the client side. Make sure you have players logged in to allow this API call.

FRegistry::Lobby.Connect();
FRegistry::Lobby.GetPartyStorage(PartyId, THandler<FAccelByteModelsPartyDataNotif>::CreateLambda([](const FAccelByteModelsPartyDataNotif& Result)
{
// Do something if GetPartyStoraget has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetPartyStorage has an error
UE_LOG(LogTemp, Log, TEXT("Error GetPartyStorage, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Get Party Data (Server-Side)

Use this function to retrieve specific party data from the server side. Make sure the game server is authenticated to allow this API call.

FString PartyId = FString("SomePartyId");

FRegistry::ServerLobby.GetPartyStorage(PartyId, THandler<FAccelByteModelsPartyDataNotif>::CreateLambda([](const FAccelByteModelsPartyDataNotif& Result)
{
// Do something if GetPartyStorage has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetPartyStorage has an error
UE_LOG(LogTemp, Log, TEXT("Error GetPartyStorage, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Write Party Data

Write Party Data is an exclusive feature for the game server. In writing party data, it can occur that multiple servers write to the same party at the same time. To avoid this, our SDK has a timestamp in the backend to ensure that the latest write data will never be overwritten with older data.

FString PartyId = "0123456789";  
FRegistry::ServerLobby.WritePartyStorage(PartyId, [](FJsonObjectWrapper PartyStorageData)
{
// ... Do something with the PartyStorageData then return the modified value ...
return PartyStorageData;
},
THandler<FAccelByteModelsPartyDataNotif>::CreateLambda([](FAccelByteModelsPartyDataNotif notifResult)
{
UE_LOG(LogAccelByteServerLobbyTest, Log, TEXT("Write Party Storage Success"));
}),
FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
UE_LOG(LogAccelByteServerLobbyTest, Log, TEXT("Can't write party storage. Error code: %d\nError message:%s"), ErrorCode, *ErrorMessage);
}));
  • Learn about our Chat service, which let’s party members interact with each other.
  • Players can form parties with their friends if you integrate our Friends service into your game.