Check out our latest project โœจ OpenChapter.io: free ebooks the way its meant to be ๐Ÿ“–

Godot-GameBackendSDK

An asset by HOXSEC
The page banner background of a mountain and forest
Godot-GameBackendSDK hero image

Quick Information

0 ratings
Godot-GameBackendSDK icon image
HOXSEC
Godot-GameBackendSDK

Production-ready Godot 4.4+ addon for custom game backendsAuthentication, Cloud Saves, Leaderboards, and Remote Config

Supported Engine Version
4.4
Version String
1.0.0
License Version
MIT
Support Level
community
Modified Date
9 hours ago
Git URL
Issue URL

Godot 4.4+ MIT License

Logo

๐ŸŽฎ GameBackendSDK

Production-ready Godot 4.4+ addon for custom game backends
Authentication, Cloud Saves, Leaderboards, and Remote Config

Features โ€ข Installation โ€ข Quick Start โ€ข API Reference โ€ข Backend Contract


โœจ Features

Feature Description
๐Ÿ” Authentication Guest login, email/password registration & login, automatic token refresh
๐Ÿ’พ Cloud Saves Key-value storage with optimistic locking and versioning
๐Ÿ† Leaderboards Submit scores, fetch rankings, get player position
โš™๏ธ Remote Config Platform-specific configuration and feature flags
๐Ÿ”„ Auto-Retry Exponential backoff with jitter on network failures
๐Ÿ“ฆ Zero Dependencies Pure GDScript, no external plugins required
๐Ÿ›ก๏ธ Type-Safe Consistent return shapes with comprehensive error handling

๐Ÿ“ฆ Installation

Option 1: Manual Installation

  1. Download or clone this repository
  2. Copy the addons/GameBackendSDK/ folder into your Godot project's addons/ directory
  3. Add Backend.gd as an autoload singleton:
    • Open Project Settings โ†’ Autoload
    • Path: res://addons/GameBackendSDK/Backend.gd
    • Node Name: Backend
    • Click Add

Option 2: Git Submodule

cd your-godot-project
git submodule add https://github.com/YOUR_USERNAME/GameBackendSDK.git addons/GameBackendSDK

๐Ÿš€ Quick Start

Prerequisites

  1. Install this SDK (see Installation above)
  2. Deploy or run the Godot-GameBackendAPI backend server

Basic Usage

extends Node

func _ready() -> void:
    # Initialize the SDK with your backend URL
    # For local testing: "http://localhost:3000"
    # For production: "https://api.yourgame.com"
    var result := await Backend.init("http://localhost:3000", "your_project_id", {
        "timeout_sec": 10,
        "retries": 3,
        "debug": true  # Enable debug logging (disable in production)
    })
    
    if not result.ok:
        print("Init failed: ", result.error.message)
        return
    
    # Ensure guest session
    result = await Backend.ensure_guest()
    if result.ok:
        print("Logged in as: ", result.data.user_id)
    
    # Save player data
    result = await Backend.kv_set("player_progress", {
        "level": 5,
        "coins": 1000
    })
    
    # Submit score
    result = await Backend.leaderboard_submit("global", 9999)
    if result.ok:
        print("Your rank: ", result.data.rank)

๐Ÿ’ก Tip: To test locally, clone and run Godot-GameBackendAPI first!


๐Ÿ“š API Reference

Initialization

Backend.init(base_url: String, project_id: String, options := {}) -> Dictionary

Options:

  • timeout_sec: int = 10 - Request timeout in seconds
  • retries: int = 3 - Maximum retry attempts for failed requests
  • backoff_base_ms: int = 100 - Base delay for exponential backoff
  • user_agent: String = "GameBackendSDK/1.0" - Custom user agent
  • default_headers: Dictionary = {} - Additional headers for all requests
  • endpoints: Dictionary = {} - Override default endpoint paths
  • queue_requests: bool = true - Serialize requests to prevent race conditions
  • debug: bool = false - Enable debug logging to Godot console

Authentication

Backend.ensure_guest()                              # Create/retrieve guest session
Backend.register(email: String, password: String)   # Register new account
Backend.login(email: String, password: String)      # Login with credentials
Backend.logout()                                    # Logout current user
Backend.refresh()                                   # Manually refresh access token

Cloud Storage

Backend.kv_set(key: String, value: Variant, expected_version := null)  # Store data
Backend.kv_get(key: String)                                            # Retrieve data
Backend.kv_delete(key: String, expected_version := null)               # Delete data

Leaderboards

Backend.leaderboard_submit(board: String, score: int)  # Submit score
Backend.leaderboard_top(board: String, limit: int)     # Get top entries
Backend.leaderboard_me(board: String)                  # Get player's rank

Remote Config

Backend.config_fetch(platform: String, app_version: String)

Signals

Backend.auth_changed.connect(func(user_id): ...)        # Auth state changed
Backend.request_started.connect(func(method, path): ...) 
Backend.request_finished.connect(func(method, path, ok, status): ...)
Backend.token_refreshed.connect(func(ok): ...)          # Token refresh result
Backend.banned_detected.connect(func(details): ...)     # Account banned

๐Ÿ”— Backend Contract

This SDK requires a backend that implements the REST API contract. Your backend must provide these endpoints:

Authentication Endpoints

Method Endpoint Description
POST /v1/auth/guest Create guest session
POST /v1/auth/register Register new user
POST /v1/auth/login Login existing user
POST /v1/auth/refresh Refresh access token
POST /v1/auth/logout Logout (invalidate tokens)

