/// <summary> /// Removes a player from the guild. /// </summary> /// <param name="player">The player to remove from the guild.</param> /// <param name="initiator">The player who initiated this change (null if done by the api or some other method).</param> public void RemoveMember(Player player, Player initiator = null, GuildActivityType action = GuildActivityType.Left) { if (player != null) { using (var context = DbInterface.CreatePlayerContext(readOnly: false)) { var dbPlayer = context.Players.Where(p => p.Id == player.Id && p.DbGuild.Id == this.Id).Include(p => p.DbGuild).FirstOrDefault(); if (dbPlayer != null) { dbPlayer.DbGuild = null; dbPlayer.GuildRank = 0; context.ChangeTracker.DetectChanges(); context.SaveChanges(); player.Guild = null; player.GuildRank = 0; player.GuildInvite = null; if (player.BankInterface != null && player.GuildBank) { player.BankInterface.Dispose(); } Members.TryRemove(player.Id, out GuildMember removed); // Send our new guild list to everyone that's online. UpdateMemberList(); // Send our entity data to nearby players. PacketSender.SendEntityDataToProximity(Player.FindOnline(player.Id)); LogActivity(Id, player, initiator, action); } } } }
/// <summary> /// Logs guild activity /// </summary> /// <param name="guildId">The player to which to send a message.</param> /// <param name="player">The player which this activity impacts.</param> /// <param name="initiator">The id of the player who caused this activity (or null if caused by the api or something else).</param> /// <param name="type">The type of message we are sending.</param> /// <param name="meta">Any other info regarding this activity</param> public static void LogActivity(Guid guildId, Player player, Player initiator, GuildActivityType type, string meta = "") { if (Options.Instance.Logging.GuildActivity) { DbInterface.Pool.QueueWorkItem(new Action <GuildHistory>(Log), new GuildHistory { GuildId = guildId, TimeStamp = DateTime.UtcNow, UserId = player?.Client?.User?.Id ?? Guid.Empty, PlayerId = player?.Id ?? Guid.Empty, Ip = player?.Client?.GetIp(), InitiatorId = initiator?.Id ?? Guid.Empty, Type = type, Meta = meta, }); } }