public void GuildRemove(RealmTime t, GuildRemovePacket pkt) { var pname = pkt.Name; try { var p = RealmManager.FindPlayer(pname); if (p != null && p.Guild == Guild) { var db = new Database(); var g = db.ChangeGuild(p.Client.Account, p.Client.Account.Guild.Id, p.GuildRank, p.Client.Account.Guild.Fame, true); p.Guild = ""; p.GuildRank = 0; p.Client.Account.Guild = g; p.UpdateCount++; if (p != this) { p.SendGuild("You have been kicked from the guild."); foreach (var pl in RealmManager.GuildMembersOf(Guild)) pl.SendGuild(p.nName + " has been kicked from the guild by " + nName + "."); } else { p.SendGuild("You have left the guild."); foreach (var pl in RealmManager.GuildMembersOf(Guild)) pl.SendGuild(nName + " has left the guild."); } } else { try { var db = new Database(); var other = db.GetAccount(pname); if (other.Guild.Name == Guild) { db.ChangeGuild(other, other.Guild.Id, other.Guild.Rank, other.Guild.Fame, true); foreach (var pl in RealmManager.GuildMembersOf(Guild)) pl.SendGuild(pname + " has been kicked from the guild by " + nName + "."); } } catch (Exception e) { psr.SendPacket(new TextPacket() { BubbleTime = 0, Stars = -1, Name = "*Error*", Text = e.Message }); } } } catch (Exception e) { psr.SendPacket(new TextPacket() { BubbleTime = 0, Stars = -1, Name = "*Error*", Text = e.Message }); } }
public void LeaveGuild(GuildRemovePacket pkt) { try { if (psr.Account.Guild == null || psr.Account.Guild.Name == "") { psr.SendPacket(new CreateGuildResultPacket() { ResultMessage = "You don't have a guild!", Success = false }); return; } using (Database dbx = new Database()) { var cmd = dbx.CreateQuery(); cmd.CommandText = "UPDATE accounts SET guild='0', guildRank='-1' WHERE id=@id"; cmd.Parameters.AddWithValue("@id", psr.Account.AccountId); if (cmd.ExecuteNonQuery() == 0) { psr.SendPacket(new CreateGuildResultPacket() { ResultMessage = "Unable to remove guild from account data!", Success = false }); return; } else { var members = dbx.GetGuildMembers(psr.Account); if (!members.Contains(psr.Account.AccountId)) { psr.SendPacket(new CreateGuildResultPacket() { ResultMessage = "Unable to find account in guild's members list!", Success = false }); return; } members.Remove(psr.Account.AccountId); var newmembers = Utils.GetCommaSepString<int>(members.ToArray()); if (newmembers.Length == 0) { if (dbx.RemoveGuild(psr.Account) == false) { psr.SendPacket(new CreateGuildResultPacket() { ResultMessage = "Unable to delete guild!", Success = false }); return; } } else { if (dbx.RemoveFromGuildMembers(psr.Account) == false) { psr.SendPacket(new CreateGuildResultPacket() { ResultMessage = "Unable to remove account from guild's members list!", Success = false }); return; } } foreach (var i in RealmManager.Clients.Values) { if (i.Account.Guild.Name == psr.Account.Guild.Name && i.Account.Guild.Id == psr.Account.Guild.Id) { i.SendPacket(new TextPacket() { Name = "", BubbleTime = 0, Stars = -1, Text = psr.Account.Name + " left the guild." }); } } psr.Account.Guild = new Guild() { Id = 0, Name = "", Rank = -1 }; UpdateCount++; psr.SendPacket(new CreateGuildResultPacket() { ResultMessage = "Successfully left the guild!", Success = true }); return; } } } catch { psr.SendPacket(new CreateGuildResultPacket() { ResultMessage = "Error leaving the guild!", Success = false }); return; } }