You may actively search for matchmaking hosts to match and join as a guest.
As a matchmaking guest, you may do the following:
- Search for matchmakings.
- Either join matched matchmaking automatically or have the server send the matched list of matchmakings to join manually.
- Send and receive custom messages to and from other matched and joined user clients.
- Leave an already matched and joined a matchmaking.
- Receive matchmaking completion notification.
- Synchronize P2P client addresses with already matched and joined user clients.
How To Search For Matchmakings With Auto Join
MatchMaker mm = new MatchMaker();
// MatchMaker will use the profiles in the order of the list until it finds results.
List<string> profileIDs = new List<string>();
profileIDs.Add(mm.MatchmakingProfileID);
// Search condition properties
Dictionary<string, uint> props = new Dictionary<string, uint>();
props1.Add("lvl", (uint)10);
props1.Add("league", (uint)2);
mm.Properties = props;
bool autoJoin = true;
ushort resultNum = 10;
byte[] joinedMessage = Encoding.UTF8.GetBytes("This message will be sent to the other matched user clients.");
// Start the search
mm.Search(profileIDs, autoJoin, resultNum, joinedMessage);
Receive The Response For The Search
mm.OnJoinResponse += (bool success, string[] memberIDs, byte[] payload) =>
{
// success will be true, if the search and auto-join was successful.
// memberIDs contains the list of matched and joined user client IDs that you just joined.
};
Receive A Notification From Another User Client For Joining
mm.OnMemberJoin += (byte[] joinMessage) => {
};
How To Search For Matchmakings And Join Manually
You may choose to receive a list of matchmakings from the server instead of auto-joining one.
MatchMaker mm = new MatchMaker();
// MatchMaker will use the profiles in the order of the list until it finds results.
List<string> profileIDs = new List<string>();
profileIDs.Add(mm.MatchmakingProfileID);
// Search condition properties
Dictionary<string, uint> props = new Dictionary<string, uint>();
props1.Add("lvl", (uint)10);
props1.Add("league", (uint)2);
mm.Properties = props;
bool autoJoin = false;
ushort resultNum = 10;
byte[] joinedMessage = Encoding.UTF8.GetBytes("This message will be sent to the other matched user clients.");
// Start the search
mm.Search(profileIDs, autoJoin, resultNum, joinedMessage);
Receive A List of Matched Matchmakings and Join One Of Them Manually
mm.OnResults += (bool success, MatchMaker.ResultItem[] results, byte[] payload) =>
{
// success will be true, if the search was successful.
// Results contain the list of matched matchmaking results.
if (results.Length == 0)
{
// no matchmakings found
return;
}
byte[] joinedMessage = Encoding.UTF8.GetBytes("This message will be sent to the other matched user clients.");
// For this example, we will chose the first result item and try to join it
mm.JoinMatchmakingFromResult(results[0], joinMessage);
};
Receive A Server Response For Join
mm.OnJoinResponse += (bool success, string[] memberIDs, byte[] payload) =>
{
// success will be true, if the search and auto-join was successful.
// memberIDs contains the list of matched and joined user client IDs that you just joined.
};
Receive A Notification From Another User Client For Joining
mm.OnMemberJoin += (byte[] joinMessage) => {
};
How To Leave A Current Matchmaking
byte[] leaveMessage = Encoding.UTF8.GetBytes("This message will be send to other matched user clients.");
mm.LeaveMatchmaking(leaveMessage);
Receive A Server Response For Leaving
mm.OnLeaveResponse += (bool success, byte[] payload) =>
{
// If success is true, you have successfully left the current matchmaking.
};
Receive A Notification From Other User Clients For Leaving
mm.OnMemberLeave += (byte[] leaveMessage) =>
{
};
Receive A Notification When A Matched Member Has Been Kicked Out
mm.OnKick += (string kickedOutUserID) =>
{
};