From 7cf5cb58865bc5f3951a6f4e40cf892ede96fc5a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 5 Jan 2012 18:35:21 +0300 Subject: Update copyrights year. --- src/utils/stringutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utils/stringutils.cpp') diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 39f14a646..642ba0df2 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2007-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * -- cgit v1.2.3-70-g09d2 From 72d496fb243f622c9a582d593b0d51ec057acd37 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 8 Jan 2012 20:41:48 +0300 Subject: Validate update host. --- src/client.cpp | 4 ++++ src/gui/logindialog.cpp | 12 ++++++++++-- src/main.cpp | 7 ++++++- src/net/ea/loginhandler.cpp | 5 +++++ src/net/manaserv/loginhandler.cpp | 9 +++++++++ src/utils/stringutils.cpp | 10 ++++++++++ src/utils/stringutils.h | 2 ++ 7 files changed, 46 insertions(+), 3 deletions(-) (limited to 'src/utils/stringutils.cpp') diff --git a/src/client.cpp b/src/client.cpp index 5d5ce3535..88fe8c443 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1689,6 +1689,8 @@ void Client::initConfiguration() config.setValue("musicVolume", 60); config.setValue("fpslimit", 60); std::string defaultUpdateHost = branding.getValue("defaultUpdateHost", ""); + if (!checkPath(defaultUpdateHost)) + defaultUpdateHost = ""; config.setValue("updatehost", defaultUpdateHost); config.setValue("customcursor", true); config.setValue("useScreenshotDirectorySuffix", true); @@ -1741,6 +1743,8 @@ void Client::initUpdatesDir() // If updatesHost is currently empty, fill it from config file if (mUpdateHost.empty()) mUpdateHost = config.getStringValue("updatehost"); + if (!checkPath(mUpdateHost)) + return; // Don't go out of range int he next check if (mUpdateHost.length() < 2) diff --git a/src/gui/logindialog.cpp b/src/gui/logindialog.cpp index 719b86cb8..b1c80b102 100644 --- a/src/gui/logindialog.cpp +++ b/src/gui/logindialog.cpp @@ -184,8 +184,16 @@ void LoginDialog::action(const gcn::ActionEvent &event) serverConfig.setValue("customUpdateHost", mUpdateHostText->getText()); - mLoginData->updateHost = mUpdateHostText->getText(); - *mUpdateHost = mUpdateHostText->getText(); + if (checkPath(mUpdateHostText->getText())) + { + mLoginData->updateHost = mUpdateHostText->getText(); + *mUpdateHost = mUpdateHostText->getText(); + } + else + { + mLoginData->updateHost = ""; + *mUpdateHost = ""; + } } mLoginData->updateType = updateType; serverConfig.setValue("updateType", updateType); diff --git a/src/main.cpp b/src/main.cpp index 1988e5962..71794487c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,6 +33,8 @@ #include #include +#include "utils/stringutils.h" + #ifdef __MINGW32__ #include #endif @@ -140,7 +142,10 @@ static void parseOptions(int argc, char *argv[], Client::Options &options) options.printHelp = true; break; case 'H': - options.updateHost = optarg; + if (checkPath(optarg)) + options.updateHost = optarg; + else + options.updateHost = ""; break; case 'c': options.character = optarg; diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp index bbf19fb34..291a92906 100644 --- a/src/net/ea/loginhandler.cpp +++ b/src/net/ea/loginhandler.cpp @@ -150,6 +150,11 @@ void LoginHandler::processUpdateHost(Net::MessageIn &msg) len = msg.readInt16() - 4; mUpdateHost = msg.readString(len); + if (!checkPath(mUpdateHost)) + { + mUpdateHost = ""; + logger->log1("Warning: incorrect update server name"); + } loginData.updateHost = mUpdateHost; logger->log("Received update host \"%s\" from login server.", diff --git a/src/net/manaserv/loginhandler.cpp b/src/net/manaserv/loginhandler.cpp index f1cb8e352..8b8ac831f 100644 --- a/src/net/manaserv/loginhandler.cpp +++ b/src/net/manaserv/loginhandler.cpp @@ -341,9 +341,18 @@ void LoginHandler::readServerInfo(Net::MessageIn &msg) // Set the update host when included in the message const std::string updateHost = msg.readString(); if (!updateHost.empty()) + { + if (!checkPath(updateHost)) + { + logger->log1("Warning: incorrect update server name"); + updateHost = ""; + } mLoginData->updateHost = updateHost; + } else + { logger->log1("Warning: server does not have an update host set!"); + } // Read the client data folder for dynamic data loading. // This is only used by the QT client. diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 642ba0df2..b855e3b04 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -612,3 +612,13 @@ std::string &removeProtocol(std::string &url) url = url.substr(i + 3); return url; } + +bool checkPath(std::string path) +{ + if (path.empty()) + return true; + return path.find("../") == std::string::npos + && path.find("..\\") == std::string::npos + && path.find("/..") == std::string::npos + && path.find("\\..") == std::string::npos; +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 0913c7348..c6eb08a6c 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -206,4 +206,6 @@ bool findCutFirst(std::string &str1, std::string str2); std::string &removeProtocol(std::string &url); +bool checkPath(std::string path); + #endif // UTILS_STRINGUTILS_H -- cgit v1.2.3-70-g09d2 From 7d60bf1c04fce4ed16144aece76e594e0e217960 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 23 Jan 2012 18:26:41 +0300 Subject: Add support for request client language from server. --- src/net/tmwa/network.cpp | 2 +- src/net/tmwa/network.h | 2 +- src/net/tmwa/npchandler.cpp | 33 ++++++++++++++++++++++++++++++--- src/net/tmwa/npchandler.h | 7 +++++++ src/net/tmwa/protocol.h | 1 + src/utils/stringutils.cpp | 13 +++++++++++++ src/utils/stringutils.h | 2 ++ 7 files changed, 55 insertions(+), 5 deletions(-) (limited to 'src/utils/stringutils.cpp') diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index addc737ee..08ba1db10 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -83,7 +83,7 @@ short packet_lengths[] = -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10, // #0x0200 26, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 19, 10, 0, 0, 0, - 2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 2, -1, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 122, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; diff --git a/src/net/tmwa/network.h b/src/net/tmwa/network.h index 17a4f7370..c0ec6ef3c 100644 --- a/src/net/tmwa/network.h +++ b/src/net/tmwa/network.h @@ -39,7 +39,7 @@ * Protocol version, reported to the eAthena char and mapserver who can adjust * the protocol accordingly. */ -#define CLIENT_PROTOCOL_VERSION 4 +#define CLIENT_PROTOCOL_VERSION 5 #define CLIENT_TMW_PROTOCOL_VERSION 1 namespace TmwAthena diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index 574f34d55..5e305070e 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -41,7 +41,8 @@ extern Net::NpcHandler *npcHandler; namespace TmwAthena { -NpcHandler::NpcHandler() +NpcHandler::NpcHandler() : + mRequestLang(false) { static const Uint16 _messages[] = { @@ -51,6 +52,7 @@ NpcHandler::NpcHandler() SMSG_NPC_CLOSE, SMSG_NPC_INT_INPUT, SMSG_NPC_STR_INPUT, + SMSG_NPC_COMMAND, 0 }; handledMessages = _messages; @@ -59,9 +61,12 @@ NpcHandler::NpcHandler() void NpcHandler::handleMessage(Net::MessageIn &msg) { - getNpc(msg, msg.getId() == SMSG_NPC_CHOICE + int npcId = getNpc(msg, msg.getId() == SMSG_NPC_CHOICE || msg.getId() == SMSG_NPC_MESSAGE); + if (msg.getId() != SMSG_NPC_STR_INPUT) + mRequestLang = false; + switch (msg.getId()) { case SMSG_NPC_CHOICE: @@ -85,7 +90,14 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) break; case SMSG_NPC_STR_INPUT: - processNpcStrInput(msg); + if (mRequestLang) + processLangReuqest(msg, npcId); + else + processNpcStrInput(msg); + break; + + case SMSG_NPC_COMMAND: + processNpcCommand(msg); break; default: @@ -227,4 +239,19 @@ int NpcHandler::getNpc(Net::MessageIn &msg, bool haveLength) return npcId; } +void NpcHandler::processNpcCommand(Net::MessageIn &msg) +{ + const int cmd = msg.readInt16(); + if (cmd == 0) + mRequestLang = true; + else + logger->log("unknown npc command: %d", cmd); +} + +void NpcHandler::processLangReuqest(Net::MessageIn &msg A_UNUSED, int npcId) +{ + mRequestLang = false; + stringInput(npcId, getLangSimple()); +} + } // namespace TmwAthena diff --git a/src/net/tmwa/npchandler.h b/src/net/tmwa/npchandler.h index 967829ddc..648b1e5d9 100644 --- a/src/net/tmwa/npchandler.h +++ b/src/net/tmwa/npchandler.h @@ -65,6 +65,13 @@ class NpcHandler : public MessageHandler, public Ea::NpcHandler void sellItem(int beingId, int itemId, int amount); int getNpc(Net::MessageIn &msg, bool haveLength); + + void processNpcCommand(Net::MessageIn &msg); + + void processLangReuqest(Net::MessageIn &msg, int npcId); + + private: + bool mRequestLang; }; } // namespace TmwAthena diff --git a/src/net/tmwa/protocol.h b/src/net/tmwa/protocol.h index 0f124cc20..ddc642101 100644 --- a/src/net/tmwa/protocol.h +++ b/src/net/tmwa/protocol.h @@ -335,5 +335,6 @@ enum #define SMSG_IGNORE_ALL_RESPONSE 0x00d2 #define CMSG_ONLINE_LIST 0x0210 #define SMSG_ONLINE_LIST 0x0211 +#define SMSG_NPC_COMMAND 0x0212 #endif diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index b855e3b04..26accbc7d 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -509,6 +509,19 @@ std::vector getLang() return langs; } +std::string getLangSimple() +{ + std::string lang = config.getValue("lang", "").c_str(); + if (lang.empty()) + { + char *lng = getenv("LANG"); + if (!lng) + return ""; + return lng; + } + return lang; +} + std::string packList(std::list &list) { std::list::const_iterator i = list.begin(); diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index c6eb08a6c..5cb726eef 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -188,6 +188,8 @@ std::string combineDye2(std::string file, std::string dye); std::vector getLang(); +std::string getLangSimple(); + std::string packList(std::list &list); std::list unpackList(const std::string &str); -- cgit v1.2.3-70-g09d2