]> git.lizzy.rs Git - minetest.git/blob - src/network/serveropcodes.cpp
12665e7f17fb0176e3095b5783a868657b0c83d5
[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 };
111
112 const static ClientCommandFactory null_command_factory = { "TOCLIENT_NULL", 0, false };
113
114 /*
115         Channels used for Server -> Client communication
116         2: Bulk data (mapblocks, media, ...)
117         1: HUD packets
118         0: everything else
119
120         Packet order is only guaranteed inside a channel, so packets that operate on
121         the same objects are *required* to be in the same channel.
122 */
123
124 const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] =
125 {
126         null_command_factory, // 0x00
127         null_command_factory, // 0x01
128         { "TOCLIENT_HELLO",                    0, true }, // 0x02
129         { "TOCLIENT_AUTH_ACCEPT",              0, true }, // 0x03
130         { "TOCLIENT_ACCEPT_SUDO_MODE",         0, true }, // 0x04
131         { "TOCLIENT_DENY_SUDO_MODE",           0, true }, // 0x05
132         null_command_factory, // 0x06
133         null_command_factory, // 0x07
134         null_command_factory, // 0x08
135         null_command_factory, // 0x09
136         { "TOCLIENT_ACCESS_DENIED",            0, true }, // 0x0A
137         null_command_factory, // 0x0B
138         null_command_factory, // 0x0C
139         null_command_factory, // 0x0D
140         null_command_factory, // 0x0E
141         null_command_factory, // 0x0F
142         { "TOCLIENT_INIT",                     0, true }, // 0x10
143         null_command_factory, // 0x11
144         null_command_factory, // 0x12
145         null_command_factory, // 0x13
146         null_command_factory, // 0x14
147         null_command_factory, // 0x15
148         null_command_factory, // 0x16
149         null_command_factory, // 0x17
150         null_command_factory, // 0x18
151         null_command_factory, // 0x19
152         null_command_factory, // 0x1A
153         null_command_factory, // 0x1B
154         null_command_factory, // 0x1C
155         null_command_factory, // 0x1D
156         null_command_factory, // 0x1E
157         null_command_factory, // 0x1F
158         { "TOCLIENT_BLOCKDATA",                2, true }, // 0x20
159         { "TOCLIENT_ADDNODE",                  0, true }, // 0x21
160         { "TOCLIENT_REMOVENODE",               0, true }, // 0x22
161         null_command_factory, // 0x23
162         null_command_factory, // 0x24
163         null_command_factory, // 0x25
164         null_command_factory, // 0x26
165         { "TOCLIENT_INVENTORY",                0, true }, // 0x27
166         null_command_factory, // 0x28
167         { "TOCLIENT_TIME_OF_DAY",              0, true }, // 0x29
168         { "TOCLIENT_CSM_RESTRICTION_FLAGS",    0, true }, // 0x2A
169         { "TOCLIENT_PLAYER_SPEED",             0, true }, // 0x2B
170         { "TOCLIENT_MEDIA_PUSH",               0, true }, // 0x2C (sent over channel 1 too if legacy)
171         null_command_factory, // 0x2D
172         null_command_factory, // 0x2E
173         { "TOCLIENT_CHAT_MESSAGE",             0, true }, // 0x2F
174         null_command_factory, // 0x30
175         { "TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD", 0, true }, // 0x31
176         { "TOCLIENT_ACTIVE_OBJECT_MESSAGES",   0, true }, // 0x32 (may be sent as unrel over channel 1 too)
177         { "TOCLIENT_HP",                       0, true }, // 0x33
178         { "TOCLIENT_MOVE_PLAYER",              0, true }, // 0x34
179         null_command_factory, // 0x35
180         { "TOCLIENT_FOV",                      0, true }, // 0x36
181         { "TOCLIENT_DEATHSCREEN",              0, true }, // 0x37
182         { "TOCLIENT_MEDIA",                    2, true }, // 0x38
183         null_command_factory, // 0x39
184         { "TOCLIENT_NODEDEF",                  0, true }, // 0x3A
185         null_command_factory, // 0x3B
186         { "TOCLIENT_ANNOUNCE_MEDIA",           0, true }, // 0x3C
187         { "TOCLIENT_ITEMDEF",                  0, true }, // 0x3D
188         null_command_factory, // 0x3E
189         { "TOCLIENT_PLAY_SOUND",               0, true }, // 0x3f (may be sent as unrel too)
190         { "TOCLIENT_STOP_SOUND",               0, true }, // 0x40
191         { "TOCLIENT_PRIVILEGES",               0, true }, // 0x41
192         { "TOCLIENT_INVENTORY_FORMSPEC",       0, true }, // 0x42
193         { "TOCLIENT_DETACHED_INVENTORY",       0, true }, // 0x43
194         { "TOCLIENT_SHOW_FORMSPEC",            0, true }, // 0x44
195         { "TOCLIENT_MOVEMENT",                 0, true }, // 0x45
196         { "TOCLIENT_SPAWN_PARTICLE",           0, true }, // 0x46
197         { "TOCLIENT_ADD_PARTICLESPAWNER",      0, true }, // 0x47
198         null_command_factory, // 0x48
199         { "TOCLIENT_HUDADD",                   1, true }, // 0x49
200         { "TOCLIENT_HUDRM",                    1, true }, // 0x4a
201         { "TOCLIENT_HUDCHANGE",                1, true }, // 0x4b
202         { "TOCLIENT_HUD_SET_FLAGS",            1, true }, // 0x4c
203         { "TOCLIENT_HUD_SET_PARAM",            1, true }, // 0x4d
204         { "TOCLIENT_BREATH",                   0, true }, // 0x4e
205         { "TOCLIENT_SET_SKY",                  0, true }, // 0x4f
206         { "TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO", 0, true }, // 0x50
207         { "TOCLIENT_LOCAL_PLAYER_ANIMATIONS",  0, true }, // 0x51
208         { "TOCLIENT_EYE_OFFSET",               0, true }, // 0x52
209         { "TOCLIENT_DELETE_PARTICLESPAWNER",   0, true }, // 0x53
210         { "TOCLIENT_CLOUD_PARAMS",             0, true }, // 0x54
211         { "TOCLIENT_FADE_SOUND",               0, true }, // 0x55
212         { "TOCLIENT_UPDATE_PLAYER_LIST",       0, true }, // 0x56
213         { "TOCLIENT_MODCHANNEL_MSG",           0, true }, // 0x57
214         { "TOCLIENT_MODCHANNEL_SIGNAL",        0, true }, // 0x58
215         { "TOCLIENT_NODEMETA_CHANGED",         0, true }, // 0x59
216         { "TOCLIENT_SET_SUN",                  0, true }, // 0x5a
217         { "TOCLIENT_SET_MOON",                 0, true }, // 0x5b
218         { "TOCLIENT_SET_STARS",                0, true }, // 0x5c
219         null_command_factory, // 0x5d
220         null_command_factory, // 0x5e
221         null_command_factory, // 0x5f
222         { "TOSERVER_SRP_BYTES_S_B",            0, true }, // 0x60
223         { "TOCLIENT_FORMSPEC_PREPEND",         0, true }, // 0x61
224         { "TOCLIENT_MINIMAP_MODES",            0, true }, // 0x62
225 };