Noble Connect
Add relays and punchthrough to Mirror or UNet
NobleConnect.Mirror.NobleRoomManager Class Reference

This is a specialized NetworkManager that includes a networked room. More...

Inherits NobleConnect.Mirror.NobleNetworkManager.

Classes

struct  PendingPlayer
 

Public Member Functions

override void OnValidate ()
 
override void OnServerReady (NetworkConnection conn)
 Called on the server when a client is ready. More...
 
void CheckReadyToBegin ()
 CheckReadyToBegin checks all of the players in the room to see if their readyToBegin flag is set. More...
 
override void OnServerConnect (NetworkConnection conn)
 Called on the server when a new client connects. More...
 
override void OnServerDisconnect (NetworkConnection conn)
 Called on the server when a client disconnects. More...
 
override void OnServerAddPlayer (NetworkConnection conn)
 Called on the server when a client adds a new player with ClientScene.AddPlayer. More...
 
void RecalculateRoomPlayerIndices ()
 
override void ServerChangeScene (string newSceneName)
 This causes the server to switch scenes and sets the networkSceneName. More...
 
override void OnServerSceneChanged (string sceneName)
 Called on the server when a scene is completed loaded, when the scene load was initiated by the server with ServerChangeScene(). More...
 
override void OnStartServer ()
 This is invoked when a server is started - including when a host is started. More...
 
override void OnStartHost ()
 This is invoked when a host is started. More...
 
override void OnStopServer ()
 This is called when a server is stopped - including when a host is stopped. More...
 
override void OnStopHost ()
 This is called when a host is stopped. More...
 
override void OnStartClient ()
 This is invoked when the client is started. More...
 
override void OnClientConnect (NetworkConnection conn)
 Called on the client when connected to a server. More...
 
override void OnClientDisconnect (NetworkConnection conn)
 Called on clients when disconnected from a server. More...
 
override void OnStopClient ()
 This is called when a client is stopped. More...
 
override void OnClientSceneChanged (NetworkConnection conn)
 Called on clients when a scene has completed loaded, when the scene load was initiated by the server. More...
 
virtual void OnRoomStartHost ()
 This is called on the host when a host is started. More...
 
virtual void OnRoomStopHost ()
 This is called on the host when the host is stopped. More...
 
virtual void OnRoomStartServer ()
 This is called on the server when the server is started - including when a host is started. More...
 
virtual void OnRoomStopServer ()
 This is called on the server when the server is started - including when a host is stopped. More...
 
virtual void OnRoomServerConnect (NetworkConnection conn)
 This is called on the server when a new client connects to the server. More...
 
virtual void OnRoomServerDisconnect (NetworkConnection conn)
 This is called on the server when a client disconnects. More...
 
virtual void OnRoomServerSceneChanged (string sceneName)
 This is called on the server when a networked scene finishes loading. More...
 
virtual GameObject OnRoomServerCreateRoomPlayer (NetworkConnection conn)
 This allows customization of the creation of the room-player object on the server. More...
 
virtual GameObject OnRoomServerCreateGamePlayer (NetworkConnection conn)
 Obsolete: Use OnRoomServerCreateGamePlayer(NetworkConnection, GameObject) instead. More...
 
virtual GameObject OnRoomServerCreateGamePlayer (NetworkConnection conn, GameObject roomPlayer)
 This allows customization of the creation of the GamePlayer object on the server. More...
 
virtual void OnRoomServerAddPlayer (NetworkConnection conn)
 This allows customization of the creation of the GamePlayer object on the server. More...
 
virtual bool OnRoomServerSceneLoadedForPlayer (GameObject roomPlayer, GameObject gamePlayer)
 Obsolete: Use OnRoomServerSceneLoadedForPlayer(NetworkConnection, GameObject, GameObject) instead. More...
 
