Class: Gs2::Matchmaking::Client

Inherits:
Core::AbstractClient
  • Object
show all
Defined in:
lib/gs2/matchmaking/Client.rb

Overview

GS2-Matchmaking クライアント

Author:

  • Game Server Services, Inc.

Constant Summary

@@ENDPOINT =
'matchmaking'
@@VARIATION =
'a'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region, gs2_client_id, gs2_client_secret) ⇒ Client

コンストラクタ

Parameters:

  • region (String)

    リージョン名

  • gs2_client_id (String)

    GSIクライアントID

  • gs2_client_secret (String)

    GSIクライアントシークレット



18
19
20
# File 'lib/gs2/matchmaking/Client.rb', line 18

def initialize(region, gs2_client_id, gs2_client_secret)
  super(region, gs2_client_id, gs2_client_secret)
end

Class Method Details

.ENDPOINT(v = nil) ⇒ Object

デバッグ用。通常利用する必要はありません。



23
24
25
26
27
28
29
# File 'lib/gs2/matchmaking/Client.rb', line 23

def self.ENDPOINT(v = nil)
  if v
    @@ENDPOINT = v
  else
    return @@ENDPOINT
  end
end

.VARIATION(v = nil) ⇒ Object

デバッグ用。通常利用する必要はありません。



32
33
34
35
36
37
38
# File 'lib/gs2/matchmaking/Client.rb', line 32

def self.VARIATION(v = nil)
  if v
    @@VARIATION = v
  else
    return @@VARIATION
  end
end

Instance Method Details

#anybody_describe_joined_user(request) ⇒ Array

Anybodyマッチメイキング - ギャザリングに参加しているユーザID一覧取得を実行

accessToken には Gs2::Auth::Client::login() でログインして取得したアクセストークンを指定してください。

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名

    • gatheringId => ギャザリングID

    • accessToken => アクセストークン

Returns:

  • (Array)
    • items => 参加ユーザID一覧



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/gs2/matchmaking/Client.rb', line 293

