Party
Overview
AccelByte Cloud's 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.
- 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 Invitation allows players to reject a party invitation. The inviter will be notified that their invitation was rejected.
- Promote a Member to Party Leader allows players to set another player as the party leader.
- Kick Party allows party leaders to remove another player from their party.
- 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.
Permissions
Permissions are used to grant access to specific resources within our services. Make sure your account has the following permissions before you attempt to manage a party in the Admin Portal.
Usage | Resource | Action |
---|---|---|
Admin Get All Parties | ADMIN:NAMESPACE:{namespace}:PARTY:STORAGE | Read |
Admin Get Party Data | ADMIN:NAMESPACE:{namespace}:PARTY:STORAGE | Read |
Update Party Attributes | ADMIN:NAMESPACE:{namespace}:PARTY:STORAGE | Update |
Admin Get User Party Data | ADMIN:NAMESPACE:{namespace}:PARTY:STORAGE | Read |
Permissions work slightly differently depending on whether they are assigned to IAM Clients or Roles assigned to users. For more information, read the Authentication and Authorization documentation.
Implement Party Interactions using the Client SDKs
Create a Party
Players can create a party that can be used for matchmaking. A player can only create one party at a time and will become the leader of the party they create.
- Unreal Engine
- Unity
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();
//Create Party
PartyInfo partyInfo;
var lobby = AccelBytePlugin.GetLobby();
lobby.CreateParty(result =>
{
if(result.IsError)
{
Debug.Log("Error. Code: " + result.Error.Code + ", Reason: " + result.Error.Message);
}
else
{
partyInfo = result.Value;
Debug.Log("Successfully create a party");
}
});
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.
- Unreal Engine
- Unity
FRegistry::Lobby.SetInvitePartyResponseDelegate(Lobby::FPartyInviteResponse::CreateLambda([](FAccelByteModelsPartyInviteResponse result)
{
UE_LOG(LogAccelByteLobbyTest, Log, TEXT("Invite Party Success!"));
})
);
const FString InvitedPlayerId = “a1b2c3d4e5”;
FRegistry::Lobby.SendInviteToPartyRequest(InvitedPlayerId);
//Invite Party
string inviteeUserId = “987654321”;
lobby.InviteToParty(inviteeUserId, result =>
{
if(result.IsError)
{
Debug.Log("Error. Code: " + result.Error.Code + ", Reason: " + result.Error.Message);
}
else
{
Debug.Log("Successfully invite an invitee");
}
});
//Notification: invited notification
//This notification will be received by the invitee
PartyInvitation partyInvitation;
lobby.InvitedToParty += result
{
if(!result.IsError)
{
partyInvitation = result.Value;
Debug.Log(“[Notification] Invited by:” + result.Value.from);
}
};
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.
- Unreal Engine
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.
- Unreal Engine
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.
- Unreal Engine
FRegistry::Lobby.SetPartyGetCodeResponseDelegate(
Api::Lobby::FAccelByteModelsPartyGetCodeResponse ::CreateLambda([](FAccelByteModelsPartyGetCodeResponse Response)
{
// Handle result.PartyCode here
}));
FRegistry::Lobby.SendPartyGetCodeRequest();
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.
- Unreal Engine
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.
- Unreal Engine
- Unity
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!"));
}
}));
//Join a Party
lobby.JoinParty(partyInvitation.partyID, partyInvitation.invitationToken, result =>
{
if(result.IsError)
{
Debug.Log("Error. Code: " + result.Error.Code + ", Reason: " + result.Error.Message);
}
else
{
Debug.Log("Successfully join a party");
}
});
//Notification: joined from party notification
//This notification will be received by the member of the party
lobby.JoinedParty += result
{
if(!result.IsError)
{
Debug.Log(“[Notification] Invitee join a party”);
}
};
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.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetInvitePartyRejectResponseDelegate(AccelByte::Api::Lobby::FPartyRejectResponse::CreateLambda([](const FAccelByteModelsPartyRejectResponse& Result)
{
if (Result.Code == "0")
{
// Do something if InvitePartyRejectResponseDelegate has been successful
}
else
{
// Do something if InvitePartyRejectResponseDelegate has an error
}
}));
FString PartyId = FString("SomePartyId");
FString InvitationToken = FString("SomeInvitationToken");
FRegistry::Lobby.SendRejectInvitationRequest(PartyId, InvitationToken);
string partyId = "SomePartyId";
string invitationToken = "SomeInvitationToken";
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().RejectPartyInvitation(partyId, invitationToken, result =>
{
if (result.IsError)
{
// Do something if RejectPartyInvitation has an error
Debug.Log($"Error RejectPartyInvitation, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if RejectPartyInvitation has been successful
}
});
Promote a 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.
This is how the party leader can promote another party member to become a new party leader. The new party leader is identified by a specific user id from a party member.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetPartyPromoteLeaderResponseDelegate(AccelByte::Api::Lobby::FPartyPromoteLeaderResponse::CreateLambda([](const FAccelByteModelsPartyPromoteLeaderResponse& Result)
{
if (Result.Code == "0")
{
// Do something if PartyPromoteLeaderResponseDelegate has been successful
}
else
{
// Do something if PartyPromoteLeaderResponseDelegate has an error
}
}));
FString UserId = FString("SomeUserId");
FRegistry::Lobby.SendPartyPromoteLeaderRequest(UserId);
string userId = "SomeUserId";
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().PromotePartyLeader(userId, result =>
{
if (result.IsError)
{
// Do something if PromotePartyLeader has an error
Debug.Log($"Error PromotePartyLeader, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if PromotePartyLeader has been successful
}
});
Kick a 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. The kicked party member 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.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetInvitePartyKickMemberResponseDelegate(AccelByte::Api::Lobby::FPartyKickResponse::CreateLambda([](const FAccelByteModelsKickPartyMemberResponse& Result)
{
if (Result.Code == "0")
{
// Do something if InvitePartyKickMemberResponseDelegate has been successful
}
else
{
// Do something if InvitePartyKickMemberResponseDelegate has an error
}
}));
FString UserId = FString("SomeUserId");
FRegistry::Lobby.SendKickPartyMemberRequest(UserId);
string userId = "SomeUserId";
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().KickPartyMember(userId, result =>
{
if (result.IsError)
{
// Do something if KickPartyMember has an error
Debug.Log($"Error KickPartyMember, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if KickPartyMember has been successful
}
});
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.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetLeavePartyResponseDelegate(AccelByte::Api::Lobby::FPartyLeaveResponse::CreateLambda([](const FAccelByteModelsLeavePartyResponse& Result)
{
if (Result.Code == "0")
{
// Do something if LeavePartyResponseDelegate has been successful
}
else
{
// Do something if LeavePartyResponseDelegate has an error
}
}));
FRegistry::Lobby.SendLeavePartyRequest();
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().LeaveParty(result =>
{
if (result.IsError)
{
// Do something if LeaveParty has an error
Debug.Log($"Error LeaveParty, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if LeaveParty has been successful
}
});
Implement Party Notifications using the Client SDKs
Invite a Player
This is how the invited player will get notification after the other player requests an invite party to the player that will get the notification.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetPartyGetInvitedNotifDelegate(AccelByte::Api::Lobby::FPartyGetInvitedNotif::CreateLambda([](const FAccelByteModelsPartyGetInvitedNotice& Result)
{
// Do something if PartyGetInvitedNotifDelegate has been successful
}));
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().InvitedToParty += result =>
{
if (result.IsError)
{
// Do something if InvitedToParty has an error
Debug.Log($"Error InvitedToParty, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if InvitedToParty has been successful
}
};
Join a Party
When someone joins the party, the player inside the party will get some notification that there are some new party members inside the party.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetPartyJoinNotifDelegate(AccelByte::Api::Lobby::FPartyJoinNotif::CreateLambda([](const FAccelByteModelsPartyJoinNotice& Result)
{
// Do something if PartyJoinNotifDelegate has been successful
}));
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().JoinedParty += result =>
{
if (result.IsError)
{
// Do something if JoinedParty has an error
Debug.Log($"Error JoinedParty, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if JoinedParty has been successful
}
};
Reject a Party Notification
This is how the player party member and party leader will get notification after the invitation player rejects the invitation request.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetPartyInvitationRejectedNotifDelegate(AccelByte::Api::Lobby::FPartyRejectNotif::CreateLambda([](const FAccelByteModelsPartyRejectNotice& Result)
{
// Do something if PartyInvitationRejectedNotifDelegate has been successful
}));
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().RejectedPartyInvitation += result =>
{
if (result.IsError)
{
// Do something if RejectedPartyInvitation has an error
Debug.Log($"Error RejectedPartyInvitation, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if RejectedPartyInvitation has been successful
}
};
Promote a Party Leader
When there is some update from the party info data like promoting a new party leader, all party members including party leader will get a notification and get new information about the party.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetPartyDataUpdateNotifDelegate(AccelByte::Api::Lobby::FPartyDataUpdateNotif::CreateLambda([](const FAccelByteModelsPartyDataNotif& Result)
{
// Do something if PartyDataUpdateNotifDelegate has been successful
}));
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().PartyDataUpdateNotif += result =>
{
if (result.IsError)
{
// Do something if PartyDataUpdateNotif has an error
Debug.Log($"Error PartyDataUpdateNotif, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if PartyDataUpdateNotif has been successful
}
};
Kick a Party Member
Kick some party members will send a notification for all player members and party leaders that are still in the party.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetPartyKickNotifDelegate(AccelByte::Api::Lobby::FPartyKickNotif::CreateLambda([](const FAccelByteModelsGotKickedFromPartyNotice& Result)
{
// Do something if PartyKickNotifDelegate has been successful
}));
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().KickedFromParty += result =>
{
if (result.IsError)
{
// Do something if KickedFromParty has an error
Debug.Log($"Error KickedFromParty, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if KickedFromParty has been successful
}
};
Leave a Party
For other players that are still at the party, they will get a notification after some players leave from the party. Call this delegate function to get a notification when some party member leaves the party.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetPartyLeaveNotifDelegate(AccelByte::Api::Lobby::FPartyLeaveNotif::CreateLambda([](const FAccelByteModelsLeavePartyNotice& Result)
{
// Do something if PartyLeaveNotifDelegate has been successful
}));
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().LeaveFromParty += result =>
{
if (result.IsError)
{
// Do something if LeaveFromParty has an error
Debug.Log($"Error LeaveFromParty, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if LeaveFromParty has been successful
}
};
Implement 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 notifications from the server.
Party Data Update Notifications
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.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetPartyDataUpdateNotifDelegate(AccelByte::Api::Lobby::FPartyDataUpdateNotif::CreateLambda([](const FAccelByteModelsPartyDataNotif& Result)
{
// Do something if PartyDataUpdateNotifDelegate has been successful
}));
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().PartyDataUpdateNotif += result =>
{
if (result.IsError)
{
// Do something if PartyDataUpdateNotif has an error
Debug.Log($"Error PartyDataUpdateNotif, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if PartyDataUpdateNotif has been successful
}
};
Retrieve 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.
- Unreal Engine
- Unity
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);
}));
string partyId = "SomePartyid";
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().GetPartyStorage(partyId, result =>
{
if (result.IsError)
{
// Do something if GetPartyStorage has an error
Debug.Log($"Error GetPartyStorage, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if GetPartyStorage has been successful
}
});
Retrieve 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.
- Unreal Engine
- Unity
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);
}));
string partyId = "SomePartyId";
AccelBytePlugin.GetLobby().Connect();
AccelByteServerPlugin.GetLobby().GetPartyStorage(partyId, result =>
{
if (result.IsError)
{
// Do something if GetPartyStorage has an error
Debug.Log($"Error GetPartyStorage, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if GetPartyStorage has been successful
}
});
Write Party Data
Write Party Data is an exclusive feature for the game server. It's possible that multiple servers can 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.
This function you can modify from Previous Data that we called oldPartyData that you can get from the lambda or even you can input your own new Party Data.
- Unreal Engine
- Unity
FString PartyId = FString("SomePartyId");
FRegistry::ServerLobby.WritePartyStorage(PartyId, [](FJsonObjectWrapper OldPartyData)
{
// You can choose either to create new PartyDataStorage or modified from OldPartyDataStorage
/*FJsonObjectWrapper NewPartyData;
TSharedPtr<FJsonObject> MyNewJsonValue;
MyNewJsonValue->SetStringField(FString("MyNewFieldName"), FString("MyNewStringValue"));
NewPartyData.JsonObject->SetObjectField(FString("NewField"), MyNewJsonValue);
return NewPartyData;*/
FJsonObjectWrapper ModifiedPartyData = OldPartyData;
TSharedPtr<FJsonObject> MyNewJsonValue;
MyNewJsonValue->SetStringField(FString("MyNewFieldName"), FString("MyNewStringValue"));
ModifiedPartyData.JsonObject->SetObjectField(FString("NewField"), MyNewJsonValue);
return OldPartyData;
}, THandler<FAccelByteModelsPartyDataNotif>::CreateLambda([](const FAccelByteModelsPartyDataNotif& Result)
{
// Do something if WritePartyStorage has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString ErrorMessage)
{
// Do something if WritePartyStorage has an error
UE_LOG(LogTemp, Log, TEXT("Error WritePartyStorage, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
string partyId = "SomePartyId";
AccelByteServerPlugin.GetLobby().WritePartyStorage(partyId,
result =>
{
if (result.IsError)
{
// Do something if WritePartyStorage has an error
Debug.Log($"Error WritePartyStorage, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if WritePartyStorage has been successful
}
},
oldPartyData =>
{
// You can modify oldPartyData or you can input your new party data
/*Dictionary<string, object> newPartyData = null;
newPartyData.Add("newKey", "newValue");
return newPartyData;*/
Dictionary<string, object> modifiedOldPartyData = oldPartyData;
modifiedOldPartyData.Add("newKey", "newValue");
return modifiedOldPartyData;
});
Related Concepts
- For more information about the Party service, you can access this API Reference.
- Learn about our Chat service, which lets 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.