diff options
Diffstat (limited to 'src/network/serverpackethandler.cpp')
-rw-r--r-- | src/network/serverpackethandler.cpp | 181 |
1 files changed, 71 insertions, 110 deletions
diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index f756d80ef..1bcb78a8a 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -103,7 +103,7 @@ void Server::handleCommand_Init(NetworkPacket* pkt) // Use the highest version supported by both u8 depl_serial_v = std::min(client_max, our_max); // If it's lower than the lowest supported, give up. - if (depl_serial_v < SER_FMT_VER_LOWEST) + if (depl_serial_v < SER_FMT_VER_LOWEST_READ) depl_serial_v = SER_FMT_VER_INVALID; if (depl_serial_v == SER_FMT_VER_INVALID) { @@ -261,9 +261,9 @@ void Server::handleCommand_Init(NetworkPacket* pkt) auth_mechs |= AUTH_MECHANISM_FIRST_SRP; } else { // Take care of default passwords. - client->enc_pwd = getSRPVerifier(playerName, default_password); + client->enc_pwd = get_encoded_srp_verifier(playerName, default_password); auth_mechs |= AUTH_MECHANISM_SRP; - // Create auth, but only on successful login + // Allocate player in db, but only on successful login. client->create_player_on_auth_success = true; } } @@ -347,7 +347,7 @@ void Server::handleCommand_Init_Legacy(NetworkPacket* pkt) // Use the highest version supported by both int deployed = std::min(client_max, our_max); // If it's lower than the lowest supported, give up. - if (deployed < SER_FMT_VER_LOWEST) + if (deployed < SER_FMT_VER_LOWEST_READ) deployed = SER_FMT_VER_INVALID; if (deployed == SER_FMT_VER_INVALID) { @@ -549,7 +549,7 @@ void Server::handleCommand_Init_Legacy(NetworkPacket* pkt) std::string raw_default_password = g_settings->get("default_password"); std::string initial_password = - translatePassword(playername, raw_default_password); + translate_password(playername, raw_default_password); // If default_password is empty, allow any initial password if (raw_default_password.length() == 0) @@ -568,8 +568,10 @@ void Server::handleCommand_Init_Legacy(NetworkPacket* pkt) } if (given_password != checkpwd) { - actionstream << "Server: " << playername << " supplied wrong password" - << std::endl; + actionstream << "Server: User " << playername + << " at " << addr_s + << " supplied wrong password (auth mechanism: legacy)." + << std::endl; DenyAccess_Legacy(pkt->getPeerId(), L"Wrong password"); return; } @@ -760,14 +762,14 @@ void Server::handleCommand_GotBlocks(NetworkPacket* pkt) RemoteClient *client = getClient(pkt->getPeerId()); - for (u16 i = 0; i < count; i++) { - if ((s16)pkt->getSize() < 1 + (i + 1) * 6) - throw con::InvalidIncomingDataException + if ((s16)pkt->getSize() < 1 + (int)count * 6) { + throw con::InvalidIncomingDataException ("GOTBLOCKS length is too short"); - v3s16 p; + } + for (u16 i = 0; i < count; i++) { + v3s16 p; *pkt >> p; - client->GotBlock(p); } } @@ -863,13 +865,14 @@ void Server::handleCommand_DeletedBlocks(NetworkPacket* pkt) RemoteClient *client = getClient(pkt->getPeerId()); - for (u16 i = 0; i < count; i++) { - if ((s16)pkt->getSize() < 1 + (i + 1) * 6) - throw con::InvalidIncomingDataException + if ((s16)pkt->getSize() < 1 + (int)count * 6) { + throw con::InvalidIncomingDataException ("DELETEDBLOCKS length is too short"); + } + + for (u16 i = 0; i < count; i++) { v3s16 p; *pkt >> p; - client->SetBlockNotSent(p); } } @@ -1057,69 +1060,15 @@ void Server::handleCommand_ChatMessage(NetworkPacket* pkt) return; } - // If something goes wrong, this player is to blame - RollbackScopeActor rollback_scope(m_rollback, - std::string("player:")+player->getName()); - // Get player name of this client - std::wstring name = narrow_to_wide(player->getName()); - - // Run script hook - bool ate = m_script->on_chat_message(player->getName(), - wide_to_narrow(message)); - // If script ate the message, don't proceed - if (ate) - return; - - // Line to send to players - std::wstring line; - // Whether to send to the player that sent the line - bool send_to_sender_only = false; - - // Commands are implemented in Lua, so only catch invalid - // commands that were not "eaten" and send an error back - if (message[0] == L'/') { - message = message.substr(1); - send_to_sender_only = true; - if (message.length() == 0) - line += L"-!- Empty command"; - else - line += L"-!- Invalid command: " + str_split(message, L' ')[0]; - } - else { - if (checkPriv(player->getName(), "shout")) { - line += L"<"; - line += name; - line += L"> "; - line += message; - } else { - line += L"-!- You don't have permission to shout."; - send_to_sender_only = true; - } - } + std::string name = player->getName(); + std::wstring wname = narrow_to_wide(name); - if (line != L"") - { - /* - Send the message to sender - */ - if (send_to_sender_only) { - SendChatMessage(pkt->getPeerId(), line); - } - /* - Send the message to others - */ - else { - actionstream << "CHAT: " << wide_to_narrow(line)<<std::endl; - - std::vector<u16> clients = m_clients.getClientIDs(); - - for (std::vector<u16>::iterator i = clients.begin(); - i != clients.end(); ++i) { - if (*i != pkt->getPeerId()) - SendChatMessage(*i, line); - } - } + std::wstring answer_to_sender = handleChat(name, wname, message, + true, pkt->getPeerId()); + if (!answer_to_sender.empty()) { + // Send the answer to sender + SendChatMessage(pkt->getPeerId(), answer_to_sender); } } @@ -1410,7 +1359,9 @@ void Server::handleCommand_Interact(NetworkPacket* pkt) Check that target is reasonably close (only when digging or placing things) */ - if (action == 0 || action == 2 || action == 3) { + static const bool enable_anticheat = !g_settings->getBool("disable_anticheat"); + if ((action == 0 || action == 2 || action == 3) && + (enable_anticheat && !isSingleplayer())) { float d = player_pos.getDistanceFrom(pointed_pos_under); float max_d = BS * 14; // Just some large enough value if (d > max_d) { @@ -1467,21 +1418,22 @@ void Server::handleCommand_Interact(NetworkPacket* pkt) NOTE: This can be used in the future to check if somebody is cheating, by checking the timing. */ + MapNode n(CONTENT_IGNORE); bool pos_ok; - n = m_env->getMap().getNodeNoEx(p_under, &pos_ok); - if (pos_ok) - n = m_env->getMap().getNodeNoEx(p_under, &pos_ok); + n = m_env->getMap().getNodeNoEx(p_under, &pos_ok); if (!pos_ok) { infostream << "Server: Not punching: Node not found." << " Adding block to emerge queue." << std::endl; - m_emerge->enqueueBlockEmerge(pkt->getPeerId(), getNodeBlockPos(p_above), false); + m_emerge->enqueueBlockEmerge(pkt->getPeerId(), + getNodeBlockPos(p_above), false); } if (n.getContent() != CONTENT_IGNORE) m_script->node_on_punch(p_under, n, playersao, pointed); + // Cheat prevention playersao->noCheatDigStart(p_under); } @@ -1538,14 +1490,15 @@ void Server::handleCommand_Interact(NetworkPacket* pkt) MapNode n = m_env->getMap().getNodeNoEx(p_under, &pos_ok); if (!pos_ok) { infostream << "Server: Not finishing digging: Node not found." - << " Adding block to emerge queue." - << std::endl; - m_emerge->enqueueBlockEmerge(pkt->getPeerId(), getNodeBlockPos(p_above), false); + << " Adding block to emerge queue." + << std::endl; + m_emerge->enqueueBlockEmerge(pkt->getPeerId(), + getNodeBlockPos(p_above), false); } /* Cheat prevention */ bool is_valid_dig = true; - if (!isSingleplayer() && !g_settings->getBool("disable_anticheat")) { + if (enable_anticheat && !isSingleplayer()) { v3s16 nocheat_p = playersao->getNoCheatDigPos(); float nocheat_t = playersao->getNoCheatDigTime(); playersao->noCheatDigEnd(); @@ -1703,13 +1656,30 @@ void Server::handleCommand_Interact(NetworkPacket* pkt) } } // action == 4 + + /* + 5: rightclick air + */ + else if (action == 5) { + ItemStack item = playersao->getWieldedItem(); + + actionstream << player->getName() << " activates " + << item.name << std::endl; + + if (m_script->item_OnSecondaryUse( + item, playersao)) { + if( playersao->setWieldedItem(item)) { + SendInventory(playersao); + } + } + } /* Catch invalid actions */ else { - infostream << "WARNING: Server: Invalid action " + warningstream << "Server: Invalid action " << action << std::endl; } } @@ -1838,7 +1808,7 @@ void Server::handleCommand_FirstSrp(NetworkPacket* pkt) *pkt >> salt >> verification_key >> is_empty; verbosestream << "Server: Got TOSERVER_FIRST_SRP from " << addr_s - << ", with is_empty= " << is_empty << std::endl; + << ", with is_empty=" << (is_empty == 1) << std::endl; // Either this packet is sent because the user is new or to change the password if (cstate == CS_HelloSent) { @@ -1861,7 +1831,7 @@ void Server::handleCommand_FirstSrp(NetworkPacket* pkt) std::string initial_ver_key; - initial_ver_key = encodeSRPVerifier(verification_key, salt); + initial_ver_key = encode_srp_verifier(verification_key, salt); m_script->createAuth(playername, initial_ver_key); acceptAuth(pkt->getPeerId(), false); @@ -1873,7 +1843,7 @@ void Server::handleCommand_FirstSrp(NetworkPacket* pkt) return; } m_clients.event(pkt->getPeerId(), CSE_SudoLeave); - std::string pw_db_field = encodeSRPVerifier(verification_key, salt); + std::string pw_db_field = encode_srp_verifier(verification_key, salt); bool success = m_script->setPassword(playername, pw_db_field); if (success) { actionstream << playername << " changes password" << std::endl; @@ -1947,22 +1917,14 @@ void Server::handleCommand_SrpBytesA(NetworkPacket* pkt) client->chosen_mech = chosen; - std::string bytes_s; - std::string bytes_v; + std::string salt; + std::string verifier; if (based_on == 0) { - char *p_bytes_s = 0; - size_t len_s = 0; - char *p_bytes_v = 0; - size_t len_v = 0; - getSRPVerifier(client->getName(), client->enc_pwd, - &p_bytes_s, &len_s, - &p_bytes_v, &len_v); - bytes_s = std::string(p_bytes_s, len_s); - bytes_v = std::string(p_bytes_v, len_v); - free(p_bytes_s); - free(p_bytes_v); - } else if (!decodeSRPVerifier(client->enc_pwd, &bytes_s, &bytes_v)) { + + generate_srp_verifier_and_salt(client->getName(), client->enc_pwd, + &verifier, &salt); + } else if (!decode_srp_verifier_and_salt(client->enc_pwd, &verifier, &salt)) { // Non-base64 errors should have been catched in the init handler actionstream << "Server: User " << client->getName() << " tried to log in, but srp verifier field" @@ -1976,8 +1938,8 @@ void Server::handleCommand_SrpBytesA(NetworkPacket* pkt) client->auth_data = srp_verifier_new(SRP_SHA256, SRP_NG_2048, client->getName().c_str(), - (const unsigned char *) bytes_s.c_str(), bytes_s.size(), - (const unsigned char *) bytes_v.c_str(), bytes_v.size(), + (const unsigned char *) salt.c_str(), salt.size(), + (const unsigned char *) verifier.c_str(), verifier.size(), (const unsigned char *) bytes_A.c_str(), bytes_A.size(), NULL, 0, (unsigned char **) &bytes_B, &len_B, NULL, NULL); @@ -1996,7 +1958,7 @@ void Server::handleCommand_SrpBytesA(NetworkPacket* pkt) } NetworkPacket resp_pkt(TOCLIENT_SRP_BYTES_S_B, 0, pkt->getPeerId()); - resp_pkt << bytes_s << std::string(bytes_B, len_B); + resp_pkt << salt << std::string(bytes_B, len_B); Send(&resp_pkt); } @@ -2060,9 +2022,8 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt) } else { actionstream << "Server: User " << client->getName() << " at " << getPeerAddress(pkt->getPeerId()).serializeString() - << " supplied wrong (SRP) password from address " - << getPeerAddress(pkt->getPeerId()).serializeString() - << "." << std::endl; + << " supplied wrong password (auth mechanism: SRP)." + << std::endl; DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_WRONG_PASSWORD); return; } |