NoticeSProxy.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Collections.Generic;
  3. using ET;
  4. using GFGGame;
  5. namespace ET
  6. {
  7. public class NoticeSystemNoticeChanged : AMHandler<M2C_SystemNoticeChanged>
  8. {
  9. protected override async ETTask Run(Session session, M2C_SystemNoticeChanged response)
  10. {
  11. NoticeInfo noticeInfo = new NoticeInfo();
  12. noticeInfo.noticeId = response.Notice.NoticeId;
  13. noticeInfo.title = response.Notice.Title;
  14. noticeInfo.time = response.Notice.TimeSec;
  15. noticeInfo.readStatus = response.Notice.ReadStatus;
  16. noticeInfo.content = "";
  17. NoticeDataManager.Instance.UpdateNoticeIdList(noticeInfo);
  18. await ETTask.CompletedTask;
  19. }
  20. }
  21. public class NoticeSystemNoticeRemove : AMHandler<M2C_SystemNoticeRemoved>
  22. {
  23. protected override async ETTask Run(Session session, M2C_SystemNoticeRemoved response)
  24. {
  25. NoticeDataManager.Instance.UpdateSystemNoticeRemove(response.NoticeId);
  26. await ETTask.CompletedTask;
  27. }
  28. }
  29. }
  30. namespace GFGGame
  31. {
  32. public static class NoticeSProxy
  33. {
  34. public static async ETTask<bool> ReqSystemNoticeList()
  35. {
  36. N2C_GetSystemNoticeList response = null;
  37. Session session = null;
  38. try
  39. {
  40. AccountInfoComponent accountInfoComponent = GameGlobal.zoneScene.GetComponent<AccountInfoComponent>();
  41. session = GameGlobal.zoneScene.GetComponent<NetKcpComponent>().Create(NetworkHelper.ToIPEndPoint(accountInfoComponent.NoticeAddress));
  42. response = (N2C_GetSystemNoticeList)await session.Call(new C2N_GetSystemNoticeList() { AccountId = (int)accountInfoComponent.AccountId });
  43. }
  44. catch (Exception e)
  45. {
  46. Log.Error(e.ToString());
  47. return false;
  48. }
  49. finally
  50. {
  51. session?.Dispose();
  52. }
  53. if (response.Error != ErrorCode.ERR_Success)
  54. {
  55. return false;
  56. }
  57. for (int i = 0; i < response.NoticeList.Count; i++)
  58. {
  59. NoticeInfo noticeInfo = new NoticeInfo();
  60. noticeInfo.noticeId = response.NoticeList[i].NoticeId;
  61. noticeInfo.title = response.NoticeList[i].Title;
  62. noticeInfo.time = response.NoticeList[i].TimeSec;
  63. NoticeDataManager.Instance.UpdateNoticeIdList(noticeInfo);
  64. }
  65. return true;
  66. }
  67. public static async ETTask<bool> ReqSystemNotice(int noticeId)
  68. {
  69. N2C_GetSystemNotice response = null;
  70. Session session = null;
  71. try
  72. {
  73. AccountInfoComponent accountInfoComponent = GameGlobal.zoneScene.GetComponent<AccountInfoComponent>();
  74. session = GameGlobal.zoneScene.GetComponent<NetKcpComponent>().Create(NetworkHelper.ToIPEndPoint(accountInfoComponent.NoticeAddress));
  75. response = (N2C_GetSystemNotice)await session.Call(new C2N_GetSystemNotice() { NoticeId = noticeId });
  76. }
  77. catch (Exception e)
  78. {
  79. Log.Error(e.ToString());
  80. return false;
  81. }
  82. finally
  83. {
  84. session?.Dispose();
  85. }
  86. if (response.Error != ErrorCode.ERR_Success)
  87. {
  88. return false;
  89. }
  90. NoticeDataManager.Instance.UpdateNoticeContent(response.NoticeId, response.Content);
  91. return true;
  92. }
  93. }
  94. }