Dojo
Loading...
Searching...
No Matches
Dojo.DojoConnection Class Reference

Manage networking connections, matches, and user presences. More...

Inheritance diagram for Dojo.DojoConnection:

Public Member Functions

void SubscribeRemoteMessages (long opCode, Action< DojoMessage > callback, bool append=true)
 Subscribe remote message callback in Nakama match.
 
void UnsubscribeRemoteMessages (long opCode, Action< DojoMessage > callback)
 Unsubscribe remote message callback in Nakama match.
 
async Task ConnectNakama (string address="", string username="")
 Connect to Nakama framework and register a new user.
If address is empty, use IP address in NakamaConfig .
Empty username is only allowed when current role is Server or AI Player.
 
async Task JoinNakamaMatch (string targetMatch="")
 Join a Nakama match.
If targetMatch is empty, invoke RPC to allocate a new server to host a match.
If current Role is Server, ignore targetMatch and create a new match regardless.
This function will try to find and join a Nakama match within a maximum number of retries.
 
async Task LeaveNakamaMatch (bool removeSelf=true, bool reset=true)
 Disconnect and leave a Nakama match.
Leave default parameters unchanged when using in public code.
 
Task SendStateMessage (long opCode, string message, IUserPresence target)
 Send state message in current Nakama match.
Ignore if not connected to a match.
 
Task SendStateMessage (long opCode, ArraySegment< byte > message, IUserPresence target)
 Send state message in current Nakama match.
Ignore if not connected to a match.
 
Task SendStateMessage (long opCode, string message, bool broadcast=false, IEnumerable< IUserPresence > targets=null)
 Send state message in current Nakama match.
Ignore if not connected to a match.
If broadcast, this message will be sent to all users, regardless of targets.
If targets is null and IsClient is true, send this message to current Server .
If targets is null and IsServer is true, send this message to all clients in the match.
 
Task SendStateMessage (long opCode, ArraySegment< byte > message, bool broadcast=false, IEnumerable< IUserPresence > targets=null)
 Send state message in current Nakama match.
Ignore if not connected to a match.
If broadcast, this message will be sent to all users, regardless of targets.
If targets is null and IsClient is true, send this message to current Server .
If targets is null and IsServer is true, send this message to all clients in the match.
 
int RegisterAIPlayers (List< string > aiPlayerNames)
 Register number of AI players in the match.
 
async Task< List< MatchStorageData > > QueryActiveMatches ()
 Get active matches on Nakama.
Used in DojoMenu .
 
async Task< Dictionary< IUserPresence, IApiUser > > QueryUserDisplayNames (IEnumerable< IUserPresence > users)
 Get user profile on Nakama by user presence.
Used in DojoMenu .
 
void RegisterSwitchRoleRule (Func< DojoNetworkRole, DojoNetworkRole, bool > checkFunction, string name="default")
 Register custom switch role rules.
The rules get executed when a user tries to switch to another role.
 
void SwitchRole (DojoNetworkRole targetRole)
 Try to switch current role.
Only allowed when IsClient is true.
If has not joined a match, the switch is executed immediately.
Otherwise, sends a request to MatchServer to permit the switch.
 
ulong GetMeasuredRTT (IUserPresence user=default)
 Get measured RTT between server and client in Nakama match.
Used in DojoTransport
Can be ignored in public code.
 

Public Attributes

readonly Dictionary< IUserPresence, DojoNetworkRoleMatchClients = new()
 
readonly HashSet< string > MatchAIPlayers = new()
 

Properties

bool IsClient [get]
 
bool IsServer [get]
 
DojoNetworkRole Role = DojoNetworkRole.Viewer [get]
 
bool IsViewer [get]
 
bool IsPlayer [get]
 
bool HasConnected [get]
 
bool HasJoinedMatch [get]
 
IUserPresence MatchSelf [get]
 
IUserPresence MatchServer [get]
 
string MatchLabel [get]
 
string MatchID [get]
 

Events

Action OnConnectionManagerReady
 
Action OnJoinedMatch
 
Action OnLeftMatch
 
Action< IUserPresence > OnRoleChanged
 
Action< IUserPresence > OnMatchPlayerJoined
 
Action< IUserPresence > OnMatchPlayerLeft
 

Detailed Description

Manage networking connections, matches, and user presences.

Member Function Documentation

◆ ConnectNakama()

async Task Dojo.DojoConnection.ConnectNakama ( string  address = "",
string  username = "" 
)
inline

