Exemplo n.º 1
0
        public void ReopenItemsSavedInUserConfig()
        {
            string      tmp     = UserConfig.Get <string> ("OpenedItems");
            string      sel     = UserConfig.Get <string> ("SelectedProjItems");
            ProjectFile selItem = null;

            if (string.IsNullOrEmpty(tmp))
            {
                return;
            }
            foreach (string f in tmp.Split(';'))
            {
                foreach (Project p in Projects)
                {
                    ProjectFile pi;
                    if (p.TryGetProjectFileFromAbsolutePath(f, out pi))
                    {
                        OpenedItems.AddElement(pi);
                        pi.Project.IsExpanded = true;
                        ProjectNode pn = pi.Parent;
                        while (pn != null)
                        {
                            pn.IsExpanded = true;
                            pn            = pn.Parent;
                        }
                        if (pi.AbsolutePath == sel)
                        {
                            selItem = pi;
                        }
                        break;
                    }
                }
            }
            SelectedItem = selItem;            //BUG: loading in another thread focused last loaded pf
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
0
        /// <summary>
        /// The entry point of the program, where the program control starts and ends.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            Thread.Sleep(2000);
            AppDomain.CurrentDomain.UnhandledException += (o, a) =>
            {
                System.Diagnostics.Process.Start("ShiftOS.Server.exe");
                Environment.Exit(0);
            };
            UserConfig.Get();
            System.Timers.Timer tmr = new System.Timers.Timer(5000);
            tmr.Elapsed += (o, a) =>
            {
                if (server.IsOnline)
                {
                    try
                    {
                        server.DispatchAll(new NetObject("heartbeat", new ServerMessage
                        {
                            Name = "heartbeat",
                            GUID = "server"
                        }));
                    }
                    catch { }
                }
            };
            if (!Directory.Exists("saves"))
            {
                Directory.CreateDirectory("saves");
            }

            if (!Directory.Exists("scripts"))
            {
                Console.WriteLine("Creating scripts directory...");
                Directory.CreateDirectory("scripts");
                Console.WriteLine("NOTE: This MUD is not just gonna generate scripts for you. You're going to need to write them. YOU are DevX.");
            }

            Console.WriteLine("Starting server...");
            server = new NetObjectServer();

            server.OnStarted += (o, a) =>
            {
                Console.WriteLine($"Server started on address {server.Address}, port {server.Port}.");
                ServerStarted?.Invoke(server.Address.ToString());
                tmr.Start();
            };

            server.OnStopped += (o, a) =>
            {
                Console.WriteLine("WARNING! Server stopped.");
                tmr.Stop();
            };

            server.OnError += (o, a) =>
            {
                Console.WriteLine("ERROR: " + a.Exception.Message);
            };

            server.OnClientAccepted += (o, a) =>
            {
                Console.WriteLine("Client connected.");
                try
                {
                    server.DispatchTo(a.Guid, new NetObject("welcome", new ServerMessage {
                        Name = "Welcome", Contents = a.Guid.ToString(), GUID = "Server"
                    }));
                }
                catch
                {
                    Console.WriteLine("Oh, you don't have time to finish the handshake? Fine. Get off.");
                }
            };

            server.OnClientDisconnected += (o, a) =>
            {
                Console.WriteLine("Client disconnected.");
            };

            server.OnClientRejected += (o, a) =>
            {
                Console.WriteLine("F**K. Something HORRIBLE JUST HAPPENED.");
            };


            server.OnReceived += (o, a) =>
            {
                var obj = a.Data.Object;

                var msg = obj as ServerMessage;

                if (msg != null)
                {
                    Interpret(msg);
                }
            };

            IPAddress defaultAddress = null;

            var host = Dns.GetHostEntry(Dns.GetHostName());

            foreach (var ip in host.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    defaultAddress = ip;
                }
            }

            try
            {
                server.Start(defaultAddress, 13370);
            }
            catch
            {
                Console.WriteLine("So we tried to bind the server to your IP address automatically, but your operating system or the .NET environment you are in (possibly Mono on Linux) is preventing us from doing so. We'll try to bind to the loopback IP address (127.0.0.1) and if that doesn't work, the multi-user domain software may not be compatible with this OS or .NET environment.");
                server.Stop();
                server.Start(IPAddress.Loopback, 13370);
            }
            ClientDispatcher  = new Server.MudClientDispatcher(server);
            server.OnStopped += (o, a) =>
            {
                Console.WriteLine("Server stopping.");
            };

            /*
             * var task = ChatBackend.StartDiscordBots();
             * task.Wait();
             */


            while (server.IsOnline)
            {
                Console.Write("> ");
                string cmd = Console.ReadLine();
                try
                {
                    if (cmd.ToLower().StartsWith("decrypt "))
                    {
                        string username = cmd.Remove(0, 8);
                        if (File.Exists("saves/" + username + ".save"))
                        {
                            Console.WriteLine(ReadEncFile("saves/" + username + ".save"));
                        }
                        else
                        {
                            Console.WriteLine("Save not found.");
                        }
                    }
                    else if (cmd == "purge_all_bad_saves")
                    {
                        foreach (var f in Directory.GetFiles("saves"))
                        {
                            try
                            {
                                Console.WriteLine("Testing " + f + "...");
                                ReadEncFile(f);
                                Console.WriteLine("OK");
                            }
                            catch
                            {
                                Console.WriteLine("Not OK. Deleting.");
                                File.Delete(f);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }