public void UpdateGuildMember(GuildMember gm)
        {
            DbParameter characterIdParameter = _db.CreateParameter(DbNames.UPDATEGUILDMEMBER_CHARACTERID, gm.Character.CharacterId);
            characterIdParameter.DbType = DbType.Int32;

            DbParameter titleParameter = _db.CreateParameter(DbNames.UPDATEGUILDMEMBER_TITLE, gm.Title);
            titleParameter.DbType = DbType.String;

            DbParameter rankParameter = _db.CreateParameter(DbNames.UPDATEGUILDMEMBER_RANK, gm.Rank);
            rankParameter.DbType = DbType.Int32;

            _db.Open();
            _db.ExecuteNonQuery(DbNames.UPDATEGUILDMEMBER, CommandType.StoredProcedure, characterIdParameter, titleParameter, rankParameter);
            _db.Close();
        }
        void c_ClientRequestJoinGuildInfo(object sender, ClientRequestJoinGuildEventArgs e)
        {
            Client c = (Client)sender;
            RequestJoinGuildInfo i = e.Info;
            Client asker = null;
            Client target = null;
            MapEngine mapEngine = GetMapEngine(c.MyCharacter.MapId);
            Client[] clients = GetClientsForChars(mapEngine.GetCharactersInRange(c.MyCharacter.Position, 150).ToArray());

            target = GetClientByCharacterID(i.TargetID);
            asker = GetClientByCharacterID(i.AskerID);

            if (asker.MyCharacter.Guild != null)
            {
                i.Answer = GuildJoinAnswer.AlreadyInGuild;
                asker.Send(PacketManager.SendGuildJoinAnswer(i));
                return;
            }

            if (target.MyCharacter.Guild == null)
            {
                i.Answer = GuildJoinAnswer.NotInGuild;
                asker.Send(PacketManager.SendGuildJoinAnswer(i));
                return;
            }

            if (i.Answer == GuildJoinAnswer.Join)
            {
                if (target.MyCharacter.Guild != null)
                {
                    GuildMember member = target.MyCharacter.Guild.Members.Single(x => x.Character.CharacterId == target.MyCharacter.CharacterId);
                    if (member.Rank == GuildOrder.Second_Master || member.Rank == GuildOrder.Guild_Master)
                        target.Send(PacketManager.SendGuildJoinAnswer(i));
                    else
                    {
                        i.Answer = GuildJoinAnswer.Decline;
                        asker.Send(PacketManager.SendGuildJoinAnswer(i));
                        return;
                    }
                }
            }

            if (i.Answer == GuildJoinAnswer.Decline)
            {
                asker.Send(PacketManager.SendGuildJoinAnswer(i));
            }

            if (i.Answer == GuildJoinAnswer.Accept)
            {
                GuildMember newMember = new GuildMember("", GuildOrder.Member, asker.MyCharacter);

                target.MyCharacter.Guild.Members.Add(newMember);
                asker.MyCharacter.Guild = target.MyCharacter.Guild;

                SendToGuild(target.MyCharacter.Guild, PacketManager.SendGuildJoin(asker.MyCharacter));
                SendToGuild(target.MyCharacter.Guild, PacketManager.SendGuildStats(target.MyCharacter.Guild));
                SendToGuild(target.MyCharacter.Guild, PacketManager.SendGuildMember(target.MyCharacter.Guild, newMember));
                /*
                target.Send(PacketManager.SendGuildJoin(asker.MyCharacter));
                target.Send(PacketManager.SendGuildStats(target.MyCharacter.Guild));
                target.Send(PacketManager.SendGuildMember(target.MyCharacter.Guild, newMember));
                */
                asker.Send(PacketManager.SendGuildJoin(asker.MyCharacter));

                guildManager.InsertGuildMember(newMember, asker.MyCharacter.Guild);

                foreach (GuildMember m in c.MyCharacter.Guild.Members)
                {
                    if (m.Character.CharacterId != target.MyCharacter.CharacterId || m.Character.CharacterId != asker.MyCharacter.CharacterId)
                    {
                        Client member = GetClientByCharacterID(m.Character.CharacterId);
                        if (member != null)
                        {
                            member.MyCharacter.Guild = target.MyCharacter.Guild;
                        }
                    }
                }
                // update guild memberlist for each members
            }
        }
 public static byte[] SendGuildMemberInfo(GuildMember g)
 {
     Packet p = new Packet(200);
     p.WriteInt(g.Character.CharacterId);
     p.WriteString(g.Character.Name);
     p.WriteInt((int)g.Rank);
     p.WriteString(g.Title);
     p.WriteByte(Convert.ToByte(g.Online));
     p.WriteByte(g.Character.Level);
     p.WriteHexString("00"); // some stats
     p.WriteByte(g.Character.Class);
     return p.GetWrittenBuffer(PacketIds.SendGuildMemberInfo);
 }
 public static byte[] SendGuildMember(Guild g, GuildMember m)
 {
     Packet p = new Packet(20);
     p.WriteInt(m.Character.CharacterId);
     p.WriteInt(g.ID);
     p.WriteString(g.Name);
     p.WriteInt((int)m.Rank);
     p.WriteString(m.Title);
     p.WriteString(m.Character.Name); // owner name
     p.WriteHexString("00 00 00 00 00");
     p.WriteHexString("02 00 00 00");
     p.WriteHexString("00 00 00 00"); // more stats?
     p.WriteHexString("00 00 00 00"); // guild mark
     return p.GetWrittenBuffer(PacketIds.SendGuildOwner);
 }
 public static byte[] SendGuildChangeMemberTitle(Guild g, GuildMember m, GuildMemberError e)
 {
     Packet p = new Packet(20);
     p.WriteByte((byte)e); // error proly
     if (e == GuildMemberError.Success)
     {
         p.WriteInt(g.ID);
         p.WriteInt(m.Character.CharacterId);
         p.WriteString(m.Title);
     }
     else
     {
         p.WriteInt(0);
         p.WriteInt(0);
         p.WriteString("");
     }
     return p.GetWrittenBuffer(PacketIds.SendGuildChangeMemberTitle);
 }
 public static byte[] SendGuildChangeMemberRank(GuildMember m, GuildMemberError e)
 {
     Packet p = new Packet(20);
     p.WriteByte((byte)e);
     if (e == GuildMemberError.Success)
     {
         p.WriteInt(m.Character.CharacterId);
         p.WriteInt((int)m.Rank);
     }
     else
     {
         p.WriteInt(0);
         p.WriteInt(0);
     }
     return p.GetWrittenBuffer(PacketIds.SendGuildChangeMemberRank);
 }