示例#1
0
        void Auth()
        {
            inauth = true;
            try
            {
                apiclient.Close();
            }
            catch { }
            try
            {
                apiclient = new TcpClient();

                apiclient.Connect("api.yolodice.com", 4444);
                if (apiclient.Connected)
                {
                    sslStream = new SslStream(apiclient.GetStream());
                    sslStream.AuthenticateAsClient("https://api.yolodice.com");

                    string frstchallenge = string.Format(basestring, id++, "generate_auth_challenge", "");

                    sslStream.Write(Encoding.ASCII.GetBytes(frstchallenge));
                    int bytes = sslStream.Read(ReadBuffer, 0, 512);
                    challenge = Encoding.ASCII.GetString(ReadBuffer, 0, bytes);
                    YLChallenge tmp = null;
                    try
                    {
                        tmp = json.JsonDeserialize <YLChallenge>(challenge);
                    }
                    catch (Exception e)
                    {
                        Parent.updateStatus("error: " + challenge);

                        /*finishedlogin(false);
                         * return;*/
                    }
                    NBitcoin.Key tmpkey  = NBitcoin.Key.Parse(privkey);
                    string       address = tmpkey.ScriptPubKey.GetDestinationAddress(NBitcoin.Network.GetNetwork("Main")).ToString();
                    string       message = tmpkey.SignMessage(tmp.result);

                    frstchallenge = string.Format(basestring, id++, "auth_by_address", ",\"params\":" + json.JsonSerializer <YLAuthSend>(new YLAuthSend {
                        address = address, signature = message
                    }));

                    sslStream.Write(Encoding.ASCII.GetBytes(frstchallenge));
                    bytes     = sslStream.Read(ReadBuffer, 0, 512);
                    challenge = Encoding.ASCII.GetString(ReadBuffer, 0, bytes);
                    YLOgin tmologin = null;
                    try
                    {
                        tmologin = json.JsonDeserialize <YLOgin>(challenge);
                    }
                    catch (Exception e)
                    {
                        Parent.updateStatus("error: " + challenge);

                        /*finishedlogin(false);
                         * return;*/
                    }

                    uid           = tmologin.result.id;
                    this.username = tmologin.result.name;
                    frstchallenge = string.Format(basestring, id++, "read_user_coin_data", ",\"params\":{\"selector\":{\"id\":\"" + uid + "_" + Currency.ToLower() + "\"}}");
                    sslStream.Write(Encoding.ASCII.GetBytes(frstchallenge));
                    bytes     = sslStream.Read(ReadBuffer, 0, 512);
                    challenge = Encoding.ASCII.GetString(ReadBuffer, 0, bytes);
                    YLUserStats tmpstats = null;
                    try
                    {
                        tmpstats = json.JsonDeserialize <YLUserStats>(challenge).result;
                    }
                    catch (Exception e)
                    {
                        Parent.updateStatus("error: " + challenge);

                        /*finishedlogin(false);
                         * return;*/
                    }

                    if (tmpstats != null)
                    {
                        balance = (decimal)tmpstats.balance / 100000000m;
                        bets    = (int)tmpstats.bets;
                        wins    = (int)tmpstats.wins;
                        losses  = (int)tmpstats.losses;
                        profit  = (decimal)tmpstats.profit / 100000000m;
                        wagered = (decimal)tmpstats.wagered / 100000000m;
                        Parent.updateBalance(balance);
                        Parent.updateBets(bets);
                        Parent.updateWins(wins);
                        Parent.updateLosses(losses);
                        Parent.updateProfit(profit);
                        Parent.updateWagered(wagered);
                        ispd       = true;
                        lastupdate = DateTime.Now;
                        new Thread(new ThreadStart(BalanceThread)).Start();
                        new Thread(new ThreadStart(Beginreadthread)).Start();
                        //sslStream.BeginRead(ReadBuffer, 0, 512, ReadTCP, sslStream);
                        //Write("read_current_seed", "{\"selector\":{\"user_id\":" + uid + "}}");
                        //privkey = Password;
                        //Thread.Sleep(50);
                        //finishedlogin(true);
                        inauth = false;

                        return;
                    }
                    //tmp2.ImportPrivKey(Password, "", false);
                    //string message = tmp2.SignMessage(username, tmp.result);
                    //string message = //FullSignatureTest(tmp.result, new AsymmetricCipherKeyPair("", ""));


                    /*ispd = true;
                     * new Thread(new ThreadStart(BalanceThread)).Start();*/
                }
            }
            catch (Exception e)
            {
            }
            //finishedlogin(false);
            inauth = false;
        }
