Exemple #1
0
        public static bool Init()
        {
            // Generate this before validation so that MP clients have this list available otherwise
            // desyncs occur
            ValidCommandList commandList = ActionList.ActionListToApi();

            try
            {
                Log.Message("Initialising Server");

                var authed = RimConnectAPI.AuthSecret(RimConnectSettings.secret, out string Token);
                if (!authed)
                {
                    Log.Error("Unable to Connect to RimConnect server.");
                    return(false);
                }

                RimConnectSettings.token = Token;
                RimConnectAPI.PostValidCommands(commandList);
                RimConnectAPI.GetConfig();

                return(true);
            } catch (Exception err)
            {
                Log.Error(err.ToString());

                return(false);
            }
        }
Exemple #2
0
        public static void PostValidCommands(ValidCommandList commandList)
        {
            try
            {
                // Go and push all the valid commands to the server
                var validCommandRequest = new RestRequest("command/valid", Method.POST);
                validCommandRequest.AddHeader("Content-Type", "application/json")
                .AddHeader("Authorization", $"Bearer {RimConnectSettings.token}")
                .AddJsonBody(commandList);

                var validCommandResponse = client.Execute <CommandOptionList>(validCommandRequest);

                if (validCommandResponse.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    RimConnectSettings.initialiseSuccessful = false;
                    Log.Error("Failed to provide valid commands to the server");
                }
                else
                {
                    RimConnectSettings.initialiseSuccessful = true;

                    CommandOptionList commandOptionList = new CommandOptionList();
                    commandOptionList.commandOptions = validCommandResponse.Data.commandOptions;

                    Settings.CommandOptionListController.commandOptionList = commandOptionList;
                    Log.Message($"Provided a total of {commandOptionList.commandOptions.Count} valid commands to the server");
                }
            }
            catch (Exception e)
            {
                Log.Error($"Failed to provide valid commands to server. {e.Message}");
            }
        }