public Lobby CurrentLobby = > m_CurrentLobby ;
Lobby m_CurrentLobby ;
LobbyEventCallbacks m_LobbyEventCallbacks = new LobbyEventCallbacks ( ) ;
const int k_maxLobbiesToShow = 1 6 ; // If more are necessary, consider retrieving paginated results or using filters.
const int
k_maxLobbiesToShow = 1 6 ; // If more are necessary, consider retrieving paginated results or using filters.
Task m_HeartBeatTask ;
{
await m_QueryCooldown . WaitUntilCooldown ( ) ;
Debug . Log ( "Lobby - Retrieving List." ) ;
var filters = LobbyColorToFilters ( limitToColor ) ;
QueryLobbiesOptions queryOptions = new QueryLobbiesOptions
return await LobbyService . Instance . QueryLobbiesAsync ( queryOptions ) ;
}
public async Task SubscribeToLocalLobbyChanges ( string lobbyID , LocalLobby localLobby )
public async Task BindLocalLobbyToRemote ( string lobbyID , LocalLobby localLobby )
{
m_LobbyEventCallbacks . LobbyChanged + = async changes = >
{
foreach ( var change in changes . Data . Value )
{
var changedValue = change . Value ;
var changedKey = change . Key ;
if ( changedValue . Removed )
{
RemoveCustomLobbyData ( changedKey ) ;
}
var changedKey = change . Key ;
ParseRemoteLobbyData ( changedKey , changedValue . Value ) ;
ParseCustomLobbyData ( changedKey , changedValue . Value ) ;
void ParseRemoteLobbyData ( string changedKey , DataObject playerDataObject )
void ParseCustomLobbyData ( string changedKey , DataObject playerDataObject )
{
if ( changedKey = = key_RelayCode )
localLobby . RelayCode . Value = playerDataObject . Value ;
if ( changedKey = = key_LobbyColor )
localLobby . LocalLobbyColor . Value = ( LobbyColor ) int . Parse ( playerDataObject . Value ) ;
}
void RemoveCustomLobbyData ( string changedKey )
{
if ( changedKey = = key_RelayCode )
localLobby . RelayCode . Value = "" ;
if ( changedKey = = key_RelayNGOCode )
localLobby . RelayNGOCode . Value = "" ;
}
}
void PlayersJoined ( )
var id = joinedPlayer . Id ;
var index = playerChanges . PlayerIndex ;
var isHost = localLobby . HostID . Value = = id ;
var isHost = localLobby . HostID . Value . Equals ( id ) ;
var displayName = joinedPlayer . Data ? . ContainsKey ( key_Displayname ) = = true
? joinedPlayer . Data [ key_Displayname ] . Value
: default ;
var emote = joinedPlayer . Data ? . ContainsKey ( key_Emote ) = = true
? ( EmoteType ) int . Parse ( joinedPlayer . Data [ key_Emote ] . Value )
: EmoteType . None ;
var userStatus = joinedPlayer . Data ? . ContainsKey ( key_Userstatus ) = = true
? ( UserStatus ) int . Parse ( joinedPlayer . Data [ key_Userstatus ] . Value )
: UserStatus . Lobby ;
var newPlayer = new LocalPlayer ( id , index , isHost ) ;
foreach ( var dataEntry in joinedPlayer . Data )
{
var dataObject = dataEntry . Value ;
ParseCustomPlayerData ( newPlayer , dataEntry . Key , dataObject . Value ) ;
}
var newPlayer = new LocalPlayer ( id , index , isHost , displayName , emote , userStatus ) ;
localLobby . AddPlayer ( newPlayer ) ;
localLobby . AddPlayer ( index , newPlayer ) ;
}
}
{
var lastUpdated = playerChanges . LastUpdatedChanged . Value ;
Debug . Log (
$"ConnectionInfo for {localPlayer.DisplayName.Value} changed to {lastUpdated}" ) ;
$"LastUpdated for {localPlayer.DisplayName.Value} changed to {lastUpdated}" ) ;
}
if ( playerChanges . ChangedData . Changed )
{
if ( changedValue . Removed )
{
Debug . LogWarning ( "This Sample does not remove Values currently." ) ;
Debug . LogWarning ( "This Sample does not remove Player Values currently." ) ;
var changedKey = playerChange . Key ;
ParseLocalPlayerData ( changedKey , playerDataObject ) ;
ParseCustomPlayerData ( localPlayer , playerChange . Key , playerDataObject . Value ) ;
void ParseLocalPlayerData ( string dataKey , PlayerDataObject playerDataObject )
{
localPlayer . DisplayName . Value = dataKey = = key_Displayname
? playerDataObject . Value
: default ;
localPlayer . Emote . Value = dataKey = = key_Emote
? ( EmoteType ) int . Parse ( playerDataObject . Value )
: EmoteType . None ;
localPlayer . UserStatus . Value = dataKey = = key_Userstatus
? ( UserStatus ) int . Parse ( playerDataObject . Value )
: UserStatus . Lobby ;
}
}
}
} ;
Debug . Log ( $"Lobby Event Changed {lobbyEventConnectionState}" ) ;
Debug . Log ( $"Lobby ConnectionState Changed to {lobbyEventConnectionState}" ) ;
} ;
m_LobbyEventCallbacks . KickedFromLobby + = ( ) = >
await LobbyService . Instance . SubscribeToLobbyEventsAsync ( lobbyID , m_LobbyEventCallbacks ) ;
}
void ParseCustomPlayerData ( LocalPlayer player , string dataKey , string playerDataValue )
{
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 )
{
m_CurrentLobby = null ;
}
public async Task < Lobby > UpdatePlayerDataAsync ( Dictionary < string , string > data )
public async Task UpdatePlayerDataAsync ( Dictionary < string , string > data )
return null ;
return ;
await m_UpdatePlayerCooldown . WaitUntilCooldown ( ) ;
Debug . Log ( "Lobby - Updating Player Data" ) ;
AllocationId = null ,
ConnectionInfo = null
} ;
return m_CurrentLobby =
await LobbyService . Instance . UpdatePlayerAsync ( m_CurrentLobby . Id , playerId , updateOptions ) ;
m_CurrentLobby = await LobbyService . Instance . UpdatePlayerAsync ( m_CurrentLobby . Id , playerId , updateOptions ) ;
}
public async Task < Lobby > UpdatePlayerRelayInfoAsync ( string lobbyID , string allocationId , string connectionInfo )
return m_CurrentLobby = await LobbyService . Instance . UpdatePlayerAsync ( lobbyID , playerId , updateOptions ) ;
}
public async Task < Lobby > UpdateLobbyDataAsync ( Dictionary < string , string > data )
public async Task UpdateLobbyDataAsync ( Dictionary < string , string > data )
return null ;
return ;
await m_UpdateLobbyCooldown . WaitUntilCooldown ( ) ;
Debug . Log ( "Lobby - Updating Lobby Data" ) ;
}
UpdateLobbyOptions updateOptions = new UpdateLobbyOptions { Data = dataCurr , IsLocked = shouldLock } ;
return m_CurrentLobby = await LobbyService . Instance . UpdateLobbyAsync ( m_CurrentLobby . Id , updateOptions ) ;
m_CurrentLobby = await LobbyService . Instance . UpdateLobbyAsync ( m_CurrentLobby . Id , updateOptions ) ;
}
public async Task DeleteLobbyAsync ( )
QueryFilter . OpOptions . EQ ) ) ;
return filters ;
}
//Since the LobbyManager maintains the "connection" to the lobby, we will continue to heartbeat until host leaves.
async Task SendHeartbeatPingAsync ( )
{
}
}
}
}
}