Skip to content

4Players/fleet-sdk-csharp

Repository files navigation

OdinFleet - a C# library to access the Odin Fleet API

Introducing the Odin Fleet API by 4Players, enabling developers to deploy game servers globally with just a few lines of code. Odin Fleet, the technology behind 4Netplayers, now empowers developers and publishers to manage their own server fleets effortlessly. Our streamlined API makes it easy to deploy and manage game servers worldwide.

This C# SDK is automatically generated by the OpenAPI Generator project based on our API specification that can be found here.

For an easier point of entry we have created a simple wrapper OdinFleetClient that sets up the correct configuration and provides a simple interface to the API. If you want to use the API directly, you can use the OdinFleetApi class, but you need to set up the configuration yourself - see the code in OdinFleetClient how to set the api token and base path.

Changing the underlying http library

This API uses built-int httpclient, so you can use it with any .NET project. However, if you want to use the API within Unity you need to use the UnityWebRequest class or a library like RestSharp. You can update the underlying auto-generated code (and thus changing the http client) using the generate.sh script in the root of this repository.

In the script you'll find the openapi-generator-cli command that generates the code. You can change the library option to restsharp or unityWebRequest to generate the code for those libraries. We suggest using the OdinFleetClient wrapper as you don't need to change the code in your project even if you change the underlying http library.

Getting an API Key

To use the Odin Fleet API, you need an API key. You can get one by signing up in our Console at https://console.4players.io. Next navigate to settings by clicking on profile image at the top right corner and then click on Settings. Navigate to API-Keys and copy the key automatically generated for you to get started using the API.

Frameworks supported

  • .NET Core >=1.0
  • .NET Framework >=4.6
  • Mono/Xamarin >=vNext

Please note, that the SDK is compatible with .NET 4.8 and above. If you need another version, please contact us.

Dependencies

The DLLs included in the package may not be the latest version. We recommend using NuGet to obtain the latest version of the packages:

Install-Package Newtonsoft.Json
Install-Package JsonSubTypes
Install-Package System.ComponentModel.Annotations

Installation

Generate the DLL using your preferred tool (e.g. dotnet build)

Then include the DLL (under the bin folder) in the C# project, and use the namespaces:

using OdinFleet.Api;
using OdinFleet.Client;
using OdinFleet.Model;

Usage

To use the API client with a HTTP proxy, setup a System.Net.WebProxy

Configuration c = new Configuration();
System.Net.WebProxy webProxy = new System.Net.WebProxy("http://myProxyUrl:80/");
webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
c.Proxy = webProxy;

Please note: This code refers to the default httpclient used in this API per default. If you changed the underlying http library, this code might not work. Please refer to the documentation of the library you are using (i.e. RestSharp or UnityWebRequest).

Getting Started

To get started easily we have created a simple Wrapper OdinFleetClient that sets up the correct configuration and provides a simple interface to the API. If you want to use the API directly, you can use the OdinFleetApi class, but you need to set up the configuration yourself - see the code in OdinFleetClient how to set the api token and base path.

using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http;
using OdinFleet.Api;
using OdinFleet.Client;
using OdinFleet.Model;

namespace Example
{
    public class Example
    {
        public static void Main()
        {            
            var apiInstance = new OdinFleetClient("__YOUR_API_TOKEN__");

            try
            {
                // Create a list of apps
                List<App> apps = apiInstance.GetApps();
                
                // Select the first app in the list so that subsequent calls can use it
                App app = apps[0];
                apiInstance.SelectApp(app.Id);
                
                // Get all servers for the selected app
                List<Server> servers = apiInstance.GetServers();
                
                // Create a backup for the first server in the list
                var result = client.CreateServerBackup(servers[0].Id, "My Backup");
                if (result) {
                    Debug.Print("Backup created successfully");
                }
                else {
                    Debug.Print("Backup creation failed");
                }
            }
            catch (ApiException e)
            {
                Debug.Print("Exception when calling OdinFleetApi.CreateApp: " + e.Message );
                Debug.Print("Status Code: "+ e.ErrorCode);
                Debug.Print(e.StackTrace);
            }

        }
    }
}

