#include "client.h"
#include "util/base64.h"
+#include "chatmessage.h"
#include "clientmedia.h"
#include "log.h"
#include "map.h"
#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)
{
m_chosen_auth_mech = AUTH_MECHANISM_NONE;
m_access_denied = true;
m_access_denied_reason = "Unknown";
- m_con.Disconnect();
+ m_con->Disconnect();
}
}
<< m_recommended_send_interval<<std::endl;
// Reply to server
- NetworkPacket resp_pkt(TOSERVER_INIT2, 0);
+ std::string lang = gettext("LANG_CODE");
+ if (lang == "LANG_CODE")
+ lang = "";
+
+ NetworkPacket resp_pkt(TOSERVER_INIT2, sizeof(u16) + lang.size());
+ resp_pkt << lang;
Send(&resp_pkt);
m_state = LC_Init;
}
void Client::handleCommand_DenySudoMode(NetworkPacket* pkt)
{
- pushToChatQueue(L"Password change denied. Password NOT changed.");
+ ChatMessage *chatMessage = new ChatMessage(CHATMESSAGE_TYPE_SYSTEM,
+ L"Password change denied. Password NOT changed.");
+ pushToChatQueue(chatMessage);
// reset everything and be sad
deleteAuthData();
}
if (denyCode == SERVER_ACCESSDENIED_SHUTDOWN ||
denyCode == SERVER_ACCESSDENIED_CRASH) {
*pkt >> m_access_denied_reason;
- if (m_access_denied_reason == "") {
+ if (m_access_denied_reason.empty()) {
m_access_denied_reason = accessDeniedStrings[denyCode];
}
u8 reconnect;
// 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";
}
}
<< " dr=" << dr << std::endl;
}
-void Client::handleCommand_ChatMessage(NetworkPacket* pkt)
+void Client::handleCommand_ChatMessageOld(NetworkPacket *pkt)
{
/*
u16 command
}
// 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;
}
}
Strfnd sf(str);
while(!sf.at_end()) {
std::string baseurl = trim(sf.next(","));
- if (baseurl != "")
+ if (!baseurl.empty())
m_media_downloader->addRemoteServer(baseurl);
}
}
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";
[23 + len] u16 object_id
[25 + len] bool loop
[26 + len] f32 fade
+ [30 + len] f32 pitch
*/
s32 server_id;
v3f pos;
u16 object_id;
bool loop;
- float fade = 0;
+ float fade = 0.0f;
+ float pitch = 1.0f;
*pkt >> server_id >> name >> gain >> type >> pos >> object_id >> loop;
try {
*pkt >> fade;
+ *pkt >> pitch;
} catch (PacketError &e) {};
// Start playing
int client_id = -1;
switch(type) {
case 0: // local
- client_id = m_sound->playSound(name, loop, gain, fade);
+ client_id = m_sound->playSound(name, loop, gain, fade, pitch);
break;
case 1: // positional
- client_id = m_sound->playSoundAt(name, loop, gain, pos);
+ client_id = m_sound->playSoundAt(name, loop, gain, pos, pitch);
break;
case 2:
{ // object
ClientActiveObject *cao = m_env.getActiveObject(object_id);
if (cao)
pos = cao->getPosition();
- client_id = m_sound->playSoundAt(name, loop, gain, pos);
+ client_id = m_sound->playSoundAt(name, loop, gain, pos, pitch);
// TODO: Set up sound to move with object
break;
}
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)
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;
}
}
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;
+}