X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fnetwork%2Fclientpackethandler.cpp;h=f42f9219b78b6d8bf3249e8ca23492c25fd5992d;hb=3cea7a349ac55df93b3eac1bf40365e00e472480;hp=caaf24d80f23b8296e93d80eebbbafafa38bbbf8;hpb=ff73c7a5da6ab8ac0bb678ebf25b83e805397029;p=minetest.git diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index caaf24d80..f42f9219b 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client.h" #include "util/base64.h" +#include "chatmessage.h" #include "clientmedia.h" #include "log.h" #include "map.h" @@ -30,10 +31,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "server.h" #include "util/strfnd.h" #include "network/clientopcodes.h" +#include "network/connection.h" #include "script/scripting_client.h" #include "util/serialize.h" #include "util/srp.h" #include "tileanimation.h" +#include "gettext.h" void Client::handleCommand_Deprecated(NetworkPacket* pkt) { @@ -96,7 +99,7 @@ void Client::handleCommand_Hello(NetworkPacket* pkt) m_chosen_auth_mech = AUTH_MECHANISM_NONE; m_access_denied = true; m_access_denied_reason = "Unknown"; - m_con.Disconnect(); + m_con->Disconnect(); } } @@ -121,7 +124,12 @@ void Client::handleCommand_AuthAccept(NetworkPacket* pkt) << m_recommended_send_interval<> m_access_denied_reason; - if (m_access_denied_reason == "") { + if (m_access_denied_reason.empty()) { m_access_denied_reason = accessDeniedStrings[denyCode]; } u8 reconnect; @@ -234,7 +244,7 @@ void Client::handleCommand_AccessDenied(NetworkPacket* pkt) // Until then (which may be never), this is outside // of the defined protocol. *pkt >> m_access_denied_reason; - if (m_access_denied_reason == "") { + if (m_access_denied_reason.empty()) { m_access_denied_reason = "Unknown"; } } @@ -395,7 +405,7 @@ void Client::handleCommand_TimeOfDay(NetworkPacket* pkt) << " dr=" << dr << std::endl; } -void Client::handleCommand_ChatMessage(NetworkPacket* pkt) +void Client::handleCommand_ChatMessageOld(NetworkPacket *pkt) { /* u16 command @@ -413,8 +423,43 @@ void Client::handleCommand_ChatMessage(NetworkPacket* pkt) } // If chat message not consummed by client lua API + // @TODO send this to CSM using ChatMessage object if (!moddingEnabled() || !m_script->on_receiving_message(wide_to_utf8(message))) { - pushToChatQueue(message); + pushToChatQueue(new ChatMessage(message)); + } +} + +void Client::handleCommand_ChatMessage(NetworkPacket *pkt) +{ + /* + u8 version + u8 message_type + u16 sendername length + wstring sendername + u16 length + wstring message + */ + + ChatMessage *chatMessage = new ChatMessage(); + u8 version, message_type; + *pkt >> version >> message_type; + + if (version != 1 || message_type >= CHATMESSAGE_TYPE_MAX) { + delete chatMessage; + return; + } + + *pkt >> chatMessage->sender >> chatMessage->message >> chatMessage->timestamp; + + chatMessage->type = (ChatMessageType) message_type; + + // @TODO send this to CSM using ChatMessage object + if (!moddingEnabled() || !m_script->on_receiving_message( + wide_to_utf8(chatMessage->message))) { + pushToChatQueue(chatMessage); + } else { + // Message was consumed by CSM and should not handled by client, destroying + delete chatMessage; } } @@ -645,7 +690,7 @@ void Client::handleCommand_AnnounceMedia(NetworkPacket* pkt) Strfnd sf(str); while(!sf.at_end()) { std::string baseurl = trim(sf.next(",")); - if (baseurl != "") + if (!baseurl.empty()) m_media_downloader->addRemoteServer(baseurl); } } @@ -683,8 +728,7 @@ void Client::handleCommand_Media(NetworkPacket* pkt) if (num_files == 0) return; - if (m_media_downloader == NULL || - !m_media_downloader->isStarted()) { + if (!m_media_downloader || !m_media_downloader->isStarted()) { const char *problem = m_media_downloader ? "media has not been requested" : "all media has been received already"; @@ -1146,18 +1190,23 @@ void Client::handleCommand_HudSetFlags(NetworkPacket* pkt) assert(player != NULL); bool was_minimap_visible = player->hud_flags & HUD_FLAG_MINIMAP_VISIBLE; + bool was_minimap_radar_visible = player->hud_flags & HUD_FLAG_MINIMAP_RADAR_VISIBLE; player->hud_flags &= ~mask; player->hud_flags |= flags; m_minimap_disabled_by_server = !(player->hud_flags & HUD_FLAG_MINIMAP_VISIBLE); + bool m_minimap_radar_disabled_by_server = !(player->hud_flags & HUD_FLAG_MINIMAP_RADAR_VISIBLE); // Hide minimap if it has been disabled by the server - if (m_minimap && m_minimap_disabled_by_server && was_minimap_visible) { + if (m_minimap && m_minimap_disabled_by_server && was_minimap_visible) // defers a minimap update, therefore only call it if really // needed, by checking that minimap was visible before m_minimap->setMinimapMode(MINIMAP_MODE_OFF); - } + + // Switch to surface mode if radar disabled by server + if (m_minimap && m_minimap_radar_disabled_by_server && was_minimap_radar_visible) + m_minimap->setMinimapMode(MINIMAP_MODE_SURFACEx1); } void Client::handleCommand_HudSetParam(NetworkPacket* pkt) @@ -1175,9 +1224,21 @@ void Client::handleCommand_HudSetParam(NetworkPacket* pkt) player->hud_hotbar_itemcount = hotbar_itemcount; } else if (param == HUD_PARAM_HOTBAR_IMAGE) { + // If value not empty verify image exists in texture source + if (!value.empty() && !getTextureSource()->isKnownSourceImage(value)) { + errorstream << "Server sent wrong Hud hotbar image (sent value: '" + << value << "')" << std::endl; + return; + } player->hotbar_image = value; } else if (param == HUD_PARAM_HOTBAR_SELECTED_IMAGE) { + // If value not empty verify image exists in texture source + if (!value.empty() && !getTextureSource()->isKnownSourceImage(value)) { + errorstream << "Server sent wrong Hud hotbar selected image (sent value: '" + << value << "')" << std::endl; + return; + } player->hotbar_selected_image = value; } } @@ -1327,3 +1388,8 @@ void Client::handleCommand_SrpBytesSandB(NetworkPacket* pkt) resp_pkt << std::string(bytes_M, len_M); Send(&resp_pkt); } + +void Client::handleCommand_CSMFlavourLimits(NetworkPacket *pkt) +{ + *pkt >> m_csm_flavour_limits >> m_csm_noderange_limit; +}