示例#1
0
        public bool RemoveFromGuild(DbAccount acc)
        {
            var guild = GetGuild(acc.GuildId);

            if (guild == null)
            {
                return(false);
            }

            List <int> members;

            using (TimedLock.Lock(guild.MemberLock))
            {
                members = guild.Members.ToList();
                if (members.Contains(acc.AccountId))
                {
                    members.Remove(acc.AccountId);
                    guild.Members = members.ToArray();
                    guild.FlushAsync();
                }
            }

            // remove guild name from guilds if there are no members
            if (members.Count <= 0)
            {
                _db.HashDeleteAsync("guilds", guild.Name.ToUpperInvariant(), CommandFlags.FireAndForget);
            }

            acc.GuildId   = 0;
            acc.GuildRank = 0;
            acc.GuildFame = 0;
            acc.FlushAsync();
            return(true);
        }
示例#2
0
        // Market
        public void RemovePlayerOffer(DbAccount acc, int id)
        {
            acc.Reload("marketOffers");

            var gList = acc.MarketOffers.ToList();

            gList.Remove(id);
            acc.MarketOffers = gList.ToArray();
            acc.FlushAsync();
        }
示例#3
0
        public void Ban(int accId, string reason = "", int liftTime = -1)
        {
            var acc = new DbAccount(_db, accId)
            {
                Banned      = true,
                Notes       = reason,
                BanLiftTime = liftTime
            };

            acc.FlushAsync();
        }
示例#4
0
        public void AddGifts(DbAccount acc, IEnumerable <ushort> items)
        {
            acc.Reload("gifts");

            var gList = acc.Gifts.ToList();

            gList.AddRange(items);

            acc.Gifts = gList.ToArray();
            acc.FlushAsync();
        }
示例#5
0
        public void AddPlayerOffers(DbAccount acc, IEnumerable <int> ids)
        {
            acc.Reload("marketOffers");

            var gList = acc.MarketOffers.ToList();

            gList.AddRange(ids);

            acc.MarketOffers = gList.ToArray();
            acc.FlushAsync();
        }
示例#6
0
        public bool ChangeGuildRank(DbAccount acc, int rank)
        {
            if (acc.GuildId <= 0 || !(new Int16[] { 0, 10, 20, 30, 40 }).Any(r => r == rank))
            {
                return(false);
            }

            acc.GuildRank = rank;
            acc.FlushAsync();
            return(true);
        }
示例#7
0
        public bool UnBan(int accId)
        {
            var acc = new DbAccount(_db, accId);

            if (acc.Banned)
            {
                acc.Banned = false;
                acc.FlushAsync();
                return(true);
            }

            return(false);
        }
示例#8
0
        public AddGuildMemberStatus AddGuildMember(DbGuild guild, DbAccount acc, bool founder = false)
        {
            if (acc == null)
            {
                return(AddGuildMemberStatus.Error);
            }

            if (acc.NameChosen == false)
            {
                return(AddGuildMemberStatus.NameNotChosen);
            }

            if (acc.GuildId == guild.Id)
            {
                return(AddGuildMemberStatus.AlreadyInGuild);
            }

            if (acc.GuildId > 0)
            {
                return(AddGuildMemberStatus.InAnotherGuild);
            }

            using (TimedLock.Lock(guild.MemberLock))
            {
                int guildSize = 50;
                // probably not best to lock this up but should be ok
                if (guild.Members.Length >= guildSize)
                {
                    return(AddGuildMemberStatus.GuildFull);
                }

                var members = guild.Members.ToList();
                if (members.Contains(acc.AccountId))
                {
                    return(AddGuildMemberStatus.IsAMember); // this should not happen...
                }
                members.Add(acc.AccountId);
                guild.Members = members.ToArray();
                guild.FlushAsync();
            }

            // set account guild info
            acc.GuildId   = guild.Id;
            acc.GuildRank = (founder) ? 40 : 0;
            acc.FlushAsync();

            return(AddGuildMemberStatus.OK);
        }