virtual bool OnRoomServerSceneLoadedForPlayer (NetworkConnection conn, GameObject roomPlayer, GameObject gamePlayer)
 This is called on the server when it is told that a client has finished switching from the room scene to a game player scene. More...
 
virtual void OnRoomServerPlayersReady ()
 This is called on the server when all the players in the room are ready. More...
 
virtual void OnRoomClientEnter ()
 This is a hook to allow custom behaviour when the game client enters the room. More...
 
virtual void OnRoomClientExit ()
 This is a hook to allow custom behaviour when the game client exits the room. More...
 
virtual void OnRoomClientConnect (NetworkConnection conn)
 This is called on the client when it connects to server. More...
 
virtual void OnRoomClientDisconnect (NetworkConnection conn)
 This is called on the client when disconnected from a server. More...
 
virtual void OnRoomStartClient ()
 This is called on the client when a client is started. More...
 
virtual void OnRoomStopClient ()
 This is called on the client when the client stops. More...
 
virtual void OnRoomClientSceneChanged (NetworkConnection conn)
 This is called on the client when the client is finished loading a new networked scene. More...
 
virtual void OnRoomClientAddPlayerFailed ()
 Called on the client when adding a player to the room fails. More...
 
virtual void OnGUI ()
 virtual so inheriting classes can roll their own More...
 
- Public Member Functions inherited from NobleConnect.Mirror.NobleNetworkManager
override void Awake ()
 Initialize connectionConfig and HostTopology plus some other important setup. More...
 
override void Start ()
 
virtual void Update ()
 Updates the NobleClient and NobleServer. More...
 
void InitClient ()
 Initialize the NobleClient and allocate a relay. More...
 
new void StartClient ()
 Like NetworkManager.StartClient() but utilizes the Noble Connect relay and punchthrough services. More...
 
void StartClient (IPEndPoint hostEndPoint)
 Connect to a HostEndPoint, utilizing the Noble Connect relay and punchthrough services. More...
 
void StartClientLANOnly ()
 Start a client in LAN only mode. No relays or punchthrough will be used. More...
 
void StartClientLANOnly (IPEndPoint hostEndPoint)
 Start a client in LAN only mode. No relays or punchthrough will be used. More...
 
override void OnStartClient ()
 
virtual new void StartHost ()
 Start hosting, connect a local client, and request a HostEndPoint from the NobleConnectServices More...
 
void StartHostLANOnly ()
 Start hosting, connect a local client, but do no create a relay or enable punchthrough More...
 
new void StartServer ()
 Start a server and request a HostEndPoint from the NobleConnectServices More...
 
void StartServerLANonly ()
 Start a server, but do no create a relay or enable punchthrough More...
 
new void StopClient ()
 Stop the client. More...
 
void RegisterClientHandlers ()
 Register default client message handlers More...
 
override void OnStartServer ()
 Called when hosting starts. More...
 
void OnStartServerLANOnly ()
 
IPAddress GetALANAddress ()
 
virtual void OnFatalError (string error)
 Override this method to be informed when something goes horribly wrong. More...
 
override void OnStopServer ()
 Cleans up the server More...
 
override void OnStopClient ()
 
override void OnServerConnect (NetworkConnection conn)
 Called when the server receives a client connection. More...
 
override void OnClientDisconnect (NetworkConnection conn)
 
override void OnServerDisconnect (NetworkConnection conn)
 Called on the server when a client disconnects More...
 
virtual void OnServerPrepared (string hostAddress, ushort hostPort)
 Override this method to know when a Server has received their HostEndPoint More...
 
override void OnDestroy ()
 Clean up the client and server. More...
 

Public Attributes

string RoomScene
 The scene to use for the room. This is similar to the offlineScene of the NetworkManager. More...
 
string GameplayScene
 The scene to use for the playing the game from the room. This is similar to the onlineScene of the NetworkManager. More...
 
List< PendingPlayerpendingPlayers = new List<PendingPlayer>()
 List of players that are in the Room More...
 
