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