ManaServer.cs 9.1 KB

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