bool allPlayersReady
 True when all players have submitted a Ready message More...
 
List< NobleRoomPlayerroomSlots = new List<NobleRoomPlayer>()
 These slots track players that enter the room. More...
 
- Public Attributes inherited from NobleConnect.Mirror.NobleNetworkManager
NobleClient client
 The NobleClient that will be used to connect to the host. More...
 
int networkPort
 
GeographicRegion region = GeographicRegion.AUTO
 The geographic region to use when selecting a relay server. More...
 
bool forceRelayConnection
 You can enable this to force relay connections to be used for testing purposes. More...
 
NobleConnect.Logger.Level logLevel = NobleConnect.Logger.Level.Info
 How much output do you want to see? More...
 
float requestTimeout = .2f
 Request timeout. More...
 
int relayRefreshTime = 30
 How often to send relay refresh requests, in seconds. More...
 
float relayRefreshTimeout = .1f
 Initial timeout before resending refresh messages. This is doubled for each failed resend. More...
 
int maxRelayRefreshAttempts = 3
 Max number of times to try and resend refresh messages before giving up and shutting down the relay connection. More...
 
int relayLifetime = 30
 How long a relay will stay alive without being refreshed (in seconds) More...
 
Action< NetworkConnection > onClientConnectInternal
 We need a reference to Mirror's internal connect method but it is not public so we get it via reflection. More...
 
Action< NetworkConnection > onClientDisconnectInternal
 We need a reference to Mirror's internal disconnect method but it is not public so we get it via reflection. More...
 
Action< NetworkConnection > onServerConnectInternal
 We need a reference to Mirror's internal connect method but it is not public so we get it via reflection. More...
 
Action< NetworkConnection > onServerDisconnectInternal
 We need a reference to Mirror's internal disconnect method but it is not public so we get it via reflection. More...
 
bool isDisconnecting
 True when in the middle of disconnecting More...
 

Protected Attributes

NobleRoomPlayer roomPlayerPrefab
 
- Protected Attributes inherited from NobleConnect.Mirror.NobleNetworkManager
bool isLANOnly
 If the current connection is LAN only More...
 

Additional Inherited Members

- Properties inherited from NobleConnect.Mirror.NobleNetworkManager
IPEndPoint HostEndPoint [get]
 This is the address that clients should connect to. It is assigned by the relay server. More...
 

Detailed Description

This is a specialized NetworkManager that includes a networked room.

The room has slots that track the joined players, and a maximum player count that is enforced. It requires that the NetworkRoomPlayer component be on the room player objects.

NetworkRoomManager is derived from NetworkManager, and so it implements many of the virtual functions provided by the NetworkManager class. To avoid accidentally replacing functionality of the NetworkRoomManager, there are new virtual functions on the NetworkRoomManager that begin with "OnRoom". These should be used on classes derived from NetworkRoomManager instead of the virtual functions on NetworkManager.

The OnRoom*() functions have empty implementations on the NetworkRoomManager base class, so the base class functions do not have to be called.

Member Function Documentation

◆ CheckReadyToBegin()

void NobleConnect.Mirror.NobleRoomManager.CheckReadyToBegin ( )

CheckReadyToBegin checks all of the players in the room to see if their readyToBegin flag is set.

If all of the players are ready, then the server switches from the RoomScene to the PlayScene, essentially starting the game. This is called automatically in response to NetworkRoomPlayer.CmdChangeReadyState.

◆ OnClientConnect()

override void NobleConnect.Mirror.NobleRoomManager.OnClientConnect ( NetworkConnection  conn)

Called on the client when connected to a server.

The default implementation of this function sets the client as ready and adds a player. Override the function to dictate what happens when the client connects.

Parameters
connConnection to the server.

◆ OnClientDisconnect()

override void NobleConnect.Mirror.NobleRoomManager.OnClientDisconnect ( NetworkConnection  conn)

Called on clients when disconnected from a server.

