This replaces the magic numbers used as interaction modes both client-side and server-side, primarily for the sake of ease-of-readability.
*pkt << fov << wanted_range;
}
-void Client::interact(u8 action, const PointedThing& pointed)
+void Client::interact(InteractAction action, const PointedThing& pointed)
{
if(m_state != LC_Ready) {
errorstream << "Client::interact() "
[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: perform secondary action of item
*/
NetworkPacket pkt(TOSERVER_INTERACT, 1 + 2 + 0);
- pkt << action;
+ pkt << (u8)action;
pkt << myplayer->getWieldIndex();
std::ostringstream tmp_os(std::ios::binary);
}
void Client::sendChangePassword(const std::string &oldpassword,
- const std::string &newpassword)
+ const std::string &newpassword)
{
LocalPlayer *player = m_env.getLocalPlayer();
if (player == NULL)
void Send(NetworkPacket* pkt);
- void interact(u8 action, const PointedThing& pointed);
+ void interact(InteractAction action, const PointedThing &pointed);
void sendNodemetaFields(v3s16 p, const std::string &formname,
const StringMap &fields);
shootline = core::line3d<f32>(player_eye_position,
player_eye_position + camera_direction * BS * d);
} else {
- // prevent player pointing anything in front-view
+ // prevent player pointing anything in front-view
shootline = core::line3d<f32>(camera_position, camera_position);
}
if (runData.digging) {
if (input->getLeftReleased()) {
infostream << "Left button released"
- << " (stopped digging)" << std::endl;
+ << " (stopped digging)" << std::endl;
runData.digging = false;
} else if (pointed != runData.pointed_old) {
if (pointed.type == POINTEDTHING_NODE
// Don't reset.
} else {
infostream << "Pointing away from node"
- << " (stopped digging)" << std::endl;
+ << " (stopped digging)" << std::endl;
runData.digging = false;
hud->updateSelectionMesh(camera_offset);
}
}
if (!runData.digging) {
- client->interact(1, runData.pointed_old);
+ client->interact(INTERACT_STOP_DIGGING, runData.pointed_old);
client->setCrack(-1, v3s16(0, 0, 0));
runData.dig_time = 0.0;
}
if (selected_def.usable && input->getLeftState()) {
if (input->getLeftClicked() && (!client->moddingEnabled()
|| !client->getScript()->on_item_use(selected_item, pointed)))
- client->interact(4, pointed);
+ client->interact(INTERACT_USE, pointed);
} else if (pointed.type == POINTEDTHING_NODE) {
handlePointingAtNode(pointed, selected_item, hand_item, dtime);
} else if (pointed.type == POINTEDTHING_OBJECT) {
infostream << "Right Clicked in Air" << std::endl;
PointedThing fauxPointed;
fauxPointed.type = POINTEDTHING_NOTHING;
- client->interact(5, fauxPointed);
+ client->interact(INTERACT_ACTIVATE, fauxPointed);
}
&& !isKeyDown(KeyType::SNEAK)) {
// Report right click to server
if (nodedef_manager->get(map.getNodeNoEx(nodepos)).rightclickable) {
- client->interact(3, pointed);
+ client->interact(INTERACT_PLACE, pointed);
}
infostream << "Launching custom inventory view" << std::endl;
if (placed) {
// Report to server
- client->interact(3, pointed);
+ client->interact(INTERACT_PLACE, pointed);
// Read the sound
soundmaker->m_player_rightpunch_sound =
def.sound_place;
if (def.node_placement_prediction.empty() ||
nodedef_manager->get(map.getNodeNoEx(nodepos)).rightclickable) {
- client->interact(3, pointed); // Report to server
+ client->interact(INTERACT_PLACE, pointed); // Report to server
} else {
soundmaker->m_player_rightpunch_sound =
def.sound_place_failed;
runData.time_from_last_punch = 0;
if (!disable_send)
- client->interact(0, pointed);
+ client->interact(INTERACT_START_DIGGING, pointed);
}
} else if (input->getRightClicked()) {
infostream << "Right-clicked object" << std::endl;
- client->interact(3, pointed); // place
+ client->interact(INTERACT_PLACE, pointed); // place
}
}
runData.dig_instantly = runData.dig_time_complete == 0;
if (client->moddingEnabled() && client->getScript()->on_punchnode(nodepos, n))
return;
- client->interact(0, pointed);
+ client->interact(INTERACT_START_DIGGING, pointed);
runData.digging = true;
runData.ldown_for_dig = true;
}
MapNode wasnode = map.getNodeNoEx(nodepos, &is_valid_position);
if (is_valid_position) {
if (client->moddingEnabled() &&
- client->getScript()->on_dignode(nodepos, wasnode)) {
+ client->getScript()->on_dignode(nodepos, wasnode)) {
return;
}
// implicit else: no prediction
}
- client->interact(2, pointed);
+ client->interact(INTERACT_DIGGING_COMPLETED, pointed);
if (m_cache_enable_particles) {
const ContentFeatures &features =
// 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")
+};
return true;
}
-void Server::handleCommand_Interact(NetworkPacket* pkt)
+void Server::handleCommand_Interact(NetworkPacket *pkt)
{
/*
[0] u16 command
[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);
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);
}
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
/*
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;
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;
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
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
}
}
- } // 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 "
SendInventory(playersao);
}
}
- }
+ } // action == INTERACT_ACTIVATE
/*