예제 #1
0
        public static bool ListAll()
        {
            try {
                Dictionary <string, int> upgrades = new Dictionary <string, int>();
                int maxLength = 5;

                foreach (var upg in Shiftorium.GetAvailable())
                {
                    if (upg.ID.Length > maxLength)
                    {
                        maxLength = upg.ID.Length;
                    }

                    upgrades.Add(upg.ID, upg.Cost);
                }

                Console.WriteLine("ID".PadRight((maxLength + 5) - 2) + "Cost (Codepoints)");

                foreach (var upg in upgrades)
                {
                    Console.WriteLine(upg.Key.PadRight((maxLength + 5) - upg.Key.Length) + "  " + upg.Value.ToString());
                }
                return(true);
            } catch (Exception e) {
                CrashHandler.Start(e);
                return(false);
            }
        }
예제 #2
0
        public static void Main()
        {
            try
            {
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
                //Taxes: Remote Desktop Connection and painting
                //http://blogs.msdn.com/oldnewthing/archive/2006/01/03/508694.aspx
                Application.ThreadException += (o, a) =>
                {
                    CrashHandler.Start(a.Exception);
                };

                Application.ApplicationExit += (o, a) =>
                {
                    ServerManager.Disconnect();

                    //I really want a glass of juice.
                    //Process.GetCurrentProcess().Kill();
                };
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                //Application.Run(new Desktop());
            }
            catch (Exception ex)
            {
                CrashHandler.Start(ex);
            }
        }
예제 #3
0
 public static bool CrashInstantly()
 {
     try {
         throw new Exception("ShiftOS was sent a command to forcefully crash.");
     } catch (Exception e) {
         CrashHandler.Start(e);
         return(true);
     }
 }
예제 #4
0
        /// <summary>
        /// Start the entire ShiftOS engine.
        /// </summary>
        /// <param name="useDefaultUI">Whether ShiftOS should initiate it's Windows Forms front-end.</param>
        public static void Begin(bool useDefaultUI = true)
        {
            AppDomain.CurrentDomain.UnhandledException += (o, a) =>
            {
                CrashHandler.Start((Exception)a.ExceptionObject);
            };

            if (!System.IO.File.Exists(Paths.SaveFile))
            {
                var root = new ShiftOS.Objects.ShiftFS.Directory();
                root.Name        = "System";
                root.permissions = UserPermissions.Guest;
                System.IO.File.WriteAllText(Paths.SaveFile, JsonConvert.SerializeObject(root));
            }

            if (Utils.Mounts.Count == 0)
            {
                Utils.Mount(System.IO.File.ReadAllText(Paths.SaveFile));
            }
            Paths.Init();

            Localization.SetupTHETRUEDefaultLocals();
            SkinEngine.Init();
            Random rnd          = new Random();
            int    loadingJoke1 = rnd.Next(10);
            int    loadingJoke2 = rnd.Next(11);

            TerminalBackend.OpenTerminal();

            TerminalBackend.InStory = true;
            var thread = new Thread(new ThreadStart(() =>
            {
                //Do not uncomment until I sort out the copyright stuff... - Michael
                //AudioManager.Init();

                var defaultConf = new EngineConfig();
                if (System.IO.File.Exists("engineconfig.json"))
                {
                    defaultConf = JsonConvert.DeserializeObject <EngineConfig>(System.IO.File.ReadAllText("engineconfig.json"));
                }
                else
                {
                    System.IO.File.WriteAllText("engineconfig.json", JsonConvert.SerializeObject(defaultConf, Formatting.Indented));
                }

                Thread.Sleep(350);
                Console.WriteLine("{MISC_KERNELVERSION}");
                Thread.Sleep(50);
                Console.WriteLine("Copyright (c) 2018 DevX. Licensed under MIT.");
                Console.WriteLine("");
                Console.WriteLine("THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR");
                Console.WriteLine("IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,");
                Console.WriteLine("FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE");
                Console.WriteLine("AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER");
                Console.WriteLine("LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,");
                Console.WriteLine("OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE");
                Console.WriteLine("SOFTWARE.");
                Console.WriteLine("");
                Thread.Sleep(250);
                Console.WriteLine("{MISC_KERNELBOOTED}");
                Console.WriteLine("{MISC_SHIFTFSDRV}");
                Thread.Sleep(350);
                Console.WriteLine("{MISC_SHIFTFSBLOCKSREAD}");
                Console.WriteLine("{LOADINGMSG1_" + loadingJoke1 + "}");
                Thread.Sleep(500);
                Console.WriteLine("{MISC_LOADINGCONFIG}");
                Thread.Sleep(30);
                Console.WriteLine("{MISC_BUILDINGCMDS}");
                TerminalBackend.PopulateTerminalCommands();

                if (IsSandbox == false)
                {
                    Console.WriteLine("{MISC_CONNECTINGTONETWORK}");

                    Ready.Reset();

                    if (PreDigitalSocietyConnection != null)
                    {
                        PreDigitalSocietyConnection?.Invoke();
                        Ready.WaitOne();
                    }

                    ServerManager.GUIDReceived += (str) =>
                    {
                        //Connection successful! Stop waiting!
                        Console.WriteLine("{MISC_CONNECTIONSUCCESSFUL}");
                        Thread.Sleep(100);
                        Console.WriteLine("{LOADINGMSG2_" + loadingJoke2 + "}");
                        Thread.Sleep(500);
                    };

                    try
                    {
                        if (ServerManager.ServerOnline)
                        {
                            ServerManager.Initiate(UserConfig.Get().DigitalSocietyAddress, UserConfig.Get().DigitalSocietyPort);
                            // This halts the client until the connection is successful.
                            ServerManager.guidReceiveARE.WaitOne();
                            Console.WriteLine("{MISC_DHCPHANDSHAKEFINISHED}");
                        }
                        else
                        {
                            Console.WriteLine("{MISC_NONETWORK}");
                            Console.WriteLine("{LOADINGMSG2_" + loadingJoke2 + "}");
                        }
                        FinishBootstrap();
                    }
                    catch (Exception ex)
                    {
                        // "No errors, this never gets called."
                        Console.WriteLine("[inetd] SEVERE: " + ex.Message);
                        string dest = "Startup Exception " + DateTime.Now.ToString().Replace("/", "-").Replace(":", "-") + ".txt";
                        System.IO.File.WriteAllText(dest, ex.ToString());
                        Console.WriteLine("[inetd] Full exception details have been saved to: " + dest);
                        Thread.Sleep(3000);
                        System.Diagnostics.Process.GetCurrentProcess().Kill();
                    }

                    //Nothing happens past this point - but the client IS connected! It shouldn't be stuck in that while loop above.
                }
                else
                {
                    Console.WriteLine("{MISC_SANDBOXMODE}");
                    CurrentSave = new Save
                    {
                        IsSandbox  = true,
                        Username   = "******",
                        Password   = "******",
                        SystemName = "shiftos",
                        Users      = new List <ClientSave>
                        {
                            new ClientSave
                            {
                                Username    = "******",
                                Password    = "",
                                Permissions = 0
                            }
                        },
                        Class                = 0,
                        ID                   = new Guid(),
                        Upgrades             = new Dictionary <string, bool>(),
                        CurrentLegions       = null,
                        IsMUDAdmin           = false,
                        IsPatreon            = false,
                        Language             = "english",
                        LastMonthPaid        = 0,
                        MajorVersion         = 1,
                        MinorVersion         = 0,
                        MusicEnabled         = false,
                        MusicVolume          = 100,
                        MyShop               = "",
                        PasswordHashed       = false,
                        PickupPoint          = "",
                        RawReputation        = 0.0f,
                        Revision             = 0,
                        ShiftnetSubscription = 0,
                        SoundEnabled         = true,
                        StoriesExperienced   = null,
                        StoryPosition        = 0,
                        UniteAuthToken       = "",
                    };

                    CurrentUser = CurrentSave.Users.First();

                    Localization.SetupTHETRUEDefaultLocals();

                    Shiftorium.Init();

                    TerminalBackend.InStory       = false;
                    TerminalBackend.PrefixEnabled = true;

                    Desktop.InvokeOnWorkerThread(new Action(() =>
                    {
                        ShiftOS.Engine.Scripting.LuaInterpreter.RunSft(Paths.GetPath("kernel.sft"));
                    }));


                    Desktop.InvokeOnWorkerThread(new Action(() => Desktop.PopulateAppLauncher()));
                    GameReady?.Invoke();
                }
            }));

            thread.IsBackground = true;
            thread.Start();
        }
