Example #1
0
        /// <Summary>
        /// Launch the Nova GUI to play a turn for a give player.
        /// </Summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param>
        private void PlayerList_DoubleClick(object sender, EventArgs e)
        {
            // On occasion this fires but SelectedItems is empty. Ignore and let the user re-click. See issue #2974019.
            if (playerList.SelectedItems.Count == 0)
            {
                return;
            }

            // Find what was clicked
            string raceName = playerList.SelectedItems[0].SubItems[1].Text;

            try
            {
                // Launch the nova GUI
                CommandArguments args = new CommandArguments();
                args.Add(CommandArguments.Option.RaceName, raceName);
                args.Add(CommandArguments.Option.Turn, serverState.TurnYear);
                args.Add(CommandArguments.Option.IntelFileName, Path.Combine(serverState.GameFolder, raceName + Global.IntelExtension));

                Nova.WinForms.Gui.NovaGUI gui = new Nova.WinForms.Gui.NovaGUI(args.ToArray());
                gui.Show();
            }
            catch (Exception ex)
            {
                Report.Error("NovaConsole.cs : PlayerList_DoubleClick() - Failed to launch GUI. Details:" +
                             Environment.NewLine + ex.ToString());
            }
        }
Example #2
0
        /// <Summary>
        /// When the 'Continue Game' button is pressed, continue the last opened game.
        /// </Summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param>
        private void ContinueGameButton_Click(object sender, EventArgs e)
        {
            // start the GUI
            if (this.clientStateFile != null)
            {
                CommandArguments args = new CommandArguments();
                args.Add(CommandArguments.Option.GuiSwitch);
                args.Add(CommandArguments.Option.StateFileName, this.clientStateFile);

                try
                {
                    Nova.WinForms.Gui.NovaGUI gui = new Nova.WinForms.Gui.NovaGUI(args.ToArray());
                    gui.Show();
                }
                catch
                {
                    Report.Error("Failed to launch GUI.");
                }
            }

            // start the server
            if (this.serverStateFile != null)
            {
                try
                {
                    Nova.WinForms.Console.NovaConsole novaConsole = new Nova.WinForms.Console.NovaConsole();
                    novaConsole.Show();
                    return;
                }
                catch
                {
                    Report.FatalError("Unable to launch Console.");
                }
            }
        }
Example #3
0
        /// <Summary>
        /// Load Next Turn
        /// </Summary>
        /// <remarks>
        /// This menu Item has been disabled as it does not currently detect if there is
        /// a valid next turn.
        /// TODO (priority 6) - detect when a new turn is available.
        /// </remarks>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param>
        private void LoadNextTurnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // prepare the arguments that will tell how to re-initialize.
            CommandArguments commandArguments = new CommandArguments();

            commandArguments.Add(CommandArguments.Option.RaceName, clientState.EmpireState.Race.Name);
            commandArguments.Add(CommandArguments.Option.Turn, clientState.EmpireState.TurnYear + 1);

            clientState.Initialize(commandArguments.ToArray());
            this.NextTurn();
        }
Example #4
0
        public override string Build(string branch)
        {
            if (!string.IsNullOrEmpty(_publishType))
            {
                CommandArguments.Add(_publishType);
            }

            return(base.Build(branch));
        }
Example #5
0
 /// <summary>
 /// Default Constructor
 /// </summary>
 public HelpCommand() : base()
 {
     Name = "Help";
     CommandArguments.Add("-h");
     CommandArguments.Add("--help");
     CommandArguments.Add("-help");
     CommandArguments.Add("-?");
     HelpText = "";
 }
 public DatabaseQueryCommand() : base()
 {
     Name = "Database Query";
     CommandArguments.Add("-db");
     CommandArguments.Add("--database");
     CommandArguments.Add("-database");
     HelpText = "Creates an excel file from the given query and database connection\n";
     Arguments.Add(new RequiredArgument("Query"));
     Arguments.Add(new RequiredArgument("DB Conn String"));
     Arguments.Add(new RequiredArgument("FileName"));
     Arguments.Add(new OptionalArgument("FileLocation", System.IO.Directory.GetCurrentDirectory()));
 }
        public virtual CommandArguments GetArguments(string commandLine)
        {
            var match = syntaxRegex.Match(commandLine);

            var args = new CommandArguments();

            foreach (var group in match.Groups.Where(x => ExpectedArgs.Contains(x.Name)))
            {
                args.Add(group.Name, group.Value);
            }

            return(args);
        }
