コード例 #1
0
        internal override Object CreateRepositoryType(long id)
        {
            PlayerAccount acct = new PlayerAccount(id);

            acct.roles.Add(Modules.Roles.GetRole("player"));
            return(acct);
        }
コード例 #2
0
        internal void CmdRoles(GameObject invoker, CommandData cmd)
        {
            if (cmd.objTarget == null)
            {
                invoker.WriteLine("Who do you wish to view the roles of?", true);
                return;
            }

            PlayerAccount acct = Game.Accounts.FindAccount(cmd.objTarget);

            if (acct == null)
            {
                invoker.WriteLine($"Cannot find account for '{cmd.objTarget}'.", true);
                return;
            }

            string header = $"Roles for {acct.userName}";
            Dictionary <string, List <string> > roleDetails = new Dictionary <string, List <string> >();

            roleDetails.Add(header, new List <string>());

            int wrap = 80;

            if (invoker.HasComponent(Text.CompClient))
            {
                ClientComponent client = (ClientComponent)invoker.GetComponent(Text.CompClient);
                wrap = client.client.config.wrapwidth;
            }

            foreach (GameRole role in acct.roles)
            {
                roleDetails[header].Add(Text.FormatPopup(role.name, role.GetSummary(), wrap + Text.NestedWrapwidthModifier));
            }
            invoker.WriteLine(Text.FormatBlock(roleDetails, wrap), true);
        }
コード例 #3
0
        internal override void AddCommandParameters(SQLiteCommand command, Object instance)
        {
            PlayerAccount acct = (PlayerAccount)instance;

            command.Parameters.AddWithValue("@p0", acct.id);
            command.Parameters.AddWithValue("@p1", acct.userName);
            command.Parameters.AddWithValue("@p2", acct.passwordHash);
            command.Parameters.AddWithValue("@p3", acct.objectId);
            List <string> roleKeys = new List <string>();

            foreach (GameRole role in acct.roles)
            {
                roleKeys.Add(role.name);
            }
            command.Parameters.AddWithValue("@p4", JsonConvert.SerializeObject(roleKeys));
        }
コード例 #4
0
        internal override void InstantiateFromRecord(SQLiteDataReader reader, SQLiteConnection dbConnection)
        {
            PlayerAccount acct = (PlayerAccount)CreateRepositoryType((long)reader["id"]);

            acct.userName     = reader["userName"].ToString();
            acct.passwordHash = reader["passwordHash"].ToString();
            acct.objectId     = (long)reader["objectId"];
            foreach (string role in JsonConvert.DeserializeObject <List <string> >(reader["roles"].ToString()))
            {
                GameRole foundRole = Modules.Roles.GetRole(role);
                if (foundRole != null && !acct.roles.Contains(foundRole))
                {
                    acct.roles.Add(foundRole);
                }
            }
            accounts.Add(acct.userName, acct);
            contents.Add(acct.id, acct);
        }
コード例 #5
0
        internal PlayerAccount CreateAccount(string userName, string passwordHash)
        {
            // Create the new, blank account.
            PlayerAccount acct = (PlayerAccount)CreateNewInstance(GetUnusedIndex(), false);

            acct.userName     = userName;
            acct.passwordHash = passwordHash;

            // Create the shell the client will be piloting around, saving data to, etc.
            GameObject gameObj = Modules.Templates.Instantiate("mob");

            gameObj.name    = Text.Capitalize(acct.userName);
            gameObj.gender  = Modules.Gender.GetByTerm(Text.GenderPlural);
            gameObj.aliases = new List <string>()
            {
                gameObj.name.ToLower()
            };
            VisibleComponent vis = (VisibleComponent)gameObj.GetComponent(Text.CompVisible);

            vis.SetValue(Text.FieldShortDesc, $"{gameObj.name}");
            vis.SetValue(Text.FieldRoomDesc, $"{gameObj.name} is here.");
            vis.SetValue(Text.FieldExaminedDesc, "and are completely uninteresting.");
            MobileComponent mob = (MobileComponent)gameObj.GetComponent(Text.CompMobile);

            mob.SetValue(Text.FieldEnterMessage, $"{gameObj.name} enters from the $DIR.");
            mob.SetValue(Text.FieldLeaveMessage, $"{gameObj.name} leaves to the $DIR.");
            mob.SetValue(Text.FieldDeathMessage, $"The corpse of {gameObj.name} lies here.");
            Game.Objects.QueueForUpdate(gameObj);

            acct.objectId = gameObj.id;

            // If the account DB is empty, give them admin roles.
            if (accounts.Count <= 0)
            {
                Debug.WriteLine($"No accounts found, giving admin roles to {acct.userName}.");
                acct.roles.Add(Modules.Roles.GetRole("builder"));
                acct.roles.Add(Modules.Roles.GetRole("administrator"));
            }

            // Finalize everything.
            accounts.Add(acct.userName, acct);
            AddDatabaseEntry(acct);
            return(acct);
        }
