public static bool RemoveUser(Dictionary <string, object> args)
        {
            string name = args["name"].ToString();

            if (SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == name) == null)
            {
                Console.WriteLine("{ERR_NOUSER}");
                return(true);
            }

            var user = SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == name);

            if (user.Username != SaveSystem.CurrentUser.Username)
            {
                Console.WriteLine("{ERR_REMOVEYOU}");
                return(true);
            }
            SaveSystem.CurrentSave.Users.Remove(user);
            Console.WriteLine(Localization.Parse("{RES_REMOVINGUSER}", new Dictionary <string, string>
            {
                ["%name"] = name
            }));
            SaveSystem.SaveGame();
            return(true);
        }
        public static bool AddUser(Dictionary <string, object> args)
        {
            string name = args["name"].ToString();

            if (SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == name) != null)
            {
                Console.WriteLine("{ERR_USERFOUND}");
                return(true);
            }

            var user = new ClientSave
            {
                Username    = name,
                Password    = "",
                Permissions = UserPermissions.User
            };

            SaveSystem.CurrentSave.Users.Add(user);
            Console.WriteLine(Localization.Parse("{RES_CREATINGUSER}", new Dictionary <string, string>
            {
                { "%name", name }
            }));
            SaveSystem.SaveGame();
            return(true);
        }
Esempio n. 3
0
 public static bool SetMusicEnabled(Dictionary <string, object> args)
 {
     try
     {
         bool value = Convert.ToBoolean(args["value"].ToString());
         SaveSystem.CurrentSave.MusicEnabled = value;
         SaveSystem.SaveGame();
     }
     catch
     {
         Console.WriteLine("{ERR_BADBOOL}");
     }
     return(true);
 }
Esempio n. 4
0
        public static bool SetSfxVolume(Dictionary <string, object> args)
        {
            int value = int.Parse(args["value"].ToString());

            if (value >= 0 && value <= 100)
            {
                SaveSystem.CurrentSave.MusicVolume = value;
                SaveSystem.SaveGame();
            }
            else
            {
                Console.WriteLine("{ERR_BADPERCENT}");
            }
            return(true);
        }
        public static bool SetPassword(Dictionary <string, object> args)
        {
            string old     = args["old"].ToString();
            string newpass = args["new"].ToString();

            if (old == SaveSystem.CurrentUser.Password)
            {
                SaveSystem.CurrentUser.Password = newpass;
                SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == SaveSystem.CurrentUser.Username).Password = newpass;
                Console.WriteLine("{RES_PASSWD_SET}");
                SaveSystem.SaveGame();
            }
            else
            {
                Console.WriteLine("{ERR_PASSWD_MISMATCH}");
            }
            return(true);
        }
Esempio n. 6
0
        public static bool SetLanguage(Dictionary <string, object> userArgs)
        {
            try
            {
                string lang = "";

                lang = (string)userArgs["language"];

                if (Localization.GetAllLanguages().Contains(lang))
                {
                    SaveSystem.CurrentSave.Language = lang;
                    SaveSystem.SaveGame();
                    Console.WriteLine("{RES_LANGUAGE_CHANGED}");
                    return(true);
                }

                throw new Exception("{ERR_NOLANG}");
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 7
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 { }
            }
        }
Esempio n. 8
0
 public static bool Save()
 {
     SaveSystem.SaveGame();
     return(true);
 }
Esempio n. 9
0
 public static bool Shutdown()
 {
     SaveSystem.SaveGame();
     AppearanceManager.Exit();
     return(true);
 }
Esempio n. 10
0
        /// <summary>
        /// Initiate a new Digital Society connection.
        /// </summary>
        /// <param name="mud_address">The IP address or hostname of the target server</param>
        /// <param name="port">The target port.</param>
        public static void Initiate(string mud_address, int port)
        {
            client = new NetObjectClient();
            client.OnDisconnected += (o, a) =>
            {
                if (!UserDisconnect)
                {
                    Desktop.PushNotification("digital_society_connection", "Disconnected from Digital Society.", "The ShiftOS kernel has been disconnected from the Digital Society. We are attempting to re-connect you.");
                    TerminalBackend.PrefixEnabled = true;
                    ConsoleEx.ForegroundColor     = ConsoleColor.Red;
                    ConsoleEx.Bold = true;
                    Console.Write($@"Disconnected from MUD: ");
                    ConsoleEx.Bold            = false;
                    ConsoleEx.Italic          = true;
                    ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine("You have been disconnected from the multi-user domain for an unknown reason. Your save data is preserved within the kernel and you will be reconnected shortly.");
                    TerminalBackend.PrefixEnabled = true;
                    TerminalBackend.PrintPrompt();
                    Initiate(mud_address, port);
                }
            };
            client.OnReceived += (o, a) =>
            {
                if (PingTimer.IsRunning)
                {
                    DigitalSocietyPing = PingTimer.ElapsedMilliseconds;
                    PingTimer.Reset();
                }
                var msg = a.Data.Object as ServerMessage;
                if (msg.Name == "Welcome")
                {
                    thisGuid = new Guid(msg.Contents);
                    GUIDReceived?.Invoke(msg.Contents);
                    guidReceiveARE.Set();
                    TerminalBackend.PrefixEnabled = true;
                    TerminalBackend.PrintPrompt();
                }
                else if (msg.Name == "allusers")
                {
                    foreach (var acc in JsonConvert.DeserializeObject <string[]>(msg.Contents))
                    {
                        Console.WriteLine(acc);
                    }
                    TerminalBackend.PrintPrompt();
                }
                else if (msg.Name == "update_your_cp")
                {
                    var args = JsonConvert.DeserializeObject <Dictionary <string, object> >(msg.Contents);
                    if (args["username"] as string == SaveSystem.CurrentUser.Username)
                    {
                        SaveSystem.CurrentSave.Codepoints += (ulong)args["amount"];
                        Desktop.InvokeOnWorkerThread(new Action(() =>
                        {
                            Infobox.Show($"MUD Control Centre", $"Someone bought an item in your shop, and they have paid {args["amount"]}, and as such, you have been granted these Codepoints.");
                        }));
                        SaveSystem.SaveGame();
                    }
                }
                else if (msg.Name == "broadcast")
                {
                    Console.WriteLine(msg.Contents);
                }
                else if (msg.Name == "forward")
                {
                    MessageReceived?.Invoke(JsonConvert.DeserializeObject <ServerMessage>(msg.Contents));
                }
                else if (msg.Name == "Error")
                {
                    var ex = JsonConvert.DeserializeObject <Exception>(msg.Contents);
                    TerminalBackend.PrefixEnabled = true;
                    ConsoleEx.ForegroundColor     = ConsoleColor.Red;
                    ConsoleEx.Bold = true;
                    Console.Write($@"{{MUD_ERROR}}: ");
                    ConsoleEx.Bold            = false;
                    ConsoleEx.Italic          = true;
                    ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine(ex.Message);
                    TerminalBackend.PrefixEnabled = true;
                    TerminalBackend.PrintPrompt();
                }
                else
                {
                    MessageReceived?.Invoke(msg);
                }
            };

            try
            {
                client.Connect(mud_address, port);
            }
            catch (SocketException ex)
            {
                System.Diagnostics.Debug.Print(ex.ToString());
                Initiate(mud_address, port);
            }
        }