ManaServer.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 && !LoginComplete)
  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. ManaDebug.Log(jsonData.ToJson());
  77. LoginComplete = true;
  78. if (jsonData.Inst_Object.ContainsKey("c"))
  79. {
  80. Connect = true;
  81. JsonData = jsonData;
  82. Time = DateUtil.GetTime(jsonData["time"].ToJson());
  83. if (Data._PlayerDoc != null)
  84. {
  85. if (Data.GetPlayerString("ID") == "Default")
  86. {
  87. ID = jsonData["o"].ToString();
  88. if (Initializer.LoadComplete)
  89. {
  90. ManaReso.SetText("L_UserLab", ID);
  91. }
  92. }
  93. }
  94. ManaDebug.Log("<color=red>连接成功</color>");
  95. }
  96. else
  97. {
  98. Connect = false;
  99. ManaDebug.Log("<color=red>连接失败</color>");
  100. }
  101. }
  102. public static void Save()
  103. {
  104. ManaData.SaveTimer = 0;
  105. URLRequestData urlData = new URLRequestData();
  106. urlData.Add("u", ID);
  107. Data.SavePlayerConfig();
  108. urlData.Add("l", Data.PlayerDoc.OuterXml);
  109. URLRequest.CreateURLRequest("https://garden.dashgame.com/index.php/home/user/save", urlData, SaveCallback, URLRequest.Method.POST);
  110. }
  111. private static void SaveCallback(JsonData jsonData)
  112. {
  113. ManaDebug.Log("<color=red>发送存档成功</color>");
  114. }
  115. public static void Load(string id, URLRequest.URLRequestJsonCallBackDelegate callback)
  116. {
  117. URLRequestData urlData = new URLRequestData();
  118. urlData.Add("u", id);
  119. URLRequest.CreateURLRequest("https://garden.dashgame.com/index.php/home/user/load", urlData, callback, URLRequest.Method.POST);
  120. }
  121. public static void Report()
  122. {
  123. ManaReso.Get("Lb_Info").TweenBacCG();
  124. string str = ManaReso.Get<Text>("Lb_InputLab").text;
  125. if (string.IsNullOrEmpty(str))
  126. {
  127. Bubble.Show(null, Language.GetStr("UI", "Lb_Send2"));
  128. }
  129. else if(ReportStr == str)
  130. {
  131. Bubble.Show(null, Language.GetStr("UI", "Lb_Send1"));
  132. }
  133. else
  134. {
  135. MailMessage mailMessage = new MailMessage();
  136. mailMessage.To.Add(new MailAddress("bug@dashgame.com"));
  137. mailMessage.From = new MailAddress("dashgamegarden@163.com");
  138. ReportStr = str;
  139. mailMessage.Body = ReportStr + '\n' + GetSystemInfo();
  140. mailMessage.Subject = ID + " MyLovelyGargen Issue";
  141. SmtpClient smtpClient = new SmtpClient("smtp.163.com");
  142. smtpClient.Credentials = new MyCredentials("dashgamegarden@163.com", "cs670cs");
  143. smtpClient.SendAsync(mailMessage, "Async");
  144. Bubble.Show(null, Language.GetStr("UI", "Lb_Send0"));
  145. }
  146. }
  147. public static string GetSystemInfo()
  148. {
  149. StringBuilder sb = new StringBuilder();
  150. sb.AppendLine("deviceType :" + SystemInfo.deviceType.ToString());
  151. sb.AppendLine("deviceName :" + SystemInfo.deviceName.ToString());
  152. sb.AppendLine("deviceModel :" + SystemInfo.deviceModel.ToString());
  153. sb.AppendLine("deviceUniqueIdentifier :" + SystemInfo.deviceUniqueIdentifier.ToString());
  154. sb.AppendLine("graphicsDeviceID :" + SystemInfo.graphicsDeviceID.ToString());
  155. sb.AppendLine("graphicsDeviceType :" + SystemInfo.graphicsDeviceType.ToString());
  156. sb.AppendLine("graphicsDeviceName :" + SystemInfo.graphicsDeviceName.ToString());
  157. sb.AppendLine("graphicsShaderLevel :" + SystemInfo.graphicsShaderLevel.ToString());
  158. sb.AppendLine("graphicsMemorySize :" + SystemInfo.graphicsMemorySize.ToString());
  159. sb.AppendLine("graphicsDeviceVersion :" + SystemInfo.graphicsDeviceVersion.ToString());
  160. sb.AppendLine("graphicsMultiThreaded :" + SystemInfo.graphicsMultiThreaded.ToString());
  161. sb.AppendLine("graphicsDeviceVendor :" + SystemInfo.graphicsDeviceVendor.ToString());
  162. sb.AppendLine("graphicsDeviceVendorID :" + SystemInfo.graphicsDeviceVendorID.ToString());
  163. sb.AppendLine("npotSupport :" + SystemInfo.npotSupport.ToString());
  164. sb.AppendLine("maxTextureSize :" + SystemInfo.maxTextureSize.ToString());
  165. sb.AppendLine("operatingSystem :" + SystemInfo.operatingSystem.ToString());
  166. sb.AppendLine("operatingSystemFamily :" + SystemInfo.operatingSystemFamily.ToString());
  167. sb.AppendLine("processorType :" + SystemInfo.processorType.ToString());
  168. sb.AppendLine("processorCount :" + SystemInfo.processorCount.ToString());
  169. sb.AppendLine("processorFrequency :" + SystemInfo.processorFrequency.ToString());
  170. sb.AppendLine("copyTextureSupport :" + SystemInfo.copyTextureSupport.ToString());
  171. sb.AppendLine("graphicsMultiThreaded :" + SystemInfo.graphicsMultiThreaded.ToString());
  172. sb.AppendLine("supportedRenderTargetCount :" + SystemInfo.supportedRenderTargetCount.ToString());
  173. sb.AppendLine("supports3DTextures :" + SystemInfo.supports3DTextures.ToString());
  174. sb.AppendLine("supports2DArrayTextures :" + SystemInfo.supports2DArrayTextures.ToString());
  175. sb.AppendLine("supportsAccelerometer :" + SystemInfo.supportsAccelerometer.ToString());
  176. sb.AppendLine("supportsAudio :" + SystemInfo.supportsAudio.ToString());
  177. sb.AppendLine("supportsComputeShaders :" + SystemInfo.supportsComputeShaders.ToString());
  178. sb.AppendLine("supportsCubemapArrayTextures :" + SystemInfo.supportsCubemapArrayTextures.ToString());
  179. sb.AppendLine("supportsGyroscope :" + SystemInfo.supportsGyroscope.ToString());
  180. sb.AppendLine("supportsImageEffects :" + SystemInfo.supportsImageEffects.ToString());
  181. sb.AppendLine("supportsInstancing :" + SystemInfo.supportsInstancing.ToString());
  182. sb.AppendLine("supportsLocationService :" + SystemInfo.supportsLocationService.ToString());
  183. sb.AppendLine("supportsMotionVectors :" + SystemInfo.supportsMotionVectors.ToString());
  184. sb.AppendLine("supportsRawShadowDepthSampling :" + SystemInfo.supportsRawShadowDepthSampling.ToString());
  185. sb.AppendLine("supportsRenderToCubemap :" + SystemInfo.supportsRenderToCubemap.ToString());
  186. sb.AppendLine("supportsShadows :" + SystemInfo.supportsShadows.ToString());
  187. sb.AppendLine("supportsSparseTextures :" + SystemInfo.supportsSparseTextures.ToString());
  188. sb.AppendLine("supportsVibration :" + SystemInfo.supportsVibration.ToString());
  189. sb.AppendLine("systemMemorySize :" + SystemInfo.systemMemorySize.ToString());
  190. sb.AppendLine("usesReversedZBuffer :" + SystemInfo.usesReversedZBuffer.ToString());
  191. return sb.ToString();
  192. }
  193. }