This is called on the client when it disconnects from the server. Override this function to decide what happens when the client disconnects.

Parameters
connConnection to the server.

◆ OnClientSceneChanged()

override void NobleConnect.Mirror.NobleRoomManager.OnClientSceneChanged ( NetworkConnection  conn)

Called on clients when a scene has completed loaded, when the scene load was initiated by the server.

Scene changes can cause player objects to be destroyed. The default implementation of OnClientSceneChanged in the NetworkManager is to add a player object for the connection if no player object exists.

Parameters
connConnection of the client

◆ OnGUI()

virtual void NobleConnect.Mirror.NobleRoomManager.OnGUI ( )
virtual

virtual so inheriting classes can roll their own

◆ OnRoomClientAddPlayerFailed()

virtual void NobleConnect.Mirror.NobleRoomManager.OnRoomClientAddPlayerFailed ( )
virtual

Called on the client when adding a player to the room fails.

This could be because the room is full, or the connection is not allowed to have more players.

◆ OnRoomClientConnect()

virtual void NobleConnect.Mirror.NobleRoomManager.OnRoomClientConnect ( NetworkConnection  conn)
virtual

This is called on the client when it connects to server.

Parameters
connThe connection that connected.

◆ OnRoomClientDisconnect()

virtual void NobleConnect.Mirror.NobleRoomManager.OnRoomClientDisconnect ( NetworkConnection  conn)
virtual

This is called on the client when disconnected from a server.

Parameters
connThe connection that disconnected.

◆ OnRoomClientEnter()

virtual void NobleConnect.Mirror.NobleRoomManager.OnRoomClientEnter ( )
virtual

This is a hook to allow custom behaviour when the game client enters the room.

◆ OnRoomClientExit()

virtual void NobleConnect.Mirror.NobleRoomManager.OnRoomClientExit ( )
virtual

This is a hook to allow custom behaviour when the game client exits the room.

◆ OnRoomClientSceneChanged()

virtual void NobleConnect.Mirror.NobleRoomManager.OnRoomClientSceneChanged ( NetworkConnection  conn)
virtual

This is called on the client when the client is finished loading a new networked scene.

Parameters
connThe connection that finished loading a new networked scene.

◆ OnRoomServerAddPlayer()

virtual void NobleConnect.Mirror.NobleRoomManager.OnRoomServerAddPlayer ( NetworkConnection  conn)
virtual

This allows customization of the creation of the GamePlayer object on the server.

This is only called for subsequent GamePlay scenes after the first one.

See OnRoomServerCreateGamePlayer(NetworkConnection, GameObject) to customize the player object for the initial GamePlay scene.

Parameters
connThe connection the player object is for.

◆ OnRoomServerConnect()

virtual void NobleConnect.Mirror.NobleRoomManager.OnRoomServerConnect ( NetworkConnection  conn)
virtual

This is called on the server when a new client connects to the server.

Parameters
connThe new connection.

◆ OnRoomServerCreateGamePlayer() [1/2]

virtual GameObject NobleConnect.Mirror.NobleRoomManager.OnRoomServerCreateGamePlayer ( NetworkConnection  conn)
virtual

Obsolete: Use OnRoomServerCreateGamePlayer(NetworkConnection, GameObject) instead.

Parameters
connThe connection the player object is for.
Returns
A new GamePlayer object.

◆ OnRoomServerCreateGamePlayer() [2/2]

virtual GameObject NobleConnect.Mirror.NobleRoomManager.OnRoomServerCreateGamePlayer ( NetworkConnection  conn,
GameObject  roomPlayer 
)
virtual

This allows customization of the creation of the GamePlayer object on the server.

By default the gamePlayerPrefab is used to create the game-player, but this function allows that behaviour to be customized. The object returned from the function will be used to replace the room-player on the connection.

Parameters
connThe connection the player object is for.
roomPlayerThe room player object for this connection.
Returns
A new GamePlayer object.

