ManaServer.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using LitJson;
  2. using UnityEngine;
  3. using UnityEngine.Events;
  4. using System;
  5. using System.Collections;
  6. using System.Net;
  7. using System.Net.Mail;
  8. using System.Security.Cryptography.X509Certificates;
  9. using UnityEngine.UI;
  10. public class MyCredentials : ICredentialsByHost
  11. {
  12. public NetworkCredential NetworkCredential;
  13. public NetworkCredential GetCredential(string host, int port, string authType)
  14. {
  15. return NetworkCredential.GetCredential(new Uri("http://" + host + ":" + port), authType);
  16. }
  17. public MyCredentials(string username, string password)
  18. {
  19. NetworkCredential = new NetworkCredential(username, password);
  20. }
  21. }
  22. public class ManaServer : Regist
  23. {
  24. #region 变量
  25. public static bool Connect
  26. {
  27. get
  28. {
  29. if (Connect_)
  30. {
  31. return true;
  32. }
  33. else
  34. {
  35. if (ManaTutorial.ConnectExemptAmt > 0)
  36. {
  37. ManaTutorial.ConnectExemptAmt--;
  38. return true;
  39. }
  40. else
  41. {
  42. return false;
  43. }
  44. }
  45. }
  46. set { Connect_ = value; }
  47. }
  48. public static bool Connect_;
  49. public static float Timer;
  50. public static bool LoginComplete;
  51. public static string ReportStr;
  52. public static string ID = "Default";
  53. public static JsonData JsonData;
  54. public static DateTime Time;
  55. #endregion
  56. private void Update()
  57. {
  58. if (!LoginComplete)
  59. {
  60. Timer += UnityEngine.Time.fixedDeltaTime;
  61. if (Timer >= 5)
  62. {
  63. ManaData.LoginCallbackInitial(new JsonData());
  64. }
  65. }
  66. }
  67. public static void Login(URLRequest.URLRequestJsonCallBackDelegate callback = null)
  68. {
  69. URLRequestData urlData = new URLRequestData();
  70. urlData.Add("u", SystemInfo.deviceUniqueIdentifier);
  71. URLRequest.CreateURLRequest("https://garden.dashgame.com/index.php/home/user/login", urlData, LoginCallback + callback, URLRequest.Method.POST);
  72. }
  73. private static void LoginCallback(JsonData jsonData)
  74. {
  75. LoginComplete = true;
  76. if (jsonData["c"].ToJson() == "0")
  77. {
  78. Connect = true;
  79. JsonData = jsonData;
  80. Time = DateUtil.GetTime(jsonData["time"].ToJson());
  81. if (Data._PlayerDoc != null)
  82. {
  83. if (Data.GetPlayerString("ID") == "Default")
  84. {
  85. ID = jsonData["o"].ToString();
  86. if (Initializer.LoadComplete)
  87. {
  88. ManaReso.SetText("L_UserLab", ID);
  89. }
  90. }
  91. }
  92. ManaDebug.Log("<color=red>连接成功</color>");
  93. }
  94. else
  95. {
  96. Connect = false;
  97. ManaDebug.Log("<color=red>连接失败</color>");
  98. }
  99. }
  100. public static void Save()
  101. {
  102. URLRequestData urlData = new URLRequestData();
  103. urlData.Add("u", ID);
  104. Data.SavePlayerConfig();
  105. urlData.Add("l", Data.PlayerDoc.OuterXml);
  106. URLRequest.CreateURLRequest("https://garden.dashgame.com/index.php/home/user/save", urlData, SaveCallback, URLRequest.Method.POST);
  107. }
  108. private static void SaveCallback(JsonData jsonData)
  109. {
  110. ManaDebug.Log("<color=red>发送存档成功</color>");
  111. }
  112. public static void Load(string id, URLRequest.URLRequestJsonCallBackDelegate callback)
  113. {
  114. URLRequestData urlData = new URLRequestData();
  115. urlData.Add("u", id);
  116. URLRequest.CreateURLRequest("https://garden.dashgame.com/index.php/home/user/load", urlData, callback, URLRequest.Method.POST);
  117. }
  118. public static void Report()
  119. {
  120. ManaReso.Get("Lb_Info").TweenBacCG();
  121. string str = ManaReso.Get<Text>("Lb_InputLab").text;
  122. if (string.IsNullOrEmpty(str))
  123. {
  124. Bubble.Show(null, Language.GetStr("UI", "Lb_Send2"));
  125. }
  126. else if(ReportStr == str)
  127. {
  128. Bubble.Show(null, Language.GetStr("UI", "Lb_Send1"));
  129. }
  130. else
  131. {
  132. MailMessage mailMessage = new MailMessage();
  133. mailMessage.To.Add(new MailAddress("bug@dashgame.com"));
  134. mailMessage.From = new MailAddress("dashgamegarden@163.com");
  135. ReportStr = str;
  136. mailMessage.Body = ReportStr;
  137. mailMessage.Subject = ID + " MyLovelyGargen Issue";
  138. SmtpClient smtpClient = new SmtpClient("smtp.163.com");
  139. smtpClient.Credentials = new MyCredentials("dashgamegarden@163.com", "cs670cs");
  140. smtpClient.SendAsync(mailMessage, "Async");
  141. Bubble.Show(null, Language.GetStr("UI", "Lb_Send0"));
  142. }
  143. }
  144. }