protected override void _Login(LoginParamValue[] LoginParams) { try { privkey = LoginParams[0].Value; 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) { callError("error: ", true, ErrorType.Other); callLoginFinished(false); return; } string address = ""; string message = ""; try { NBitcoin.Key tmpkey = NBitcoin.Key.Parse(privkey, NBitcoin.Network.Main); address = tmpkey.ScriptPubKey.GetDestinationAddress(NBitcoin.Network.GetNetwork("Main")).ToString(); message = tmpkey.SignMessage(tmp.result); } catch (Exception e) { callError("API key format error. Are you using your Private key?", true, ErrorType.Other); callLoginFinished(false); return; } 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) { callError("error: " + challenge, true, ErrorType.Other); callLoginFinished(false); return; } uid = tmologin.result.id; this.username = tmologin.result.name; frstchallenge = string.Format(basestring, id++, "read_user_coin_data", ",\"params\":{\"selector\":{\"id\":\"" + uid + "_" + CurrentCurrency.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) { callError("error: " + challenge, true, ErrorType.Other); callLoginFinished(false); return; } if (tmpstats != null) { Stats.Balance = (decimal)tmpstats.balance / 100000000m; Stats.Bets = (int)tmpstats.bets; Stats.Wins = (int)tmpstats.wins; Stats.Losses = (int)tmpstats.losses; Stats.Profit = (decimal)tmpstats.profit / 100000000m; Stats.Wagered = (decimal)tmpstats.wagered / 100000000m; ispd = true; lastupdate = DateTime.Now; new Thread(new ThreadStart(BalanceThread)).Start(); new Thread(new ThreadStart(Beginreadthread)).Start(); Thread.Sleep(50); callLoginFinished(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) { Logger.DumpLog(e); } callLoginFinished(false); }
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) { Logger.DumpLog(e); callError("error: " + challenge, true, ErrorType.Unknown); /*finishedlogin(false); * return;*/ } NBitcoin.Key tmpkey = NBitcoin.Key.Parse(privkey, NBitcoin.Network.Main); 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) { Logger.DumpLog(e); callError("error: " + challenge, true, ErrorType.Unknown); /*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 + "_" + CurrentCurrency.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) { callError("error: " + challenge, true, ErrorType.Unknown); /*finishedlogin(false); * return;*/ } if (tmpstats != null) { Stats.Balance = (decimal)tmpstats.balance / 100000000m; Stats.Bets = (int)tmpstats.bets; Stats.Wins = (int)tmpstats.wins; Stats.Losses = (int)tmpstats.losses; Stats.Profit = (decimal)tmpstats.profit / 100000000m; Stats.Wagered = (decimal)tmpstats.wagered / 100000000m; ispd = true; lastupdate = DateTime.Now; new Thread(new ThreadStart(BalanceThread)).Start(); new Thread(new ThreadStart(Beginreadthread)).Start(); inauth = false; return; } } } catch (Exception e) { } //finishedlogin(false); inauth = false; }