Skip to content
Blog

Easier Matchmaking With AccelByte’s Golang Server SDK

This is a follow up on our previous article. If you have not read that already, you can read that first.

As mentioned previously, Golang Server SDK allows you to more easily shift logic implementation from game clients to the backend. Here is another example of that. For this, we will use the Tic Tac Toe sample app which is included with our Golang Server SDK.

An Overview

Here is the overview of the tic tac toe sample app. It consists of two parts:

  1. A Lambda function which contains tic tac toe logic implementation (backend)
  2. A client for both player 1 and player 2 of tic tac toe game which talks to the Lambda function via API Gateway

Code Snippets

Validating Access Token

We validate the access token before executing logic implemented in the backend.

Starting a Match

To start a match, the Lambda function will send notification for both player 1 and player 2 via Lobby service.

Making A Move

Requests to make a move from client for both player 1 and player 2 are handled in the makeMoveHandler method. In this method, a player movement will also be communicated to the other player via Lobby service.

A Quick Demonstration

1. Prerequisites

  1. Go
  2. AWS SAM CLI
  3. A Redis instance (for REDIS_URL e.g. tic-tac-toe.XXXXX.ng.0001.use1.cache.amazonaws.com:6379)
  4. From AWS Console
    a. Lambda function execution role ARN, containing:
    i. AmazonEC2FullAccess
    ii. AmazonAPIGatewayInvokeFullAccess
    iii. AWSLambdaVPCAccessExecutionRole
    iv. AWSLambdaBasicExecutionRole
    b. VpcConfig Security Group Id and Subnet Id
  5. From the Accelbyte Admin Portal
    a. Base URL (for ACCELBYTE_BASE_URL and JUSTICE_BASE_URL e.g. https://demo.accelbyte.io)
    b. IAM Base URL (for IAM_BASE_URL e.g. https://demo.accelbyte.io/iam)
    c. IAM Public Client Id (for IAM_CLIENT_ID and APP_CLIENT_ID)
    d. Two user account for playing tic tac toe

2. Deploying The Lambda Function

To make it easy to deploy the lambda function, this sample app uses a SAM template. You only need to edit a few things in template.yml before deploying.

  1. Open template.yml and add in required Role ARN, VpcConfig and Environment Variables.

2. Build and deploy.

3. Done! You should be able to find the API URL in AWS Console.

3. Using The Client

The client is available in the client directory inside the sample app. Before running the client, you need to set a few environment variables.

  1. Open the first command line terminal.
    a. Set the required environment variables
    i. APP_CLIENT_ID
    ii. JUSTICE_BASE_URL e.g. https://demo.accelbyte.io
    iii. TIC_TAC_TOE_ENDPOINT, e.g. https://XXXXXXXXXX.execute-api.us-east-1.amazonaws.com/Prod

b. Run the client and login with the first user account

2. Open the second command line terminal, set the required environment variables and run the client (same as step 1) but login using the second user account.

3. Proceed to create matchmaking in both the first and second terminal. If successful, the tic tac toe game will start.

4. Both user terminals will get updated on every move. This updated information is sent to the AccelByte Lobby service and then sent to the both players via websocket.

5. At the end of the game, there will be a confirmation message on which player won.

Q&A

Will there be more language runtimes supported, like TypeScript, C#, or Java?

Yes! Please reach out to us if you are interested to learn more about the Service SDKs we have in the works.

Learn More

You can find our Golang Server SDK in our public Github. Interested in learning more about our solutions? Get in touch here.

Find a Backend Solution for Your Game!

Reach out to the AccelByte team to learn more.