ゲストとしてマッチメイキングを行う方法

MatchMaker では他のマッチメイキングを検索することで、ゲストとしてマッチメイキングに参加することができます。

マッチメイキングのゲストとして、以下のことを実行することができます。

  • マッチメイキングの検索
  • 自動でマッチしたマッチメイキングに参加、あるいはマッチした一覧を取得して任意のマッチメイキングに手動で参加
  • マッチした他のクライアントとのカスタムメッセージのやりとり
  • 参加しているマッチメイキングから離脱する
  • 参加しているマッチメイキングの完了通知を受け取る
  • 参加しているマッチしたクライアントと P2P 通信をするためのアドレスを同期する

マッチメイキングを検索して自動で参加する

MatchMaker クラスを初期化

#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); });
}

// 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);

検索のレスポンスを受け取る

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();
}

他のユーザーがマッチした際にサーバからの通知を受け取る

void DiarkisMatchMakerBase::OnMemberJoin(const DiarkisMMSyncEventArgs& 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 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);

検索結果を取得して、手動でマッチメイキングに参加する

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);
}

参加処理のレスポンスを受け取る

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();
}

他のユーザーが参加した際に通知をつけとる

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

参加しているマッチメイキングから離脱する

// 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);

離脱処理のレスポンスを受け取る

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

他のユーザーが離脱した通知をつけとる

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.

}

任意の同期メッセージを受信する

既に参加しているユーザーから任意で送られてくる同期メッセージをイベントとして受け取ることが可能です。

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

}

マッチメイキングが完了した通知を受け取る

マッチメイキングの定員に達するとサーバから自動で OnComplete イベントの通知が参加している全てのクライアントで発生します。

またホストは任意に NotifyMatchmakingCompletion を実行することで、OnComplete イベントを発生させることが可能です。

void DiarkisMatchMakerBase::OnComplete(void)
{

}

マッチメイキングが解散した通知を受け取る

ホストは任意にマッチメイキングを解散することができます。この際にマッチしているユーザーにはマッチメイキングが解散された通知が送信されます。

void DiarkisMatchMakerBase::OnDisbandMatchmaking(const DiarkisMMSyncEventArgs& e)
{
// message is a custom message byte array that the host decides to send when disbanding the matchmaking.
};

P2P 通信を開始するためにクライアントのアドレスを同期する

全ての参加しているユーザーに対して、参加ユーザー全員のクライアント・アドレスを共有することができます。

同期実行

mm.P2PAddressSync();

受信イベント

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

}