Beispiel #1
0
        public bool SetGuildBoard(DbGuild guild, string text)
        {
            if (guild.IsNull)
            {
                return(false);
            }

            guild.Board = text;
            guild.FlushAsync();
            return(true);
        }
Beispiel #2
0
        public bool ChangeGuildLevel(DbGuild guild, int level)
        {
            // supported guild levels
            if (level != 1 &&
                level != 2 &&
                level != 3)
            {
                return(false);
            }

            guild.Level = level;
            guild.FlushAsync();
            return(true);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public GuildCreateStatus CreateGuild(string guildName, out DbGuild guild)
        {
            guild = null;

            if (String.IsNullOrWhiteSpace(guildName))
            {
                return(GuildCreateStatus.InvalidName);
            }

            // remove excessive whitespace
            var rgx = new Regex(@"\s+");

            guildName = rgx.Replace(guildName, " ");
            guildName = guildName.Trim();

            // check if valid
            rgx = new Regex(@"^[A-Za-z\s]{1,20}$");
            if (!rgx.IsMatch(guildName))
            {
                return(GuildCreateStatus.InvalidName);
            }

            // add guild to guild list
            var newGuildId = (int)_db.StringIncrement("nextGuildId");

            if (!_db.HashSet("guilds", guildName.ToUpperInvariant(), newGuildId, When.NotExists))
            {
                return(GuildCreateStatus.UsedName);
            }

            // create guild data structure
            guild = new DbGuild(_db, newGuildId)
            {
                Name      = guildName,
                Level     = 0,
                Fame      = 0,
                TotalFame = 0
            };

            // save
            guild.FlushAsync();

            return(GuildCreateStatus.OK);
        }