public static void Login(IClient client, String password) { String owner = Settings.Get <String>("owner"); if (!String.IsNullOrEmpty(owner)) { if (password == owner) { client.Registered = true; client.Captcha = true; client.Owner = true; Events.LoginGranted(client); client.Level = ILevel.Host; using (SHA1 sha1 = SHA1.Create()) client.Password = sha1.ComputeHash(Encoding.UTF8.GetBytes(owner)); if (client.Quarantined) { client.Unquarantine(); } CaptchaManager.AddCaptcha(client); ServerCore.Log(client.Name + " logged in with the room owner account"); return; } } using (SHA1 sha1 = SHA1.Create()) { byte[] pwd = sha1.ComputeHash(Encoding.UTF8.GetBytes(password)); Account a = Settings.Get <bool>("strict") ? list.Find(x => x.Password.SequenceEqual(pwd) && x.Guid.Equals(client.Guid)) : list.Find(x => x.Password.SequenceEqual(pwd)); if (a != null) { client.Registered = true; client.Captcha = true; Events.LoginGranted(client); client.Level = a.Level; client.Password = a.Password; if (client.Quarantined) { client.Unquarantine(); } CaptchaManager.AddCaptcha(client); ServerCore.Log(client.Name + " logged in with " + a.Name + "'s account [level designation: " + a.Level + "]"); return; } } Events.InvalidLoginAttempt(client); }
public static void SecureLogin(IClient client, byte[] password) { List <IPAddress> addresses = new List <IPAddress>(); addresses.Add(IPAddress.Loopback); addresses.Add(Settings.ExternalIP); addresses.Add(Settings.LocalIP); using (SHA1 sha1 = SHA1.Create()) { String owner = Settings.Get <String>("owner"); if (!String.IsNullOrEmpty(owner)) { foreach (IPAddress ip in addresses) { byte[] pwd = sha1.ComputeHash(Encoding.UTF8.GetBytes(owner)); pwd = sha1.ComputeHash(SecurePassword(pwd, client.Cookie, ip)); if (pwd.SequenceEqual(password)) { client.Registered = true; client.Captcha = true; client.Owner = true; Events.LoginGranted(client); client.Level = ILevel.Host; client.Password = sha1.ComputeHash(Encoding.UTF8.GetBytes(owner)); if (client.Quarantined) { client.Unquarantine(); } CaptchaManager.AddCaptcha(client); ServerCore.Log(client.Name + " logged in with the room owner account"); return; } } } var linq = Settings.Get <bool>("strict") ? (from x in list where x.Guid.Equals(client.Guid) select x) : (from x in list select x); foreach (Account a in linq) { foreach (IPAddress ip in addresses) { byte[] pwd = sha1.ComputeHash(SecurePassword(a.Password, client.Cookie, ip)); if (pwd.SequenceEqual(password)) { client.Registered = true; client.Captcha = true; Events.LoginGranted(client); client.Level = a.Level; client.Password = a.Password; if (client.Quarantined) { client.Unquarantine(); } CaptchaManager.AddCaptcha(client); ServerCore.Log(client.Name + " logged in with " + a.Name + "'s account [level designation: " + a.Level + "]"); return; } } } } }
private static void Public(AresClient client, TCPPacketReader packet) { String text = packet.ReadString(client); if (text.Length > 300) { text = text.Substring(0, 300); } if (text.StartsWith("#login") || text.StartsWith("#register")) { Command(client, text.Substring(1)); return; } if (text.StartsWith("#") && client.SocketConnected) { Command(client, text.Substring(1)); } if (client.SocketConnected) { if (!client.Captcha) { if (String.IsNullOrEmpty(client.CaptchaWord) || (client.CaptchaWord.Length > 0 && client.CaptchaWord.ToUpper() != Helpers.StripColors(text).Trim().ToUpper())) { if (client.CaptchaWord.Length > 0 && client.CaptchaWord.ToUpper() != Helpers.StripColors(text).Trim().ToUpper()) { Events.CaptchaReply(client, text); if (!client.SocketConnected) { return; } } CaptchaItem cap = Captcha.Create(); client.CaptchaWord = cap.Word; Events.CaptchaSending(client); client.SendPacket(TCPOutbound.NoSuch(client, String.Empty)); foreach (String str in cap.Lines) { client.SendPacket(TCPOutbound.NoSuch(client, str)); } client.SendPacket(TCPOutbound.NoSuch(client, String.Empty)); return; } else { client.Captcha = true; Events.CaptchaReply(client, text); CaptchaManager.AddCaptcha(client); if (client.Quarantined) { client.Unquarantine(); } return; } } else { Events.TextReceived(client, text); } } else { return; } if (client.SocketConnected) { text = Events.TextSending(client, text); if (!String.IsNullOrEmpty(text) && client.SocketConnected && !client.Muzzled) { if (client.Idled) { uint seconds_away = (uint)((Time.Now - client.IdleStart) / 1000); IdleManager.Remove(client); Events.Unidled(client, seconds_away); } if (client.SocketConnected) { byte[] js_style = null; AresFont font = (AresFont)client.Font; if (font.Enabled) { font.IsEmote = !String.IsNullOrEmpty(client.CustomName); js_style = TCPOutbound.Font(font); } UserPool.AUsers.ForEachWhere(x => { if (x.SupportsHTML && x.Ares) { if (String.IsNullOrEmpty(client.CustomName) || x.BlockCustomNames) { if (x.SupportsHTML) { if (js_style != null) { x.SendPacket(js_style); } } x.SendPacket(TCPOutbound.Public(x, client.Name, text)); } else { if (x.SupportsHTML) { if (js_style != null) { x.SendPacket(js_style); } } x.SendPacket(TCPOutbound.NoSuch(x, client.CustomName + text)); } } else { if (String.IsNullOrEmpty(client.CustomName) || x.BlockCustomNames) { x.SendPacket(TCPOutbound.Public(x, client.Name, text)); } else { x.SendPacket(TCPOutbound.NoSuch(x, client.CustomName + text)); } } }, x => x.LoggedIn && x.Vroom == client.Vroom && !x.IgnoreList.Contains(client.Name) && !x.Quarantined); UserPool.WUsers.ForEachWhere(x => x.QueuePacket(String.IsNullOrEmpty(client.CustomName) ? ib0t.WebOutbound.PublicTo(x, client.Name, text) : ib0t.WebOutbound.NoSuchTo(x, client.CustomName + text)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.IgnoreList.Contains(client.Name) && !x.Quarantined); if (ServerCore.Linker.Busy && ServerCore.Linker.LoginPhase == LinkLeaf.LinkLogin.Ready) { ServerCore.Linker.SendPacket(LinkLeaf.LeafOutbound.LeafPublicText(ServerCore.Linker, client.Name, text)); } Events.TextSent(client, text); } } } }