With MatchMaker client class, hosting a matchmaking is made simple.
When you host matchmaking, you will be able to wait for other user clients to find your matchmaking and join.
The host and other matched user clients will receive a notification every time a new user client matches and joins/leaves the matchmaking.
What You Can Do As A Host
Here is the list of actions you may take as a matchmaking host:
Clear (abort) your matchmaking and notify all matched (joined) user clients.
Send custom messages to matched (joined) user clients.
Notify matched (joined) user clients of matchmaking completion. The host may decide when to send this out otherwise the server will automatically notify all user clients when the matchmaking reaches its member limit.
Synchronize client addresses of all user clients for Diarkis P2P (peer-to-peer).
NOTE: The example below assumes there is a matchmaking profile called RankMatch defined on the server.
// Specify which matchmaking profile to use for your matchmakingstd::string profileID ="RankMatch";// Matchmaking condition propertiesstd::vector<MatchMakerCondition> conditionMap;MatchMakerCondition codition;codition.value = rankValue;codition.key ="rank";conditionMap.push_back(codition);std::vector<uint8_t> metadata(0); // empty// Unique ID to identify your matchmaking i.e. your user ID etc.std::string uid ="XXXXXXXXXXXXXXX";mm->SetUID(uid);// Define how many user clients allowed to join your matchmakingmm->SetMaxMembers(8);// Set ttlmm->SetTime(60);// Specify which matchmaking profile to use for your matchmakingmm->SetProfileID(profileID);// Set Matchmaking condition propertiesmm->SetProperties(conditionMap);// Set Metadatamm->SetMetaData(metadata);// Set this to true, if you wish to start multiple matchmakings without joining yourselfmm->SetReserveOnly(false);mm->HostMatchmaking();
Matchmaking Host Events
When you execute HostMatchmaking, the server sends a response to indicate if the operation was successful or not.
// Server response for HostMatchmaking// that tells you if becoming a host has failed or notvoid DiarkisMatchMakerBase::OnHostMatchmaking(constDiarkisMMHostEventArgs& e){}
Event Raised When A new Match Joins
When a new matched user client joins, all matched (and joined) user clients will raise the OnMemberJoin event.
void DiarkisMatchMakerBase::OnMemberJoin(constDiarkisMMSyncEventArgs& e){ // Message byte array data from the newly matched user client vector<uint8_t> payload =e.GetPayload(); std::string newUid((char*)payload.data(),payload.size()); // Process when a new member joins.}
Event Raised When A Match Leaves
When a matched user client leaves, all matched (and joined) user clients will raise the OnMemberLeave event.
void DiarkisMatchMakerBase::OnMemberLeave(constDiarkisMMSyncEventArgs& e){ vector<uint8_t> payload =e.GetPayload(); std::string leaveUid((char*)payload.data(),payload.size()); // Process when a member leaves the room.}
Event Raised When A Match Sends A Synchronizing Message
All matched (and joined) user clients may freely send messages to other matched user clients.
When the matchmaking reaches is MaxMatchMembers, the server raises the OnComplete event on all matched (and joined) user clients.
The host may freely trigger OnComplete as well.
Call NotifyMatchmakingCompletion
mm->NotifyMatchmakingCompletion();
Event
void DiarkisMatchMakerBase::OnComplete(void){}
Event Raised When Client Addresses For P2P Is Synchronized
All matched (and joined) user clients may synchronize client addresses to start P2P.
Synchronize
mm.P2PAddressSync();
Event
void DiarkisMatchMakerBase::OnP2PAddress(constDiarkisMMP2PEventArgs& e){ // The list of all matched and joined user clients' client addresses. // The format of the address string is "0.0.0.0:8888". std::vector<std::string> addressList =e.GetAddresses(); // Process P2P Connect}
Clear (Abort) The Matchmaking
You may abort your current matchmaking as a host. Clearing the matchmaking does NOT disband the matchmaking and the matched users remain with the matchmaking.
Clearing the matchmaking will make it ONLY remove itself from matchmaking searches.
You may disband the matchmaking. By disbanding the matchmaking, you will be destroying the matchmaking completely and all matched users will be removed from the matchmaking.
It is possible to use a room that is already in use ingame, for example, to invite a new user client in using MatchMaker again.
NotifyMatchmakingCompletion Once the matching is complete, you can use StartBackfill to make it searchable again.
Run backfill using a room that is already in use ingame.
string inGameRoomID =inGameRoom.GetRoomID();// We need to pass the room ID to start the backfillmm.StartBackfill(inGameRoomID);
Receiving Responses
void DiarkisMatchMakerBase::OnBackfillEvent(constDiarkisMMResponseEventArgs& e){ // If success is true, the backfill operation has successfully started.}
Kicking out any match participating user
A host can kick out a specific matched user from matchmaking.
When a user is ejected, a notification will be sent to other matched users (including the ejected user).
To perform an ejection
// You must pass the user ID of the user to kick out.mm.Kick(userIDToKickOut);
Receive response for execution of expulsion.
Receive the response from the server whether the expulsion was successful or not.