private void Load() { //members DataTable MemberData = null; using(DatabaseClient DBClient = Program.DatabaseManager.GetClient()) { MemberData = DBClient.ReadDataTable("SELECT * FROM GuildMembers WHERE GuildID = "+this.ID+""); } foreach (DataRow row in MemberData.Rows) { //get character WorldCharacter character; if (!CharacterManager.Instance.GetCharacterByID(Convert.ToInt32(row["CharID"]), out character)) continue; var member = new GuildMember(this, character, (GuildRank)GetDataTypes.GetByte(row["Rank"]), GetDataTypes.GetUshort(row["Korp"])); Members.Add(member); } //academy Academy = new GuildAcademy(this); }
public void UpdateMemberRank(GuildMember Member, GuildRank NewRank) { Member.Rank = NewRank; Member.Save(); //broadcast to members using (var packet = new Packet(SH29Type.UpdateGuildMemberRank)) { packet.WriteString(Member.Character.Character.Name, 16); packet.WriteByte((byte)NewRank); Broadcast(packet); } //broadcast to zones using (var packet = new InterPacket(InterHeader.ZONE_GuildMemberRankUpdate)) { packet.WriteInt(ID); packet.WriteInt(Member.Character.ID); packet.WriteByte((byte)NewRank); ZoneManager.Instance.Broadcast(packet); } }
public void RemoveMember(GuildMember Member, MySqlConnection con = null, bool BroadcastRemove = true) { lock (ThreadLocker) { var conCreated = (con == null); if (conCreated) { con = Program.DatabaseManager.GetClient().GetConnection(); } //remove from db using (var cmd = con.CreateCommand()) { cmd.CommandText = "GuildMember_Remove"; cmd.Parameters.Add(new MySqlParameter("@pGuildID", ID)); cmd.Parameters.Add(new MySqlParameter("@pCharacterID", Member.Character.ID)); cmd.ExecuteNonQuery(); } //remove from list Members.Remove(Member); //update character Member.Character.Guild = null; Member.Character.GuildMember = null; Member.Character.GuildAcademy = null; //broadcast member left packet if (BroadcastRemove) { using (var packet = new Packet(SH29Type.GuildMemberLeft)) { packet.WriteString(Member.Character.Character.Name); Broadcast(packet); } //send packet to zones that a member has been removed using (var packet = new InterPacket(InterHeader.ZONE_GuildMemberRemove)) { packet.WriteInt(ID); packet.WriteInt(Member.Character.ID); ZoneManager.Instance.Broadcast(packet); } } //clean up Member.Dispose(); if (conCreated) { con.Dispose(); } } }
public bool GetMember(string Name, out GuildMember Member) { lock (ThreadLocker) { Member = Members.Find(m => m.Character.Character.Name.Equals(Name)); } return (Member != null); }
public void Broadcast(Packet Packet, GuildMember Exclude = null) { lock (ThreadLocker) { foreach (var member in Members) { if (Exclude != null && member == Exclude) continue; if (member.Character.IsOnline) { try { member.Character.Client.SendPacket(Packet); } catch (Exception) { continue; } } } } }
public void AddMember(WorldCharacter Character, GuildRank Rank, MySqlConnection con = null, bool BroadcastAdd = true, bool SendGuildInfoToClient = true) { lock (ThreadLocker) { var conCreated = (con == null); if (conCreated) { con = Program.DatabaseManager.GetClient().GetConnection(); } //add to db int result; using (var cmd = con.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "GuildMember_Create"; cmd.Parameters.Add(new MySqlParameter("@pGuildID", ID)); cmd.Parameters.Add(new MySqlParameter("@pCharacterID", Character.ID)); cmd.Parameters.Add(new MySqlParameter("@pRank", (byte)Rank)); cmd.Parameters.Add(new MySqlParameter("@pCorp", Convert.ToInt16("0"))); result = Convert.ToInt32(cmd.ExecuteScalar()); } if (result == -1) return; //create object var newMember = new GuildMember(this, Character, Rank, 0); //update character Character.Guild = this; Character.GuildMember = newMember; Character.GuildAcademy = Academy; //add to list Members.Add(newMember); if (BroadcastAdd) { newMember.BroadcastGuildName(); //broadcast that guild member joined using (var packet = new Packet(SH29Type.GuildMemberJoined)) { newMember.WriteInfo(packet); Broadcast(packet, newMember); } using (var packet = new Packet(SH29Type.GuildMemberLoggedIn)) { packet.WriteString(newMember.Character.Character.Name, 16); Broadcast(packet, newMember); } //let zone know that a new member has been added to guild using (var packet = new InterPacket(InterHeader.ZONE_GuildMemberAdd)) { packet.WriteInt(ID); packet.WriteInt(Character.ID); packet.WriteByte((byte)newMember.Rank); packet.WriteUShort(newMember.Corp); Managers.ZoneManager.Instance.Broadcast(packet); } } //send guild info to new member if (SendGuildInfoToClient) { SendMemberList(newMember.Character.Client); using (var packet = new Packet(SH4Type.CharacterGuildinfo)) { WriteGuildInfo(packet); newMember.Character.Client.SendPacket(packet); } } if (conCreated) { con.Dispose(); } } }