Permalink
Browse files

Rename CSM flavours to restrictions

& Satisfy LINT
  • Loading branch information...
SmallJoker committed Jun 20, 2018
1 parent 7bdf5ea commit db42542e271a00efd017b192f3a63e04f5b3dbf4
@@ -115,7 +115,7 @@ safe_dig_and_place (Safe digging and placing) bool false
# Enable random user input (only used for testing).
random_input (Random input) bool false

# Continuous forward movement, toggled by autoforward key.
# Continuous forward movement, toggled by autoforward key.
# Press the autoforward key again or the backwards movement to disable.
continuous_forward (Continuous forward) bool false

@@ -1134,13 +1134,12 @@ server_side_occlusion_culling (Server side occlusion culling) bool true
# CHAT_MESSAGES: 2 (disable send_chat_message call client-side)
# READ_ITEMDEFS: 4 (disable get_item_def call client-side)
# READ_NODEDEFS: 8 (disable get_node_def call client-side)
# LOOKUP_NODES_LIMIT: 16 (limits get_node call client-side to csm_flavour_noderange_limit)
# type: int
csm_flavour_limits (Client side modding flavour limits) int 18
# LOOKUP_NODES_LIMIT: 16 (limits get_node call client-side to csm_restriction_noderange)
csm_restriction_flags (Client side modding restrictions) int 18

# If the CSM flavour for node range is enabled, get_node is limited to
# this many nodes from the player.
csm_flavour_noderange_limit (Client side noderange flavour limit) int 8
# If the CSM restriction for node range is enabled, get_node calls are limited
# to this distance from the player to the node.
csm_restriction_noderange (Client side node lookup range restriction) int 8

[*Security]

@@ -1246,7 +1245,7 @@ high_precision_fpu (High-precision FPU) bool true
# Changes the main menu UI:
# - Full: Multple singleplayer worlds, game choice, texture pack chooser, etc.
# - Simple: One singleplayer world, no game or texture pack choosers. May be necessary for smaller screens.
# - Auto: Simple on Android, full on everything else.
# - Auto: Simple on Android, full on everything else.
main_menu_style (Main menu style) enum auto auto,full,simple

# Replaces the default main menu with a custom one.
@@ -130,13 +130,14 @@ void Client::loadMods()
return;
}

// If modding is not enabled or flavour disable it, don't load mods, just builtin
// If modding is not enabled or CSM restrictions disable it
// don't load CSM mods, only builtin
if (!m_modding_enabled) {
warningstream << "Client side mods are disabled by configuration." << std::endl;
return;
}

