How To Become A Matchmaking Guest

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

Initalize MatchMaker Class

#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_))

  // Set logger
  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); });
}

// Specify which matchmaking profile to use for your matchmaking
std::vector<std::string> profileIDs;
profileIDs.push_back("RankMatch");

// Matchmaking condition properties
std::vector<MatchMakerCondition> conditionMap;
MatchMakerCondition codition;
codition.value = rankValue;
codition.key = "rank";
conditionMap.push_back(codition);

// If set to true, the client will automatically joins the matched matchmaking room
// and OnSearch event will be raised.
bool joinFlag = true;

// Determine maximum how many matched results to expect by the search results.
uint16_t howmany = 4;

// For example, send your UID.
std::string uid = "XXXXXXXXXXXXXXX";
std::vector<uint8_t> message((uint8_t*)uid.data(), (uint8_t*)uid.data()+uid.size());

mm->Search(profileIDs, conditionMap, joinFlag, howmany, message);

Receive The Response For The Search

void DiarkisMatchMakerBase::OnSearch(const DiarkisMMJoinResponseEventArgs& e)
{
// success will be true, if the search and auto-join was successful.
bool bSuccess = e.IsSuccess();

// memberIDs contains the list of matched and joined user client IDs that you just joined.
std::vector<std::string> members = e.GetMemberIDs();
}
void DiarkisMatchMakerBase::OnJoin(const DiarkisMMJoinResponseEventArgs& e)
{
// success will be true, if the search and auto-join was successful.
bool bSuccess = e.IsSuccess();

  // memberIDs contains the list of matched and joined user client IDs that you just joined.
    std::vector<std::string> members = e.GetMemberIDs();
}

Receive A Notification From Another User Client For Joining

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

}

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.

// Specify which matchmaking profile to use for your matchmaking
std::vector<std::string> profileIDs;
profileIDs.push_back("RankMatch");

// Matchmaking condition properties
std::vector<MatchMakerCondition> conditionMap;
MatchMakerCondition codition;
codition.value = rankValue;
codition.key = "rank";
conditionMap.push_back(codition);

// If set to false, search will send a list of matched result back to the client
// with OnResults event.
bool joinFlag = false;

// Determine maximum how many matched results to expect by the search results.
uint16_t howmany = 4;

// For example, send your UID.
std::string uid = "XXXXXXXXXXXXXXX";
std::vector<uint8_t> message((uint8_t*)uid.data(), (uint8_t*)uid.data()+uid.size());

mm->Search(profileIDs, conditionMap, joinFlag, howmany, message);

Receive A List of Matched Matchmakings and Join One Of Them Manually

void DiarkisMatchMakerBase::OnResutls(const DiarkisMMResultEventArgs& e)
{
  // success will be true, if the search was successful.
bool bSuccess = e.IsSuccess();

// Results contain the list of matched matchmaking results.
    std::vector<MatchMakerResultItem*> results = e.GetResultItem();
   if (results.size() == 0)
{
// no matchmakings found
return;
}

// For example, send your UID.
   std::string uid = "XXXXXXXXXXXXXXX";
std::vector<uint8_t> message((uint8_t*)uid.data(), (uint8_t*)uid.data()+uid.size());

// For this example, we will chose the first result item and try to join it
   mm->JoinMatchmakingFromResult(results[0], message);
}

Receive A Server Response For Join

void DiarkisMatchMakerBase::OnJoin(const DiarkisMMJoinResponseEventArgs& e)
{
// success will be true, if the search and auto-join was successful.
bool bSuccess = e.IsSuccess();

  // memberIDs contains the list of matched and joined user client IDs that you just joined.
    std::vector<std::string> members = e.GetMemberIDs();
}

Receive A Notification From Another User Client For Joining

void DiarkisMatchMakerBase::OnMemberJoin(const DiarkisMMSyncEventArgs& e)
{
    vector<uint8_t> payload = e.GetPayload();
    std::string newUid((char*)payload.data(), payload.size());

// Process when a new member joins.
}

How To Leave A Current Matchmaking

// For example, send your UID.
std::string uid= "XXXXXXXXXXXXXXX";
std::vector<uint8_t> message((uint8_t*)uid.data(), (uint8_t*)uid.data()+uid.size());

mm->LeaveMatchmaking(message);

Receive A Server Response For Leaving

void DiarkisMatchMakerBase::OnLeave(const DiarkisMMResponseEventArgs& e)
{
// If success is true, you have successfully left the current matchmaking.
}

Receive A Notification From Other User Clients For Leaving

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

mm.OnComplete += () =>
{

};

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

mm.OnP2PAddressSync += (string[] addressList) => {
// The list of all matched and joined user clients' client addresses.
// The format of the address string is "0.0.0.0:8888".
};