ChatSProxy.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 (message.Type == ChatType.Private)
  17. // {
  18. // if (!ChatDataManager.Instance.PrivateChatDatas.ContainsKey(chatData.TargetId))
  19. // {
  20. // ChatDataManager.Instance.PrivateChatDatas[chatData.TargetId] = new List<ChatData>();
  21. // }
  22. // ChatDataManager.Instance.PrivateChatDatas[chatData.TargetId].Add(chatData);
  23. // if (response.ChatMsgs[i].Type == ChatType.Private)
  24. // {
  25. // ChatDataManager.Instance.GetChatDatas(chatData.TargetId).Add(chatData);
  26. // }
  27. // else
  28. // {
  29. // ChatDataManager.Instance.GetChatDatas(chatData.Type).Add(chatData);
  30. // }
  31. // }
  32. // else
  33. // {
  34. // if (!ChatDataManager.Instance.PrivateChatDatas.ContainsKey(chatData.Type))
  35. // {
  36. // ChatDataManager.Instance.PrivateChatDatas[chatData.Type] = new List<ChatData>();
  37. // }
  38. // ChatDataManager.Instance.PrivateChatDatas[chatData.Type].Add(chatData);
  39. // }
  40. if (chatData.Type == ChatType.Private)
  41. {
  42. ChatDataManager.Instance.GetChatDatas(chatData.TargetId).Add(chatData);
  43. }
  44. else
  45. {
  46. ChatDataManager.Instance.GetChatDatas(chatData.Type).Add(chatData);
  47. }
  48. EventAgent.DispatchEvent(ConstMessage.NOTICE_CHAT_MESSAGE);
  49. await ETTask.CompletedTask;
  50. }
  51. }
  52. }
  53. namespace GFGGame
  54. {
  55. public static class ChatSProxy
  56. {
  57. public static async ETTask<bool> ReqSendChatMsg(int type, string content, long targetId = 0)
  58. {
  59. S2C_SendChatMsg response = null;
  60. response = (S2C_SendChatMsg)await MessageHelper.SendToServer(new C2S_SendChatMsg() { Type = type, Content = content, TargetId = targetId });
  61. if (response != null)
  62. {
  63. if (response.Error == ErrorCode.ERR_Success)
  64. {
  65. return true;
  66. }
  67. }
  68. return false;
  69. }
  70. public static async ETTask<bool> ReqQueryChatMsg(int type)
  71. {
  72. S2C_QueryChatMsg response = null;
  73. response = (S2C_QueryChatMsg)await MessageHelper.SendToServer(new C2S_QueryChatMsg() { Type = type });
  74. if (response != null)
  75. {
  76. if (response.Error == ErrorCode.ERR_Success)
  77. {
  78. if (ChatDataManager.Instance.ChatDatas.ContainsKey(type))
  79. {
  80. ChatDataManager.Instance.ChatDatas[type].Clear();
  81. }
  82. for (int i = 0; i < response.ChatMsgs.Count; i++)
  83. {
  84. ChatData chatData = new ChatData();
  85. chatData.Type = response.ChatMsgs[i].Type;
  86. chatData.RoleInfo = RoleDataManager.GetOtherRoleInfoData(response.ChatMsgs[i].RoleInfo);
  87. chatData.TargetId = chatData.RoleInfo.roleId;
  88. chatData.Content = response.ChatMsgs[i].Content;
  89. chatData.Time = response.ChatMsgs[i].Time;
  90. if (response.ChatMsgs[i].Type == ChatType.Private)
  91. {
  92. ChatDataManager.Instance.GetChatDatas(chatData.TargetId).Add(chatData);
  93. }
  94. else
  95. {
  96. ChatDataManager.Instance.GetChatDatas(chatData.Type).Add(chatData);
  97. }
  98. }
  99. return true;
  100. }
  101. }
  102. return false;
  103. }
  104. }
  105. }