示例#2
0
        //long uid = 0;
        public override void Login(string Username, string Password, string twofa)
        {
            try
            {
                apiclient = new TcpClient();

                apiclient.Connect("api.yolodice.com", 4444);
                if (apiclient.Connected)
                {
                    sslStream = new SslStream(apiclient.GetStream());
                    sslStream.AuthenticateAsClient("api.yolodice.com");//, null, System.Security.Authentication.SslProtocols.Ssl2| System.Security.Authentication.SslProtocols.Ssl3| System.Security.Authentication.SslProtocols.Tls11|System.Security.Authentication.SslProtocols.Tls12, false);

                    string frstchallenge = string.Format(basestring, id++, "generate_auth_challenge", "");

                    sslStream.Write(Encoding.ASCII.GetBytes(frstchallenge));
                    int bytes = sslStream.Read(ReadBuffer, 0, 512);
                    challenge = Encoding.ASCII.GetString(ReadBuffer, 0, bytes);
                    YLChallenge tmp = null;
                    try
                    {
                        tmp = json.JsonDeserialize <YLChallenge>(challenge);
                    }
                    catch (Exception e)
                    {
                        Parent.updateStatus("error: " + challenge);
                        finishedlogin(false);
                        return;
                    }
                    string address = "";
                    string message = "";
                    try
                    {
                        NBitcoin.Key tmpkey = NBitcoin.Key.Parse(Password);
                        address = tmpkey.ScriptPubKey.GetDestinationAddress(NBitcoin.Network.GetNetwork("Main")).ToString();
                        message = tmpkey.SignMessage(tmp.result);
                    }
                    catch (Exception e)
                    {
                        Parent.updateStatus("API key format error. Are you using your Private key?");
                        finishedlogin(false);
                        return;
                    }
                    frstchallenge = string.Format(basestring, id++, "auth_by_address", ",\"params\":" + json.JsonSerializer <YLAuthSend>(new YLAuthSend {
                        address = address, signature = message
                    }));
                    //{"id":1,"method":"auth_by_address","params":{"address":"n3kmufwdR3Zzgk3k6NYeeLBxB9SpHKe5Tc","signature":"H4W6yMaVK6EzrTw/9jqmLh1lvoyFnxCFqRon2g25lJ7FTCAUHGJWWF3UJD5wCzCVafdjIfCmIYH2KyHboodjjcU="}}

                    //{"id":1,"method":"auth_by_address","params":{"address":"1PUgaiHavJrpi7r7JhkhwWj7Kf9Ls68Z6w","signature":"Hz0oh29Nho+bVz7zggS1dqx\/N7VAyD6jsk8k98qW84ild7D71Q9rUbmEE4GIj0a5eKPcK1EjvSEwwa74jBJRyY8="}}

                    sslStream.Write(Encoding.ASCII.GetBytes(frstchallenge));
                    bytes     = sslStream.Read(ReadBuffer, 0, 512);
                    challenge = Encoding.ASCII.GetString(ReadBuffer, 0, bytes);
                    YLOgin tmologin = null;
                    try
                    {
                        tmologin = json.JsonDeserialize <YLOgin>(challenge);
                    }
                    catch (Exception e)
                    {
                        Parent.updateStatus("error: " + challenge);
                        finishedlogin(false);
                        return;
                    }

                    uid           = tmologin.result.id;
                    this.username = tmologin.result.name;
                    frstchallenge = string.Format(basestring, id++, "read_user_coin_data", ",\"params\":{\"selector\":{\"id\":\"" + uid + "_" + Currency.ToLower() + "\"}}");
                    sslStream.Write(Encoding.ASCII.GetBytes(frstchallenge));
                    bytes     = sslStream.Read(ReadBuffer, 0, 512);
                    challenge = Encoding.ASCII.GetString(ReadBuffer, 0, bytes);
                    YLUserStats tmpstats = null;
                    try
                    {
                        tmpstats = json.JsonDeserialize <YLUserStats>(challenge).result;
                    }
                    catch (Exception e)
                    {
                        Parent.updateStatus("error: " + challenge);
                        finishedlogin(false);
                        return;
                    }

                    if (tmpstats != null)
                    {
                        balance = (decimal)tmpstats.balance / 100000000m;
                        bets    = (int)tmpstats.bets;
                        wins    = (int)tmpstats.wins;
                        losses  = (int)tmpstats.losses;
                        profit  = (decimal)tmpstats.profit / 100000000m;
                        wagered = (decimal)tmpstats.wagered / 100000000m;
                        Parent.updateBalance(balance);
                        Parent.updateBets(bets);
                        Parent.updateWins(wins);
                        Parent.updateLosses(losses);
                        Parent.updateProfit(profit);
                        Parent.updateWagered(wagered);
                        ispd       = true;
                        lastupdate = DateTime.Now;
                        new Thread(new ThreadStart(BalanceThread)).Start();
                        privkey = Password;
                        new Thread(new ThreadStart(Beginreadthread)).Start();
                        Thread.Sleep(50);
                        finishedlogin(true);

                        return;
                    }
                    //tmp2.ImportPrivKey(Password, "", false);
                    //string message = tmp2.SignMessage(username, tmp.result);
                    //string message = //FullSignatureTest(tmp.result, new AsymmetricCipherKeyPair("", ""));


                    /*ispd = true;
                     * new Thread(new ThreadStart(BalanceThread)).Start();*/
                }
            }
            catch (Exception e)
            {
                Parent.DumpLog(e.ToString(), 0);
            }
            finishedlogin(false);
        }