NoticeSProxy.cs 3.5 KB

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