ChatSProxy.cs 3.8 KB

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