示例#9
0
        public bool UnnameIGN(DbAccount acc, string lockToken)
        {
            var trans = _db.CreateTransaction();

            trans.AddCondition(Condition.StringEqual(NAME_LOCK, lockToken));
            trans.HashDeleteAsync("names", acc.Name.ToUpperInvariant());
            if (!trans.Execute())
            {
                return(false);
            }

            acc.Name       = GuestNames[acc.AccountId % GuestNames.Length];
            acc.NameChosen = false;
            acc.FlushAsync();
            return(true);
        }
示例#10
0
        public void PurchaseSkin(DbAccount acc, ushort skinType, int cost)
        {
            if (cost > 0)
            {
                acc.TotalCredits = (int)_db.HashIncrement(acc.Key, "totalCredits", cost);
            }
            acc.Credits = (int)_db.HashIncrement(acc.Key, "credits", cost);

            // not thread safe
            var ownedSkins = acc.Skins.ToList();

            ownedSkins.Add(skinType);
            acc.Skins = ownedSkins.ToArray();

            acc.FlushAsync();
        }
示例#11
0
        public bool RenameIGN(DbAccount acc, string newName, string lockToken)
        {
            var trans = _db.CreateTransaction();

            trans.AddCondition(Condition.StringEqual(NAME_LOCK, lockToken));
            trans.HashDeleteAsync("names", acc.Name.ToUpperInvariant());
            trans.HashSetAsync("names", newName.ToUpperInvariant(), acc.AccountId.ToString());
            if (!trans.Execute())
            {
                return(false);
            }

            acc.Name       = newName;
            acc.NameChosen = true;
            acc.FlushAsync();
            return(true);
        }
示例#12
0
        public bool RenameUUID(DbAccount acc, string newUuid, string lockToken)
        {
            string p     = _db.HashGet("logins", acc.UUID.ToUpperInvariant());
            var    trans = _db.CreateTransaction();

            trans.AddCondition(Condition.StringEqual(REG_LOCK, lockToken));
            trans.AddCondition(Condition.HashNotExists("logins", newUuid.ToUpperInvariant()));
            trans.HashDeleteAsync("logins", acc.UUID.ToUpperInvariant());
            trans.HashSetAsync("logins", newUuid.ToUpperInvariant(), p);
            if (!trans.Execute())
            {
                return(false);
            }

            acc.UUID = newUuid;
            acc.FlushAsync();
            return(true);
        }
示例#13
0
        public void IgnoreAccount(DbAccount target, DbAccount acc, bool add)
        {
            var ignoreList = target.IgnoreList.ToList();

            if (ignoreList.Contains(acc.AccountId) && add)
            {
                return;
            }

            if (add)
            {
                ignoreList.Add(acc.AccountId);
            }
            else
            {
                ignoreList.Remove(acc.AccountId);
            }

            target.IgnoreList = ignoreList.ToArray();
            target.FlushAsync();
        }
示例#14
0
        public void LockAccount(DbAccount target, DbAccount acc, bool add)
        {
            var lockList = target.LockList.ToList();

            if (lockList.Contains(acc.AccountId) && add)
            {
                return;
            }

            if (add)
            {
                lockList.Add(acc.AccountId);
            }
            else
            {
                lockList.Remove(acc.AccountId);
            }

            target.LockList = lockList.ToArray();
            target.FlushAsync();
        }
示例#15
0
 public void ReloadAccount(DbAccount acc)
 {
     acc.FlushAsync();
     acc.Reload();
 }
示例#16
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);
        }
示例#17
0
 public void Guest(DbAccount acc, bool isGuest)
 {
     acc.Guest = isGuest;
     acc.FlushAsync();
 }
示例#18
0
 public void ChangeAgeVerified(DbAccount acc, bool verified)
 {
     acc.AgeVerified = true;
     acc.FlushAsync();
 }