Пример #1
0
        internal static IVirus CreateVirus(string id, int threatlevel)
        {
            if (threatlevel < 1)
            {
                throw new Exception("Threat level can't be below 1.");
            }
            if (threatlevel > 4)
            {
                throw new Exception("Threat level can't be above 4.");
            }

            foreach (var type in ReflectMan.Types.Where(x => x.GetInterfaces().Contains(typeof(IVirus)) && Shiftorium.UpgradeAttributesUnlocked(x)))
            {
                var attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is VirusAttribute) as VirusAttribute;
                if (attrib != null)
                {
                    if (attrib.ID == id)
                    {
                        IVirus virus = (IVirus)Activator.CreateInstance(type);
                        virus.Infect(threatlevel);
                        return(virus);
                    }
                }
            }

            throw new Exception("Cannot create virus.");
        }
Пример #2
0
 /// <summary>
 /// Gets a list of all <see cref="IStatusIcon"/> objects that meet their Shiftorium dependencies.
 /// </summary>
 /// <returns>An array of <see cref="Type"/>s containing the found objects.</returns>
 public static Type[] GetAllStatusIcons()
 {
     return(Array.FindAll(ReflectMan.Types, x => x.GetInterfaces().Contains(typeof(IStatusIcon)) && Shiftorium.UpgradeAttributesUnlocked(x)));
 }
