대결 목록 #

플레이어가 매치메이커를 사용하여 새 대결에서 함께 플레이할 상대(또는 팀원)를 찾을 수 있는 경우, 대결 목록은 플레이어가 즉시 가입할 수 있는 현재 진행 중인 대결을 표시하는 데 사용됩니다.

대결 목록을 사용하여 단순히 지정된 수의 활성 대결을 반환할 수 있지만 대결 레이블을 사용하여 활성 대결을 쿼리하고 플레이어가 원하는 기준에 따라 결과를 필터링하면 더 관련성 있는 대결과 더 매력적인 사용자 경험을 느낄 수 있습니다.

또한 label 대결 외에 권한 보유 상태 및 플레이어 수를 기준으로 결과를 필터링할 수 있습니다. 사용 가능한 모든 매개변수는 기능 참조를 참조하세요.

필터 대 쿼리 비교 #

label 대결 필드를 사용하여 결과를 나열하는 방법에는 일치하는 대결 필터링과 쿼리라는 두 가지가 있습니다.

예를 들어, skill=100-150 레이블이 있는 대결을 나열하려는 경우 일치하는 대결 필터링은 다음과 같습니다:

Server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
local nk = require("nakama")

local limit = 10
local isAuthoritative = true
local label = "skill=100-150"
local min_size = 0
local max_size = 4
local matches = nk.match_list(limit, isAuthoritative, label, min_size, max_size)

for _, match in ipairs(matches) do
  nk.logger_info(string.format("Match id %s", match.match_id))
end
Server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
limit := 10
isAuthoritative := true
label := "skill=100-150"
min_size := 0
max_size := 4

if matches, err := nk.MatchList(ctx, limit, isAuthoritative, label, min_size, max_size, ""); err != nil {
    logger.WithField("err", err).Error("Match list error.")
} else {
    for _, match := range matches {
        logger.Info("Match id %s", match.GetMatchId())
    }
}
Server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
function getMatchListings(context: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama) {
  const limit = 10
  const isAuthoritative = true;
  const label = "skill=100-150";
  const minSize = 0;
  const maxSize = 4;
  const matches = nk.matchList(limit, isAuthoritative, label, minSize, maxSize, "");

  matches.forEach(function (match) {
    logger.info("Match id '%s'", match.matchId);
  });
}

여기에서는 레이블의 문자열 값을 기반으로 필터링하므로 결과에는 일치하는 skill=100-150 레이블이 있는 대결만 포함됩니다. skill=100 또는 skill=150 레이블이 있는 대결은 반환되지 않습니다.

반환된 결과는 정확히 플레이어가 찾고 있는 것일 수 있지만 일치하는 대결을 전혀 찾지 못하면 좌절할 수 있습니다.

대안은 쿼리를 사용하여 원하는 기준에 따라 필터링된 사용 가능한 대결을 나열하는 것입니다. 이 경우 skill범위는 다음과 같습니다:

Server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
local nk = require("nakama")

local limit = 10
local isauthoritative = true
local label = ""
local min_size = 0
local max_size = 4
local query = "+label.skill>=100 +label.skill<=150"
local matches = nk.match_list(limit, isauthoritative, label, min_size, max_size, query)

for _, match in ipairs(matches) do
  nk.logger_info(string.format("Match id %s", match.match_id))
end
Server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
limit := 10
authoritative := true
label := ""
minSize := 0
maxSize := 4
query := "+label.skill>=100 +label.skill<=150"
matches, err := nk.MatchList(ctx, limit, authoritative, label, minSize, maxSize, query)

if err != nil {
    logger.WithField("err", err).Error("Match listings error.")
    return
}

for _, match := range matches {
    logger.Info("Match id %s", match.MatchId)
}
Server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
function findMatch(context: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama) {
  const limit = 10
  const isAuthoritative = true;
  const minSize = 0;
  const maxSize = 4;
  const query = "+label.skill>=100 +label.skill<=150";
  var matches = nk.matchList(limit, isAuthoritative, minSize, maxSize, query);

  matches.forEach(function (match) {
    logger.info("Match id '%s'", match.matchId);
  });
}

이 방법을 사용하면 결과에 100에서 150 사이의 skill 레이블과 일치하는 모든 대결이 포함됩니다.

쿼리 구문 문법을 사용하여 결과를 필터링하고 정렬하는 방법을 알아봅니다.

찾기 및 생성 #

여러분의 사용자에게 원활한 게임플레이 경험을 제공하기 위해 대결 목록이 일치하는 결과를 반환하지 못하는 경우 사용자를 위해 새 대결을 직접 생성할 수 있습니다.

