Example #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            LoadProxies();
            db = Database.Get();

            foreach (SocksProxy.Proxy p in proxyList)
            {
                ChatangoAccount newAccount;

                if (db.ContainsKey(p.ToString()))
                {
                    newAccount = db[p.ToString()];
                    clients.Add(new ChatangoSocksClient(newAccount));
                    Console.WriteLine("Loaded account from db: " + newAccount.username);
                }
                else
                {
                    newAccount = new ChatangoAccount(null, null, p);
                    clients.Add(new ChatangoSocksClient(newAccount));
                    Console.WriteLine("Trying to create account: " + newAccount.username);
                }
            }

            listBox1.DataSource = clients;
            this.Show();
        }
Example #2
0
        public static void Delete(ChatangoAccount chAccount)
        {
            string key = chAccount.proxy.ToString();

            lock (dbLock)
            {
                db.Remove(key);
            }

            Save();
        }
Example #3
0
        public static void Add(ChatangoAccount chAccount)
        {
            string key = chAccount.proxy.ToString();

            lock (dbLock)
            {
                db[key] = chAccount;
            }

            Save();
        }
Example #4
0
        public static Dictionary <string, ChatangoAccount> Get()
        {
            lock (dbLock)
            {
                // access file, load db
                string[] accounts;

                if (Initialized)
                {
                    return(db);
                }
                else
                {
                    db          = new Dictionary <string, ChatangoAccount>();
                    Initialized = true;
                }

                try
                {
                    accounts = File.ReadAllLines(dbName);
                }
                catch (FileNotFoundException)
                {
                    File.Create(dbName);
                    return(db.DeepClone());
                }

                foreach (string account in accounts)
                {
                    string[]        items     = account.Split(':');
                    string          key       = items[0] + ":" + items[1] + ":" + items[2];
                    ChatangoAccount chAccount = new ChatangoAccount(
                        items[3],
                        items[4],
                        new SocksProxy.Proxy(
                            items[0],
                            items[1],
                            (items[2] == "SOCKS5" ? SocksProxy.ProxyType.SOCKS5 : SocksProxy.ProxyType.SOCKS4)
                            )
                        );
                    db[key] = chAccount;
                }
            }

            lock (dbLock)
            {
                return(db.DeepClone());
            }
        }
    public ChatangoSocksClient(ChatangoAccount account)
        : base(account.proxy)
    {
        this.incompletePacketData = "";
        this.account = account;

        onReceiveCallback = ChOnRecieve;
        //onConnectCallback = ChOnConnect;
        onCloseCallback = ChOnClose;

        if (this.account.exists)
        {
            GetAuthID();
        }
        else
        {
            CreateAccount();
        }
    }
Example #6
0
        private static void Save()
        {
            lock (dbLock)
            {
                File.Delete(dbName);
                List <string> lines = new List <string>();
                foreach (string key in db.Keys)
                {
                    ChatangoAccount chAccount = db[key];
                    string          data      =
                        chAccount.proxy.ToString() + ":" +
                        chAccount.username + ":" +
                        chAccount.password;
                    lines.Add(data);
                }

                File.WriteAllLines(dbName, lines.ToArray());
            }
        }