Example #1
0
        public bool AddGuildRank(Guild g, GuildMemberRank gmr)
        {
            string SQL = "INSERT INTO guild_ranks "
            + "(gid, rankprivileges, rankname) "
            + "VALUES(?gid, ?rankpriv, ?rankname);";

            // Are we GM
            if (gmr.RankName == "GuildMaster")
                gmr.RankPrivileges = 7;
            else
                gmr.RankPrivileges = 0;

            MySqlCommand cmd = new MySqlCommand(SQL, GuildDAOConnection);
            cmd.Parameters.AddWithValue("?gid", g.GuildId);
            cmd.Parameters.AddWithValue("?rankpriv", gmr.RankPrivileges);
            cmd.Parameters.AddWithValue("?rankname", gmr.RankName);

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                Log.ErrorException("DAO: Guild Rank Add Error!", e);
                return false;
            }
            return true;
        }
Example #2
0
 public void AddCharacterToGuild(Player player, Guild guild)
 {
     string SQL = "UPDATE guilds SET guildmembers = ?player WHERE guildname = ?gname";
     MySqlCommand cmd = new MySqlCommand(SQL, GuildDAOConnection);
     cmd.Parameters.AddWithValue("?player", player);
     cmd.Parameters.AddWithValue("?gname", guild.GuildName);
 }
Example #3
0
        public void AddMemberToGuild(Player player, Guild guild, Player inviter = null)
        {
            if (guild == null || player == null)
                return;

            if(guild.GuildMembers != null && guild.GuildMembers.Count > 30)
                return;

            lock (guild.MembersLock)
            {
                if (guild.GuildMembers == null || guild.GuildMembers.Count == 0)
                    guild.GuildMembers = new Dictionary<Player, int> {{player, 1}};
                else
                    guild.GuildMembers.Add(player, 2);
            }

            AddHistoryEvent(guild,
                            new HistoryEvent
                                {
                                    Args = GuildHistoryStrings.UserXInvitedUserY(player.PlayerData.Name)
                                        /* TODO:
                                         * inviter != null
                                            ? GuildHistoryStrings.UserXInvitedUserY(player.PlayerData.Name)
                                            : GuildHistoryStrings.GuildCreate(player.PlayerData.Name)*/
                                });

            player.Guild = guild;

            Communication.Global.VisibleService.Send(player,
                                                     new SpCharacterGuildInfo(player, guild.GuildName, "Recruit"));

            Communication.Global.RelationService.ResendRelation(player);
        }
Example #4
0
        public void AddHistoryEvent(Guild guild, HistoryEvent hEvent, Player initiator = null)
        {
            if(guild == null)
                return;

            hEvent.Date = Funcs.GetRoundedUtc();

            guild.GuildHistory.Add(hEvent);

            //TODO update
        }
Example #5
0
 private Player GetPlayerById(Guild guild, int playerId)
 {
     return guild.GuildMembers.FirstOrDefault(pl => pl.Key.PlayerId == playerId).Key;
 }
Example #6
0
        private void AddNewRank(Guild guild, GuildMemberRank rank)
        {
            if(guild == null)
                return;

            if (rank.RankName == "Guildmaster")
                rank.RankPrivileges = 7;

            guild.GuildRanks.Add(rank);

            AddHistoryEvent(guild, new HistoryEvent {Args = GuildHistoryStrings.AddNewRank(rank.RankName)});

            UpdateGuild(guild);
        }
Example #7
0
        public void UpdateGuild(Guild guild)
        {
            if(guild == null)
                return;

            if(guild.GuildMembers == null)
                return;

            lock (guild.MembersLock)
            {
                foreach (var member in guild.GuildMembers)
                {
                    if(Communication.Global.PlayerService.IsPlayerOnline(member.Key))
                    {
                        new SpGuildRanking(member.Key).Send(member.Key);
                        new SpGuildMemberList(guild).Send(member.Key);
                    }
                }
            }
        }
Example #8
0
 public void SendPacketToGuildMembers(ISendPacket packet, Guild guild, Player sender = null)
 {
     lock (guild.MembersLock)
         foreach (
             KeyValuePair<Player, int> guildMember in
                 guild.GuildMembers.Where(
                     guildMember => Communication.Global.PlayerService.IsPlayerOnline(guildMember.Key) && !guildMember.Key.Equals(sender)))
             packet.Send(guildMember.Key.Connection);
 }