◆ OnRoomServerCreateRoomPlayer()

virtual GameObject NobleConnect.Mirror.NobleRoomManager.OnRoomServerCreateRoomPlayer ( NetworkConnection  conn)
virtual

This allows customization of the creation of the room-player object on the server.

By default the roomPlayerPrefab is used to create the room-player, but this function allows that behaviour to be customized.

Parameters
connThe connection the player object is for.
Returns
The new room-player object.

◆ OnRoomServerDisconnect()

virtual void NobleConnect.Mirror.NobleRoomManager.OnRoomServerDisconnect ( NetworkConnection  conn)
virtual

This is called on the server when a client disconnects.

Parameters
connThe connection that disconnected.

◆ OnRoomServerPlayersReady()

virtual void NobleConnect.Mirror.NobleRoomManager.OnRoomServerPlayersReady ( )
virtual

This is called on the server when all the players in the room are ready.

The default implementation of this function uses ServerChangeScene() to switch to the game player scene. By implementing this callback you can customize what happens when all the players in the room are ready, such as adding a countdown or a confirmation for a group leader.

◆ OnRoomServerSceneChanged()

virtual void NobleConnect.Mirror.NobleRoomManager.OnRoomServerSceneChanged ( string  sceneName)
virtual

This is called on the server when a networked scene finishes loading.

Parameters
sceneNameName of the new scene.

◆ OnRoomServerSceneLoadedForPlayer() [1/2]

virtual bool NobleConnect.Mirror.NobleRoomManager.OnRoomServerSceneLoadedForPlayer ( GameObject  roomPlayer,
GameObject  gamePlayer 
)
virtual

◆ OnRoomServerSceneLoadedForPlayer() [2/2]

virtual bool NobleConnect.Mirror.NobleRoomManager.OnRoomServerSceneLoadedForPlayer ( NetworkConnection  conn,
GameObject  roomPlayer,
GameObject  gamePlayer 
)
virtual

This is called on the server when it is told that a client has finished switching from the room scene to a game player scene.

When switching from the room, the room-player is replaced with a game-player object. This callback function gives an opportunity to apply state from the room-player to the game-player object.

Parameters
connThe connection of the player
roomPlayerThe room player object.
gamePlayerThe game player object.
Returns
False to not allow this player to replace the room player.

◆ OnRoomStartClient()

virtual void NobleConnect.Mirror.NobleRoomManager.OnRoomStartClient ( )
virtual

This is called on the client when a client is started.

Parameters
roomClientThe connection for the room.

◆ OnRoomStartHost()

virtual void NobleConnect.Mirror.NobleRoomManager.OnRoomStartHost ( )
virtual

This is called on the host when a host is started.

◆ OnRoomStartServer()

virtual void NobleConnect.Mirror.NobleRoomManager.OnRoomStartServer ( )
virtual

This is called on the server when the server is started - including when a host is started.

◆ OnRoomStopClient()

virtual void NobleConnect.Mirror.NobleRoomManager.OnRoomStopClient ( )
virtual

This is called on the client when the client stops.

◆ OnRoomStopHost()

virtual void NobleConnect.Mirror.NobleRoomManager.OnRoomStopHost ( )
virtual

This is called on the host when the host is stopped.

◆ OnRoomStopServer()

virtual void NobleConnect.Mirror.NobleRoomManager.OnRoomStopServer ( )
virtual

This is called on the server when the server is started - including when a host is stopped.

◆ OnServerAddPlayer()

override void NobleConnect.Mirror.NobleRoomManager.OnServerAddPlayer ( NetworkConnection  conn)

Called on the server when a client adds a new player with ClientScene.AddPlayer.

The default implementation for this function creates a new player object from the playerPrefab.

Parameters
connConnection from client.

◆ OnServerConnect()

override void NobleConnect.Mirror.NobleRoomManager.OnServerConnect ( NetworkConnection  conn)

Called on the server when a new client connects.

