Provides functionality for creating, listing, joining, and leaving matches. More...
Inherits MonoBehaviour.
Public Member Functions | |
IEnumerator | ConnectToMatchmaker () |
Connect to the matchmaking server. This called automatically in Start(). More... | |
void | CreateMatch (int v, Dictionary< string, MatchData > matchData, object onMatchCreated) |
void | CreateMatch (int maxClients, Dictionary< string, MatchData > matchData=null, Action< bool, Match > onCreateMatch=null) |
Send the command to the matchmaking server to create a new match. More... | |
void | DestroyMatch (Action< bool > onDestroyMatch=null) |
Destroy a match. This also removes all Client entries and MatchData on the matchmaking server. More... | |
void | GetMatch (Action< bool, Match > onGetMatch, int id, bool includeMatchData=true) |
Get info on a single match More... | |
void | GetMatchList (Action< bool, Match[]> onMatchList, int pageNumber=0, int resultsPerPage=10, List< MatchFilter > filters=null, bool includeMatchData=true) |
Get the match list, optionally filtering the results. More... | |
void | JoinMatch (Match match, Action< bool, Match > onJoinMatch=null) |
Join one of the matches returned my GetMatchList(). More... | |
void | LeaveMatch (Action< bool > onLeaveMatch=null) |
Leave a match. More... | |
void | SetMatchData (string key, MatchData matchData, Action< bool, Match > onSetMatchData=null) |
Set a single MatchData value and immediately send it to the matchmaking server. More... | |
void | SetMatchData (Dictionary< string, MatchData > matchData, Action< bool, Match > onSetMatchData=null) |
Replace all existing match data with new match data. More... | |
void | UpdateMatchData (Dictionary< string, MatchData > additionalData, Action< bool, Match > onUpdateMatchData=null) |
Merge new MatchData with existing MatchData and immediately send it all to the matchmaking server. More... | |
void | UpdateMatchData (Action< bool, Match > onUpdateMatchData=null) |
Send current MatchData to the matchmaking server. More... | |
Static Public Member Functions | |
static IEnumerator | FetchExternalIP (string ipSource) |
Fetch the external IP More... | |
static string | GetLocalAddress (AddressFamily family) |
Gets the a local address by looping through all network interfaces and returning first address from the first interface whose OperationalStatus is Up and whose address family matches the provided family. More... | |
static string | PickCorrectAddressToConnectTo (string hostExternalIP, string hostInternalIP) |
Select between internal and external IP. More... | |
Public Attributes | |
Match | currentMatch |
The current Match. This is set whenever a Match is created or joined. More... | |
string | externalIPSource = "ipv4.noblewhale.com" |
A web service to query to retrieve the external IP of this computer. More... | |
int | matchmakerPort = 20204 |
The port to connect to on the matchmaking server. More... | |
string | matchmakerURL = "noblewhale.com" |
The url of the matchmaking server. More... | |
int | maxReconnectionAttempts = 5 |
How many times to attempt to re-connect to the matchmaking server if connection is lost. More... | |
Action | onLostConnectionToMatchmakingServer = null |
You can use this action to be informed if connection is lost to the matchmaking server More... | |
float | timeout = 5 |
How long to wait for a response before giving up More... | |
Static Public Attributes | |
static string | externalIP |
The externalIP which is fetched from an external server More... | |
Protected Member Functions | |
virtual void | Update () |
Check for incoming responses from the matchmaking server. More... | |
Properties | |
bool | IsReady [get] |
Returns true when the matchmaking server has been succesfully connected to. More... | |
Provides functionality for creating, listing, joining, and leaving matches.
Opens up a tcp socket connection to the matchmaking server in order to send commands and receive responses. Most methods take an optional callback parameter which you can use to get the response once it is received.
IEnumerator ConnectToMatchmaker | ( | ) |
Connect to the matchmaking server. This called automatically in Start().
Called automatically on start and also when reconnecting after a lost connection. You can also call it yourself if you implement your own re-connection scheme or for whatever other reason you may find.
void CreateMatch | ( | int | maxClients, |
Dictionary< string, MatchData > | matchData = null , |
||
Action< bool, Match > | onCreateMatch = null |
||
) |
Send the command to the matchmaking server to create a new match.
maxClients | The maximum number of clients to allow. Once a match is full it is no longer returned in match listings (until a client leaves). |
matchData | Optional match data to include with the match. This is a good place to store your connection data. |
matchName | The name of the match. |
onCreateMatch | Optional callback method to call when a response is received from the matchmaking server. |
void DestroyMatch | ( | Action< bool > | onDestroyMatch = null | ) |
Destroy a match. This also removes all Client entries and MatchData on the matchmaking server.
onDestroyMatch | Optional callback method to call when a response is received from the matchmaking server. |
|
static |
Fetch the external IP
ipSource | The url from which to fetch the IP |
|
static |
Gets the a local address by looping through all network interfaces and returning first address from the first interface whose OperationalStatus is Up and whose address family matches the provided family.
void GetMatch | ( | Action< bool, Match > | onGetMatch, |
int | id, | ||
bool | includeMatchData = true |
||
) |
Get info on a single match
onGetMatch | Callback method to call when the response is received from the matchmaking server |
id | The ID of the match to fetch info for |
includeMatchData | Whether or not to include match data in the response |
void GetMatchList | ( | Action< bool, Match[]> | onMatchList, |
int | pageNumber = 0 , |
||
int | resultsPerPage = 10 , |
||
List< MatchFilter > | filters = null , |
||
bool | includeMatchData = true |
||
) |
Get the match list, optionally filtering the results.
Ex:
onMatchList | Callback method to call when a response is received from the matchmaking server. |
pageNumber | Used with resultsPerPage. Determines which page of results to return. Defaults to 0. |
resultsPerPage | User with pageNumber. Determines how many matches to return for each page. Defaults to 10. |
filters | Optional List of Filters to use when fetching the match list |
includeMatchData | By default match data is included for every match in the list. If you don't need / want this you can pass false in here and save some bandwidth. If you don't retrieve match data here you can still get it when joining the match. |
Join one of the matches returned my GetMatchList().
You can use the callback to get the Match object after it is received from the matchmaking server. Once the match is joined you'll have access to all the match's MatchData.
match | The Match to join. Generally this will come from GetMatchList() |
onJoinMatch | Optional callback method to call when a response is received from the matchmaking server. |
void LeaveMatch | ( | Action< bool > | onLeaveMatch = null | ) |
Leave a match.
onLeaveMatch | Optional callback method to call when a response is received from the matchmaking server. |
|
static |
Select between internal and external IP.
Most of the time we connect to the externalIP but when connecting to another PC on the same local network or another build on the same computer we need to use the local address or localhost instead
hostExternalIP | The host's external IP |
hostInternalIP | The host's internal IP |
Set a single MatchData value and immediately send it to the matchmaking server.
Ex:
key | The key |
matchData | The value |
onSetMatchData | Optional callback method to call when a response is received from the matchmaking server. |
void SetMatchData | ( | Dictionary< string, MatchData > | matchData, |
Action< bool, Match > | onSetMatchData = null |
||
) |
Replace all existing match data with new match data.
Ex:
matchData | A Dictionary of new MatchData |
onSetMatchData | Optional callback method to call when a response is received from the matchmaking server. |
|
protectedvirtual |
Check for incoming responses from the matchmaking server.
void UpdateMatchData | ( | Dictionary< string, MatchData > | additionalData, |
Action< bool, Match > | onUpdateMatchData = null |
||
) |
Merge new MatchData with existing MatchData and immediately send it all to the matchmaking server.
Ex:
additionalData | A Dictionary of additional MatchData to merge into existing match data |
onUpdateMatchData | Optional callback method to call when a response is received from the matchmaking server. |
void UpdateMatchData | ( | Action< bool, Match > | onUpdateMatchData = null | ) |
Send current MatchData to the matchmaking server.
Ex:
onUpdateMatchData | Optional callback method to call when a response is received from the matchmaking server. |
|
static |
The externalIP which is fetched from an external server
string externalIPSource = "ipv4.noblewhale.com" |
A web service to query to retrieve the external IP of this computer.
int matchmakerPort = 20204 |
The port to connect to on the matchmaking server.
Leave this as default unless you started the server on a specific port using
string matchmakerURL = "noblewhale.com" |
The url of the matchmaking server.
You can use mine for testing but it could go offline at any time so don't even think of trying to release a game without hosting your own matchmaking server.
int maxReconnectionAttempts = 5 |
How many times to attempt to re-connect to the matchmaking server if connection is lost.
When the connection is lost the Matchmaker will automatically try and reconnect this many times. If you wish to implement your own reconnect behaviour, use the onLostConnectonToMatchmakingServer action and set this to 0 to disable the default behaviour.
Action onLostConnectionToMatchmakingServer = null |
You can use this action to be informed if connection is lost to the matchmaking server
Generally this means someone pulled out the internet plug or something equally catastrophic. If the connection is lost on the host, the current match is destroyed. If the connection is lost on the client, the current match is left. When the connection is lost the Matchmaker will automatically try and reconnect. If you wish to implement your own reconnect behaviour make sure to set maxReconnectionAttempts to 0 to disable the default behaviour.
float timeout = 5 |
How long to wait for a response before giving up
|
get |
Returns true when the matchmaking server has been succesfully connected to.