ManaServer.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. using LitJson;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using UnityEngine.Events;
  5. using System;
  6. using System.Net;
  7. using System.Xml;
  8. using System.Text;
  9. using System.Net.Mail;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. public class MyCredentials : ICredentialsByHost
  13. {
  14. public NetworkCredential NetworkCredential;
  15. public NetworkCredential GetCredential(string host, int port, string authType)
  16. {
  17. return NetworkCredential.GetCredential(new Uri("http://" + host + ":" + port), authType);
  18. }
  19. public MyCredentials(string username, string password)
  20. {
  21. NetworkCredential = new NetworkCredential(username, password);
  22. }
  23. }
  24. public class ManaServer : Regist
  25. {
  26. #region 变量
  27. public static bool Connect
  28. {
  29. get
  30. {
  31. if (Connect_)
  32. {
  33. return true;
  34. }
  35. else
  36. {
  37. if (ManaTutorial.ConnectExemptAmt > 0)
  38. {
  39. ManaTutorial.ConnectExemptAmt--;
  40. return true;
  41. }
  42. else
  43. {
  44. return false;
  45. }
  46. }
  47. }
  48. set { Connect_ = value; }
  49. }
  50. public static bool PackLock
  51. {
  52. get { return PackLock_; }
  53. set
  54. {
  55. PackLock_ = value;
  56. foreach (var kv in ManaCenter.SkillDic)
  57. {
  58. if (kv.Value is Pack)
  59. {
  60. ((Pack) kv.Value).SetActive(!PackLock_);
  61. }
  62. }
  63. }
  64. }
  65. public static bool Connect_;
  66. public static bool PackLock_;
  67. public static int Counter;
  68. public static float Timer;
  69. public static bool Complete;
  70. public static bool FirstConnect = true;
  71. public static string ID = "Default";
  72. public static string ReportContent;
  73. public static JsonData JsonData;
  74. public static DateTime Time;
  75. #endregion
  76. public void Update()
  77. {
  78. if (!ManaCenter.Complete && !Complete)
  79. {
  80. Timer += UnityEngine.Time.fixedDeltaTime;
  81. if (Timer >= 2f)
  82. {
  83. Timer = 0;
  84. Counter++;
  85. if (Counter > 4)
  86. {
  87. Complete = true;
  88. ManaCenter.LoginCallbackInitial(new JsonData());
  89. }
  90. else
  91. {
  92. Login(ManaCenter.LoginCallbackInitial);
  93. }
  94. }
  95. }
  96. }
  97. public override bool RegistImmed()
  98. {
  99. if (base.RegistImmed())
  100. {
  101. return true;
  102. }
  103. enabled = true;
  104. return false;
  105. }
  106. public static void SetPackLock()
  107. {
  108. URLRequestData urlData = new URLRequestData();
  109. URLRequest.CreateURLRequest
  110. (
  111. "https://garden.dashgame.com/index.php/home/index/index",
  112. urlData,
  113. data =>
  114. {
  115. if (data.Inst_Object.ContainsKey("error"))
  116. {
  117. if (ManaData.PlayerDoc_ != null)
  118. {
  119. PackLock = ManaData.GetPlayerBool("PackLock");
  120. }
  121. }
  122. else
  123. {
  124. PackLock = Auxiliary.BoolParse(data["l"]["val"].ToJson().Trim('"'), true);
  125. if (ManaData.PlayerDoc_ != null)
  126. {
  127. ManaData.SavePlayerBool("PackLock", PackLock);
  128. }
  129. }
  130. }
  131. );
  132. }
  133. public static void DecodeRewardXml(string rewardXml)
  134. {
  135. XmlDocument xmlDoc = new XmlDocument();
  136. xmlDoc.LoadXml(rewardXml);
  137. XmlNodeList rewardNodeList = xmlDoc.SelectNodes("OneTimeReward");
  138. List<string> receivedIdList = Auxiliary.StringListParse(' ', ManaData.GetPlayerString("OneTimeReward"), new List<string>());
  139. for (int i = 0; i < rewardNodeList.Count; i++)
  140. {
  141. string id = rewardNodeList[i].SelectSingleNode("id").Value;
  142. if (receivedIdList.Contains(id))
  143. {
  144. continue;
  145. }
  146. XmlNodeList targetIdNodeList = rewardNodeList[i].SelectSingleNode("targets").SelectNodes("id");
  147. for (int j = 0; j < targetIdNodeList.Count; j++)
  148. {
  149. if (targetIdNodeList[i].Value == ID)
  150. {
  151. GetReward(rewardNodeList[i].SelectSingleNode("reward"));
  152. ManaData.SavePlayerString("OneTimeReward", $"{ManaData.GetPlayerString("OneTimeReward")} id".Trim(' '));
  153. break;
  154. }
  155. }
  156. }
  157. }
  158. public static void GetReward(XmlNode xmlNode)
  159. {
  160. if (xmlNode.Name == "pack")
  161. {
  162. UnityAction unityAction;
  163. if (ManaIAP.ProductActionDic.TryGetValue($"Pack{xmlNode.Value}", out unityAction))
  164. {
  165. unityAction.Invoke();
  166. }
  167. else
  168. {
  169. Debug.LogWarning("Unknown id");
  170. }
  171. }
  172. else if (xmlNode.Name == "close")
  173. {
  174. int id = int.Parse(xmlNode.Value);
  175. CloseUnit closeUnit;
  176. if (ManaPlayer.CloseUnitDic.TryGetValue(id, out closeUnit))
  177. {
  178. closeUnit.Unlock();
  179. ManaPlayer.BoughtCloseList.UniqueAdd(id);
  180. }
  181. else
  182. {
  183. Debug.LogWarning("Unknown id");
  184. }
  185. }
  186. else if (xmlNode.Name == "flower")
  187. {
  188. int id = int.Parse(xmlNode.Value);
  189. FlowerInfo flowerInfo;
  190. if (ManaGarden.FlowerInfoDic.TryGetValue(id, out flowerInfo))
  191. {
  192. if (flowerInfo.Unlock == false)
  193. {
  194. flowerInfo.Unlock = true;
  195. }
  196. }
  197. else
  198. {
  199. Debug.LogWarning("Unknown id");
  200. }
  201. }
  202. else if (xmlNode.Name == "coin")
  203. {
  204. ManaCenter.AddCoin(double.Parse(xmlNode.Value), StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.ServerReward);
  205. }
  206. else if (xmlNode.Name == "diamond")
  207. {
  208. ManaCenter.AddDiamond(double.Parse(xmlNode.Value), StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.ServerReward);
  209. }
  210. }
  211. public static void GetProductID(string id, URLRequest.URLRequestCallBackDelegate callback)
  212. {
  213. URLRequestData urlData = new URLRequestData();
  214. urlData.Add("t", 1);
  215. urlData.Add("i", id);
  216. urlData.Add("u", JsonData.Inst_Object["i"].ToJson().Trim('"'));
  217. URLRequest.CreateStrURLRequest("https://garden.dashgame.com/index.php/home/pay/pay", urlData, callback, URLRequest.Method.POST);
  218. }
  219. public static void Login(URLRequest.URLRequestJsonCallBackDelegate callback = null)
  220. {
  221. URLRequestData urlData = new URLRequestData();
  222. urlData.Add("u", SystemInfo.deviceUniqueIdentifier);
  223. URLRequest.CreateURLRequest("https://garden.dashgame.com/index.php/home/user/login", urlData, LoginCallback + callback, URLRequest.Method.POST);
  224. }
  225. private static void LoginCallback(JsonData jsonData)
  226. {
  227. Complete = true;
  228. if (jsonData.Inst_Object.ContainsKey("c"))
  229. {
  230. Connect = true;
  231. JsonData = jsonData;
  232. Time = DateUtil.GetTime(jsonData["time"].ToJson());
  233. if (ManaData.DamageLock)
  234. {
  235. ID = jsonData["o"].ToString();
  236. }
  237. else if (ManaData.PlayerDoc_ != null)
  238. {
  239. if (ManaData.GetPlayerString("ID") == "Default")
  240. {
  241. ID = jsonData["o"].ToString();
  242. if (Initializer.Complete)
  243. {
  244. ManaReso.SetText("L_UserLab", ID);
  245. }
  246. }
  247. }
  248. if (FirstConnect)
  249. {
  250. FirstConnect = false;
  251. StaticsManager.GetInstance().ActOrReg(ID, DataEyeGA.AccountType.Official);
  252. }
  253. ManaDebug.Log("<color=red>连接成功</color>");
  254. }
  255. else
  256. {
  257. Connect = false;
  258. ManaDebug.Log("<color=red>连接失败</color>");
  259. }
  260. }
  261. public static void Save()
  262. {
  263. ManaCenter.SaveTimer = 0;
  264. URLRequestData urlData = new URLRequestData();
  265. urlData.Add("u", ID);
  266. ManaData.SavePlayerConfig();
  267. urlData.Add("l", ManaData.PlayerDoc.OuterXml);
  268. URLRequest.CreateURLRequest("https://garden.dashgame.com/index.php/home/user/save", urlData, SaveCallback, URLRequest.Method.POST);
  269. }
  270. private static void SaveCallback(JsonData jsonData)
  271. {
  272. ManaDebug.Log("<color=red>发送存档成功</color>");
  273. }
  274. public static void Download(string id, URLRequest.URLRequestJsonCallBackDelegate callback)
  275. {
  276. URLRequestData urlData = new URLRequestData();
  277. urlData.Add("u", id);
  278. URLRequest.CreateURLRequest("https://garden.dashgame.com/index.php/home/user/load", urlData, callback, URLRequest.Method.POST);
  279. }
  280. public static void RandomLoad(URLRequest.URLRequestJsonCallBackDelegate callback)
  281. {
  282. URLRequestData urlData = new URLRequestData();
  283. urlData.Add("i", "");
  284. URLRequest.CreateURLRequest("https://garden.dashgame.com/index.php/home/user/rand", urlData, callback, URLRequest.Method.POST);
  285. }
  286. public static void Report()
  287. {
  288. ManaReso.Get("Lb_Info").TweenBacCG();
  289. string str = ManaReso.Get<Text>("Lb_InputLab").text;
  290. if (string.IsNullOrEmpty(str))
  291. {
  292. Bubble.Show(null, Language.GetStr("UI", "Lb_Send2"));
  293. }
  294. else if(ReportContent == str)
  295. {
  296. Bubble.Show(null, Language.GetStr("UI", "Lb_Send1"));
  297. }
  298. else
  299. {
  300. MailMessage mailMessage = new MailMessage();
  301. mailMessage.To.Add(new MailAddress("bug@dashgame.com"));
  302. mailMessage.From = new MailAddress("dashgamegarden@163.com");
  303. ReportContent = str;
  304. mailMessage.Body = ReportContent + '\n' + GetSystemInfo();
  305. mailMessage.Subject = ID + " MyLovelyGargen Issue";
  306. SmtpClient smtpClient = new SmtpClient("smtp.163.com");
  307. smtpClient.Credentials = new MyCredentials("dashgamegarden@163.com", "cs670cs");
  308. smtpClient.SendAsync(mailMessage, "Async");
  309. Bubble.Show(null, Language.GetStr("UI", "Lb_Send0"));
  310. }
  311. }
  312. public static string GetSystemInfo()
  313. {
  314. StringBuilder sb = new StringBuilder();
  315. sb.AppendLine("deviceType :" + SystemInfo.deviceType.ToString());
  316. sb.AppendLine("deviceName :" + SystemInfo.deviceName.ToString());
  317. sb.AppendLine("deviceModel :" + SystemInfo.deviceModel.ToString());
  318. sb.AppendLine("deviceUniqueIdentifier :" + SystemInfo.deviceUniqueIdentifier.ToString());
  319. sb.AppendLine("graphicsDeviceID :" + SystemInfo.graphicsDeviceID.ToString());
  320. sb.AppendLine("graphicsDeviceType :" + SystemInfo.graphicsDeviceType.ToString());
  321. sb.AppendLine("graphicsDeviceName :" + SystemInfo.graphicsDeviceName.ToString());
  322. sb.AppendLine("graphicsShaderLevel :" + SystemInfo.graphicsShaderLevel.ToString());
  323. sb.AppendLine("graphicsMemorySize :" + SystemInfo.graphicsMemorySize.ToString());
  324. sb.AppendLine("graphicsDeviceVersion :" + SystemInfo.graphicsDeviceVersion.ToString());
  325. sb.AppendLine("graphicsMultiThreaded :" + SystemInfo.graphicsMultiThreaded.ToString());
  326. sb.AppendLine("graphicsDeviceVendor :" + SystemInfo.graphicsDeviceVendor.ToString());
  327. sb.AppendLine("graphicsDeviceVendorID :" + SystemInfo.graphicsDeviceVendorID.ToString());
  328. sb.AppendLine("npotSupport :" + SystemInfo.npotSupport.ToString());
  329. sb.AppendLine("maxTextureSize :" + SystemInfo.maxTextureSize.ToString());
  330. sb.AppendLine("operatingSystem :" + SystemInfo.operatingSystem.ToString());
  331. sb.AppendLine("operatingSystemFamily :" + SystemInfo.operatingSystemFamily.ToString());
  332. sb.AppendLine("processorType :" + SystemInfo.processorType.ToString());
  333. sb.AppendLine("processorCount :" + SystemInfo.processorCount.ToString());
  334. sb.AppendLine("processorFrequency :" + SystemInfo.processorFrequency.ToString());
  335. sb.AppendLine("copyTextureSupport :" + SystemInfo.copyTextureSupport.ToString());
  336. sb.AppendLine("graphicsMultiThreaded :" + SystemInfo.graphicsMultiThreaded.ToString());
  337. sb.AppendLine("supportedRenderTargetCount :" + SystemInfo.supportedRenderTargetCount.ToString());
  338. sb.AppendLine("supports3DTextures :" + SystemInfo.supports3DTextures.ToString());
  339. sb.AppendLine("supports2DArrayTextures :" + SystemInfo.supports2DArrayTextures.ToString());
  340. sb.AppendLine("supportsAccelerometer :" + SystemInfo.supportsAccelerometer.ToString());
  341. sb.AppendLine("supportsAudio :" + SystemInfo.supportsAudio.ToString());
  342. sb.AppendLine("supportsComputeShaders :" + SystemInfo.supportsComputeShaders.ToString());
  343. sb.AppendLine("supportsCubemapArrayTextures :" + SystemInfo.supportsCubemapArrayTextures.ToString());
  344. sb.AppendLine("supportsGyroscope :" + SystemInfo.supportsGyroscope.ToString());
  345. sb.AppendLine("supportsImageEffects :" + SystemInfo.supportsImageEffects.ToString());
  346. sb.AppendLine("supportsInstancing :" + SystemInfo.supportsInstancing.ToString());
  347. sb.AppendLine("supportsLocationService :" + SystemInfo.supportsLocationService.ToString());
  348. sb.AppendLine("supportsMotionVectors :" + SystemInfo.supportsMotionVectors.ToString());
  349. sb.AppendLine("supportsRawShadowDepthSampling :" + SystemInfo.supportsRawShadowDepthSampling.ToString());
  350. sb.AppendLine("supportsRenderToCubemap :" + SystemInfo.supportsRenderToCubemap.ToString());
  351. sb.AppendLine("supportsShadows :" + SystemInfo.supportsShadows.ToString());
  352. sb.AppendLine("supportsSparseTextures :" + SystemInfo.supportsSparseTextures.ToString());
  353. sb.AppendLine("supportsVibration :" + SystemInfo.supportsVibration.ToString());
  354. sb.AppendLine("systemMemorySize :" + SystemInfo.systemMemorySize.ToString());
  355. sb.AppendLine("usesReversedZBuffer :" + SystemInfo.usesReversedZBuffer.ToString());
  356. return sb.ToString();
  357. }
  358. }