コード例 #6
0
        internal void CmdAddrole(GameObject invoker, CommandData cmd)
        {
            if (cmd.objTarget == null)
            {
                invoker.WriteLine("Who do you wish to view the roles of?", true);
                return;
            }
            else if (cmd.strArgs.Length < 1)
            {
                invoker.WriteLine("Which role do you wish to add?", true);
                return;
            }

            PlayerAccount acct = Game.Accounts.FindAccount(cmd.objTarget);

            if (acct == null)
            {
                invoker.WriteLine($"Cannot find account for '{cmd.objTarget}'.", true);
                return;
            }

            GameRole role = Modules.Roles.GetRole(cmd.strArgs[0].ToLower());

            if (role == null)
            {
                invoker.WriteLine($"Cannot find role for '{cmd.strArgs[0]}'.");
            }
            else if (acct.roles.Contains(role))
            {
                invoker.WriteLine($"They already have that role.");
            }
            else
            {
                acct.roles.Add(role);
                Game.Accounts.QueueForUpdate(acct);
                invoker.WriteLine($"Added role '{role.name}' to '{acct.userName}'.");
            }
            invoker.SendPrompt();
        }
コード例 #7
0
        internal override bool TakeInput(GameClient invoker, string command, string rawCommand, string arguments)
        {
            if (command == "register")
            {
                string[] tokens = arguments.Split(" ");
                if (tokens.Length < 1)
                {
                    invoker.WriteLine($"Please supply a desired username when registering.");
                }
                else
                {
                    string newUser = tokens[0].ToLower();
                    if (Game.Accounts.GetAccountByUser(newUser) != null)
                    {
                        invoker.WriteLine($"An account already exists with that username.");
                    }
                    else if (!ValidateUsername(newUser))
                    {
                        invoker.WriteLine($"Usernames must be 2 to 16 characters long and can only contain letters.");
                    }
                    else
                    {
                        invoker.id = newUser;
                        loginState.Remove(invoker);
                        loginState.Add(invoker, "registering_entering_password");
                        invoker.WriteLine("Enter a new password of at least 6 characters, including at least one number or symbol. Remember that Telnet is not secure; do not reuse an important personal password.");
                    }
                }
            }
            else
            {
                switch (loginState[invoker])
                {
                case "connected":
                    PlayerAccount acct = Game.Accounts.GetAccountByUser(command);
                    if (acct == null)
                    {
                        invoker.WriteLine($"No account exists for '{command}'. Use {Colours.Fg("register [username]", Colours.BoldWhite)} to create one.");
                    }
                    else
                    {
                        invoker.account = acct;
                        invoker.WriteLine("Enter your password.");
                        loginState.Remove(invoker);
                        loginState.Add(invoker, "entering_password");
                    }
                    break;

                case "entering_password":
                    bool correctPass = invoker.account.CheckPassword(rawCommand);
                    if (correctPass)
                    {
                        invoker.WriteLine("Password correct.");
                        HandleLogin(invoker);
                    }
                    else
                    {
                        invoker.WriteLine("Incorrect password.");
                        invoker.account = null;
                        loginState.Remove(invoker);
                        loginState.Add(invoker, "connected");
                        ShowSplashScreen(invoker);
                    }
                    break;

                case "registering_entering_password":

                    if (!ValidatePassword(rawCommand))
                    {
                        invoker.WriteLine($"Passwords must be 6 to 30 characters long and must contain at least one symbol or number.");
                    }
                    else
                    {
                        passwordConfirmations.Remove(invoker);
                        passwordConfirmations.Add(invoker, rawCommand);
                        loginState.Remove(invoker);
                        loginState.Add(invoker, "registering_confirming_password");
                        invoker.WriteLine("Please reenter your password to confirm.");
                    }
                    break;

                case "registering_confirming_password":
                    if (passwordConfirmations.ContainsKey(invoker) && passwordConfirmations[invoker] == rawCommand)
                    {
                        invoker.account = Game.Accounts.CreateAccount(invoker.id, BCrypt.Net.BCrypt.HashPassword(passwordConfirmations[invoker], 10));
                        invoker.WriteLine("Account created.");
                        HandleLogin(invoker);
                    }
                    else
                    {
                        invoker.WriteLine("Passwords do not match.");
                        passwordConfirmations.Remove(invoker);
                        loginState.Remove(invoker);
                        loginState.Add(invoker, "connected");
                        ShowSplashScreen(invoker);
                    }
                    break;
                }
            }
            invoker.SendPrompt();
            return(true);
        }