def anybody_describe_joined_user(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  if not request.has_key?('gatheringId'); raise ArgumentError.new(); end
  if not request['gatheringId']; raise ArgumentError.new(); end
  if not request.has_key?('accessToken'); raise ArgumentError.new(); end
  if not request['accessToken']; raise ArgumentError.new(); end
  query = {}
  header = {
    'X-GS2-ACCESS-TOKEN' => request['accessToken']
  }
  return get(
      'Gs2Matchmaking',
      'DescribeJoinedUser',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/' + request['matchmakingName'] + "/anybody/" + request['gatheringId'] + "/player",
      query,
      header);
end

#anybody_do_matchmaking(request) ⇒ Array

Anybodyマッチメイキング - マッチメイキングを実行

Anybodyマッチメイキングのマッチメイキングプロセスは、このAPIを呼び出すことで完結します。
このAPIを呼び出した段階で参加者を待っているギャザリングが存在すれば参加し、
参加者を待っているギャザリングが存在しなければ、新しくギャザリングに作成して、そのギャザリングに参加します。

戻り値にはギャザリングに参加している人数が含まれますので、自分がギャザリングを作成したのかはそこで確認することができます。

マッチメイキング完了コールバックをが返るまで待つことでマッチメイキングの完了を待つことができます。
マッチメイキングの進捗を確認したい場合は #anybody_describe_joined_user を呼び出すことで、
ギャザリングに参加しているユーザIDが取得できるため、誰とマッチメイキングが行われているか途中経過を取得できます。

ユーザ操作などにより、マッチメイキングを中断する場合は #anybody_leave_gathering を呼び出すことで中断できます。
GS2-Matchmaking にはホストという明確な役割は存在しないため、ギャザリングを作成したユーザがマッチメイキングを中断したとしてもマッチメイキングは継続されます。

accessToken には Gs2::Auth::Client::login() でログインして取得したアクセストークンを指定してください。

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名

    • accessToken => アクセストークン

Returns:

  • (Array)
    • item

      • gatheringId => ギャザリングID

      • joinPlayer => 参加プレイヤー数

      • updateAt => 更新日時



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/gs2/matchmaking/Client.rb', line 261

def anybody_do_matchmaking(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  if not request.has_key?('accessToken'); raise ArgumentError.new(); end
  if not request['accessToken']; raise ArgumentError.new(); end
  body = {}
  query = {}
  header = {
    'X-GS2-ACCESS-TOKEN' => request['accessToken']
  }
  return post(
      'Gs2Matchmaking',
      'DoMatchmaking',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/' + request['matchmakingName'] + "/anybody",
      body,
      query,
      header);
end

#anybody_leave_gathering(request) ⇒ Object

Anybodyマッチメイキング - ギャザリングからの離脱を実行

accessToken には Gs2::Auth::Client::login() でログインして取得したアクセストークンを指定してください。

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名

    • gatheringId => ギャザリングID

    • accessToken => アクセストークン



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/gs2/matchmaking/Client.rb', line 323

def anybody_leave_gathering(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  if not request.has_key?('gatheringId'); raise ArgumentError.new(); end
  if not request['gatheringId']; raise ArgumentError.new(); end
  if not request.has_key?('accessToken'); raise ArgumentError.new(); end
  if not request['accessToken']; raise ArgumentError.new(); end
  query = {}
  header = {
    'X-GS2-ACCESS-TOKEN' => request['accessToken']
  }
  delete(
      'Gs2Matchmaking',
      'LeaveGathering',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/' + request['matchmakingName'] + "/anybody/" + request['gatheringId'] + "/player",
      query,
      header);
end

#create_matchmaking(request) ⇒ Array

マッチメイキングを作成

GS2-Matchmaking を利用するためにまず作成するデータモデルです。
マッチメイキングの設定項目として、マッチメイキングの方式や最大プレイヤー数を設定します。

Parameters:

  • request (Array)
    • name => マッチメイキング名

    • description => 説明文

    • serviceClass => サービスクラス

    • type => 種類

    • maxPlayer => 最大プレイヤー数

    • callback => コールバックURL

Returns:

  • (Array)
    • item

      • matchmakingId => マッチメイキングID

      • ownerId => オーナーID

      • name => マッチメイキング名

      • description => 説明文

      • type => 種類

      • maxPlayer => 最大プレイヤー数

      • serviceClass => サービスクラス

      • callback => コールバックURL

      • createAt => 作成日時

      • updateAt => 更新日時



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/gs2/matchmaking/Client.rb', line 110

def create_matchmaking(request)
  if not request; raise ArgumentError.new(); end
  body = {}
  if request.has_key?('name'); body['name'] = request['name']; end
  if request.has_key?('description'); body['description'] = request['description']; end
  if request.has_key?('serviceClass'); body['serviceClass'] = request['serviceClass']; end
  if request.has_key?('type'); body['type'] = request['type']; end
  if request.has_key?('maxPlayer'); body['maxPlayer'] = request['maxPlayer']; end
  if request.has_key?('callback'); body['callback'] = request['callback']; end
  query = {}
  return post(
        'Gs2Matchmaking', 
        'CreateMatchmaking', 
        @@ENDPOINT, 
        @@VARIATION,
        '/matchmaking',
        body,
        query);
end

#custom_auto_describe_joined_user(request) ⇒ Array

CustomAutoマッチメイキング - ギャザリングに参加しているユーザID一覧取得を実行

accessToken には Gs2::Auth::Client::login() でログインして取得したアクセストークンを指定してください。

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名

    • gatheringId => ギャザリングID

    • accessToken => アクセストークン

Returns:

  • (Array)
    • items => 参加ユーザID一覧



444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
# File 'lib/gs2/matchmaking/Client.rb', line 444

def custom_auto_describe_joined_user(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  if not request.has_key?('gatheringId'); raise ArgumentError.new(); end
  if not request['gatheringId']; raise ArgumentError.new(); end
  if not request.has_key?('accessToken'); raise ArgumentError.new(); end
  if not request['accessToken']; raise ArgumentError.new(); end
  query = {}
  header = {
    'X-GS2-ACCESS-TOKEN' => request['accessToken']
  }
  return get(
      'Gs2Matchmaking',
      'DescribeJoinedUser',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/' + request['matchmakingName'] + "/customauto/" + request['gatheringId'] + "/player",
      query,
      header);
end

#custom_auto_do_matchmaking(request) ⇒ Array

CustomAutoマッチメイキング -

CustomAutoマッチメイキングを実行する場合は、基本的にはこのAPIを呼び出すことで完結します。
CustomAutoマッチメイキングのリクエストパラメータには、参加対象となるギャザリングの属性値の範囲を指定して行われます。
属性値は最大5個指定することができ、属性値毎に検索する最小値・最大値を指定できます。
すべての属性値が希望する範囲内に収まっているギャザリングを見つけた場合はそのギャザリングに参加します。

一定時間内にすべてのギャザリングの検索を終えることができなかった場合は、searchContext というパラメータを応答します。
この場合、searchContext を指定して このAPIを再度呼び出すことで、検索を再開することができます。
この際に指定する検索条件は以前の searchContext と同じ条件にするようにしてください。
条件が変更されたうえで、searchContext を利用した場合の動作は保証できません。

すべてのギャザリングを検索した結果、対象となるギャザリングが存在しなかった場合は、新しくギャザリングを作成し、そのギャザリングに参加します。

戻り値にはギャザリングに参加している人数が含まれますので、自分がギャザリングを作成したのかはそこで確認することができます。

マッチメイキング完了コールバックをが返るまで待つことでマッチメイキングの完了を待つことができます。
マッチメイキングの進捗を確認したい場合は #custom_auto_describe_joined_user を呼び出すことで、
ギャザリングに参加しているユーザIDが取得できるため、誰とマッチメイキングが行われているか途中経過を取得できます。

ユーザ操作などにより、マッチメイキングを中断する場合は #custom_auto_leave_gathering を呼び出すことで中断できます。
GS2-Matchmaking にはホストという明確な役割は存在しないため、ギャザリングを作成したユーザがマッチメイキングを中断したとしてもマッチメイキングは継続されます。

accessToken には Gs2::Auth::Client::login() でログインして取得したアクセストークンを指定してください。

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名

    • attribute1 => ギャザリング新規作成時の属性1

    • attribute2 => ギャザリング新規作成時の属性2

    • attribute3 => ギャザリング新規作成時の属性3

    • attribute4 => ギャザリング新規作成時の属性4

    • attribute5 => ギャザリング新規作成時の属性5

    • searchAttribute1Min => 検索対象ギャザリング属性1の下限

    • searchAttribute1Max => 検索対象ギャザリング属性1の上限

    • searchAttribute2Min => 検索対象ギャザリング属性2の下限

    • searchAttribute2Max => 検索対象ギャザリング属性2の上限

    • searchAttribute3Min => 検索対象ギャザリング属性3の下限

    • searchAttribute3Max => 検索対象ギャザリング属性3の上限

    • searchAttribute4Min => 検索対象ギャザリング属性4の下限

    • searchAttribute4Max => 検索対象ギャザリング属性4の上限

    • searchAttribute5Min => 検索対象ギャザリング属性5の下限

    • searchAttribute5Max => 検索対象ギャザリング属性5の上限

    • searchContext => 検索コンテキスト

    • accessToken => アクセストークン

Returns:

  • (Array)
    • done => 検索が完了したか

    • item

      • gatheringId => ギャザリングID

      • joinPlayer => 参加プレイヤー数

      • updateAt => 更新日時

    • searchContext => 検索コンテキスト



396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/gs2/matchmaking/Client.rb', line 396

def custom_auto_do_matchmaking(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  if not request.has_key?('accessToken'); raise ArgumentError.new(); end
  if not request['accessToken']; raise ArgumentError.new(); end
  body = {}
  if request.has_key?('attribute1'); body['attribute1'] = request['attribute1']; end
  if request.has_key?('attribute2'); body['attribute2'] = request['attribute2']; end
  if request.has_key?('attribute3'); body['attribute3'] = request['attribute3']; end
  if request.has_key?('attribute4'); body['attribute4'] = request['attribute4']; end
  if request.has_key?('attribute5'); body['attribute5'] = request['attribute5']; end
  if request.has_key?('searchAttribute1Min'); body['searchAttribute1Min'] = request['searchAttribute1Min']; end
  if request.has_key?('searchAttribute2Min'); body['searchAttribute2Min'] = request['searchAttribute2Min']; end
  if request.has_key?('searchAttribute3Min'); body['searchAttribute3Min'] = request['searchAttribute3Min']; end
  if request.has_key?('searchAttribute4Min'); body['searchAttribute4Min'] = request['searchAttribute4Min']; end
  if request.has_key?('searchAttribute5Min'); body['searchAttribute5Min'] = request['searchAttribute5Min']; end
  if request.has_key?('searchAttribute1Max'); body['searchAttribute1Max'] = request['searchAttribute1Max']; end
  if request.has_key?('searchAttribute2Max'); body['searchAttribute2Max'] = request['searchAttribute2Max']; end
  if request.has_key?('searchAttribute3Max'); body['searchAttribute3Max'] = request['searchAttribute3Max']; end
  if request.has_key?('searchAttribute4Max'); body['searchAttribute4Max'] = request['searchAttribute4Max']; end
  if request.has_key?('searchAttribute5Max'); body['searchAttribute5Max'] = request['searchAttribute5Max']; end
  if request.has_key?('searchContext'); body['searchContext'] = request['searchContext']; end
  query = {}
  header = {
    'X-GS2-ACCESS-TOKEN' => request['accessToken']
  }
  return post(
      'Gs2Matchmaking',
      'DoMatchmaking',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/' + request['matchmakingName'] + "/customauto",
      body,
      query,
      header);
end

#custom_auto_leave_gathering(request) ⇒ Object

CustomAutoマッチメイキング - ギャザリングからの離脱を実行

accessToken には Gs2::Auth::Client::login() でログインして取得したアクセストークンを指定してください。

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名

    • gatheringId => ギャザリングID

    • accessToken => アクセストークン



474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
# File 'lib/gs2/matchmaking/Client.rb', line 474

def custom_auto_leave_gathering(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  if not request.has_key?('gatheringId'); raise ArgumentError.new(); end
  if not request['gatheringId']; raise ArgumentError.new(); end
  if not request.has_key?('accessToken'); raise ArgumentError.new(); end
  if not request['accessToken']; raise ArgumentError.new(); end
  query = {}
  header = {
    'X-GS2-ACCESS-TOKEN' => request['accessToken']
  }
  return delete(
      'Gs2Matchmaking',
      'LeaveGathering',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/' + request['matchmakingName'] + "/customauto/" + request['gatheringId'] + "/player",
      query,
      header);
end

#delete_matchmaking(request) ⇒ Object

マッチメイキングを削除

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名



222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/gs2/matchmaking/Client.rb', line 222

def delete_matchmaking(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  query = {}
  return delete(
        'Gs2Matchmaking', 
        'DeleteMatchmaking', 
        @@ENDPOINT, 
        @@VARIATION,
        '/matchmaking/' + request['matchmakingName'],
        query);
end

#describe_matchmaking(pageToken = nil, limit = nil) ⇒ Array

マッチメイキングリストを取得

Parameters:

  • pageToken (String) (defaults to: nil)

    ページトークン

  • limit (Integer) (defaults to: nil)

    取得件数

Returns:

  • (Array)
    • items

      Array
      • matchmakingId => マッチメイキングID

      • ownerId => オーナーID

      • name => マッチメイキング名

      • description => 説明文

      • type => 種類

      • maxPlayer => 最大プレイヤー数

      • serviceClass => サービスクラス

      • callback => コールバックURL

      • createAt => 作成日時

      • updateAt => 更新日時

    • nextPageToken => 次ページトークン



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/gs2/matchmaking/Client.rb', line 58

def describe_matchmaking(pageToken = nil, limit = nil)
  query = {}
  if pageToken; query['pageToken'] = pageToken; end
  if limit; query['limit'] = limit; end
  return get(
        'Gs2Matchmaking', 
        'DescribeMatchmaking', 
        @@ENDPOINT, 
        @@VARIATION,
        '/matchmaking',
        query);
end

#describe_service_classArray

サービスクラスリストを取得

Returns:

  • (Array)

    サービスクラス



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/gs2/matchmaking/Client.rb', line 74

def describe_service_class()
  query = {}
  result = get(
      'Gs2Matchmaking',
      'DescribeServiceClass',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/serviceClass',
      query);
  return result['items'];
end

#get_matchmaking(request) ⇒ Array

マッチメイキングを取得

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名

Returns:

  • (Array)
    • item

      • matchmakingId => マッチメイキングID

      • ownerId => オーナーID

      • name => マッチメイキング名

      • description => 説明文

      • type => 種類

      • maxPlayer => 最大プレイヤー数

      • serviceClass => サービスクラス

      • callback => コールバックURL

      • createAt => 作成日時

      • updateAt => 更新日時



146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gs2/matchmaking/Client.rb', line 146

def get_matchmaking(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  query = {}
  return get(
      'Gs2Matchmaking',
      'GetMatchmaking',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/' + request['matchmakingName'],
      query);
end

#get_matchmaking_status(request) ⇒ Array

マッチメイキングの状態を取得

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名

Returns:

  • (Array)
    • status => 状態



166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/gs2/matchmaking/Client.rb', line 166

def get_matchmaking_status(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  query = {}
  return get(
      'Gs2Matchmaking',
      'GetMatchmakingStatus',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/' + request['matchmakingName'] + '/status',
      query);
end

#passcode_create_gathering(request) ⇒ Array

Passcodeマッチメイキング - ギャザリングを作成

Passcodeマッチメイキングの開始手段は2つに別れます。
ひとつ目は既存のギャザリングに参加すること。もう一つはこのAPIで実行できる、新しくギャザリングを作成する。という手段です。

ギャザリングを新しく作成するにあたって必要なパラメータなどはありません。
このAPIを呼び出すことでギャザリングが新しく作られ、ギャザリングには固有のパスコード(8ケタ数字)が割り当てられます。
割り当てられたパスコードは戻り値に含まれています。

パスコードの上位は乱数、下位はミリ秒単位のタイムスタンプで構成されています。
そのため、非常に短い間隔でリクエストを出した時に、乱数もあるため可能性は低くいですがパスコードが衝突する可能性があります。
その場合はパスコードを入力した時に同一パスコードを持つギャザリングのうちどのギャザリングに参加するかは不定です。

万全を期するには、ミリ秒単位でルームの作成が多数衝突する頻度でギャザリングを作成する必要がある場合は、
Anybody や CustomAuto といった方法のマッチメイキングも併用していただき、友達同士と遊びたい場合にのみ Passcode 方式を利用するよう誘導いただくのが得策です。

ギャザリング作成後は、マッチメイキング完了コールバックをが返るまで待つことでマッチメイキングの完了を待つことができます。
マッチメイキングの進捗を確認したい場合は #passcode_describe_joined_user を呼び出すことで、
ギャザリングに参加しているユーザIDが取得できるため、誰とマッチメイキングが行われているか途中経過を取得できます。

ユーザ操作などにより、マッチメイキングを中断する場合は #passcode_leave_gathering を呼び出すことで中断できます。
GS2-Matchmaking にはホストという明確な役割は存在しないため、ギャザリングを作成したユーザがマッチメイキングを中断したとしてもマッチメイキングは継続されます。

accessToken には Gs2::Auth::Client::login() でログインして取得したアクセストークンを指定してください。

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名

    • accessToken => アクセストークン

Returns:

  • (Array)
    • item

      • gatheringId => ギャザリングID

      • joinPlayer => 参加プレイヤー数

      • passcode => ギャザリング参加用パスコード

      • updateAt => 更新日時



530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
# File 'lib/gs2/matchmaking/Client.rb', line 530

def passcode_create_gathering(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  if not request.has_key?('accessToken'); raise ArgumentError.new(); end
  if not request['accessToken']; raise ArgumentError.new(); end
  body = {}
  query = {}
  header = {
    'X-GS2-ACCESS-TOKEN' => request['accessToken']
  }
  return post(
      'Gs2Matchmaking',
      'CreateGathering',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/' + request['matchmakingName'] + "/passcode",
      body,
      query,
      header);
end

#passcode_describe_joined_user(request) ⇒ Array

Passcodeマッチメイキング - ギャザリングに参加しているユーザID一覧取得を実行

accessToken には Gs2::Auth::Client::login() でログインして取得したアクセストークンを指定してください。

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名

    • gatheringId => ギャザリングID

    • accessToken => アクセストークン

Returns:

  • (Array)
    • items => 参加ユーザID一覧



614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
# File 'lib/gs2/matchmaking/Client.rb', line 614

def passcode_describe_joined_user(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  if not request.has_key?('gatheringId'); raise ArgumentError.new(); end
  if not request['gatheringId']; raise ArgumentError.new(); end
  if not request.has_key?('accessToken'); raise ArgumentError.new(); end
  if not request['accessToken']; raise ArgumentError.new(); end
  query = {}
  header = {
    'X-GS2-ACCESS-TOKEN' => request['accessToken']
  }
  return get(
      'Gs2Matchmaking',
      'DescribeJoinedUser',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/' + request['matchmakingName'] + "/passcode/" + request['gatheringId'] + "/player",
      query,
      header);
end

#passcode_join_gathering(request) ⇒ Array

Passcodeマッチメイキング - ギャザリングに参加

Passcodeマッチメイキングの開始手段は2つに別れます。
ひとつ目は新しくギャザリングを作成すること。もう一つはこのAPIで実行できる、既存のギャザリングに参加する。という手段です。

パスコードの交換方法は GS2 では提供しません。
ソーシャル連携などの手段は各ゲームで実装頂く必要があります。

何らかの手段で得たパスコードを指定してこのAPIを呼び出すことで、既存のギャザリングに参加することができます。

ギャザリング参加後は、マッチメイキング完了コールバックをが返るまで待つことでマッチメイキングの完了を待つことができます。
マッチメイキングの進捗を確認したい場合は #passcode_describe_joined_user を呼び出すことで、
ギャザリングに参加しているユーザIDが取得できるため、誰とマッチメイキングが行われているか途中経過を取得できます。

ユーザ操作などにより、マッチメイキングを中断する場合は #passcode_leave_gathering を呼び出すことで中断できます。

accessToken には Gs2::Auth::Client::login() でログインして取得したアクセストークンを指定してください。

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名

    • passcode => ギャザリング参加用パスコード

    • accessToken => アクセストークン

Returns:

  • (Array)
    • item

      • gatheringId => ギャザリングID

      • joinPlayer => 参加プレイヤー数

      • passcode => ギャザリング参加用パスコード

      • updateAt => 更新日時



580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
# File 'lib/gs2/matchmaking/Client.rb', line 580

def passcode_join_gathering(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  if not request.has_key?('passcode'); raise ArgumentError.new(); end
  if not request['passcode']; raise ArgumentError.new(); end
  if not request.has_key?('accessToken'); raise ArgumentError.new(); end
  if not request['accessToken']; raise ArgumentError.new(); end
  body = {}
  query = {}
  header = {
    'X-GS2-ACCESS-TOKEN' => request['accessToken']
  }
  return post(
      'Gs2Matchmaking',
      'JoinGathering',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/' + request['matchmakingName'] + "/passcode/join/" + request['passcode'],
      body,
      query,
      header);
end

#passcode_leave_gathering(request) ⇒ Object

Passcodeマッチメイキング - ギャザリングからの離脱を実行

accessToken には Gs2::Auth::Client::login() でログインして取得したアクセストークンを指定してください。

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名

    • gatheringId => ギャザリングID

    • accessToken => アクセストークン



644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
# File 'lib/gs2/matchmaking/Client.rb', line 644

def passcode_leave_gathering(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  if not request.has_key?('gatheringId'); raise ArgumentError.new(); end
  if not request['gatheringId']; raise ArgumentError.new(); end
  if not request.has_key?('accessToken'); raise ArgumentError.new(); end
  if not request['accessToken']; raise ArgumentError.new(); end
  query = {}
  header = {
    'X-GS2-ACCESS-TOKEN' => request['accessToken']
  }
  return delete(
      'Gs2Matchmaking',
      'LeaveGathering',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/' + request['matchmakingName'] + "/passcode/" + request['gatheringId'] + "/player",
      query,
      header);
end

#room_create_gathering(request) ⇒ Array

Roomマッチメイキング - ギャザリングを作成

Room 方式のマッチメイキングは以下のプロセスで成立します。

  1. #room_create_gathering でギャザリングを作成

  2. #room_describe_gathering でギャザリング一覧を取得

  3. 気に入ったルームが見つかったら #room_join_gathering でギャザリングに参加

このAPIでは1番目のプロセスのギャザリングの作成が行えます。

ギャザリングの作成リクエストには、128バイト以下と非常に小さいですが、ギャザリングのメタ情報を付加することができます。
ここにはホストが遊びたいと思っているゲームモードなどの情報を付与し、ギャザリング一覧での表示に利用できます。
129バイト以上のデータを利用したい場合はメタデータのURLを格納するなどして対処してください。

ギャザリング作成後、マッチメイキング完了コールバックをが返るまで待つことでマッチメイキングの完了を待つことができます。
マッチメイキングの進捗を確認したい場合は #room_describe_joined_user を呼び出すことで、
ギャザリングに参加しているユーザIDが取得できるため、誰とマッチメイキングが行われているか途中経過を取得できます。

ユーザ操作などにより、マッチメイキングを中断する場合は #room_leave_gathering を呼び出すことで中断できます。
GS2-Matchmaking にはホストという明確な役割は存在しないため、ギャザリングを作成したユーザがマッチメイキングを中断したとしてもマッチメイキングは継続されます。

accessToken には Gs2::Auth::Client::login() でログインして取得したアクセストークンを指定してください。

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名

    • meta => メタデータ(Optional)

    • accessToken => アクセストークン

Returns:

  • (Array)
    • item

      • gatheringId => ギャザリングID

      • joinPlayer => 参加プレイヤー数

      • meta => メタデータ

      • updateAt => 更新日時



699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
# File 'lib/gs2/matchmaking/Client.rb', line 699

def room_create_gathering(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  if not request.has_key?('accessToken'); raise ArgumentError.new(); end
  if not request['accessToken']; raise ArgumentError.new(); end
  body = {}
  if request.has_key?('meta'); body['meta'] = request['meta']; end
  query = {}
  header = {
    'X-GS2-ACCESS-TOKEN' => request['accessToken']
  }
  return post(
      'Gs2Matchmaking',
      'CreateGathering',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/' + request['matchmakingName'] + "/room",
      body,
      query,
      header);
end

#room_describe_gathering(request, pageToken = nil, limit = nil) ⇒ Array

Roomマッチメイキング - ギャザリング一覧を取得

Room 方式のマッチメイキングは以下のプロセスで成立します。

  1. #room_create_gathering でギャザリングを作成

  2. #room_describe_gathering でギャザリング一覧を取得

  3. 気に入ったルームが見つかったら #room_join_gathering でギャザリングに参加


このAPIでは2番目のプロセスのギャザリング一覧の取得が行えます。

ギャザリングの一覧をユーザに提供し、気に入ったギャザリングがあれば次のプロセスへ
見つからなければ、先頭から取り直すか戻り値に含まれる nextPageToken を利用して次のページを案内できます。

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名

    • accessToken => アクセストークン

  • pageToken (String) (defaults to: nil)

    ページトークン

  • limit (Integer) (defaults to: nil)

    取得件数

Returns:

  • (Array)
    • items

      Array
      • gatheringId => ギャザリングID

      • joinPlayer => 参加プレイヤー数

      • meta => メタデータ

      • updateAt => 更新日時

    • nextPageToken => 次ページトークン



809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
# File 'lib/gs2/matchmaking/Client.rb', line 809

def room_describe_gathering(request, pageToken = nil, limit = nil)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  if not request.has_key?('accessToken'); raise ArgumentError.new(); end
  if not request['accessToken']; raise ArgumentError.new(); end
  query = {}
  if pageToken; query['pageToken'] = pageToken; end
  if limit; query['limit'] = limit; end
  header = {
    'X-GS2-ACCESS-TOKEN' => request['accessToken']
  }
  return get(
      'Gs2Matchmaking',
      'DescribeGathering',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/' + request['matchmakingName'] + "/room/",
      query,
      header);
end

#room_describe_joined_user(request) ⇒ Array

Roomマッチメイキング - ギャザリングに参加しているユーザID一覧取得を実行

accessToken には Gs2::Auth::Client::login() でログインして取得したアクセストークンを指定してください。

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名

    • gatheringId => ギャザリングID

    • accessToken => アクセストークン

Returns:

  • (Array)
    • items => 参加ユーザID一覧



841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
# File 'lib/gs2/matchmaking/Client.rb', line 841

def room_describe_joined_user(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  if not request.has_key?('gatheringId'); raise ArgumentError.new(); end
  if not request['gatheringId']; raise ArgumentError.new(); end
  if not request.has_key?('accessToken'); raise ArgumentError.new(); end
  if not request['accessToken']; raise ArgumentError.new(); end
  query = {}
  header = {
    'X-GS2-ACCESS-TOKEN' => request['accessToken']
  }
  return get(
      'Gs2Matchmaking',
      'DescribeJoinedUser',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/' + request['matchmakingName'] + "/room/" + request['gatheringId'] + "/player",
      query,
      header);
end

#room_join_gathering(request) ⇒ Array

Roomマッチメイキング - ギャザリングに参加

Room 方式のマッチメイキングは以下のプロセスで成立します。

  1. #room_create_gathering でギャザリングを作成

  2. #room_describe_gathering でギャザリング一覧を取得

  3. 気に入ったルームが見つかったら #room_join_gathering でギャザリングに参加


このAPIでは3番目のプロセスのギャザリングへの参加が行えます。
ギャザリングの一覧取得からギャザリングへの参加がアトミックに行われるわけではないので、
このAPIを呼び出した段階では、ギャザリングが解散していたり、すでに満員になっている可能性があります。
そのような場合は、このAPIはエラー応答として、Gs2::Core::BadRequestException 例外をスローします。

ギャザリング参加後、マッチメイキング完了コールバックをが返るまで待つことでマッチメイキングの完了を待つことができます。
マッチメイキングの進捗を確認したい場合は #room_describe_joined_user を呼び出すことで、
ギャザリングに参加しているユーザIDが取得できるため、誰とマッチメイキングが行われているか途中経過を取得できます。

ユーザ操作などにより、マッチメイキングを中断する場合は #room_leave_gathering を呼び出すことで中断できます。

ゲーム利用者にとって、最もニーズに合ったギャザリングに参加できるのが Room 方式のマッチメイキングの特徴ではありますが、
プレイヤー数が多いゲームにおいては、このアトミックに操作が行われないという点がUXにマイナスの影響をおよぼす可能性があります。
どうしても Room 方式でなければならない理由がないのであれば、他のマッチメイキング方式を採用することをおすすめします。

accessToken には Gs2::Auth::Client::login() でログインして取得したアクセストークンを指定してください。

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名

    • gatheringId => ギャザリングID

    • accessToken => アクセストークン

Returns:

  • (Array)
    • item

      • gatheringId => ギャザリングID

      • joinPlayer => 参加プレイヤー数

      • meta => メタデータ

      • updateAt => 更新日時



758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
# File 'lib/gs2/matchmaking/Client.rb', line 758

def room_join_gathering(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  if not request.has_key?('gatheringId'); raise ArgumentError.new(); end
  if not request['gatheringId']; raise ArgumentError.new(); end
  if not request.has_key?('accessToken'); raise ArgumentError.new(); end
  if not request['accessToken']; raise ArgumentError.new(); end
  body = {}
  query = {}
  header = {
    'X-GS2-ACCESS-TOKEN' => request['accessToken']
  }
  return post(
      'Gs2Matchmaking',
      'JoinGathering',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/' + request['matchmakingName'] + "/room/" + request['gatheringId'],
      body,
      query,
      header);
end

#room_leave_gathering(request) ⇒ Object

Roomマッチメイキング - ギャザリングからの離脱を実行

accessToken には Gs2::Auth::Client::login() でログインして取得したアクセストークンを指定してください。

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名

    • gatheringId => ギャザリングID

    • accessToken => アクセストークン



871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
# File 'lib/gs2/matchmaking/Client.rb', line 871

def room_leave_gathering(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  if not request.has_key?('gatheringId'); raise ArgumentError.new(); end
  if not request['gatheringId']; raise ArgumentError.new(); end
  if not request.has_key?('accessToken'); raise ArgumentError.new(); end
  if not request['accessToken']; raise ArgumentError.new(); end
  query = {}
  header = {
    'X-GS2-ACCESS-TOKEN' => request['accessToken']
  }
  return delete(
      'Gs2Matchmaking',
      'LeaveGathering',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/' + request['matchmakingName'] + "/room/" + request['gatheringId'] + "/player",
      query,
      header);
end

#update_matchmaking(request) ⇒ Array

マッチメイキングを更新

Parameters:

  • request (Array)
    • matchmakingName => マッチメイキング名

    • description => 説明文

    • serviceClass => サービスクラス

    • callback => コールバックURL

Returns:

  • (Array)
    • item

      • matchmakingId => マッチメイキングID

      • ownerId => オーナーID

      • name => マッチメイキング名

      • description => 説明文

      • type => 種類

      • maxPlayer => 最大プレイヤー数

      • serviceClass => サービスクラス

      • callback => コールバックURL

      • createAt => 作成日時

      • updateAt => 更新日時



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/gs2/matchmaking/Client.rb', line 199

def update_matchmaking(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('matchmakingName'); raise ArgumentError.new(); end
  if not request['matchmakingName']; raise ArgumentError.new(); end
  body = {}
  if request.has_key?('description'); body['description'] = request['description']; end
  if request.has_key?('serviceClass'); body['serviceClass'] = request['serviceClass']; end
  if request.has_key?('callback'); body['callback'] = request['callback']; end
  query = {}
  return put(
      'Gs2Matchmaking',
      'UpdateMatchmaking',
      @@ENDPOINT,
      @@VARIATION,
      '/matchmaking/' + request['matchmakingName'],
      body,
      query);
end