API Reference of GS2-Realtime SDK for Game Engine
Model
EzRoom
Room
A game server for communication processing of real-time matches. IP address, port, and encryption key will be assigned a short time after creation.
Type | Require | Default | Limitation | Description | |
---|---|---|---|---|---|
name | string | ✓ | ~ 128 chars | Room Name | |
ipAddress | string | ~ 128 chars | IP address | ||
port | int | ~ 65535 | Standby port | ||
encryptionKey | string | ~ 256 chars | Encryption key |
Methods
now
Get current time
Request
Type | Require | Default | Limitation | Description |
---|
Result
Type | Description | |
---|---|---|
timestamp | long | Current time |
Implementation Example
var domain = gs2.Realtime;
var result = await domain.NowAsync(
);
var timestamp = result.Timestamp;
var domain = gs2.Realtime;
var future = domain.NowFuture(
);
yield return future;
if (future.Error != null)
{
onError.Invoke(future.Error, null);
yield break;
}
var timestamp = future.Result.Timestamp;
const auto Domain = Gs2->Realtime;
const auto Future = Domain->Now(
);
Future->StartSynchronousTask();
if (Future->GetTask().IsError())
{
return false;
}
const auto Timestamp = Result->Timestamp;
getRoom
Get room information
Request
Type | Require | Default | Limitation | Description | |
---|---|---|---|---|---|
namespaceName | string | ✓ | ~ 32 chars | Namespace name | |
roomName | string | ✓ | ~ 128 chars | Room Name |
Result
Type | Description | |
---|---|---|
item | EzRoom | Room |
Implementation Example
var domain = gs2.Realtime.Namespace(
namespaceName: "namespace-0001"
).Room(
roomName: "room-0001"
);
var item = await domain.ModelAsync();
var domain = gs2.Realtime.Namespace(
namespaceName: "namespace-0001"
).Room(
roomName: "room-0001"
);
var future = domain.Model();
yield return future;
var item = future.Result;
const auto Domain = Gs2->Realtime->Namespace(
"namespace-0001" // namespaceName
)->Room(
"room-0001" // roomName
);
const auto Future = Domain.Model();
Future->StartSynchronousTask();
if (Future->GetTask().IsError())
{
return false;
}
Value change event handling
var domain = gs2.Realtime.Namespace(
namespaceName: "namespace-0001"
).Room(
roomName: "room-0001"
);
// Start event handling
var callbackId = domain.Subscribe(
value => {
// Called when the value changes
// The "value" is passed the value after the change.
}
);
// Stop event handling
domain.Unsubscribe(callbackId);
var domain = gs2.Realtime.Namespace(
namespaceName: "namespace-0001"
).Room(
roomName: "room-0001"
);
var future = domain.Model();
yield return future;
var item = future.Result;
const auto Domain = Gs2->Realtime->Namespace(
"namespace-0001" // namespaceName
)->Room(
"room-0001" // roomName
);
// Start event handling
const auto CallbackId = Domain->Subscribe(
[](TSharedPtr<Gs2::Realtime::Model::FRoom> value) {
// Called when the value changes
// The "value" is passed the value after the change.
}
);
// Stop event handling
Domain->Unsubscribe(CallbackId);
Warning
This event is called when the value in the local cache that the SDK has is changed.
The local cache will only be changed by executing the SDK’s API, or by executing a stamp sheet via GS2-Distributor with GS2-Gateway notification enabled, or by executing a GS2-JobQueue with GS2-Gateway notification enabled. GS2-Gateway notification enabled.
Therefore, callbacks will not be invoked if the value is changed in any other way.
Event Handler
OnCreateNotification
Notification used when room creation is complete
Name | Type | Description |
---|---|---|
namespaceName | string | Namespace name |
roomName | string | Room Name |
Implementation Example
gs2.Realtime.OnCreateNotification += notification =>
{
var namespaceName = notification.NamespaceName;
var roomName = notification.RoomName;
};
gs2.Realtime.OnCreateNotification += notification =>
{
var namespaceName = notification.NamespaceName;
var roomName = notification.RoomName;
};
Gs2->Realtime->OnCreateNotification().AddLambda([](const auto Notification)
{
const auto NamespaceName = Notification->NamespaceNameValue;
const auto RoomName = Notification->RoomNameValue;
});