summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-01-23 18:26:41 +0300
committerAndrei Karas <akaras@inbox.ru>2012-01-23 18:26:41 +0300
commit7d60bf1c04fce4ed16144aece76e594e0e217960 (patch)
treed2831dcbbdf6b7bd3ad89a9e0571b25afa5caad0
parent20ffb556085e519f98a96f00257ee6b837116a8e (diff)
downloadmv-7d60bf1c04fce4ed16144aece76e594e0e217960.tar.gz
mv-7d60bf1c04fce4ed16144aece76e594e0e217960.tar.bz2
mv-7d60bf1c04fce4ed16144aece76e594e0e217960.tar.xz
mv-7d60bf1c04fce4ed16144aece76e594e0e217960.zip
Add support for request client language from server.
-rw-r--r--src/net/tmwa/network.cpp2
-rw-r--r--src/net/tmwa/network.h2
-rw-r--r--src/net/tmwa/npchandler.cpp33
-rw-r--r--src/net/tmwa/npchandler.h7
-rw-r--r--src/net/tmwa/protocol.h1
-rw-r--r--src/utils/stringutils.cpp13
-rw-r--r--src/utils/stringutils.h2
7 files changed, 55 insertions, 5 deletions
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<std::string> 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<std::string> &list)
{
std::list<std::string>::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<std::string> getLang();
+std::string getLangSimple();
+
std::string packList(std::list<std::string> &list);
std::list<std::string> unpackList(const std::string &str);