]> git.lizzy.rs Git - minetest.git/blob - src/network/serveropcodes.cpp
Add minetest.get_player_window_information() (#12367)
[minetest.git] / src / network / serveropcodes.cpp
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2015 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #include "serveropcodes.h"
22
23 const static ToServerCommandHandler null_command_handler = { "TOSERVER_NULL", TOSERVER_STATE_ALL, &Server::handleCommand_Null };
24
25 const ToServerCommandHandler toServerCommandTable[TOSERVER_NUM_MSG_TYPES] =
26 {
27         null_command_handler, // 0x00 (never use this)
28         null_command_handler, // 0x01
29         { "TOSERVER_INIT",                     TOSERVER_STATE_NOT_CONNECTED, &Server::handleCommand_Init }, // 0x02
30         null_command_handler, // 0x03
31         null_command_handler, // 0x04
32         null_command_handler, // 0x05
33         null_command_handler, // 0x06
34         null_command_handler, // 0x07
35         null_command_handler, // 0x08
36         null_command_handler, // 0x09
37         null_command_handler, // 0x0a
38         null_command_handler, // 0x0b
39         null_command_handler, // 0x0c
40         null_command_handler, // 0x0d
41         null_command_handler, // 0x0e
42         null_command_handler, // 0x0f
43         null_command_handler, // 0x10
44         { "TOSERVER_INIT2",                    TOSERVER_STATE_NOT_CONNECTED, &Server::handleCommand_Init2 }, // 0x11
45         null_command_handler, // 0x12
46         null_command_handler, // 0x13
47         null_command_handler, // 0x14
48         null_command_handler, // 0x15
49         null_command_handler, // 0x16
50         { "TOSERVER_MODCHANNEL_JOIN",          TOSERVER_STATE_INGAME, &Server::handleCommand_ModChannelJoin }, // 0x17
51         { "TOSERVER_MODCHANNEL_LEAVE",         TOSERVER_STATE_INGAME, &Server::handleCommand_ModChannelLeave }, // 0x18
52         { "TOSERVER_MODCHANNEL_MSG",           TOSERVER_STATE_INGAME, &Server::handleCommand_ModChannelMsg }, // 0x19
53         null_command_handler, // 0x1a
54         null_command_handler, // 0x1b
55         null_command_handler, // 0x1c
56         null_command_handler, // 0x1d
57         null_command_handler, // 0x1e
58         null_command_handler, // 0x1f
59         null_command_handler, // 0x20
60         null_command_handler, // 0x21
61         null_command_handler, // 0x22
62         { "TOSERVER_PLAYERPOS",                TOSERVER_STATE_INGAME, &Server::handleCommand_PlayerPos }, // 0x23
63         { "TOSERVER_GOTBLOCKS",                TOSERVER_STATE_STARTUP, &Server::handleCommand_GotBlocks }, // 0x24
64         { "TOSERVER_DELETEDBLOCKS",            TOSERVER_STATE_INGAME, &Server::handleCommand_DeletedBlocks }, // 0x25
65         null_command_handler, // 0x26
66         null_command_handler, // 0x27
67         null_command_handler, // 0x28
68         null_command_handler, // 0x29
69         null_command_handler, // 0x2a
70         null_command_handler, // 0x2b
71         null_command_handler, // 0x2c
72         null_command_handler, // 0x2d
73         null_command_handler, // 0x2e
74         null_command_handler, // 0x2f
75         null_command_handler, // 0x30
76         { "TOSERVER_INVENTORY_ACTION",         TOSERVER_STATE_INGAME, &Server::handleCommand_InventoryAction }, // 0x31
77         { "TOSERVER_CHAT_MESSAGE",             TOSERVER_STATE_INGAME, &Server::handleCommand_ChatMessage }, // 0x32
78         null_command_handler, // 0x33
79         null_command_handler, // 0x34
80         { "TOSERVER_DAMAGE",                   TOSERVER_STATE_INGAME, &Server::handleCommand_Damage }, // 0x35
81         null_command_handler, // 0x36
82         { "TOSERVER_PLAYERITEM",               TOSERVER_STATE_INGAME, &Server::handleCommand_PlayerItem }, // 0x37
83         { "TOSERVER_RESPAWN",                  TOSERVER_STATE_INGAME, &Server::handleCommand_Respawn }, // 0x38
84         { "TOSERVER_INTERACT",                 TOSERVER_STATE_INGAME, &Server::handleCommand_Interact }, // 0x39
85         { "TOSERVER_REMOVED_SOUNDS",           TOSERVER_STATE_INGAME, &Server::handleCommand_RemovedSounds }, // 0x3a
86         { "TOSERVER_NODEMETA_FIELDS",          TOSERVER_STATE_INGAME, &Server::handleCommand_NodeMetaFields }, // 0x3b
87         { "TOSERVER_INVENTORY_FIELDS",         TOSERVER_STATE_INGAME, &Server::handleCommand_InventoryFields }, // 0x3c
88         null_command_handler, // 0x3d
89         null_command_handler, // 0x3e
90         null_command_handler, // 0x3f
91         { "TOSERVER_REQUEST_MEDIA",            TOSERVER_STATE_STARTUP, &Server::handleCommand_RequestMedia }, // 0x40
92         { "TOSERVER_HAVE_MEDIA",               TOSERVER_STATE_INGAME, &Server::handleCommand_HaveMedia }, // 0x41
93         null_command_handler, // 0x42
94         { "TOSERVER_CLIENT_READY",             TOSERVER_STATE_STARTUP, &Server::handleCommand_ClientReady }, // 0x43
95         null_command_handler, // 0x44
96         null_command_handler, // 0x45
97         null_command_handler, // 0x46
98         null_command_handler, // 0x47
99         null_command_handler, // 0x48
100         null_command_handler, // 0x49
101         null_command_handler, // 0x4a
102         null_command_handler, // 0x4b
103         null_command_handler, // 0x4c
104         null_command_handler, // 0x4d
105         null_command_handler, // 0x4e
106         null_command_handler, // 0x4f
107         { "TOSERVER_FIRST_SRP",                TOSERVER_STATE_NOT_CONNECTED, &Server::handleCommand_FirstSrp }, // 0x50
108         { "TOSERVER_SRP_BYTES_A",              TOSERVER_STATE_NOT_CONNECTED, &Server::handleCommand_SrpBytesA }, // 0x51
109         { "TOSERVER_SRP_BYTES_M",              TOSERVER_STATE_NOT_CONNECTED, &Server::handleCommand_SrpBytesM }, // 0x52
110         { "TOSERVER_UPDATE_CLIENT_INFO",       TOSERVER_STATE_INGAME, &Server::handleCommand_UpdateClientInfo }, // 0x53
111 };
112
113 const static ClientCommandFactory null_command_factory = { "TOCLIENT_NULL", 0, false };
114
115 /*
116         Channels used for Server -> Client communication
117         2: Bulk data (mapblocks, media, ...)
118         1: HUD packets
119         0: everything else
120
121         Packet order is only guaranteed inside a channel, so packets that operate on
122         the same objects are *required* to be in the same channel.
123 */
124
125 const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] =
126 {
127         null_command_factory, // 0x00
128         null_command_factory, // 0x01
129         { "TOCLIENT_HELLO",                    0, true }, // 0x02
130         { "TOCLIENT_AUTH_ACCEPT",              0, true }, // 0x03
131         { "TOCLIENT_ACCEPT_SUDO_MODE",         0, true }, // 0x04
132         { "TOCLIENT_DENY_SUDO_MODE",           0, true }, // 0x05
133         null_command_factory, // 0x06
134         null_command_factory, // 0x07
135         null_command_factory, // 0x08
136         null_command_factory, // 0x09
137         { "TOCLIENT_ACCESS_DENIED",            0, true }, // 0x0A
138         null_command_factory, // 0x0B
139         null_command_factory, // 0x0C
140         null_command_factory, // 0x0D
141         null_command_factory, // 0x0E
142         null_command_factory, // 0x0F
143         { "TOCLIENT_INIT",                     0, true }, // 0x10
144         null_command_factory, // 0x11
145         null_command_factory, // 0x12
146         null_command_factory, // 0x13
147         null_command_factory, // 0x14
148         null_command_factory, // 0x15
149         null_command_factory, // 0x16
150         null_command_factory, // 0x17
151         null_command_factory, // 0x18
152         null_command_factory, // 0x19
153         null_command_factory, // 0x1A
154         null_command_factory, // 0x1B
155         null_command_factory, // 0x1C
156         null_command_factory, // 0x1D
157         null_command_factory, // 0x1E
158         null_command_factory, // 0x1F
159         { "TOCLIENT_BLOCKDATA",                2, true }, // 0x20
160         { "TOCLIENT_ADDNODE",                  0, true }, // 0x21
161         { "TOCLIENT_REMOVENODE",               0, true }, // 0x22
162         null_command_factory, // 0x23
163         null_command_factory, // 0x24
164         null_command_factory, // 0x25
165         null_command_factory, // 0x26
166         { "TOCLIENT_INVENTORY",                0, true }, // 0x27
167         null_command_factory, // 0x28
168         { "TOCLIENT_TIME_OF_DAY",              0, true }, // 0x29
169         { "TOCLIENT_CSM_RESTRICTION_FLAGS",    0, true }, // 0x2A
170         { "TOCLIENT_PLAYER_SPEED",             0, true }, // 0x2B
171         { "TOCLIENT_MEDIA_PUSH",               0, true }, // 0x2C (sent over channel 1 too if legacy)
172         null_command_factory, // 0x2D
173         null_command_factory, // 0x2E
174         { "TOCLIENT_CHAT_MESSAGE",             0, true }, // 0x2F
175         null_command_factory, // 0x30
176         { "TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD", 0, true }, // 0x31
177         { "TOCLIENT_ACTIVE_OBJECT_MESSAGES",   0, true }, // 0x32 (may be sent as unrel over channel 1 too)
178         { "TOCLIENT_HP",                       0, true }, // 0x33
179         { "TOCLIENT_MOVE_PLAYER",              0, true }, // 0x34
180         null_command_factory, // 0x35
181         { "TOCLIENT_FOV",                      0, true }, // 0x36
182         { "TOCLIENT_DEATHSCREEN",              0, true }, // 0x37
183         { "TOCLIENT_MEDIA",                    2, true }, // 0x38
184         null_command_factory, // 0x39
185         { "TOCLIENT_NODEDEF",                  0, true }, // 0x3A
186         null_command_factory, // 0x3B
187         { "TOCLIENT_ANNOUNCE_MEDIA",           0, true }, // 0x3C
188         { "TOCLIENT_ITEMDEF",                  0, true }, // 0x3D
189         null_command_factory, // 0x3E
190         { "TOCLIENT_PLAY_SOUND",               0, true }, // 0x3f (may be sent as unrel too)
191         { "TOCLIENT_STOP_SOUND",               0, true }, // 0x40
192         { "TOCLIENT_PRIVILEGES",               0, true }, // 0x41
193         { "TOCLIENT_INVENTORY_FORMSPEC",       0, true }, // 0x42
194         { "TOCLIENT_DETACHED_INVENTORY",       0, true }, // 0x43
195         { "TOCLIENT_SHOW_FORMSPEC",            0, true }, // 0x44
196         { "TOCLIENT_MOVEMENT",                 0, true }, // 0x45
197         { "TOCLIENT_SPAWN_PARTICLE",           0, true }, // 0x46
198         { "TOCLIENT_ADD_PARTICLESPAWNER",      0, true }, // 0x47
199         null_command_factory, // 0x48
200         { "TOCLIENT_HUDADD",                   1, true }, // 0x49
201         { "TOCLIENT_HUDRM",                    1, true }, // 0x4a
202         { "TOCLIENT_HUDCHANGE",                1, true }, // 0x4b
203         { "TOCLIENT_HUD_SET_FLAGS",            1, true }, // 0x4c
204         { "TOCLIENT_HUD_SET_PARAM",            1, true }, // 0x4d
205         { "TOCLIENT_BREATH",                   0, true }, // 0x4e
206         { "TOCLIENT_SET_SKY",                  0, true }, // 0x4f
207         { "TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO", 0, true }, // 0x50
208         { "TOCLIENT_LOCAL_PLAYER_ANIMATIONS",  0, true }, // 0x51
209         { "TOCLIENT_EYE_OFFSET",               0, true }, // 0x52
210         { "TOCLIENT_DELETE_PARTICLESPAWNER",   0, true }, // 0x53
211         { "TOCLIENT_CLOUD_PARAMS",             0, true }, // 0x54
212         { "TOCLIENT_FADE_SOUND",               0, true }, // 0x55
213         { "TOCLIENT_UPDATE_PLAYER_LIST",       0, true }, // 0x56
214         { "TOCLIENT_MODCHANNEL_MSG",           0, true }, // 0x57
215         { "TOCLIENT_MODCHANNEL_SIGNAL",        0, true }, // 0x58
216         { "TOCLIENT_NODEMETA_CHANGED",         0, true }, // 0x59
217         { "TOCLIENT_SET_SUN",                  0, true }, // 0x5a
218         { "TOCLIENT_SET_MOON",                 0, true }, // 0x5b
219         { "TOCLIENT_SET_STARS",                0, true }, // 0x5c
220         null_command_factory, // 0x5d
221         null_command_factory, // 0x5e
222         null_command_factory, // 0x5f
223         { "TOCLIENT_SRP_BYTES_S_B",            0, true }, // 0x60
224         { "TOCLIENT_FORMSPEC_PREPEND",         0, true }, // 0x61
225         { "TOCLIENT_MINIMAP_MODES",            0, true }, // 0x62
226         { "TOCLIENT_SET_LIGHTING",             0, true }, // 0x63
227 };