Esempio n. 1
0
        public RegisterStatus Register(string uuid, string password, bool isGuest, out DbAccount acc)
        {
            acc = null;
            if (!Hashes.SetIfNotExists(0, "logins", uuid.ToUpperInvariant(), "{}").Exec())
            {
                return(RegisterStatus.UsedName);
            }

            int newAccId = (int)Strings.Increment(0, "nextAccId").Exec();

            acc = new DbAccount(this, newAccId.ToString())
            {
                UUID          = uuid,
                Name          = defaultNames[(uint)uuid.GetHashCode() % defaultNames.Length],
                Rank          = 0,
                Admin         = false,
                NameChosen    = false,
                Verified      = false,
                Converted     = false,
                GuildId       = "-1",
                GuildRank     = -1,
                VaultCount    = 1,
                MaxCharSlot   = 3,
                RegTime       = DateTime.Now,
                Guest         = true,
                Fame          = 0,
                TotalFame     = 0,
                Credits       = 1000,
                FortuneTokens = 0,
                Gifts         = new int[] { 0xae9 },
                PetYardType   = 1,
                IsAgeVerified = 1,
            };
            acc.Flush();

            var login = new DbLoginInfo(this, uuid);

            var x = new byte[0x10];

            gen.GetNonZeroBytes(x);
            string salt = Convert.ToBase64String(x);
            string hash = Convert.ToBase64String(Utils.SHA1(password + salt));

            login.HashedPassword = hash;
            login.Salt           = salt;
            login.AccountId      = acc.AccountId;
            login.Flush();

            var stats = new DbClassStats(acc);

            stats.Flush();

            var vault = new DbVault(acc);

            vault[0] = Enumerable.Repeat(-1, 8).ToArray();
            vault.Flush();

            return(RegisterStatus.OK);
        }
Esempio n. 2
0
        public void ChangePassword(string uuid, string password)
        {
            DbLoginInfo login = new DbLoginInfo(_db, uuid);

            byte[] x = new byte[0x10];
            gen.GetNonZeroBytes(x);
            string salt = Convert.ToBase64String(x);
            string hash = Convert.ToBase64String(Utils.SHA1(password + salt));

            login.HashedPassword = hash;
            login.Salt           = salt;
            login.Flush();
        }
Esempio n. 3
0
        public DbAccount GetAccount(string uuid)
        {
            DbLoginInfo info = new DbLoginInfo(_db, uuid);

            if (info.IsNull)
            {
                return(null);
            }
            DbAccount ret = new DbAccount(_db, info.AccountId);

            if (ret.IsNull)
            {
                return(null);
            }
            return(ret);
        }
Esempio n. 4
0
        public DbAccount GetAccountByUUID(string uuid)
        {
            var info = new DbLoginInfo(this, uuid);

            if (info.IsNull)
            {
                return(null);
            }
            var ret = new DbAccount(this, info.AccountId);

            if (ret.IsNull)
            {
                return(null);
            }
            return(ret);
        }
Esempio n. 5
0
        public LoginStatus Verify(string uuid, string password, out DbAccount acc)
        {
            acc = null;

            //check login
            var info = new DbLoginInfo(_db, uuid);

            if (info.IsNull)
            {
                return(LoginStatus.AccountNotExists);
            }

            byte[] userPass = Utils.SHA1(password + info.Salt);
            if (Convert.ToBase64String(userPass) != info.HashedPassword)
            {
                return(LoginStatus.InvalidCredentials);
            }

            acc = new DbAccount(_db, info.AccountId);

            // make sure account has all classes if they are supposed to
            var stats = new DbClassStats(acc);

            if (_resources.Settings.Accounts.ClassesUnlocked)
            {
                foreach (var @class in _resources.GameData.Classes.Keys)
                {
                    stats.Unlock(@class);
                }
            }
            stats.FlushAsync();

            // make sure account has all skins if they are supposed to
            if (_resources.Settings.Accounts.SkinsUnlocked)
            {
                acc.Skins = (from skin in _resources.GameData.Skins.Values
                             where !skin.NoSkinSelect
                             select skin.Type).ToArray();
            }

            return(LoginStatus.OK);
        }
Esempio n. 6
0
        public LoginStatus Verify(string uuid, string password, out DbAccount acc)
        {
            acc = null;
            var info = new DbLoginInfo(this, uuid);

            if (info.IsNull)
            {
                return(LoginStatus.AccountNotExists);
            }

            var userPass = Utils.SHA1(password + info.Salt);

            if (Convert.ToBase64String(userPass) != info.HashedPassword)
            {
                return(LoginStatus.InvalidCredentials);
            }

            acc = new DbAccount(this, info.AccountId);

            return(LoginStatus.OK);
        }
