chat_interface.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. Minetest
  3. Copyright (C) 2015 est31 <MTest31@outlook.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include "util/container.h"
  18. #include <string>
  19. #include <queue>
  20. #include "irrlichttypes.h"
  21. enum ChatEventType {
  22. CET_CHAT,
  23. CET_NICK_ADD,
  24. CET_NICK_REMOVE,
  25. CET_TIME_INFO,
  26. };
  27. class ChatEvent {
  28. protected:
  29. ChatEvent(ChatEventType a_type) { type = a_type; }
  30. public:
  31. ChatEventType type;
  32. };
  33. struct ChatEventTimeInfo : public ChatEvent {
  34. ChatEventTimeInfo(
  35. u64 a_game_time,
  36. u32 a_time) :
  37. ChatEvent(CET_TIME_INFO),
  38. game_time(a_game_time),
  39. time(a_time)
  40. {}
  41. u64 game_time;
  42. u32 time;
  43. };
  44. struct ChatEventNick : public ChatEvent {
  45. ChatEventNick(ChatEventType a_type,
  46. const std::string &a_nick) :
  47. ChatEvent(a_type), // one of CET_NICK_ADD, CET_NICK_REMOVE
  48. nick(a_nick)
  49. {}
  50. std::string nick;
  51. };
  52. struct ChatEventChat : public ChatEvent {
  53. ChatEventChat(const std::string &a_nick,
  54. const std::wstring &an_evt_msg) :
  55. ChatEvent(CET_CHAT),
  56. nick(a_nick),
  57. evt_msg(an_evt_msg)
  58. {}
  59. std::string nick;
  60. std::wstring evt_msg;
  61. };
  62. struct ChatInterface {
  63. MutexedQueue<ChatEvent *> command_queue; // chat backend --> server
  64. MutexedQueue<ChatEvent *> outgoing_queue; // server --> chat backend
  65. };