예제 #5
0
        public static bool ListAll(Dictionary <string, object> args)
        {
            try
            {
                bool showOnlyInCategory = false;

                string cat = "Other";

                if (args.ContainsKey("cat"))
                {
                    showOnlyInCategory = true;
                    cat = args["cat"].ToString();
                }

                Dictionary <string, ulong> upgrades = new Dictionary <string, ulong>();
                int maxLength = 5;

                IEnumerable <ShiftoriumUpgrade> upglist = Shiftorium.GetAvailable();
                if (showOnlyInCategory)
                {
                    if (Shiftorium.IsCategoryEmptied(cat))
                    {
                        ConsoleEx.Bold            = true;
                        ConsoleEx.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("{SHFM_QUERYERROR}");
                        Console.WriteLine();
                        ConsoleEx.Bold            = false;
                        ConsoleEx.ForegroundColor = ConsoleColor.Gray;
                        Console.WriteLine("{ERR_EMPTYCATEGORY}");
                        return(true);
                    }
                    upglist = Shiftorium.GetAvailable().Where(x => x.Category == cat);
                }


                if (upglist.Count() == 0)
                {
                    ConsoleEx.Bold            = true;
                    ConsoleEx.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("{SHFM_NOUPGRADES}");
                    Console.WriteLine();
                    ConsoleEx.Bold            = false;
                    ConsoleEx.ForegroundColor = ConsoleColor.Gray;
                    Console.WriteLine("{ERR_NOMOREUPGRADES}");
                    return(true);
                }
                foreach (var upg in upglist)
                {
                    if (upg.ID.Length > maxLength)
                    {
                        maxLength = upg.ID.Length;
                    }

                    upgrades.Add(upg.ID, upg.Cost);
                }

                foreach (var upg in upgrades)
                {
                    Console.WriteLine(Localization.Parse("{SHFM_UPGRADE}", new Dictionary <string, string>
                    {
                        ["%id"]   = upg.Key,
                        ["%cost"] = upg.Value.ToString()
                    }));
                }
                return(true);
            }
            catch (Exception e)
            {
                CrashHandler.Start(e);
                return(false);
            }
        }