ManaServer.cs 9.4 KB

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