/// <summary> /// Create a new ban for the given ip lasting for the given period. /// </summary> public static void Ban(string ip, TimeSpan @for, string reason) { // Never ban an internal IP if (Current.IsPrivateIP(ip)) { return; } var db = Current.WriteDB; var now = Current.Now; var newBan = new IPBan { CreationDate = now, ExpirationDate = now + @for, IP = ip, Reason = reason }; db.IPBans.InsertOnSubmit(newBan); db.SubmitChanges(); var period = new BanPeriod { CreationDate = newBan.CreationDate, ExpirationDate = newBan.ExpirationDate }; BannedIPCache.AddOrUpdate(ip, period, (string key, BanPeriod old) => period); }
public IPBanData GetIPBan(IPAddress address) { IPBan ban = null; BanManager.Instance.PostWait(mgr => ban = mgr.FindIPBan(x => x.Address.Equals(address))).Wait(); return(ban != null?ban.Serialize() : null); }
public ActionResult CreateIPBan(string ip, string expires, string reason, bool?showall, int?page, int?pagesize) { var retryValues = new { ip, expires, reason }; if (!ip.HasValue()) { return(RecoverableError("IP must be set.", retryValues)); } if (!expires.HasValue()) { return(RecoverableError("Expires must be set.", retryValues)); } if (!reason.HasValue()) { return(RecoverableError("Reason must be set.", retryValues)); } DateTime expDate; if (!DateTime.TryParse(expires, out expDate)) { return(RecoverableError("Expires not recognized as a date.", retryValues)); } var now = Current.Now; if (expDate < now) { return(RecoverableError("Expiration date must be in the future.", retryValues)); } var newBan = new IPBan { CreationDate = now, ExpirationDate = expDate, IP = ip, Reason = reason }; var db = Current.WriteDB; db.IPBans.InsertOnSubmit(newBan); db.SubmitChanges(); return(SafeRedirect( (Func <bool?, int?, int?, ActionResult>)IPBans, new { showall, page, pagesize })); }
private IPBan BuildIPBan(DataRow row) { IPBan ipBan = new IPBan(); ipBan.IP = (string)row["ip"]; ipBan.BanDate = Convert.ToInt64((uint)row["bandate"]).ToDateTime(); ipBan.UnbanDate = Convert.ToInt64((uint)row["unbandate"]).ToDateTime(); ipBan.BannedBy = (string)row["bannedby"]; ipBan.BanReason = (string)row["banreason"]; return(ipBan); }
static void AuthServer_OnClientReceive(byte[] buffer, int length, ClientWrapper arg3) { var player = arg3.Connector as Client.AuthClient; AuthClient authClient = arg3.Connector as AuthClient; player.Cryptographer.Decrypt(buffer, length); player.Queue.Enqueue(buffer, length); while (player.Queue.CanDequeue()) { byte[] packet = player.Queue.Dequeue(); ushort len = BitConverter.ToUInt16(packet, 0); ushort id = BitConverter.ToUInt16(packet, 2); if (len == 312) { player.Info = new Authentication(); player.Info.Deserialize(packet); player.Account = new AccountTable(player.Info.Username); if (!BruteForceProtection.AcceptJoin(arg3.IP)) { Console.WriteLine(string.Concat(new string[] { "Client > ", player.Info.Username, "was blocked address", arg3.IP, "!" })); arg3.Disconnect(); break; } Forward Fw = new Forward(); if (player.Account.Password == player.Info.Password && player.Account.exists) { Fw.Type = Forward.ForwardType.Ready; } else { BruteForceProtection.ClientRegistred(arg3.IP); Fw.Type = Forward.ForwardType.InvalidInfo; } if (IPBan.IsBanned(arg3.IP)) { Fw.Type = Forward.ForwardType.Banned; player.Send(Fw); return; } if (Fw.Type == Network.AuthPackets.Forward.ForwardType.Ready) { Fw.Identifier = player.Account.GenerateKey(); Kernel.AwaitingPool[Fw.Identifier] = player.Account; Fw.IP = ConquordIP; Fw.Port = GamePort; } player.Send(Fw); } } }
public void CreateIPBan(IPAddress address, string notes, DateTime?expiry) { IPBan ban = null; BanManager.Instance.PostWait(mgr => ban = mgr.FindIPBan(x => x.Equals(address))).Wait(); if (ban != null) { throw new ArgumentException("IP ban already exists."); } BanManager.Instance.PostAsync(mgr => mgr.CreateIPBan(address, notes, expiry)); }