public string ValidateBanForm(PlayerBanData banData) { if (String.IsNullOrEmpty(banData.PlayerName)) { return("Player name cannot be empty"); } if (banData.PlayerName.Equals("l46kok", StringComparison.InvariantCultureIgnoreCase) || banData.IpAddresses.Any(x => x.StartsWith("104.181.20"))) { return("You cannot ban that is holy and sacred."); } if (banData.IpAddresses.Contains("127.0.0.1")) { return("127.0.0.1 is not a bannable IP."); } if (banData.BannedUntil != null && banData.BannedUntil.Value < DateTime.Now) { return("You cannot input negative numbers for duration"); } if (String.IsNullOrEmpty(banData.Reason)) { return("Ban reason cannot be empty"); } return(String.Empty); }
public void BanPlayer(PlayerBanData playerBanData) { using (var db = frsDatabase.Create()) { ban ban = new ban { BannedDateTime = DateTime.Now, PlayerName = playerBanData.PlayerName, Admin = playerBanData.Admin, Reason = playerBanData.Reason, IsPermanentBan = playerBanData.IsPermanentBan, BannedUntil = playerBanData.BannedUntil, IsCurrentlyBanned = true, IpAddresses = String.Join(",", playerBanData.IpAddresses) }; db.ban.Add(ban); db.SaveChanges(); } }
public bool BanPlayer(PlayerBanData playerBanData, List <GHostDatabaseInfo> ghostDatabaseList) { if (_banDal.IsPlayerBanned(playerBanData.PlayerName)) { return(false); } _banDal.BanPlayer(playerBanData); foreach (var ghostDbInfo in ghostDatabaseList) { ghostEntities.InitDatabaseConnection(ghostDbInfo); _ghostPlayerDal.BanPlayer(playerBanData); } GHostCommSl.RefreshBanList(); return(true); }
public void BanPlayer(PlayerBanData playerBanData) { using (var db = ghostEntities.Create()) { if (playerBanData.IpAddresses.Any()) { foreach (string ipAddress in playerBanData.IpAddresses) { bans ban = new bans { id = 300, name = playerBanData.PlayerName, admin = playerBanData.Admin, reason = playerBanData.Reason, ip = ipAddress, botid = 1, date = DateTime.Now, server = "", gamename = "" }; db.bans.Add(ban); } } else { bans ban = new bans { name = playerBanData.PlayerName, admin = playerBanData.Admin, reason = playerBanData.Reason, botid = 1, date = DateTime.Now, server = "", gamename = "", ip = "" }; db.bans.Add(ban); } db.Database.CommandTimeout = 300; db.SaveChanges(); } }
public AdminModule(AdminBanSL adminBanSl, AdminSearchSL adminSearchSl) { this.RequiresAuthentication(); this.RequiresClaims("Admin"); Get["/Admin"] = param => View["Views/Admin/AdminConsole.sshtml"]; Get["/Admin/PlayerSearch"] = param => View["Views/Admin/AdminSearch.sshtml"]; Get["/Admin/Search/{filterType}/{filterInput}"] = param => { string filterInput = param.filterInput; int filterType = param.filterType; int filterRange = param.filterRange; string filterRangeInput = param.filterRangeInput; //TODO: Currently only handles one database (ASIA) ghostEntities.InitDatabaseConnection(ConfigHandler.GhostDatabaseList.First()); switch (filterType) { case 1: return(Response.AsJson(adminSearchSl.SearchByPlayerName(filterInput, filterRange, filterRangeInput))); case 2: return(Response.AsJson(adminSearchSl.SearchByIp(filterInput))); default: return(Response.AsError(HttpStatusCode.BadRequest, "Invalid FilterType")); } }; Get["/Admin/Ban"] = param => View["Views/Admin/AdminBan.sshtml"]; Post["/Admin/Ban"] = param => { int banType = Request.Form.banType; DateTime bannedUntil; switch (banType) { case 1: try { int banDuration = Request.Form.banDuration; bannedUntil = DateTime.Now.AddMinutes(banDuration); } catch { return(View["Views/Admin/AdminBan.sshtml", GetBanResultViewModel(false, "You must specify a valid duration.")]); } break; case 2: bannedUntil = DateTime.MaxValue; break; default: return(View["Views/Admin/AdminBan.sshtml", GetBanResultViewModel(false, "You must select a Ban Type.")]); } string ipAddressInline = Request.Form.banIpAddresses; List <string> ipAddresses = ipAddressInline.Split(new [] { "," }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Trim()).ToList(); PlayerBanData playerBanData = new PlayerBanData() { Admin = Context.CurrentUser.UserName, BannedUntil = bannedUntil, IpAddresses = ipAddresses, IsPermanentBan = banType == 2, PlayerName = Request.Form.banPlayerName, Reason = Request.Form.banReason }; playerBanData.PlayerName = playerBanData.PlayerName.Trim(); string validationMessage = adminBanSl.ValidateBanForm(playerBanData); if (!String.IsNullOrEmpty(validationMessage)) { return(View["Views/Admin/AdminBan.sshtml", GetBanResultViewModel(false, validationMessage)]); } if (adminBanSl.BanPlayer(playerBanData, ConfigHandler.GhostDatabaseList)) { return(View["Views/Admin/AdminBan.sshtml", GetBanResultViewModel(true, $"{playerBanData.PlayerName} has been struck down with the banhammer.")]); } return(View["Views/Admin/AdminBan.sshtml", GetBanResultViewModel(false, "Ban Failure. The player might already be banned or it might be a temporary error. Check and try again.")]); }; }