Unity calls this on the Server when a Client connects to the Server. Use an override to tell the NetworkManager what to do when a client connects to the server.

Parameters
connConnection from client.

◆ OnServerDisconnect()

override void NobleConnect.Mirror.NobleRoomManager.OnServerDisconnect ( NetworkConnection  conn)

Called on the server when a client disconnects.

This is called on the Server when a Client disconnects from the Server. Use an override to decide what should happen when a disconnection is detected.

Parameters
connConnection from client.

◆ OnServerReady()

override void NobleConnect.Mirror.NobleRoomManager.OnServerReady ( NetworkConnection  conn)

Called on the server when a client is ready.

The default implementation of this function calls NetworkServer.SetClientReady() to continue the network setup process.

Parameters
connConnection from client.

◆ OnServerSceneChanged()

override void NobleConnect.Mirror.NobleRoomManager.OnServerSceneChanged ( string  sceneName)

Called on the server when a scene is completed loaded, when the scene load was initiated by the server with ServerChangeScene().

Parameters
sceneNameThe name of the new scene.

◆ OnStartClient()

override void NobleConnect.Mirror.NobleRoomManager.OnStartClient ( )

This is invoked when the client is started.

◆ OnStartHost()

override void NobleConnect.Mirror.NobleRoomManager.OnStartHost ( )

This is invoked when a host is started.

StartHost has multiple signatures, but they all cause this hook to be called.

◆ OnStartServer()

override void NobleConnect.Mirror.NobleRoomManager.OnStartServer ( )

This is invoked when a server is started - including when a host is started.

StartServer has multiple signatures, but they all cause this hook to be called.

◆ OnStopClient()

override void NobleConnect.Mirror.NobleRoomManager.OnStopClient ( )

This is called when a client is stopped.

◆ OnStopHost()

override void NobleConnect.Mirror.NobleRoomManager.OnStopHost ( )

This is called when a host is stopped.

◆ OnStopServer()

override void NobleConnect.Mirror.NobleRoomManager.OnStopServer ( )

This is called when a server is stopped - including when a host is stopped.

◆ OnValidate()

override void NobleConnect.Mirror.NobleRoomManager.OnValidate ( )

◆ RecalculateRoomPlayerIndices()

void NobleConnect.Mirror.NobleRoomManager.RecalculateRoomPlayerIndices ( )

◆ ServerChangeScene()

override void NobleConnect.Mirror.NobleRoomManager.ServerChangeScene ( string  newSceneName)

This causes the server to switch scenes and sets the networkSceneName.

Clients that connect to this server will automatically switch to this scene. This is called autmatically if onlineScene or offlineScene are set, but it can be called from user code to switch scenes again while the game is in progress. This automatically sets clients to be not-ready. The clients must call NetworkClient.Ready() again to participate in the new scene.

Parameters
newSceneName

Member Data Documentation

◆ allPlayersReady

bool NobleConnect.Mirror.NobleRoomManager.allPlayersReady

True when all players have submitted a Ready message

◆ GameplayScene

string NobleConnect.Mirror.NobleRoomManager.GameplayScene

The scene to use for the playing the game from the room. This is similar to the onlineScene of the NetworkManager.

◆ pendingPlayers

List<PendingPlayer> NobleConnect.Mirror.NobleRoomManager.pendingPlayers = new List<PendingPlayer>()

List of players that are in the Room

◆ roomPlayerPrefab

NobleRoomPlayer NobleConnect.Mirror.NobleRoomManager.roomPlayerPrefab
protected

◆ RoomScene

string NobleConnect.Mirror.NobleRoomManager.RoomScene

The scene to use for the room. This is similar to the offlineScene of the NetworkManager.

◆ roomSlots

List<NobleRoomPlayer> NobleConnect.Mirror.NobleRoomManager.roomSlots = new List<NobleRoomPlayer>()

These slots track players that enter the room.

The slotId on players is global to the game - across all players.