class Gs2::Realtime::Client

GS2-Realtime クライアント

@author Game Server Services, Inc.

Public Class Methods

ENDPOINT(v = nil) click to toggle source

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

# File lib/gs2/realtime/Client.rb, line 22
def self.ENDPOINT(v = nil)
  if v
    @@ENDPOINT = v
  else
    return @@ENDPOINT
  end
end
new(region, gs2_client_id, gs2_client_secret) click to toggle source

コンストラクタ

@param region [String] リージョン名 @param gs2_client_id [String] GSIクライアントID @param gs2_client_secret [String] GSIクライアントシークレット

Calls superclass method
# File lib/gs2/realtime/Client.rb, line 17
def initialize(region, gs2_client_id, gs2_client_secret)
  super(region, gs2_client_id, gs2_client_secret)
end

Public Instance Methods

create_gathering(request) click to toggle source

ギャザリングを作成

ギャザリングを作成すると、ゲームサーバが起動します。
ゲームサーバはWebSocketで接続することができ、同じゲームサーバに接続しているユーザ間でメッセージをやり取りすることができます。
ゲームサーバとの通信プロトコルの説明については別途ドキュメントを確認してください。

userIds にユーザIDを指定することで、ギャザリングに参加できるユーザのIDを制限することができます。
ギャザリング作成時に参加するユーザが確定している場合は指定してください。
省略すると、暗号鍵を知っていれば誰でも参加することができます。

@param request [Array]

* gatheringPoolName => ギャザリングプール名
* name => ギャザリング名
* userIds => 参加ユーザIDリスト

@return [Array]

* item
  * gatheringId => ギャザリングID
  * ownerId => オーナーID
  * name => ギャザリング名
  * hostId => ホストID
  * ipAddress => IPアドレス
  * port => 待ち受けポート
  * secret => 暗号鍵
  * userIds => 参加ユーザIDリスト
  * createAt => 作成日時
