Lobby

Overview

AccelByte lobby services provide continuous connection between the players and the game by using WebSocket. WebSocket ensures reliable, real-time data transfer by allowing two-way communication between the server and clients. Our lobby includes the following services:

  1. Presence enables players to see what other players are doing in real-time. This feature is critical in online multiplayer games, because player interactions rely on knowing which players are available.
  2. Party is used as the basis for multiplayer matchmaking. The party can be integrated with other lobby services such as presence, friends, and chat, to enrich the multiplayer experience.
  3. Friends lets players connect and interact with each other. AccelByte supports both in-game friends and platform or launcher level friends. In-game friends can chat and play together within a game title, whereas platform level friends allows players of different games to interact with each other.
  4. Chat enables real-time text based communication in-game. We support global, party, and individual chat.
  5. Matchmaking is responsible for matching multiple players based on the selected matchmaking channel configurations.

Tutorials

Connect to Lobby

Before you can use social services, you must set up a lobby connection by using the command below.

var lobby = AccelBytePlugin.GetLobby();
lobby.Connect();

Once you have set up a lobby connection, you will be able to use other Social features such as user presence.

Handle the Connect / Disconnect Event

This feature notifies the game of any changes to the connection to the Lobby server. The SDK already provides an auto-reconnect mechanism, but when the auto-reconnect times out you must reconnect manually.

var lobby = AccelBytePlugin.GetLobby();
lobby.Connect();
lobby.Connected += () =>
{
// doing something when connected, for example: update UI status to online
};
lobby.Disconnected += () =>
{
// doing something when disconnected, for example: update UI status to offline
};

Block a Player

Blocking allows players to restrict other players from interacting with them. When one player blocks another, both players are prevented from interacting with each other in the following ways:

  • Adding the other as a friend. If the players are already friends, they will be unfriended.
  • Sending or receiving messages to or from each other.
  • Seeing each other’s messages in global chat rooms.
  • Inviting each other to parties.
  • Meeting each other in matches.
  • Being in the same party, unless they were both invited by a 3rd player. Please note that should this occur, the blocking and blocked players will be able to interact with each other in the Party chat.
  • Inviting each other to join groups.
  • Seeing each other’s player profile in group member lists.

Blocked players cannot see the profile of the blocking player, and blocked players receive no notification regarding the block. See the tutorials below to implement player blocking using the SDK.

Blocking a player can be done by calling BlockPlayer(userId, callback). The callback from this method will return the blocked player’s user ID.

Lobby lobby = AccelBytePlugin.GetLobby();
lobby.BlockPlayer(/*player user id*/, blockResult =>
{
if(blockResult.IsError)
{
// blocking error
Debug.Log("Block error " + blockResult.Error.Code + " msg " + blockResult.Error.Message);
}
else
{
// blocking success
Debug.Log("Success blocking " + blockResult.Value.blockedUserId);
}
});

Listen to Player Blocking Events

Sometimes the game needs to know if a player is being blocked by another player. Blocking events can be tracked by subscribing to the PlayerBlockedNotif event. The event will be raised on the blocked player side and will pass data that contains the blocking player’s user ID and the blocked player’s user ID.

Lobby lobby = AccelBytePlugin.GetLobby();
lobby.PlayerBlockedNotif += (data) =>
{
Debug.Log(data.Value.userId + " is blocking " + data.Value.blockedUserId);
};

Unblocking a Player

Unblocking a player can be done by calling the method UnblockPlayer(userId, callback). The callback from this method will return the unblocked player’s user ID in the Value field.

Lobby lobby = AccelBytePlugin.GetLobby();
lobby.UnblockPlayer(/*player user id*/, unblockResult =>
{
if (unblockResult.IsError)
{
// unblocking error
Debug.Log("Unblock error " + unblockResult.Error.Code + " msg " + unblockResult.Error.Message);
}
else
{
// unblocking success
Debug.Log("Success Unblocking " + unblockResult.Value.unblockedUserId);
}
});

Listen to Player Unblocked Events

Just like the Player Blocked Event, the PlayerUnblockedNotif event will be raised on the unblocked player’s side, and will pass data that contains the unblocking player’s User ID and the unblocked player’s User ID.

Lobby lobby = AccelBytePlugin.GetLobby();
lobby.PlayerUnblockedNotif += (data) =>
{
Debug.Log(data.Value.userId + " is unblocking " + data.Value.unblockedUserId);
};

Get List of Blocked Players

To retrieve the list of currently blocked players, call the GetListOfBlockedUser method. This method has a callback that returns an array of BlockedData that contains the blocked players’ User IDs and the timestamp for each block.

Lobby lobby = AccelBytePlugin.GetLobby();
lobby.GetListOfBlockedUser(listResult =>
{
if (listResult.IsError)
{
Debug.Log("get list error " + listResult.Error.Code + " msg " + listResult.Error.Message);
}
else
{
string s = "Blocked List\n";
foreach(BlockedData data in listResult.Value.data)
{
s += data.blockedUserId + " blocked at time " + data.blockedAt + "\n";
}
Debug.Log(s);
}
});

Get List of Blocking Players

To retrieve a list of players that have blocked other players, call the GetListOfBlocker method. This method has a callback that returns an array of BlockerData that contains the blocking players’ User IDs and a timestamp for each block.

Lobby lobby = AccelBytePlugin.GetLobby();
lobby.GetListOfBlocker(listResult =>
{
if (listResult.IsError)
{
Debug.Log("get list error " + listResult.Error.Code + " msg " + listResult.Error.Message);
}
else
{
string s = "Blocked by...\n";
foreach (BlockerData data in listResult.Value.data)
{
s += data.userId + " blocked at time " + data.blockedAt + "\n";
}
Debug.Log(s);
}
});

What’s Next?

  • Check out the API Reference for more information about Lobby services.