summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorANAND <ClobberXD@gmail.com>2019-08-04 10:23:59 +0530
committerSmallJoker <mk939@ymail.com>2019-08-07 19:21:14 +0200
commite788ee283fe7eb8151898916f72c2cf803255fa4 (patch)
tree29e03adb9208c5371f969dd2c12535f2fe490e72 /src/network
parente462a9a5ef46776d974203bb44e0b89e8c980b29 (diff)
downloadminetest-e788ee283fe7eb8151898916f72c2cf803255fa4.tar.gz
minetest-e788ee283fe7eb8151898916f72c2cf803255fa4.tar.bz2
minetest-e788ee283fe7eb8151898916f72c2cf803255fa4.zip
Client::Interact: Use InteractAction enum instead of numeric constants
This replaces the magic numbers used as interaction modes both client-side and server-side, primarily for the sake of ease-of-readability.
Diffstat (limited to 'src/network')
-rw-r--r--src/network/networkprotocol.h20
-rw-r--r--src/network/serverpackethandler.cpp56
2 files changed, 41 insertions, 35 deletions
diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h
index 85436068f..0ab11ee7e 100644
--- a/src/network/networkprotocol.h
+++ b/src/network/networkprotocol.h
@@ -954,10 +954,20 @@ enum CSMRestrictionFlags : u64 {
// When those are complete, this should return to only being a restriction on the
// loading of client mods.
CSM_RF_LOAD_CLIENT_MODS = 0x00000001, // Don't load client-provided mods or 'builtin'
- 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_READ_PLAYERINFO = 0x00000020, // Disable player info lookups
+ 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_READ_PLAYERINFO = 0x00000020, // Disable player info lookups
CSM_RF_ALL = 0xFFFFFFFF,
};
+
+enum InteractAction : u8
+{
+ INTERACT_START_DIGGING, // 0: start digging (from undersurface) or use
+ INTERACT_STOP_DIGGING, // 1: stop digging (all parameters ignored)
+ INTERACT_DIGGING_COMPLETED, // 2: digging completed
+ INTERACT_PLACE, // 3: place block or item (to abovesurface)
+ INTERACT_USE, // 4: use item
+ INTERACT_ACTIVATE // 5: rightclick air ("activate")
+};
diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp
index 0ce785169..30ae5fc56 100644
--- a/src/network/serverpackethandler.cpp
+++ b/src/network/serverpackethandler.cpp
@@ -974,7 +974,7 @@ bool Server::checkInteractDistance(RemotePlayer *player, const f32 d, const std:
return true;
}
-void Server::handleCommand_Interact(NetworkPacket* pkt)
+void Server::handleCommand_Interact(NetworkPacket *pkt)
{
/*
[0] u16 command
@@ -983,18 +983,14 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
[5] u32 length of the next item (plen)
[9] serialized PointedThing
[9 + plen] player position information
- actions:
- 0: start digging (from undersurface) or use
- 1: stop digging (all parameters ignored)
- 2: digging completed
- 3: place block or item (to abovesurface)
- 4: use item
- 5: rightclick air ("activate")
*/
- u8 action;
+
+ InteractAction action;
u16 item_i;
- *pkt >> action;
+
+ *pkt >> (u8 &)action;
*pkt >> item_i;
+
std::istringstream tmp_is(pkt->readLongString(), std::ios::binary);
PointedThing pointed;
pointed.deSerialize(tmp_is);
@@ -1073,18 +1069,18 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
Make sure the player is allowed to do it
*/
if (!checkPriv(player->getName(), "interact")) {
- actionstream<<player->getName()<<" attempted to interact with "
- <<pointed.dump()<<" without 'interact' privilege"
- <<std::endl;
+ actionstream << player->getName() << " attempted to interact with " <<
+ pointed.dump() << " without 'interact' privilege" << std::endl;
+
// Re-send block to revert change on client-side
RemoteClient *client = getClient(pkt->getPeerId());
// Digging completed -> under
- if (action == 2) {
+ if (action == INTERACT_DIGGING_COMPLETED) {
v3s16 blockpos = getNodeBlockPos(floatToInt(pointed_pos_under, BS));
client->SetBlockNotSent(blockpos);
}
// Placement -> above
- else if (action == 3) {
+ else if (action == INTERACT_PLACE) {
v3s16 blockpos = getNodeBlockPos(floatToInt(pointed_pos_above, BS));
client->SetBlockNotSent(blockpos);
}
@@ -1098,10 +1094,10 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
static thread_local const bool enable_anticheat =
!g_settings->getBool("disable_anticheat");
- if ((action == 0 || action == 2 || action == 3 || action == 4) &&
+ if ((action == INTERACT_START_DIGGING || action == INTERACT_DIGGING_COMPLETED ||
+ action == INTERACT_PLACE || action == INTERACT_USE) &&
enable_anticheat && !isSingleplayer()) {
- float d = playersao->getEyePosition()
- .getDistanceFrom(pointed_pos_under);
+ float d = playersao->getEyePosition().getDistanceFrom(pointed_pos_under);
if (!checkInteractDistance(player, d, pointed.dump())) {
// Re-send block to revert change on client-side
@@ -1121,7 +1117,7 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
/*
0: start digging or punch object
*/
- if (action == 0) {
+ if (action == INTERACT_START_DIGGING) {
if (pointed.type == POINTEDTHING_NODE) {
MapNode n(CONTENT_IGNORE);
bool pos_ok;
@@ -1174,18 +1170,18 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, pointed_object));
}
- } // action == 0
+ } // action == INTERACT_START_DIGGING
/*
1: stop digging
*/
- else if (action == 1) {
- } // action == 1
+ else if (action == INTERACT_STOP_DIGGING) {
+ } // action == INTERACT_STOP_DIGGING
/*
2: Digging completed
*/
- else if (action == 2) {
+ else if (action == INTERACT_DIGGING_COMPLETED) {
// Only digging of nodes
if (pointed.type == POINTEDTHING_NODE) {
bool pos_ok;
@@ -1281,12 +1277,12 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
client->ResendBlockIfOnWire(blockpos);
}
}
- } // action == 2
+ } // action == INTERACT_DIGGING_COMPLETED
/*
3: place block or right-click object
*/
- else if (action == 3) {
+ else if (action == INTERACT_PLACE) {
ItemStack item = playersao->getWieldedItem();
// Reset build time counter
@@ -1335,12 +1331,12 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
client->ResendBlockIfOnWire(blockpos2);
}
}
- } // action == 3
+ } // action == INTERACT_PLACE
/*
4: use
*/
- else if (action == 4) {
+ else if (action == INTERACT_USE) {
ItemStack item = playersao->getWieldedItem();
actionstream << player->getName() << " uses " << item.name
@@ -1354,12 +1350,12 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
}
}
- } // action == 4
+ } // action == INTERACT_USE
/*
5: rightclick air
*/
- else if (action == 5) {
+ else if (action == INTERACT_ACTIVATE) {
ItemStack item = playersao->getWieldedItem();
actionstream << player->getName() << " activates "
@@ -1371,7 +1367,7 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
SendInventory(playersao);
}
}
- }
+ } // action == INTERACT_ACTIVATE
/*