How To Become A Matchmaking Host

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).

Hosting A Matchmaking

#define REG_EVENT(__EVENT__, __LAMBDA__) this->eventUnsubscriptions.push_back(__EVENT__->Register(__LAMBDA__))

void DiarkisMatchMakerBase::SetupUdpMatchMaker(std::shared_ptr<IDiarkisUdp> udp_, std::shared_ptr<LoggerFactory> loggerFactory)
{
mm = shared_ptr<IDiarkisMatchMaker>(DiarkisCreateMatchMaker());
mm->SetupAsUdp(udp_))

// クライアントライブラリで使用するロガーをセットする
mm->SetLoggerFactory(loggerFactory, "-UDP");

REG_EVENT(mm->GetHostEvent(), [this](void*, const DiarkisMMHostEventArgs& e) { OnHostMatchmaking(e); });
REG_EVENT(mm->GetAbortEvent(), [this](void*, const DiarkisMMResponseEventArgs& e) { OnAbortMatchmaking(e);});
REG_EVENT(mm->GetDisbandEvent(), [this](void*, const DiarkisMMSyncEventArgs& e) { OnDisbandMatchmaking(e);});
REG_EVENT(mm->GetMemberLeaveEvent(), [this](void*, const DiarkisMMSyncEventArgs& e) { OnMemberLeave(e); });
REG_EVENT(mm->GetMemberJoinEvent(), [this](void*, const DiarkisMMSyncEventArgs& e) { OnMemberJoin(e); });
REG_EVENT(mm->GetMemberSyncEvent(), [this](void*, const DiarkisMMSyncEventArgs& e) { OnMemberSync(e); });
  REG_EVENT(mm->GetJoinEvent(), [this](void*, const DiarkisMMJoinResponseEventArgs& e) { OnJoin(e); });
REG_EVENT(mm->GetLeaveEvent(), [this](void*, const DiarkisMMResponseEventArgs& e) { OnLeave(e); });

  REG_EVENT(mm->GetCompleteEvent(), [this](void*, void*) { OnComplete(); });
REG_EVENT(mm->GetSearchEvent(), [this](void*, const DiarkisMMJoinResponseEventArgs& e) { OnSearch(e); });

 REG_EVENT(mm->GetResultsEvent(), [this](void*, const DiarkisMMResultEventArgs& e) { OnResutls(e); });
 REG_EVENT(mm->GetP2PAddressEvent(), [this](void*, const DiarkisMMP2PEventArgs& e) { OnP2PAddress(e); });

  REG_EVENT(mm->GetP2PResponseEvent(), [this](void*, const DiarkisMMResponseEventArgs& e) { OnP2PResponse(e); });
 REG_EVENT(mm->GetBackfillEvent(), [this](void*, const DiarkisMMResponseEventArgs& e) { OnBackfillEvent(e); });
REG_EVENT(mm->GetKickEvent(), [this](void*, const DiarkisPayloadEventArgs& e) { OnKick(e); });
  REG_EVENT(mm->GetKickResponseEvent(), [this](void*, const DiarkisMMResponseEventArgs& e) { OnKickResponse(e); });
}

NOTE: The example below assumes there is a matchmaking profile called RankMatch defined on the server.

// Specify which matchmaking profile to use for your matchmaking
std::string profileID = "RankMatch";

// Matchmaking condition properties
std::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 matchmaking
mm->SetMaxMembers(8);

// Set ttl
mm->SetTime(60);

// Specify which matchmaking profile to use for your matchmaking
mm->SetProfileID(profileID);

// Set Matchmaking condition properties
mm->SetProperties(conditionMap);

// Set Metadata
mm->SetMetaData(metadata);

// Set this to true, if you wish to start multiple matchmakings without joining yourself
mm->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 not
void DiarkisMatchMakerBase::OnHostMatchmaking(const DiarkisMMHostEventArgs& 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(const DiarkisMMSyncEventArgs& 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(const DiarkisMMSyncEventArgs& 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.

void DiarkisMatchMakerBase::OnMemberSync(const DiarkisMMSyncEventArgs& e)
{

}

Event Raised When The Matchmaking is Completed

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(const DiarkisMMP2PEventArgs& 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.

mm->AbortMatchmaking();

Receive Server Response

void DiarkisMatchMakerBase::OnAbortMatchmaking(const DiarkisMMResponseEventArgs& e)
{

}

Disbanding The Matchmaking

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.

std::string msg = "Disband";
std::vector<uint8_t> payload((uint8_t*)msg.data(), (uint8_t*)msg.data() + msg.size());

mm->DisbandMatchmaking(payload);

Receive Notification For Matchmaking Disbandment

void DiarkisMatchMakerBase::OnDisbandMatchmaking(const DiarkisMMSyncEventArgs& e)
{

}

Run backfill

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 backfill
mm.StartBackfill(inGameRoomID);

Receiving Responses

void DiarkisMatchMakerBase::OnBackfillEvent(const DiarkisMMResponseEventArgs& 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.

void DiarkisMatchMakerBase::OnKickResponse(const DiarkisMMResponseEventArgs& e)
{

}

Receive notification that a user has been kicked out.

void DiarkisMatchMakerBase::OnKick(const DiarkisPayloadEventArgs& e)
{

};