NAV
Unity Unreal Engine 4

GS2-Gateway

GS2-SDK for Game Engine のリファレンス

ゲームエンジン向けSDKモデル

EzWebSocketSession

説明
connectionId string コネクションID
namespaceName string ネームスペース名
userId string ユーザーID

メソッド

setUserId

setUserId

ProfilePtr = std::make_shared<gs2::ez::Profile>(
    TCHAR_TO_ANSI(*ClientId),
    TCHAR_TO_ANSI(*ClientSecret),
    gs2::ez::Gs2BasicReopener()
);

ClientPtr = std::make_shared<gs2::ez::Client>(
    *ProfilePtr
);

ProfilePtr->initialize(
    [this](gs2::ez::Profile::AsyncInitializeResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "profile.initialize failed.");
        }
        else
        {
            AccountCreate();
        }
    }
);

// Up to this line is the initialization process.

ClientPtr->gateway.setUserId(
    [](gs2::ez::account::AsyncEzSetUserIdResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "gateway.setUserId failed.");
        }
        else
        {
            Item = r.getResult()->getItem();
        }
    },
    ProfilePtr->getGs2Session(),
    TCHAR_TO_ANSI("namespace1"), // namespaceName
    null // allowConcurrentAccess
);
using Gs2.Core.AsyncResult;
using Gs2.Gs2Account.Unity.Result;
using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);

{
    AsyncResult<object> asyncResult = null;

    var current = profile.Initialize(
        r => { asyncResult = r; }
    );

    yield return current;

    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }
}

// Up to this line is the initialization process.

var gs2 = new Gs2.Unity.Client(profile);

{
    AsyncResult<EzSetUserIdResult> asyncResult = null;
    var current = gs2.Gateway.SetUserId(
        callback: r => { asyncResult = r; },
        session: session,
        namespaceName: "namespace1",
        allowConcurrentAccess: null
    );

    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }

    var result = asyncResult.Result;
    var item = result.Item;
}

サーバからプッシュ通知を受けるためのユーザーIDを設定

Request

必須 デフォルト 値の制限 説明
namespaceName string ~ 128文字 ネームスペース名
accessToken string ~ 128文字 ユーザーID
allowConcurrentAccess bool true 同時に異なるクライアントからの接続を許容するか

Result

説明
item WebSocketSession 更新したWebsocketセッション