HttpManager.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  1. using LitJson;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using UnityEngine.Events;
  5. using System;
  6. using System.IO;
  7. using System.Net;
  8. using System.Xml;
  9. using System.Text;
  10. using System.Linq;
  11. using System.Net.Mail;
  12. using System.Collections;
  13. using System.Collections.Generic;
  14. using Random = UnityEngine.Random;
  15. public class MyCredentials : ICredentialsByHost
  16. {
  17. public NetworkCredential NetworkCredential;
  18. public NetworkCredential GetCredential(string host, int port, string authType)
  19. {
  20. return NetworkCredential.GetCredential(new Uri("http://" + host + ":" + port), authType);
  21. }
  22. public MyCredentials(string username, string password)
  23. {
  24. NetworkCredential = new NetworkCredential(username, password);
  25. }
  26. }
  27. public enum CommentType
  28. {
  29. Garden = 0,
  30. }
  31. public class HttpManager : Regist
  32. {
  33. public class MailReward
  34. {
  35. public string Id;
  36. public string Key;
  37. public string Value;
  38. public MailReward(string id, string key, string value)
  39. {
  40. Id = id;
  41. Key = key;
  42. Value = value;
  43. }
  44. }
  45. #region Config
  46. public static bool Connect
  47. {
  48. get
  49. {
  50. if (Connect_)
  51. {
  52. return true;
  53. }
  54. else
  55. {
  56. return TutorialManager.ConnectExempt;
  57. }
  58. }
  59. set { Connect_ = value; }
  60. }
  61. public static bool PackLock
  62. {
  63. get { return PackLock_; }
  64. set
  65. {
  66. PackLock_ = value;
  67. foreach (var kv in Manager.SkillDic)
  68. {
  69. if (kv.Value is Pack)
  70. {
  71. ((Pack) kv.Value).SetActive();
  72. }
  73. }
  74. }
  75. }
  76. public static bool Connect_;
  77. public static bool PackLock_;
  78. public static int Counter;
  79. public static int PraiseAmt;
  80. public static bool RankReady;
  81. public static List<JsonData> RankDatas;
  82. public static int NotificationIndex = -1;
  83. public static bool NotificationReady;
  84. public static string NotificationStr;
  85. public static Sprite NotificationSprite;
  86. public static float Timer;
  87. public static bool Complete;
  88. public static bool FirstConnect = true;
  89. public static int ReplayVersion;
  90. public static string ID = "Default";
  91. public static string SerialNumber = "Default";
  92. public static string ReportContent;
  93. public static JsonData JsonData;
  94. public static DateTime Time = DateTime.Now;
  95. public static string MailXml;
  96. public static List<MailReward> MailRewardList = new List<MailReward>();
  97. public static string BaseURL = "https://garden.dashgame.com/index.php/home";
  98. public static string NewBaseURL = "https://garden.dashgame.com/index.php/newhome";
  99. public static string NicknameURL = NewBaseURL + "/user/nickname";
  100. public static string RankURL = NewBaseURL + "/user/look";
  101. public static string PraiseURL= NewBaseURL + "/praise/click";
  102. public static string TargetURL= NewBaseURL + "/praise/target";
  103. public static string AddCommentURL= NewBaseURL + "/comment/comment";
  104. public static string GetCommentURL= NewBaseURL + "/comment/index";
  105. public static string IndexURL= NewBaseURL + "/index/index";
  106. public static string GetProductIDURL= NewBaseURL + "/pay/pay";
  107. public static string LoginURL= NewBaseURL + "/user/login";
  108. public static string SaveURL= NewBaseURL + "/user/save";
  109. public static string OtherURL= NewBaseURL + "/user/other";
  110. public static string DownloadURL= NewBaseURL + "/user/load";
  111. public static string RandomURL= NewBaseURL + "/user/rand";
  112. public static string ThanksGiftInfoURL= NewBaseURL + "/index/gift";
  113. public static string ReportMailAddress= "bug@dashgame.com";
  114. #endregion
  115. public void Awake()
  116. {
  117. //URLRequestData urlData = new URLRequestData();
  118. //urlData.Add("u", "1710065808151506837");
  119. //urlData.Add("t", "1710066204207012789");
  120. //URLRequest.CreateStrURLRequest(true, NewBaseURL + "/praise/target", urlData, Debug.Log, URLRequest.Method.POST);
  121. //URLRequestData urlData = new URLRequestData();
  122. //urlData.Add("u", "1709207727231988804");
  123. //URLRequest.CreateStrURLRequest(true, NewBaseURL + "/user/other", urlData, Debug.Log, URLRequest.Method.POST);
  124. }
  125. public void Update()
  126. {
  127. if (!Manager.Complete && !Complete)
  128. {
  129. Timer += UnityEngine.Time.deltaTime;
  130. if (Timer >= 2f)
  131. {
  132. Timer = 0;
  133. Counter++;
  134. if (Counter > 4)
  135. {
  136. Complete = true;
  137. Manager.LoginCallbackInitial(new JsonData());
  138. }
  139. else
  140. {
  141. Login(Manager.LoginCallbackInitial);
  142. IOSAlipayRequest();
  143. }
  144. }
  145. }
  146. }
  147. public override bool InitAtOnce()
  148. {
  149. if (base.InitAtOnce())
  150. {
  151. return true;
  152. }
  153. enabled = true;
  154. return false;
  155. }
  156. public override void FirstInit()
  157. {
  158. ReplayVersion = ConfigManager.GetPlayerInt(PlayerConfigLabel.ReplayVersion);
  159. }
  160. public static void SetNickName(string nickname, Action succeedCallback, Action<string> failCallback)
  161. {
  162. URLRequestData urlData = new URLRequestData();
  163. urlData.Add("u", SerialNumber);
  164. urlData.Add("n", nickname);
  165. URLRequest.CreateStrURLRequest
  166. (
  167. true,
  168. NicknameURL,
  169. urlData,
  170. data =>
  171. {
  172. if (data == " {\"error\":0}")
  173. {
  174. succeedCallback.Invoke();
  175. }
  176. else if (data.Contains("Could not resolve host"))
  177. {
  178. failCallback.Invoke(Language.GetStr(LanguageLabel.UI__Fg_Lab3));
  179. }
  180. else
  181. {
  182. failCallback.Invoke(Language.GetStr(LanguageLabel.UI__T_RepeatName));
  183. }
  184. },
  185. URLRequest.Method.POST
  186. );
  187. }
  188. public static void RankRequest()
  189. {
  190. URLRequestData urlData = new URLRequestData();
  191. URLRequest.CreateStrURLRequest
  192. (
  193. false,
  194. RankURL,
  195. urlData,
  196. data =>
  197. {
  198. //Debug.Log(data);
  199. string str = "{\"l\":" + data.Substring(1) + "}";
  200. JsonData jsondata;
  201. try
  202. {
  203. jsondata = JsonMapper.ToObject(str);
  204. }
  205. catch (Exception)
  206. {
  207. jsondata = new JsonData();
  208. jsondata["error"] = 0;
  209. }
  210. RankRequestCallback(jsondata);
  211. //Debug.Log(data[0]);
  212. //StreamWriter streamWriter = new StreamWriter("Assets/123.txt");
  213. //streamWriter.Write(data);
  214. //streamWriter.Close();
  215. }
  216. );
  217. //URLRequest.CreateURLRequest
  218. //(
  219. // NewBaseURL + "/user/look",
  220. // urlData,
  221. // RankRequestCallback,
  222. // URLRequest.Method.POST
  223. //);
  224. }
  225. public static void RankRequestCallback(JsonData jsonData)
  226. {
  227. if (jsonData.Inst_Object.ContainsKey("l"))
  228. {
  229. RankDatas = new List<JsonData>();
  230. for (int i = 0; i < jsonData["l"].Count; i++)
  231. {
  232. RankDatas.Add(jsonData["l"][i]);
  233. }
  234. RankReady = true;
  235. SocialManager.InitializeRankPanel();
  236. }
  237. }
  238. public static void NotificationRequest()
  239. {
  240. //Debug.Log("A");
  241. IndexRequest
  242. (
  243. data =>
  244. {
  245. //Debug.Log("B");
  246. URLRequestData urlData = new URLRequestData();
  247. URLRequest.CreateStrURLRequest
  248. (
  249. true,
  250. data["l"][3]["val"].ToString(),
  251. urlData,
  252. notificationXml =>
  253. {
  254. //Debug.Log("C");
  255. NotificationCallback(notificationXml);
  256. }
  257. );
  258. }
  259. );
  260. }
  261. public static void NotificationCallback(string xml)
  262. {
  263. //Debug.Log("D");
  264. XmlNode rootNode;
  265. XmlDocument document = new XmlDocument();
  266. try
  267. {
  268. document.LoadXml(xml);
  269. rootNode = document.SelectSingleNode("announce");
  270. NotificationIndex = int.Parse(rootNode.SelectSingleNode(PlayerConfigLabel.Version).InnerText);
  271. XmlNodeList nodeList = rootNode.SelectNodes(ConfigLabel.ChildNode);
  272. List<string> urlList = new List<string>();
  273. for (int i = 0; i < nodeList.Count; i++)
  274. {
  275. DecodeNotificationItem(nodeList[i], urlList);
  276. }
  277. Auxiliary.Instance.StartCoroutine(PullNotifyTexs(urlList, PullNotifyTexsCallback));
  278. }
  279. catch (Exception)
  280. {
  281. }
  282. finally
  283. {
  284. }
  285. }
  286. public static void DecodeNotificationItem(XmlNode node, List<string> urlList)
  287. {
  288. XmlNodeList nodeList = node.SelectNodes("title");
  289. for (int i = 0; i < nodeList.Count; i++)
  290. {
  291. AnnounceManager.AddLine(false, nodeList[i].Attributes[0].Value, nodeList[i].InnerText, TextAnchor.MiddleLeft);
  292. }
  293. AnnounceManager.AddLine(false, "null", node.SelectSingleNode("date").InnerText, TextAnchor.MiddleLeft);
  294. nodeList = node.SelectSingleNode("content").ChildNodes;
  295. for (int i = 0; i < nodeList.Count; i++)
  296. {
  297. if (nodeList[i].Name == "text")
  298. {
  299. AnnounceManager.AddLine(false, nodeList[i].Attributes[0].Value, nodeList[i].InnerText, TextAnchor.MiddleLeft);
  300. }
  301. else if (nodeList[i].Name == "image")
  302. {
  303. urlList.UniqueAdd(nodeList[i].InnerText);
  304. AnnounceManager.AddLine(true, "null", $"<({Path.GetFileNameWithoutExtension(nodeList[i].InnerText)})>", TextAnchor.MiddleCenter);
  305. }
  306. }
  307. AnnounceManager.AddLine(false, "null", "", TextAnchor.MiddleLeft);
  308. }
  309. public static void PullNotifyTexsCallback(List<WWW> wwwList)
  310. {
  311. List<Texture2D> textureList = new List<Texture2D>();
  312. List<SpriteInfo> spriteInfoList = new List<SpriteInfo>();
  313. for (int i = 0; i < wwwList.Count; i++)
  314. {
  315. textureList.Add(wwwList[i].texture);
  316. SpriteInfo spriteInfo = new SpriteInfo();
  317. spriteInfo.Name = Path.GetFileNameWithoutExtension(wwwList[i].url);
  318. spriteInfoList.Add(spriteInfo);
  319. }
  320. Texture2D atlas = new Texture2D(2048, 2048);
  321. Rect[] rects = atlas.PackTextures(textureList.ToArray(), 1);
  322. Sprite sprite = Sprite.Create(atlas, new Rect(0, 0, atlas.width, atlas.height), new Vector2(0.5f, 0.5f));
  323. for (int i = 0; i < spriteInfoList.Count; i++)
  324. {
  325. spriteInfoList[i].Width = textureList[i].width;
  326. spriteInfoList[i].Height = textureList[i].height;
  327. spriteInfoList[i].UvList = new List<Vector2>()
  328. {
  329. new Vector2(rects[i].xMin, rects[i].yMax),
  330. new Vector2(rects[i].xMax, rects[i].yMax),
  331. new Vector2(rects[i].xMax, rects[i].yMin),
  332. new Vector2(rects[i].xMin, rects[i].yMin),
  333. };
  334. SpriteAsset.SpriteInfoDic.Add(spriteInfoList[i].Name, spriteInfoList[i]);
  335. }
  336. NotificationSprite = sprite;
  337. NotificationReady = true;
  338. if (Initializer.Complete)
  339. {
  340. ResourceManager.Get(ObjectLabel.C_Notify).TweenForCG();
  341. }
  342. //Debug.Log("Done");
  343. }
  344. public static IEnumerator PullNotifyTexs(List<string> urlList, Action<List<WWW>> callback)
  345. {
  346. List<WWW> wwwList = new List<WWW>();
  347. for (int i = 0; i < urlList.Count; i++)
  348. {
  349. wwwList.Add(new WWW(urlList[i]));
  350. }
  351. for (int i = 0; i < wwwList.Count; i++)
  352. {
  353. yield return wwwList[i];
  354. }
  355. callback(wwwList);
  356. }
  357. public static void Praise(string sendID, string receiveID)
  358. {
  359. if (receiveID == null)
  360. {
  361. return;
  362. }
  363. URLRequestData urlData = new URLRequestData();
  364. urlData.Add("u", sendID);
  365. urlData.Add("t", receiveID);
  366. URLRequest.CreateStrURLRequest(true, PraiseURL, urlData, (data)=> {}, URLRequest.Method.POST);
  367. }
  368. public static void Target(string userID, string targetID, Action<JsonData> callback)
  369. {
  370. URLRequestData urlData = new URLRequestData();
  371. urlData.Add("u", userID);
  372. urlData.Add("t", targetID);
  373. URLRequest.CreateURLRequest(true, TargetURL, urlData, data => callback(data), URLRequest.Method.POST);
  374. }
  375. public static void AddComment(string sendID, string receiveID, string content, CommentType type)
  376. {
  377. if (string.IsNullOrEmpty(sendID) || string.IsNullOrEmpty(receiveID))
  378. {
  379. return;
  380. }
  381. if (sendID.ToLower() == "default" || receiveID.ToLower() == "default")
  382. {
  383. return;
  384. }
  385. URLRequestData urlData = new URLRequestData();
  386. urlData.Add("c", sendID);
  387. urlData.Add("u", receiveID);
  388. urlData.Add("i", content);
  389. urlData.Add("t", type.GetHashCode());
  390. //Debug.LogWarning(sendID);
  391. //Debug.LogWarning(receiveID);
  392. //Debug.LogWarning(content);
  393. //Debug.LogWarning(type.GetHashCode());
  394. URLRequest.CreateStrURLRequest
  395. (
  396. true,
  397. AddCommentURL,
  398. urlData,
  399. data =>
  400. {
  401. if (data == "{\"error\":0}")
  402. {
  403. Bubble.Show(Language.GetStr(LanguageLabel.UI__Q_CommentDone));
  404. SocialManager.UpdatePage(false);
  405. }
  406. else
  407. {
  408. Bubble.Show(Language.GetStr(LanguageLabel.UI__Q_CommentFail));
  409. }
  410. },
  411. URLRequest.Method.POST
  412. );
  413. }
  414. public static void GetComment(string id, string page, CommentType type, Action<JsonData> callback)
  415. {
  416. JsonData defaultData = new JsonData();
  417. defaultData["error"] = 0;
  418. if (string.IsNullOrEmpty(id))
  419. {
  420. callback.Invoke(defaultData);
  421. return;
  422. }
  423. if (id.ToLower() == "default")
  424. {
  425. callback.Invoke(defaultData);
  426. return;
  427. }
  428. URLRequestData urlData = new URLRequestData();
  429. //Debug.LogWarning(id);
  430. //Debug.LogWarning(page);
  431. //Debug.LogWarning(type.GetHashCode());
  432. urlData.Add("u", id);
  433. urlData.Add("p", page);
  434. urlData.Add("t", type.GetHashCode());
  435. URLRequest.CreateURLRequest(true, GetCommentURL, urlData, data => { callback(data);}, URLRequest.Method.POST);
  436. }
  437. public static void IndexRequest(Action<JsonData> callback)
  438. {
  439. URLRequestData urlData = new URLRequestData();
  440. URLRequest.CreateURLRequest
  441. (
  442. true,
  443. IndexURL,
  444. urlData,
  445. data =>
  446. {
  447. if (data.Inst_Object.ContainsKey("error"))
  448. {
  449. if (ConfigManager.PlayerDoc_ != null)
  450. {
  451. if (Application.platform == RuntimePlatform.Android)
  452. {
  453. PackLock = true;
  454. }
  455. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  456. {
  457. PackLock = ConfigManager.GetPlayerBool("PackLock");
  458. }
  459. }
  460. }
  461. else
  462. {
  463. callback(data);
  464. }
  465. }
  466. );
  467. }
  468. public static void MailRequest()
  469. {
  470. //MailXml = "<mail>" +
  471. // "<OneTimeReward>" +
  472. // "<id>4</id>" +
  473. // "<start>2017-08-18 12:12:12</start>" +
  474. // "<end>2017-09-1 11:30:12</end>" +
  475. // "<reward>" +
  476. // "<coin>1000</coin>" +
  477. // "<diamond>10</diamond>" +
  478. // "</reward>" +
  479. // "<targets>" +
  480. // "<id>90arbl</id>" +
  481. // "</targets>" +
  482. // "</OneTimeReward>" +
  483. // "<OneTimeReward>" +
  484. // "<id>3</id>" +
  485. // "<start>2017-08-21 12:12:12</start>" +
  486. // "<end>2017-09-01 18:12:12</end>" +
  487. // "<reward>" +
  488. // "<coin>10000</coin>" +
  489. // "<diamond>100</diamond>" +
  490. // "</reward>" +
  491. // "<targets>" +
  492. // "<id>90arbl</id>" +
  493. // "</targets>" +
  494. // "</OneTimeReward>" +
  495. // "</mail>";
  496. IndexRequest
  497. (
  498. data =>
  499. {
  500. URLRequestData urlData = new URLRequestData();
  501. URLRequest.CreateStrURLRequest
  502. (
  503. true,
  504. data["l"][1]["val"].ToJson().Trim('"'),
  505. urlData,
  506. mailXml =>
  507. {
  508. MailXml = mailXml;
  509. }
  510. );
  511. }
  512. );
  513. }
  514. public static void GetMailReward()
  515. {
  516. for (int i = 0; i < MailRewardList.Count; i++)
  517. {
  518. GetMailReward(MailRewardList[i]);
  519. }
  520. }
  521. public static void GetMailReward(MailReward mailReward)
  522. {
  523. //Debug.Log(mailReward.Id);
  524. ConfigManager.SavePlayerString("OneTimeReward", $"{ConfigManager.GetPlayerString("OneTimeReward")} {mailReward.Id}".Trim(' '));
  525. if (mailReward.Key == "pack")
  526. {
  527. SkillRoot skillRoot;
  528. if (Manager.SkillDic.TryGetValue($"Pack{mailReward.Value}", out skillRoot))
  529. {
  530. Pack pack = (Pack) skillRoot;
  531. pack.OnBuySucceed();
  532. Transform mailItem = ResourceManager.Get("MailItem", Folder.UI, false, ResourceManager.Get(ObjectLabel.Bd_Grid), new Vector3(), ObjType.MailItem);
  533. float newSpriteSize = 0.35f;
  534. mailItem.GetChild(1).SetActive(false);
  535. mailItem.GetChild(0).GetComponent<Image>().sprite = pack.Icon;
  536. mailItem.GetChild(0).GetComponent<Image>().Resize(true, newSpriteSize, newSpriteSize);
  537. mailItem.GetChild(0).transform.localPosition = new Vector2(0, 0);
  538. mailItem.GetChild(2).GetComponent<Text>().text = pack.Name;
  539. InfoBoxManager.GardenInfoBox.Show($"{Language.GetStr(LanguageLabel.Common__Get)} {TransferLabel.PackSprite}{pack.Name}", 10, Color.white, ResourceManager.LoadSprite("Atlas", Folder.Atlas));
  540. }
  541. else
  542. {
  543. Debug.LogWarning($"Unknown id {mailReward.Value}");
  544. }
  545. }
  546. else if (mailReward.Key == "close")
  547. {
  548. List<int> idList = Auxiliary.StringToInts(' ', mailReward.Value, new List<int>());
  549. CloseItem closeItem;
  550. for (int i = 0; i < idList.Count; i++)
  551. {
  552. if (PlayerManager.CloseItemDic.TryGetValue(idList[i], out closeItem))
  553. {
  554. if (closeItem.Possess == false)
  555. {
  556. closeItem.Unlock();
  557. PlayerManager.BoughtCloseList.UniqueAdd(idList[i]);
  558. }
  559. Transform mailItem = ResourceManager.Get("MailItem", Folder.UI, false, ResourceManager.Get(ObjectLabel.Bd_Grid), new Vector3(), ObjType.MailItem);
  560. float newSize = 0.6f;
  561. float newSpriteSize = closeItem.PixelSize*newSize/closeItem.Sprites[0].rect.width;
  562. mailItem.GetChild(1).GetComponent<Image>().sprite = closeItem.Sprites[0];
  563. mailItem.GetChild(1).GetComponent<Image>().Resize(true, newSpriteSize, newSpriteSize);
  564. mailItem.GetChild(1).transform.localPosition = new Vector2(0, closeItem.IconOffset*newSize);
  565. if (closeItem.Sprites.Length > 1)
  566. {
  567. mailItem.GetChild(0).SetActive(true);
  568. mailItem.GetChild(0).GetComponent<Image>().sprite = closeItem.Sprites[1];
  569. mailItem.GetChild(0).GetComponent<Image>().Resize(true, newSpriteSize, newSpriteSize);
  570. mailItem.GetChild(0).transform.localPosition = closeItem.IconOffset1*newSpriteSize + new Vector2(0, closeItem.IconOffset*newSize);
  571. }
  572. else
  573. {
  574. mailItem.GetChild(0).SetActive(false);
  575. }
  576. mailItem.GetChild(2).GetComponent<Text>().text = closeItem.Name;
  577. InfoBoxManager.GardenInfoBox.Show($"{Language.GetStr(LanguageLabel.Common__Get)} {TransferLabel.CloseSprite}{closeItem.Name}", 10, Color.white, ResourceManager.LoadSprite("Atlas", Folder.Atlas));
  578. }
  579. else
  580. {
  581. Debug.LogWarning($"Unknown id {idList[i]}");
  582. }
  583. }
  584. }
  585. else if (mailReward.Key == "flower")
  586. {
  587. List<int> idList = Auxiliary.StringToInts(' ', mailReward.Value, new List<int>());
  588. FlowerInfo flowerInfo;
  589. for (int i = 0; i < idList.Count; i++)
  590. {
  591. if (GardenManager.FlowerInfoDic.TryGetValue(idList[i], out flowerInfo))
  592. {
  593. flowerInfo.Add();
  594. Transform mailItem = ResourceManager.Get("MailItem", Folder.UI, false, ResourceManager.Get(ObjectLabel.Bd_Grid), new Vector3(), ObjType.MailItem);
  595. float newSpriteSize = 0.225f;
  596. mailItem.GetChild(1).SetActive(false);
  597. mailItem.GetChild(0).GetComponent<Image>().sprite = flowerInfo.Icon;
  598. mailItem.GetChild(0).GetComponent<Image>().Resize(true, newSpriteSize, newSpriteSize);
  599. mailItem.GetChild(0).transform.localPosition = new Vector2(0, 0);
  600. mailItem.GetChild(2).GetComponent<Text>().text = flowerInfo.Name;
  601. InfoBoxManager.GardenInfoBox.Show($"{Language.GetStr(LanguageLabel.Common__Get)} {TransferLabel.FlowerSprite}{flowerInfo.Name}", 10, Color.white, ResourceManager.LoadSprite("Atlas", Folder.Atlas));
  602. }
  603. else
  604. {
  605. Debug.LogWarning($"Unknown id {idList[i]}");
  606. }
  607. }
  608. }
  609. else if (mailReward.Key == "coin")
  610. {
  611. Manager.AddCoin(double.Parse(mailReward.Value), StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.Mail);
  612. Transform mailItem = ResourceManager.Get("MailItem", Folder.UI, false, ResourceManager.Get(ObjectLabel.Bd_Grid), new Vector3(), ObjType.MailItem);
  613. float newSpriteSize = 0.75f;
  614. mailItem.GetChild(1).SetActive(false);
  615. mailItem.GetChild(0).GetComponent<Image>().sprite = ResourceManager.LoadSprite("金币", Folder.UI);
  616. mailItem.GetChild(0).GetComponent<Image>().Resize(true, newSpriteSize, newSpriteSize);
  617. mailItem.GetChild(0).transform.localPosition = new Vector2(0, 0);
  618. mailItem.GetChild(2).GetComponent<Text>().text = Auxiliary.ShrinkNumberStr(double.Parse(mailReward.Value));
  619. InfoBoxManager.GardenInfoBox.Show($"{Language.GetStr(LanguageLabel.Common__Get)} {TransferLabel.CoinSprite}{Auxiliary.ShrinkNumberStr(double.Parse(mailReward.Value))}", 10, Color.white, ResourceManager.LoadSprite("Atlas", Folder.Atlas));
  620. }
  621. else if (mailReward.Key == "diamond")
  622. {
  623. Manager.AddDiamond(double.Parse(mailReward.Value), StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.Mail);
  624. Transform mailItem = ResourceManager.Get("MailItem", Folder.UI, false, ResourceManager.Get(ObjectLabel.Bd_Grid), new Vector3(), ObjType.MailItem);
  625. float newSpriteSize = 0.75f;
  626. mailItem.GetChild(1).SetActive(false);
  627. mailItem.GetChild(0).GetComponent<Image>().sprite = ResourceManager.LoadSprite("钻石", Folder.UI);
  628. mailItem.GetChild(0).GetComponent<Image>().Resize(true, newSpriteSize, newSpriteSize);
  629. mailItem.GetChild(0).transform.localPosition = new Vector2(0, 0);
  630. mailItem.GetChild(2).GetComponent<Text>().text = Auxiliary.ShrinkNumberStr(double.Parse(mailReward.Value));
  631. InfoBoxManager.GardenInfoBox.Show($"{Language.GetStr(LanguageLabel.Common__Get)} {TransferLabel.DiamondSprite}{Auxiliary.ShrinkNumberStr(double.Parse(mailReward.Value))}", 10, Color.white, ResourceManager.LoadSprite("Atlas", Folder.Atlas));
  632. }
  633. else
  634. {
  635. Debug.Log(mailReward.Key);
  636. }
  637. }
  638. public static void DecodeMailXml(string mailXml)
  639. {
  640. MailRewardList = new List<MailReward>();
  641. XmlDocument xmlDoc = new XmlDocument();
  642. //Debug.Log("Decode");
  643. try
  644. {
  645. xmlDoc.LoadXml(mailXml);
  646. }
  647. catch (Exception)
  648. {
  649. return;
  650. }
  651. XmlNodeList rewardNodeList = xmlDoc.SelectSingleNode("mail").SelectNodes("OneTimeReward");
  652. //Debug.Log(ManaData.GetPlayerString("OneTimeReward"));
  653. List<string> receivedIdList = Auxiliary.StringToStrings(' ', ConfigManager.GetPlayerString("OneTimeReward"), new List<string>());
  654. //Debug.Log("");
  655. //foreach (var id in receivedIdList)
  656. //{
  657. // Debug.Log(id);
  658. //}
  659. //Debug.Log("");
  660. for (int i = 0; i < rewardNodeList.Count; i++)
  661. {
  662. string id = rewardNodeList[i].SelectSingleNode("id").InnerText;
  663. //Debug.Log(id);
  664. if (receivedIdList.Contains(id))
  665. {
  666. continue;
  667. }
  668. DateTime startTime = DateTime.Parse(rewardNodeList[i].SelectSingleNode("start").InnerText);
  669. DateTime endTime = DateTime.Parse(rewardNodeList[i].SelectSingleNode("end").InnerText);
  670. if (Time < startTime || Time > endTime)
  671. {
  672. //Debug.Log("Skip");
  673. continue;
  674. }
  675. XmlNodeList targetIdNodeList = rewardNodeList[i].SelectSingleNode("targets").SelectNodes("id");
  676. for (int j = 0; j < targetIdNodeList.Count; j++)
  677. {
  678. if (targetIdNodeList[j].InnerText == ID)
  679. {
  680. XmlNodeList xmlNodeList = rewardNodeList[i].SelectSingleNode("reward").ChildNodes;
  681. for (int k = 0; k < xmlNodeList.Count; k++)
  682. {
  683. MailRewardList.Add(new MailReward(id, xmlNodeList[k].Name, xmlNodeList[k].InnerText));
  684. }
  685. break;
  686. }
  687. }
  688. }
  689. }
  690. public static void PackTypeRequest()
  691. {
  692. IndexRequest
  693. (
  694. data =>
  695. {
  696. PackLock = Auxiliary.StringToBool(data["l"][0]["val"].ToJson().Trim('"'), true);
  697. if (Application.platform == RuntimePlatform.Android)
  698. {
  699. PackLock = true;
  700. }
  701. if (ConfigManager.PlayerDoc_ != null)
  702. {
  703. ConfigManager.SavePlayerBool("PackLock", PackLock);
  704. }
  705. }
  706. );
  707. }
  708. public static void IOSAlipayRequest()
  709. {
  710. IndexRequest
  711. (
  712. data =>
  713. {
  714. IAPManager.UseAlipayOnIOS = Auxiliary.StringToBool(data["l"][2]["val"].ToJson().Trim('"'), false);
  715. }
  716. );
  717. }
  718. public static void GetProductID(string id, URLRequest.URLRequestCallBackDelegate callback)
  719. {
  720. URLRequestData urlData = new URLRequestData();
  721. urlData.Add("t", 1);
  722. urlData.Add("i", id);
  723. urlData.Add("u", JsonData.Inst_Object["i"].ToJson().Trim('"'));
  724. URLRequest.CreateStrURLRequest(true, GetProductIDURL, urlData, callback, URLRequest.Method.POST);
  725. }
  726. public static void Login(URLRequest.URLRequestJsonCallBackDelegate callback = null)
  727. {
  728. URLRequestData urlData = new URLRequestData();
  729. urlData.Add("u", SystemInfo.deviceUniqueIdentifier);
  730. URLRequest.CreateURLRequest(false, LoginURL, urlData, LoginCallback + callback, URLRequest.Method.POST);
  731. }
  732. private static void LoginCallback(JsonData jsonData)
  733. {
  734. Complete = true;
  735. if (jsonData.Inst_Object.ContainsKey("c"))
  736. {
  737. Connect = true;
  738. //Debug.Log(jsonData.ToJson());
  739. JsonData = jsonData;
  740. Time = DateUtil.GetTime(jsonData["time"].ToJson());
  741. PraiseAmt = int.Parse(jsonData["p"].ToJson().Trim('"'));
  742. if (ConfigManager.DamageLock)
  743. {
  744. ID = jsonData["o"].ToString();
  745. SerialNumber = jsonData["i"].ToString();
  746. }
  747. else if (ConfigManager.PlayerDoc_ != null)
  748. {
  749. if (ConfigManager.GetPlayerString("ID") == "Default")
  750. {
  751. ID = jsonData["o"].ToString();
  752. if (Initializer.Complete)
  753. {
  754. ResourceManager.SetText(ObjectLabel.L_UserLab, ID);
  755. }
  756. }
  757. if (ConfigManager.GetPlayerString("SerialNumber") == "Default")
  758. {
  759. SerialNumber = JsonData["i"].ToString();
  760. }
  761. }
  762. if (FirstConnect)
  763. {
  764. FirstConnect = false;
  765. StaticsManager.GetInstance().ActOrReg(ID, DataEyeGA.AccountType.Official);
  766. }
  767. //ManaDebug.Log("<color=red>连接成功</color>");
  768. }
  769. else
  770. {
  771. Connect = false;
  772. //ManaDebug.Log("<color=red>连接失败</color>");
  773. }
  774. }
  775. public static void Save()
  776. {
  777. Manager.SaveTimer = 0;
  778. URLRequestData urlData = new URLRequestData();
  779. urlData.Add("u", SerialNumber);
  780. urlData.Add("v", ReplayVersion);
  781. ConfigManager.SavePlayerConfig();
  782. urlData.Add("l", ConfigManager.PlayerDoc.OuterXml);
  783. URLRequest.CreateURLRequest(false, SaveURL, urlData, SaveCallback, URLRequest.Method.POST);
  784. //URLRequest.CreateStrURLRequest(false, NewBaseURL + "/user/save", urlData, Debug.Log, URLRequest.Method.POST);
  785. }
  786. private static void SaveCallback(JsonData jsonData)
  787. {
  788. //ManaDebug.Log("<color=red>发送存档成功</color>");
  789. }
  790. public static void Other(string id, URLRequest.URLRequestJsonCallBackDelegate callback)
  791. {
  792. URLRequestData urlData = new URLRequestData();
  793. urlData.Add("u", id);
  794. URLRequest.CreateURLRequest(true, OtherURL, urlData, callback, URLRequest.Method.POST);
  795. }
  796. public static void DownloadByID(string id, URLRequest.URLRequestJsonCallBackDelegate callback)
  797. {
  798. URLRequestData urlData = new URLRequestData();
  799. urlData.Add("u", id);
  800. URLRequest.CreateURLRequest(true, DownloadURL, urlData, callback, URLRequest.Method.POST);
  801. }
  802. public static void DownloadBySerialNumber(string serialNumber, URLRequest.URLRequestJsonCallBackDelegate callback)
  803. {
  804. URLRequestData urlData = new URLRequestData();
  805. urlData.Add("u", serialNumber);
  806. URLRequest.CreateURLRequest(true, DownloadURL, urlData, callback, URLRequest.Method.POST);
  807. }
  808. public static void RandomLoad(URLRequest.URLRequestJsonCallBackDelegate callback)
  809. {
  810. URLRequestData urlData = new URLRequestData();
  811. urlData.Add("i", "");
  812. URLRequest.CreateURLRequest(false, RandomURL, urlData, callback, URLRequest.Method.POST);
  813. }
  814. public static void GetThanksGiftInfo(Action<JsonData> callback, Action failed)
  815. {
  816. URLRequestData urlData = new URLRequestData();
  817. URLRequest.CreateURLRequest
  818. (
  819. false,
  820. ThanksGiftInfoURL,
  821. urlData,
  822. jData =>
  823. {
  824. if (jData.Inst_Object.ContainsKey("l"))
  825. {
  826. callback.Invoke(jData["l"]);
  827. }
  828. else
  829. {
  830. failed.Invoke();
  831. }
  832. }
  833. );
  834. //URLRequest.CreateStrURLRequest
  835. //(
  836. // false,
  837. // NewBaseURL + "/index/gift",
  838. // urlData,
  839. // Debug.Log
  840. //);
  841. //JsonData rootJson = new JsonData();
  842. //JsonData jData = new JsonData();
  843. //rootJson["l"] = jData;
  844. //JsonData json = new JsonData();
  845. //json["i"] = 1;
  846. //json["g"] = "g100";
  847. //jData.Add(json);
  848. //json = new JsonData();
  849. //json["i"] = 2;
  850. //json["g"] = "d200";
  851. //jData.Add(json);
  852. //json = new JsonData();
  853. //json["i"] = 3;
  854. //json["g"] = "p1";
  855. //rootJson.Add(json);
  856. //json = new JsonData();
  857. //json["i"] = 4;
  858. //json["g"] = "f1";
  859. //rootJson.Add(json);
  860. //json = new JsonData();
  861. //json["i"] = 5;
  862. //json["g"] = "c1";
  863. //rootJson.Add(json);
  864. //json = new JsonData();
  865. //json["i"] = 6;
  866. //json["g"] = "s1";
  867. //rootJson.Add(json);
  868. //json = new JsonData();
  869. //json["i"] = 7;
  870. //json["g"] = "a1";
  871. //rootJson.Add(json);
  872. //Debug.Log(rootJson.ToJson());
  873. //Debug.Log(rootJson["l"][0].ToJson());
  874. //Debug.Log(rootJson["l"][1].ToJson());
  875. }
  876. public static void Report()
  877. {
  878. ResourceManager.Get(ObjectLabel.Lb_Info).TweenBacCG();
  879. string emailAddress = ResourceManager.Get<Text>(ObjectLabel.Lb_InputLab0).text;
  880. if (string.IsNullOrEmpty(emailAddress) || !emailAddress.Contains("@"))
  881. {
  882. Bubble.Show(null, Language.GetStr(LanguageLabel.UI__Lb_Send3));
  883. return;
  884. }
  885. string content = ResourceManager.Get<Text>(ObjectLabel.Lb_InputLab).text;
  886. if (string.IsNullOrEmpty(content))
  887. {
  888. Bubble.Show(null, Language.GetStr(LanguageLabel.UI__Lb_Send2));
  889. }
  890. else if(ReportContent == content)
  891. {
  892. Bubble.Show(null, Language.GetStr(LanguageLabel.UI__Lb_Send1));
  893. }
  894. else
  895. {
  896. MailMessage mailMessage = new MailMessage();
  897. mailMessage.To.Add(new MailAddress(ReportMailAddress));
  898. mailMessage.From = new MailAddress("dashgamegarden@163.com");
  899. ReportContent = content;
  900. mailMessage.Body = emailAddress + '\n' + ReportContent + '\n' + GetSystemInfo();
  901. mailMessage.Subject = ID + " MyLovelyGargen Issue";
  902. SmtpClient smtpClient = new SmtpClient("smtp.163.com");
  903. smtpClient.Credentials = new MyCredentials("dashgamegarden@163.com", "cs670cs");
  904. smtpClient.SendAsync(mailMessage, "Async");
  905. Bubble.Show(null, Language.GetStr(LanguageLabel.UI__Lb_Send0));
  906. }
  907. }
  908. public static string GetSystemInfo()
  909. {
  910. StringBuilder sb = new StringBuilder();
  911. sb.AppendLine("deviceType :" + SystemInfo.deviceType.ToString());
  912. sb.AppendLine("deviceName :" + SystemInfo.deviceName.ToString());
  913. sb.AppendLine("deviceModel :" + SystemInfo.deviceModel.ToString());
  914. sb.AppendLine("deviceUniqueIdentifier :" + SystemInfo.deviceUniqueIdentifier.ToString());
  915. sb.AppendLine("graphicsDeviceID :" + SystemInfo.graphicsDeviceID.ToString());
  916. sb.AppendLine("graphicsDeviceType :" + SystemInfo.graphicsDeviceType.ToString());
  917. sb.AppendLine("graphicsDeviceName :" + SystemInfo.graphicsDeviceName.ToString());
  918. sb.AppendLine("graphicsShaderLevel :" + SystemInfo.graphicsShaderLevel.ToString());
  919. sb.AppendLine("graphicsMemorySize :" + SystemInfo.graphicsMemorySize.ToString());
  920. sb.AppendLine("graphicsDeviceVersion :" + SystemInfo.graphicsDeviceVersion.ToString());
  921. sb.AppendLine("graphicsMultiThreaded :" + SystemInfo.graphicsMultiThreaded.ToString());
  922. sb.AppendLine("graphicsDeviceVendor :" + SystemInfo.graphicsDeviceVendor.ToString());
  923. sb.AppendLine("graphicsDeviceVendorID :" + SystemInfo.graphicsDeviceVendorID.ToString());
  924. sb.AppendLine("npotSupport :" + SystemInfo.npotSupport.ToString());
  925. sb.AppendLine("maxTextureSize :" + SystemInfo.maxTextureSize.ToString());
  926. sb.AppendLine("operatingSystem :" + SystemInfo.operatingSystem.ToString());
  927. sb.AppendLine("operatingSystemFamily :" + SystemInfo.operatingSystemFamily.ToString());
  928. sb.AppendLine("processorType :" + SystemInfo.processorType.ToString());
  929. sb.AppendLine("processorCount :" + SystemInfo.processorCount.ToString());
  930. sb.AppendLine("processorFrequency :" + SystemInfo.processorFrequency.ToString());
  931. sb.AppendLine("copyTextureSupport :" + SystemInfo.copyTextureSupport.ToString());
  932. sb.AppendLine("graphicsMultiThreaded :" + SystemInfo.graphicsMultiThreaded.ToString());
  933. sb.AppendLine("supportedRenderTargetCount :" + SystemInfo.supportedRenderTargetCount.ToString());
  934. sb.AppendLine("supports3DTextures :" + SystemInfo.supports3DTextures.ToString());
  935. sb.AppendLine("supports2DArrayTextures :" + SystemInfo.supports2DArrayTextures.ToString());
  936. sb.AppendLine("supportsAccelerometer :" + SystemInfo.supportsAccelerometer.ToString());
  937. sb.AppendLine("supportsAudio :" + SystemInfo.supportsAudio.ToString());
  938. sb.AppendLine("supportsComputeShaders :" + SystemInfo.supportsComputeShaders.ToString());
  939. sb.AppendLine("supportsCubemapArrayTextures :" + SystemInfo.supportsCubemapArrayTextures.ToString());
  940. sb.AppendLine("supportsGyroscope :" + SystemInfo.supportsGyroscope.ToString());
  941. sb.AppendLine("supportsImageEffects :" + SystemInfo.supportsImageEffects.ToString());
  942. sb.AppendLine("supportsInstancing :" + SystemInfo.supportsInstancing.ToString());
  943. sb.AppendLine("supportsLocationService :" + SystemInfo.supportsLocationService.ToString());
  944. sb.AppendLine("supportsMotionVectors :" + SystemInfo.supportsMotionVectors.ToString());
  945. sb.AppendLine("supportsRawShadowDepthSampling :" + SystemInfo.supportsRawShadowDepthSampling.ToString());
  946. sb.AppendLine("supportsRenderToCubemap :" + SystemInfo.supportsRenderToCubemap.ToString());
  947. sb.AppendLine("supportsShadows :" + SystemInfo.supportsShadows.ToString());
  948. sb.AppendLine("supportsSparseTextures :" + SystemInfo.supportsSparseTextures.ToString());
  949. sb.AppendLine("supportsVibration :" + SystemInfo.supportsVibration.ToString());
  950. sb.AppendLine("systemMemorySize :" + SystemInfo.systemMemorySize.ToString());
  951. sb.AppendLine("usesReversedZBuffer :" + SystemInfo.usesReversedZBuffer.ToString());
  952. return sb.ToString();
  953. }
  954. }