-
Notifications
You must be signed in to change notification settings - Fork 13
Game Session
The MDGameSession
class is initialized by the MDGameInstance
and can by accessed by any Node
by calling this.GetGameSession()
or elsewhere by using MDStatics.GetGameSession()
.
The class has 3 useful methods for managing your networked session.
For starting the server you can call:
bool StartServer(int Port, int MaxPlayers);
For connecting to the server from the client:
bool StartClient(string Address, int Port);
And finally for disconnecting (as either server or client)
void Disconnect();
There's also a method to start the session without the network but still trigger the Game Session events to make it easier when implementing your game:
bool StartStandalone();
Those 4 methods are all available as console commands to make it easier for you to start testing.
These events are all on MDGameSession
.
Triggered when the session begins for any mode (standalone, server, client)
Triggered when the session cannot start for server or client
Triggered when the session ends (disconnects)
Triggered on all clients whenever a player joins before initializing the player, including for the local player and existing players when joining in progress
- PeerId - The PeerId of the player that joined
Triggered on all clients when a player has completed initialization
- PeerId - The PeerId of the player that completed initialization
Triggered on all clients when a player leaves, right before the PlayerInfo is destroyed, also fires locally for each player when disconnecting from the server
- PeerId - The PeerId of the player that left
Triggered on all clients when a networked node is spawned
- NetworkedNode - The Node that was just spawned
Triggered on all clients right before the node is removed
- NetworkedNode - The Node is about to be removed
The MDPlayerInfo
class is the location for you to store all the information specific to a player.
A player info instance is created for each player on each player's game.
The player info is meant to be extended.
To do this, you must set the PlayerInfo type in your config file, it should match the C# class name (with namespace):
[GameInstance]
PlayerInfoType="MyPlayerInfo"
Then in your MyPlayerInfo
class, override void OnServerRequestedInitialization()
.
In MDPlayerInfo
you can see it sends a player name to the server.
Then once initialization is complete, call MarkPlayerInitializationCompleted()
which will notify the session that the player info is initialized and ready to be used.
By default, UPNP is disabled.
To enabled UPNP, change UseUPNP
in your config.