NAT Traversal for UNET
Provides NAT punch-through, automatic port forwarding, and other useful features on top of Unity's UNET HLAPI networking system.
MigrationManager Class Reference

Extends UNet's NetworkMigrationManager to work with punchthrough connections. More...

Inherits NetworkMigrationManager.

Public Member Functions

virtual new bool BecomeNewHost (int port)
 Become the new host. Starts listening for punchthrough. More...
 
virtual bool FindNewHost (out ExtraPeerInfoMessage newHostInfo, out bool youAreNewHost)
 This is how the punchthrough client is added. More...
 
virtual new void Initialize (NetworkClient directClient, MatchInfo newMatchInfo)
 Initialize host migration. Registers the client to listen for ExtraPeerInfo messages. More...
 
virtual new bool LostHostOnClient (NetworkConnection conn)
 Disconnect both clients. Disable client owned objects. More...
 
virtual new void LostHostOnHost ()
 Sets the client to null and calls base.LostHostOnClient() More...
 
new bool ReconnectPlayerForConnection (NetworkConnection newConnection, GameObject oldPlayer, int oldConnectionId, short playerControllerId)
 Called on new host when a client from the old host re-connects a player More...
 
virtual void ReconnectToNewHost ()
 
virtual new void SendPeerInfo ()
 Send ExtraPeerInfo messages to everyone. More...
 
virtual void Start ()
 Grabs a reference to the NetworkManager. Calls Reset(). More...
 

Protected Member Functions

override void OnServerReconnectPlayer (NetworkConnection newConnection, GameObject oldPlayer, int oldConnectionId, short playerControllerId)
 Called on new host when a client from the old host re-connects a player More...
 
override void OnServerReconnectPlayer (NetworkConnection newConnection, GameObject oldPlayer, int oldConnectionId, short playerControllerId, NetworkReader extraMessageReader)
 Called on new host when a client from the old host re-connects a player More...
 

Protected Attributes

NATTraversal.NetworkManager networkManager
 
ExtraPeerInfoMessage newHost
 

Detailed Description

Extends UNet's NetworkMigrationManager to work with punchthrough connections.

Member Function Documentation

◆ BecomeNewHost()

virtual new bool BecomeNewHost ( int  port)
virtual

Become the new host. Starts listening for punchthrough.

Parameters
port
Returns

◆ FindNewHost()

virtual bool FindNewHost ( out ExtraPeerInfoMessage  newHostInfo,
out bool  youAreNewHost 
)
virtual

This is how the punchthrough client is added.

Parameters
extraClient

Pick a new host. Override this to change how the new host is selected.

If you override this method DO NOT call the base method.

◆ Initialize()

virtual new void Initialize ( NetworkClient  directClient,
MatchInfo  newMatchInfo 
)
virtual

Initialize host migration. Registers the client to listen for ExtraPeerInfo messages.

Parameters
directClient
newMatchInfo

◆ LostHostOnClient()

virtual new bool LostHostOnClient ( NetworkConnection  conn)
virtual

Disconnect both clients. Disable client owned objects.

Parameters
conn
Returns

◆ LostHostOnHost()

virtual new void LostHostOnHost ( )
virtual

Sets the client to null and calls base.LostHostOnClient()

◆ OnServerReconnectPlayer() [1/2]

override void OnServerReconnectPlayer ( NetworkConnection  newConnection,
GameObject  oldPlayer,
int  oldConnectionId,
short  playerControllerId 
)
protected

Called on new host when a client from the old host re-connects a player

Parameters
newConnection
oldPlayer
oldConnectionId
playerControllerId

◆ OnServerReconnectPlayer() [2/2]

override void OnServerReconnectPlayer ( NetworkConnection  newConnection,
GameObject  oldPlayer,
int  oldConnectionId,
short  playerControllerId,
NetworkReader  extraMessageReader 
)
protected

Called on new host when a client from the old host re-connects a player

Parameters
newConnection
oldPlayer
oldConnectionId
playerControllerId
extraMessageReader

◆ ReconnectPlayerForConnection()

new bool ReconnectPlayerForConnection ( NetworkConnection  newConnection,
GameObject  oldPlayer,
int  oldConnectionId,
short  playerControllerId 
)

Called on new host when a client from the old host re-connects a player

Parameters
newConnection
oldPlayer
oldConnectionId
playerControllerId
Returns

◆ SendPeerInfo()

virtual new void SendPeerInfo ( )
virtual

Send ExtraPeerInfo messages to everyone.

◆ Start()

virtual void Start ( )
virtual

Grabs a reference to the NetworkManager. Calls Reset().

Make sure to call the base method if you override this.