Esempio n. 7
0
        public RegisterStatus Register(string uuid, string password, bool isGuest, out DbAccount acc)
        {
            var newAccounts = _resources.Settings.NewAccounts;

            acc = null;
            if (!_db.HashSet("logins", uuid.ToUpperInvariant(), "{}", When.NotExists))
            {
                return(RegisterStatus.UsedName);
            }

            int newAccId = (int)_db.StringIncrement("nextAccId");

            acc = new DbAccount(_db, newAccId)
            {
                UUID           = uuid,
                Name           = GuestNames[(uint)uuid.GetHashCode() % GuestNames.Length],
                Admin          = false,
                NameChosen     = false,
                FirstDeath     = true,
                GuildId        = 0,
                GuildRank      = 0,
                VaultCount     = newAccounts.VaultCount,
                MaxCharSlot    = newAccounts.MaxCharSlot,
                RegTime        = DateTime.Now,
                Guest          = isGuest,
                Fame           = newAccounts.Fame,
                TotalFame      = newAccounts.Fame,
                Credits        = newAccounts.Credits,
                TotalCredits   = newAccounts.Credits,
                PassResetToken = "",
                LastSeen       = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds
            };

            if (newAccounts.SkinsUnlocked)
            {
                acc.Skins = (from skin in _resources.GameData.Skins.Values
                             select skin.Type).ToArray();
            }

            acc.FlushAsync();

            DbLoginInfo login = new DbLoginInfo(_db, uuid);

            byte[] x = new byte[0x10];
            gen.GetNonZeroBytes(x);
            string salt = Convert.ToBase64String(x);
            string hash = Convert.ToBase64String(Utils.SHA1(password + salt));

            login.HashedPassword = hash;
            login.Salt           = salt;
            login.AccountId      = acc.AccountId;
            login.Flush();

            DbClassStats stats = new DbClassStats(acc);

            if (newAccounts.ClassesUnlocked)
            {
                foreach (var @class in _resources.GameData.Classes.Keys)
                {
                    stats.Unlock(@class);
                }
            }
            stats.FlushAsync();

            return(RegisterStatus.OK);
        }
Esempio n. 8
0
        public RegisterStatus Register(string uuid, string password, bool isGuest, out DbAccount acc)
        {
            acc = null;
            if (!Hashes.SetIfNotExists(0, "logins", uuid.ToUpperInvariant(), "{}").Exec())
            {
                return(RegisterStatus.UsedName);
            }

            int newAccId = (int)Strings.Increment(0, "nextAccId").Exec();

            acc = new DbAccount(this, newAccId.ToString())
            {
                AccType           = AccountType.FREE_ACCOUNT,
                UUID              = uuid,
                Name              = defaultNames[(uint)uuid.GetHashCode() % defaultNames.Length],
                Rank              = 0,
                Admin             = false,
                NameChosen        = false,
                Verified          = Settings.STARTUP.VERIFIED,
                Converted         = false,
                GuildId           = "0",
                GuildRank         = 0,
                GuildFame         = 0,
                VaultCount        = 1,
                MaxCharSlot       = Settings.STARTUP.MAX_CHAR_SLOTS,
                RegTime           = DateTime.Now,
                Guest             = isGuest,
                Fame              = Settings.STARTUP.FAME,
                TotalFame         = Settings.STARTUP.TOTAL_FAME,
                Credits           = Settings.STARTUP.GOLD,
                FortuneTokens     = Settings.STARTUP.TOKENS,
                Gifts             = new int[] { },
                PetYardType       = 1,
                IsAgeVerified     = Settings.STARTUP.IS_AGE_VERIFIED,
                OwnedSkins        = new int[] { },
                PurchasedPackages = new int[] { },
                PurchasedBoxes    = new int[] { },
                AuthToken         = GenerateRandomString(128),
                Muted             = false,
                Banned            = false,
                Locked            = new int[] { 0 },
                Ignored           = new int[] { 0 }
            };
            acc.Flush();

            var login = new DbLoginInfo(this, uuid);

            var x = new byte[0x10];

            gen.GetNonZeroBytes(x);
            string salt = Convert.ToBase64String(x);
            string hash = Convert.ToBase64String(Utils.SHA1(password + salt));

            login.HashedPassword = hash;
            login.Salt           = salt;
            login.AccountId      = acc.AccountId;
            login.Flush();

            var stats = new DbClassStats(acc);

            stats.Flush();

            var vault = new DbVault(acc);

            vault[0] = Enumerable.Repeat(-1, 8).ToArray();
            vault.Flush();

            return(RegisterStatus.OK);
        }