Connect to Nakama framework and register a new user.
If address is empty, use IP address in NakamaConfig .
Empty username is only allowed when current role is Server or AI Player.

Parameters
addressrunning Nakama framework address
usernameusername on Nakama framework
Returns
Task to be awaited

◆ GetMeasuredRTT()

ulong Dojo.DojoConnection.GetMeasuredRTT ( IUserPresence  user = default)
inline

Get measured RTT between server and client in Nakama match.
Used in DojoTransport
Can be ignored in public code.

Parameters
usertarget user
Returns
RTT in milliseconds

◆ JoinNakamaMatch()

async Task Dojo.DojoConnection.JoinNakamaMatch ( string  targetMatch = "")
inline

Join a Nakama match.
If targetMatch is empty, invoke RPC to allocate a new server to host a match.
If current Role is Server, ignore targetMatch and create a new match regardless.
This function will try to find and join a Nakama match within a maximum number of retries.

Parameters
targetMatchtarget match ID
Returns
Task to be awaited

◆ LeaveNakamaMatch()

async Task Dojo.DojoConnection.LeaveNakamaMatch ( bool  removeSelf = true,
bool  reset = true 
)
inline

Disconnect and leave a Nakama match.
Leave default parameters unchanged when using in public code.

Parameters
removeSelfdelete self presence on Nakama framework or not
resetreset internal states or not
Returns
Task to be awaited

◆ QueryActiveMatches()

async Task< List< MatchStorageData > > Dojo.DojoConnection.QueryActiveMatches ( )
inline

Get active matches on Nakama.
Used in DojoMenu .

Returns
list of match info

◆ QueryUserDisplayNames()

async Task< Dictionary< IUserPresence, IApiUser > > Dojo.DojoConnection.QueryUserDisplayNames ( IEnumerable< IUserPresence >  users)
inline

Get user profile on Nakama by user presence.
Used in DojoMenu .

Parameters
userslist of users to query
Returns
a mapping from user presence to user profile info

◆ RegisterAIPlayers()

int Dojo.DojoConnection.RegisterAIPlayers ( List< string >  aiPlayerNames)
inline

Register number of AI players in the match.

Parameters
aiPlayerNamesname of the AI players
Returns
size of registered AI players

◆ RegisterSwitchRoleRule()

void Dojo.DojoConnection.RegisterSwitchRoleRule ( Func< DojoNetworkRole, DojoNetworkRole, bool >  checkFunction,
string  name = "default" 
)
inline

Register custom switch role rules.
The rules get executed when a user tries to switch to another role.

Parameters
checkFunctioncheck function, given current role and target role, return the switch is allowed or not
namecheck function id, using same name will overwrite previous rule

◆ SendStateMessage() [1/4]

Task Dojo.DojoConnection.SendStateMessage ( long  opCode,
ArraySegment< byte >  message,
bool  broadcast = false,
IEnumerable< IUserPresence >  targets = null 
)
inline

Send state message in current Nakama match.
Ignore if not connected to a match.
If broadcast, this message will be sent to all users, regardless of targets.
If targets is null and IsClient is true, send this message to current Server .
If targets is null and IsServer is true, send this message to all clients in the match.

Parameters
opCodemessage type identifier
messagemessage bytes
broadcastbroadcast this message or not
targetsarray of target users to send this message to
Returns
Task to be awaited

◆ SendStateMessage() [2/4]

Task Dojo.DojoConnection.SendStateMessage ( long  opCode,
ArraySegment< byte >  message,
IUserPresence  target 
)
inline

Send state message in current Nakama match.
Ignore if not connected to a match.

Parameters
opCodemessage type identifier
messagemessage bytes
targettarget user on Nakama
Returns
Task to be awaited

◆ SendStateMessage() [3/4]

Task Dojo.DojoConnection.SendStateMessage ( long  opCode,
string  message,
bool  broadcast = false,
IEnumerable< IUserPresence >  targets = null 
)
inline

Send state message in current Nakama match.
Ignore if not connected to a match.
If broadcast, this message will be sent to all users, regardless of targets.
If targets is null and IsClient is true, send this message to current Server .
If targets is null and IsServer is true, send this message to all clients in the match.

Parameters
opCodemessage type identifier
messagemessage content
broadcastbroadcast this message or not
targetsarray of target users to send this message to
Returns
Task to be awaited

◆ SendStateMessage() [4/4]