if (checkCSMFlavourLimit(CSMFlavourLimit::CSM_FL_LOAD_CLIENT_MODS)) {
if (checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_LOAD_CLIENT_MODS)) {
warningstream << "Client side mods are disabled by server." << std::endl;
// If mods loading is disabled and builtin integrity is wrong, disconnect user.
if (!checkBuiltinIntegrity()) {
@@ -1282,16 +1283,16 @@ void Client::removeNode(v3s16 p)

/**
* Helper function for Client Side Modding
* Flavour is applied there, this should not be used for core engine
* CSM restrictions are applied there, this should not be used for core engine
* @param p
* @param is_valid_position
* @return
*/
MapNode Client::getNode(v3s16 p, bool *is_valid_position)
{
if (checkCSMFlavourLimit(CSMFlavourLimit::CSM_FL_LOOKUP_NODES)) {
if (checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_LOOKUP_NODES)) {
v3s16 ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS);
if ((u32) ppos.getDistanceFrom(p) > m_csm_noderange_limit) {
if ((u32) ppos.getDistanceFrom(p) > m_csm_restriction_noderange) {
*is_valid_position = false;
return {};
}
@@ -226,7 +226,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
void handleCommand_ModChannelSignal(NetworkPacket *pkt);
void handleCommand_SrpBytesSandB(NetworkPacket *pkt);
void handleCommand_FormspecPrepend(NetworkPacket *pkt);
void handleCommand_CSMFlavourLimits(NetworkPacket *pkt);
void handleCommand_CSMRestrictionFlags(NetworkPacket *pkt);

void ProcessData(NetworkPacket *pkt);

@@ -261,7 +261,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef

/**
* Helper function for Client Side Modding
* Flavour is applied there, this should not be used for core engine
* CSM restrictions are applied there, this should not be used for core engine
* @param p
* @param is_valid_position
* @return
@@ -412,14 +412,14 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
return m_address_name;
}

inline bool checkCSMFlavourLimit(CSMFlavourLimit flag) const
inline bool checkCSMRestrictionFlag(CSMRestrictionFlags flag) const
{
return m_csm_flavour_limits & flag;
return m_csm_restriction_flags & flag;
}

u32 getCSMNodeRangeLimit() const
{
return m_csm_noderange_limit;
return m_csm_restriction_noderange;
}

inline std::unordered_map<u32, u32> &getHUDTranslationMap()
@@ -600,9 +600,9 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef

bool m_shutdown = false;

// CSM flavour limits byteflag
u64 m_csm_flavour_limits = CSMFlavourLimit::CSM_FL_NONE;
u32 m_csm_noderange_limit = 8;
// CSM restrictions byteflag
u64 m_csm_restriction_flags = CSMRestrictionFlags::CSM_RF_NONE;
u32 m_csm_restriction_noderange = 8;

std::unique_ptr<ModChannelMgr> m_modchannel_mgr;
};
@@ -332,8 +332,8 @@ void set_default_settings(Settings *settings)
settings->setDefault("max_block_send_distance", "9");
settings->setDefault("block_send_optimize_distance", "4");
settings->setDefault("server_side_occlusion_culling", "true");
settings->setDefault("csm_flavour_limits", "18");
settings->setDefault("csm_flavour_noderange_limit", "8");
settings->setDefault("csm_restriction_flags", "18");
settings->setDefault("csm_restriction_noderange", "8");
settings->setDefault("max_clearobjects_extra_loaded_blocks", "4096");
settings->setDefault("time_speed", "72");
settings->setDefault("world_start_time", "5250");
@@ -66,7 +66,7 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
{ "TOCLIENT_INVENTORY", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_Inventory }, // 0x27
null_command_handler,
{ "TOCLIENT_TIME_OF_DAY", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_TimeOfDay }, // 0x29
{ "TOCLIENT_CSM_FLAVOUR_LIMITS", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_CSMFlavourLimits }, // 0x2A
{ "TOCLIENT_CSM_RESTRICTION_FLAGS", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_CSMRestrictionFlags }, // 0x2A
null_command_handler,
null_command_handler,
null_command_handler,
@@ -1333,11 +1333,11 @@ void Client::handleCommand_FormspecPrepend(NetworkPacket *pkt)
*pkt >> player->formspec_prepend;
}

void Client::handleCommand_CSMFlavourLimits(NetworkPacket *pkt)
void Client::handleCommand_CSMRestrictionFlags(NetworkPacket *pkt)
{
*pkt >> m_csm_flavour_limits >> m_csm_noderange_limit;
*pkt >> m_csm_restriction_flags >> m_csm_restriction_noderange;

// Now we have flavours, load mods if it's enabled
// Restrictions were received -> load mods if it's enabled
// Note: this should be moved after mods receptions from server instead
loadMods();
}
@@ -169,7 +169,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
* sender
* type (RAW, NORMAL, ANNOUNCE, SYSTEM)
* content
Add TOCLIENT_CSM_FLAVOUR_LIMITS to define which CSM flavour should be
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
@@ -283,9 +283,9 @@ enum ToClientCommand
f1000 time_speed
*/

TOCLIENT_CSM_FLAVOUR_LIMITS = 0x2A,
TOCLIENT_CSM_RESTRICTION_FLAGS = 0x2A,
/*
u32 CSMFlavourLimits byteflag
u32 CSMRestrictionFlags byteflag
*/

// (oops, there is some gap here)
@@ -928,12 +928,12 @@ enum PlayerListModifer: u8
PLAYER_LIST_REMOVE,
};

enum CSMFlavourLimit : u64 {
CSM_FL_NONE = 0x00000000,
CSM_FL_LOAD_CLIENT_MODS = 0x00000001, // Disable mods provided by clients
CSM_FL_CHAT_MESSAGES = 0x00000002, // Disable chat message sending from CSM
CSM_FL_READ_ITEMDEFS = 0x00000004, // Disable itemdef lookups
CSM_FL_READ_NODEDEFS = 0x00000008, // Disable nodedef lookups
CSM_FL_LOOKUP_NODES = 0x00000010, // Limit node lookups
CSM_FL_ALL = 0xFFFFFFFF,
enum CSMRestrictionFlags : u64 {
CSM_RF_NONE = 0x00000000,
CSM_RF_LOAD_CLIENT_MODS = 0x00000001, // Disable mods provided by clients
CSM_RF_CHAT_MESSAGES = 0x00000002, // Disable chat message sending from CSM
CSM_RF_READ_ITEMDEFS = 0x00000004, // Disable itemdef lookups
CSM_RF_READ_NODEDEFS = 0x00000008, // Disable nodedef lookups
CSM_RF_LOOKUP_NODES = 0x00000010, // Limit node lookups
CSM_RF_ALL = 0xFFFFFFFF,
};
@@ -155,7 +155,7 @@ const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] =
{ "TOCLIENT_INVENTORY", 0, true }, // 0x27
null_command_factory,
{ "TOCLIENT_TIME_OF_DAY", 0, true }, // 0x29
{ "TOCLIENT_CSM_FLAVOUR_LIMITS", 0, true }, // 0x2A
{ "TOCLIENT_CSM_RESTRICTION_FLAGS", 0, true }, // 0x2A
null_command_factory,
null_command_factory,
null_command_factory,
@@ -320,7 +320,7 @@ void Server::handleCommand_Init2(NetworkPacket* pkt)
float time_speed = g_settings->getFloat("time_speed");
SendTimeOfDay(pkt->getPeerId(), time, time_speed);

SendCSMFlavourLimits(pkt->getPeerId());
SendCSMRestrictionFlags(pkt->getPeerId());

// Warnings about protocol version can be issued here
if (getClient(pkt->getPeerId())->net_proto_version < LATEST_PROTOCOL_VERSION) {
@@ -94,8 +94,12 @@ int ModApiClient::l_send_chat_message(lua_State *L)
return 0;

// If server disabled this API, discard
if (getClient(L)->checkCSMFlavourLimit(CSMFlavourLimit::CSM_FL_CHAT_MESSAGES))

// clang-format off
if (getClient(L)->checkCSMRestrictionFlag(
CSMRestrictionFlags::CSM_RF_CHAT_MESSAGES))
return 0;
// clang-format on

std::string message = luaL_checkstring(L, 1);
getClient(L)->sendChatMessage(utf8_to_wide(message));
@@ -290,8 +294,11 @@ int ModApiClient::l_get_item_def(lua_State *L)
IItemDefManager *idef = gdef->idef();
assert(idef);

if (getClient(L)->checkCSMFlavourLimit(CSMFlavourLimit::CSM_FL_READ_ITEMDEFS))
// clang-format off
if (getClient(L)->checkCSMRestrictionFlag(
CSMRestrictionFlags::CSM_RF_READ_ITEMDEFS))
return 0;
// clang-format on

if (!lua_isstring(L, 1))
return 0;
@@ -318,8 +325,11 @@ int ModApiClient::l_get_node_def(lua_State *L)
if (!lua_isstring(L, 1))
return 0;

if (getClient(L)->checkCSMFlavourLimit(CSMFlavourLimit::CSM_FL_READ_NODEDEFS))
// clang-format off
if (getClient(L)->checkCSMRestrictionFlag(
CSMRestrictionFlags::CSM_RF_READ_NODEDEFS))
return 0;
// clang-format on

const std::string &name = lua_tostring(L, 1);
const ContentFeatures &cf = ndef->get(ndef->getId(name));
@@ -770,7 +770,8 @@ int ModApiEnvMod::l_find_node_near(lua_State *L)
#ifndef SERVER
// Client API limitations
if (getClient(L) &&
getClient(L)->checkCSMFlavourLimit(CSMFlavourLimit::CSM_FL_LOOKUP_NODES)) {
getClient(L)->checkCSMRestrictionFlag(
CSMRestrictionFlags::CSM_RF_LOOKUP_NODES)) {
radius = std::max<int>(radius, getClient(L)->getCSMNodeRangeLimit());
}
#endif
@@ -401,8 +401,8 @@ void Server::init()

m_liquid_transform_every = g_settings->getFloat("liquid_update");
m_max_chatmessage_length = g_settings->getU16("chat_message_max_size");
m_csm_flavour_limits = g_settings->getU64("csm_flavour_limits");
m_csm_noderange_limit = g_settings->getU32("csm_flavour_noderange_limit");
m_csm_restriction_flags = g_settings->getU64("csm_restriction_flags");
m_csm_restriction_noderange = g_settings->getU32("csm_restriction_noderange");
}

void Server::start()
@@ -1934,11 +1934,11 @@ void Server::SendActiveObjectMessages(session_t peer_id, const std::string &data
&pkt, reliable);
}

void Server::SendCSMFlavourLimits(session_t peer_id)
void Server::SendCSMRestrictionFlags(session_t peer_id)
{
NetworkPacket pkt(TOCLIENT_CSM_FLAVOUR_LIMITS,
sizeof(m_csm_flavour_limits) + sizeof(m_csm_noderange_limit), peer_id);
pkt << m_csm_flavour_limits << m_csm_noderange_limit;
NetworkPacket pkt(TOCLIENT_CSM_RESTRICTION_FLAGS,
sizeof(m_csm_restriction_flags) + sizeof(m_csm_restriction_noderange), peer_id);
pkt << m_csm_restriction_flags << m_csm_restriction_noderange;
Send(&pkt);
}

@@ -462,7 +462,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
u32 SendActiveObjectRemoveAdd(session_t peer_id, const std::string &datas);
void SendActiveObjectMessages(session_t peer_id, const std::string &datas,
bool reliable = true);
void SendCSMFlavourLimits(session_t peer_id);
void SendCSMRestrictionFlags(session_t peer_id);

/*
Something random
@@ -650,9 +650,9 @@ class Server : public con::PeerHandler, public MapEventReceiver,
std::unordered_map<std::string, ModMetadata *> m_mod_storages;
float m_mod_storage_save_timer = 10.0f;

// CSM flavour limits byteflag
u64 m_csm_flavour_limits = CSMFlavourLimit::CSM_FL_NONE;
u32 m_csm_noderange_limit = 8;
// CSM restrictions byteflag
u64 m_csm_restriction_flags = CSMRestrictionFlags::CSM_RF_NONE;
u32 m_csm_restriction_noderange = 8;

// ModChannel manager
std::unique_ptr<ModChannelMgr> m_modchannel_mgr;

0 comments on commit db42542

Please sign in to comment.