Cloud Storage Endpoints

Method Endpoint Description
GET /v1/kv/:key Get stored value
PUT /v1/kv/:key Set value
DELETE /v1/kv/:key Delete value

Leaderboard Endpoints

Method Endpoint Description
POST /v1/leaderboards/:board/submit Submit score
GET /v1/leaderboards/:board/top Get top entries
GET /v1/leaderboards/:board/me Get player's rank

Configuration Endpoint

Method Endpoint Description
GET /v1/config Get remote config

Need a backend? Check out GameBackendAPI - a reference implementation ready to deploy!

For complete endpoint specifications, see the Backend Contract Documentation.


๐Ÿ“– Return Format

All API methods return a consistent Dictionary structure:

{
    "ok": bool,           # true if successful, false if error
    "data": Variant,      # Method-specific data (null on error)
    "error": {            # null if ok=true
        "code": String,       # Error code (e.g., "unauthorized", "network_error")
        "message": String,    # Human-readable error message
        "status": int,        # HTTP status code (0 for non-HTTP errors)
        "details": Variant    # Additional error context
    }
}

Error Codes

  • network_error - Connection failed, DNS resolution failed, etc.
  • timeout - Request exceeded timeout limit
  • http_error - Generic HTTP error (4xx/5xx)
  • unauthorized - 401 response (invalid/expired token)
  • forbidden - 403 response (access denied)
  • not_found - 404 response (resource not found)
  • conflict - 409 response (version mismatch, duplicate, etc.)
  • rate_limited - 429 response (too many requests)
  • server_error - 5xx response (backend error)
  • invalid_response - Response is not valid JSON
  • banned - Account has been banned
  • validation_error - Request validation failed

๐ŸŽฏ Advanced Features

Automatic Token Refresh

When a request receives a 401 response and a refresh token exists:

  1. The SDK automatically calls the refresh endpoint
  2. Updates stored tokens
  3. Retries the original request once with the new token
  4. Emits token_refreshed signal

Retry Logic

Requests automatically retry on:

  • Network errors (connection failed, DNS errors, etc.)
  • Server errors (5xx responses)
  • Timeouts

Retry behavior:

  • Exponential backoff with jitter
  • Configurable max attempts
  • Automatic cancellation on non-retryable errors

Request Queueing

By default, requests are queued and processed serially to prevent:

  • Token refresh race conditions
  • Concurrent writes to the same key
  • Server overload

Disable for parallel requests: queue_requests: false in init options.

Token Storage

Tokens are automatically persisted to user://game_backend_sdk.json and survive game restarts.


๐ŸŽฎ Demo Scene

This repository includes a demo scene to test all features:

  1. Start the backend server (Godot-GameBackendAPI):

    cd Godot-GameBackendAPI
    bun install
    bun dev
    
  2. Open addons/GameBackendSDK/demo/Demo.tscn in Godot

  3. Set Base URL to http://localhost:3000

  4. Click "Initialize SDK" and test all features!


๐Ÿงช Testing

Run automated smoke tests:

# Add as autoload or instantiate
var tests = preload("res://addons/GameBackendSDK/demo/SmokeTest.gd").new()
add_child(tests)

๐Ÿ”ง Troubleshooting

"SDK not initialized" error

Call Backend.init() before any other methods.

Requests timeout immediately

Check your timeout_sec setting and network connectivity.

401 errors persist

  • Verify backend returns valid tokens
  • Check token format (should be Bearer token)
  • Ensure refresh endpoint works correctly

Tokens don't persist

Check that user:// directory is writable and not cleared between sessions.


๐Ÿ“ Project Structure

GameBackendSDK/
โ”œโ”€โ”€ addons/
โ”‚   โ””โ”€โ”€ GameBackendSDK/
โ”‚       โ”œโ”€โ”€ Backend.gd          # Main SDK singleton
โ”‚       โ”œโ”€โ”€ internal/
โ”‚       โ”‚   โ”œโ”€โ”€ HttpClient.gd   # HTTP request handling
โ”‚       โ”‚   โ”œโ”€โ”€ TokenStore.gd   # Token persistence
โ”‚       โ”‚   โ”œโ”€โ”€ Result.gd       # Result type helpers
โ”‚       โ”‚   โ”œโ”€โ”€ Types.gd        # Constants & types
โ”‚       โ”‚   โ””โ”€โ”€ Backoff.gd      # Exponential backoff logic
โ”‚       โ”œโ”€โ”€ demo/
โ”‚       โ”‚   โ”œโ”€โ”€ Demo.tscn       # Interactive demo scene
โ”‚       โ”‚   โ””โ”€โ”€ SmokeTest.gd    # Automated tests
โ”‚       โ””โ”€โ”€ README.md           # Detailed SDK documentation
โ”œโ”€โ”€ LICENSE
โ””โ”€โ”€ README.md

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ’ฌ Support


Made with โค๏ธ for the Godot community

Production-ready Godot 4.4+ addon for custom game backends
Authentication, Cloud Saves, Leaderboards, and Remote Config

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
Godot-GameBackendSDK icon image
HOXSEC
Godot-GameBackendSDK

Production-ready Godot 4.4+ addon for custom game backendsAuthentication, Cloud Saves, Leaderboards, and Remote Config

Supported Engine Version
4.4
Version String
1.0.0
License Version
MIT
Support Level
community
Modified Date
9 hours ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers