예제 #1
0
 public static void Logout(IClient client)
 {
     client.Registered = false;
     client.Level      = ILevel.Regular;
     Events.Logout(client);
     ServerCore.Log(client.Name + " logged out");
 }
예제 #2
0
        public static void Unregister(IClient client)
        {
            if (!client.Registered || client.Owner || client.Password == null)
            {
                return;
            }

            Account a = list.Find(x => x.Guid.Equals(client.Guid));

            if (a != null)
            {
                list.RemoveAll(x => x.Guid.Equals(client.Guid));
                client.Level      = ILevel.Regular;
                client.Registered = false;

                using (SQLiteConnection connection = new SQLiteConnection("Data Source=\"" + DataPath + "\""))
                {
                    connection.Open();

                    String query = @"delete from accounts
                                     where guid=@guid";

                    using (SQLiteCommand command = new SQLiteCommand(query, connection))
                    {
                        command.Parameters.Add(new SQLiteParameter("@guid", client.Guid.ToString()));
                        command.ExecuteNonQuery();
                    }
                }

                Events.Unregistered(client);
                ServerCore.Log(client.Name + " has unregistered " + a.Name + "'s account");
            }
        }
예제 #3
0
 public void EnforceRules(ulong time)
 {
     if ((!this.LoggedIn && time > (this.Time + 15000)) ||
         (this.LoggedIn && time > (this.Time + 240000)))
     {
         this.SocketConnected = false;
         ServerCore.Log("ping timeout or login timeout from " + this.ExternalIP + " id: " + this.ID);
     }
 }
예제 #4
0
        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);
        }
예제 #5
0
        private static void DownloadTor()
        {
            new Thread(new ThreadStart(() =>
            {
                try
                {
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.dan.me.uk/torlist/");
                    request.Host           = "www.dan.me.uk";
                    request.UserAgent      = String.Empty;

                    using (WebResponse response = request.GetResponse())
                        using (Stream stream = response.GetResponseStream())
                            using (StreamReader reader = new StreamReader(stream))
                            {
                                String page    = reader.ReadToEnd();
                                String[] split = page.Split(new String[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);

                                lock (list)
                                {
                                    list.Clear();
                                    IPAddress ip;

                                    for (int i = 0; i < split.Length; i++)
                                    {
                                        if (IPAddress.TryParse(split[i], out ip))
                                        {
                                            list.Add(ip);
                                        }
                                    }
                                }

                                String path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
                                              "\\sb0t\\" + AppDomain.CurrentDomain.FriendlyName + "\\tor.dat";

                                try
                                {
                                    lock (list)
                                    {
                                        List <byte> buf = new List <byte>();

                                        foreach (IPAddress ip in list)
                                        {
                                            buf.AddRange(ip.GetAddressBytes());
                                        }

                                        File.WriteAllBytes(path, buf.ToArray());
                                        ServerCore.Log("Downloaded " + list.Count + " tor addresses from remote collection");
                                    }
                                }
                                catch { }
                            }
                }
                catch { }
            })).Start();
        }
예제 #6
0
        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();
            }
        }
예제 #7
0
        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());
            }
        }
예제 #8
0
        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());
            }
        }
예제 #9
0
        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");
            }
        }
예제 #10
0
        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;
                        }
                    }
                }
            }
        }