Photon Bolt Engine API
Networking Middleware
Public Member Functions | Protected Member Functions | List of all members
BoltInternal.GlobalEventListenerBase Class Reference

Base class for all BoltCallbacks objects More...

Inheritance diagram for BoltInternal.GlobalEventListenerBase:

Public Member Functions

virtual bool PersistBetweenStartupAndShutdown ()
 Override this method and return true if you want the event listener to keep being attached to Bolt even when Bolt shuts down and starts again. More...
 
virtual void BoltShutdownBegin (Bolt.AddCallback registerDoneCallback)
 
virtual void BoltStartBegin ()
 
virtual void BoltStartDone ()
 
virtual void BoltStartFailed ()
 
virtual void StreamDataReceived (BoltConnection connection, UdpStreamData data)
 
virtual void PortMappingChanged (Bolt.INatDevice device, Bolt.IPortMapping portMapping)
 
virtual void SceneLoadLocalBegin (string map)
 
virtual void SceneLoadLocalBegin (string scene, Bolt.IProtocolToken token)
 
virtual void SceneLoadLocalDone (string map)
 
virtual void SceneLoadLocalDone (string scene, Bolt.IProtocolToken token)
 
virtual void SceneLoadRemoteDone (BoltConnection connection)
 
virtual void SceneLoadRemoteDone (BoltConnection connection, Bolt.IProtocolToken token)
 
virtual void Connected (BoltConnection connection)
 
virtual void ConnectFailed (UdpEndPoint endpoint, Bolt.IProtocolToken token)
 
virtual void ConnectRequest (UdpEndPoint endpoint, Bolt.IProtocolToken token)
 
virtual void ConnectRefused (UdpEndPoint endpoint, Bolt.IProtocolToken token)
 
virtual void ConnectAttempt (UdpEndPoint endpoint, Bolt.IProtocolToken token)
 
virtual void Disconnected (BoltConnection connection)
 
virtual void ControlOfEntityLost (BoltEntity entity)
 
virtual void ControlOfEntityGained (BoltEntity entity)
 
virtual void EntityAttached (BoltEntity entity)
 
virtual void EntityDetached (BoltEntity entity)
 
virtual void EntityReceived (BoltEntity entity)
 
virtual void EntityFrozen (BoltEntity entity)
 
virtual void EntityThawed (BoltEntity entity)
 
virtual void ZeusConnectFailed (UdpEndPoint endpoint)
 
virtual void ZeusConnected (UdpEndPoint endpoint)
 
virtual void ZeusDisconnected (UdpEndPoint endpoint)
 
virtual void ZeusNatProbeResult (UdpKit.NatFeatures features)
 
virtual void SessionListUpdated (Map< System.Guid, UdpSession > sessionList)
 
virtual void SessionConnectFailed (UdpSession session, Bolt.IProtocolToken token)
 

Protected Member Functions

void OnEnable ()
 
void OnDisable ()
 

Detailed Description

Base class for all BoltCallbacks objects

Example: Accepting an incoming remote connection.

1 public override void ConnectRequest(BoltConnection connection) {
2  BoltNetwork.Accept(connection.remoteEndPoint);
3 }

Member Function Documentation

virtual void BoltInternal.GlobalEventListenerBase.BoltShutdownBegin ( Bolt.AddCallback  registerDoneCallback)
inlinevirtual

Callback triggered when the bolt simulation is shutting down.

Example: Logging a message in the bolt console when the server has shut down unexpectedly.

1 public override void BoltShutdown() {
2  BoltConsole.Write("Warning: Server Shutting Down...");
3 }
virtual void BoltInternal.GlobalEventListenerBase.BoltStartBegin ( )
inlinevirtual
virtual void BoltInternal.GlobalEventListenerBase.BoltStartDone ( )
inlinevirtual
virtual void BoltInternal.GlobalEventListenerBase.BoltStartFailed ( )
inlinevirtual
virtual void BoltInternal.GlobalEventListenerBase.ConnectAttempt ( UdpEndPoint  endpoint,
Bolt.IProtocolToken  token 
)
inlinevirtual

Callback triggered when trying to connect to a remote endpoint

Parameters
endpointThe remote server address

Example: Logging a message when initializing a connection to server.

