diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-10-19 01:05:22 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-10-19 01:05:22 +0300 |
commit | 990c96c992c4cf21173c904dd85f0b378e1c89b0 (patch) | |
tree | a87e8b060a3bae6869e8945082fb9b11a6a60957 | |
parent | 3945c533f8930093b6101b00827a37d6bbde0fb4 (diff) | |
download | manaplus-990c96c992c4cf21173c904dd85f0b378e1c89b0.tar.gz manaplus-990c96c992c4cf21173c904dd85f0b378e1c89b0.tar.bz2 manaplus-990c96c992c4cf21173c904dd85f0b378e1c89b0.tar.xz manaplus-990c96c992c4cf21173c904dd85f0b378e1c89b0.zip |
Hide passwords from packets logs.
-rw-r--r-- | src/net/messageout.cpp | 28 | ||||
-rw-r--r-- | src/net/messageout.h | 7 | ||||
-rw-r--r-- | src/net/tmwa/loginhandler.cpp | 6 |
3 files changed, 38 insertions, 3 deletions
diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index a8b66f5ae..f18f65a93 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -82,6 +82,34 @@ void MessageOut::writeString(const std::string &string, int length) PacketCounters::incOutBytes(length); } +void MessageOut::writeStringNoLog(const std::string &string, int length) +{ + DEBUGLOG("writeString: ***"); + int stringLength = static_cast<int>(string.length()); + if (length < 0) + { + // Write the length at the start if not fixed + writeInt16(static_cast<short>(stringLength)); + length = stringLength; + } + else if (length < stringLength) + { + // Make sure the length of the string is no longer than specified + stringLength = length; + } + expand(length); + + // Write the actual string + memcpy(mData + mPos, string.c_str(), stringLength); + + // Pad remaining space with zeros + if (length > stringLength) + memset(mData + mPos + stringLength, '\0', length - stringLength); + + mPos += length; + PacketCounters::incOutBytes(length); +} + char *MessageOut::getData() const { return mData; diff --git a/src/net/messageout.h b/src/net/messageout.h index 39a2e68bd..4445bbbe8 100644 --- a/src/net/messageout.h +++ b/src/net/messageout.h @@ -57,6 +57,13 @@ class MessageOut virtual void writeString(const std::string &string, int length = -1); /** + * Writes a string. If a fixed length is not given (-1), it is stored + * as a short at the start of the string. + */ + virtual void writeStringNoLog(const std::string &string, + int length = -1); + + /** * Returns the content of the message. */ virtual char *getData() const; diff --git a/src/net/tmwa/loginhandler.cpp b/src/net/tmwa/loginhandler.cpp index cac8df623..bdc944d63 100644 --- a/src/net/tmwa/loginhandler.cpp +++ b/src/net/tmwa/loginhandler.cpp @@ -118,8 +118,8 @@ void LoginHandler::changePassword(const std::string &username A_UNUSED, const std::string &newPassword) { MessageOut outMsg(CMSG_CHAR_PASSWORD_CHANGE); - outMsg.writeString(oldPassword, 24); - outMsg.writeString(newPassword, 24); + outMsg.writeStringNoLog(oldPassword, 24); + outMsg.writeStringNoLog(newPassword, 24); } void LoginHandler::sendLoginRegister(const std::string &username, @@ -128,7 +128,7 @@ void LoginHandler::sendLoginRegister(const std::string &username, MessageOut outMsg(0x0064); outMsg.writeInt32(0); // client version outMsg.writeString(username, 24); - outMsg.writeString(password, 24); + outMsg.writeStringNoLog(password, 24); /* * eAthena calls the last byte "client version 2", but it isn't used at |