Skip to main content

ApplicationStartupManager

A class in Root.Township, the global namespace.

Startup component in the first scene: checks internet and version, hooks login events, then decides what to do after login (start a server, join one, join the tutorial, or load the main menu). Both sides; a server is started through the /start_server flag.

Constructors​

MemberWhat it is
ApplicationStartupManager()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
static ApplicationStartupManager instanceStatic field, not assigned in this file.
4 private and internal fields
MemberWhat it is
private bool isLoadingAllCosmeticsIntoRAMInEditorInspector flag, not used in this file.
private static readonly Logger loggerNLog logger for this class.
private static IServerHostController serverHostControllerInjected IServerHostController. Set by Inject but not used in this file.
private IValidVersionService validVersionServiceInjected service used by CheckVersion.

Properties​

MemberWhat it is
static bool IsSkippingMenu { get; set; }Static flag other code can set to skip the menu. Not read in this file.

Events​

MemberWhat it is
static event Action StartedRaised once startup has hooked login and checked the version.

Methods​

MemberWhat it is
static void DisableRegularStartupActions()Unhooks RegularStartupActions from login, so logging in doesn't run the usual startup flow.
static int GetLastLaunchedSceneIndex()Returns the scene index saved by StartLocalServer, or MenuSettings.LocalGameScene if none or out of range.
static async Task<bool> JoinTutorialAsync()Asks matchmaking for a tutorial server and joins it. Returns false if none is found.
static bool PlayerHasNotCompletedTutorial()True if the access token lacks server_access_pre_alpha (or server_access_tester on Quest), which is how the game tells a player still needs the tutorial.
static async void RunStartupActions(bool checksTutorial)Tries /start_server, then /join_server, then the tutorial, then an Oculus deep link, and loads the main menu if none worked (unless headless).
protected void Inject(IValidVersionService validVersionService, IServerHostController injectedServerHostController)VContainer injection of the version service and server host controller.
23 private and internal methods
MemberWhat it is
private bool ApproveAll(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)Certificate callback that accepts every TLS certificate. Used by IgnoreSecurityProtocol.
private void AttemptGameLaunchedEvent()Posts the GameLaunch analytics event now, or after the login attempt when started with /access_token. Skipped with /agones.
private static async Task<bool> AttemptServerJoinAsync(string[] joinArgs)Parses a server id from the /join_server argument, fetches that server from the API and joins it.
private static async Task<bool> AttemptServerStartAsync(string[] startServerArguments)Parses id, headless flag and port from /start_server and starts that server. Id -1 starts the local test server.
private void Awake()Sets the working directory to the folder above the game's data folder.
private async void CheckVersion()Asks IValidVersionService if this version is valid and shows a popup if not.
private void CleanStoreCredentials()On logout: clears the stored offline token and stops tracking credential refreshes.
private void HandlePostLogin()Posts the GameLaunch analytics event with the logged in user's id, if any.
private bool HasOfflinePermissions()True if the user has the play_offline permission.
private void IgnoreSecurityProtocol()Turns off TLS certificate checks for all web requests. Not called in this file.
private static async Task<bool> JoinLocalServer()Joins a dev server on localhost port 1757, or starts a local test if that fails and StartLocalTestOnServerJoinFail is set.
private void OnApplicationQuit()Empty.
private void OnLoggedIn()Login handler that posts the launch event. It re-adds itself to LoggedIn instead of removing itself, so it probably fires again on later logins.
private void OnLoginAttemptFailed(string message)Posts the launch event without a user id after a failed login, and unhooks itself.
private static void OnStarted()Raises the Started event.
private static async void PostGameLaunchedEvent(int? userId = null)Posts a GameLaunch analytics event with the source (/source flag, or Launcher), version and user id.
private static void RegularStartupActions()Runs once on the first login: calls RunStartupActions without the tutorial check.
private async void Start()Client: loads the no-internet scene if offline. Otherwise runs Startup.
private static async Task<bool> StartLocalServer(int serverSceneIndex)Starts a local server for the given scene index and saves the index for GetLastLaunchedSceneIndex.
private void Startup()Hooks login and logout handlers, checks the version and handles the launch analytics event.
private void StoreOfflineCredentials()If the user may play offline, stores the access token as the offline token and keeps it updated on refresh.
private static void StoreOfflineCredentials(LoginCredentials userCredentials)If the user may play offline, stores the access token as the offline token and keeps it updated on refresh.
private void StoreUpdatedOfflineCredentials(LoginCredentials oldCredentials, LoginCredentials newCredentials)Stores the new access token as the offline token when the login refreshes.