Party

Overview

The AccelByte Lobby Service includes Party features to 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 the list of Party Members.
  • Create Party allows players to create a new party that other players can join.
  • Leave Party allows players to leave a party that they have already joined. The other party members will be notified when a player leaves their party.
  • Invite 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 Invitation allows players to reject a party invitation. The inviter will be notified that their invitation was rejected.
  • Kick Party allows party leaders to remove another player from their party.

Tutorials

Create a Party

You can create a party that can be used for matchmaking. A player can only create one party, and the player who made the party will become the party leader.

var lobby = AccelBytePlugin.GetLobby();
lobby.Connect();
Result<PartyInfo> createPartyResult = null;
lobby.CreateParty(result => createPartyResult = result);

Invite to Party

Players can invite other players to their party. The invitees will receive a notification.

var invitedPlayerId = “a1b2c3d4e5”;
Result inviteResult = null;
lobby.InviteToParty(invitedPlayerId, result => inviteResult = result);;

Join a Party

When a player has been invited to a party, they can join that party using the Invitation Token and Party ID.

Result<PartyInvitation> invitedToPartyResult = null;
lobby.InvitedToParty += result => {
invitedToPartyResult = result;
lobby.JoinParty(
invitedToPartyResult.Value.partyID,
invitedToPartyResult.Value.invitationToken,
result => joinPartyResult = result);
};

Reject Party Invitation

When a player has been invited to a party, they can choose to reject that invitation. A callback can be registered so that the inviter receives a notification when a player rejects their invitation.

Result<PartyInvitation> invitedToPartyResult = null;
lobby.InvitedToParty += result => {
invitedToPartyResult = result;
lobby.RejectPartyInvitation(
invitedToPartyResult.Value.partyID,
invitedToPartyResult.Value.invitationToken,
result => Debug.Log("Invitation Rejected!"));
};
//Inviter - Reject notification
lobby.RejectedPartyInvitation += result =>
{
Debug.Log("Your invitation has been rejected by " + result.Value.userID);
}

Kick Players From a Party

The Party leader has the privilege to remove a party member from their party by kicking them out of the party.

var kickedPlayerId = “a1b2c3d4e5”;
Result kickResult = null;
lobby.KickPartyMember(kickedPlayerId, result => kickResult = result);

Leave a Party

Players can leave a party in order to stop playing or to join another party. To do so, players should leave the current party.

Result leavePartyResult = null;
lobby.LeaveParty(result => leavePartyResult = result);

Party Storage

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 the party.

Result<PartyDataUpdateNotif> partyDataNotifResult = null;
lobby.PartyDataUpdateNotif += result => partyDataNotifResult = result;

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.

Result<PartyDataUpdateNotif> getPartyStorageResult = null;
AccelBytePlugin.GetLobby().GetPartyStorage(getPartyInfoResult.Value.partyID, result => getPartyStorageResult = result );

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.

Result<PartyDataUpdateNotif> getPartyStorageResult = null;
AccelByteServerPlugin.GetLobby().GetPartyStorage(getPartyInfoResult.Value.partyID, result => getPartyStorageResult = result );

Retrieve Active Parties

This function will retrieve active parties from the game server side. The game server must be authenticated to allow this API call.There are two types of functions you can use to retrieve active parties:

In the first function, you can define the limit and offset in the beginning.

int limit = 50; // the amount of party that returned from one call
int offset = 0; //the index of the query active parties. 0 is the first item in the first page
Result<ActivePartiesData> getActivePartiesResult = null;
AccelByteServerPlugin.GetLobby().GetActiveParties(limit, offset, result => getActivePartiesResult = result);

In the second function, you can retrieve the active party on the next page using the previous pagination.

Result<ActivePartiesData> getActivePartiesResult1 = null;
AccelByteServerPlugin.GetLobby().GetActiveParties(50, 0, result => getActivePartiesResult1 = result);
// Retrieve the next page
Result<ActivePartiesData> getActivePartiesResult2 = null;
AccelByteServerPlugin.GetLobby().GetActiveParties(getActivePartiesResult1.Value.paging, PaginationType.NEXT, result => getActivePartiesResult2 = result);

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.

string partyID = “0123456789”; //example
AccelByteServerPlugin.GetLobby().WritePartyStorage(partyID, result =>
{
Interlocked.Increment(ref serverUpdateDone);
if (!result.IsError)
{
Interlocked.Increment(ref serverUpdateSuccessCount);
}
},
oldData =>
{
//perform modification to the existing party storage (oldData)
oldData.Add($"key_{dictIndex}", dictIndex);
return oldData;
});

What’s Next?

  • For more information about the Party service, you can access this API Reference.
  • Learn about our Chat service, which let’s party members interact with each other.
  • Check out our Matchmaking guide to see how parties can be matched to play against each other.
  • Players can form parties with their friends if you integrate our Friends service into your game.