summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-09-17 16:34:43 +0300
committerAndrei Karas <akaras@inbox.ru>2014-09-17 16:58:46 +0300
commit38659dbd75d81edbe336d5311a1cd1184d359b7e (patch)
tree919c97a5e48c5e9287250eab34cb36ef5f02c21e /src/net
parentc1ba61eb566a0a1a2532690ba3bf7e6498bee06b (diff)
downloadplus-38659dbd75d81edbe336d5311a1cd1184d359b7e.tar.gz
plus-38659dbd75d81edbe336d5311a1cd1184d359b7e.tar.bz2
plus-38659dbd75d81edbe336d5311a1cd1184d359b7e.tar.xz
plus-38659dbd75d81edbe336d5311a1cd1184d359b7e.zip
add support for ignore packets logging.
Option for coma separated packet ids added in misc tab.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/ea/network.cpp6
-rw-r--r--src/net/eathena/messagein.cpp22
-rw-r--r--src/net/eathena/messagein.h2
-rw-r--r--src/net/messagein.cpp4
-rw-r--r--src/net/messagein.h3
-rw-r--r--src/net/messageout.cpp10
-rw-r--r--src/net/messageout.h2
-rw-r--r--src/net/net.cpp19
-rw-r--r--src/net/net.h4
-rw-r--r--src/net/tmwa/messagein.cpp22
-rw-r--r--src/net/tmwa/messagein.h2
11 files changed, 86 insertions, 10 deletions
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