Esempio n. 1
0
        public Client(string email, string password)
        {
            this.ClientSetup();

            Dictionary <string, string> values = new Dictionary <string, string>()
            {
                { "captcha_key", null },
                { "email", email },
                { "gift_code_sku_id", null },
                { "login_source", null },
                { "password", password },
                { "undelete", null }
            };

            string json = JsonConvert.SerializeObject(values);

            HttpWebRequest request = (HttpWebRequest)WebRequest.CreateHttp(ApiBase + "auth/login");

            request.ContentType = "application/json";
            request.Method      = "POST";
            using (StreamWriter sw = new StreamWriter(request.GetRequestStream()))
            {
                sw.Write(json);
                sw.Flush();
                sw.Close();
            }

            using (StreamReader reader = new StreamReader(request.GetResponse().GetResponseStream()))
            {
                JObject jObj = JObject.Parse(reader.ReadToEnd());
                if (jObj["mfa"].ToObject <bool>() == true)
                {
                    string ticket = jObj["ticket"].ToString();

                    this.SendSMSCodeRequest(ticket);

                    Console.Write("Enter code: ");
                    string code = Console.ReadLine();
                    Dictionary <string, string> param = new Dictionary <string, string>();
                    param.Add("code", code);
                    param.Add("ticket", ticket);
                    string         vals = JsonConvert.SerializeObject(param);
                    HttpWebRequest req  = (HttpWebRequest)WebRequest.CreateHttp(ApiBase + "auth/mfa/sms");
                    req.ContentType = "application/json";
                    req.Method      = "POST";
                    using (StreamWriter sw = new StreamWriter(req.GetRequestStream()))
                    {
                        sw.Write(vals);
                        sw.Flush();
                        sw.Close();
                    }

                    using (StreamReader r = new StreamReader(req.GetResponse().GetResponseStream()))
                    {
                        jObj = JObject.Parse(r.ReadToEnd());
                    }
                }
                _token = jObj["token"].ToString();
            }

            ConnectionProperties connectionProperties = new ConnectionProperties();

            connectionProperties.Os      = "Windows 10";
            connectionProperties.Browser = "Firefox";
            connectionProperties.Device  = "Laptop";

            this.WebSocketSetup();

            this.HeartBeat();
            this.OpcodeIdentify(connectionProperties);
        }