public static void Start(uint time) { list = new List <IPAddress>(); last = 0; offset = (uint)new Random().Next(20000, 43200); uint tmp = Settings.Get <uint>("tor_time"); if (tmp != 0) { last = tmp; String path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\sb0t\\" + AppDomain.CurrentDomain.FriendlyName + "\\tor.dat"; if (File.Exists(path)) { try { using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { byte[] buf = new byte[4]; lock (list) while (stream.Read(buf, 0, 4) == 4) { list.Add(new IPAddress(buf)); } } } catch { } lock (list) ServerCore.Log("Loaded " + list.Count + " tor addresses from local collection"); } else { last = 0; } } else { Settings.Set("tor_time", time); DownloadTor(); } }
public static void CreateAresClient(Socket sock, ulong time) { try { for (ushort u = 0; u < ushort.MaxValue; u++) { int index = AUsers.FindIndex(x => x.ID == u); if (index == -1) { AUsers.Add(new AresClient(sock, time, u)); AUsers.Sort((x, y) => x.ID.CompareTo(y.ID)); break; } } } catch (Exception e) { ServerCore.Log(e.ToString()); } }
public static void CreateIb0tClient(AresClient client, ulong time) { try { for (ushort u = 700; u < ushort.MaxValue; u++) { int index = WUsers.FindIndex(x => x.ID == u); if (index == -1) { WUsers.Add(new ib0tClient(client, time, u)); WUsers.Sort((x, y) => x.ID.CompareTo(y.ID)); client.Sock = null; AUsers.RemoveAll(x => x.ID == client.ID); break; } } } catch (Exception e) { ServerCore.Log(e.ToString()); } }
public static void Register(IClient client, String password) { if (password.Length < 2) { Events.InvalidRegistration(client); return; } int number_count = password.Count(Char.IsDigit); int letter_count = password.Count(Char.IsLetter); if (number_count == 0 || letter_count == 0) { Events.InvalidRegistration(client); return; } if (Events.Registering(client)) { list.RemoveAll(x => x.Guid.Equals(client.Guid)); using (SQLiteConnection connection = new SQLiteConnection("Data Source=\"" + DataPath + "\"")) { connection.Open(); using (SQLiteCommand command = new SQLiteCommand("delete from accounts where guid=@guid", connection)) { command.Parameters.Add(new SQLiteParameter("@guid", client.Guid.ToString())); command.ExecuteNonQuery(); } } if (client.Level != ILevel.Regular) { client.Level = ILevel.Regular; } byte[] pwd; using (SHA1 sha1 = SHA1.Create()) { pwd = sha1.ComputeHash(Encoding.UTF8.GetBytes(password)); list.Add(new Account { Guid = client.Guid, Level = ILevel.Regular, Name = client.Name, Owner = false, Password = pwd }); } using (SQLiteConnection connection = new SQLiteConnection("Data Source=\"" + DataPath + "\"")) { connection.Open(); String query = @"insert into accounts (name, level, guid, password) values (@name, @level, @guid, @password)"; using (SQLiteCommand command = new SQLiteCommand(query, connection)) { command.Parameters.Add(new SQLiteParameter("@name", client.Name)); command.Parameters.Add(new SQLiteParameter("@level", (int)(byte)client.Level)); command.Parameters.Add(new SQLiteParameter("@guid", client.Guid.ToString())); command.Parameters.Add(new SQLiteParameter("@password", pwd)); command.ExecuteNonQuery(); } } client.Password = pwd; Events.Registered(client); client.Registered = true; Events.LoginGranted(client); ServerCore.Log(client.Name + " has registered"); } }
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; } } } } }