ManaServer.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. using LitJson;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using UnityEngine.Events;
  5. using System;
  6. using System.Net;
  7. using System.Text;
  8. using System.Net.Mail;
  9. using System.Collections;
  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 int Counter;
  50. public static float Timer;
  51. public static bool Complete;
  52. public static string ID = "Default";
  53. public static string ReportContent;
  54. public static JsonData JsonData;
  55. public static DateTime Time;
  56. #endregion
  57. public void Update()
  58. {
  59. if (!ManaCenter.Complete && !Complete)
  60. {
  61. Timer += UnityEngine.Time.fixedDeltaTime;
  62. if (Timer >= 2f)
  63. {
  64. Timer = 0;
  65. Counter++;
  66. if (Counter > 4)
  67. {
  68. Complete = true;
  69. ManaCenter.LoginCallbackInitial(new JsonData());
  70. }
  71. else
  72. {
  73. Login(ManaCenter.LoginCallbackInitial);
  74. }
  75. }
  76. }
  77. }
  78. public override bool RegistImmed()
  79. {
  80. if (base.RegistImmed())
  81. {
  82. return true;
  83. }
  84. enabled = true;
  85. return false;
  86. }
  87. public static void Login(URLRequest.URLRequestJsonCallBackDelegate callback = null)
  88. {
  89. URLRequestData urlData = new URLRequestData();
  90. urlData.Add("u", SystemInfo.deviceUniqueIdentifier);
  91. URLRequest.CreateURLRequest("https://garden.dashgame.com/index.php/home/user/login", urlData, LoginCallback + callback, URLRequest.Method.POST);
  92. }
  93. private static void LoginCallback(JsonData jsonData)
  94. {
  95. Complete = true;
  96. if (jsonData.Inst_Object.ContainsKey("c"))
  97. {
  98. Connect = true;
  99. JsonData = jsonData;
  100. Time = DateUtil.GetTime(jsonData["time"].ToJson());
  101. if (ManaData.PlayerDoc_ != null)
  102. {
  103. if (ManaData.GetPlayerString("ID") == "Default")
  104. {
  105. ID = jsonData["o"].ToString();
  106. if (Initializer.Complete)
  107. {
  108. ManaReso.SetText("L_UserLab", ID);
  109. }
  110. }
  111. }
  112. ManaDebug.Log("<color=red>连接成功</color>");
  113. }
  114. else
  115. {
  116. Connect = false;
  117. ManaDebug.Log("<color=red>连接失败</color>");
  118. }
  119. }
  120. public static void Save()
  121. {
  122. ManaCenter.SaveTimer = 0;
  123. URLRequestData urlData = new URLRequestData();
  124. urlData.Add("u", ID);
  125. ManaData.SavePlayerConfig();
  126. urlData.Add("l", ManaData.PlayerDoc.OuterXml);
  127. URLRequest.CreateURLRequest("https://garden.dashgame.com/index.php/home/user/save", urlData, SaveCallback, URLRequest.Method.POST);
  128. }
  129. private static void SaveCallback(JsonData jsonData)
  130. {
  131. ManaDebug.Log("<color=red>发送存档成功</color>");
  132. }
  133. public static void Download(string id, URLRequest.URLRequestJsonCallBackDelegate callback)
  134. {
  135. URLRequestData urlData = new URLRequestData();
  136. urlData.Add("u", id);
  137. URLRequest.CreateURLRequest("https://garden.dashgame.com/index.php/home/user/load", urlData, callback, URLRequest.Method.POST);
  138. }
  139. public static void RandomLoad(URLRequest.URLRequestJsonCallBackDelegate callback)
  140. {
  141. URLRequestData urlData = new URLRequestData();
  142. urlData.Add("i", "");
  143. URLRequest.CreateURLRequest("https://garden.dashgame.com/index.php/home/user/rand", urlData, callback, URLRequest.Method.POST);
  144. }
  145. public static void Report()
  146. {
  147. ManaReso.Get("Lb_Info").TweenBacCG();
  148. string str = ManaReso.Get<Text>("Lb_InputLab").text;
  149. if (string.IsNullOrEmpty(str))
  150. {
  151. Bubble.Show(null, Language.GetStr("UI", "Lb_Send2"));
  152. }
  153. else if(ReportContent == str)
  154. {
  155. Bubble.Show(null, Language.GetStr("UI", "Lb_Send1"));
  156. }
  157. else
  158. {
  159. MailMessage mailMessage = new MailMessage();
  160. mailMessage.To.Add(new MailAddress("bug@dashgame.com"));
  161. mailMessage.From = new MailAddress("dashgamegarden@163.com");
  162. ReportContent = str;
  163. mailMessage.Body = ReportContent + '\n' + GetSystemInfo();
  164. mailMessage.Subject = ID + " MyLovelyGargen Issue";
  165. SmtpClient smtpClient = new SmtpClient("smtp.163.com");
  166. smtpClient.Credentials = new MyCredentials("dashgamegarden@163.com", "cs670cs");
  167. smtpClient.SendAsync(mailMessage, "Async");
  168. Bubble.Show(null, Language.GetStr("UI", "Lb_Send0"));
  169. }
  170. }
  171. public static string GetSystemInfo()
  172. {
  173. StringBuilder sb = new StringBuilder();
  174. sb.AppendLine("deviceType :" + SystemInfo.deviceType.ToString());
  175. sb.AppendLine("deviceName :" + SystemInfo.deviceName.ToString());
  176. sb.AppendLine("deviceModel :" + SystemInfo.deviceModel.ToString());
  177. sb.AppendLine("deviceUniqueIdentifier :" + SystemInfo.deviceUniqueIdentifier.ToString());
  178. sb.AppendLine("graphicsDeviceID :" + SystemInfo.graphicsDeviceID.ToString());
  179. sb.AppendLine("graphicsDeviceType :" + SystemInfo.graphicsDeviceType.ToString());
  180. sb.AppendLine("graphicsDeviceName :" + SystemInfo.graphicsDeviceName.ToString());
  181. sb.AppendLine("graphicsShaderLevel :" + SystemInfo.graphicsShaderLevel.ToString());
  182. sb.AppendLine("graphicsMemorySize :" + SystemInfo.graphicsMemorySize.ToString());
  183. sb.AppendLine("graphicsDeviceVersion :" + SystemInfo.graphicsDeviceVersion.ToString());
  184. sb.AppendLine("graphicsMultiThreaded :" + SystemInfo.graphicsMultiThreaded.ToString());
  185. sb.AppendLine("graphicsDeviceVendor :" + SystemInfo.graphicsDeviceVendor.ToString());
  186. sb.AppendLine("graphicsDeviceVendorID :" + SystemInfo.graphicsDeviceVendorID.ToString());
  187. sb.AppendLine("npotSupport :" + SystemInfo.npotSupport.ToString());
  188. sb.AppendLine("maxTextureSize :" + SystemInfo.maxTextureSize.ToString());
  189. sb.AppendLine("operatingSystem :" + SystemInfo.operatingSystem.ToString());
  190. sb.AppendLine("operatingSystemFamily :" + SystemInfo.operatingSystemFamily.ToString());
  191. sb.AppendLine("processorType :" + SystemInfo.processorType.ToString());
  192. sb.AppendLine("processorCount :" + SystemInfo.processorCount.ToString());
  193. sb.AppendLine("processorFrequency :" + SystemInfo.processorFrequency.ToString());
  194. sb.AppendLine("copyTextureSupport :" + SystemInfo.copyTextureSupport.ToString());
  195. sb.AppendLine("graphicsMultiThreaded :" + SystemInfo.graphicsMultiThreaded.ToString());
  196. sb.AppendLine("supportedRenderTargetCount :" + SystemInfo.supportedRenderTargetCount.ToString());
  197. sb.AppendLine("supports3DTextures :" + SystemInfo.supports3DTextures.ToString());
  198. sb.AppendLine("supports2DArrayTextures :" + SystemInfo.supports2DArrayTextures.ToString());
  199. sb.AppendLine("supportsAccelerometer :" + SystemInfo.supportsAccelerometer.ToString());
  200. sb.AppendLine("supportsAudio :" + SystemInfo.supportsAudio.ToString());
  201. sb.AppendLine("supportsComputeShaders :" + SystemInfo.supportsComputeShaders.ToString());
  202. sb.AppendLine("supportsCubemapArrayTextures :" + SystemInfo.supportsCubemapArrayTextures.ToString());
  203. sb.AppendLine("supportsGyroscope :" + SystemInfo.supportsGyroscope.ToString());
  204. sb.AppendLine("supportsImageEffects :" + SystemInfo.supportsImageEffects.ToString());
  205. sb.AppendLine("supportsInstancing :" + SystemInfo.supportsInstancing.ToString());
  206. sb.AppendLine("supportsLocationService :" + SystemInfo.supportsLocationService.ToString());
  207. sb.AppendLine("supportsMotionVectors :" + SystemInfo.supportsMotionVectors.ToString());
  208. sb.AppendLine("supportsRawShadowDepthSampling :" + SystemInfo.supportsRawShadowDepthSampling.ToString());
  209. sb.AppendLine("supportsRenderToCubemap :" + SystemInfo.supportsRenderToCubemap.ToString());
  210. sb.AppendLine("supportsShadows :" + SystemInfo.supportsShadows.ToString());
  211. sb.AppendLine("supportsSparseTextures :" + SystemInfo.supportsSparseTextures.ToString());
  212. sb.AppendLine("supportsVibration :" + SystemInfo.supportsVibration.ToString());
  213. sb.AppendLine("systemMemorySize :" + SystemInfo.systemMemorySize.ToString());
  214. sb.AppendLine("usesReversedZBuffer :" + SystemInfo.usesReversedZBuffer.ToString());
  215. return sb.ToString();
  216. }
  217. }