示例#1
0
        private Hashtable GetCommands(GameSession gameSession)
        {
            // TODO: Split for two functions 1. - Get commands from API 2. Get unfinished commands
            Hashtable result;

            _logger.Debug($"Turn {gameSession.Turn}. Commands count is {gameSession.Commands.Count}");


            lock (Commands)
            {
                result = Commands.DeepClone();

                foreach (Command command in Commands.Values)
                {
                    CommandsHistory.Add(command.DeepClone());
                }

                Commands = new Hashtable();

                foreach (Command command in gameSession.Commands.Values)
                {
                    if (command.UntilTurnId <= gameSession.Turn)
                    {
                        continue;
                    }

                    var commandKey = gameSession.Id + "_" + command.CelestialObjectId + "_" + command.Type;

                    _logger.Info($"Turn {gameSession.Turn} resume command execution. {command.Type}");

                    result.Add(commandKey, command);
                }

                _logger.Debug($"Finished clear turn commands. Count is {result.Count}");
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// Shell Interpreter
        /// </summary>
        /// <param name="cmd">Command</param>
        public static void _CommandManger(string cmd)
        {
            #region Power

            if (cmd.Equals("shutdown"))
            {//NOTE: Why isn't it just the constructor? This leaves more room for <package>.<class>.HelpInfo;
                Power.Shutdown.c_Shutdown();
            }
            else if (cmd.Equals("reboot"))
            {
                Power.Reboot.c_Reboot();
            }

            #endregion Power

            #region Console

            else if ((cmd.Equals("clear")) || (cmd.Equals("cls")))
            {
                c_Console.Clear.c_Clear();
            }
            else if (cmd.StartsWith("echo "))
            {
                c_Console.Echo.c_Echo(cmd);
            }
            else if (cmd.Equals("help"))
            {
                System.Translation.List_Translation._Help();
            }

            #endregion Console

            #region FileSystem

            else if (cmd.StartsWith("cd "))
            {
                FileSystem.CD.c_CD(cmd);
            }
            else if (cmd.Equals("cp"))
            {
                FileSystem.CP.c_CP_only();
            }
            else if (cmd.StartsWith("cp "))
            {
                FileSystem.CP.c_CP(cmd);
            }
            else if ((cmd.Equals("dir")) || (cmd.Equals("ls")))
            {
                FileSystem.Dir.c_Dir();
            }
            else if ((cmd.StartsWith("dir ")) || (cmd.StartsWith("ls ")))
            {
                FileSystem.Dir.c_Dir(cmd);
            }
            else if (cmd.Equals("mkdir"))
            {
                FileSystem.Mkdir.c_Mkdir();
            }
            else if (cmd.StartsWith("mkdir "))
            {
                FileSystem.Mkdir.c_Mkdir(cmd);
            }
            else if (cmd.StartsWith("rmdir "))
            {
                FileSystem.Rmdir.c_Rmdir(cmd);
            }//TODO: orgainize
            else if (cmd.StartsWith("rmfil "))
            {
                FileSystem.Rmfil.c_Rmfil(cmd);
            }
            else if (cmd.Equals("mkfil"))
            {
                FileSystem.Mkfil.c_mkfil();
            }
            else if (cmd.StartsWith("mkfil "))
            {
                FileSystem.Mkfil.c_mkfil(cmd);
            }
            else if (cmd.StartsWith("edit "))
            {
                FileSystem.Edit.c_Edit(cmd);
            }
            else if (cmd.Equals("vol"))
            {
                FileSystem.Vol.c_Vol();
            }
            else if (cmd.StartsWith("run "))
            {
                FileSystem.Run.c_Run(cmd);
            }

            #endregion FileSystem

            #region Settings

            else if (cmd.Equals("logout"))
            {
                Settings.Logout.c_Logout();
            }
            else if (cmd.Equals("settings"))
            {
                Settings.Settings.c_Settings();
            }
            else if (cmd.StartsWith("settings "))
            {
                Settings.Settings.c_Settings(cmd);
            }
            else if (cmd.StartsWith("passwd "))
            {
                Settings.Passwd.c_Passwd(cmd);
            }
            else if (cmd.Equals("passwd"))
            {
                Settings.Passwd.c_Passwd(Kernel.userLogged);
            }

            #endregion Settings

            #region System Infomation

            else if (cmd.Equals("systeminfo"))
            {
                SystemInfomation.SystemInfomation.c_SystemInfomation();
            }
            else if ((cmd.Equals("ver")) || (cmd.Equals("version")))
            {
                SystemInfomation.Version.c_Version();
            }
            else if ((cmd.Equals("ipconfig")) || (cmd.Equals("ifconfig")) || (cmd.Equals("netconf")))
            {
                SystemInfomation.IPConfig.c_IPConfig();
            }
            else if ((cmd.Equals("time")) || (cmd.Equals("date")))
            {
                SystemInfomation.Time.c_Time();
            }

            #endregion System Infomation

            #region Tests

            else if (cmd.Equals("crash"))
            {
                Tests.Crash.c_Crash();
            }

            else if (cmd.Equals("cmd"))
            {
                CMDs.Add("ipconfig");
                CMDs.Add("netconf");
                CMDs.Add("help");
            }

            else if (cmd.Equals("crashcpu"))
            {
                int value = 1;
                value = value - 1;
                int result = 1 / value; //Division by 0
            }

            else if (cmd.Equals("beep"))
            {
                Kernel.speaker.beep();
            }

            else if (cmd.Equals("play"))
            {
                Kernel.speaker.playmusic();
            }

            //else if (cmd.StartsWith("xml "))
            //{
            //    Util.xml.CmdXmlParser.c_CmdXmlParser(cmd, 0, 4);
            //}

            #endregion Tests

            #region Tools

            else if (cmd.Equals("snake"))
            {
                Tools.Snake.c_Snake();
            }
            else if (cmd.StartsWith("md5"))
            {
                Tools.MD5.c_MD5(cmd);
            }
            else if (cmd.StartsWith("sha256"))
            {
                Tools.SHA256.c_SHA256(cmd);
            }

            #endregion

            #region Util

            else if (cmd.StartsWith("export"))
            {
                Util.EnvVar.c_Export(cmd);
            }

            else if (cmd.Equals("lspci"))
            {
                Util.Lspci.c_Lspci();
            }

            else if (cmd.Equals("about"))
            {
                Util.About.c_About();
            }

            else
            {
                if (cmd.Length <= 0)
                {
                    Console.WriteLine();
                    return;
                }
                else
                {
                    Util.CmdNotFound.c_CmdNotFound();
                }
            }

            CommandsHistory.Add(cmd); //adding last command to the commands history

            Console.WriteLine();

            #endregion Util
        }
        /// <summary>
        /// Shell Interpreter
        /// </summary>
        /// <param name="cmd">Command</param>
        public static void _CommandManger(string cmd)
        {
            CommandsHistory.Add(cmd); //adding last command to the commands history

            if (cmd.Length <= 0)
            {
                Console.WriteLine();
                return;
            }

            #region Parse command

            List <string> arguments = Misc.ParseCommandLine(cmd);

            string firstarg = arguments[0]; //command name

            if (arguments.Count > 0)
            {
                arguments.RemoveAt(0); //get only arguments
            }

            #endregion

            foreach (var command in CMDs)
            {
                if (command.ContainsCommand(firstarg))
                {
                    ReturnInfo result;

                    if (arguments.Count > 0 && (arguments[0] == "/help" || arguments[0] == "/h"))
                    {
                        ShowHelp(command);
                        result = new ReturnInfo(command, ReturnCode.OK);
                    }
                    else
                    {
                        result = CheckCommand(command);

                        if (result.Code == ReturnCode.OK)
                        {
                            if (arguments.Count == 0)
                            {
                                result = command.Execute();
                            }
                            else
                            {
                                result = command.Execute(arguments);
                            }
                        }
                    }

                    ProcessCommandResult(result);

                    return;
                }
            }

            Console.ForegroundColor = ConsoleColor.DarkRed;
            L.Text.Display("UnknownCommand");
            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine();
        }
        /// <summary>
        /// Shell Interpreter
        /// </summary>
        /// <param name="cmd">Command</param>
        public static void _CommandManger(string cmd)
        {
            if (Kernel.debugger != null)
            {
                if (Kernel.debugger.enabled)
                {
                    Kernel.debugger.Send("[Command] > " + cmd);
                }
            }

            #region Power

            if (cmd.Equals("shutdown") || cmd.Equals("sd"))
            {//NOTE: Why isn't it just the constructor? This leaves more room for <package>.<class>.HelpInfo;
                Power.Shutdown.c_Shutdown();
            }
            else if (cmd.Equals("reboot") || cmd.Equals("rb"))
            {
                Power.Reboot.c_Reboot();
            }

            #endregion Power

            #region Console

            else if ((cmd.Equals("clear")) || (cmd.Equals("cls")))
            {
                c_Console.Clear.c_Clear();
            }
            else if (cmd.StartsWith("echo "))
            {
                c_Console.Echo.c_Echo(cmd);
            }
            else if (cmd.Equals("help"))
            {
                System.Translation.List_Translation._Help();
            }

            #endregion Console

            #region FileSystem

            else if (cmd.StartsWith("cd "))
            {
                FileSystem.CD.c_CD(cmd);
            }
            else if (cmd.Equals("cp"))
            {
                FileSystem.CP.c_CP_only();
            }
            else if (cmd.StartsWith("cp "))
            {
                FileSystem.CP.c_CP(cmd);
            }
            else if ((cmd.Equals("dir")) || (cmd.Equals("ls")))
            {
                FileSystem.Dir.c_Dir();
            }
            else if ((cmd.StartsWith("dir ")) || (cmd.StartsWith("ls ")))
            {
                FileSystem.Dir.c_Dir(cmd);
            }
            else if (cmd.Equals("mkdir"))
            {
                FileSystem.Mkdir.c_Mkdir();
            }
            else if (cmd.StartsWith("mkdir "))
            {
                FileSystem.Mkdir.c_Mkdir(cmd);
            }
            else if (cmd.StartsWith("rmdir "))
            {
                FileSystem.Rmdir.c_Rmdir(cmd);
            }//TODO: orgainize
            else if (cmd.StartsWith("rmfil "))
            {
                FileSystem.Rmfil.c_Rmfil(cmd);
            }
            else if (cmd.Equals("mkfil"))
            {
                FileSystem.Mkfil.c_mkfil();
            }
            else if (cmd.StartsWith("mkfil "))
            {
                FileSystem.Mkfil.c_mkfil(cmd);
            }
            else if (cmd.StartsWith("edit "))
            {
                FileSystem.Edit.c_Edit(cmd);
            }
            else if (cmd.Equals("vol"))
            {
                FileSystem.Vol.c_Vol();
            }
            else if (cmd.StartsWith("run "))
            {
                FileSystem.Run.c_Run(cmd);
            }
            else if (cmd.StartsWith("cat"))
            {
                FileSystem.Cat.c_Cat(cmd);
            }

            #endregion FileSystem

            #region Settings

            else if (cmd.Equals("logout"))
            {
                Settings.Logout.c_Logout();
            }
            else if (cmd.Equals("settings"))
            {
                Settings.Settings.c_Settings();
            }
            else if (cmd.StartsWith("settings "))
            {
                Settings.Settings.c_Settings(cmd);
            }
            else if (cmd.StartsWith("passwd "))
            {
                Settings.Passwd.c_Passwd(cmd);
            }
            else if (cmd.Equals("passwd"))
            {
                Settings.Passwd.c_Passwd(Kernel.userLogged);
            }

            #endregion Settings

            #region System Infomation

            else if (cmd.Equals("systeminfo"))
            {
                SystemInfomation.SystemInfomation.c_SystemInfomation();
            }
            else if ((cmd.Equals("ver")) || (cmd.Equals("version")))
            {
                SystemInfomation.Version.c_Version();
            }
            else if ((cmd.StartsWith("ipconfig")) || (cmd.StartsWith("ifconfig")) || (cmd.StartsWith("netconf")))
            {
                SystemInfomation.IPConfig.c_IPConfig(cmd);
            }
            else if ((cmd.Equals("time")) || (cmd.Equals("date")))
            {
                SystemInfomation.Time.c_Time();
            }

            #endregion System Infomation

            #region Tests

            else if (cmd.Equals("crash"))
            {
                Tests.Crash.c_Crash();
            }

            else if (cmd.Equals("crashcpu"))
            {
                int value = 1;
                value = value - 1;
                int result = 1 / value; //Division by 0
            }

            else if (cmd.Equals("beep"))
            {
                Kernel.speaker.beep();
            }

            else if (cmd.Equals("play"))
            {
                Kernel.speaker.playmusic();
            }

            else if (cmd.Equals("udp"))
            {
                var xClient = new System.Network.IPV4.UDP.UdpClient(4242);
                xClient.Connect(new System.Network.IPV4.Address(192, 168, 1, 12), 4242);
                xClient.Send(Encoding.ASCII.GetBytes("Hello from Aura Operating System!"));
            }

            else if (cmd.Equals("tcp"))
            {
                var xClient = new System.Network.IPV4.TCP.TCPClient(4343);
                xClient.Connect(new System.Network.IPV4.Address(192, 168, 1, 12), 4224);
                xClient.Send(Encoding.ASCII.GetBytes("1"));
                xClient.Send(Encoding.ASCII.GetBytes("2"));
                xClient.Send(Encoding.ASCII.GetBytes("3"));
                xClient.Send(Encoding.ASCII.GetBytes("4"));
                xClient.Send(Encoding.ASCII.GetBytes("5"));
            }

            else if (cmd.Equals("haship"))
            {
                Console.WriteLine(new HAL.MACAddress(new byte[] { 00, 01, 02, 03, 04, 05 }).Hash);
                Console.WriteLine(new System.Network.IPV4.Address(192, 168, 1, 12).Hash);
            }

            else if (cmd.Equals("dns"))
            {
                System.Network.IPV4.UDP.DNS.DNSClient DNSRequest = new System.Network.IPV4.UDP.DNS.DNSClient(53);
                DNSRequest.Ask("perdu.com");
            }

            else if (cmd.Equals("net /refresh"))
            {
                foreach (HAL.Drivers.Network.NetworkDevice networkDevice in HAL.Drivers.Network.NetworkDevice.Devices)
                {
                    File.Create(@"0:\System\" + networkDevice.Name + ".conf");
                    Utils.Settings settings = new Utils.Settings(@"0:\System\" + networkDevice.Name + ".conf");
                    settings.Edit("ipaddress", "0.0.0.0");
                    settings.Edit("subnet", "0.0.0.0");
                    settings.Edit("gateway", "0.0.0.0");
                    settings.Edit("dns01", "0.0.0.0");
                    settings.Push();
                }
            }

            //else if (cmd.StartsWith("xml "))
            //{
            //    Util.xml.CmdXmlParser.c_CmdXmlParser(cmd, 0, 4);
            //}

            #endregion Tests

            #region Tools

            else if (cmd.Equals("snake"))
            {
                Tools.Snake.c_Snake();
            }
            else if (cmd.StartsWith("md5"))
            {
                Tools.MD5.c_MD5(cmd);
            }
            else if (cmd.StartsWith("sha256"))
            {
                Tools.SHA256.c_SHA256(cmd);
            }
            else if (cmd.StartsWith("ping"))
            {
                Network.Ping.c_Ping(cmd);
            }
            else if (cmd.Equals("debug"))
            {
                Tools.Debug.c_Debug();
            }
            else if (cmd.StartsWith("debug "))
            {
                Tools.Debug.c_Debug(cmd);
            }

            #endregion

            #region Util

            else if (cmd.StartsWith("export"))
            {
                Util.EnvVar.c_Export(cmd);
            }

            else if (cmd.Equals("lspci"))
            {
                Util.Lspci.c_Lspci();
            }

            else if (cmd.Equals("about"))
            {
                Util.About.c_About();
            }

            else
            {
                if (cmd.Length <= 0)
                {
                    Console.WriteLine();
                    return;
                }
                else if (cmd.Length == 2)
                {
                    FileSystem.ChangeVol.c_ChangeVol(cmd);
                }
                else
                {
                    Util.CmdNotFound.c_CmdNotFound();
                }
            }

            CommandsHistory.Add(cmd); //adding last command to the commands history

            Console.WriteLine();

            #endregion Util
        }
        /// <summary>
        /// Shell Interpreter
        /// </summary>
        /// <param name="cmd">Command</param>
        public static void _CommandManger(string cmd)
        {
            CommandsHistory.Add(cmd); //adding last command to the commands history

            if (cmd.Length <= 0)
            {
                Console.WriteLine();
                return;
            }

            List <string> arguments = Misc.ParseCommandLine(cmd);

            string firstarg = arguments[0]; //command name

            if (arguments.Count > 0)
            {
                arguments.RemoveAt(0); //get only arguments
            }

            foreach (var command in CMDs)
            {
                if (command.ContainsCommand(firstarg))
                {
                    ReturnInfo result;

                    if (arguments.Count == 0)
                    {
                        result = command.Execute();
                    }
                    else
                    {
                        result = command.Execute(arguments);
                    }

                    if (result.Code == ReturnCode.ERROR_ARG)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        L.Text.Display("invalidargcommand");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else if (result.Code == ReturnCode.ERROR)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("Error: " + result.Info);
                        Console.ForegroundColor = ConsoleColor.White;
                    }

                    Console.WriteLine();

                    return;
                }
            }

            Console.ForegroundColor = ConsoleColor.DarkRed;
            L.Text.Display("UnknownCommand");
            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine();

            /*
             *
             #region FileSystem
             *
             * else if (cmd.StartsWith("cd "))
             * {
             *  FileSystem.CD.c_CD(cmd);
             * }
             * else if (cmd.Equals("cp"))
             * {
             *  FileSystem.CP.c_CP_only();
             * }
             * else if (cmd.StartsWith("cp "))
             * {
             *  FileSystem.CP.c_CP(cmd);
             * }
             * else if ((cmd.Equals("dir")) || (cmd.Equals("ls")))
             * {
             *  FileSystem.Dir.c_Dir();
             * }
             * else if ((cmd.StartsWith("dir ")) || (cmd.StartsWith("ls ")))
             * {
             *  FileSystem.Dir.c_Dir(cmd);
             * }
             * else if (cmd.Equals("mkdir"))
             * {
             *  FileSystem.Mkdir.c_Mkdir();
             * }
             * else if (cmd.StartsWith("mkdir "))
             * {
             *  FileSystem.Mkdir.c_Mkdir(cmd);
             * }
             * else if (cmd.StartsWith("rmdir "))
             * {
             *  FileSystem.Rmdir.c_Rmdir(cmd);
             * }//TODO: orgainize
             * else if (cmd.StartsWith("rmfil "))
             * {
             *  FileSystem.Rmfil.c_Rmfil(cmd);
             * }
             * else if (cmd.Equals("mkfil"))
             * {
             *  FileSystem.Mkfil.c_mkfil();
             * }
             * else if (cmd.StartsWith("mkfil "))
             * {
             *  FileSystem.Mkfil.c_mkfil(cmd);
             * }
             * else if (cmd.StartsWith("edit "))
             * {
             *  FileSystem.Edit.c_Edit(cmd);
             * }
             * else if (cmd.Equals("vol"))
             * {
             *  FileSystem.Vol.c_Vol();
             * }
             * else if (cmd.StartsWith("run "))
             * {
             *  FileSystem.Run.c_Run(cmd);
             * }
             * else if (cmd.StartsWith("cat"))
             * {
             *  FileSystem.Cat.c_Cat(cmd);
             * }
             *
             #endregion FileSystem
             *
             #region Settings
             *
             * else if (cmd.Equals("logout"))
             * {
             *  Settings.Logout.c_Logout();
             * }
             * else if (cmd.Equals("settings"))
             * {
             *  Settings.Settings.c_Settings();
             * }
             * else if (cmd.StartsWith("settings "))
             * {
             *  Settings.Settings.c_Settings(cmd);
             * }
             * else if (cmd.StartsWith("passwd "))
             * {
             *  Settings.Passwd.c_Passwd(cmd);
             * }
             * else if (cmd.Equals("passwd"))
             * {
             *  Settings.Passwd.c_Passwd(Kernel.userLogged);
             * }
             *
             #endregion Settings
             *
             #region Tools
             *
             * else if (cmd.Equals("snake"))
             * {
             *  Tools.Snake.c_Snake();
             * }
             * else if (cmd.StartsWith("md5"))
             * {
             *  Tools.MD5.c_MD5(cmd);
             * }
             * else if (cmd.StartsWith("sha256"))
             * {
             *  Tools.SHA256.c_SHA256(cmd);
             * }
             * else if (cmd.Equals("debug"))
             * {
             *  Tools.Debug.c_Debug();
             * }
             * else if (cmd.StartsWith("debug "))
             * {
             *  Tools.Debug.c_Debug(cmd);
             * }
             *
             #endregion
             */
        }
示例#6
0
        /// <summary>
        /// Shell Interpreter
        /// </summary>
        /// <param name="cmd">Command</param>
        public static void _CommandManger(string cmd)
        {
            CommandsHistory.Add(cmd); //adding last command to the commands history

            if (cmd.Length <= 0)
            {
                Console.WriteLine();
                return;
            }

            List <string> arguments = Misc.ParseCommandLine(cmd);

            string firstarg = arguments[0]; //command name

            if (arguments.Count > 0)
            {
                arguments.RemoveAt(0); //get only arguments
            }

            foreach (var command in CMDs)
            {
                if (command.ContainsCommand(firstarg))
                {
                    ReturnInfo result = DoCheck(command);

                    if (result.Code == ReturnCode.OK)
                    {
                        if (arguments.Count == 0)
                        {
                            result = command.Execute();
                        }
                        else
                        {
                            result = command.Execute(arguments);
                        }
                    }

                    if (result.Code == ReturnCode.ERROR_ARG)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        L.Text.Display("invalidargcommand");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else if (result.Code == ReturnCode.ERROR)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("Error: " + result.Info);
                        Console.ForegroundColor = ConsoleColor.White;
                    }

                    Console.WriteLine();

                    return;
                }
            }

            Console.ForegroundColor = ConsoleColor.DarkRed;
            L.Text.Display("UnknownCommand");
            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine();
        }