aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_http.cpp
blob: 5ea3b3f996f0143ea4300f111166825a3ae0b12a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "lua_api/l_internal.h"
#include "common/c_converter.h"
#include "common/c_content.h"
#include "lua_api/l_http.h"
#include "httpfetch.h"
#include "settings.h"
#include "debug.h"
#include "log.h"

#include <algorithm>
#include <iomanip>
#include <cctype>

#define HTTP_API(name) \
	lua_pushstring(L, #name); \
	lua_pushcfunction(L, l_http_##name); \
	lua_settable(L, -3);

#if USE_CURL
void ModApiHttp::read_http_fetch_request(lua_State *L, HTTPFetchRequest &req)
{
	luaL_checktype(L, 1, LUA_TTABLE);

	req.caller = httpfetch_caller_alloc_secure();
	getstringfield(L, 1, "url", req.url);
	lua_getfield(L, 1, "user_agent");
	if (lua_isstring(L, -1))
		req.useragent = getstringfield_default(L, 1, "user_agent", "");
	lua_pop(L, 1);
	req.multipart = getboolfield_default(L, 1, "multipart", false);
	req.timeout = getintfield_default(L, 1, "timeout", 3) * 1000;

	lua_getfield(L, 1, "method");
	if (lua_isstring(L, -1)) {
		std::string mth = getstringfield_default(L, 1, "method", "");
		if (mth == "GET")
			req.method = HTTP_GET;
		else if (mth == "POST")
			req.method = HTTP_POST;
		else if (mth == "PUT")
			req.method = HTTP_PUT;
		else if (mth == "DELETE")
			req.method = HTTP_DELETE;
	}
	lua_pop(L, 1);

	// post_data: if table, post form data, otherwise raw data DEPRECATED use data and method instead
	lua_getfield(L, 1, "post_data");
	if (lua_isnil(L, 2)) {
		lua_pop(L, 1);
		lua_getfield(L, 1, "data");
	}
	else {
		req.method = HTTP_POST;
	}

	if (lua_istable(L, 2)) {
		lua_pushnil(L);
		while (lua_next(L, 2) != 0) {
			req.fields[readParam<std::string>(L, -2)] = readParam<std::string>(L, -1);
			lua_pop(L, 1);
		}
	} else if (lua_isstring(L, 2)) {
		req.raw_data = readParam<std::string>(L, 2);
	}

	lua_pop(L, 1);

	lua_getfield(L, 1, "extra_headers");
	if (lua_istable(L, 2)) {
		lua_pushnil(L);
		while (lua_next(L, 2) != 0) {
			req.extra_headers.emplace_back(readParam<std::string>(L, -1));
			lua_pop(L, 1);
		}
	}
	lua_pop(L, 1);
}

void ModApiHttp::push_http_fetch_result(lua_State *L, HTTPFetchResult &res, bool completed)
{
	lua_newtable(L);
	setboolfield(L, -1, "succeeded", res.succeeded);
	setboolfield(L, -1, "timeout", res.timeout);
	setboolfield(L, -1, "completed", completed);
	setintfield(L, -1, "code", res.response_code);
	setstringfield(L, -1, "data", res.data);
}

// http_api.fetch_sync(HTTPRequest definition)
int ModApiHttp::l_http_fetch_sync(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;

	HTTPFetchRequest req;
	read_http_fetch_request(L, req);

	infostream << "Mod performs HTTP request with URL " << req.url << std::endl;

	HTTPFetchResult res;
	httpfetch_sync(req, res);

	push_http_fetch_result(L, res, true);

	return 1;
}

// http_api.fetch_async(HTTPRequest definition)
int ModApiHttp::l_http_fetch_async(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;

	HTTPFetchRequest req;
	read_http_fetch_request(L, req);

	infostream << "Mod performs HTTP request with URL " << req.url << std::endl;
	httpfetch_async(req);

	// Convert handle to hex string since lua can't handle 64-bit integers
	std::stringstream handle_conversion_stream;
	handle_conversion_stream << std::hex << req.caller;
	std::string caller_handle(handle_conversion_stream.str());

	lua_pushstring(L, caller_handle.c_str());
	return 1;
}

// http_api.fetch_async_get(handle)
int ModApiHttp::l_http_fetch_async_get(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;

	std::string handle_str = luaL_checkstring(L, 1);

	// Convert hex string back to 64-bit handle
	u64 handle;
	std::stringstream handle_conversion_stream;
	handle_conversion_stream << std::hex << handle_str;
	handle_conversion_stream >> handle;

	HTTPFetchResult res;
	bool completed = httpfetch_async_get(handle, res);

	push_http_fetch_result(L, res, completed);

	return 1;
}

int ModApiHttp::l_request_http_api(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;

	// We have to make sure that this function is being called directly by
	// a mod, otherwise a malicious mod could override this function and
	// steal its return value.
	lua_Debug info;

	// Make sure there's only one item below this function on the stack...
	if (lua_getstack(L, 2, &info)) {
		return 0;
	}
	FATAL_ERROR_IF(!lua_getstack(L, 1, &info), "lua_getstack() failed");
	FATAL_ERROR_IF(!lua_getinfo(L, "S", &info), "lua_getinfo() failed");

	// ...and that that item is the main file scope.
	if (strcmp(info.what, "main") != 0) {
		return 0;
	}

	// Mod must be listed in secure.http_mods or secure.trusted_mods
	lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME);
	if (!lua_isstring(L, -1)) {
		return 0;
	}

	std::string mod_name = readParam<std::string>(L, -1);
	std::string http_mods = g_settings->get("secure.http_mods");
	http_mods.erase(std::remove(http_mods.begin(), http_mods.end(), ' '), http_mods.end());
	std::vector<std::string> mod_list_http = str_split(http_mods, ',');

	std::string trusted_mods = g_settings->get("secure.trusted_mods");
	trusted_mods.erase(std::remove(trusted_mods.begin(), trusted_mods.end(), ' '), trusted_mods.end());
	std::vector<std::string> mod_list_trusted = str_split(trusted_mods, ',');

	mod_list_http.insert(mod_list_http.end(), mod_list_trusted.begin(), mod_list_trusted.end());
	if (std::find(mod_list_http.begin(), mod_list_http.end(), mod_name) == mod_list_http.end()) {
		lua_pushnil(L);
		return 1;
	}

	lua_getglobal(L, "core");
	lua_getfield(L, -1, "http_add_fetch");

	lua_newtable(L);
	HTTP_API(fetch_async);
	HTTP_API(fetch_async_get);

	// Stack now looks like this:
	// <core.http_add_fetch> <table with fetch_async, fetch_async_get>
	// Now call core.http_add_fetch to append .fetch(request, callback) to table
	lua_call(L, 1, 1);

	return 1;
}

int ModApiHttp::l_get_http_api(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;

	lua_newtable(L);
	HTTP_API(fetch_async);
	HTTP_API(fetch_async_get);
	HTTP_API(fetch_sync);

	return 1;
}

#endif

void ModApiHttp::Initialize(lua_State *L, int top)
{
#if USE_CURL

	bool isMainmenu = false;
#ifndef SERVER
	isMainmenu = ModApiBase::getGuiEngine(L) != nullptr;
#endif

	if (isMainmenu) {
		API_FCT(get_http_api);
	} else {
		API_FCT(request_http_api);
	}

#endif
}

void ModApiHttp::InitializeAsync(lua_State *L, int top)
{
#if USE_CURL
	API_FCT(get_http_api);
#endif
}
'#n1189'>1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415
-- minetest.lua
-- Packet dissector for the UDP-based Minetest protocol
-- Copy this to $HOME/.wireshark/plugins/


--
-- Minetest
-- Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along
-- with this program; if not, write to the Free Software Foundation, Inc.,
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
--


-- Wireshark documentation:
-- https://web.archive.org/web/20170711121726/https://www.wireshark.org/docs/wsdg_html_chunked/lua_module_Proto.html
-- https://web.archive.org/web/20170711121844/https://www.wireshark.org/docs/wsdg_html_chunked/lua_module_Tree.html
-- https://web.archive.org/web/20170711121917/https://www.wireshark.org/docs/wsdg_html_chunked/lua_module_Tvb.html


-- Table of Contents:
--   Part 1: Utility functions
--   Part 2: Client command dissectors (TOSERVER_*)
--   Part 3: Server command dissectors (TOCLIENT_*)
--   Part 4: Wrapper protocol subdissectors
--   Part 5: Wrapper protocol main dissector
--   Part 6: Utility functions part 2


-----------------------
-- Part 1            --
-- Utility functions --
-----------------------

-- Creates two ProtoFields to hold a length and variable-length text content
-- lentype must be either "uint16" or "uint32"
function minetest_field_helper(lentype, name, abbr)
	local f_textlen = ProtoField[lentype](name .. "len", abbr .. " (length)", base.DEC)
	local f_text = ProtoField.string(name, abbr)
	return f_textlen, f_text
end




--------------------------------------------
-- Part 2                                 --
-- Client command dissectors (TOSERVER_*) --
--------------------------------------------

minetest_client_commands = {}
minetest_client_obsolete = {}

-- TOSERVER_INIT

do
	local abbr = "minetest.client.init_"

	local f_ser_fmt = ProtoField.uint8(abbr.."ser_version",
		"Maximum serialization format version", base.DEC)
	local f_comp_modes = ProtoField.uint16(abbr.."compression",
		"Supported compression modes", base.DEC, { [0] = "No compression" })
	local f_proto_min = ProtoField.uint16(abbr.."proto_min", "Minimum protocol version", base.DEC)
	local f_proto_max = ProtoField.uint16(abbr.."_proto_max", "Maximum protocol version", base.DEC)
	local f_player_namelen, f_player_name =
		minetest_field_helper("uint16", abbr.."player_name", "Player Name")

	minetest_client_commands[0x02] = {
		"INIT",                            -- Command name
		11,                                -- Minimum message length including code
		{ f_ser_fmt,                       -- List of fields [optional]
		  f_comp_modes,
		  f_proto_min,
		  f_proto_max,
		  f_player_namelen,
		  f_player_name },
		function(buffer, pinfo, tree, t)   -- Dissector function [optional]
			t:add(f_ser_fmt, buffer(2,1))
			t:add(f_comp_modes, buffer(3,2))
			t:add(f_proto_min, buffer(5,2))
			t:add(f_proto_max, buffer(7,2))
			minetest_decode_helper_ascii(buffer, t, "uint16", 9, f_player_namelen, f_player_name)
		end
	}
end

-- TOSERVER_INIT_LEGACY (obsolete)

minetest_client_commands[0x10] = { "INIT_LEGACY", 53 }
minetest_client_obsolete[0x10] = true

-- TOSERVER_INIT2

do
	local f_langlen, f_lang =
		minetest_field_helper("uint16", "minetest.client.init2_language", "Language Code")

	minetest_client_commands[0x11] = {
		"INIT2",
		2,
		{ f_langlen,
		  f_lang },
		function(buffer, pinfo, tree, t)
			minetest_decode_helper_ascii(buffer, t, "uint16", 2, f_langlen, f_lang)
		end
	}
end

-- TOSERVER_MODCHANNEL_JOIN

minetest_client_commands[0x17] = { "MODCHANNEL_JOIN", 2 }

-- TOSERVER_MODCHANNEL_LEAVE

minetest_client_commands[0x18] = { "MODCHANNEL_LEAVE", 2 }

-- TOSERVER_MODCHANNEL_MSG

minetest_client_commands[0x19] = { "MODCHANNEL_MSG", 2 }

-- TOSERVER_GETBLOCK (obsolete)

minetest_client_commands[0x20] = { "GETBLOCK", 2 }
minetest_client_obsolete[0x20] = true

-- TOSERVER_ADDNODE (obsolete)

minetest_client_commands[0x21] = { "ADDNODE", 2 }
minetest_client_obsolete[0x21] = true

-- TOSERVER_REMOVENODE (obsolete)

minetest_client_commands[0x22] = { "REMOVENODE", 2 }
minetest_client_obsolete[0x22] = true

-- TOSERVER_PLAYERPOS

do
	local abbr = "minetest.client.playerpos_"

	local f_x = ProtoField.int32(abbr.."x", "Position X", base.DEC)
	local f_y = ProtoField.int32(abbr.."y", "Position Y", base.DEC)
	local f_z = ProtoField.int32(abbr.."z", "Position Z", base.DEC)
	local f_speed_x = ProtoField.int32(abbr.."speed_x", "Speed X", base.DEC)
	local f_speed_y = ProtoField.int32(abbr.."speed_y", "Speed Y", base.DEC)
	local f_speed_z = ProtoField.int32(abbr.."speed_z", "Speed Z", base.DEC)
	local f_pitch = ProtoField.int32(abbr.."pitch", "Pitch", base.DEC)
	local f_yaw = ProtoField.int32(abbr.."yaw", "Yaw", base.DEC)
	local f_key_pressed = ProtoField.bytes(abbr.."key_pressed", "Pressed keys")
	local f_fov = ProtoField.uint8(abbr.."fov", "FOV", base.DEC)
	local f_wanted_range = ProtoField.uint8(abbr.."wanted_range", "Requested view range", base.DEC)

	minetest_client_commands[0x23] = {
		"PLAYERPOS", 34,
		{ f_x, f_y, f_z, f_speed_x, f_speed_y, f_speed_z, f_pitch, f_yaw,
		  f_key_pressed, f_fov, f_wanted_range },
		function(buffer, pinfo, tree, t)
			t:add(f_x, buffer(2,4))
			t:add(f_y, buffer(6,4))
			t:add(f_z, buffer(10,4))
			t:add(f_speed_x, buffer(14,4))
			t:add(f_speed_y, buffer(18,4))
			t:add(f_speed_z, buffer(22,4))
			t:add(f_pitch, buffer(26,4))
			t:add(f_yaw, buffer(30,4))
			t:add(f_key_pressed, buffer(34,4))
			t:add(f_fov, buffer(38,1))
			t:add(f_wanted_range, buffer(39,1))
		end
	}
end

-- TOSERVER_GOTBLOCKS

do
	local f_count = ProtoField.uint8("minetest.client.gotblocks_count", "Count", base.DEC)
	local f_block = ProtoField.bytes("minetest.client.gotblocks_block", "Block", base.NONE)
	local f_x = ProtoField.int16("minetest.client.gotblocks_x", "Block position X", base.DEC)
	local f_y = ProtoField.int16("minetest.client.gotblocks_y", "Block position Y", base.DEC)
	local f_z = ProtoField.int16("minetest.client.gotblocks_z", "Block position Z", base.DEC)

	minetest_client_commands[0x24] = {
		"GOTBLOCKS", 3,
		{ f_count, f_block, f_x, f_y, f_z },
		function(buffer, pinfo, tree, t)
			t:add(f_count, buffer(2,1))
			local count = buffer(2,1):uint()
			if minetest_check_length(buffer, 3 + 6*count, t) then
				pinfo.cols.info:append(" * " .. count)
				local index
				for index = 0, count - 1 do
					local pos = 3 + 6*index
					local t2 = t:add(f_block, buffer(pos, 6))
					t2:set_text("Block, X: " .. buffer(pos, 2):int()
						.. ", Y: " .. buffer(pos + 2, 2):int()
						.. ", Z: " .. buffer(pos + 4, 2):int())
					t2:add(f_x, buffer(pos, 2))
					t2:add(f_y, buffer(pos + 2, 2))
					t2:add(f_z, buffer(pos + 4, 2))
				end
			end
		end
	}
end

-- TOSERVER_DELETEDBLOCKS

do
	local f_count = ProtoField.uint8("minetest.client.deletedblocks_count", "Count", base.DEC)
	local f_block = ProtoField.bytes("minetest.client.deletedblocks_block", "Block", base.NONE)
	local f_x = ProtoField.int16("minetest.client.deletedblocks_x", "Block position X", base.DEC)
	local f_y = ProtoField.int16("minetest.client.deletedblocks_y", "Block position Y", base.DEC)
	local f_z = ProtoField.int16("minetest.client.deletedblocks_z", "Block position Z", base.DEC)

	minetest_client_commands[0x25] = {
		"DELETEDBLOCKS", 3,
		{ f_count, f_block, f_x, f_y, f_z },
		function(buffer, pinfo, tree, t)
			t:add(f_count, buffer(2,1))
			local count = buffer(2,1):uint()
			if minetest_check_length(buffer, 3 + 6*count, t) then
				pinfo.cols.info:append(" * " .. count)
				local index
				for index = 0, count - 1 do
					local pos = 3 + 6*index
					local t2 = t:add(f_block, buffer(pos, 6))
					t2:set_text("Block, X: " .. buffer(pos, 2):int()
						.. ", Y: " .. buffer(pos + 2, 2):int()
						.. ", Z: " .. buffer(pos + 4, 2):int())
					t2:add(f_x, buffer(pos, 2))
					t2:add(f_y, buffer(pos + 2, 2))
					t2:add(f_z, buffer(pos + 4, 2))
				end
			end
		end
	}
end

-- TOSERVER_ADDNODE_FROM_INVENTORY (obsolete)

minetest_client_commands[0x26] = { "ADDNODE_FROM_INVENTORY", 2 }
minetest_client_obsolete[0x26] = true

-- TOSERVER_CLICK_OBJECT (obsolete)

minetest_client_commands[0x27] = { "CLICK_OBJECT", 2 }
minetest_client_obsolete[0x27] = true

-- TOSERVER_GROUND_ACTION (obsolete)

minetest_client_commands[0x28] = { "GROUND_ACTION", 2 }
minetest_client_obsolete[0x28] = true

-- TOSERVER_RELEASE (obsolete)

minetest_client_commands[0x29] = { "RELEASE", 2 }
minetest_client_obsolete[0x29] = true

-- TOSERVER_SIGNTEXT (obsolete)

minetest_client_commands[0x30] = { "SIGNTEXT", 2 }
minetest_client_obsolete[0x30] = true

-- TOSERVER_INVENTORY_ACTION

do
	local f_action = ProtoField.string("minetest.client.inventory_action", "Action")

	minetest_client_commands[0x31] = {
		"INVENTORY_ACTION", 2,
		{ f_action },
		function(buffer, pinfo, tree, t)
			t:add(f_action, buffer(2, buffer:len() - 2))
		end
	}
end

-- TOSERVER_CHAT_MESSAGE

do
	local f_length = ProtoField.uint16("minetest.client.chat_message_length", "Length", base.DEC)
	local f_message = ProtoField.string("minetest.client.chat_message", "Message")

	minetest_client_commands[0x32] = {
		"CHAT_MESSAGE", 4,
		{ f_length, f_message },
		function(buffer, pinfo, tree, t)
			t:add(f_length, buffer(2,2))
			local textlen = buffer(2,2):uint()
			if minetest_check_length(buffer, 4 + textlen*2, t) then
				t:add(f_message, buffer(4, textlen*2), buffer(4, textlen*2):ustring())
			end
		end
	}
end

-- TOSERVER_SIGNNODETEXT (obsolete)

minetest_client_commands[0x33] = { "SIGNNODETEXT", 2 }
minetest_client_obsolete[0x33] = true


-- TOSERVER_CLICK_ACTIVEOBJECT (obsolete)

minetest_client_commands[0x34] = { "CLICK_ACTIVEOBJECT", 2 }
minetest_client_obsolete[0x34] = true

-- TOSERVER_DAMAGE

do
	local f_amount = ProtoField.uint8("minetest.client.damage_amount", "Amount", base.DEC)

	minetest_client_commands[0x35] = {
		"DAMAGE", 3,
		{ f_amount },
		function(buffer, pinfo, tree, t)
			t:add(f_amount, buffer(2,1))
		end
	}
end

-- TOSERVER_PASSWORD (obsolete)

minetest_client_commands[0x36] = { "CLICK_ACTIVEOBJECT", 2 }
minetest_client_obsolete[0x36] = true

-- TOSERVER_PLAYERITEM

do
	local f_item = ProtoField.uint16("minetest.client.playeritem_item", "Wielded item")

	minetest_client_commands[0x37] = {
		"PLAYERITEM", 4,
		{ f_item },
		function(buffer, pinfo, tree, t)
			t:add(f_item, buffer(2,2))
		end
	}
end

-- TOSERVER_RESPAWN

minetest_client_commands[0x38] = { "RESPAWN", 2 }

-- TOSERVER_INTERACT

do
	local abbr = "minetest.client.interact_"
	local vs_action = {
		[0] = "Start digging",
		[1] = "Stop digging",
		[2] = "Digging completed",
		[3] = "Place block or item",
		[4] = "Use item",
		[5] = "Activate held item",
	}
	local vs_pointed_type = {
		[0] = "Nothing",
		[1] = "Node",
		[2] = "Object",
	}

	local f_action = ProtoField.uint8(abbr.."action", "Action", base.DEC, vs_action)
	local f_item = ProtoField.uint16(abbr.."item", "Item Index", base.DEC)
	local f_plen = ProtoField.uint32(abbr.."plen", "Length of pointed thing", base.DEC)
	local f_pointed_version = ProtoField.uint8(abbr.."pointed_version",
		"Pointed Thing Version", base.DEC)
	local f_pointed_type = ProtoField.uint8(abbr.."pointed_version",
		"Pointed Thing Type", base.DEC, vs_pointed_type)
	local f_pointed_under_x = ProtoField.int16(abbr.."pointed_under_x",
		"Node position (under surface) X")
	local f_pointed_under_y = ProtoField.int16(abbr.."pointed_under_y",
		"Node position (under surface) Y")
	local f_pointed_under_z = ProtoField.int16(abbr.."pointed_under_z",
		"Node position (under surface) Z")
	local f_pointed_above_x = ProtoField.int16(abbr.."pointed_above_x",
		"Node position (above surface) X")
	local f_pointed_above_y = ProtoField.int16(abbr.."pointed_above_y",
		"Node position (above surface) Y")
	local f_pointed_above_z = ProtoField.int16(abbr.."pointed_above_z",
		"Node position (above surface) Z")
	local f_pointed_object_id = ProtoField.int16(abbr.."pointed_object_id",
		"Object ID")
	-- mising: additional playerpos data just like in TOSERVER_PLAYERPOS

	minetest_client_commands[0x39] = {
		"INTERACT", 11,
		{ f_action,
		  f_item,
		  f_plen,
		  f_pointed_version,
		  f_pointed_type,
		  f_pointed_under_x,
		  f_pointed_under_y,
		  f_pointed_under_z,
		  f_pointed_above_x,
		  f_pointed_above_y,
		  f_pointed_above_z,
		  f_pointed_object_id },
		function(buffer, pinfo, tree, t)
			t:add(f_action, buffer(2,1))
			t:add(f_item, buffer(3,2))
			t:add(f_plen, buffer(5,4))
			local plen = buffer(5,4):uint()
			if minetest_check_length(buffer, 9 + plen, t) then
				t:add(f_pointed_version, buffer(9,1))
				t:add(f_pointed_type, buffer(10,1))
				local ptype = buffer(10,1):uint()
				if ptype == 1 then -- Node
					t:add(f_pointed_under_x, buffer(11,2))
					t:add(f_pointed_under_y, buffer(13,2))
					t:add(f_pointed_under_z, buffer(15,2))
					t:add(f_pointed_above_x, buffer(17,2))
					t:add(f_pointed_above_y, buffer(19,2))
					t:add(f_pointed_above_z, buffer(21,2))
				elseif ptype == 2 then -- Object
					t:add(f_pointed_object_id, buffer(11,2))
				end
			end
		end
	}
end

-- ...

minetest_client_commands[0x3a] = { "REMOVED_SOUNDS", 2 }
minetest_client_commands[0x3b] = { "NODEMETA_FIELDS", 2 }
minetest_client_commands[0x3c] = { "INVENTORY_FIELDS", 2 }
minetest_client_commands[0x40] = { "REQUEST_MEDIA", 2 }
minetest_client_commands[0x41] = { "RECEIVED_MEDIA", 2 }

-- TOSERVER_BREATH (obsolete)

minetest_client_commands[0x42] = { "BREATH", 2 }
minetest_client_obsolete[0x42] = true

-- TOSERVER_CLIENT_READY

do
	local abbr = "minetest.client.client_ready_"
	local f_major = ProtoField.uint8(abbr.."major","Version Major")
	local f_minor = ProtoField.uint8(abbr.."minor","Version Minor")
	local f_patch = ProtoField.uint8(abbr.."patch","Version Patch")
	local f_reserved = ProtoField.uint8(abbr.."reserved","Reserved")
	local f_versionlen, f_version =
		minetest_field_helper("uint16", abbr.."version", "Full Version String")
	local f_formspec_ver = ProtoField.uint16(abbr.."formspec_version",
		"Formspec API version")

	minetest_client_commands[0x43] = {
		"CLIENT_READY",
		8,
		{ f_major, f_minor, f_patch, f_reserved, f_versionlen,
		  f_version, f_formspec_ver },
		function(buffer, pinfo, tree, t)
			t:add(f_major, buffer(2,1))
			t:add(f_minor, buffer(3,1))
			t:add(f_patch, buffer(4,1))
			t:add(f_reserved, buffer(5,1))
			local off = minetest_decode_helper_ascii(buffer, t, "uint16", 6,
				f_versionlen, f_version)
			if off and minetest_check_length(buffer, off + 2, t) then
				t:add(f_formspec_ver, buffer(off,2))
			end
		end
	}
end

-- ...

minetest_client_commands[0x50] = { "FIRST_SRP", 2 }
minetest_client_commands[0x51] = { "SRP_BYTES_A", 2 }
minetest_client_commands[0x52] = { "SRP_BYTES_M", 2 }



--------------------------------------------
-- Part 3                                 --
-- Server command dissectors (TOCLIENT_*) --
--------------------------------------------

minetest_server_commands = {}
minetest_server_obsolete = {}

-- TOCLIENT_HELLO

do
	local abbr = "minetest.server.hello_"

	local f_ser_fmt = ProtoField.uint8(abbr.."ser_version",
		"Deployed serialization format version", base.DEC)
	local f_comp_mode = ProtoField.uint16(abbr.."compression",
		"Deployed compression mode", base.DEC, { [0] = "No compression" })
	local f_proto = ProtoField.uint16(abbr.."proto",
		"Deployed protocol version", base.DEC)
	local f_auth_methods = ProtoField.bytes(abbr.."auth_modes",
		"Supported authentication modes")
	local f_legacy_namelen, f_legacy_name = minetest_field_helper("uint16",
		abbr.."legacy_name", "Legacy player name for hashing")

	minetest_server_commands[0x02] = {
		"HELLO",
		13,
		{ f_ser_fmt, f_comp_mode, f_proto, f_auth_methods,
		  f_legacy_namelen, f_legacy_name },
		function(buffer, pinfo, tree, t)
			t:add(f_ser_fmt, buffer(2,1))
			t:add(f_comp_mode, buffer(3,2))
			t:add(f_proto, buffer(5,2))
			t:add(f_auth_methods, buffer(7,4))
			minetest_decode_helper_ascii(buffer, t, "uint16", 11, f_legacy_namelen, f_legacy_name)
		end
	}
end

-- TOCLIENT_AUTH_ACCEPT

do
	local abbr = "minetest.server.auth_accept_"

	local f_player_x = ProtoField.float(abbr.."player_x", "Player position X")
	local f_player_y = ProtoField.float(abbr.."player_y", "Player position Y")
	local f_player_z = ProtoField.float(abbr.."player_z", "Player position Z")
	local f_map_seed = ProtoField.uint64(abbr.."map_seed", "Map seed")
	local f_send_interval = ProtoField.float(abbr.."send_interval",
		"Recommended send interval")
	local f_sudo_auth_methods = ProtoField.bytes(abbr.."sudo_auth_methods",
		"Supported auth methods for sudo mode")

	minetest_server_commands[0x03] = {
		"AUTH_ACCEPT",
		30,
		{ f_player_x, f_player_y, f_player_z, f_map_seed,
		  f_send_interval, f_sudo_auth_methods },
		function(buffer, pinfo, tree, t)
			t:add(f_player_x, buffer(2,4))
			t:add(f_player_y, buffer(6,4))
			t:add(f_player_z, buffer(10,4))
			t:add(f_map_seed, buffer(14,8))
			t:add(f_send_interval, buffer(22,4))
			t:add(f_sudo_auth_methods, buffer(26,4))
		end
	}
end

-- ...

minetest_server_commands[0x04] = {"ACCEPT_SUDO_MODE", 2}
minetest_server_commands[0x05] = {"DENY_SUDO_MODE", 2}
minetest_server_commands[0x0A] = {"ACCESS_DENIED", 2}

-- TOCLIENT_INIT (obsolete)

minetest_server_commands[0x10] = { "INIT", 2 }
minetest_server_obsolete[0x10] = true

-- TOCLIENT_BLOCKDATA

do
	local f_x = ProtoField.int16("minetest.server.blockdata_x", "Block position X", base.DEC)
	local f_y = ProtoField.int16("minetest.server.blockdata_y", "Block position Y", base.DEC)
	local f_z = ProtoField.int16("minetest.server.blockdata_z", "Block position Z", base.DEC)
	local f_data = ProtoField.bytes("minetest.server.blockdata_block", "Serialized MapBlock")

	minetest_server_commands[0x20] = {
		"BLOCKDATA", 8,
		{ f_x, f_y, f_z, f_data },
		function(buffer, pinfo, tree, t)
			t:add(f_x, buffer(2,2))
			t:add(f_y, buffer(4,2))
			t:add(f_z, buffer(6,2))
			t:add(f_data, buffer(8, buffer:len() - 8))
		end
	}
end

-- TOCLIENT_ADDNODE

do
	local f_x = ProtoField.int16("minetest.server.addnode_x", "Position X", base.DEC)
	local f_y = ProtoField.int16("minetest.server.addnode_y", "Position Y", base.DEC)
	local f_z = ProtoField.int16("minetest.server.addnode_z", "Position Z", base.DEC)
	local f_data = ProtoField.bytes("minetest.server.addnode_node", "Serialized MapNode")

	minetest_server_commands[0x21] = {
		"ADDNODE", 8,
		{ f_x, f_y, f_z, f_data },
		function(buffer, pinfo, tree, t)
			t:add(f_x, buffer(2,2))
			t:add(f_y, buffer(4,2))
			t:add(f_z, buffer(6,2))
			t:add(f_data, buffer(8, buffer:len() - 8))
		end
	}
end

-- TOCLIENT_REMOVENODE

do
	local f_x = ProtoField.int16("minetest.server.removenode_x", "Position X", base.DEC)
	local f_y = ProtoField.int16("minetest.server.removenode_y", "Position Y", base.DEC)
	local f_z = ProtoField.int16("minetest.server.removenode_z", "Position Z", base.DEC)

	minetest_server_commands[0x22] = {
		"REMOVENODE", 8,
		{ f_x, f_y, f_z },
		function(buffer, pinfo, tree, t)
			t:add(f_x, buffer(2,2))
			t:add(f_y, buffer(4,2))
			t:add(f_z, buffer(6,2))
		end
	}
end

-- TOCLIENT_PLAYERPOS (obsolete)

minetest_server_commands[0x23] = { "PLAYERPOS", 2 }
minetest_server_obsolete[0x23] = true

-- TOCLIENT_PLAYERINFO (obsolete)

minetest_server_commands[0x24] = { "PLAYERINFO", 2 }
minetest_server_obsolete[0x24] = true

-- TOCLIENT_OPT_BLOCK_NOT_FOUND (obsolete)

minetest_server_commands[0x25] = { "OPT_BLOCK_NOT_FOUND", 2 }
minetest_server_obsolete[0x25] = true

-- TOCLIENT_SECTORMETA (obsolete)

minetest_server_commands[0x26] = { "SECTORMETA", 2 }
minetest_server_obsolete[0x26] = true

-- TOCLIENT_INVENTORY

do
	local f_inventory = ProtoField.string("minetest.server.inventory", "Inventory")

	minetest_server_commands[0x27] = {
		"INVENTORY", 2,
		{ f_inventory },
		function(buffer, pinfo, tree, t)
			t:add(f_inventory, buffer(2, buffer:len() - 2))
		end
	}
end

-- TOCLIENT_OBJECTDATA (obsolete)

minetest_server_commands[0x28] = { "OBJECTDATA", 2 }
minetest_server_obsolete[0x28] = true

-- TOCLIENT_TIME_OF_DAY

do
	local f_time = ProtoField.uint16("minetest.server.time_of_day", "Time", base.DEC)
	local f_time_speed = ProtoField.float("minetest.server.time_speed", "Time Speed", base.DEC)

	minetest_server_commands[0x29] = {
		"TIME_OF_DAY", 4,
		{ f_time, f_time_speed },
		function(buffer, pinfo, tree, t)
			t:add(f_time, buffer(2,2))
			t:add(f_time_speed, buffer(4,4))
		end
	}
end

-- TOCLIENT_CSM_RESTRICTION_FLAGS

minetest_server_commands[0x2a] = { "CSM_RESTRICTION_FLAGS", 2 }

-- TOCLIENT_PLAYER_SPEED

minetest_server_commands[0x2b] = { "PLAYER_SPEED", 2 }

-- TOCLIENT_CHAT_MESSAGE

do
	local abbr = "minetest.server.chat_message_"
	local vs_type = {
		[0] = "Raw",
		[1] = "Normal",
		[2] = "Announce",
		[3] = "System",
	}

	local f_version = ProtoField.uint8(abbr.."version", "Version")
	local f_type = ProtoField.uint8(abbr.."type", "Message Type", base.DEC, vs_type)
	local f_senderlen, f_sender = minetest_field_helper("uint16", abbr.."sender",
		"Message sender")
	local f_messagelen, f_message = minetest_field_helper("uint16", abbr:sub(1,-2),
		"Message")

	minetest_server_commands[0x2f] = {
		"CHAT_MESSAGE", 8,
		{ f_version, f_type, f_senderlen, f_sender,
		  f_messagelen, f_message },
		function(buffer, pinfo, tree, t)
			t:add(f_version, buffer(2,1))
			t:add(f_type, buffer(3,1))
			local off = 4
			off = minetest_decode_helper_utf16(buffer, t, "uint16", off, f_senderlen, f_sender)
			if off then
				off = minetest_decode_helper_utf16(buffer, t, "uint16", off, f_messagelen, f_message)
			end
		end
	}
end

-- TOCLIENT_CHAT_MESSAGE_OLD (obsolete)

minetest_server_commands[0x30] = { "CHAT_MESSAGE_OLD", 2 }
minetest_server_obsolete[0x30] = true

-- TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD

do
	local f_removed_count = ProtoField.uint16(
		"minetest.server.active_object_remove_add_removed_count",
		"Count of removed objects", base.DEC)
	local f_removed = ProtoField.bytes(
		"minetest.server.active_object_remove_add_removed",
		"Removed object")
	local f_removed_id = ProtoField.uint16(
		"minetest.server.active_object_remove_add_removed_id",
		"ID", base.DEC)

	local f_added_count = ProtoField.uint16(
		"minetest.server.active_object_remove_add_added_count",
		"Count of added objects", base.DEC)
	local f_added = ProtoField.bytes(
		"minetest.server.active_object_remove_add_added",
		"Added object")
	local f_added_id = ProtoField.uint16(
		"minetest.server.active_object_remove_add_added_id",
		"ID", base.DEC)
	local f_added_type = ProtoField.uint8(
		"minetest.server.active_object_remove_add_added_type",
		"Type", base.DEC)
	local f_added_init_length = ProtoField.uint32(
		"minetest.server.active_object_remove_add_added_init_length",
		"Initialization data length", base.DEC)
	local f_added_init_data = ProtoField.bytes(
		"minetest.server.active_object_remove_add_added_init_data",
		"Initialization data")

	minetest_server_commands[0x31] = {
		"ACTIVE_OBJECT_REMOVE_ADD", 6,
		{ f_removed_count, f_removed, f_removed_id,
		  f_added_count, f_added, f_added_id,
		  f_added_type, f_added_init_length, f_added_init_data },
		function(buffer, pinfo, tree, t)
			local t2, index, pos

			local removed_count_pos = 2
			local removed_count = buffer(removed_count_pos, 2):uint()
			t:add(f_removed_count, buffer(removed_count_pos, 2))

			local added_count_pos = removed_count_pos + 2 + 2 * removed_count
			if not minetest_check_length(buffer, added_count_pos + 2, t) then
				return
			end

			-- Loop through removed active objects
			for index = 0, removed_count - 1 do
				pos = removed_count_pos + 2 + 2 * index
				t2 = t:add(f_removed, buffer(pos, 2))
				t2:set_text("Removed object, ID = " ..  buffer(pos, 2):uint())
				t2:add(f_removed_id, buffer(pos, 2))
			end

			local added_count = buffer(added_count_pos, 2):uint()
			t:add(f_added_count, buffer(added_count_pos, 2))

			-- Loop through added active objects
			pos = added_count_pos + 2
			for index = 0, added_count - 1 do
				if not minetest_check_length(buffer, pos + 7, t) then
					return
				end

				local init_length = buffer(pos + 3, 4):uint()
				if not minetest_check_length(buffer, pos + 7 + init_length, t) then
					return
				end

				t2 = t:add(f_added, buffer(pos, 7 + init_length))
				t2:set_text("Added object, ID = " .. buffer(pos, 2):uint())
				t2:add(f_added_id, buffer(pos, 2))
				t2:add(f_added_type, buffer(pos + 2, 1))
				t2:add(f_added_init_length, buffer(pos + 3, 4))
				t2:add(f_added_init_data, buffer(pos + 7, init_length))

				pos = pos + 7 + init_length
			end

			pinfo.cols.info:append(" * " .. (removed_count + added_count))
		end
	}
end

-- TOCLIENT_ACTIVE_OBJECT_MESSAGES

do
	local f_object_count = ProtoField.uint16(
		"minetest.server.active_object_messages_object_count",
		"Count of objects", base.DEC)
	local f_object = ProtoField.bytes(
		"minetest.server.active_object_messages_object",
		"Object")
	local f_object_id = ProtoField.uint16(
		"minetest.server.active_object_messages_id",
		"ID", base.DEC)
	local f_message_length = ProtoField.uint16(
		"minetest.server.active_object_messages_message_length",
		"Message length", base.DEC)
	local f_message = ProtoField.bytes(
		"minetest.server.active_object_messages_message",
		"Message")

	minetest_server_commands[0x32] = {
		"ACTIVE_OBJECT_MESSAGES", 2,
		{ f_object_count, f_object, f_object_id, f_message_length, f_message },
		function(buffer, pinfo, tree, t)
			local t2, count, pos, message_length

			count = 0
			pos = 2
			while pos < buffer:len() do
				if not minetest_check_length(buffer, pos + 4, t) then
					return
				end
				message_length = buffer(pos + 2, 2):uint()
				if not minetest_check_length(buffer, pos + 4 + message_length, t) then
					return
				end
				count = count + 1
				pos = pos + 4 + message_length
			end

			pinfo.cols.info:append(" * " .. count)
			t:add(f_object_count, count):set_generated()

			pos = 2
			while pos < buffer:len() do
				message_length = buffer(pos + 2, 2):uint()

				t2 = t:add(f_object, buffer(pos, 4 + message_length))
				t2:set_text("Object, ID = " ..  buffer(pos, 2):uint())
				t2:add(f_object_id, buffer(pos, 2))
				t2:add(f_message_length, buffer(pos + 2, 2))
				t2:add(f_message, buffer(pos + 4, message_length))

				pos = pos + 4 + message_length
			end
		end
	}
end

-- TOCLIENT_HP

do
	local f_hp = ProtoField.uint16("minetest.server.hp", "Health points", base.DEC)

	minetest_server_commands[0x33] = {
		"HP", 4,
		{ f_hp },
		function(buffer, pinfo, tree, t)
			t:add(f_hp, buffer(2,2))
		end
	}
end

-- TOCLIENT_MOVE_PLAYER

do
	local abbr = "minetest.server.move_player_"

	local f_x = ProtoField.float(abbr.."x", "Position X")
	local f_y = ProtoField.float(abbr.."y", "Position Y")
	local f_z = ProtoField.float(abbr.."z", "Position Z")
	local f_pitch = ProtoField.float(abbr.."_pitch", "Pitch")
	local f_yaw = ProtoField.float(abbr.."yaw", "Yaw")

	minetest_server_commands[0x34] = {
		"MOVE_PLAYER", 22,
		{ f_x, f_y, f_z, f_pitch, f_yaw, f_garbage },
		function(buffer, pinfo, tree, t)
			t:add(f_x, buffer(2, 4))
			t:add(f_y, buffer(6, 4))
			t:add(f_z, buffer(10, 4))
			t:add(f_pitch, buffer(14, 4))
			t:add(f_yaw, buffer(18, 4))
		end
	}
end

-- TOCLIENT_ACCESS_DENIED_LEGACY

do
	local f_reason_length = ProtoField.uint16("minetest.server.access_denied_reason_length", "Reason length", base.DEC)
	local f_reason = ProtoField.string("minetest.server.access_denied_reason", "Reason")

	minetest_server_commands[0x35] = {
		"ACCESS_DENIED_LEGACY", 4,
		{ f_reason_length, f_reason },
		function(buffer, pinfo, tree, t)
			t:add(f_reason_length, buffer(2,2))
			local reason_length = buffer(2,2):uint()
			if minetest_check_length(buffer, 4 + reason_length * 2, t) then
				t:add(f_reason, minetest_convert_utf16(buffer(4, reason_length * 2), "Converted reason message"))
			end
		end
	}
end

-- TOCLIENT_FOV

minetest_server_commands[0x36] = { "FOV", 2 }

-- TOCLIENT_DEATHSCREEN

do
	local f_set_camera_point_target = ProtoField.bool(
		"minetest.server.deathscreen_set_camera_point_target",
		"Set camera point target")
	local f_camera_point_target_x = ProtoField.int32(
		"minetest.server.deathscreen_camera_point_target_x",
		"Camera point target X", base.DEC)
	local f_camera_point_target_y = ProtoField.int32(
		"minetest.server.deathscreen_camera_point_target_y",
		"Camera point target Y", base.DEC)
	local f_camera_point_target_z = ProtoField.int32(
		"minetest.server.deathscreen_camera_point_target_z",
		"Camera point target Z", base.DEC)

	minetest_server_commands[0x37] = {
		"DEATHSCREEN", 15,
		{ f_set_camera_point_target, f_camera_point_target_x,
		  f_camera_point_target_y, f_camera_point_target_z},
		function(buffer, pinfo, tree, t)
			t:add(f_set_camera_point_target, buffer(2,1))
			t:add(f_camera_point_target_x, buffer(3,4))
			t:add(f_camera_point_target_y, buffer(7,4))
			t:add(f_camera_point_target_z, buffer(11,4))
		end
	}
end

-- TOCLIENT_MEDIA

minetest_server_commands[0x38] = {"MEDIA", 2}

-- TOCLIENT_TOOLDEF (obsolete)

minetest_server_commands[0x39] = {"TOOLDEF", 2}
minetest_server_obsolete[0x39] = true

-- TOCLIENT_NODEDEF

minetest_server_commands[0x3a] = {"NODEDEF", 2}

-- TOCLIENT_CRAFTITEMDEF (obsolete)

minetest_server_commands[0x3b] = {"CRAFTITEMDEF", 2}
minetest_server_obsolete[0x3b] = true

-- ...

minetest_server_commands[0x3c] = {"ANNOUNCE_MEDIA", 2}
minetest_server_commands[0x3d] = {"ITEMDEF", 2}
minetest_server_commands[0x3f] = {"PLAY_SOUND", 2}
minetest_server_commands[0x40] = {"STOP_SOUND", 2}
minetest_server_commands[0x41] = {"PRIVILEGES", 2}
minetest_server_commands[0x42] = {"INVENTORY_FORMSPEC", 2}
minetest_server_commands[0x43] = {"DETACHED_INVENTORY", 2}
minetest_server_commands[0x44] = {"SHOW_FORMSPEC", 2}
minetest_server_commands[0x45] = {"MOVEMENT", 2}
minetest_server_commands[0x46] = {"SPAWN_PARTICLE", 2}
minetest_server_commands[0x47] = {"ADD_PARTICLE_SPAWNER", 2}

-- TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY (obsolete)

minetest_server_commands[0x48] = {"DELETE_PARTICLESPAWNER_LEGACY", 2}
minetest_server_obsolete[0x48] = true

-- ...

minetest_server_commands[0x49] = {"HUDADD", 2}
minetest_server_commands[0x4a] = {"HUDRM", 2}
minetest_server_commands[0x4b] = {"HUDCHANGE", 2}
minetest_server_commands[0x4c] = {"HUD_SET_FLAGS", 2}
minetest_server_commands[0x4d] = {"HUD_SET_PARAM", 2}
minetest_server_commands[0x4e] = {"BREATH", 2}
minetest_server_commands[0x4f] = {"SET_SKY", 2}
minetest_server_commands[0x50] = {"OVERRIDE_DAY_NIGHT_RATIO", 2}
minetest_server_commands[0x51] = {"LOCAL_PLAYER_ANIMATIONS", 2}
minetest_server_commands[0x52] = {"EYE_OFFSET", 2}
minetest_server_commands[0x53] = {"DELETE_PARTICLESPAWNER", 2}
minetest_server_commands[0x54] = {"CLOUD_PARAMS", 2}
minetest_server_commands[0x55] = {"FADE_SOUND", 2}

-- TOCLIENT_UPDATE_PLAYER_LIST

do
	local abbr = "minetest.server.update_player_list_"
	local vs_type = {
		[0] = "Init",
		[1] = "Add",
		[2] = "Remove",
	}

	local f_type = ProtoField.uint8(abbr.."type", "Type", base.DEC, vs_type)
	local f_count = ProtoField.uint16(abbr.."count", "Number of players", base.DEC)
	local f_name = ProtoField.string(abbr.."name", "Name")

	minetest_server_commands[0x56] = {
		"UPDATE_PLAYER_LIST",
		5,
		{ f_type, f_count, f_name },
		function(buffer, pinfo, tree, t)
			t:add(f_type, buffer(2,1))
			t:add(f_count, buffer(3,2))
			local count = buffer(3,2):uint()
			local off = 5
			for i = 1, count do