Example #9
0
        public void RemoveMember(Player player, Guild guild)
        {
            if(guild == null)
                return;

            lock (guild.MembersLock)
            {
                guild.GuildMembers.Remove(player);
                player.Guild = null;
            }

            if(Communication.Global.PlayerService.IsPlayerOnline(player))
                new SpGuildMemberList().Send(player);

            SystemMessages.YouLeftTheGuild(guild.GuildName).Send(player.Connection);

            if (GetLeader(guild).Equals(player) || guild.GuildMembers.Count <= 1)
            {
                DisbandGuild(GetLeader(guild), guild);
                return;
            }

            SendPacketToGuildMembers(SystemMessages.PlayerHasBeenRemovedFromTheGuild(player.PlayerData.Name), guild);

            UpdateGuild(guild);

            Communication.Global.RelationService.ResendRelation(player);
        }
Example #10
0
 public SpGuildHistory(Guild guild)
 {
     Guild = guild;
 }
Example #11
0
        public void DisbandGuild(Player initiator, Guild guild)
        {
            if(!GetLeader(guild).Equals(initiator))
                return;

            SendPacketToGuildMembers(SystemMessages.TheGuildHasBeenDisbanded(guild.GuildName), guild);

            lock (guild.MembersLock)
            {
                foreach (KeyValuePair<Player, int> guildMember in guild.GuildMembers)
                {
                    guildMember.Key.Guild = null;
                    SendGuildToPlayer(guildMember.Key);
                }
            }

            guild.GuildMembers = null;

            lock (GuildsLock)
                Cache.Guilds.Remove(guild.GuildId);

            if (Cache.UsedGuildNames.Contains(guild.GuildName.ToLower()))
                Cache.UsedGuildNames.Remove(guild.GuildName.ToLower());
        }
Example #12
0
        public void CreateNewRank(Guild guild, string rankName)
        {
            if(guild == null)
                return;

            if(guild.GuildRanks.Count >= 10)
                return;

            if(guild.GuildRanks.FirstOrDefault(rank => rank.RankName.ToLower() == rankName.ToLower()) != null)
                return;

            AddNewRank(guild,
                       new GuildMemberRank
                           {
                               RankId = guild.GuildRanks.Last().RankId + 1,
                               RankName = rankName,
                               RankPrivileges = 0
                           });

            UpdateGuild(guild);
        }
Example #13
0
 public void ChangeGuildIcon(Player initiator, Guild guild, byte[] newIcon)
 {
     throw new NotImplementedException();
 }
Example #14
0
        public void AddNewGuild(List<Player> players, string guildName)
        {
            Guild g = new Guild
                          {
                              GuildLogo = "",
                              GuildName = guildName,
                              CreationDate = Funcs.GetRoundedUtc(),
                              GuildHistory = new List<HistoryEvent>(),
                              GuildRanks = new List<GuildMemberRank>()
                          };

            AddNewRank(g, new GuildMemberRank {RankId = 1, RankName = "Guildmaster"});
            AddNewRank(g, new GuildMemberRank {RankId = 2, RankName = "Recruit"});

            foreach (Player player in players)
            {
                AddMemberToGuild(player, g);
                SystemMessages.GuildHasBeenCreated(guildName).Send(player.Connection);
            }

            lock (GuildsLock)
                Cache.Guilds.Add(g.GuildId, g);

            Cache.UsedGuildNames.Add(g.GuildName.ToLower());
        }
 public SpGuildMemberList(Guild guild)
 {
     Guild = guild;
 }
Example #16
0
 private Player GetPlayerByName(Guild guild, string name)
 {
     return guild.GuildMembers.FirstOrDefault(pl => pl.Key.PlayerData.Name == name).Key;
 }
Example #17
0
        private void SendGuildInformationToOnlineMembers(Guild guild)
        {
            if(guild == null)
                return;

            lock (guild.MembersLock)
                foreach (KeyValuePair<Player, int> member in guild.GuildMembers)
                    if (Communication.Global.PlayerService.IsPlayerOnline(member.Key))
                        new SpGuildRanking(member.Key).Send(member.Key);
        }
Example #18
0
        public Player GetLeader(Guild guild)
        {
            if (guild == null)
                return null;

            return guild.GuildMembers.FirstOrDefault(player => player.Value == 1).Key;
        }
Example #19
0
 public void LeaveGuild(Player player, Guild guild)
 {
     RemoveMember(player, guild);
 }
Example #20
0
 public SpGuildRanking(Player player)
 {
     Guild = player.Guild;
     Player = player;
 }