public static TimeSpan?OnFailed(string ip) { TimeSpan?ts = null; IPLock iplock; lock (locker) { if (!iplocks.TryGetValue(ip, out iplock)) { iplock = new IPLock(ip); iplocks[ip] = iplock; } if (++iplock.Attempts >= MaxAttempts) // only ban after MaxAttempts has been exceeded (default 3) { ++iplock.BanTimes; // this will multiply the time every repeated attempt to login up to UpperBanLimit times // by default the max ban time is 5 * 15 = var timeMultiplier = Math.Min(UpperBanLimit, (iplock.Attempts - MaxAttempts) + 1); iplock.BanExpireDate = DateTime.UtcNow.AddMinutes(5 * timeMultiplier); ts = iplock.BanExpireDate - DateTime.UtcNow; } } return(ts); }
protected override void OnClientConnected(Client client) { if (IPLock.IsLocked(client.IP)) { client.Disconnect(); return; // client.Tag is null so there is no OnClientDisconnected code running for it } client.Tag = new UserClient(client); Logger.Log(LogType.Debug, "[{0}-{1}] Client connected", client.IP, client.SocketHandle.ToInt32()); }
void OnLogin(UserClient client, string data) { string server_keydata = string.Empty; if (!ServerConfiguration.GetValue("keydata", out server_keydata)) { client.Disconnect("Server keydata is missing..."); return; } if (data.Length != server_keydata.Length || string.Compare(data, server_keydata) != 0) { IPLock.AddLock(client.NetworkClient.IP); client.Disconnect("Client keydata is invalid"); return; } client.IsAuthorized = true; client.NetworkClient.Send("logedin\n"); Logger.Log(LogType.Debug, "{0} successfully authorized.", client.NetworkClient.IP); // send hosts list and shit var sb = new StringBuilder(); sb.Append("hosts "); int i = 0; HostsDatabase.Lock(); foreach (var host in HostsDatabase.Hosts) { if (i++ > 0) { sb.Append('|'); } sb.AppendFormat( "{0}/{1}/{2}/{3}", host.Name.Escape(EscapeLanguage.Xml), host.IP.Escape(EscapeLanguage.Xml), host.Description.Escape(EscapeLanguage.Xml), host.Hidden ? "1" : "0"); } HostsDatabase.Unlock(); sb.Append('\n'); client.NetworkClient.Send(sb.ToString()); // host list }
public void SetUp() { _ipValidator = new Mock <IIPValidator>(); _browser = new Browser(config => { config.Module <TestModule>(); config.RequestStartup((container, pipelines, ctx) => { IPLock.Enable(pipelines, new IPLockConfiguration { IPValidator = _ipValidator.Object }); }); }); }