위의 필터 예제 사용:

Server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
local nk = require("nakama")
local function findorcreatematch(limit, label, min_size, max_size)
  local matches = nk.match_list(limit, true, label, min_size, max_size)

  if (#matches > 0) then
    table.sort(matches, function(a, b)
      return a.size > b.size;
    end)
    return matches[1].match_id
  end

  local modulename = "supermatch"
  local initialstate = {}
  local match_id = nk.match_create(modulename, initialstate)
  return match_id
end
Server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
if matches, err := nk.MatchList(ctx, limit, true, label, min_size, max_size, "*"); err != nil {
    return "", err
} else {
    if len(matches) > 0 {
        sort.Slice(matches, func(i, j int) bool {
          return matches[i].Size < matches[j].Size
        })

        return matches[0].MatchId
    }
}

modulename := "supermatch"

if matchId, err := nk.MatchCreate(ctx, modulename, nil); err != nil {
    return "", err
} else {
    return matchId, nil
}

return "", nil
Server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
function findOrCreateMatch(context: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama): string {
  var matches = nk.matchList(limit, isAuthoritative, label, minSize, maxSize, "");

  // If matches exist, sort by match size and return the largest.
  if (matches.length > 0) {
    matches.sort(function (a, b) {
      return a.size >= b.size ? 1 : -1;
    });
    return matches[0].matchId;
  }

  // If no matches exist, create a new one using the "lobby" module and return it's ID.
  var matchId = nk.matchCreate('supermatch', {});
  return JSON.stringify({ matchId });
}

대결을 쿼리할 때도 이렇게 할 수 있습니다:

Server
1
2
3
4
5
6
7
8
9
local query = "+label.skill>=100 +label.skill<=150"
local matches = nk.match_list(10, true, "", 2, 4, query)

if #matches > 0 then
  nk.logger_info(matches[0].match_id)
else
  local match_id = nk.match_create("matchname", {})
  nk.logger_info(match_id)
end
Server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
query := "+label.skill>=100 +label.skill<=150"
matches, err := nk.MatchList(ctx, 1, true, "", 2, 4, query)

if err != nil {
    logger.WithField("err", err).Error("List match error.")
    return
}

if len(matches) > 0 {
    logger.Info(matches[0].MatchId)
} else {
    matchId, err := nk.MatchCreate(ctx, "matchname", nil)

    if err != nil {
        logger.WithField("err", err).Error("Match create error.")
        return
    }

    logger.Info(matchId)
}
Server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
function findOrCreateMatch(context: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama) {
  const query = "+label.skill>=100 +label.skill<=150";
  var matches = nk.matchList(10, true, "", 2, maxSize, query);

  // If matches exist, sort by match size and return the largest.
  if (matches.length > 0) {
    logger.info("Match id '%s'", matches[0].matchId);
  }

  // If no matches exist, create a new one using the "lobby" module and return it's ID.
  var matchId = nk.matchCreate('supermatch', {});
  logger.info(matchId);
}

#

플레이어 수 #

minSizemaxSize 매개변수를 사용하여 지정된 수의 플레이어가 포함된 대결만 나열할 수 있습니다. 이는 이미 거의 가득 찬 결과를 반환하는 데 유용할 수 있습니다(따라서 대결이 거의 시작할 때임).

예를 들어, 8명의 플레이어가 가입하면 경기가 시작된다고 가정하고 5-7명의 플레이어가 있는 대결만 나열합니다:

Server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
local nk = require("nakama")

local limit = 10
local isAuthoritative = true
local min_size = 5
local max_size = 7
local matches = nk.match_list(limit, isAuthoritative, min_size, max_size)

for _, match in ipairs(matches) do
  nk.logger_info(string.format("Match id %s", match.match_id))
end
Server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
limit := 10
isAuthoritative := true
min_size := 5
max_size := 7

if matches, err := nk.MatchList(ctx, limit, isAuthoritative, min_size, max_size, ""); err != nil {
    logger.WithField("err", err).Error("Match list error.")
} else {
    for _, match := range matches {
        logger.Info("Match id %s", match.GetMatchId())
    }
}
Server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
function getMatchListings(context: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama) {
  const limit = 10
  const isAuthoritative = true;
  const minSize = 5;
  const maxSize = 7;
  const matches = nk.matchList(limit, isAuthoritative, minSize, maxSize, "");

  matches.forEach(function (match) {
    logger.info("Match id '%s'", match.matchId);
  });
}

Related Pages