// Update is called once per frame void Update() { if (IsPause.Equals(false) && IsTimeOver.Equals(false)) { CurrentTime -= Time.deltaTime; TimerText.text = string.Format("Time \r\n{0}", (int)CurrentTime); if (CurrentTime < 0.0f) { IsTimeOver = true; } } }
private void ProcessApiDataResponse(HttpListenerRequest request, HttpListenerResponse response) { if (response != null) { Task.Factory.StartNew(() => { try { var requestJSON = string.Empty; JObject jResponse = null; if (request.HasEntityBody) { using (var body = request.InputStream) using (var reader = new System.IO.StreamReader(body, request.ContentEncoding)) requestJSON = reader.ReadToEnd(); } try { var jRequest = (JObject)JsonConvert.DeserializeObject(requestJSON); var jMethodName = jRequest.SelectToken("$.method").Value <string>(); switch (jMethodName) { case RequestMethods.GetMinerAddress: jResponse = GetMasterResult(m_minerEthAddress); break; case RequestMethods.GetMaximumTarget: jResponse = GetMasterResult(m_maxTarget); break; case RequestMethods.GetKingAddress: jResponse = GetMasterResult(m_kingEthAddress); break; case RequestMethods.GetChallenge: jResponse = GetMasterResult(m_challenge); break; case RequestMethods.GetDifficulty: jResponse = GetMasterResult(m_difficulty); break; case RequestMethods.GetTarget: jResponse = GetMasterResult(m_target); break; case RequestMethods.GetPause: jResponse = GetMasterResult(IsPause.ToString()); break; case RequestMethods.GetPoolMining: jResponse = GetMasterResult(NetworkInterface.IsPool.ToString()); break; case RequestMethods.SubmitSolution: var slaveURL = request.RemoteEndPoint.ToString(); Program.Print("[INFO] Solution received from slave URL: http://" + slaveURL); var jParams = jRequest.SelectToken("$.params").Value <JArray>(); var digest = Utils.Numerics.HexStringToByte32Array(jParams[0].Value <string>()); var challenge = Utils.Numerics.HexStringToByte32Array(jParams[1].Value <string>()); var difficulty = Utils.Numerics.HexStringToByte32Array(jParams[2].Value <string>()); var nonce = Utils.Numerics.HexStringToByte32Array(jParams[3].Value <string>()); var difficultyBigInteger = new HexBigInteger(new BigInteger(difficulty, isUnsigned: true, isBigEndian: true)); var result = NetworkInterface.SubmitSolution(m_minerEthAddress, digest, challenge, difficultyBigInteger, nonce, this); jResponse = GetMasterResult(result.ToString()); break; } } catch (Exception ex) { HandleException(ex); } var buffer = Encoding.UTF8.GetBytes(Utils.Json.SerializeFromObject(jResponse)); if (buffer != null) { using (var output = response.OutputStream) { output.Write(buffer, 0, buffer.Length); output.Flush(); } } } catch (Exception ex) { response.StatusCode = (int)HttpStatusCode.InternalServerError; HandleException(ex); } finally { try { response.Close(); } catch (Exception ex) { HandleException(ex); } } }, TaskCreationOptions.LongRunning); } }