· 6 years ago · Feb 25, 2019, 09:12 PM
1using UnityEngine;
2using System.Collections;
3
4public class GUI_postscore : MonoBehaviour
5{
6 private string secretKey = "xxx";
7 private string addScoreURL = "xxx";
8 private string CheckIfLoggedInURL = "xxx";
9
10 public string username;
11 public int puks;
12 public int time;
13 public int points;
14 public string post_url;
15
16 public GameObject savedGUI;
17 public GameObject thisGUI;
18 private bool backgroundcheckeractive = false;
19
20 void OnMouseDown()
21 {
22 StartCoroutine("CheckIfLoggedinFlash");
23 }
24
25
26 IEnumerator CheckIfLoggedinFlash()
27 {
28
29 StopCoroutine("CheckBackGroundLogin");
30
31 WWWCaller wwwCaller = new WWWCaller();
32 wwwCaller.DoWebRequest(CheckIfLoggedInURL);
33
34 while(WWWCaller.response == "No response yet."){yield return null;}
35
36 if(WWWCaller.response != "0")
37 {
38 Debug.Log ("we are logged in, Posting score");
39 username = GameSetup.SP.Username;
40 puks = GameSetup.SP.totalpuks;
41 time = GameSetup.SP.totaltime;
42 points = GameSetup.SP.CurrentScore;
43
44 StartCoroutine(PostScores(username,time,puks,points));
45 }
46 else
47 {
48 Debug.Log ("we are not logged in, opening Login HTML GUI");
49 if(!backgroundcheckeractive){BrowserCommunicatorHighScore.TestCommunication(); StartCoroutine("CheckBackGroundLogin");backgroundcheckeractive = true;}
50 }
51 StopCoroutine("CheckIfLoggedinFlash");
52 }
53
54
55 IEnumerator CheckBackGroundLogin()
56 {
57 yield return new WaitForSeconds(1);
58 Debug.Log ("CheckIfLoggedinFlash");
59 StartCoroutine("CheckIfLoggedinFlash");
60 }
61
62
63
64 IEnumerator PostScores(string username, int time, int puks, int points)
65 {
66 string hash = MD5Wrapper.Md5Sum(time + puks + points + secretKey);
67
68 post_url = addScoreURL + "time=" + time + "&puks=" + puks + "&points=" + points + "&hash=" + hash;
69
70 WWWCaller wwwCaller = new WWWCaller();
71 wwwCaller.DoWebRequest(post_url);
72 while(WWWCaller.response == "No response yet."){yield return null;}
73
74 if(WWWCaller.response == "Success.\n" || WWWCaller.response == "Success.")
75 {
76 savedGUI.SetActive(true);
77 savedGUI.animation.Play("TutorialGUI_Anim02");
78 thisGUI.animation.enabled = true;
79 thisGUI.animation.Play("TutorialGUI_Anim01");
80 }
81 }
82
83
84
85}