# File lib/gs2/realtime/Client.rb, line 213
def create_gathering(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('gatheringPoolName'); raise ArgumentError.new(); end
  if not request['gatheringPoolName']; raise ArgumentError.new(); end
  body = {}
  if request.has_key?('name'); body['name'] = request['name']; end
  if request.has_key?('userIds')
    body['userIds'] = request['userIds']
    if body['userIds'].is_a?(Array); body['userIds'] = body['userIds'].join(','); end
  end
  query = {}
  return post(
        'Gs2Realtime', 
        'CreateGathering', 
        @@ENDPOINT, 
        '/gatheringPool/' + request['gatheringPoolName'] + '/gathering',
        body,
        query);
end
create_gathering_pool(request) click to toggle source

ギャザリングプールを作成

GS2-Realtime を利用するには、まずギャザリングプールを作成する必要があります。
ギャザリングプールには複数のギャザリングを紐付けることができます。

@param request [Array]

* name => マッチメイキング名
* description => 説明文

@return [Array]

* item
  * gatheringPoolId => ギャザリングプールID
  * ownerId => オーナーID
  * name => ギャザリングプール名
  * description => 説明文
  * createAt => 作成日時
# File lib/gs2/realtime/Client.rb, line 70
def create_gathering_pool(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
  query = {}
  return post(
        'Gs2Realtime', 
        'CreateGatheringPool', 
        @@ENDPOINT, 
        '/gatheringPool',
        body,
        query);
end
delete_gathering(request) click to toggle source

ギャザリングを削除

@param request [Array]

* gatheringPoolName => ギャザリングプール名
* gatheringName => ギャザリング名
# File lib/gs2/realtime/Client.rb, line 269
def delete_gathering(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('gatheringPoolName'); raise ArgumentError.new(); end
  if not request['gatheringPoolName']; raise ArgumentError.new(); end
  if not request.has_key?('gatheringName'); raise ArgumentError.new(); end
  if not request['gatheringName']; raise ArgumentError.new(); end
  query = {}
  return delete(
        'Gs2Realtime', 
        'DeleteGathering', 
        @@ENDPOINT, 
        '/gatheringPool/' + request['gatheringPoolName'] + '/gathering/' + request['gatheringName'],
        query);
end
delete_gathering_pool(request) click to toggle source

ギャザリングプールを削除

@param request [Array]

* gatheringPoolName => ギャザリングプール名
# File lib/gs2/realtime/Client.rb, line 141
def delete_gathering_pool(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('gatheringPoolName'); raise ArgumentError.new(); end
  if not request['gatheringPoolName']; raise ArgumentError.new(); end
  query = {}
  return delete(
        'Gs2Realtime', 
        'DeleteGatheringPool', 
        @@ENDPOINT, 
        '/gatheringPool/' + request['gatheringPoolName'],
        query);
end
describe_gathering(request, pageToken = nil, limit = nil) click to toggle source

ギャザリングリストを取得

@param request [Array]

* gatheringPoolName => ギャザリングプール名

@param pageToken [String] ページトークン @param limit [Integer] 取得件数 @return [Array]

* items
  [Array]
    * gatheringId => ギャザリングID
    * ownerId => オーナーID
    * name => ギャザリング名
    * hostId => ホストID
    * ipAddress => IPアドレス
    * port => 待ち受けポート
    * secret => 暗号鍵
    * userIds => 参加ユーザIDリスト
    * createAt => 作成日時
* nextPageToken => 次ページトークン
# File lib/gs2/realtime/Client.rb, line 173
def describe_gathering(request, pageToken = nil, limit = nil)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('gatheringPoolName'); raise ArgumentError.new(); end
  if not request['gatheringPoolName']; raise ArgumentError.new(); end
  query = {}
  if pageToken; query['pageToken'] = pageToken; end
  if limit; query['limit'] = limit; end
  return get(
        'Gs2Realtime', 
        'DescribeGathering', 
        @@ENDPOINT, 
        '/gatheringPool/' + request['gatheringPoolName'] + '/gathering',
        query);
end
describe_gathering_pool(pageToken = nil, limit = nil) click to toggle source

ギャザリングプールリストを取得

@param pageToken [String] ページトークン @param limit [Integer] 取得件数 @return [Array]

* items
  [Array]
    * gatheringPoolId => ギャザリングプールID
    * ownerId => オーナーID
    * name => ギャザリングプール名
    * description => 説明文
    * createAt => 作成日時
* nextPageToken => 次ページトークン
# File lib/gs2/realtime/Client.rb, line 43
def describe_gathering_pool(pageToken = nil, limit = nil)
  query = {}
  if pageToken; query['pageToken'] = pageToken; end
  if limit; query['limit'] = limit; end
  return get(
        'Gs2Realtime', 
        'DescribeGatheringPool', 
        @@ENDPOINT, 
        '/gatheringPool',
        query);
end
get_gathering(request) click to toggle source

ギャザリングを取得

@param request [Array]

* gatheringPoolName => ギャザリングプール名
* gatheringName => ギャザリング名

@return [Array]

* item
  * gatheringId => ギャザリングID
  * ownerId => オーナーID
  * name => ギャザリング名
  * hostId => ホストID
  * ipAddress => IPアドレス
  * port => 待ち受けポート
  * secret => 暗号鍵
  * userIds => 参加ユーザIDリスト
  * createAt => 作成日時
# File lib/gs2/realtime/Client.rb, line 249
def get_gathering(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('gatheringPoolName'); raise ArgumentError.new(); end
  if not request['gatheringPoolName']; raise ArgumentError.new(); end
  if not request.has_key?('gatheringName'); raise ArgumentError.new(); end
  if not request['gatheringName']; raise ArgumentError.new(); end
  query = {}
  return get(
      'Gs2Realtime',
      'GetGathering',
      @@ENDPOINT,
      '/gatheringPool/' + request['gatheringPoolName'] + '/gathering/' + request['gatheringName'],
      query);
end
get_gathering_pool(request) click to toggle source

ギャザリングプールを取得

@param request [Array]

* gatheringPoolName => ギャザリングプール名

@return [Array]

* item
  * gatheringPoolId => ギャザリングプールID
  * ownerId => オーナーID
  * name => ギャザリングプール名
  * description => 説明文
  * createAt => 作成日時
# File lib/gs2/realtime/Client.rb, line 96
def get_gathering_pool(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('gatheringPoolName'); raise ArgumentError.new(); end
  if not request['gatheringPoolName']; raise ArgumentError.new(); end
  query = {}
  return get(
      'Gs2Realtime',
      'GetGatheringPool',
      @@ENDPOINT,
      '/gatheringPool/' + request['gatheringPoolName'],
      query);
end
update_gathering_pool(request) click to toggle source

ギャザリングプールを更新

@param request [Array]

* gatheringPoolName => ギャザリングプール名
* description => 説明文

@return [Array]

* item
  * gatheringPoolId => ギャザリングプールID
  * ownerId => オーナーID
  * name => ギャザリングプール名
  * description => 説明文
  * createAt => 作成日時
# File lib/gs2/realtime/Client.rb, line 121
def update_gathering_pool(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('gatheringPoolName'); raise ArgumentError.new(); end
  if not request['gatheringPoolName']; raise ArgumentError.new(); end
  body = {}
  if request.has_key?('description'); body['description'] = request['description']; end
  query = {}
  return put(
      'Gs2Realtime',
      'UpdateGatheringPool',
      @@ENDPOINT,
      '/gatheringPool/' + request['gatheringPoolName'],
      body,
      query);
end