diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-09-17 16:34:43 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-09-17 16:58:46 +0300 |
commit | 38659dbd75d81edbe336d5311a1cd1184d359b7e (patch) | |
tree | 919c97a5e48c5e9287250eab34cb36ef5f02c21e /src | |
parent | c1ba61eb566a0a1a2532690ba3bf7e6498bee06b (diff) | |
download | manaplus-38659dbd75d81edbe336d5311a1cd1184d359b7e.tar.gz manaplus-38659dbd75d81edbe336d5311a1cd1184d359b7e.tar.bz2 manaplus-38659dbd75d81edbe336d5311a1cd1184d359b7e.tar.xz manaplus-38659dbd75d81edbe336d5311a1cd1184d359b7e.zip |
add support for ignore packets logging.
Option for coma separated packet ids added in misc tab.
Diffstat (limited to 'src')
-rw-r--r-- | src/client.cpp | 1 | ||||
-rw-r--r-- | src/defaults.cpp | 1 | ||||
-rw-r--r-- | src/gui/widgets/tabs/setup_other.cpp | 7 | ||||
-rw-r--r-- | src/logger.h | 20 | ||||
-rw-r--r-- | src/net/ea/network.cpp | 6 | ||||
-rw-r--r-- | src/net/eathena/messagein.cpp | 22 | ||||
-rw-r--r-- | src/net/eathena/messagein.h | 2 | ||||
-rw-r--r-- | src/net/messagein.cpp | 4 | ||||
-rw-r--r-- | src/net/messagein.h | 3 | ||||
-rw-r--r-- | src/net/messageout.cpp | 10 | ||||
-rw-r--r-- | src/net/messageout.h | 2 | ||||
-rw-r--r-- | src/net/net.cpp | 19 | ||||
-rw-r--r-- | src/net/net.h | 4 | ||||
-rw-r--r-- | src/net/tmwa/messagein.cpp | 22 | ||||
-rw-r--r-- | src/net/tmwa/messagein.h | 2 |
15 files changed, 105 insertions, 20 deletions
diff --git a/src/client.cpp b/src/client.cpp index 0cde9295c..4c1820513 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -264,6 +264,7 @@ void Client::gameInit() #endif ConfigManager::backupConfig("config.xml"); ConfigManager::initConfiguration(); + Net::loadIgnorePackets(); paths.setDefaultValues(getPathsDefaults()); initFeatures(); logger->log("init 4"); diff --git a/src/defaults.cpp b/src/defaults.cpp index e1762d91f..44221309a 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -368,6 +368,7 @@ DefaultsData* getConfigDefaults() AddDEF("hidesupport", false); AddDEF("showserverpos", false); AddDEF("textureSize", "1024,1024,1024,1024,1024,1024"); + AddDEF("ignorelogpackets", ""); return configData; } diff --git a/src/gui/widgets/tabs/setup_other.cpp b/src/gui/widgets/tabs/setup_other.cpp index 2c62e179c..ad25127f7 100644 --- a/src/gui/widgets/tabs/setup_other.cpp +++ b/src/gui/widgets/tabs/setup_other.cpp @@ -35,6 +35,8 @@ #include "resources/map/mapconsts.h" +#include "net/net.h" + #include "utils/delete2.h" #include "utils/gettext.h" @@ -364,6 +366,10 @@ Setup_Other::Setup_Other(const Widget2 *const widget) : "debugLog", this, "debugLogEvent"); // TRANSLATORS: settings option + new SetupItemTextField(_("Ignore logging packets"), "", + "ignorelogpackets", this, "ignorelogpacketsEvent"); + + // TRANSLATORS: settings option new SetupItemCheckBox(_("Enable OpenGL log"), "", "debugOpenGL", this, "debugOpenGLEvent"); @@ -423,6 +429,7 @@ void Setup_Other::apply() SetupTabScroll::apply(); logger->setDebugLog(config.getBoolValue("debugLog")); + Net::loadIgnorePackets(); } void Setup_Other::externalUpdated() diff --git a/src/logger.h b/src/logger.h index d288d7c8d..9d2221543 100644 --- a/src/logger.h +++ b/src/logger.h @@ -33,17 +33,17 @@ #include "localconsts.h" #ifdef ENABLEDEBUGLOG -#define DEBUGLOG(msg) if (logger) logger->dlog(msg) +#define DEBUGLOG(str) \ + if (logger && !mIgnore) \ + logger->dlog(str) +#define DEBUGLOG2(str, pos, comment) \ + if (logger && !mIgnore) \ + logger->dlog2(str, pos, comment) +#define IGNOREDEBUGLOG mIgnore = Net::isIgnorePacket(mId) #else -#define DEBUGLOG(msg) {} -#endif - -#ifdef ENABLEDEBUGLOG -#define DEBUGLOG2(msg, pos, comment) \ - if (logger) \ - logger->dlog2(msg, pos, comment) -#else -#define DEBUGLOG2(msg, comment) {} +#define DEBUGLOG(str) {} +#define DEBUGLOG2(str, comment) {} +#define IGNOREDEBUGLOG {} #endif /** diff --git a/src/net/ea/network.cpp b/src/net/ea/network.cpp index c080e35ec..b64ae68cb 100644 --- a/src/net/ea/network.cpp +++ b/src/net/ea/network.cpp @@ -153,7 +153,11 @@ void Network::flush() SDL_mutexP(mMutexOut); const int ret = TcpNet::send(mSocket, mOutBuffer, mOutSize); - DEBUGLOG(std::string("Send ").append(toString(mOutSize)).append(" bytes")); + if (logger) + { + logger->dlog(std::string("Send ").append( + toString(mOutSize)).append(" bytes")); + } if (ret < static_cast<int>(mOutSize)) { SDL_mutexV(mMutexOut); diff --git a/src/net/eathena/messagein.cpp b/src/net/eathena/messagein.cpp index e24134a72..bacf189c6 100644 --- a/src/net/eathena/messagein.cpp +++ b/src/net/eathena/messagein.cpp @@ -22,6 +22,7 @@ #include "net/eathena/messagein.h" +#include "net/net.h" #include "net/packetcounters.h" #include "logger.h" @@ -43,7 +44,26 @@ MessageIn::MessageIn(const char *const data, const unsigned int length) : void MessageIn::postInit() { // Read the message ID - mId = readInt16("packet id"); + mId = readId(); + IGNOREDEBUGLOG; + DEBUGLOG2("Receive packet", 0, "MessageIn"); + readInt16("packet id"); +} + +uint16_t MessageIn::readId() +{ + int16_t value = -1; + if (mPos + 2 <= mLength) + { +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + int16_t swap; + memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int16_t)); + value = SDL_Swap16(swap); +#else + memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int16_t)); +#endif + } + return value; } int16_t MessageIn::readInt16(const char *const str) diff --git a/src/net/eathena/messagein.h b/src/net/eathena/messagein.h index 1b9001c64..fec2b5e4f 100644 --- a/src/net/eathena/messagein.h +++ b/src/net/eathena/messagein.h @@ -53,6 +53,8 @@ class MessageIn final : public Net::MessageIn int32_t readInt32(const char *const str = nullptr); int64_t readInt64(const char *const str = nullptr); + + uint16_t readId(); }; } // namespace EAthena diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 2f064a8a0..fde20a423 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -40,11 +40,11 @@ namespace Net MessageIn::MessageIn(const char *const data, const unsigned int length) : mData(data), mLength(length), + mPos(0), mId(0), - mPos(0) + mIgnore(false) { PacketCounters::incInPackets(); - DEBUGLOG("MessageIn"); } MessageIn::~MessageIn() diff --git a/src/net/messagein.h b/src/net/messagein.h index d05f58b57..181a2a740 100644 --- a/src/net/messagein.h +++ b/src/net/messagein.h @@ -126,7 +126,6 @@ class MessageIn notfinal const char *mData; /**< The message data. */ unsigned int mLength; /**< The length of the data. */ - uint16_t mId; /**< The message ID. */ /** * Actual position in the packet. From 0 to packet->length. @@ -134,6 +133,8 @@ class MessageIn notfinal * reading it. */ unsigned int mPos; + uint16_t mId; /**< The message ID. */ + bool mIgnore; }; } // namespace Net diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index 0026538b5..7ee08b0d4 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -22,6 +22,7 @@ #include "net/messageout.h" +#include "net/net.h" #include "net/packetcounters.h" #include "logger.h" @@ -36,13 +37,16 @@ namespace Net { -MessageOut::MessageOut(const int16_t id A_UNUSED) : +MessageOut::MessageOut(const int16_t id) : mData(nullptr), mDataSize(0), - mPos(0) + mPos(0), + mId(id), + mIgnore(false) { PacketCounters::incOutPackets(); - DEBUGLOG("MessageOut"); + IGNOREDEBUGLOG; + DEBUGLOG2("Send packet", 0, "MessageOut"); } void MessageOut::writeInt8(const int8_t value, const char *const str) diff --git a/src/net/messageout.h b/src/net/messageout.h index b2429ab33..9238e2c55 100644 --- a/src/net/messageout.h +++ b/src/net/messageout.h @@ -99,6 +99,8 @@ class MessageOut notfinal char *mData; /**< Data building up. */ unsigned int mDataSize; /**< Size of data. */ unsigned int mPos; /**< Position in the data. */ + uint16_t mId; + bool mIgnore; }; } // namespace Net diff --git a/src/net/net.cpp b/src/net/net.cpp index 237287fef..3aba48940 100644 --- a/src/net/net.cpp +++ b/src/net/net.cpp @@ -20,9 +20,11 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "main.h" + #include "net/net.h" -#include "main.h" +#include "configuration.h" #include "net/loginhandler.h" @@ -34,6 +36,8 @@ #include "net/eathena/generalhandler.h" #endif +#include "utils/stringutils.h" + #include "debug.h" namespace Net @@ -90,6 +94,7 @@ Net::QuestHandler *questHandler = nullptr; namespace Net { ServerInfo::Type networkType = ServerInfo::UNKNOWN; +std::set<int> ignorePackets; void connectToServer(const ServerInfo &server) { @@ -142,6 +147,7 @@ void unload() GeneralHandler *const handler = generalHandler; if (handler) handler->unload(); + ignorePackets.clear(); } ServerInfo::Type getNetworkType() @@ -149,4 +155,15 @@ ServerInfo::Type getNetworkType() return networkType; } +void loadIgnorePackets() +{ + const std::string str = config.getStringValue("ignorelogpackets"); + splitToIntSet(ignorePackets, str, ','); +} + +bool isIgnorePacket(const int id) +{ + return ignorePackets.find(id) != ignorePackets.end(); +} + } // namespace Net diff --git a/src/net/net.h b/src/net/net.h index 12abe18a6..eddc9aeba 100644 --- a/src/net/net.h +++ b/src/net/net.h @@ -45,6 +45,10 @@ void connectToServer(const ServerInfo &server); void unload(); +void loadIgnorePackets(); + +bool isIgnorePacket(const int id); + } // namespace Net #endif // NET_NET_H diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp index 214540483..75dcb917c 100644 --- a/src/net/tmwa/messagein.cpp +++ b/src/net/tmwa/messagein.cpp @@ -22,6 +22,7 @@ #include "net/tmwa/messagein.h" +#include "net/net.h" #include "net/packetcounters.h" #include "logger.h" @@ -43,7 +44,26 @@ MessageIn::MessageIn(const char *const data, const unsigned int length) : void MessageIn::postInit() { // Read the message ID - mId = readInt16("packet id"); + mId = readId(); + IGNOREDEBUGLOG; + DEBUGLOG2("Receive packet", 0, "MessageIn"); + readInt16("packet id"); +} + +uint16_t MessageIn::readId() +{ + int16_t value = -1; + if (mPos + 2 <= mLength) + { +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + int16_t swap; + memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int16_t)); + value = SDL_Swap16(swap); +#else + memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int16_t)); +#endif + } + return value; } int16_t MessageIn::readInt16(const char *const str) diff --git a/src/net/tmwa/messagein.h b/src/net/tmwa/messagein.h index f0645ddda..12e2b58cf 100644 --- a/src/net/tmwa/messagein.h +++ b/src/net/tmwa/messagein.h @@ -53,6 +53,8 @@ class MessageIn final : public Net::MessageIn int32_t readInt32(const char *const str = nullptr); int64_t readInt64(const char *const str = nullptr); + + uint16_t readId(); }; } // namespace TmwAthena |