ManaServer.cs 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  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. //"1710065808151506837" "a54unp"
  106. //URLRequestData urlData = new URLRequestData();
  107. //urlData.Add("s", "1710065808151506837");
  108. //URLRequest.CreateStrURLRequest(true, BaseURL + "/user/delete", urlData, Debug.Log, URLRequest.Method.POST);
  109. }
  110. public void Update()
  111. {
  112. if (!ManaCenter.Complete && !Complete)
  113. {
  114. Timer += UnityEngine.Time.deltaTime;
  115. if (Timer >= 2f)
  116. {
  117. Timer = 0;
  118. Counter++;
  119. if (Counter > 4)
  120. {
  121. Complete = true;
  122. ManaCenter.LoginCallbackInitial(new JsonData());
  123. }
  124. else
  125. {
  126. Login(ManaCenter.LoginCallbackInitial);
  127. IOSAlipayRequest();
  128. }
  129. }
  130. }
  131. }
  132. public override bool RegistImmed()
  133. {
  134. if (base.RegistImmed())
  135. {
  136. return true;
  137. }
  138. enabled = true;
  139. return false;
  140. }
  141. public static void SetNickName(string nickname, Action succeedCallback, Action failCallback)
  142. {
  143. URLRequestData urlData = new URLRequestData();
  144. urlData.Add("u", SerialNumber);
  145. urlData.Add("n", nickname);
  146. URLRequest.CreateStrURLRequest
  147. (
  148. true,
  149. NewBaseURL + "/user/nickname",
  150. urlData,
  151. data =>
  152. {
  153. if (data == "{\"error\":0}")
  154. {
  155. succeedCallback.Invoke();
  156. }
  157. else
  158. {
  159. failCallback.Invoke();
  160. }
  161. },
  162. URLRequest.Method.POST
  163. );
  164. }
  165. public static void RankRequest()
  166. {
  167. URLRequestData urlData = new URLRequestData();
  168. URLRequest.CreateStrURLRequest
  169. (
  170. false,
  171. NewBaseURL + "/user/look",
  172. urlData,
  173. data =>
  174. {
  175. //Debug.Log(data);
  176. string str = "{\"l\":" + data.Substring(1) + "}";
  177. JsonData jsondata;
  178. try
  179. {
  180. jsondata = JsonMapper.ToObject(str);
  181. }
  182. catch (Exception)
  183. {
  184. jsondata = new JsonData();
  185. jsondata["error"] = 0;
  186. }
  187. RankRequestCallback(jsondata);
  188. //Debug.Log(data[0]);
  189. //StreamWriter streamWriter = new StreamWriter("Assets/123.txt");
  190. //streamWriter.Write(data);
  191. //streamWriter.Close();
  192. }
  193. );
  194. //URLRequest.CreateURLRequest
  195. //(
  196. // NewBaseURL + "/user/look",
  197. // urlData,
  198. // RankRequestCallback,
  199. // URLRequest.Method.POST
  200. //);
  201. }
  202. public static void RankRequestCallback(JsonData jsonData)
  203. {
  204. if (jsonData.Inst_Object.ContainsKey("l"))
  205. {
  206. RankDatas = new List<JsonData>();
  207. for (int i = 0; i < jsonData["l"].Count; i++)
  208. {
  209. RankDatas.Add(jsonData["l"][i]);
  210. }
  211. RankReady = true;
  212. ManaSocial.InitializeRankPanel();
  213. }
  214. }
  215. public static void NotificationRequest()
  216. {
  217. //Debug.Log("A");
  218. IndexRequest
  219. (
  220. data =>
  221. {
  222. //Debug.Log("B");
  223. URLRequestData urlData = new URLRequestData();
  224. URLRequest.CreateStrURLRequest
  225. (
  226. true,
  227. data["l"][3]["val"].ToString(),
  228. urlData,
  229. notificationXml =>
  230. {
  231. //Debug.Log("C");
  232. NotificationCallback(notificationXml);
  233. }
  234. );
  235. }
  236. );
  237. }
  238. public static void NotificationCallback(string xml)
  239. {
  240. //Debug.Log("D");
  241. XmlNode rootNode;
  242. XmlDocument document = new XmlDocument();
  243. try
  244. {
  245. document.LoadXml(xml);
  246. rootNode = document.SelectSingleNode("announce");
  247. NotificationIndex = int.Parse(rootNode.SelectSingleNode("version").InnerText);
  248. XmlNodeList nodeList = rootNode.SelectNodes("item");
  249. List<string> urlList = new List<string>();
  250. for (int i = 0; i < nodeList.Count; i++)
  251. {
  252. DecodeNotificationItem(nodeList[i], urlList);
  253. }
  254. Auxiliary.Instance.StartCoroutine(PullNotifyTexs(urlList, PullNotifyTexsCallback));
  255. }
  256. catch (Exception)
  257. {
  258. }
  259. finally
  260. {
  261. }
  262. }
  263. public static void DecodeNotificationItem(XmlNode node, List<string> urlList)
  264. {
  265. XmlNodeList nodeList = node.SelectNodes("title");
  266. for (int i = 0; i < nodeList.Count; i++)
  267. {
  268. ManaNotify.AddLine(false, nodeList[i].Attributes[0].Value, nodeList[i].InnerText, TextAnchor.MiddleLeft);
  269. }
  270. ManaNotify.AddLine(false, "null", node.SelectSingleNode("date").InnerText, TextAnchor.MiddleLeft);
  271. nodeList = node.SelectSingleNode("content").ChildNodes;
  272. for (int i = 0; i < nodeList.Count; i++)
  273. {
  274. if (nodeList[i].Name == "text")
  275. {
  276. ManaNotify.AddLine(false, nodeList[i].Attributes[0].Value, nodeList[i].InnerText, TextAnchor.MiddleLeft);
  277. }
  278. else if (nodeList[i].Name == "image")
  279. {
  280. urlList.UniqueAdd(nodeList[i].InnerText);
  281. ManaNotify.AddLine(true, "null", $"<({Path.GetFileNameWithoutExtension(nodeList[i].InnerText)})>", TextAnchor.MiddleCenter);
  282. }
  283. }
  284. ManaNotify.AddLine(false, "null", "", TextAnchor.MiddleLeft);
  285. }
  286. public static void PullNotifyTexsCallback(List<WWW> wwwList)
  287. {
  288. List<Texture2D> textureList = new List<Texture2D>();
  289. List<SpriteInfo> spriteInfoList = new List<SpriteInfo>();
  290. for (int i = 0; i < wwwList.Count; i++)
  291. {
  292. textureList.Add(wwwList[i].texture);
  293. SpriteInfo spriteInfo = new SpriteInfo();
  294. spriteInfo.Name = Path.GetFileNameWithoutExtension(wwwList[i].url);
  295. spriteInfoList.Add(spriteInfo);
  296. }
  297. Texture2D atlas = new Texture2D(2048, 2048);
  298. Rect[] rects = atlas.PackTextures(textureList.ToArray(), 1);
  299. Sprite sprite = Sprite.Create(atlas, new Rect(0, 0, atlas.width, atlas.height), new Vector2(0.5f, 0.5f));
  300. for (int i = 0; i < spriteInfoList.Count; i++)
  301. {
  302. spriteInfoList[i].Width = textureList[i].width;
  303. spriteInfoList[i].Height = textureList[i].height;
  304. spriteInfoList[i].UvList = new List<Vector2>()
  305. {
  306. new Vector2(rects[i].xMin, rects[i].yMax),
  307. new Vector2(rects[i].xMax, rects[i].yMax),
  308. new Vector2(rects[i].xMax, rects[i].yMin),
  309. new Vector2(rects[i].xMin, rects[i].yMin),
  310. };
  311. SpriteAsset.SpriteInfoDic.Add(spriteInfoList[i].Name, spriteInfoList[i]);
  312. }
  313. NotificationSprite = sprite;
  314. NotificationReady = true;
  315. if (Initializer.Complete)
  316. {
  317. ManaReso.Get("C_Notify").TweenForCG();
  318. }
  319. //Debug.Log("Done");
  320. }
  321. public static IEnumerator PullNotifyTexs(List<string> urlList, Action<List<WWW>> callback)
  322. {
  323. List<WWW> wwwList = new List<WWW>();
  324. for (int i = 0; i < urlList.Count; i++)
  325. {
  326. wwwList.Add(new WWW(urlList[i]));
  327. }
  328. for (int i = 0; i < wwwList.Count; i++)
  329. {
  330. yield return wwwList[i];
  331. }
  332. callback(wwwList);
  333. }
  334. public static void Praise(string sendID, string receiveID)
  335. {
  336. if (receiveID == null)
  337. {
  338. return;
  339. }
  340. URLRequestData urlData = new URLRequestData();
  341. urlData.Add("u", sendID);
  342. urlData.Add("t", receiveID);
  343. URLRequest.CreateStrURLRequest(true, NewBaseURL + "/praise/click", urlData, (data)=> {}, URLRequest.Method.POST);
  344. }
  345. public static void Target(string userID, string targetID, Action<JsonData> callback)
  346. {
  347. URLRequestData urlData = new URLRequestData();
  348. urlData.Add("u", userID);
  349. urlData.Add("t", targetID);
  350. URLRequest.CreateURLRequest(true, NewBaseURL + "/praise/target", urlData, data => callback(data), URLRequest.Method.POST);
  351. }
  352. public static void AddComment(string sendID, string receiveID, string content, CommentType type)
  353. {
  354. if (string.IsNullOrEmpty(sendID) || string.IsNullOrEmpty(receiveID))
  355. {
  356. return;
  357. }
  358. if (sendID.ToLower() == "default" || receiveID.ToLower() == "default")
  359. {
  360. return;
  361. }
  362. URLRequestData urlData = new URLRequestData();
  363. urlData.Add("c", sendID);
  364. urlData.Add("u", receiveID);
  365. urlData.Add("i", content);
  366. urlData.Add("t", type.GetHashCode());
  367. //Debug.LogWarning(sendID);
  368. //Debug.LogWarning(receiveID);
  369. //Debug.LogWarning(content);
  370. //Debug.LogWarning(type.GetHashCode());
  371. URLRequest.CreateStrURLRequest
  372. (
  373. true,
  374. NewBaseURL + "/comment/comment",
  375. urlData,
  376. data =>
  377. {
  378. if (data == "{\"error\":0}")
  379. {
  380. Bubble.Show(Language.GetStr("UI", "Q_CommentDone"));
  381. ManaSocial.UpdatePage(false);
  382. }
  383. else
  384. {
  385. Bubble.Show(Language.GetStr("UI", "Q_CommentFail"));
  386. }
  387. },
  388. URLRequest.Method.POST
  389. );
  390. }
  391. public static void GetComment(string id, string page, CommentType type, Action<JsonData> callback)
  392. {
  393. JsonData defaultData = new JsonData();
  394. defaultData["error"] = 0;
  395. if (string.IsNullOrEmpty(id))
  396. {
  397. callback.Invoke(defaultData);
  398. return;
  399. }
  400. if (id.ToLower() == "default")
  401. {
  402. callback.Invoke(defaultData);
  403. return;
  404. }
  405. URLRequestData urlData = new URLRequestData();
  406. //Debug.LogWarning(id);
  407. //Debug.LogWarning(page);
  408. //Debug.LogWarning(type.GetHashCode());
  409. urlData.Add("u", id);
  410. urlData.Add("p", page);
  411. urlData.Add("t", type.GetHashCode());
  412. URLRequest.CreateURLRequest(true, NewBaseURL + "/comment/index", urlData, data => { callback(data);}, URLRequest.Method.POST);
  413. }
  414. public static void IndexRequest(Action<JsonData> callback)
  415. {
  416. URLRequestData urlData = new URLRequestData();
  417. URLRequest.CreateURLRequest
  418. (
  419. true,
  420. NewBaseURL + "/index/index",
  421. urlData,
  422. data =>
  423. {
  424. if (data.Inst_Object.ContainsKey("error"))
  425. {
  426. if (ManaData.PlayerDoc_ != null)
  427. {
  428. if (Application.platform == RuntimePlatform.Android)
  429. {
  430. PackLock = true;
  431. }
  432. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  433. {
  434. PackLock = ManaData.GetPlayerBool("PackLock");
  435. }
  436. }
  437. }
  438. else
  439. {
  440. callback(data);
  441. }
  442. }
  443. );
  444. }
  445. public static void MailRequest()
  446. {
  447. //MailXml = "<mail>" +
  448. // "<OneTimeReward>" +
  449. // "<id>4</id>" +
  450. // "<start>2017-08-18 12:12:12</start>" +
  451. // "<end>2017-09-1 11:30:12</end>" +
  452. // "<reward>" +
  453. // "<coin>1000</coin>" +
  454. // "<diamond>10</diamond>" +
  455. // "</reward>" +
  456. // "<targets>" +
  457. // "<id>90arbl</id>" +
  458. // "</targets>" +
  459. // "</OneTimeReward>" +
  460. // "<OneTimeReward>" +
  461. // "<id>3</id>" +
  462. // "<start>2017-08-21 12:12:12</start>" +
  463. // "<end>2017-09-01 18:12:12</end>" +
  464. // "<reward>" +
  465. // "<coin>10000</coin>" +
  466. // "<diamond>100</diamond>" +
  467. // "</reward>" +
  468. // "<targets>" +
  469. // "<id>90arbl</id>" +
  470. // "</targets>" +
  471. // "</OneTimeReward>" +
  472. // "</mail>";
  473. IndexRequest
  474. (
  475. data =>
  476. {
  477. URLRequestData urlData = new URLRequestData();
  478. URLRequest.CreateStrURLRequest
  479. (
  480. true,
  481. data["l"][1]["val"].ToJson().Trim('"'),
  482. urlData,
  483. mailXml =>
  484. {
  485. MailXml = mailXml;
  486. }
  487. );
  488. }
  489. );
  490. }
  491. public static void GetMailReward()
  492. {
  493. for (int i = 0; i < MailRewardList.Count; i++)
  494. {
  495. GetMailReward(MailRewardList[i]);
  496. }
  497. }
  498. public static void GetMailReward(MailReward mailReward)
  499. {
  500. //Debug.Log(mailReward.Id);
  501. ManaData.SavePlayerString("OneTimeReward", $"{ManaData.GetPlayerString("OneTimeReward")} {mailReward.Id}".Trim(' '));
  502. if (mailReward.Key == "pack")
  503. {
  504. SkillRoot skillRoot;
  505. if (ManaCenter.SkillDic.TryGetValue($"Pack{mailReward.Value}", out skillRoot))
  506. {
  507. Pack pack = (Pack) skillRoot;
  508. pack.PurchaseResult();
  509. Transform mailItem = ManaReso.Get("MailItem", Folder.UI, false, ManaReso.Get("Bd_Grid"), new Vector3(), ObjType.MailItem);
  510. float newSpriteSize = 0.35f;
  511. mailItem.GetChild(1).SetActive(false);
  512. mailItem.GetChild(0).GetComponent<Image>().sprite = pack.Icon;
  513. mailItem.GetChild(0).GetComponent<Image>().Resize(true, newSpriteSize, newSpriteSize);
  514. mailItem.GetChild(0).transform.localPosition = new Vector2(0, 0);
  515. mailItem.GetChild(2).GetComponent<Text>().text = pack.Name;
  516. ManaInfoBox.Show(InfoCategory.Garden, $"{Language.GetStr("Common", "Get")} <(礼包)>{pack.Name}", 10, Color.white, ManaReso.LoadSprite("Atlas", Folder.Atlas));
  517. }
  518. else
  519. {
  520. Debug.LogWarning($"Unknown id {mailReward.Value}");
  521. }
  522. }
  523. else if (mailReward.Key == "close")
  524. {
  525. List<int> idList = Auxiliary.IntListParse(' ', mailReward.Value, new List<int>());
  526. CloseUnit closeUnit;
  527. for (int i = 0; i < idList.Count; i++)
  528. {
  529. if (ManaPlayer.CloseUnitDic.TryGetValue(idList[i], out closeUnit))
  530. {
  531. if (closeUnit.Bought == false)
  532. {
  533. closeUnit.Unlock();
  534. ManaPlayer.BoughtCloseList.UniqueAdd(idList[i]);
  535. }
  536. Transform mailItem = ManaReso.Get("MailItem", Folder.UI, false, ManaReso.Get("Bd_Grid"), new Vector3(), ObjType.MailItem);
  537. float newSize = 0.6f;
  538. float newSpriteSize = closeUnit.PixelSize*newSize/closeUnit.Sprites[0].rect.width;
  539. mailItem.GetChild(1).GetComponent<Image>().sprite = closeUnit.Sprites[0];
  540. mailItem.GetChild(1).GetComponent<Image>().Resize(true, newSpriteSize, newSpriteSize);
  541. mailItem.GetChild(1).transform.localPosition = new Vector2(0, closeUnit.IconOffset*newSize);
  542. if (closeUnit.Sprites.Length > 1)
  543. {
  544. mailItem.GetChild(0).SetActive(true);
  545. mailItem.GetChild(0).GetComponent<Image>().sprite = closeUnit.Sprites[1];
  546. mailItem.GetChild(0).GetComponent<Image>().Resize(true, newSpriteSize, newSpriteSize);
  547. mailItem.GetChild(0).transform.localPosition = closeUnit.IconOffset1*newSpriteSize + new Vector2(0, closeUnit.IconOffset*newSize);
  548. }
  549. else
  550. {
  551. mailItem.GetChild(0).SetActive(false);
  552. }
  553. mailItem.GetChild(2).GetComponent<Text>().text = closeUnit.Name;
  554. ManaInfoBox.Show(InfoCategory.Garden, $"{Language.GetStr("Common", "Get")} <(服装)>{closeUnit.Name}", 10, Color.white, ManaReso.LoadSprite("Atlas", Folder.Atlas));
  555. }
  556. else
  557. {
  558. Debug.LogWarning($"Unknown id {idList[i]}");
  559. }
  560. }
  561. }
  562. else if (mailReward.Key == "flower")
  563. {
  564. List<int> idList = Auxiliary.IntListParse(' ', mailReward.Value, new List<int>());
  565. FlowerInfo flowerInfo;
  566. for (int i = 0; i < idList.Count; i++)
  567. {
  568. if (ManaGarden.FlowerInfoDic.TryGetValue(idList[i], out flowerInfo))
  569. {
  570. flowerInfo.Add();
  571. Transform mailItem = ManaReso.Get("MailItem", Folder.UI, false, ManaReso.Get("Bd_Grid"), new Vector3(), ObjType.MailItem);
  572. float newSpriteSize = 0.225f;
  573. mailItem.GetChild(1).SetActive(false);
  574. mailItem.GetChild(0).GetComponent<Image>().sprite = flowerInfo.Icon;
  575. mailItem.GetChild(0).GetComponent<Image>().Resize(true, newSpriteSize, newSpriteSize);
  576. mailItem.GetChild(0).transform.localPosition = new Vector2(0, 0);
  577. mailItem.GetChild(2).GetComponent<Text>().text = flowerInfo.Name;
  578. ManaInfoBox.Show(InfoCategory.Garden, $"{Language.GetStr("Common", "Get")} <(花朵)>{flowerInfo.Name}", 10, Color.white, ManaReso.LoadSprite("Atlas", Folder.Atlas));
  579. }
  580. else
  581. {
  582. Debug.LogWarning($"Unknown id {idList[i]}");
  583. }
  584. }
  585. }
  586. else if (mailReward.Key == "coin")
  587. {
  588. ManaCenter.AddCoin(double.Parse(mailReward.Value), StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.Mail);
  589. Transform mailItem = ManaReso.Get("MailItem", Folder.UI, false, ManaReso.Get("Bd_Grid"), new Vector3(), ObjType.MailItem);
  590. float newSpriteSize = 0.75f;
  591. mailItem.GetChild(1).SetActive(false);
  592. mailItem.GetChild(0).GetComponent<Image>().sprite = ManaReso.LoadSprite("金币", Folder.UI);
  593. mailItem.GetChild(0).GetComponent<Image>().Resize(true, newSpriteSize, newSpriteSize);
  594. mailItem.GetChild(0).transform.localPosition = new Vector2(0, 0);
  595. mailItem.GetChild(2).GetComponent<Text>().text = Auxiliary.ShrinkNumberStr(double.Parse(mailReward.Value));
  596. ManaInfoBox.Show(InfoCategory.Garden, $"{Language.GetStr("Common", "Get")} <(金币)>{Auxiliary.ShrinkNumberStr(double.Parse(mailReward.Value))}", 10, Color.white, ManaReso.LoadSprite("Atlas", Folder.Atlas));
  597. }
  598. else if (mailReward.Key == "diamond")
  599. {
  600. ManaCenter.AddDiamond(double.Parse(mailReward.Value), StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.Mail);
  601. Transform mailItem = ManaReso.Get("MailItem", Folder.UI, false, ManaReso.Get("Bd_Grid"), new Vector3(), ObjType.MailItem);
  602. float newSpriteSize = 0.75f;
  603. mailItem.GetChild(1).SetActive(false);
  604. mailItem.GetChild(0).GetComponent<Image>().sprite = ManaReso.LoadSprite("钻石", Folder.UI);
  605. mailItem.GetChild(0).GetComponent<Image>().Resize(true, newSpriteSize, newSpriteSize);
  606. mailItem.GetChild(0).transform.localPosition = new Vector2(0, 0);
  607. mailItem.GetChild(2).GetComponent<Text>().text = Auxiliary.ShrinkNumberStr(double.Parse(mailReward.Value));
  608. ManaInfoBox.Show(InfoCategory.Garden, $"{Language.GetStr("Common", "Get")} <(钻石)>{Auxiliary.ShrinkNumberStr(double.Parse(mailReward.Value))}", 10, Color.white, ManaReso.LoadSprite("Atlas", Folder.Atlas));
  609. }
  610. else
  611. {
  612. Debug.Log(mailReward.Key);
  613. }
  614. }
  615. public static void DecodeMailXml(string mailXml)
  616. {
  617. MailRewardList = new List<MailReward>();
  618. XmlDocument xmlDoc = new XmlDocument();
  619. //Debug.Log("Decode");
  620. try
  621. {
  622. xmlDoc.LoadXml(mailXml);
  623. }
  624. catch (Exception)
  625. {
  626. return;
  627. }
  628. XmlNodeList rewardNodeList = xmlDoc.SelectSingleNode("mail").SelectNodes("OneTimeReward");
  629. //Debug.Log(ManaData.GetPlayerString("OneTimeReward"));
  630. List<string> receivedIdList = Auxiliary.StringListParse(' ', ManaData.GetPlayerString("OneTimeReward"), new List<string>());
  631. //Debug.Log("");
  632. //foreach (var id in receivedIdList)
  633. //{
  634. // Debug.Log(id);
  635. //}
  636. //Debug.Log("");
  637. for (int i = 0; i < rewardNodeList.Count; i++)
  638. {
  639. string id = rewardNodeList[i].SelectSingleNode("id").InnerText;
  640. //Debug.Log(id);
  641. if (receivedIdList.Contains(id))
  642. {
  643. continue;
  644. }
  645. DateTime startTime = DateTime.Parse(rewardNodeList[i].SelectSingleNode("start").InnerText);
  646. DateTime endTime = DateTime.Parse(rewardNodeList[i].SelectSingleNode("end").InnerText);
  647. if (Time < startTime || Time > endTime)
  648. {
  649. //Debug.Log("Skip");
  650. continue;
  651. }
  652. XmlNodeList targetIdNodeList = rewardNodeList[i].SelectSingleNode("targets").SelectNodes("id");
  653. for (int j = 0; j < targetIdNodeList.Count; j++)
  654. {
  655. if (targetIdNodeList[j].InnerText == ID)
  656. {
  657. XmlNodeList xmlNodeList = rewardNodeList[i].SelectSingleNode("reward").ChildNodes;
  658. for (int k = 0; k < xmlNodeList.Count; k++)
  659. {
  660. MailRewardList.Add(new MailReward(id, xmlNodeList[k].Name, xmlNodeList[k].InnerText));
  661. }
  662. break;
  663. }
  664. }
  665. }
  666. }
  667. public static void PackTypeRequest()
  668. {
  669. IndexRequest
  670. (
  671. data =>
  672. {
  673. PackLock = Auxiliary.BoolParse(data["l"][0]["val"].ToJson().Trim('"'), true);
  674. if (Application.platform == RuntimePlatform.Android)
  675. {
  676. PackLock = true;
  677. }
  678. if (ManaData.PlayerDoc_ != null)
  679. {
  680. ManaData.SavePlayerBool("PackLock", PackLock);
  681. }
  682. }
  683. );
  684. }
  685. public static void IOSAlipayRequest()
  686. {
  687. IndexRequest
  688. (
  689. data =>
  690. {
  691. ManaIAP.UseAlipayOnIOS = Auxiliary.BoolParse(data["l"][2]["val"].ToJson().Trim('"'), false);
  692. }
  693. );
  694. }
  695. public static void GetProductID(string id, URLRequest.URLRequestCallBackDelegate callback)
  696. {
  697. URLRequestData urlData = new URLRequestData();
  698. urlData.Add("t", 1);
  699. urlData.Add("i", id);
  700. urlData.Add("u", JsonData.Inst_Object["i"].ToJson().Trim('"'));
  701. URLRequest.CreateStrURLRequest(true, NewBaseURL + "/pay/pay", urlData, callback, URLRequest.Method.POST);
  702. }
  703. public static void Login(URLRequest.URLRequestJsonCallBackDelegate callback = null)
  704. {
  705. URLRequestData urlData = new URLRequestData();
  706. urlData.Add("u", SystemInfo.deviceUniqueIdentifier);
  707. URLRequest.CreateURLRequest(false, NewBaseURL + "/user/login", urlData, LoginCallback + callback, URLRequest.Method.POST);
  708. }
  709. private static void LoginCallback(JsonData jsonData)
  710. {
  711. Complete = true;
  712. if (jsonData.Inst_Object.ContainsKey("c"))
  713. {
  714. Connect = true;
  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. }