ChatSProxy.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System.Collections.Generic;
  2. using ET;
  3. using GFGGame;
  4. namespace ET
  5. {
  6. public class NoticeNoticeChatMsg : AMHandler<S2C_NoticeChatMsg>
  7. {
  8. protected override async ETTask Run(Session session, S2C_NoticeChatMsg message)
  9. {
  10. ChatData chatData = new ChatData();
  11. chatData.Type = message.Type;
  12. chatData.RoleInfo = RoleDataManager.GetOtherRoleInfoData(message.RoleInfo);
  13. chatData.TargetId = chatData.RoleInfo.roleId;
  14. chatData.Content = message.Content;
  15. chatData.Time = message.Time;
  16. if (chatData.Type == ChatType.Private)
  17. {
  18. ChatDataManager.Instance.GetChatDatas(chatData.TargetId).Add(chatData);
  19. }
  20. else
  21. {
  22. ChatDataManager.Instance.GetChatDatas(chatData.Type).Add(chatData);
  23. }
  24. if (!ViewManager.isViewOpen(typeof(LeagueChatView).FullName))
  25. ChatDataManager.Instance.NewChatInfo = true;
  26. EventAgent.DispatchEvent(ConstMessage.NOTICE_CHAT_MESSAGE);
  27. await ETTask.CompletedTask;
  28. }
  29. }
  30. }
  31. namespace GFGGame
  32. {
  33. public static class ChatSProxy
  34. {
  35. public static async ETTask<bool> ReqSendChatMsg(int type, string content, long targetId = 0)
  36. {
  37. S2C_SendChatMsg response = null;
  38. response = (S2C_SendChatMsg)await MessageHelper.SendToServer(new C2S_SendChatMsg() { Type = type, Content = content, TargetId = targetId });
  39. if (response != null)
  40. {
  41. // ChatData chatData = new ChatData();
  42. // chatData.Type = type;
  43. // chatData.RoleInfo = RoleDataManager.GetMineRoleInfoData();
  44. // chatData.TargetId = targetId;
  45. // chatData.Content = content;
  46. // chatData.Time = TimeHelper.ServerNow();
  47. if (response.Error == ErrorCode.ERR_Success)
  48. {
  49. // if (type == ChatType.Private)
  50. // {
  51. // ChatDataManager.Instance.GetChatDatas(targetId).Add(chatData);
  52. // }
  53. // else
  54. // {
  55. // ChatDataManager.Instance.GetChatDatas(type).Add(chatData);
  56. // }
  57. return true;
  58. }
  59. }
  60. return false;
  61. }
  62. public static async ETTask<bool> ReqQueryChatMsg(int type)
  63. {
  64. S2C_QueryChatMsg response = null;
  65. response = (S2C_QueryChatMsg)await MessageHelper.SendToServer(new C2S_QueryChatMsg() { Type = type });
  66. if (response != null)
  67. {
  68. if (response.Error == ErrorCode.ERR_Success)
  69. {
  70. if (ChatDataManager.Instance.ChatDatas.ContainsKey(type))
  71. {
  72. ChatDataManager.Instance.ChatDatas[type].Clear();
  73. }
  74. for (int i = 0; i < response.ChatMsgs.Count; i++)
  75. {
  76. ChatData chatData = new ChatData();
  77. chatData.Type = response.ChatMsgs[i].Type;
  78. chatData.RoleInfo = RoleDataManager.GetOtherRoleInfoData(response.ChatMsgs[i].RoleInfo);
  79. chatData.TargetId = chatData.RoleInfo.roleId;
  80. chatData.Content = response.ChatMsgs[i].Content;
  81. chatData.Time = response.ChatMsgs[i].Time;
  82. if (response.ChatMsgs[i].Type == ChatType.Private)
  83. {
  84. ChatDataManager.Instance.GetChatDatas(chatData.TargetId).Add(chatData);
  85. }
  86. else
  87. {
  88. ChatDataManager.Instance.GetChatDatas(chatData.Type).Add(chatData);
  89. }
  90. }
  91. return true;
  92. }
  93. }
  94. return false;
  95. }
  96. }
  97. }