ManaServer.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 System.Text;
  10. using UnityEngine.UI;
  11. public class MyCredentials : ICredentialsByHost
  12. {
  13. public NetworkCredential NetworkCredential;
  14. public NetworkCredential GetCredential(string host, int port, string authType)
  15. {
  16. return NetworkCredential.GetCredential(new Uri("http://" + host + ":" + port), authType);
  17. }
  18. public MyCredentials(string username, string password)
  19. {
  20. NetworkCredential = new NetworkCredential(username, password);
  21. }
  22. }
  23. public class ManaServer : Regist
  24. {
  25. #region 变量
  26. public static bool Connect
  27. {
  28. get
  29. {
  30. if (Connect_)
  31. {
  32. return true;
  33. }
  34. else
  35. {
  36. if (ManaTutorial.ConnectExemptAmt > 0)
  37. {
  38. ManaTutorial.ConnectExemptAmt--;
  39. return true;
  40. }
  41. else
  42. {
  43. return false;
  44. }
  45. }
  46. }
  47. set { Connect_ = value; }
  48. }
  49. public static bool Connect_;
  50. public static float Timer;
  51. public static bool LoginComplete;
  52. public static string ReportStr;
  53. public static string ID = "Default";
  54. public static JsonData JsonData;
  55. public static DateTime Time;
  56. #endregion
  57. private void Update()
  58. {
  59. if (!ManaData.InitiateComplete)
  60. {
  61. Timer += UnityEngine.Time.fixedDeltaTime;
  62. if (Timer >= 5)
  63. {
  64. ManaData.LoginCallbackInitial(new JsonData());
  65. }
  66. }
  67. }
  68. public static void Login(URLRequest.URLRequestJsonCallBackDelegate callback = null)
  69. {
  70. URLRequestData urlData = new URLRequestData();
  71. urlData.Add("u", SystemInfo.deviceUniqueIdentifier);
  72. URLRequest.CreateURLRequest("https://garden.dashgame.com/index.php/home/user/login", urlData, LoginCallback + callback, URLRequest.Method.POST);
  73. }
  74. private static void LoginCallback(JsonData jsonData)
  75. {
  76. try
  77. {
  78. LoginComplete = true;
  79. if (jsonData.Inst_Object.ContainsKey("c") && jsonData["c"].ToJson() == "0")
  80. {
  81. Connect = true;
  82. JsonData = jsonData;
  83. Time = DateUtil.GetTime(jsonData["time"].ToJson());
  84. if (Data._PlayerDoc != null)
  85. {
  86. if (Data.GetPlayerString("ID") == "Default")
  87. {
  88. ID = jsonData["o"].ToString();
  89. if (Initializer.LoadComplete)
  90. {
  91. ManaReso.SetText("L_UserLab", ID);
  92. }
  93. }
  94. }
  95. ManaDebug.Log("<color=red>连接成功</color>");
  96. }
  97. else
  98. {
  99. Connect = false;
  100. ManaDebug.Log("<color=red>连接失败</color>");
  101. }
  102. }
  103. catch (Exception e)
  104. {
  105. ManaDebug.Log(e.Message);
  106. ManaDebug.Log(jsonData.ToJson());
  107. ManaDebug.Log("如果看到这个Bug,把上面的调试信息发给我,thank you");
  108. Debug.Log(e.Message);
  109. Debug.Log(jsonData.ToJson());
  110. Debug.LogError("如果看到这个Bug,把上面的调试信息发给我,thank you");
  111. }
  112. }
  113. public static void Save()
  114. {
  115. URLRequestData urlData = new URLRequestData();
  116. urlData.Add("u", ID);
  117. Data.SavePlayerConfig();
  118. urlData.Add("l", Data.PlayerDoc.OuterXml);
  119. URLRequest.CreateURLRequest("https://garden.dashgame.com/index.php/home/user/save", urlData, SaveCallback, URLRequest.Method.POST);
  120. }
  121. private static void SaveCallback(JsonData jsonData)
  122. {
  123. ManaDebug.Log("<color=red>发送存档成功</color>");
  124. }
  125. public static void Load(string id, URLRequest.URLRequestJsonCallBackDelegate callback)
  126. {
  127. URLRequestData urlData = new URLRequestData();
  128. urlData.Add("u", id);
  129. URLRequest.CreateURLRequest("https://garden.dashgame.com/index.php/home/user/load", urlData, callback, URLRequest.Method.POST);
  130. }
  131. public static void Report()
  132. {
  133. ManaReso.Get("Lb_Info").TweenBacCG();
  134. string str = ManaReso.Get<Text>("Lb_InputLab").text;
  135. if (string.IsNullOrEmpty(str))
  136. {
  137. Bubble.Show(null, Language.GetStr("UI", "Lb_Send2"));
  138. }
  139. else if(ReportStr == str)
  140. {
  141. Bubble.Show(null, Language.GetStr("UI", "Lb_Send1"));
  142. }
  143. else
  144. {
  145. MailMessage mailMessage = new MailMessage();
  146. mailMessage.To.Add(new MailAddress("bug@dashgame.com"));
  147. mailMessage.From = new MailAddress("dashgamegarden@163.com");
  148. ReportStr = str;
  149. mailMessage.Body = ReportStr + '\n' + GetSystemInfo();
  150. mailMessage.Subject = ID + " MyLovelyGargen Issue";
  151. SmtpClient smtpClient = new SmtpClient("smtp.163.com");
  152. smtpClient.Credentials = new MyCredentials("dashgamegarden@163.com", "cs670cs");
  153. smtpClient.SendAsync(mailMessage, "Async");
  154. Bubble.Show(null, Language.GetStr("UI", "Lb_Send0"));
  155. }
  156. }
  157. public static string GetSystemInfo()
  158. {
  159. StringBuilder sb = new StringBuilder();
  160. sb.AppendLine("deviceType :" + SystemInfo.deviceType.ToString());
  161. sb.AppendLine("deviceName :" + SystemInfo.deviceName.ToString());
  162. sb.AppendLine("deviceModel :" + SystemInfo.deviceModel.ToString());
  163. sb.AppendLine("deviceUniqueIdentifier :" + SystemInfo.deviceUniqueIdentifier.ToString());
  164. sb.AppendLine("graphicsDeviceID :" + SystemInfo.graphicsDeviceID.ToString());
  165. sb.AppendLine("graphicsDeviceType :" + SystemInfo.graphicsDeviceType.ToString());
  166. sb.AppendLine("graphicsDeviceName :" + SystemInfo.graphicsDeviceName.ToString());
  167. sb.AppendLine("graphicsShaderLevel :" + SystemInfo.graphicsShaderLevel.ToString());
  168. sb.AppendLine("graphicsMemorySize :" + SystemInfo.graphicsMemorySize.ToString());
  169. sb.AppendLine("graphicsDeviceVersion :" + SystemInfo.graphicsDeviceVersion.ToString());
  170. sb.AppendLine("graphicsMultiThreaded :" + SystemInfo.graphicsMultiThreaded.ToString());
  171. sb.AppendLine("graphicsDeviceVendor :" + SystemInfo.graphicsDeviceVendor.ToString());
  172. sb.AppendLine("graphicsDeviceVendorID :" + SystemInfo.graphicsDeviceVendorID.ToString());
  173. sb.AppendLine("npotSupport :" + SystemInfo.npotSupport.ToString());
  174. sb.AppendLine("maxTextureSize :" + SystemInfo.maxTextureSize.ToString());
  175. sb.AppendLine("operatingSystem :" + SystemInfo.operatingSystem.ToString());
  176. sb.AppendLine("operatingSystemFamily :" + SystemInfo.operatingSystemFamily.ToString());
  177. sb.AppendLine("processorType :" + SystemInfo.processorType.ToString());
  178. sb.AppendLine("processorCount :" + SystemInfo.processorCount.ToString());
  179. sb.AppendLine("processorFrequency :" + SystemInfo.processorFrequency.ToString());
  180. sb.AppendLine("copyTextureSupport :" + SystemInfo.copyTextureSupport.ToString());
  181. sb.AppendLine("graphicsMultiThreaded :" + SystemInfo.graphicsMultiThreaded.ToString());
  182. sb.AppendLine("supportedRenderTargetCount :" + SystemInfo.supportedRenderTargetCount.ToString());
  183. sb.AppendLine("supports3DTextures :" + SystemInfo.supports3DTextures.ToString());
  184. sb.AppendLine("supports2DArrayTextures :" + SystemInfo.supports2DArrayTextures.ToString());
  185. sb.AppendLine("supportsAccelerometer :" + SystemInfo.supportsAccelerometer.ToString());
  186. sb.AppendLine("supportsAudio :" + SystemInfo.supportsAudio.ToString());
  187. sb.AppendLine("supportsComputeShaders :" + SystemInfo.supportsComputeShaders.ToString());
  188. sb.AppendLine("supportsCubemapArrayTextures :" + SystemInfo.supportsCubemapArrayTextures.ToString());
  189. sb.AppendLine("supportsGyroscope :" + SystemInfo.supportsGyroscope.ToString());
  190. sb.AppendLine("supportsImageEffects :" + SystemInfo.supportsImageEffects.ToString());
  191. sb.AppendLine("supportsInstancing :" + SystemInfo.supportsInstancing.ToString());
  192. sb.AppendLine("supportsLocationService :" + SystemInfo.supportsLocationService.ToString());
  193. sb.AppendLine("supportsMotionVectors :" + SystemInfo.supportsMotionVectors.ToString());
  194. sb.AppendLine("supportsRawShadowDepthSampling :" + SystemInfo.supportsRawShadowDepthSampling.ToString());
  195. sb.AppendLine("supportsRenderToCubemap :" + SystemInfo.supportsRenderToCubemap.ToString());
  196. sb.AppendLine("supportsShadows :" + SystemInfo.supportsShadows.ToString());
  197. sb.AppendLine("supportsSparseTextures :" + SystemInfo.supportsSparseTextures.ToString());
  198. sb.AppendLine("supportsVibration :" + SystemInfo.supportsVibration.ToString());
  199. sb.AppendLine("systemMemorySize :" + SystemInfo.systemMemorySize.ToString());
  200. sb.AppendLine("usesReversedZBuffer :" + SystemInfo.usesReversedZBuffer.ToString());
  201. return sb.ToString();
  202. }
  203. }