ManaServer.cs 35 KB

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