mirror of
https://github.com/minetest/minetest.git
synced 2024-12-21 21:52:25 +01:00
Network: offload often changed constants to source file (#15207)
* Network: offload often changed constants to source file This prevents unnecessary recompiling when using incremental builds. There is also no need to have separate max proto version variables; as they're subject to the handshake between client and server. The code is also expected to support the same version (or higher). Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
parent
22ef4c8be1
commit
3797ca52c4
@ -1147,7 +1147,7 @@ void Client::sendInit(const std::string &playerName)
|
||||
NetworkPacket pkt(TOSERVER_INIT, 1 + 2 + 2 + (1 + playerName.size()));
|
||||
|
||||
pkt << (u8) SER_FMT_VER_HIGHEST_READ << (u16) 0;
|
||||
pkt << (u16) CLIENT_PROTOCOL_VERSION_MIN << (u16) CLIENT_PROTOCOL_VERSION_MAX;
|
||||
pkt << CLIENT_PROTOCOL_VERSION_MIN << LATEST_PROTOCOL_VERSION;
|
||||
pkt << playerName;
|
||||
|
||||
Send(&pkt);
|
||||
|
@ -35,6 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "gameparams.h"
|
||||
#include "script/common/c_types.h" // LuaError
|
||||
#include "util/numeric.h"
|
||||
#include "util/string.h" // StringMap
|
||||
|
||||
#ifdef SERVER
|
||||
#error Do not include in server builds
|
||||
|
@ -728,7 +728,7 @@ static void startup_message()
|
||||
print_version(infostream);
|
||||
infostream << "SER_FMT_VER_HIGHEST_READ=" <<
|
||||
TOSTRING(SER_FMT_VER_HIGHEST_READ) <<
|
||||
" LATEST_PROTOCOL_VERSION=" << TOSTRING(LATEST_PROTOCOL_VERSION)
|
||||
" LATEST_PROTOCOL_VERSION=" << LATEST_PROTOCOL_VERSION
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ set(common_network_SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mtp/impl.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mtp/threads.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/networkpacket.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/networkprotocol.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/serveropcodes.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/serverpackethandler.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/socket.cpp
|
||||
|
@ -19,7 +19,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "util/pointer.h"
|
||||
#include "util/pointer.h" // Buffer<T>
|
||||
#include "irrlichttypes_bloated.h"
|
||||
#include "networkprotocol.h"
|
||||
#include <SColor.h>
|
||||
|
||||
|
66
src/network/networkprotocol.cpp
Normal file
66
src/network/networkprotocol.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
// Minetest
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include "networkprotocol.h"
|
||||
|
||||
|
||||
/*
|
||||
PROTOCOL VERSION < 37:
|
||||
Until (and including) version 0.4.17.1
|
||||
PROTOCOL VERSION 37:
|
||||
Redo detached inventory sending
|
||||
Add TOCLIENT_NODEMETA_CHANGED
|
||||
New network float format
|
||||
ContentFeatures version 13
|
||||
Add full Euler rotations instead of just yaw
|
||||
Add TOCLIENT_PLAYER_SPEED
|
||||
[bump for 5.0.0]
|
||||
PROTOCOL VERSION 38:
|
||||
Incremental inventory sending mode
|
||||
Unknown inventory serialization fields no longer throw an error
|
||||
Mod-specific formspec version
|
||||
Player FOV override API
|
||||
"ephemeral" added to TOCLIENT_PLAY_SOUND
|
||||
PROTOCOL VERSION 39:
|
||||
Updated set_sky packet
|
||||
Adds new sun, moon and stars packets
|
||||
Minimap modes
|
||||
PROTOCOL VERSION 40:
|
||||
TOCLIENT_MEDIA_PUSH changed, TOSERVER_HAVE_MEDIA added
|
||||
PROTOCOL VERSION 41:
|
||||
Added new particlespawner parameters
|
||||
[scheduled bump for 5.6.0]
|
||||
PROTOCOL VERSION 42:
|
||||
TOSERVER_UPDATE_CLIENT_INFO added
|
||||
new fields for TOCLIENT_SET_LIGHTING and TOCLIENT_SET_SKY
|
||||
Send forgotten TweenedParameter properties
|
||||
[scheduled bump for 5.7.0]
|
||||
PROTOCOL VERSION 43:
|
||||
"start_time" added to TOCLIENT_PLAY_SOUND
|
||||
place_param2 type change u8 -> optional<u8>
|
||||
[scheduled bump for 5.8.0]
|
||||
PROTOCOL VERSION 44:
|
||||
AO_CMD_SET_BONE_POSITION extended
|
||||
Add TOCLIENT_MOVE_PLAYER_REL
|
||||
Move default minimap from client-side C++ to server-side builtin Lua
|
||||
[scheduled bump for 5.9.0]
|
||||
PROTOCOL VERSION 45:
|
||||
Minimap HUD element supports negative size values as percentages
|
||||
[bump for 5.9.1]
|
||||
PROTOCOL VERSION 46:
|
||||
Move default hotbar from client-side C++ to server-side builtin Lua
|
||||
Add shadow tint to Lighting packets
|
||||
Add shadow color to CloudParam packets
|
||||
Move death screen to server and make it a regular formspec
|
||||
The server no longer triggers the hardcoded client-side death
|
||||
formspec, but the client still supports it for compatibility with
|
||||
old servers.
|
||||
Rename TOCLIENT_DEATHSCREEN to TOCLIENT_DEATHSCREEN_LEGACY
|
||||
Rename TOSERVER_RESPAWN to TOSERVER_RESPAWN_LEGACY
|
||||
[scheduled bump for 5.10.0]
|
||||
*/
|
||||
|
||||
const u16 LATEST_PROTOCOL_VERSION = 46;
|
||||
|
||||
// See also formspec [Version History] in doc/lua_api.md
|
||||
const u16 FORMSPEC_API_VERSION = 7;
|
@ -19,240 +19,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "util/string.h"
|
||||
#include "irrTypes.h"
|
||||
using namespace irr;
|
||||
|
||||
/*
|
||||
changes by PROTOCOL_VERSION:
|
||||
|
||||
PROTOCOL_VERSION 3:
|
||||
Base for writing changes here
|
||||
PROTOCOL_VERSION 4:
|
||||
Add TOCLIENT_MEDIA
|
||||
Add TOCLIENT_TOOLDEF
|
||||
Add TOCLIENT_NODEDEF
|
||||
Add TOCLIENT_CRAFTITEMDEF
|
||||
Add TOSERVER_INTERACT
|
||||
Obsolete TOSERVER_CLICK_ACTIVEOBJECT
|
||||
Obsolete TOSERVER_GROUND_ACTION
|
||||
PROTOCOL_VERSION 5:
|
||||
Make players to be handled mostly as ActiveObjects
|
||||
PROTOCOL_VERSION 6:
|
||||
Only non-cached textures are sent
|
||||
PROTOCOL_VERSION 7:
|
||||
Add TOCLIENT_ITEMDEF
|
||||
Obsolete TOCLIENT_TOOLDEF
|
||||
Obsolete TOCLIENT_CRAFTITEMDEF
|
||||
Compress the contents of TOCLIENT_ITEMDEF and TOCLIENT_NODEDEF
|
||||
PROTOCOL_VERSION 8:
|
||||
Digging based on item groups
|
||||
Many things
|
||||
PROTOCOL_VERSION 9:
|
||||
ContentFeatures and NodeDefManager use a different serialization
|
||||
format; better for future version cross-compatibility
|
||||
Many things
|
||||
Obsolete TOCLIENT_PLAYERITEM
|
||||
PROTOCOL_VERSION 10:
|
||||
TOCLIENT_PRIVILEGES
|
||||
Version raised to force 'fly' and 'fast' privileges into effect.
|
||||
Node metadata change (came in later; somewhat incompatible)
|
||||
PROTOCOL_VERSION 11:
|
||||
TileDef in ContentFeatures
|
||||
Nodebox drawtype
|
||||
(some dev snapshot)
|
||||
TOCLIENT_INVENTORY_FORMSPEC
|
||||
(0.4.0, 0.4.1)
|
||||
PROTOCOL_VERSION 12:
|
||||
TOSERVER_INVENTORY_FIELDS
|
||||
16-bit node ids
|
||||
TOCLIENT_DETACHED_INVENTORY
|
||||
PROTOCOL_VERSION 13:
|
||||
InventoryList field "Width" (deserialization fails with old versions)
|
||||
PROTOCOL_VERSION 14:
|
||||
Added transfer of player pressed keys to the server
|
||||
Added new messages for mesh and bone animation, as well as attachments
|
||||
AO_CMD_SET_ANIMATION
|
||||
AO_CMD_SET_BONE_POSITION
|
||||
GENERIC_CMD_SET_ATTACHMENT
|
||||
PROTOCOL_VERSION 15:
|
||||
Serialization format changes
|
||||
PROTOCOL_VERSION 16:
|
||||
TOCLIENT_SHOW_FORMSPEC
|
||||
PROTOCOL_VERSION 17:
|
||||
Serialization format change: include backface_culling flag in TileDef
|
||||
Added rightclickable field in nodedef
|
||||
TOCLIENT_SPAWN_PARTICLE
|
||||
TOCLIENT_ADD_PARTICLESPAWNER
|
||||
TOCLIENT_DELETE_PARTICLESPAWNER
|
||||
PROTOCOL_VERSION 18:
|
||||
damageGroups added to ToolCapabilities
|
||||
sound_place added to ItemDefinition
|
||||
PROTOCOL_VERSION 19:
|
||||
AO_CMD_SET_PHYSICS_OVERRIDE
|
||||
PROTOCOL_VERSION 20:
|
||||
TOCLIENT_HUDADD
|
||||
TOCLIENT_HUDRM
|
||||
TOCLIENT_HUDCHANGE
|
||||
TOCLIENT_HUD_SET_FLAGS
|
||||
PROTOCOL_VERSION 21:
|
||||
TOCLIENT_BREATH
|
||||
TOSERVER_BREATH
|
||||
range added to ItemDefinition
|
||||
drowning, leveled and liquid_range added to ContentFeatures
|
||||
stepheight and collideWithObjects added to object properties
|
||||
version, heat and humidity transfer in MapBock
|
||||
automatic_face_movement_dir and automatic_face_movement_dir_offset
|
||||
added to object properties
|
||||
PROTOCOL_VERSION 22:
|
||||
add swap_node
|
||||
PROTOCOL_VERSION 23:
|
||||
Obsolete TOSERVER_RECEIVED_MEDIA
|
||||
Server: Stop using TOSERVER_CLIENT_READY
|
||||
PROTOCOL_VERSION 24:
|
||||
ContentFeatures version 7
|
||||
ContentFeatures: change number of special tiles to 6 (CF_SPECIAL_COUNT)
|
||||
PROTOCOL_VERSION 25:
|
||||
Rename TOCLIENT_ACCESS_DENIED to TOCLIENT_ACCESS_DENIED_LEGAGY
|
||||
Rename TOCLIENT_DELETE_PARTICLESPAWNER to
|
||||
TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY
|
||||
Rename TOSERVER_PASSWORD to TOSERVER_PASSWORD_LEGACY
|
||||
Rename TOSERVER_INIT to TOSERVER_INIT_LEGACY
|
||||
Rename TOCLIENT_INIT to TOCLIENT_INIT_LEGACY
|
||||
Add TOCLIENT_ACCESS_DENIED new opcode (0x0A), using error codes
|
||||
for standard error, keeping customisation possible. This
|
||||
permit translation
|
||||
Add TOCLIENT_DELETE_PARTICLESPAWNER (0x53), fixing the u16 read and
|
||||
reading u32
|
||||
Add new opcode TOSERVER_INIT for client presentation to server
|
||||
Add new opcodes TOSERVER_FIRST_SRP, TOSERVER_SRP_BYTES_A,
|
||||
TOSERVER_SRP_BYTES_M, TOCLIENT_SRP_BYTES_S_B
|
||||
for the three supported auth mechanisms around srp
|
||||
Add new opcodes TOCLIENT_ACCEPT_SUDO_MODE and TOCLIENT_DENY_SUDO_MODE
|
||||
for sudo mode handling (auth mech generic way of changing password).
|
||||
Add TOCLIENT_HELLO for presenting server to client after client
|
||||
presentation
|
||||
Add TOCLIENT_AUTH_ACCEPT to accept connection from client
|
||||
Rename GENERIC_CMD_SET_ATTACHMENT to AO_CMD_ATTACH_TO
|
||||
PROTOCOL_VERSION 26:
|
||||
Add TileDef tileable_horizontal, tileable_vertical flags
|
||||
PROTOCOL_VERSION 27:
|
||||
backface_culling: backwards compatibility for playing with
|
||||
newer client on pre-27 servers.
|
||||
Add nodedef v3 - connected nodeboxes
|
||||
PROTOCOL_VERSION 28:
|
||||
CPT2_MESHOPTIONS
|
||||
PROTOCOL_VERSION 29:
|
||||
Server doesn't accept TOSERVER_BREATH anymore
|
||||
serialization of TileAnimation params changed
|
||||
TAT_SHEET_2D
|
||||
Removed client-sided chat perdiction
|
||||
PROTOCOL VERSION 30:
|
||||
New ContentFeatures serialization version
|
||||
Add node and tile color and palette
|
||||
Fix plantlike visual_scale being applied squared and add compatibility
|
||||
with pre-30 clients by sending sqrt(visual_scale)
|
||||
PROTOCOL VERSION 31:
|
||||
Add tile overlay
|
||||
Stop sending TOSERVER_CLIENT_READY
|
||||
PROTOCOL VERSION 32:
|
||||
Add fading sounds
|
||||
PROTOCOL VERSION 33:
|
||||
Add TOCLIENT_UPDATE_PLAYER_LIST and send the player list to the client,
|
||||
instead of guessing based on the active object list.
|
||||
PROTOCOL VERSION 34:
|
||||
Add sound pitch
|
||||
PROTOCOL VERSION 35:
|
||||
Rename TOCLIENT_CHAT_MESSAGE to TOCLIENT_CHAT_MESSAGE_OLD (0x30)
|
||||
Add TOCLIENT_CHAT_MESSAGE (0x2F)
|
||||
This chat message is a signalisation message containing various
|
||||
informations:
|
||||
* timestamp
|
||||
* sender
|
||||
* type (RAW, NORMAL, ANNOUNCE, SYSTEM)
|
||||
* content
|
||||
Add TOCLIENT_CSM_RESTRICTION_FLAGS to define which CSM features should be
|
||||
limited
|
||||
Add settable player collisionbox. Breaks compatibility with older
|
||||
clients as a 1-node vertical offset has been removed from player's
|
||||
position
|
||||
Add settable player stepheight using existing object property.
|
||||
Breaks compatibility with older clients.
|
||||
PROTOCOL VERSION 36:
|
||||
Backwards compatibility drop
|
||||
Add 'can_zoom' to player object properties
|
||||
Add glow to object properties
|
||||
Change TileDef serialization format.
|
||||
Add world-aligned tiles.
|
||||
Mod channels
|
||||
Raise ObjectProperties version to 3 for removing 'can_zoom' and adding
|
||||
'zoom_fov'.
|
||||
Nodebox version 5
|
||||
Add disconnected nodeboxes
|
||||
Add TOCLIENT_FORMSPEC_PREPEND
|
||||
PROTOCOL VERSION 37:
|
||||
Redo detached inventory sending
|
||||
Add TOCLIENT_NODEMETA_CHANGED
|
||||
New network float format
|
||||
ContentFeatures version 13
|
||||
Add full Euler rotations instead of just yaw
|
||||
Add TOCLIENT_PLAYER_SPEED
|
||||
PROTOCOL VERSION 38:
|
||||
Incremental inventory sending mode
|
||||
Unknown inventory serialization fields no longer throw an error
|
||||
Mod-specific formspec version
|
||||
Player FOV override API
|
||||
"ephemeral" added to TOCLIENT_PLAY_SOUND
|
||||
PROTOCOL VERSION 39:
|
||||
Updated set_sky packet
|
||||
Adds new sun, moon and stars packets
|
||||
Minimap modes
|
||||
PROTOCOL VERSION 40:
|
||||
TOCLIENT_MEDIA_PUSH changed, TOSERVER_HAVE_MEDIA added
|
||||
PROTOCOL VERSION 41:
|
||||
Added new particlespawner parameters
|
||||
[scheduled bump for 5.6.0]
|
||||
PROTOCOL VERSION 42:
|
||||
TOSERVER_UPDATE_CLIENT_INFO added
|
||||
new fields for TOCLIENT_SET_LIGHTING and TOCLIENT_SET_SKY
|
||||
Send forgotten TweenedParameter properties
|
||||
[scheduled bump for 5.7.0]
|
||||
PROTOCOL VERSION 43:
|
||||
"start_time" added to TOCLIENT_PLAY_SOUND
|
||||
place_param2 type change u8 -> optional<u8>
|
||||
[scheduled bump for 5.8.0]
|
||||
PROTOCOL VERSION 44:
|
||||
AO_CMD_SET_BONE_POSITION extended
|
||||
Add TOCLIENT_MOVE_PLAYER_REL
|
||||
Move default minimap from client-side C++ to server-side builtin Lua
|
||||
[scheduled bump for 5.9.0]
|
||||
PROTOCOL VERSION 45:
|
||||
Minimap HUD element supports negative size values as percentages
|
||||
[bump for 5.9.1]
|
||||
PROTOCOL VERSION 46:
|
||||
Move default hotbar from client-side C++ to server-side builtin Lua
|
||||
Add shadow tint to Lighting packets
|
||||
Add shadow color to CloudParam packets
|
||||
Move death screen to server and make it a regular formspec
|
||||
The server no longer triggers the hardcoded client-side death
|
||||
formspec, but the client still supports it for compatibility with
|
||||
old servers.
|
||||
Rename TOCLIENT_DEATHSCREEN to TOCLIENT_DEATHSCREEN_LEGACY
|
||||
Rename TOSERVER_RESPAWN to TOSERVER_RESPAWN_LEGACY
|
||||
[scheduled bump for 5.10.0]
|
||||
*/
|
||||
|
||||
#define LATEST_PROTOCOL_VERSION 46
|
||||
#define LATEST_PROTOCOL_VERSION_STRING TOSTRING(LATEST_PROTOCOL_VERSION)
|
||||
extern const u16 LATEST_PROTOCOL_VERSION;
|
||||
|
||||
// Server's supported network protocol range
|
||||
#define SERVER_PROTOCOL_VERSION_MIN 37
|
||||
#define SERVER_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION
|
||||
constexpr u16 SERVER_PROTOCOL_VERSION_MIN = 37;
|
||||
|
||||
// Client's supported network protocol range
|
||||
#define CLIENT_PROTOCOL_VERSION_MIN 37
|
||||
#define CLIENT_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION
|
||||
constexpr u16 CLIENT_PROTOCOL_VERSION_MIN = 37;
|
||||
|
||||
// See also formspec [Version History] in doc/lua_api.md
|
||||
#define FORMSPEC_API_VERSION 7
|
||||
extern const u16 FORMSPEC_API_VERSION;
|
||||
|
||||
#define TEXTURENAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-"
|
||||
|
||||
|
@ -135,10 +135,10 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
|
||||
|
||||
// Figure out a working version if it is possible at all
|
||||
if (max_net_proto_version >= SERVER_PROTOCOL_VERSION_MIN ||
|
||||
min_net_proto_version <= SERVER_PROTOCOL_VERSION_MAX) {
|
||||
min_net_proto_version <= LATEST_PROTOCOL_VERSION) {
|
||||
// If maximum is larger than our maximum, go with our maximum
|
||||
if (max_net_proto_version > SERVER_PROTOCOL_VERSION_MAX)
|
||||
net_proto_version = SERVER_PROTOCOL_VERSION_MAX;
|
||||
if (max_net_proto_version > LATEST_PROTOCOL_VERSION)
|
||||
net_proto_version = LATEST_PROTOCOL_VERSION;
|
||||
// Else go with client's maximum
|
||||
else
|
||||
net_proto_version = max_net_proto_version;
|
||||
|
@ -1034,7 +1034,7 @@ int ModApiMainMenu::l_get_min_supp_proto(lua_State *L)
|
||||
|
||||
int ModApiMainMenu::l_get_max_supp_proto(lua_State *L)
|
||||
{
|
||||
lua_pushinteger(L, CLIENT_PROTOCOL_VERSION_MAX);
|
||||
lua_pushinteger(L, LATEST_PROTOCOL_VERSION);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -531,7 +531,7 @@ int ModApiUtil::l_get_version(lua_State *L)
|
||||
lua_pushnumber(L, SERVER_PROTOCOL_VERSION_MIN);
|
||||
lua_setfield(L, table, "proto_min");
|
||||
|
||||
lua_pushnumber(L, SERVER_PROTOCOL_VERSION_MAX);
|
||||
lua_pushnumber(L, LATEST_PROTOCOL_VERSION);
|
||||
lua_setfield(L, table, "proto_max");
|
||||
|
||||
if (strcmp(g_version_string, g_version_hash) != 0) {
|
||||
|
@ -4292,12 +4292,10 @@ u16 Server::getProtocolVersionMin()
|
||||
min_proto = LATEST_PROTOCOL_VERSION;
|
||||
return rangelim(min_proto,
|
||||
SERVER_PROTOCOL_VERSION_MIN,
|
||||
SERVER_PROTOCOL_VERSION_MAX);
|
||||
LATEST_PROTOCOL_VERSION);
|
||||
}
|
||||
|
||||
u16 Server::getProtocolVersionMax()
|
||||
{
|
||||
return g_settings->getBool("strict_protocol_version_checking")
|
||||
? LATEST_PROTOCOL_VERSION
|
||||
: SERVER_PROTOCOL_VERSION_MAX;
|
||||
return LATEST_PROTOCOL_VERSION;
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
@ -43,7 +43,12 @@ read_versions() {
|
||||
# in: $1
|
||||
read_proto_ver() {
|
||||
local ref=$1
|
||||
git show "$ref":src/network/networkprotocol.h | grep -oE 'LATEST_PROTOCOL_VERSION [0-9]+' | tr -dC 0-9
|
||||
local output=$(git show "$ref":src/network/networkprotocol.cpp 2>/dev/null)
|
||||
if [ -z "$output" ]; then
|
||||
# Fallback to previous file (for tags < 5.10.0)
|
||||
output=$(git show "$ref":src/network/networkprotocol.h)
|
||||
fi
|
||||
grep -oE 'LATEST_PROTOCOL_VERSION\s+=?\s*[0-9]+' <<<"$output" | tr -dC 0-9
|
||||
}
|
||||
|
||||
## Prompts for new version
|
||||
|
Loading…
Reference in New Issue
Block a user