Documentation for API Endpoints

All URIs are relative to http://b2b.api.4np.4players.de/api

Class Method HTTP request Description
OdinFleetApi CreateApp POST /apps Create an app
OdinFleetApi CreateAppLocationSetting POST /apps/{app}/location-settings Create a new location setting
OdinFleetApi CreateBackup POST /services/{service}/backup Creates a backup of the service
OdinFleetApi CreateBinary POST /apps/{app}/binaries Create a binary and the related file
OdinFleetApi CreateDockerRegistry POST /docker-registries Create a new docker registry
OdinFleetApi CreateServerConfig POST /apps/{app}/configs Create a new server config
OdinFleetApi DeleteApp DELETE /apps/{app} Delete a specific app
OdinFleetApi DeleteAppLocationSetting DELETE /app-location-settings/{appLocationSetting} Delete a location setting
OdinFleetApi DeleteAuthToken DELETE /auth/token Handles the deletion of a user's authentication tokens
OdinFleetApi DeleteBinary DELETE /binaries/{binary} Delete a specified binary
OdinFleetApi DeleteDockerRegistry DELETE /docker-registries/{dockerRegistry} Delete a specific docker registry
OdinFleetApi DeleteServerConfig DELETE /server-configs/{serverConfig} Delete a specific server config
OdinFleetApi GetAppById GET /apps/{app} Show a specific app
OdinFleetApi GetAppLocationSettings GET /apps/{app}/location-settings Show all location settings
OdinFleetApi GetApps GET /apps Show all apps
OdinFleetApi GetAuthToken POST /auth/token Handles user authentication
OdinFleetApi GetBackups GET /services/{service}/backups List all backups for the specified Docker service
OdinFleetApi GetBinaries GET /apps/{app}/binaries Show all binaries
OdinFleetApi GetBinaryById GET /binaries/{binary} Show a specific binary
OdinFleetApi GetDockerRegistries GET /docker-registries Show all docker registries
OdinFleetApi GetDockerRegistryById GET /docker-registries/{dockerRegistry} Display a specific docker registry
OdinFleetApi GetLocations GET /nodes/locations Show a unique listing of locations based on active and ready worker nodes
OdinFleetApi GetMostRecentBackup GET /services/{service}/backup Display the most recent backup for the specified Docker service
OdinFleetApi GetServerBackupDownloadUrl GET /services/{service}/backup/download Generates a presigned URL for downloading a backup from AWS S3 if the backup method is 'archive'
OdinFleetApi GetServerById GET /apps/{app}/services/{service} Display a specific DockerService associated with the given App
OdinFleetApi GetServerConfigById GET /server-configs/{serverConfig} Show a specific server config
OdinFleetApi GetServerConfigs GET /apps/{app}/configs Show all server configs
OdinFleetApi GetServerLogs GET /services/{service}/logs Get stdout and stderr logs from a service or task
OdinFleetApi GetServers GET /apps/{app}/services Show all services for a given app
OdinFleetApi RestartServer POST /services/{service}/restart Restarts a specific Docker service
OdinFleetApi RestoreBackup POST /services/{service}/restore Restore a backup for a specified Docker service
OdinFleetApi UpdateAppLocationSetting PUT /app-location-settings/{appLocationSetting} Update a location setting
OdinFleetApi UpdateBinary PUT /binaries/{binary} Update a binary and the related file
OdinFleetApi UpdateDockerRegistry PUT /docker-registries/{dockerRegistry} Update a specific docker registry
OdinFleetApi UpdateServerConfig PUT /server-configs/{serverConfig} Update a server config

Documentation for Models

Documentation for Authorization

Endpoints do not require authorization.

Releases

No releases published

Packages

No packages published