| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.UI;
- public class DatabaseController : MonoBehaviour
- {
- private string secretKey = "TheNarKampenSecretKey";
- private string questionURL = "http://nordh.xyz:8088/Questions.php?";
- private string categoriesURL = "http://nordh.xyz:8088/Categories.php";
- public Text statusText;
- List<Category> categories = new List<Category>();
- private void Awake()
- {
- StartCoroutine(getCategories());
- }
- private IEnumerator getCategories()
- {
- UnityWebRequest request = UnityWebRequest.Get(categoriesURL);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.Success)
- {
- Debug.Log(request.downloadHandler.text);
- }
- else if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.DataProcessingError)
- {
- Debug.Log("ERROR " + request.downloadHandler.error);
- }
- else
- {
- Debug.Log("OTHER ERROR " + request.responseCode + " " + request.downloadHandler.error);
- }
- }
- public IEnumerator getQuestion()
- {
- Question question = new Question();
- WWW getQuestion = new WWW(questionURL);
- yield return getQuestion;
- if (getQuestion.error != null)
- {
- print("There was an error getting question: " + getQuestion.error);
- }
- else
- {
- statusText.text = getQuestion.text;
- }
- }
- public string Md5Sum(string strToEncrypt)
- {
- System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding();
- byte[] bytes = ue.GetBytes(strToEncrypt);
- // encrypt bytes
- System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
- byte[] hashBytes = md5.ComputeHash(bytes);
- // Convert the encrypted bytes back to a string (base 16)
- string hashString = "";
- for (int i = 0; i < hashBytes.Length; i++)
- {
- hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
- }
- return hashString.PadLeft(32, '0');
- }
- }
|