|
Dojo
|
Manage networking connections, matches, and user presences. More...
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, DojoNetworkRole > | MatchClients = 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 |
Manage networking connections, matches, and user presences.
|
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.
| address | running Nakama framework address |
| username | username on Nakama framework |
Task to be awaited
|
inline |
Get measured RTT between server and client in Nakama match.
Used in DojoTransport
Can be ignored in public code.
| user | target user |
|
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.
| targetMatch | target match ID |
Task to be awaited
|
inline |
Disconnect and leave a Nakama match.
Leave default parameters unchanged when using in public code.
| removeSelf | delete self presence on Nakama framework or not |
| reset | reset internal states or not |
Task to be awaited
|
inline |
Get active matches on Nakama.
Used in DojoMenu .
|
inline |
Get user profile on Nakama by user presence.
Used in DojoMenu .
| users | list of users to query |
|
inline |
Register number of AI players in the match.
| aiPlayerNames | name of the AI players |
|
inline |
Register custom switch role rules.
The rules get executed when a user tries to switch to another role.
| checkFunction | check function, given current role and target role, return the switch is allowed or not |
| name | check function id, using same name will overwrite previous rule |
|
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.
| opCode | message type identifier |
| message | message bytes |
| broadcast | broadcast this message or not |
| targets | array of target users to send this message to |
Task to be awaited
|
inline |
Send state message in current Nakama match.
Ignore if not connected to a match.
| opCode | message type identifier |
| message | message bytes |
| target | target user on Nakama |
Task to be awaited
|
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.
| opCode | message type identifier |
| message | message content |
| broadcast | broadcast this message or not |
| targets | array of target users to send this message to |
Task to be awaited
|
inline |
Send state message in current Nakama match.
Ignore if not connected to a match.
| opCode | message type identifier |
| message | message content |
| target | target user on Nakama |
Task to be awaited
|
inline |
Subscribe remote message callback in Nakama match.
| opCode | message type identifier |
| callback | callback function for registering |
| append | force only one callback for this message or not |
|
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.
| targetRole | target role to switch to |
|
inline |
Unsubscribe remote message callback in Nakama match.
| opCode | message type identifier |
| callback | same callback function used in SubscribeRemoteMessages |
| readonly Dictionary<IUserPresence, DojoNetworkRole> Dojo.DojoConnection.MatchClients = new() |
All current users in Nakama match
Mapping from user (Nakama.IUserPresence) to DojoNetworkRole
|
get |
Has connected to Nakama framework?
|
get |
Has joined a match on Nakama framework?
|
get |
Whether if current user is Client
|
get |
Whether if current user is Human Player
DojoNetworkRole.Player
|
get |
Whether if current user is Server
DojoNetworkRole.Server
|
get |
Whether if current user is Human Viewer
DojoNetworkRole.Viewer
|
get |
Current Nakama match unique ID
null if has not joined a match
|
get |
Current Nakama match label
null if has not joined a match
|
get |
Current user (Nakama.IUserPresence) in Nakama match
null if has not joined a match
|
get |
Server user (Nakama.IUserPresence) in Nakama match
null if has not joined a match
|
get |
User current role in Dojo network
| Action Dojo.DojoConnection.OnConnectionManagerReady |
Invoked when DojoConnection is ready
| Action Dojo.DojoConnection.OnJoinedMatch |
Invoked when current user joined a new match on Nakama
| Action Dojo.DojoConnection.OnLeftMatch |
Invoked when current user left current match on Nakama
| 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
| [in] | user | The user (Nakama.IUserPresence) that has joined |
| 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
| [in] | user | The user (Nakama.IUserPresence) that has left |
| 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
| [in] | user | The user (Nakama.IUserPresence) that has changed |