MatchMaker では他のマッチメイキングを検索することで、ゲストとしてマッチメイキングに参加することができます。
マッチメイキングのゲストとして、以下のことを実行することができます。
- マッチメイキングの検索
- 自動でマッチしたマッチメイキングに参加、あるいはマッチした一覧を取得して任意のマッチメイキングに手動で参加
- マッチした他のクライアントとのカスタムメッセージのやりとり
- 参加しているマッチメイキングから離脱する
- 参加しているマッチメイキングの完了通知を受け取る
- 参加しているマッチしたクライアントと P2P 通信をするためのアドレスを同期する
マッチメイキングを検索して自動で参加する
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>();
props.Add("lvl", (uint)10);
props.Add("league", (uint)2);
// If autoJoin is true, you will automatically join one of the matched matchmakings immediately.
bool autoJoin = true;
// Number of match results you ask for.
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, props, autoJoin, resultNum, joinedMessage);
検索のレスポンスを受け取る
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.
};
他のユーザーがマッチした際にサーバからの通知を受け取る
mm.OnMemberJoin += (byte[] joinMessage) => {
};
マッチメイキングを検索して結果一覧を受け取り、手動で参加する
検索したマッチメイキングの結果をサーバから取得して任意のものに手動で参加することも可能です。
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>();
props.Add("lvl", (uint)10);
props.Add("league", (uint)2);
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, props, autoJoin, resultNum, joinedMessage);
検索結果を取得して、手動でマッチメイキングに参加する
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);
};
参加処理のレスポンスを受け取る
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.
};
他のユーザーが参加した際に通知をつけとる
mm.OnMemberJoin += (byte[] joinMessage) => {
};
参加しているマッチメイキングから離脱する
byte[] leaveMessage = Encoding.UTF8.GetBytes("This message will be send to other matched user clients.");
mm.LeaveMatchmaking(leaveMessage);
離脱処理のレスポンスを受け取る
mm.OnLeaveResponse += (bool success, byte[] payload) =>
{
// If success is true, you have successfully left the current matchmaking.
};
他のユーザーが離脱した通知をつけとる
mm.OnMemberLeave += (byte[] leaveMessage) =>
{
};
他のユーザーがキックされた通知を受け取る
mm.OnKick += (string kickedOutUserID) =>
{
};
任意の同期メッセージを受信する
既に参加しているユーザーから任意で送られてくる同期メッセージをイベントとして受け取ることが可能です。
mm.OnMemberSync += (byte[] message) =>
{
};
マッチメイキングが完了した通知を受け取る
マッチメイキングの定員に達するとサーバから自動で OnComplete イベントの通知が参加している全てのクライアントで発生します。
またホストは任意に NotifyMatchmakingCompletion を実行することで、OnComplete イベントを発生させることが可能です。
mm.OnComplete += () =>
{
};
マッチメイキングが解散した通知を受け取る
ホストは任意にマッチメイキングを解散することができます。この際にマッチしているユーザーにはマッチメイキングが解散された通知が送信されます。
mm.OnDisbandMatchmaking += (byte[] message) =>
{
// message is a custom message byte array that the host decides to send when disbanding the matchmaking.
};
P2P 通信を開始するためにクライアントのアドレスを同期する
全ての参加しているユーザーに対して、参加ユーザー全員のクライアント・アドレスを共有することができます。
同期実行
mm.P2PAddressSync();
受信イベント
mm.OnP2PAddressSync += (byte) => {
// The list of all matched and joined user clients' client addresses.
// The format of the address string is "0.0.0.0:8888".
};