Пример #3
0
        public static bool Help()
        {
            var asm = Assembly.GetExecutingAssembly();

            var types = asm.GetTypes();

            foreach (var type in types)
            {
                if (Shiftorium.UpgradeAttributesUnlocked(type))
                {
                    foreach (var a in type.GetCustomAttributes(false))
                    {
                        if (a is Namespace)
                        {
                            var ns = a as Namespace;

                            if (!ns.hide)
                            {
                                string descp = "{NAMESPACE_" + ns.name.ToUpper() + "_DESCRIPTION}";
                                if (descp == Localization.Parse(descp))
                                {
                                    descp = "";
                                }
                                else
                                {
                                    descp = Shiftorium.UpgradeInstalled("help_description") ? Localization.Parse("{SEPERATOR}" + descp) : "";
                                }

                                Console.WriteLine($"{{NAMESPACE}}{ns.name}" + descp);

                                foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static))
                                {
                                    if (Shiftorium.UpgradeAttributesUnlocked(method))
                                    {
                                        foreach (var ma in method.GetCustomAttributes(false))
                                        {
                                            if (ma is Command)
                                            {
                                                var cmd = ma as Command;

                                                if (!cmd.hide)
                                                {
                                                    string descriptionparse = "{COMMAND_" + ns.name.ToUpper() + "_" + cmd.name.ToUpper() + "_DESCRIPTION}";
                                                    string usageparse       = "{COMMAND_" + ns.name.ToUpper() + "_" + cmd.name.ToUpper() + "_USAGE}";
                                                    if (descriptionparse == Localization.Parse(descriptionparse))
                                                    {
                                                        descriptionparse = "";
                                                    }
                                                    else
                                                    {
                                                        descriptionparse = Shiftorium.UpgradeInstalled("help_description") ? Localization.Parse("{SEPERATOR}" + descriptionparse) : "";
                                                    }

                                                    if (usageparse == Localization.Parse(usageparse))
                                                    {
                                                        usageparse = "";
                                                    }
                                                    else
                                                    {
                                                        usageparse = Shiftorium.UpgradeInstalled("help_usage") ? Localization.Parse("{SEPERATOR}" + usageparse, new Dictionary <string, string>()
                                                        {
                                                            { "%ns", ns.name },
                                                            { "%cmd", cmd.name }
                                                        }) : "";
                                                    }

                                                    Console.WriteLine($"{{COMMAND}}{ns.name}.{cmd.name}" + usageparse + descriptionparse);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }
Пример #4
0
        /// <summary>
        /// Pulls a list of all available App Launcher items.
        /// </summary>
        /// <returns>A <see cref="List{LauncherItem}"/> containing all available App Launcher items.</returns>
        public static List <LauncherItem> Available()
        {
            List <LauncherItem> win = new List <LauncherItem>();

            foreach (var type in Array.FindAll(ReflectMan.Types, t => t.GetInterfaces().Contains(typeof(IShiftOSWindow)) && Shiftorium.UpgradeAttributesUnlocked(t)))
            {
                foreach (var attr in type.GetCustomAttributes(false))
                {
                    if (!(attr is MultiplayerOnlyAttribute && !KernelWatchdog.MudConnected))
                    {
                        if (attr is LauncherAttribute)
                        {
                            var launch = attr as LauncherAttribute;
                            if (launch.UpgradeInstalled)
                            {
                                var data = new LauncherItem {
                                    DisplayData = launch, LaunchType = type
                                };
                                data.DisplayData.Category = Localization.Parse(data.DisplayData.Category);
                                data.DisplayData.Name     = Localization.Parse(data.DisplayData.Name);
                                win.Add(data);
                            }
                        }
                    }
                }
            }

            foreach (var file in Utils.GetFiles(Paths.GetPath("applauncher")))
            {
                if (file.EndsWith(".al"))
                {
                    var item = JsonConvert.DeserializeObject <LuaLauncherItem>(Utils.ReadAllText(file));
                    win.Add(item);
                }
            }
            return(win);
        }
Пример #5
0
 /// <summary>
 /// Opens a file from the specified ShiftFS path.
 /// </summary>
 /// <param name="path">The path to open.</param>
 public static void OpenFile(string path)
 {
     if (!Objects.ShiftFS.Utils.FileExists(path))
     {
         throw new System.IO.FileNotFoundException("ShiftFS could not find the file specified.", path);
     }
     foreach (var type in ReflectMan.Types.Where(x => x.GetInterfaces().Contains(typeof(IFileHandler)) && Shiftorium.UpgradeAttributesUnlocked(x)))
     {
         foreach (FileHandlerAttribute attrib in type.GetCustomAttributes(false).Where(x => x is FileHandlerAttribute))
         {
             if (path.ToLower().EndsWith(attrib.Extension))
             {
                 var obj = (IFileHandler)Activator.CreateInstance(type);
                 obj.OpenFile(path);
             }
         }
     }
 }
Пример #6
0
        private static void delegateToServer(ServerMessage msg)
        {
            string[] split    = msg.GUID.Split('|');
            bool     finished = false;

            if (split[0] == SaveSystem.CurrentSave.SystemName)
            {
                foreach (var type in Array.FindAll(ReflectMan.Types, x => x.GetInterfaces().Contains(typeof(Server)) && Shiftorium.UpgradeAttributesUnlocked(x)))
                {
                    var attrib = type.GetCustomAttributes().FirstOrDefault(x => x is ServerAttribute) as ServerAttribute;
                    if (attrib != null)
                    {
                        if (split[1] == attrib.Port.ToString())
                        {
                            type.GetMethods(BindingFlags.Public | BindingFlags.Instance).FirstOrDefault(x => x.Name == "MessageReceived")?.Invoke(Activator.CreateInstance(type), null);
                            finished = true;
                        }
                    }
                }
            }
            if (finished == false)
            {
                Forward(split[2], "Error", $"{split[0]}:{split[1]}: connection refused");
            }
        }
Пример #7
0
        public static bool RunClient(string text, Dictionary <string, object> args)
        {
            latestCommmand = text;

            foreach (var asmExec in System.IO.Directory.GetFiles(Environment.CurrentDirectory))
            {
                try
                {
                    var asm = Assembly.LoadFile(asmExec);

                    var types = asm.GetTypes();

                    foreach (var type in types)
                    {
                        if (Shiftorium.UpgradeAttributesUnlocked(type))
                        {
                            foreach (var a in type.GetCustomAttributes(false))
                            {
                                if (a is Namespace)
                                {
                                    var ns = a as Namespace;
                                    if (text.Split('.')[0] == ns.name)
                                    {
                                        foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static))
                                        {
                                            if (Shiftorium.UpgradeAttributesUnlocked(method))
                                            {
                                                foreach (var ma in method.GetCustomAttributes(false))
                                                {
                                                    if (ma is Command)
                                                    {
                                                        var cmd = ma as Command;
                                                        if (text.Split('.')[1] == cmd.name)
                                                        {
                                                            var attr = method.GetCustomAttribute <CommandObsolete>();

                                                            if (attr != null)
                                                            {
                                                                string newcommand = attr.newcommand;
                                                                if (attr.warn)
                                                                {
                                                                    Console.WriteLine(Localization.Parse((newcommand == "" ? "{ERROR}" : "{WARN}") + attr.reason, new Dictionary <string, string>()
                                                                    {
                                                                        { "%newcommand", newcommand }
                                                                    }));
                                                                }
                                                                if (newcommand != "")
                                                                {
                                                                    // redo the entire process running newcommand

                                                                    return(RunClient(newcommand, args));
                                                                }
                                                            }

                                                            var requiresArgs = method.GetCustomAttributes <RequiresArgument>();

                                                            bool error         = false;
                                                            bool providedusage = false;

                                                            foreach (RequiresArgument argument in requiresArgs)
                                                            {
                                                                if (!args.ContainsKey(argument.argument))
                                                                {
                                                                    if (!providedusage)
                                                                    {
                                                                        string usageparse = "{COMMAND_" + ns.name.ToUpper() + "_" + cmd.name.ToUpper() + "_USAGE}";
                                                                        if (usageparse == Localization.Parse(usageparse))
                                                                        {
                                                                            usageparse = "";
                                                                        }
                                                                        else
                                                                        {
                                                                            usageparse = Shiftorium.UpgradeInstalled("help_usage") ? Localization.Parse("{ERROR}{USAGE}" + usageparse, new Dictionary <string, string>()
                                                                            {
                                                                                { "%ns", ns.name },
                                                                                { "%cmd", cmd.name }
                                                                            }) : "";
                                                                        }

                                                                        Console.WriteLine(usageparse);

                                                                        providedusage = true;
                                                                    }

                                                                    if (Shiftorium.UpgradeInstalled("help_usage"))
                                                                    {
                                                                        Console.WriteLine(Localization.Parse("{ERROR_ARGUMENT_REQUIRED}", new Dictionary <string, string>()
                                                                        {
                                                                            { "%argument", argument.argument }
                                                                        }));
                                                                    }
                                                                    else
                                                                    {
                                                                        Console.WriteLine(Localization.Parse("{ERROR_ARGUMENT_REQUIRED_NO_USAGE}"));
                                                                    }

                                                                    error = true;
                                                                }
                                                            }

                                                            if (error)
                                                            {
                                                                throw new Exception("{ERROR_COMMAND_WRONG}");
                                                            }

                                                            try
                                                            {
                                                                return((bool)method.Invoke(null, new[] { args }));
                                                            }
                                                            catch
                                                            {
                                                                return((bool)method.Invoke(null, new object[] { }));
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch { }
            }
            return(false);
        }