ManaServer.cs 35 KB

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