|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using LobbyRelaySample.lobby; |
|
|
|
using Unity.Services.Authentication; |
|
|
|
using Unity.Services.Lobbies; |
|
|
|
using Unity.Services.Lobbies.Models; |
|
|
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// Manages one Lobby at a time, Only entry points to a lobby with ID is via JoinAsync, CreateAsync, and QuickJoinAsync
|
|
|
|
public class LobbyManager |
|
|
|
public class LobbyManager : IDisposable |
|
|
|
const string key_RelayCode = nameof(LocalLobby.RelayCode); |
|
|
|
const string key_LobbyState = nameof(LocalLobby.LocalLobbyState); |
|
|
|
const string key_LobbyColor = nameof(LocalLobby.LocalLobbyColor); |
|
|
|
|
|
|
|
const string key_Displayname = nameof(LocalPlayer.DisplayName); |
|
|
|
const string key_Userstatus = nameof(LocalPlayer.UserStatus); |
|
|
|
const string key_Emote = nameof(LocalPlayer.Emote); |
|
|
|
|
|
|
|
public event Action OnKicked; |
|
|
|
public Lobby CurrentLobby => m_CurrentLobby; |
|
|
|
LocalLobby m_CurrentLocalLobby; |
|
|
|
LobbyEventCallbacks m_LobbyEventCallbacks = new LobbyEventCallbacks(); |
|
|
|
const int |
|
|
|
k_maxLobbiesToShow = 16; // If more are necessary, consider retrieving paginated results or using filters.
|
|
|
|
|
|
|
//We dont want to queue a quickjoin
|
|
|
|
if (m_QuickJoinCooldown.IsCoolingDown) |
|
|
|
{ |
|
|
|
Debug.LogWarning("Quick Join Lobby hit the rate limit."); |
|
|
|
UnityEngine.Debug.LogWarning("Quick Join Lobby hit the rate limit."); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
return await LobbyService.Instance.QueryLobbiesAsync(queryOptions); |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<Lobby> GetLobbyAsync(string lobbyId = null) |
|
|
|
public async Task BindLocalLobbyToRemote(string lobbyID, LocalLobby localLobby) |
|
|
|
{ |
|
|
|
m_LobbyEventCallbacks.LobbyChanged += async changes => |
|
|
|
{ |
|
|
|
if (changes.LobbyDeleted) |
|
|
|
{ |
|
|
|
await LeaveLobbyAsync(); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
//Lobby Fields
|
|
|
|
if (changes.Name.Changed) |
|
|
|
localLobby.LobbyName.Value = changes.Name.Value; |
|
|
|
if (changes.HostId.Changed) |
|
|
|
localLobby.HostID.Value = changes.HostId.Value; |
|
|
|
if (changes.IsPrivate.Changed) |
|
|
|
localLobby.Private.Value = changes.IsPrivate.Value; |
|
|
|
if (changes.IsLocked.Changed) |
|
|
|
localLobby.Locked.Value = changes.IsLocked.Value; |
|
|
|
if (changes.AvailableSlots.Changed) |
|
|
|
localLobby.AvailableSlots.Value = changes.AvailableSlots.Value; |
|
|
|
if (changes.MaxPlayers.Changed) |
|
|
|
localLobby.MaxPlayerCount.Value = changes.MaxPlayers.Value; |
|
|
|
|
|
|
|
if (changes.LastUpdated.Changed) |
|
|
|
localLobby.LastUpdated.Value = changes.LastUpdated.Value.ToFileTimeUtc(); |
|
|
|
|
|
|
|
//Custom Lobby Fields
|
|
|
|
if (changes.Data.Changed) |
|
|
|
LobbyChanged(); |
|
|
|
|
|
|
|
if (changes.PlayerJoined.Changed) |
|
|
|
PlayersJoined(); |
|
|
|
|
|
|
|
if (changes.PlayerLeft.Changed) |
|
|
|
PlayersLeft(); |
|
|
|
|
|
|
|
if (changes.PlayerData.Changed) |
|
|
|
PlayerDataChanged(); |
|
|
|
|
|
|
|
void LobbyChanged() |
|
|
|
{ |
|
|
|
foreach (var change in changes.Data.Value) |
|
|
|
{ |
|
|
|
var changedValue = change.Value; |
|
|
|
var changedKey = change.Key; |
|
|
|
|
|
|
|
if (changedValue.Removed) |
|
|
|
{ |
|
|
|
RemoveCustomLobbyData(changedKey); |
|
|
|
} |
|
|
|
|
|
|
|
if (changedValue.Changed) |
|
|
|
{ |
|
|
|
ParseCustomLobbyData(changedKey, changedValue.Value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void RemoveCustomLobbyData(string changedKey) |
|
|
|
{ |
|
|
|
if (changedKey == key_RelayCode) |
|
|
|
localLobby.RelayCode.Value = ""; |
|
|
|
} |
|
|
|
|
|
|
|
void ParseCustomLobbyData(string changedKey, DataObject playerDataObject) |
|
|
|
{ |
|
|
|
if (changedKey == key_RelayCode) |
|
|
|
localLobby.RelayCode.Value = playerDataObject.Value; |
|
|
|
|
|
|
|
if (changedKey == key_LobbyState) |
|
|
|
localLobby.LocalLobbyState.Value = (LobbyState)int.Parse(playerDataObject.Value); |
|
|
|
|
|
|
|
if (changedKey == key_LobbyColor) |
|
|
|
localLobby.LocalLobbyColor.Value = (LobbyColor)int.Parse(playerDataObject.Value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void PlayersJoined() |
|
|
|
{ |
|
|
|
foreach (var playerChanges in changes.PlayerJoined.Value) |
|
|
|
{ |
|
|
|
Player joinedPlayer = playerChanges.Player; |
|
|
|
|
|
|
|
var id = joinedPlayer.Id; |
|
|
|
var index = playerChanges.PlayerIndex; |
|
|
|
var isHost = localLobby.HostID.Value == id; |
|
|
|
|
|
|
|
var newPlayer = new LocalPlayer(id, index, isHost); |
|
|
|
|
|
|
|
foreach (var dataEntry in joinedPlayer.Data) |
|
|
|
{ |
|
|
|
var dataObject = dataEntry.Value; |
|
|
|
ParseCustomPlayerData(newPlayer, dataEntry.Key, dataObject.Value); |
|
|
|
} |
|
|
|
|
|
|
|
localLobby.AddPlayer(index, newPlayer); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void PlayersLeft() |
|
|
|
{ |
|
|
|
foreach (var leftPlayerIndex in changes.PlayerLeft.Value) |
|
|
|
{ |
|
|
|
localLobby.RemovePlayer(leftPlayerIndex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void PlayerDataChanged() |
|
|
|
{ |
|
|
|
foreach (var lobbyPlayerChanges in changes.PlayerData.Value) |
|
|
|
{ |
|
|
|
var playerIndex = lobbyPlayerChanges.Key; |
|
|
|
var localPlayer = localLobby.GetLocalPlayer(playerIndex); |
|
|
|
if (localPlayer == null) |
|
|
|
continue; |
|
|
|
var playerChanges = lobbyPlayerChanges.Value; |
|
|
|
if (playerChanges.ConnectionInfoChanged.Changed) |
|
|
|
{ |
|
|
|
var connectionInfo = playerChanges.ConnectionInfoChanged.Value; |
|
|
|
Debug.Log( |
|
|
|
$"ConnectionInfo for player {playerIndex} changed to {connectionInfo}"); |
|
|
|
} |
|
|
|
|
|
|
|
if (playerChanges.LastUpdatedChanged.Changed) { } |
|
|
|
|
|
|
|
//There are changes on the Player
|
|
|
|
if (playerChanges.ChangedData.Changed) |
|
|
|
{ |
|
|
|
foreach (var playerChange in playerChanges.ChangedData.Value) |
|
|
|
{ |
|
|
|
var changedValue = playerChange.Value; |
|
|
|
|
|
|
|
//There are changes on some of the changes in the player list of changes
|
|
|
|
|
|
|
|
if (changedValue.Changed) |
|
|
|
{ |
|
|
|
if (changedValue.Removed) |
|
|
|
{ |
|
|
|
Debug.LogWarning("This Sample does not remove Player Values currently."); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
var playerDataObject = changedValue.Value; |
|
|
|
ParseCustomPlayerData(localPlayer, playerChange.Key, playerDataObject.Value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
m_LobbyEventCallbacks.LobbyEventConnectionStateChanged += lobbyEventConnectionState => |
|
|
|
{ |
|
|
|
Debug.Log($"Lobby ConnectionState Changed to {lobbyEventConnectionState}"); |
|
|
|
}; |
|
|
|
|
|
|
|
m_LobbyEventCallbacks.KickedFromLobby += () => |
|
|
|
{ |
|
|
|
Debug.Log("Left Lobby"); |
|
|
|
Dispose(); |
|
|
|
}; |
|
|
|
await LobbyService.Instance.SubscribeToLobbyEventsAsync(lobbyID, m_LobbyEventCallbacks); |
|
|
|
} |
|
|
|
|
|
|
|
void ParseCustomPlayerData(LocalPlayer player, string dataKey, string playerDataValue) |
|
|
|
if (m_GetLobbyCooldown.TaskQueued) |
|
|
|
return null; |
|
|
|
await m_GetLobbyCooldown.QueueUntilCooldown(); |
|
|
|
if (dataKey == key_Emote) |
|
|
|
player.Emote.Value = (EmoteType)int.Parse(playerDataValue); |
|
|
|
else if (dataKey == key_Userstatus) |
|
|
|
player.UserStatus.Value = (PlayerStatus)int.Parse(playerDataValue); |
|
|
|
else if (dataKey == key_Displayname) |
|
|
|
player.DisplayName.Value = playerDataValue; |
|
|
|
} |
|
|
|
public async Task<Lobby> GetLobbyAsync(string lobbyId = null) |
|
|
|
{ |
|
|
|
|
|
|
|
await m_GetLobbyCooldown.QueueUntilCooldown(); |
|
|
|
return await LobbyService.Instance.GetLobbyAsync(lobbyId); |
|
|
|
return m_CurrentLobby = await LobbyService.Instance.GetLobbyAsync(lobbyId); |
|
|
|
if (m_LeaveLobbyOrRemovePlayer.IsCoolingDown) |
|
|
|
return; |
|
|
|
await LobbyService.Instance.RemovePlayerAsync(m_CurrentLobby.Id, AuthenticationService.Instance.PlayerId); |
|
|
|
Debug.Log("Left Lobby!"); |
|
|
|
string playerId = AuthenticationService.Instance.PlayerId; |
|
|
|
|
|
|
|
await LobbyService.Instance.RemovePlayerAsync(m_CurrentLobby.Id, playerId); |
|
|
|
Dispose(); |
|
|
|
string playerId = AuthenticationService.Instance.PlayerId; |
|
|
|
if (!InLobby()) |
|
|
|
return; |
|
|
|
string playerId = AuthenticationService.Instance.PlayerId; |
|
|
|
PlayerDataObject dataObj = new PlayerDataObject( |
|
|
|
visibility: PlayerDataObject.VisibilityOptions.Member, |
|
|
|
PlayerDataObject dataObj = new PlayerDataObject(visibility: PlayerDataObject.VisibilityOptions.Member, |
|
|
|
|
|
|
|
if (dataCurr.ContainsKey(dataNew.Key)) |
|
|
|
dataCurr[dataNew.Key] = dataObj; |
|
|
|
else |
|
|
|
|
|
|
return; |
|
|
|
await m_UpdatePlayerCooldown.QueueUntilCooldown(); |
|
|
|
|
|
|
|
if (!InLobby()) |
|
|
|
return; |
|
|
|
UpdatePlayerOptions updateOptions = new UpdatePlayerOptions |
|
|
|
{ |
|
|
|
Data = dataCurr, |
|
|
|
|
|
|
Debug.Log($"SENDING : {dataCurr[LobbyConverters.key_Displayname].Value}'s Data" + |
|
|
|
$" TO : \n {m_CurrentLocalLobby}"); |
|
|
|
await LobbyService.Instance.UpdatePlayerAsync(m_CurrentLobby.Id, playerId, updateOptions); |
|
|
|
m_CurrentLobby = await LobbyService.Instance.UpdatePlayerAsync(m_CurrentLobby.Id, playerId, updateOptions); |
|
|
|
} |
|
|
|
|
|
|
|
public async Task UpdatePlayerRelayInfoAsync(string lobbyID, string allocationId, string connectionInfo) |
|
|
|
|
|
|
AllocationId = allocationId, |
|
|
|
ConnectionInfo = connectionInfo |
|
|
|
}; |
|
|
|
await LobbyService.Instance.UpdatePlayerAsync(lobbyID, playerId, updateOptions); |
|
|
|
m_CurrentLobby = await LobbyService.Instance.UpdatePlayerAsync(lobbyID, playerId, updateOptions); |
|
|
|
if (!InLobby()) |
|
|
|
return; |
|
|
|
|
|
|
|
Dictionary<string, DataObject> dataCurr = m_CurrentLobby.Data ?? new Dictionary<string, DataObject>(); |
|
|
|
|
|
|
|
var shouldLock = false; |
|
|
|
|
|
|
dataCurr.Add(dataNew.Key, dataObj); |
|
|
|
|
|
|
|
//Special Use: Get the state of the Local lobby so we can lock it from appearing in queries if it's not in the "Lobby" LocalLobbyState
|
|
|
|
if (dataNew.Key == LobbyConverters.key_LobbyState) |
|
|
|
if (dataNew.Key == "LocalLobbyState") |
|
|
|
{ |
|
|
|
Enum.TryParse(dataNew.Value, out LobbyState lobbyState); |
|
|
|
shouldLock = lobbyState != LobbyState.Lobby; |
|
|
|
|
|
|
return; |
|
|
|
await m_UpdateLobbyCooldown.QueueUntilCooldown(); |
|
|
|
|
|
|
|
if (!InLobby()) |
|
|
|
return; |
|
|
|
|
|
|
|
Debug.Log($"Updating Data in {m_CurrentLocalLobby}"); |
|
|
|
await LobbyService.Instance.UpdateLobbyAsync(m_CurrentLobby.Id, updateOptions); |
|
|
|
m_CurrentLobby = await LobbyService.Instance.UpdateLobbyAsync(m_CurrentLobby.Id, updateOptions); |
|
|
|
} |
|
|
|
|
|
|
|
public async Task DeleteLobbyAsync() |
|
|
|
|
|
|
await LobbyService.Instance.DeleteLobbyAsync(m_CurrentLobby.Id); |
|
|
|
} |
|
|
|
|
|
|
|
#region LobbyBindings
|
|
|
|
|
|
|
|
public async Task BindLocalLobbyToRemote(string lobbyID, LocalLobby localLobby) |
|
|
|
public void Dispose() |
|
|
|
m_CurrentLocalLobby = localLobby; |
|
|
|
m_CurrentLobby = null; |
|
|
|
m_LobbyEventCallbacks.LobbyChanged += ProcessLobbyChanges; |
|
|
|
m_LobbyEventCallbacks.LobbyEventConnectionStateChanged += OnStateChanged; |
|
|
|
m_LobbyEventCallbacks.KickedFromLobby += OnKickedFromLobby; |
|
|
|
|
|
|
|
await LobbyService.Instance.SubscribeToLobbyEventsAsync(lobbyID, m_LobbyEventCallbacks); |
|
|
|
void OnStateChanged(LobbyEventConnectionState newState) |
|
|
|
{ |
|
|
|
Debug.Log($"State Changed! {newState}"); |
|
|
|
} |
|
|
|
|
|
|
|
void OnKickedFromLobby() |
|
|
|
{ |
|
|
|
m_CurrentLobby = null; |
|
|
|
m_CurrentLocalLobby = null; |
|
|
|
OnKicked?.Invoke(); |
|
|
|
|
|
|
|
m_LobbyEventCallbacks.LobbyChanged -= ProcessLobbyChanges; |
|
|
|
m_LobbyEventCallbacks.KickedFromLobby -= OnKickedFromLobby; |
|
|
|
m_LobbyEventCallbacks.LobbyEventConnectionStateChanged -= OnStateChanged; |
|
|
|
} |
|
|
|
|
|
|
|
void ProcessLobbyChanges(ILobbyChanges changes) |
|
|
|
{ |
|
|
|
if (changes.LobbyDeleted) |
|
|
|
{ |
|
|
|
#pragma warning disable CS4014
|
|
|
|
LeaveLobbyAsync(); |
|
|
|
#pragma warning restore CS4014
|
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
LobbyFieldChanges(changes, m_CurrentLocalLobby); |
|
|
|
|
|
|
|
CustomLobbyChanged(changes.Data, m_CurrentLocalLobby); |
|
|
|
|
|
|
|
PlayersJoined(changes.PlayerJoined, m_CurrentLocalLobby); |
|
|
|
|
|
|
|
PlayersLeft(changes.PlayerLeft, m_CurrentLocalLobby); |
|
|
|
|
|
|
|
PlayerDataChanged(changes.PlayerData, m_CurrentLocalLobby); |
|
|
|
} |
|
|
|
|
|
|
|
void LobbyFieldChanges(ILobbyChanges changes, LocalLobby localLobby) |
|
|
|
{ |
|
|
|
if (changes.Name.Changed) |
|
|
|
localLobby.LobbyName.Value = changes.Name.Value; |
|
|
|
if (changes.HostId.Changed) |
|
|
|
localLobby.HostID.Value = changes.HostId.Value; |
|
|
|
if (changes.IsPrivate.Changed) |
|
|
|
localLobby.Private.Value = changes.IsPrivate.Value; |
|
|
|
if (changes.IsLocked.Changed) |
|
|
|
localLobby.Locked.Value = changes.IsLocked.Value; |
|
|
|
if (changes.AvailableSlots.Changed) |
|
|
|
localLobby.AvailableSlots.Value = changes.AvailableSlots.Value; |
|
|
|
if (changes.MaxPlayers.Changed) |
|
|
|
localLobby.MaxPlayerCount.Value = changes.MaxPlayers.Value; |
|
|
|
if (changes.LastUpdated.Changed) |
|
|
|
localLobby.LastUpdated.Value = changes.LastUpdated.Value.ToFileTimeUtc(); |
|
|
|
} |
|
|
|
|
|
|
|
void CustomLobbyChanged( |
|
|
|
ChangedOrRemovedLobbyValue<Dictionary<string, ChangedOrRemovedLobbyValue<DataObject>>> lobbyChanged, |
|
|
|
LocalLobby localLobby) |
|
|
|
{ |
|
|
|
if (!lobbyChanged.Changed) |
|
|
|
return; |
|
|
|
|
|
|
|
var lobbyChanges = lobbyChanged.Value; |
|
|
|
foreach (var change in lobbyChanges) |
|
|
|
{ |
|
|
|
var changedValue = change.Value; |
|
|
|
var changedKey = change.Key; |
|
|
|
|
|
|
|
if (changedValue.Removed) |
|
|
|
{ |
|
|
|
if (changedKey == LobbyConverters.key_RelayCode) |
|
|
|
localLobby.RelayCode.Value = ""; |
|
|
|
} |
|
|
|
|
|
|
|
if (changedValue.Changed) |
|
|
|
{ |
|
|
|
ParseCustomLobbyData(changedKey, changedValue.Value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ParseCustomLobbyData(string changedKey, DataObject playerDataObject) |
|
|
|
{ |
|
|
|
if (changedKey == LobbyConverters.key_RelayCode) |
|
|
|
localLobby.RelayCode.Value = playerDataObject.Value; |
|
|
|
|
|
|
|
if (changedKey == LobbyConverters.key_LobbyState) |
|
|
|
localLobby.LocalLobbyState.Value = (LobbyState)int.Parse(playerDataObject.Value); |
|
|
|
|
|
|
|
if (changedKey == LobbyConverters.key_LobbyColor) |
|
|
|
localLobby.LocalLobbyColor.Value = (LobbyColor)int.Parse(playerDataObject.Value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void PlayersJoined(ChangedLobbyValue<List<LobbyPlayerJoined>> playersJoinedChanged, LocalLobby localLobby) |
|
|
|
{ |
|
|
|
if (!playersJoinedChanged.Changed) |
|
|
|
return; |
|
|
|
|
|
|
|
foreach (var playerChanges in playersJoinedChanged.Value) |
|
|
|
{ |
|
|
|
Player joinedPlayer = playerChanges.Player; |
|
|
|
|
|
|
|
var id = joinedPlayer.Id; |
|
|
|
var index = playerChanges.PlayerIndex; |
|
|
|
var isHost = localLobby.HostID.Value == id; |
|
|
|
|
|
|
|
var newPlayer = new LocalPlayer(id, index, isHost); |
|
|
|
|
|
|
|
foreach (var dataEntry in joinedPlayer.Data) |
|
|
|
{ |
|
|
|
var dataObject = dataEntry.Value; |
|
|
|
ParseCustomPlayerData(newPlayer, dataEntry.Key, dataObject.Value); |
|
|
|
} |
|
|
|
|
|
|
|
localLobby.AddPlayer(index, newPlayer); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void PlayersLeft(ChangedLobbyValue<List<int>> playersLeftChanged, LocalLobby localLobby) |
|
|
|
{ |
|
|
|
if (!playersLeftChanged.Changed) |
|
|
|
return; |
|
|
|
foreach (var leftPlayerIndex in playersLeftChanged.Value) |
|
|
|
{ |
|
|
|
Debug.Log($"Player {leftPlayerIndex} Left"); |
|
|
|
|
|
|
|
localLobby.RemovePlayer(leftPlayerIndex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void PlayerDataChanged(ChangedLobbyValue<Dictionary<int, LobbyPlayerChanges>> playerDataChanged, |
|
|
|
LocalLobby localLobby) |
|
|
|
{ |
|
|
|
if (!playerDataChanged.Changed) |
|
|
|
return; |
|
|
|
|
|
|
|
foreach (var lobbyPlayerChanges in playerDataChanged.Value) |
|
|
|
{ |
|
|
|
var playerIndex = lobbyPlayerChanges.Key; |
|
|
|
var localPlayer = localLobby.GetLocalPlayer(playerIndex); |
|
|
|
if (localPlayer == null) |
|
|
|
continue; |
|
|
|
|
|
|
|
var playerChanges = lobbyPlayerChanges.Value; |
|
|
|
if (playerChanges.ConnectionInfoChanged.Changed) |
|
|
|
{ |
|
|
|
var connectionInfo = playerChanges.ConnectionInfoChanged.Value; |
|
|
|
Debug.Log( |
|
|
|
$"ConnectionInfo for player {playerIndex} changed to {connectionInfo}"); |
|
|
|
} |
|
|
|
|
|
|
|
if (playerChanges.LastUpdatedChanged.Changed) { } |
|
|
|
|
|
|
|
//There are changes on the Player
|
|
|
|
if (playerChanges.ChangedData.Changed) |
|
|
|
{ |
|
|
|
foreach (var playerChange in playerChanges.ChangedData.Value) |
|
|
|
{ |
|
|
|
var changedValue = playerChange.Value; |
|
|
|
|
|
|
|
//There are changes on some of the changes in the player list of changes
|
|
|
|
|
|
|
|
if (changedValue.Changed) |
|
|
|
{ |
|
|
|
if (changedValue.Removed) |
|
|
|
{ |
|
|
|
Debug.LogWarning("This Sample does not remove Player Values currently."); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
var playerDataObject = changedValue.Value; |
|
|
|
|
|
|
|
ParseCustomPlayerData(localPlayer, playerChange.Key, playerDataObject.Value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ParseCustomPlayerData(LocalPlayer player, string dataKey, string playerDataValue) |
|
|
|
{ |
|
|
|
Debug.Log($"RECIEVING : {player.DisplayName.Value}\nDATA : {dataKey} - {playerDataValue}"); |
|
|
|
|
|
|
|
if (dataKey == LobbyConverters.key_Emote) |
|
|
|
player.Emote.Value = (EmoteType)int.Parse(playerDataValue); |
|
|
|
else if (dataKey == LobbyConverters.key_Userstatus) |
|
|
|
player.UserStatus.Value = (PlayerStatus)int.Parse(playerDataValue); |
|
|
|
else if (dataKey == LobbyConverters.key_Displayname) |
|
|
|
player.DisplayName.Value = playerDataValue; |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region HeartBeat
|
|
|
|
|
|
|
|
List<QueryFilter> LobbyColorToFilters(LobbyColor limitToColor) |
|
|
|
|
|
|
#endregion
|
|
|
|
} |
|
|
|
|
|
|
|
//Manages the Amount of times you can hit a service call.
|
|
|
|
//Adds a buffer to account for ping times.
|
|
|
|
//Will Queue the latest overflow task for when the cooldown ends.
|
|
|
|
//Created to mimic the way rate limits are implemented Here: https://docs.unity.com/lobby/rate-limits.html
|
|
|
|
|
|
|
|
#region Cooldowns
|
|
|
|
|
|
|
|
//Manages the Amount of times you can hit a service call.
|
|
|
|
//Adds a buffer to account for ping times.
|
|
|
|
//Will Queue the latest overflow task for when the cooldown ends.
|
|
|
|
//Created to mimic the way rate limits are implemented Here: https://docs.unity.com/lobby/rate-limits.html
|
|
|
|
public class ServiceRateLimiter |
|
|
|
{ |
|
|
|
public Action<bool> onCooldownChange; |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
} |