Task Dojo.DojoConnection.SendStateMessage ( long  opCode,
string  message,
IUserPresence  target 
)
inline

Send state message in current Nakama match.
Ignore if not connected to a match.

Parameters
opCodemessage type identifier
messagemessage content
targettarget user on Nakama
Returns
Task to be awaited

◆ SubscribeRemoteMessages()

void Dojo.DojoConnection.SubscribeRemoteMessages ( long  opCode,
Action< DojoMessage callback,
bool  append = true 
)
inline

Subscribe remote message callback in Nakama match.

Parameters
opCodemessage type identifier
callbackcallback function for registering
appendforce only one callback for this message or not

◆ SwitchRole()

void Dojo.DojoConnection.SwitchRole ( DojoNetworkRole  targetRole)
inline

Try to switch current role.
Only allowed when IsClient is true.
If has not joined a match, the switch is executed immediately.
Otherwise, sends a request to MatchServer to permit the switch.

Parameters
targetRoletarget role to switch to

◆ UnsubscribeRemoteMessages()

void Dojo.DojoConnection.UnsubscribeRemoteMessages ( long  opCode,
Action< DojoMessage callback 
)
inline

Unsubscribe remote message callback in Nakama match.

Parameters
opCodemessage type identifier
callbacksame callback function used in SubscribeRemoteMessages

Member Data Documentation

◆ MatchClients

readonly Dictionary<IUserPresence, DojoNetworkRole> Dojo.DojoConnection.MatchClients = new()

All current users in Nakama match
Mapping from user (Nakama.IUserPresence) to DojoNetworkRole

Property Documentation

◆ HasConnected

bool Dojo.DojoConnection.HasConnected
get

Has connected to Nakama framework?

◆ HasJoinedMatch

bool Dojo.DojoConnection.HasJoinedMatch
get

Has joined a match on Nakama framework?

◆ IsClient

bool Dojo.DojoConnection.IsClient
get

Whether if current user is Client

◆ IsPlayer

bool Dojo.DojoConnection.IsPlayer
get

Whether if current user is Human Player
DojoNetworkRole.Player

◆ IsServer

bool Dojo.DojoConnection.IsServer
get

Whether if current user is Server
DojoNetworkRole.Server

◆ IsViewer

bool Dojo.DojoConnection.IsViewer
get

Whether if current user is Human Viewer
DojoNetworkRole.Viewer

◆ MatchID

string Dojo.DojoConnection.MatchID
get

Current Nakama match unique ID
null if has not joined a match

◆ MatchLabel

string Dojo.DojoConnection.MatchLabel
get

Current Nakama match label
null if has not joined a match

◆ MatchSelf

IUserPresence Dojo.DojoConnection.MatchSelf
get

Current user (Nakama.IUserPresence) in Nakama match
null if has not joined a match

◆ MatchServer

IUserPresence Dojo.DojoConnection.MatchServer
get

Server user (Nakama.IUserPresence) in Nakama match
null if has not joined a match

◆ Role

DojoNetworkRole Dojo.DojoConnection.Role = DojoNetworkRole.Viewer
get

User current role in Dojo network

Event Documentation

◆ OnConnectionManagerReady

Action Dojo.DojoConnection.OnConnectionManagerReady

Invoked when DojoConnection is ready

◆ OnJoinedMatch

Action Dojo.DojoConnection.OnJoinedMatch

Invoked when current user joined a new match on Nakama

◆ OnLeftMatch

Action Dojo.DojoConnection.OnLeftMatch

Invoked when current user left current match on Nakama

◆ OnMatchPlayerJoined

Action<IUserPresence> Dojo.DojoConnection.OnMatchPlayerJoined

Invoked when a remote user has joined current Nakama match
Only valid when current user has joined a Nakama match

Parameters
[in]userThe user (Nakama.IUserPresence) that has joined

◆ OnMatchPlayerLeft

Action<IUserPresence> Dojo.DojoConnection.OnMatchPlayerLeft

Invoked when a remote user has left current Nakama match
Only valid when current user has joined a Nakama match

Parameters
[in]userThe user (Nakama.IUserPresence) that has left

◆ OnRoleChanged

Action<IUserPresence> Dojo.DojoConnection.OnRoleChanged

Invoked a user on Dojo network has changed its Role
Only valid when current user has joined a Nakama match

Parameters
[in]userThe user (Nakama.IUserPresence) that has changed

The documentation for this class was generated from the following file: