コード例 #1
0
            public virtual void Invoke(Dictionary <string, object> args)
            {
                List <string> errors       = new List <string>();
                bool          requiresAuth = false;

                if (!KernelWatchdog.IsSafe(this))
                {
                    if (SaveSystem.CurrentUser.Permissions == Objects.UserPermissions.Admin)
                    {
                        requiresAuth = true;
                    }
                    else
                    {
                        errors.Add("You can't run this command - you do not have permission.");
                    }
                }
                if (errors.Count > 0)
                {
                    foreach (var error in errors)
                    {
                        Console.WriteLine("Command error: " + error);
                    }
                    return;
                }
                if (requiresAuth)
                {
                    Infobox.PromptText("Enter your password.", "This command requires you to have elevated permissions. Please enter your password to confirm this action.", (pass) =>
                    {
                        if (pass == SaveSystem.CurrentUser.Password)
                        {
                            var uname = SaveSystem.CurrentUser.Username;
                            SaveSystem.CurrentUser = SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == "root");
                            try
                            {
                                var h = CommandHandler;
                                h.Invoke(null, new[] { args });
                            }
                            catch
                            {
                                var h = CommandHandler;
                                h.Invoke(null, null);
                            }
                            SaveSystem.CurrentUser = SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == uname);
                        }
                        else
                        {
                            Infobox.Show("Access denied.", "Incorrect password provided. The command will not run.");
                        }
                    }, true);
                }

                try
                {
                    CommandHandler.Invoke(null, new[] { args });
                }
                catch
                {
                    CommandHandler.Invoke(null, null);
                }
            }
コード例 #2
0
        /// <summary>
        /// Finish bootstrapping the engine.
        /// </summary>
        private static void FinishBootstrap()
        {
            ServerMessageReceived savehandshake = null;

            savehandshake = (msg) =>
            {
                if (msg.Name == "mud_savefile")
                {
                    ServerManager.MessageReceived -= savehandshake;
                    try
                    {
                        CurrentSave = JsonConvert.DeserializeObject <Save>(msg.Contents);
                    }
                    catch
                    {
                        Console.WriteLine("{ENGINE_CANNOTLOADSAVE}");
                        oobe.PromptForLogin();
                    }
                }
                else if (msg.Name == "mud_login_denied")
                {
                    ServerManager.MessageReceived -= savehandshake;
                    oobe.PromptForLogin();
                }
            };
            ServerManager.MessageReceived += savehandshake;


            ReadSave();

            while (CurrentSave == null)
            {
                Thread.Sleep(10);
            }

            Shiftorium.Init();

            while (CurrentSave.StoryPosition < 1)
            {
                Thread.Sleep(10);
            }

            Thread.Sleep(75);

            Thread.Sleep(50);
            Console.WriteLine("{MISC_ACCEPTINGLOGINS}");

Sysname:
            bool waitingForNewSysName = false;
            bool gobacktosysname = false;

            if (string.IsNullOrWhiteSpace(CurrentSave.SystemName))
            {
                Infobox.PromptText("{TITLE_ENTERSYSNAME}", "{PROMPT_ENTERSYSNAME}", (name) =>
                {
                    if (string.IsNullOrWhiteSpace(name))
                    {
                        Infobox.Show("{TITLE_INVALIDNAME}", "{PROMPT_INVALIDNAME}.", () =>
                        {
                            gobacktosysname      = true;
                            waitingForNewSysName = false;
                        });
                    }
                    else if (name.Length < 5)
                    {
                        Infobox.Show("{TITLE_VALUESMALL}", "{PROMPT_SMALLSYSNAME}", () =>
                        {
                            gobacktosysname      = true;
                            waitingForNewSysName = false;
                        });
                    }
                    else
                    {
                        CurrentSave.SystemName = name;
                        SaveSystem.SaveGame();
                        gobacktosysname      = false;
                        waitingForNewSysName = false;
                    }
                });
            }

            while (waitingForNewSysName)
            {
                Thread.Sleep(10);
            }

            if (gobacktosysname)
            {
                goto Sysname;
            }

            if (CurrentSave.Users == null)
            {
                CurrentSave.Users = new List <ClientSave>();
            }

            Console.WriteLine($@"
                   `-:/++++::.`                   
              .+ydNMMMMMNNMMMMMNhs/.              
           /yNMMmy+:-` `````.-/ohNMMms-           
        `oNMMh/.`:oydmNMMMMNmhs+- .+dMMm+`             {{GEN_WELCOME}}
      `oMMmo``+dMMMMMMMMMMMMMMMMMNh/`.sNMN+       
     :NMN+ -yMMMMMMMNdhyssyyhdmNMMMMNs``sMMd.          {{GEN_SYSTEMSTATUS}}
    oMMd.`sMMMMMMd+.            `/MMMMN+ -mMN:         ----------------------
   oMMh .mMMMMMM/     `-::::-.`  :MMMMMMh`.mMM:   
  :MMd .NMMMMMMs    .dMMMMMMMMMNddMMMMMMMd`.NMN.        {{GEN_CODEPOINTS}}:     {SaveSystem.CurrentSave.Codepoints}
  mMM. dMMMMMMMo    -mMMMMMMMMMMMMMMMMMMMMs /MMy        
 :MMh :MMMMMMMMm`     .+shmMMMMMMMMMMMMMMMN` NMN`                       
 oMM+ sMMMMMMMMMN+`        `-/smMMMMMMMMMMM: hMM:       
 sMM+ sMMMMMMMMMMMMds/-`        .sMMMMMMMMM/ yMM/ 
 +MMs +MMMMMMMMMMMMMMMMMmhs:`     +MMMMMMMM- dMM-       {{GEN_SYSTEMNAME}}:    {CurrentSave.SystemName.ToUpper()}
 .MMm `NMMMMMMMMMMMMMMMMMMMMMo    `NMMMMMMd .MMN        {{GEN_USERS}}:          {Users.Count()}.
  hMM+ +MMMMMMmsdNMMMMMMMMMMN/    -MMMMMMN- yMM+        
  `NMN- oMMMMMd   `-/+osso+-     .mMMMMMN: +MMd   
   -NMN: /NMMMm`               :yMMMMMMm- oMMd`   
    -mMMs``sMMMMNdhso++///+oydNMMMMMMNo .hMMh`    
     `yMMm/ .omMMMMMMMMMMMMMMMMMMMMd+``oNMNo      
       -hMMNo. -ohNMMMMMMMMMMMMmy+. -yNMNy`       
         .sNMMms/. `-/+++++/:-` ./yNMMmo`         
            :sdMMMNdyso+++ooshdNMMMdo-            
               `:+yhmNNMMMMNNdhs+-                
                       ````                       ");

            if (CurrentSave.Users.Count == 0)
            {
                CurrentSave.Users.Add(new ClientSave
                {
                    Username    = "******",
                    Password    = "",
                    Permissions = UserPermissions.Root
                });
                Console.WriteLine("{MISC_NOUSERS}");
            }
            TerminalBackend.InStory = false;

            TerminalBackend.PrefixEnabled = false;

            if (LoginManager.ShouldUseGUILogin)
            {
                Action <ClientSave> Completed = null;
                Completed += (user) =>
                {
                    CurrentUser = user;
                    LoginManager.LoginComplete -= Completed;
                };
                LoginManager.LoginComplete += Completed;
                Desktop.InvokeOnWorkerThread(() =>
                {
                    LoginManager.PromptForLogin();
                });
                while (CurrentUser == null)
                {
                    Thread.Sleep(10);
                }
            }
            else
            {
Login:
                string username = "";
                int  progress           = 0;
                bool goback             = false;
                TextSentEventHandler ev = null;
                string loginstr         = Localization.Parse("{GEN_LPROMPT}", new Dictionary <string, string>
                {
                    ["%sysname"] = CurrentSave.SystemName
                });
                ev = (text) =>
                {
                    if (progress == 0)
                    {
                        string getuser = text.Remove(0, loginstr.Length);
                        if (!string.IsNullOrWhiteSpace(getuser))
                        {
                            if (CurrentSave.Users.FirstOrDefault(x => x.Username == getuser) == null)
                            {
                                Console.WriteLine();
                                Console.WriteLine("{ERR_NOUSER}");
                                goback = true;
                                progress++;
                                TerminalBackend.TextSent -= ev;
                                return;
                            }
                            username = getuser;
                            progress++;
                        }
                        else
                        {
                            Console.WriteLine();
                            Console.WriteLine("{ERR_NOUSER}");
                            TerminalBackend.TextSent -= ev;
                            goback = true;
                            progress++;
                        }
                    }
                    else if (progress == 1)
                    {
                        string passwordstr = Localization.Parse("{GEN_PASSWORD}: ");
                        string getpass     = text.Remove(0, passwordstr.Length);
                        var    user        = CurrentSave.Users.FirstOrDefault(x => x.Username == username);
                        if (user.Password == getpass)
                        {
                            Console.WriteLine();
                            Console.WriteLine("{GEN_WELCOME}");
                            CurrentUser = user;
                            progress++;
                        }
                        else
                        {
                            Console.WriteLine();
                            Console.WriteLine("{RES_DENIED}");
                            goback = true;
                            progress++;
                        }
                        TerminalBackend.TextSent -= ev;
                    }
                };
                TerminalBackend.TextSent += ev;
                Console.WriteLine();
                Console.Write(loginstr);
                ConsoleEx.Flush();
                while (progress == 0)
                {
                    Thread.Sleep(10);
                }
                if (goback)
                {
                    goto Login;
                }
                Console.WriteLine();
                Console.Write("{GEN_PASSWORD}: ");
                ConsoleEx.Flush();
                while (progress == 1)
                {
                    Thread.Sleep(10);
                }
                if (goback)
                {
                    goto Login;
                }
            }
            TerminalBackend.PrefixEnabled  = true;
            Shiftorium.LogOrphanedUpgrades = true;
            Desktop.InvokeOnWorkerThread(new Action(() =>
            {
                ShiftOS.Engine.Scripting.LuaInterpreter.RunSft(Paths.GetPath("kernel.sft"));
            }));


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

            if (!string.IsNullOrWhiteSpace(CurrentSave.PickupPoint))
            {
                try
                {
                    if (Story.Context == null)
                    {
                        Story.Start(CurrentSave.PickupPoint);
                    }
                }
                catch { }
            }
        }