/// <summary>Used only for visual output of the Relay connection info. The obfuscated Relay server IP is obtained during allocation in the RelayUtpSetup.</summary>
publicvoidAddPlayer(LocalPlayeruser)
{
if(m_LobbyUsers.ContainsKey(user.ID))
{
Debug.LogError($"Cant add player {user.DisplayName}({user.ID}) to lobby: {LobbyID} twice");
// Special case: We want to be able to filter on our color data, so we need to supply an arbitrary index to retrieve later. Uses N# for numerics, instead of S# for strings.
Locator.Get.Provide(this);// Simplifies access since some networked objects can't easily communicate locally (e.g. the host might call a ClientRpc without that client knowing where the call originated).
/// Once the local player is in a lobby and that lobby has entered the In-Game state, this will load in whatever is necessary to actually run the game part.
/// Once the local localPlayer is in a localLobby and that localLobby has entered the In-Game state, this will load in whatever is necessary to actually run the game part.
{m_lobby=lobby;// Most of the time this is redundant, but we need to get multiple members of the lobby to the Relay setup components, so might as well just hold onto the whole thing.
// Don't react to our own messages. Also, don't need to hold onto messages if the ID is absent; clients should be initialized and in the lobby before they send events.
// (Note that this enforces lobby membership before processing any events besides an approval request, so a client is unable to fully use Relay unless they're in the lobby.)
// If the client calls Disconnect, the host might not become aware right away (depending on when the PubSub messages get pumped), so send a message over UTP instead.
// Don't send through data from one client to everyone else if they haven't been approved yet. (They should also not be sending data if not approved, so this is a backup.)
elseif(msgType==MsgType.PlayerDisconnect)// Clients message the host when they intend to disconnect, or else the host ends up keeping the connection open.
elseif(msgType==MsgType.PlayerDisconnect
)// Clients message the host when they intend to disconnect, or else the host ends up keeping the connection open.
elseif(type==MessageType.EndGame)// This assumes that only the host will have the End Game button available; otherwise, clients need to be able to send this message, too.
elseif(type==MessageType.EndGame
)// This assumes that only the host will have the End Game button available; otherwise, clients need to be able to send this message, too.
varconn=m_networkDriver.Accept();// Note that since we pumped the event queue earlier in Update, m_networkDriver has been updated already this frame.
if(!conn.IsCreated)// "Nothing more to accept" is signalled by returning an invalid connection from Accept.
varconn=m_networkDriver
.Accept();// Note that since we pumped the event queue earlier in Update, m_networkDriver has been updated already this frame.
if(!conn.IsCreated
)// "Nothing more to accept" is signalled by returning an invalid connection from Accept.
// Although the connection is created (i.e. Accepted), we still need to approve it, which will trigger when receiving the NewPlayer message from that client.
// Since we're signed in through the same pathway as the actual game, the list of lobbies will include any that have been made in the game itself, so we should account for those.
// If you want to get around this, consider having a secondary project using the same assets with its own credentials.
yieldreturn
newWaitForSeconds(
1);// To prevent a possible 429 with the upcoming Query request, in case a previous test had one; Query requests can only occur at a rate of 1 per second.
QueryResponsequeryResponse=null;
Debug.Log("Getting Lobby List 1");
// Since we're signed in through the same pathway as the actual game, the list of lobbies will include any that have been made in the game itself, so we should account for those.
// If you want to get around this, consider having a secondary project using the same assets with its own credentials.
yieldreturn
newWaitForSeconds(
1);// To prevent a possible 429 with the upcoming Query request, in case a previous test had one; Query requests can only occur at a rate of 1 per second.
/// We want to illustrate filtering the lobby list by some arbitrary variable. This will allow the lobby host to choose a color for the lobby, and will display a lobby's current color.
/// (Note that this isn't sent over Relay to other clients for realtime updates.)