ManaServer.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 (!ManaData.InitiateComplete)
  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. ManaReso.SetText("L_UserLab", ID);
  87. }
  88. }
  89. ManaDebug.Log("<color=red>连接成功</color>");
  90. }
  91. else
  92. {
  93. Connect = false;
  94. ManaDebug.Log("<color=red>连接失败</color>");
  95. }
  96. }
  97. public static void Save()
  98. {
  99. URLRequestData urlData = new URLRequestData();
  100. urlData.Add("u", ID);
  101. Data.SavePlayerConfig();
  102. urlData.Add("l", Data.PlayerDoc.OuterXml);
  103. URLRequest.CreateURLRequest("https://garden.dashgame.com/index.php/home/user/save", urlData, SaveCallback, URLRequest.Method.POST);
  104. }
  105. private static void SaveCallback(JsonData jsonData)
  106. {
  107. ManaDebug.Log("<color=red>发送存档成功</color>");
  108. }
  109. public static void Load(string id, URLRequest.URLRequestJsonCallBackDelegate callback)
  110. {
  111. URLRequestData urlData = new URLRequestData();
  112. urlData.Add("u", id);
  113. URLRequest.CreateURLRequest("https://garden.dashgame.com/index.php/home/user/load", urlData, callback, URLRequest.Method.POST);
  114. }
  115. public static void Report()
  116. {
  117. ManaReso.Get("Lb_Info").TweenBacCG();
  118. string str = ManaReso.Get<Text>("Lb_InputLab").text;
  119. if (string.IsNullOrEmpty(str))
  120. {
  121. Bubble.Show(null, Language.GetStr("UI", "Lb_Send2"));
  122. }
  123. else if(ReportStr == str)
  124. {
  125. Bubble.Show(null, Language.GetStr("UI", "Lb_Send1"));
  126. }
  127. else
  128. {
  129. MailMessage mailMessage = new MailMessage();
  130. mailMessage.To.Add(new MailAddress("bug@dashgame.com"));
  131. mailMessage.From = new MailAddress("dashgamegarden@163.com");
  132. ReportStr = str;
  133. mailMessage.Body = ReportStr;
  134. mailMessage.Subject = ID + " MyLovelyGargen Issue";
  135. SmtpClient smtpClient = new SmtpClient("smtp.163.com");
  136. smtpClient.Credentials = new MyCredentials("dashgamegarden@163.com", "cs670cs");
  137. smtpClient.SendAsync(mailMessage, "Async");
  138. Bubble.Show(null, Language.GetStr("UI", "Lb_Send0"));
  139. }
  140. }
  141. }