ApiAccess
A static class in Root.Township, the global namespace.
Static holder of the game's Alta web API client. Picks the endpoint from settings or command line flags, or starts an offline client from stored credentials when there's no internet.
- Listed in Global namespace: A to B
- Documented in Alta's web API, Startup and app state
Fields
| Member | What it is |
|---|---|
const string StoredOfflineTokenName | PlayerPreferences key of the stored offline token. |
3 private and internal fields
| Member | What it is |
|---|---|
private static IHighLevelApiClient apiClient | Backing field for ApiClient. |
private static Logger logger | NLog logger for this class. |
private const int Timeout | Constant of 40, not used in this file. |
Properties
| Member | What it is |
|---|---|
static IHighLevelApiClient ApiClient { get; } | The shared high-level API client. Created by StartApiAccess on first use. |
Methods
| Member | What it is |
|---|---|
static async Task<bool> IsConnectedToInternet() | Checks for internet, trying once more after half a second if the first check fails. |
static void StartApiAccess() | Sets device info, then starts offline mode or the online client. Does nothing if a client already exists. |
static void StartOffline(LoginCredentials credentials) | Creates an offline API client from the given credentials. |
static void StartWithEndpoint(string endpoint) | Creates the online API client for the given URL. Logs an error if a client already exists. |
static bool TryGetLoginCredentials(out LoginCredentials credentials) | Builds login credentials from the access, identity and refresh tokens stored in PlayerPreferences. False if any is missing. |
6 private and internal methods
| Member | What it is |
|---|---|
private static bool CanUseOffline(out LoginCredentials credentials) | True if a stored offline token matches the stored access token, so the game can run offline. |
private static bool IsConnectedToInternetInternal() | Requests Google's generate_204 URL and returns whether it answered. Returns false if SimulateNoInternet is on. |
private static bool IsValidOfflineToken(string offlineToken, JwtSecurityToken accessToken) | True if the offline token string equals the written access token. |
private static void SetApiClientLogging() | Empty in this build. |
private static bool ShouldUseOffline() | True with /force_offline, or when there's no internet and /ignore_offline isn't given. |
private static void StartAPI() | Picks the API URL from GameConfig or the /development_api, /local_api, /latest_api, /test_api or /custom_api flags and starts the client. |