Introduction to external dedicated game server management integration with Session Override
Introduction
Using the AccelByte Gaming Services (AGS) Session service allows you to integrate your game with your preferred external or third-party dedicated game server management tool. The AGS Session service will request a dedicated server when the minimum number of players (in the session template config) have already joined the session.
AGS allows you to override the default session behavior using the Extend Override. Instead of requesting a dedicated game server (DS) to AMS, the session service will request a DS from the external provider you configure in the Session Override app.
This article walks you through how to:
- Modify the Extend Override app template for session function to integrate with external dedicated game server Management
- Configure custom dedicated game server source inside the session template configuration in the AGS Admin Portal.
- Create a gRPC server to override session service functionality when requesting a dedicated game server.
- The steps in this article shows how to customize the AGS Session service to integrate the Google Cloud Platform as an external dedicated server provider. Documentation for AWS Gamelift integration will be added soon.
- Check out AccelByte Multiplayer Server (AMS), AGS's dedicated server management tool. AMS is a dynamic dedicated game server manager that enables you to serve dedicated game servers as close to your players as possible.
Prerequisites
- An environment with AccelByte Gaming Services version 3.76 and later.
- A Google Cloud Platform (GCP) account.
- An understanding of the following AGS components:
Contract functions
The following are the functions in the contract:
service SessionDsm{
rpc CreateGameSession(RequestCreateGameSession) returns (ResponseCreateGameSession);
rpc TerminateGameSession(RequestTerminateGameSession) returns (ResponseTerminateGameSession);
}
CreateGameSession
CreateGameSession
is called when the client or matchmaking creates a game session that requests a dedicated game server from the DS management provider.
- Go
- C#
- Python
In the app template, the following function can be found in pkg/client/gcpvm/client.go
.
func (s *SessionDSM) CreateGameSession(ctx context.Context, req *sessiondsm.RequestCreateGameSession) (*sessiondsm.ResponseCreateGameSession, error) {
...
}
public override Task<ResponseCreateGameSession> CreateGameSession(RequestCreateGameSession request, ServerCallContext context)
{
...
}
async def CreateGameSession(
self, request: RequestCreateGameSession, context: ServicerContext
) -> ResponseCreateGameSession:
...
TerminateGameSession
TerminateGameSession
is called when the game session is deleted.
- Go
- C#
- Python
In the app template, the following function can be found in pkg/client/gcpvm/client.go
.
func (s *SessionDSM) TerminateGameSession(ctx context.Context, req *sessiondsm.RequestTerminateGameSession) (*sessiondsm.ResponseTerminateGameSession, error) {
...
}
public override Task<ResponseTerminateGameSession> TerminateGameSession(RequestTerminateGameSession request, ServerCallContext context)
{
...
}
async def TerminateGameSession(
self, request: RequestTerminateGameSession, context: ServicerContext
) -> ResponseTerminateGameSession:
...
Dedicated game server logic
It is essential to keep the game session lifecycle in sync with the dedicated game server (DS) status. This prevents the game session from hanging (or still being active) when the dedicated game server has already been removed or shut down. We recommend that the DS delete the associated game session when it shuts down by calling the delete game session endpoint. See also the SDK function.
Set up, run, and test the Extend App
For sample purposes, a Google Cloud (GCP) virtual machine is used in this configuration as the external place to deploy the dedicated game server.
Clone the app template
- Go
- C#
- Python
git clone https://github.com/AccelByte/session-dsm-grpc-plugin-go.git
git clone https://github.com/AccelByte/session-dsm-grpc-plugin-csharp.git
git clone https://github.com/AccelByte/session-dsm-grpc-plugin-python.git
Set up the Google Cloud Platform
Log in to the Google Cloud Platform (GCP)
gcloud auth login
Create your
service-key-account
.gcloud iam service-accounts keys create test.json --iam-account=xxxx@xxxx.iam.gserviceaccount.com
Allow the firewall IP address and port in the Virtual Private Cloud (VPC) for traffic in GCP.
In GCP, create a repository for the sample game DS docker image (artifact). Add the tag and push the DS to the docker repository. Example command:
docker tag sampleds asia-southeast1-docker.pkg.dev/xxxx/xxxx/sampleds
docker push asia-southeast1-docker.pkg.dev/xxxx/xxxx/sampleds
- To avoid issues during the integration, we recommend naming the instance in GCP in lowercase and not exceeding more than 62 characters.
- See Google's documentation on configuring authentication to Artifact Registry for Docker.
Configure the app and session template
Set up the GCP credentials. The credentials should be saved in a JSON file and used to call GCP. Iin the code snippet, it is named
service-account-key.json
.importantRoles that should be allowed are Compute Admin, Artifact registry reader, artifact registry writer, and service account user.
Set up the environment variable in the
.env
file. You can find the.env.template
in the app template repository.
- Go
- C#
- Python
AB_BASE_URL=https://prod.gamingservices.accelbyte.io # Base URL of AGS prod environment
AB_CLIENT_ID='xxxxxxxxxx' # Client ID from the Prerequisites section
AB_CLIENT_SECRET='xxxxxxxxxx' # Client Secret from the Prerequisites section
PLUGIN_GRPC_SERVER_AUTH_ENABLED=false # Enable or disable access token and permission verification
DS_PROVIDER='DEMO' # Select DS implementation: DEMO or GCP
// GCP Config
GCP_SERVICE_ACCOUNT_FILE='./account.json' # GCP service account file in JSON format
GCP_PROJECT_ID=xxxxx-xxxx # GCP Project ID
GCP_NETWORK=public # GCP Network type
GCP_MACHINE_TYPE=e2-micro # GCP instance type
GCP_REPOSITORY=asia-southeast1-docker.pkg.dev/xxxx/gcpvm # GCP Repository
GCP_RETRY=3 # GCP Retry to get instance
GCP_WAIT_GET_IP=1 # GCP wait time to get the instance IP in seconds
GCP_IMAGE_OPEN_PORT=8080 # Dedicated server open port
AB_BASE_URL=https://prod.gamingservices.accelbyte.io # Base URL of AGS prod environment
AB_CLIENT_ID='xxxxxxxxxx' # Client ID from the Prerequisites section
AB_CLIENT_SECRET='xxxxxxxxxx' # Client Secret from the Prerequisites section
PLUGIN_GRPC_SERVER_AUTH_ENABLED=false # Enable or disable access token and permission verification
DS_PROVIDER='DEMO' # Select DS implementation: DEMO or GCP
// GCP Config
GCP_SERVICE_ACCOUNT_FILE='./account.json' # GCP service account file in JSON format
GCP_PROJECT_ID=xxxxx-xxxx # GCP Project ID
GCP_NETWORK=public # GCP Network type
GCP_MACHINE_TYPE=e2-micro # GCP instance type
GCP_REPOSITORY=asia-southeast1-docker.pkg.dev/xxxx/gcpvm # GCP Repository
GCP_RETRY=3 # GCP Retry to get instance
GCP_WAIT_GET_IP=1 # GCP wait time to get the instance IP in seconds
GCP_IMAGE_OPEN_PORT=8080 # Dedicated server open port
AB_BASE_URL=https://prod.gamingservices.accelbyte.io # Base URL of AGS prod environment
AB_CLIENT_ID='xxxxxxxxxx' # Client ID from the Prerequisites section
AB_CLIENT_SECRET='xxxxxxxxxx' # Client Secret from the Prerequisites section
PLUGIN_GRPC_SERVER_AUTH_ENABLED=false # Enable or disable access token and permission verification
DS_PROVIDER='DEMO' # Select DS implementation: DEMO or GCP
// GCP Config
GCP_SERVICE_ACCOUNT_FILE='./account.json' # GCP service account file in JSON format
GCP_PROJECT_ID=xxxxx-xxxx # GCP Project ID
GCP_NETWORK=public # GCP Network type
GCP_MACHINE_TYPE=e2-micro # GCP instance type
GCP_REPOSITORY=asia-southeast1-docker.pkg.dev/xxxx/gcpvm # GCP Repository
GCP_RETRY=3 # GCP Retry to get instance
GCP_WAIT_GET_IP=1 # GCP wait time to get the instance IP in seconds
GCP_IMAGE_OPEN_PORT=8080 # Dedicated server open port
Run your app (gRPC) server locally or deploy it to AGS Extend (AccelByte hosted).
Run your gRPC server locally. Follow the Test with AGS steps in the Get started with session customization article.
Deploy your app to AGS Extend. Follow the Deploy in AGS steps in the Get started with session customization article.
Set up the session template configuration in your namespace and set the Server configuration to Custom. If you run your app locally or deploy it to your own server or cloud, fill in the Custom URL with your gRPC app public URL. If you deploy the App to AGS Extend, select the AccelByte Hosted” option and choose your Session Override App.
Test the Session Override app by creating a game session using the session template that you configured using Custom Server. When the minimum number of players join the session, it will request and spawn a dedicated game server in the GCP.