ManaServer.cs 9.8 KB

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