ChatSProxy.cs 4.1 KB

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