1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-15 18:57:08 +00:00

Clean up client and server command sending / tables

This commit is contained in:
sfan5 2024-01-24 18:23:11 +01:00
parent 2b99dabdac
commit 397682a5b0
9 changed files with 79 additions and 119 deletions

View file

@ -19,8 +19,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
#include "clientopcodes.h"
#include "client/client.h"
const static ToClientCommandHandler null_command_handler = {"TOCLIENT_NULL", TOCLIENT_STATE_ALL, &Client::handleCommand_Null};
const static ToClientCommandHandler null_command_handler =
{"TOCLIENT_NULL", TOCLIENT_STATE_ALL, &Client::handleCommand_Null};
const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
{
@ -126,7 +128,7 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
{ "TOCLIENT_SET_LIGHTING", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_SetLighting }, // 0x63,
};
const static ServerCommandFactory null_command_factory = { "TOSERVER_NULL", 0, false };
const static ServerCommandFactory null_command_factory = { nullptr, 0, false };
/*
Channels used for Client -> Server communication
@ -223,5 +225,5 @@ const ServerCommandFactory serverCommandFactoryTable[TOSERVER_NUM_MSG_TYPES] =
{ "TOSERVER_FIRST_SRP", 1, true }, // 0x50
{ "TOSERVER_SRP_BYTES_A", 1, true }, // 0x51
{ "TOSERVER_SRP_BYTES_M", 1, true }, // 0x52
{ "TOSERVER_UPDATE_CLIENT_INFO", 1, true }, // 0x53
{ "TOSERVER_UPDATE_CLIENT_INFO", 2, true }, // 0x53
};

View file

@ -20,10 +20,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
#include "client/client.h"
#include "networkprotocol.h"
class NetworkPacket;
class Client;
enum ToClientConnectionState {
TOCLIENT_STATE_NOT_CONNECTED,

View file

@ -251,7 +251,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
typedef u16 session_t;
enum ToClientCommand
enum ToClientCommand : u16
{
TOCLIENT_HELLO = 0x02,
/*
@ -288,9 +288,7 @@ enum ToClientCommand
u8 (bool) reconnect
*/
TOCLIENT_INIT_LEGACY = 0x10, // Obsolete
TOCLIENT_BLOCKDATA = 0x20, //TODO: Multiple blocks
TOCLIENT_BLOCKDATA = 0x20,
TOCLIENT_ADDNODE = 0x21,
/*
v3s16 position
@ -299,23 +297,15 @@ enum ToClientCommand
*/
TOCLIENT_REMOVENODE = 0x22,
TOCLIENT_PLAYERPOS = 0x23, // Obsolete
TOCLIENT_PLAYERINFO = 0x24, // Obsolete
TOCLIENT_OPT_BLOCK_NOT_FOUND = 0x25, // Obsolete
TOCLIENT_SECTORMETA = 0x26, // Obsolete
TOCLIENT_INVENTORY = 0x27,
/*
[0] u16 command
[2] serialized inventory
*/
TOCLIENT_OBJECTDATA = 0x28, // Obsolete
TOCLIENT_TIME_OF_DAY = 0x29,
/*
u16 time (0-23999)
Added in a later version:
f1000 time_speed
*/
@ -337,8 +327,6 @@ enum ToClientCommand
bool should_be_cached
*/
// (oops, there is some gap here)
TOCLIENT_CHAT_MESSAGE = 0x2F,
/*
u8 version
@ -349,8 +337,6 @@ enum ToClientCommand
wstring message
*/
TOCLIENT_CHAT_MESSAGE_OLD = 0x30, // Obsolete
TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD = 0x31,
/*
u16 count of removed objects
@ -424,26 +410,13 @@ enum ToClientCommand
string url
*/
TOCLIENT_TOOLDEF = 0x39,
/*
u32 length of the next item
serialized ToolDefManager
*/
TOCLIENT_NODEDEF = 0x3a,
/*
u32 length of the next item
serialized NodeDefManager
*/
TOCLIENT_CRAFTITEMDEF = 0x3b,
/*
u32 length of the next item
serialized CraftiItemDefManager
*/
TOCLIENT_ANNOUNCE_MEDIA = 0x3c,
/*
u32 number of files
for each texture {
@ -647,8 +620,6 @@ enum ToClientCommand
*/
TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY = 0x48, // Obsolete
TOCLIENT_HUDADD = 0x49,
/*
u32 id
@ -882,7 +853,7 @@ enum ToClientCommand
TOCLIENT_NUM_MSG_TYPES = 0x64,
};
enum ToServerCommand
enum ToServerCommand : u16
{
TOSERVER_INIT = 0x02,
/*
@ -895,14 +866,10 @@ enum ToServerCommand
std::string player name
*/
TOSERVER_INIT_LEGACY = 0x10, // Obsolete
TOSERVER_INIT2 = 0x11,
/*
Sent as an ACK for TOCLIENT_INIT.
Sent as an ACK for TOCLIENT_AUTH_ACCEPT.
After this, the server can send data.
[0] u16 TOSERVER_INIT2
*/
TOSERVER_MODCHANNEL_JOIN = 0x17,
@ -925,10 +892,6 @@ enum ToServerCommand
std::string message
*/
TOSERVER_GETBLOCK = 0x20, // Obsolete
TOSERVER_ADDNODE = 0x21, // Obsolete
TOSERVER_REMOVENODE = 0x22, // Obsolete
TOSERVER_PLAYERPOS = 0x23,
/*
[0] u16 command
@ -961,12 +924,6 @@ enum ToServerCommand
...
*/
TOSERVER_ADDNODE_FROM_INVENTORY = 0x26, // Obsolete
TOSERVER_CLICK_OBJECT = 0x27, // Obsolete
TOSERVER_GROUND_ACTION = 0x28, // Obsolete
TOSERVER_RELEASE = 0x29, // Obsolete
TOSERVER_SIGNTEXT = 0x30, // Obsolete
TOSERVER_INVENTORY_ACTION = 0x31,
/*
See InventoryAction in inventorymanager.h
@ -978,16 +935,11 @@ enum ToServerCommand
wstring message
*/
TOSERVER_SIGNNODETEXT = 0x33, // Obsolete
TOSERVER_CLICK_ACTIVEOBJECT = 0x34, // Obsolete
TOSERVER_DAMAGE = 0x35,
/*
u8 amount
*/
TOSERVER_PASSWORD_LEGACY = 0x36, // Obsolete
TOSERVER_PLAYERITEM = 0x37,
/*
Sent to change selected item.
@ -1063,8 +1015,6 @@ enum ToServerCommand
u32 token
*/
TOSERVER_BREATH = 0x42, // Obsolete
TOSERVER_CLIENT_READY = 0x43,
/*
u8 major

View file

@ -19,8 +19,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
#include "serveropcodes.h"
#include "server.h"
const static ToServerCommandHandler null_command_handler = { "TOSERVER_NULL", TOSERVER_STATE_ALL, &Server::handleCommand_Null };
const static ToServerCommandHandler null_command_handler =
{ "TOSERVER_NULL", TOSERVER_STATE_ALL, &Server::handleCommand_Null };
const ToServerCommandHandler toServerCommandTable[TOSERVER_NUM_MSG_TYPES] =
{
@ -110,7 +112,7 @@ const ToServerCommandHandler toServerCommandTable[TOSERVER_NUM_MSG_TYPES] =
{ "TOSERVER_UPDATE_CLIENT_INFO", TOSERVER_STATE_INGAME, &Server::handleCommand_UpdateClientInfo }, // 0x53
};
const static ClientCommandFactory null_command_factory = { "TOCLIENT_NULL", 0, false };
const static ClientCommandFactory null_command_factory = { nullptr, 0, false };
/*
Channels used for Server -> Client communication
@ -140,7 +142,7 @@ const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] =
null_command_factory, // 0x0D
null_command_factory, // 0x0E
null_command_factory, // 0x0F
{ "TOCLIENT_INIT", 0, true }, // 0x10
null_command_factory, // 0x10
null_command_factory, // 0x11
null_command_factory, // 0x12
null_command_factory, // 0x13
@ -217,7 +219,7 @@ const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] =
{ "TOCLIENT_SET_SUN", 0, true }, // 0x5a
{ "TOCLIENT_SET_MOON", 0, true }, // 0x5b
{ "TOCLIENT_SET_STARS", 0, true }, // 0x5c
null_command_factory, // 0x5d
{ "TOCLIENT_MOVE_PLAYER_REL", 0, true }, // 0x5d
null_command_factory, // 0x5e
null_command_factory, // 0x5f
{ "TOCLIENT_SRP_BYTES_S_B", 0, true }, // 0x60

View file

@ -20,10 +20,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
#include "server.h"
#include "networkprotocol.h"
class NetworkPacket;
class Server;
enum ToServerConnectionState {
TOSERVER_STATE_NOT_CONNECTED,
@ -33,7 +33,7 @@ enum ToServerConnectionState {
};
struct ToServerCommandHandler
{
const std::string name;
const char *name;
ToServerConnectionState state;
void (Server::*handler)(NetworkPacket* pkt);
};