1 public override void ConnectAttempt((UdpEndPoint endpoint) {
2  BoltConsole.Write(string.Format("To Remote Server At ({0}:{1})", endpoint.Address, endpoint.Port);
3 }
virtual void BoltInternal.GlobalEventListenerBase.Connected ( BoltConnection  connection)
inlinevirtual

Callback triggered when a client has become connected to this instance

Parameters
connectionEndpoint of the connected client

Example: Instantiating and configuring a player entity when a client connects to the server.

1 public override void Connected(BoltConnection connection) {
2  var player = BoltNetwork.Instantiate(BoltPrefabs.Player);
3  player.transform.position = spawnPoint.transform.position;
4 
5  var initData = prototype.GetNewPlayer(GameLogic.PlayableClass.Mercenary);
6  Configure(player, initData);
7 
8  player.AssignControl(connection);
9 }
virtual void BoltInternal.GlobalEventListenerBase.ConnectFailed ( UdpEndPoint  endpoint,
Bolt.IProtocolToken  token 
)
inlinevirtual

Callback triggered when a connection to remote server has failed

Parameters
endpointThe remote address

Example: Logging an error message when the remote connection has failed.

1 public override void ConnectFailed(UdpEndPoint endpoint) {
2  BoltConsole.Write(string.Format("Connection To ({0}:{1}) has failed", endpoint.Address.ToString(), endpoint.ToString()));
3 }
virtual void BoltInternal.GlobalEventListenerBase.ConnectRefused ( UdpEndPoint  endpoint,
Bolt.IProtocolToken  token 
)
inlinevirtual

Callback triggered when the connection to a remote server has been refused.

Parameters
endpointThe remote server endpoint
tokenData token sent by refusing server

Example: Logging an error message when the remote connection has been refused using an error message token from the server.

1 public override void ConnectRefused(UdpEndPoint endpoint, Bolt.IProtocolToken token) {
2  ServerMessage.message = (ServerMessage)token;
3  BoltConsole.Write(string.Format("Connection To ({0}:{1}) has been refused. Reason was {3}",
4  endpoint.Address.ToString(), endpoint.ToString(), serverMessage.errorDescription));
5 }
virtual void BoltInternal.GlobalEventListenerBase.ConnectRequest ( UdpEndPoint  endpoint,
Bolt.IProtocolToken  token 
)
inlinevirtual

Callback triggered when this instance receives an incoming client connection

Parameters
endpointThe incoming client endpoint
tokenA data token sent from the incoming client

Example: Accepting an incoming connection with user credentials in the data token.

1 public override void ConnectRequest(UdpEndPoint endpoint, Bolt.IProtocolToken token) {
2  UserCredentials creds = (UserCredentials)token);
3  if(Authenticate(creds.username, creds.password)) {
4  BoltNetwork.Accept(connection.remoteEndPoint);
5  }
6 }
virtual void BoltInternal.GlobalEventListenerBase.ControlOfEntityGained ( BoltEntity  entity)
inlinevirtual

Callback triggered when this instance of bolt receieves control of a bolt entity

Parameters
entityThe controlled entity

Example: Setting up the game minimap and other components to use a specific entity as the player's controlled entity.

1 public override void ControlOfEntityGained(BoltEntity entity) {
2  GameInput.instance.SetControlledEntity(entity);
3  MiniMap.instance.SetControlledEntity(entity);
4 }
virtual void BoltInternal.GlobalEventListenerBase.ControlOfEntityLost ( BoltEntity  entity)
inlinevirtual

Callback triggered when this instance of bolt loses control of a bolt entity

Parameters
entityThe controlled entity

Example: Setting up game components to no longer control an entity.

1 public override void ControlOfEntityLost(BoltEntity entity) {
2  GameInput.instance.RemoveControlledEntity(entity);
3  MiniMap.instance.RemoveControlledEntity(entity);
4 }
virtual void BoltInternal.GlobalEventListenerBase.Disconnected ( BoltConnection  connection)
inlinevirtual

Callback triggered when disconnected from remote server

Parameters
connectionThe remote server endpoint

Example: Logging a disconnect message and returning to the main menu scene.

1 public override void Disconnected(BoltConnection connection) {
2  BoltConsole.Write("Returning to main menu...");
3  Application.LoadLevel("MainMenu");
4 }
virtual void BoltInternal.GlobalEventListenerBase.EntityAttached ( BoltEntity  entity)
inlinevirtual

Callback triggered when a new entity is attached to the bolt simulation

Parameters
entityThe attached entity

Example: Setting up the game minimap to show a newly attached entity.

1 public override void EntityAttached(BoltEntity entity) {
2  MiniMap.instance.SetKnownEntity(entity);
3 }
virtual void BoltInternal.GlobalEventListenerBase.EntityDetached ( BoltEntity  entity)
inlinevirtual

Callback triggered when a new entity is detached from the bolt simulation

Parameters
entityThe detached entity

Example: Removing the newly detached entity from the game minimap.

1 public override void EntityDetached(BoltEntity entity) {
2  MiniMap.instance.RemoveKnownEntity(entity);
3 }
virtual void BoltInternal.GlobalEventListenerBase.EntityFrozen ( BoltEntity  entity)
inlinevirtual
virtual void BoltInternal.GlobalEventListenerBase.EntityReceived ( BoltEntity  entity)
inlinevirtual

Callback triggered when a bolt entity is recieved from the network

Parameters
entityThe recieved bolt entity

Example: Loggging connections from remote players in the client bolt console

1 public override void EntityReceived(BoltEntity entity) {
2  string name = entity.GetState<PlayerState>().Name;
3  BoltConsole.Write(string.Format("{0} Has Connected", name));
4 }
virtual void BoltInternal.GlobalEventListenerBase.EntityThawed ( BoltEntity  entity)
inlinevirtual
void BoltInternal.GlobalEventListenerBase.OnDisable ( )
inlineprotected
void BoltInternal.GlobalEventListenerBase.OnEnable ( )
inlineprotected
virtual bool BoltInternal.GlobalEventListenerBase.PersistBetweenStartupAndShutdown ( )
inlinevirtual

Override this method and return true if you want the event listener to keep being attached to Bolt even when Bolt shuts down and starts again.

Returns
True/False

Example: Configuring the persistence behaviour to keep this listener alive between startup and shutdown.

1 public override bool PersistBetweenStartupAndShutdown() {
2  return true;
3 }
virtual void BoltInternal.GlobalEventListenerBase.PortMappingChanged ( Bolt.INatDevice  device,
Bolt.IPortMapping  portMapping 
)
inlinevirtual

Callback when network router port mapping has been changed

Parameters
deviceThe current network routing device
portMappingThe new port mapping
virtual void BoltInternal.GlobalEventListenerBase.SceneLoadLocalBegin ( string  map)
inlinevirtual

Callback triggered before the new local scene is loaded

Parameters
mapName of scene being loaded

Example: Showing a splash screen when clients are loading the game scene.

1 public override void SceneLoadLocalBegin(string map) {
2  if(BoltNetwork.isClient && map.Equals("GameScene") {
3  SplashScreen.Show(SplashScreens.GameLoad);
4  }
5 }
virtual void BoltInternal.GlobalEventListenerBase.SceneLoadLocalBegin ( string  scene,
Bolt.IProtocolToken  token 
)
inlinevirtual
virtual void BoltInternal.GlobalEventListenerBase.SceneLoadLocalDone ( string  map)
inlinevirtual

Callback triggered before the new local scene has been completely loaded

Parameters
mapName of scene that has loaded

Example: Hiding a splash screen that was shown during loading.

1 public override void sceneLoadLocalDone(string map) {
2  if(BoltNetwork.isClient && map.Equals("GameScene") {
3  SplashScreen.Hide();
4  }
5 }
virtual void BoltInternal.GlobalEventListenerBase.SceneLoadLocalDone ( string  scene,
Bolt.IProtocolToken  token 
)
inlinevirtual
virtual void BoltInternal.GlobalEventListenerBase.SceneLoadRemoteDone ( BoltConnection  connection)
inlinevirtual

Callback triggered when a remote connection has completely loaded the current scene

Parameters
connectionThe remote connection

Example: Instantiating and configuring a player entity on the server and then assigning control to the client.

1 public override void SceneLoadRemoteDone(BoltConnection connection) {
2  var player = BoltNetwork.Instantiate(BoltPrefabs.Player);
3  player.transform.position = spawnPoint.transform.position;
4 
5  var initData = prototype.GetNewPlayer(GameLogic.PlayableClass.Mercenary);
6  Configure(player, initData);
7 
8  player.AssignControl(connection);
9 }
virtual void BoltInternal.GlobalEventListenerBase.SceneLoadRemoteDone ( BoltConnection  connection,
Bolt.IProtocolToken  token 
)
inlinevirtual
virtual void BoltInternal.GlobalEventListenerBase.SessionConnectFailed ( UdpSession  session,
Bolt.IProtocolToken  token 
)
inlinevirtual
virtual void BoltInternal.GlobalEventListenerBase.SessionListUpdated ( Map< System.Guid, UdpSession >  sessionList)
inlinevirtual
virtual void BoltInternal.GlobalEventListenerBase.StreamDataReceived ( BoltConnection  connection,
UdpStreamData  data 
)
inlinevirtual

Callback triggered when binary stream data is received

Parameters
connectionThe sender connection
dataThe binary stream data

Example: Receiving a custom player icon.

1 public override void StreamDataReceived(BoltConnection connnection, UdpStreamData data) {
2  Texture2D icon = new Texture2D(4, 4);
3  icon.LoadImage(data.Data);
4 
5  PlayerData playerData = (PlayerData)connection.userToken;
6  playerData.SetIcon(icon);
7 }
virtual void BoltInternal.GlobalEventListenerBase.ZeusConnected ( UdpEndPoint  endpoint)
inlinevirtual
virtual void BoltInternal.GlobalEventListenerBase.ZeusConnectFailed ( UdpEndPoint  endpoint)
inlinevirtual
virtual void BoltInternal.GlobalEventListenerBase.ZeusDisconnected ( UdpEndPoint  endpoint)
inlinevirtual
virtual void BoltInternal.GlobalEventListenerBase.ZeusNatProbeResult ( UdpKit.NatFeatures  features)
inlinevirtual