Example #8
0
        /// <Summary>
        /// Launch the AI program to take any turns for AI players.
        ///
        /// </Summary>
        /// <param name="status">Required as this is called in as a worker thread, but unused.</param>
        private void RunAI(object status)
        {
            if (runAiCheckBox.Checked)
            {
                // MessageBox.Show("Run AI");

                foreach (PlayerSettings settings in serverState.AllPlayers)
                {
                    if (settings.AiProgram == "Human")
                    {
                        continue;
                    }

                    EmpireData empireData;
                    serverState.AllEmpires.TryGetValue(settings.PlayerNumber, out empireData);
                    if (empireData == null || empireData.TurnYear != serverState.TurnYear || !empireData.TurnSubmitted)
                    {
                        // TODO: Add support for running custom AIs based on settings.AiProgram.
                        CommandArguments args = new CommandArguments();
                        args.Add(CommandArguments.Option.AiSwitch);
                        args.Add(CommandArguments.Option.RaceName, settings.RaceName);
                        args.Add(CommandArguments.Option.Turn, serverState.TurnYear);
                        args.Add(CommandArguments.Option.IntelFileName, Path.Combine(serverState.GameFolder, settings.RaceName + Global.IntelExtension));
                        try
                        {
                            Process.Start(Assembly.GetExecutingAssembly().Location, args.ToString());
                        }
                        catch
                        {
                            Report.Error("Failed to launch AI.");
                        }
                        // FIXME (priority 3) - can not process any more than one AI at a time.
                        // It will crash if multiple AI's try to access the same files at the same time.
                        return;
                    }
                }
            }
        }
Example #9
0
        /// <summary>
        /// Command parsing, takes a string and attempts to match it to a stored class.
        /// Also attempts to create a list of arguments that can be passed to matched command
        /// </summary>
        public void CommandInput(string text)
        {
            if (text == null)
            {
                return;
            }
            var              splitText = text.Split(' '); // splits the input text up by the space character
            string           command   = splitText[0];
            CommandArguments arguments = new CommandArguments();

            if (splitText.Length > 1)                               // if there is more than one index in the array check for arguments
            {
                string[] flags      = new string[splitText.Length]; // each array represents the flags and the associatd parameters
                string[] parameters = new string[splitText.Length]; // each index is linked across the arrays

                var paramcount = 0;
                for (int i = 1; i < splitText.Length; i++)
                {
                    var arg = splitText[i];
                    if (arg == string.Empty)
                    {
                        continue;
                    }
                    if (arg.Substring(0, 1) == "-")
                    {
                        // arg is a flag
                        flags[paramcount] = arg;
                        paramcount++;
                    }
                    else
                    {
                        // arg is an parameter
                        if (paramcount - 1 >= 0)
                        {
                            parameters[paramcount - 1] = arg;
                        }
                    }
                }

                // iterate back over the arrays and store them in the CommandArguments data structure, aligning the arrays so each flag has the correcy parameter
                for (int i = 0; i < flags.Length; i++)
                {
                    if (flags[i] == null)
                    {
                        continue;
                    }
                    if (parameters.Length > i && parameters[i] != null)
                    {
                        arguments.Add(flags[i], parameters[i]);
                    }
                    else
                    {
                        arguments.Add(flags[i], " ");
                    }
                }
            }
            Program.App.Log($"[{DateTime.Now.ToShortTimeString()}] {text}"); // Echo back into console

            if (Invoke(command, arguments) == false)
            {
                Program.App.Log($"[{DateTime.Now.ToShortTimeString()}] No command found '" + command + "'");
            }
        }
Example #10
0
        /// <Summary>
        /// When the 'Open Game' button is pressed, open a file browser to locate the game and open it.
        /// </Summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param>
        private void OpenGameButton_Click(object sender, EventArgs e)
        {
            string intelFileName = "";
            bool   gameLaunched  = false;

            // have the user identify the game to open
            try
            {
                OpenFileDialog fd = new OpenFileDialog();
                fd.Title    = "Open Game";
                fd.FileName = "*" + Global.IntelExtension;
                DialogResult result = fd.ShowDialog();
                if (result != DialogResult.OK)
                {
                    return;
                }
                intelFileName = fd.FileName;
            }
            catch
            {
                Report.FatalError("Unable to open a game.");
            }

            // Launch the GUI
            CommandArguments args = new CommandArguments();

            args.Add(CommandArguments.Option.GuiSwitch);
            args.Add(CommandArguments.Option.IntelFileName, intelFileName);

            try
            {
                Process.Start(Assembly.GetExecutingAssembly().Location, args.ToString());
                gameLaunched = true;
            }
            catch
            {
                Report.Error("NovaLauncher.cs: OpenGameButton_Click() - Failed to launch GUI.");
            }

            // Launch the Console if this is a local game, i.e. if the console.state is in the same directory.
            string        serverStateFileName = "";
            FileInfo      intelFileInfo       = new FileInfo(intelFileName);
            string        gamePathName        = intelFileInfo.DirectoryName;
            DirectoryInfo gameDirectoryInfo   = new DirectoryInfo(gamePathName);

            FileInfo[] gameFilesInfo = gameDirectoryInfo.GetFiles();
            foreach (FileInfo file in gameFilesInfo)
            {
                if (file.Extension == Global.ServerStateExtension)
                {
                    serverStateFileName = file.FullName;
                }
            }

            if (serverStateFileName.Length > 0)
            {
                args.Clear();
                args.Add(CommandArguments.Option.ConsoleSwitch);
                args.Add(CommandArguments.Option.StateFileName, serverStateFileName);

                try
                {
                    Process.Start(Assembly.GetExecutingAssembly().Location, args.ToString());
                    gameLaunched = true;
                }
                catch
                {
                    Report.Error("NovaLauncher.cs: OpenGameButton_Click() - Failed to launch GUI.");
                }
            }

            if (gameLaunched)
            {
                Application.Exit();
            }
        }