//BanAction public static void ProcessAction(Client client, Player player, BanAction action) { var target = DbInterface.GetPlayer(action.Name); if (target != null) { if (string.IsNullOrEmpty(Ban.CheckBan(target.User, ""))) { if (action.BanIp == true) { Ban.Add( target.User, action.DurationDays, action.Reason, player.Name, target.Client?.GetIp() ?? "" ); } else { Ban.Add(target.User, action.DurationDays, action.Reason, player.Name, ""); } target.Client?.Disconnect(); PacketSender.SendChatMsg(player, Strings.Account.banned.ToString(target.Name), Color.Red); } else { PacketSender.SendChatMsg(player, Strings.Account.alreadybanned.ToString(target.Name), Color.Red); } } else { PacketSender.SendChatMsg(player, Strings.Player.offline); } }
//BanAction public static void ProcessAction(Client client, Player player, BanAction action) { var target = Player.Find(action.Name); if (target != null) { if (string.IsNullOrEmpty(Ban.CheckBan(target.User, ""))) { if (action.BanIp == true) { Ban.Add( target.User, action.DurationDays, action.Reason, player.Name, target.Client?.GetIp() ?? "" ); } else { Ban.Add(target.User, action.DurationDays, action.Reason, player.Name, ""); } UserActivityHistory.LogActivity(target?.UserId ?? Guid.Empty, target?.Id ?? Guid.Empty, target?.Client?.GetIp(), UserActivityHistory.PeerType.Client, UserActivityHistory.UserAction.DisconnectBan, $"{target.User?.Name},{target.Name}"); target.Client?.Disconnect(); PacketSender.SendChatMsg(player, Strings.Account.banned.ToString(target.Name), Enums.ChatMessageType.Admin, Color.Red); } else { PacketSender.SendChatMsg(player, Strings.Account.alreadybanned.ToString(target.Name), Enums.ChatMessageType.Admin, Color.Red); } } else { PacketSender.SendChatMsg(player, Strings.Player.offline, Enums.ChatMessageType.Admin); } }
//BanAction public static void ProcessAction(Client client, Player player, BanAction action) { var target = Player.Find(action.Name); if (target != null) { if (string.IsNullOrEmpty(Ban.CheckBan(target.User, ""))) { if (action.BanIp == true) { Ban.Add( target.User, action.DurationDays, action.Reason, player.Name, target.Client?.GetIp() ?? "" ); } else { Ban.Add(target.User, action.DurationDays, action.Reason, player.Name, ""); } using (var logging = DbInterface.LoggingContext) { logging.UserActivityHistory.Add( new UserActivityHistory { UserId = target.UserId, PlayerId = target.Id, Ip = target.Client?.GetIp(), Peer = UserActivityHistory.PeerType.Client, Action = UserActivityHistory.UserAction.DisconnectBan, Meta = $"{target.User?.Name},{target.Name}" } ); } target.Client?.Disconnect(); PacketSender.SendChatMsg(player, Strings.Account.banned.ToString(target.Name), Enums.ChatMessageType.Admin, Color.Red); } else { PacketSender.SendChatMsg(player, Strings.Account.alreadybanned.ToString(target.Name), Enums.ChatMessageType.Admin, Color.Red); } } else { PacketSender.SendChatMsg(player, Strings.Player.offline, Enums.ChatMessageType.Admin); } }
protected override void HandleClient(ServerContext context, Client target, int duration, bool ip, string reason) { if (target.Entity == null) { Console.WriteLine($@" {Strings.Player.offline}"); return; } // TODO: Refactor the global/console messages into ModeratorActionCommand var name = target.Entity.Name; if (string.IsNullOrEmpty(Ban.CheckBan(target.User, ""))) { Ban.Add(target, duration, reason, Strings.Commands.banuser, ip ? target.GetIp() : ""); target.Disconnect(); PacketSender.SendGlobalMsg(Strings.Account.banned.ToString(name)); Console.WriteLine($@" {Strings.Account.banned.ToString(name)}"); } else { Console.WriteLine($@" {Strings.Account.alreadybanned.ToString(name)}"); } }
private object DoAdminActionOnUser( Func <Tuple <Client, User> > fetch, Func <HttpResponseMessage> onError, AdminActions adminAction, AdminActionParameters actionParameters ) { var(client, user) = fetch(); if (user == null) { return(onError()); } var player = client?.Entity; var targetIp = client?.GetIp() ?? ""; switch (adminAction) { case AdminActions.Ban: if (string.IsNullOrEmpty(Ban.CheckBan(user, ""))) { Ban.Add( user.Id, actionParameters.Duration, actionParameters.Reason ?? "", actionParameters.Moderator ?? @"api", actionParameters.Ip ? targetIp : "" ); client?.Disconnect(); PacketSender.SendGlobalMsg(Strings.Account.banned.ToString(user.Name)); return(Request.CreateMessageResponse( HttpStatusCode.OK, Strings.Account.banned.ToString(user.Name) )); } else { return(Request.CreateMessageResponse( HttpStatusCode.BadRequest, Strings.Account.alreadybanned.ToString(user.Name) )); } case AdminActions.UnBan: Ban.Remove(user.Id, false); PacketSender.SendGlobalMsg(Strings.Account.unbanned.ToString(user.Name)); return(Request.CreateMessageResponse( HttpStatusCode.OK, Strings.Account.unbanned.ToString(user.Name) )); case AdminActions.Mute: if (string.IsNullOrEmpty(Mute.FindMuteReason(user.Id, ""))) { Mute.Add( user, actionParameters.Duration, actionParameters.Reason ?? "", actionParameters.Moderator ?? @"api", actionParameters.Ip ? targetIp : "" ); PacketSender.SendGlobalMsg(Strings.Account.muted.ToString(user.Name)); return(Request.CreateMessageResponse( HttpStatusCode.OK, Strings.Account.muted.ToString(user.Name) )); } else { return(Request.CreateMessageResponse( HttpStatusCode.BadRequest, Strings.Account.alreadymuted.ToString(user.Name) )); } case AdminActions.UnMute: Mute.Remove(user); PacketSender.SendGlobalMsg(Strings.Account.unmuted.ToString(user.Name)); return(Request.CreateMessageResponse( HttpStatusCode.OK, Strings.Account.unmuted.ToString(user.Name) )); case AdminActions.WarpTo: if (player != null) { var mapId = actionParameters.MapId == Guid.Empty ? player.MapId : actionParameters.MapId; player.Warp(mapId, (byte)player.X, (byte)player.Y); return(Request.CreateMessageResponse( HttpStatusCode.OK, $@"Warped '{player.Name}' to {mapId} ({player.X}, {player.Y})." )); } break; case AdminActions.WarpToLoc: if (player != null) { var mapId = actionParameters.MapId == Guid.Empty ? player.MapId : actionParameters.MapId; player.Warp(mapId, actionParameters.X, actionParameters.Y, true); return(Request.CreateMessageResponse( HttpStatusCode.OK, $@"Warped '{player.Name}' to {mapId} ({actionParameters.X}, {actionParameters.Y})." )); } break; case AdminActions.Kick: if (client != null) { client.Disconnect(actionParameters.Reason); PacketSender.SendGlobalMsg(Strings.Player.serverkicked.ToString(player?.Name)); return(Request.CreateMessageResponse( HttpStatusCode.OK, Strings.Player.serverkicked.ToString(player?.Name) )); } break; case AdminActions.Kill: if (client != null && client.Entity != null) { lock (client.Entity.EntityLock) { client.Entity.Die(); } PacketSender.SendGlobalMsg(Strings.Player.serverkilled.ToString(player?.Name)); return(Request.CreateMessageResponse( HttpStatusCode.OK, Strings.Commandoutput.killsuccess.ToString(player?.Name) )); } break; case AdminActions.WarpMeTo: case AdminActions.WarpToMe: return(Request.CreateErrorResponse( HttpStatusCode.BadRequest, $@"'{adminAction.ToString()}' not supported by the API." )); case AdminActions.SetSprite: case AdminActions.SetFace: case AdminActions.SetAccess: default: return(Request.CreateErrorResponse(HttpStatusCode.NotImplemented, adminAction.ToString())); } return(Request.CreateErrorResponse(HttpStatusCode.NotFound, Strings.Player.offline)); }