Check the Client SDK Documentation for more details on each of the SDK functions and how to run the SDK locally.
Area | Action | Implemented |
---|---|---|
Lifecycle | Ready | ✔️ |
Lifecycle | Health | ✔️ |
Lifecycle | Reserve | ✔️ |
Lifecycle | Allocate | ✔️ |
Lifecycle | Shutdown | ✔️ |
Configuration | GameServer | ✔️ |
Configuration | WatchGameServer | ✔️ |
Metadata | SetAnnotation | ✔️ |
Metadata | SetLabel | ✔️ |
Counters | GetCounterCount | ❌ |
Counters | SetCounterCount | ❌ |
Counters | IncrementCounter | ❌ |
Counters | DecrementCounter | ❌ |
Counters | SetCounterCapacity | ❌ |
Counters | GetCounterCapacity | ❌ |
Lists | AppendListValue | ❌ |
Lists | DeleteListValue | ❌ |
Lists | SetListCapacity | ❌ |
Lists | GetListCapacity | ❌ |
Lists | ListContains | ❌ |
Lists | GetListLength | ❌ |
Lists | GetListValues | ❌ |
Download the source from the Releases Page or directly from GitHub.
CMake is used to build SDK for all supported platforms (Linux/Window/macOS).
Code Blind SDK only depends on the gRPC library.
If CMake cannot find gRPC with find_package(), it downloads and builds gRPC. There are some extra prerequisites for OpenSSL on Windows, see documentation:
Note that OpenSSL is not used in Code Blind SDK, but it is required to have a successful build of gRPC.
Following options are available:
(Windows only):
mkdir -p .build
cd .build
cmake .. -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=./install
cmake --build . --target install
Building with Visual Studio:
md .build
cd .build
cmake .. -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX=./install
cmake --build . --config Release --target install
Building with NMake
md .build
cd .build
cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./install
cmake --build . --target install
CMAKE_INSTALL_PREFIX may be skipped if it is OK to install Code Blind SDK to a default location (usually /usr/local or c:/Program Files/Code Blind).
CMake option -Wno-dev
is specified to suppress CMP0048 deprecation warning for gRPC build.
If AGONES_ZLIB_STATIC is set to OFF, ensure that you have installed zlib. For Windows, it’s enough to copy zlib.dll near to gameserver executable. For Linux/Mac usually no actions are needed.
In CMake-based projects it’s enough to specify a folder where SDK is installed with CMAKE_PREFIX_PATH
and use find_package(agones CONFIG REQUIRED)
command. For example:
cpp-simple.
It may be useful to disable some protobuf warnings in your project.
The C++ SDK is specifically designed to be as simple as possible, and deliberately doesn’t include any kind of singleton management, or threading/asynchronous processing to allow developers to manage these aspects as they deem appropriate for their system.
We may consider these types of features in the future, depending on demand.
To begin working with the SDK, create an instance of it:
agones::SDK *sdk = new agones::SDK();
To connect to the SDK server, either local or when running on Code Blind, run the sdk->Connect()
method.
This will block for up to 30 seconds if the SDK server has not yet started and the connection cannot be made,
and will return false
if there was an issue connecting.
bool ok = sdk->Connect();
To send a health check call sdk->Health()
. This is a synchronous request that will
return false
if it has failed in any way. Read GameServer Health Checking for more
details on the game server health checking strategy.
bool ok = sdk->Health();
To mark the game server as ready to receive player connections, call sdk->Ready()
.
This will return a grpc::Status object, from which we can call status.ok()
to determine
if the function completed successfully.
For more information you can also look at the gRPC Status reference.
grpc::Status status = sdk->Ready();
if (!status.ok()) { ... }
To mark the game server as allocated, call sdk->Allocate()
.
This will return a grpc::Status object, from which we can call status.ok()
to determine
if the function completed successfully.
For more information you can also look at the gRPC Status reference.
grpc::Status status = sdk->Allocate();
if (!status.ok()) { ... }
To mark the game server as reserved, call
sdk->Reserve(seconds)
. This will return a grpc::Status object, from which we can call status.ok()
to determine
if the function completed successfully.
For more information you can also look at the gRPC Status reference.
grpc::Status status = sdk->Reserve(std::chrono::seconds(N));
if (!status.ok()) { ... }
To mark that the game session is completed and the game server should be shut down call sdk->Shutdown()
.
This will return a grpc::Status object, from which we can call status.ok()
to determine
if the function completed successfully.
For more information you can also look at the gRPC Status reference.
grpc::Status status = sdk->Shutdown();
if (!status.ok()) { ... }
To set a Label on the backing GameServer
call
sdk->SetLabel(key, value)
.
This will return a grpc::Status object, from which we can call status.ok()
to determine
if the function completed successfully.
For more information you can also look at the gRPC Status reference.
grpc::Status status = sdk->SetLabel("test-label", "test-value");
if (!status.ok()) { ... }
To set an Annotation on the backing GameServer
call
sdk->SetAnnotation(key, value)
.
This will return a grpc::Status object, from which we can call status.ok()
to determine
if the function completed successfully.
For more information you can also look at the gRPC Status reference.
status = sdk->SetAnnotation("test-annotation", "test value");
if (!status.ok()) { ... }
To get the details on the backing GameServer
call sdk->GameServer(&gameserver)
,
passing in a agones::dev::sdk::GameServer*
to push the results of the GameServer
configuration into.
This function will return a grpc::Status object, from which we can call status.ok()
to determine
if the function completed successfully.
agones::dev::sdk::GameServer gameserver;
grpc::Status status = sdk->GameServer(&gameserver);
if (!status.ok()) {...}
To get updates on the backing GameServer
as they happen,
call sdk->WatchGameServer([](const agones::dev::sdk::GameServer& gameserver){...})
.
This will call the passed in std::function
synchronously (this is a blocking function, so you may want to run it in its own thread) whenever the backing GameServer
is updated.
sdk->WatchGameServer([](const agones::dev::sdk::GameServer& gameserver){
std::cout << "GameServer Update:\n" //
<< "\tname: " << gameserver.object_meta().name() << "\n" //
<< "\tstate: " << gameserver.status().state() << "\n"
<< std::flush;
});
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.