diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-08-31 19:59:51 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-09-01 00:19:20 +0300 |
commit | 854c72570f49f7ed57f35fce72bc91ebdc08d2ac (patch) | |
tree | 577c1b4ce129c52cabbb8665bf1b562a2e3d4f6c | |
parent | 366de9963d24841483e6ed8ff4a88f775a1c2fcf (diff) | |
download | plus-854c72570f49f7ed57f35fce72bc91ebdc08d2ac.tar.gz plus-854c72570f49f7ed57f35fce72bc91ebdc08d2ac.tar.bz2 plus-854c72570f49f7ed57f35fce72bc91ebdc08d2ac.tar.xz plus-854c72570f49f7ed57f35fce72bc91ebdc08d2ac.zip |
Add ability to log received packet names to log file.
Also add arrays with id to package info mapping for inbound packets.
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/net/ea/network.cpp | 7 | ||||
-rw-r--r-- | src/net/ea/network.h | 4 | ||||
-rw-r--r-- | src/net/eathena/messagein.cpp | 7 | ||||
-rw-r--r-- | src/net/eathena/messagein.h | 5 | ||||
-rw-r--r-- | src/net/eathena/network.cpp | 6 | ||||
-rw-r--r-- | src/net/eathena/packets.inc | 2 | ||||
-rw-r--r-- | src/net/eathena/protocol.h | 2 | ||||
-rw-r--r-- | src/net/eathena/recvpackets.h | 28 | ||||
-rw-r--r-- | src/net/messagein.cpp | 3 | ||||
-rw-r--r-- | src/net/packetinfo.h | 36 | ||||
-rw-r--r-- | src/net/recvpacketdefine.h | 26 | ||||
-rw-r--r-- | src/net/tmwa/messagein.cpp | 7 | ||||
-rw-r--r-- | src/net/tmwa/messagein.h | 5 | ||||
-rw-r--r-- | src/net/tmwa/network.cpp | 6 | ||||
-rw-r--r-- | src/net/tmwa/packets.inc | 2 | ||||
-rw-r--r-- | src/net/tmwa/protocol.h | 2 | ||||
-rw-r--r-- | src/net/tmwa/recvpackets.h | 28 |
19 files changed, 165 insertions, 19 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 479d6544d..497c7965b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -574,9 +574,11 @@ SET(SRCS net/worldinfo.h net/packetcounters.cpp net/packetcounters.h + net/packetinfo.h net/packetlimiter.cpp net/packetlimiter.h net/protocoldefine.h + net/recvpacketdefine.h resources/action.cpp resources/action.h resources/ambientlayer.cpp @@ -1482,6 +1484,7 @@ SET(SRCS_TMWA net/tmwa/questhandler.h net/tmwa/questrecv.cpp net/tmwa/questrecv.h + net/tmwa/recvpackets.h net/tmwa/serverfeatures.cpp net/tmwa/serverfeatures.h net/tmwa/skillhandler.cpp @@ -1706,6 +1709,7 @@ SET(SRCS_EATHENA net/eathena/questhandler.h net/eathena/questrecv.cpp net/eathena/questrecv.h + net/eathena/recvpackets.h net/eathena/roulettehandler.cpp net/eathena/roulettehandler.h net/eathena/rouletterecv.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 144d4118b..881a75825 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1167,6 +1167,7 @@ manaplus_SOURCES += main.cpp \ net/pethandler.h \ net/playerhandler.h \ net/questhandler.h \ + net/recvpacketdefine.h \ net/registrationoptions.h \ net/serverfeatures.h \ net/serverinfo.h \ @@ -1178,6 +1179,7 @@ manaplus_SOURCES += main.cpp \ net/worldinfo.h \ net/packetcounters.cpp \ net/packetcounters.h \ + net/packetinfo.h \ net/packetlimiter.cpp \ net/packetlimiter.h \ net/protocoldefine.h \ @@ -1325,6 +1327,7 @@ manaplus_SOURCES += \ net/tmwa/questhandler.h \ net/tmwa/questrecv.cpp \ net/tmwa/questrecv.h \ + net/tmwa/recvpackets.h \ net/tmwa/serverfeatures.cpp \ net/tmwa/serverfeatures.h \ net/tmwa/skillhandler.cpp \ @@ -1552,6 +1555,7 @@ manaplus_SOURCES += gui/windows/bankwindow.cpp \ net/eathena/questhandler.h \ net/eathena/questrecv.cpp \ net/eathena/questrecv.h \ + net/eathena/recvpackets.h \ net/eathena/roulettehandler.cpp \ net/eathena/roulettehandler.h \ net/eathena/rouletterecv.cpp \ diff --git a/src/net/ea/network.cpp b/src/net/ea/network.cpp index a214cc4e5..ac938f7bc 100644 --- a/src/net/ea/network.cpp +++ b/src/net/ea/network.cpp @@ -25,6 +25,7 @@ #include "configuration.h" #include "logger.h" +#include "utils/delete2.h" #include "utils/gettext.h" #include "utils/sdlhelper.h" @@ -55,6 +56,7 @@ int networkThread(void *data) Network::Network() : mSocket(nullptr), mServer(), + mPackets(nullptr), mInBuffer(new char[BUFFER_SIZE]), mOutBuffer(new char[BUFFER_SIZE]), mInSize(0), @@ -81,8 +83,9 @@ Network::~Network() SDL_DestroyMutex(mMutexOut); mMutexOut = nullptr; - delete []mInBuffer; - delete []mOutBuffer; + delete2Arr(mInBuffer); + delete2Arr(mOutBuffer); + delete2Arr(mPackets); TcpNet::quit(); } diff --git a/src/net/ea/network.h b/src/net/ea/network.h index 52693ef30..ae9f62f9d 100644 --- a/src/net/ea/network.h +++ b/src/net/ea/network.h @@ -26,6 +26,8 @@ #include "net/serverinfo.h" #include "net/sdltcpnet.h" +struct PacketInfo; + namespace Ea { @@ -91,6 +93,8 @@ class Network notfinal ServerInfo mServer; + PacketInfo *mPackets; + char *mInBuffer; char *mOutBuffer; unsigned int mInSize; diff --git a/src/net/eathena/messagein.cpp b/src/net/eathena/messagein.cpp index 03b8ddd3a..043f3f387 100644 --- a/src/net/eathena/messagein.cpp +++ b/src/net/eathena/messagein.cpp @@ -34,18 +34,19 @@ namespace EAthena { -MessageIn::MessageIn(const char *const data, const unsigned int length) : +MessageIn::MessageIn(const char *const data, + const unsigned int length) : Net::MessageIn(data, length) { } -void MessageIn::postInit() +void MessageIn::postInit(const char *const str) { // Read the message ID mId = readId(); IGNOREDEBUGLOG; DEBUGLOG2("Receive packet", 0, "MessageIn"); - readInt16("packet id"); + readInt16(str); } uint16_t MessageIn::readId() diff --git a/src/net/eathena/messagein.h b/src/net/eathena/messagein.h index fb20b6db7..72110614f 100644 --- a/src/net/eathena/messagein.h +++ b/src/net/eathena/messagein.h @@ -41,11 +41,12 @@ class MessageIn final : public Net::MessageIn /** * Constructor. */ - MessageIn(const char *const data, const unsigned int length); + MessageIn(const char *const data, + const unsigned int length); A_DELETE_COPY(MessageIn) - void postInit(); + void postInit(const char *const str); /**< Reads a short. */ int16_t readInt16(const char *const str) override final; diff --git a/src/net/eathena/network.cpp b/src/net/eathena/network.cpp index 80f0f579b..83dfb0796 100644 --- a/src/net/eathena/network.cpp +++ b/src/net/eathena/network.cpp @@ -24,6 +24,8 @@ #include "logger.h" +#include "net/packetinfo.h" + #include "net/eathena/messagehandler.h" #include "net/eathena/messagein.h" #include "net/eathena/packets.h" @@ -47,6 +49,8 @@ Network::Network() : { mInstance = this; memset(&mMessageHandlers[0], 0, sizeof(MessageHandler*) * 0xffff); + mPackets = new PacketInfo[messagesSize]; +#include "net/eathena/recvpackets.h" } Network::~Network() @@ -105,7 +109,7 @@ void Network::dispatchMessages() len = readWord(2); MessageIn msg(mInBuffer, len); - msg.postInit(); + msg.postInit(mPackets[msgId].name); SDL_mutexV(mMutexIn); if (len == 0) diff --git a/src/net/eathena/packets.inc b/src/net/eathena/packets.inc index 6371807a5..2a2405674 100644 --- a/src/net/eathena/packets.inc +++ b/src/net/eathena/packets.inc @@ -729,3 +729,5 @@ packet(CMSG_SEARCHSTORE_CLICK, 0x0835); packet(CMSG_SET_STATUS, 0x0b0e); packet(CMSG_ONLINE_LIST, 0x0b0f); + +#undef packet diff --git a/src/net/eathena/protocol.h b/src/net/eathena/protocol.h index 21dab17d7..b1e59d443 100644 --- a/src/net/eathena/protocol.h +++ b/src/net/eathena/protocol.h @@ -27,6 +27,4 @@ #include "net/eathena/packets.inc" -#undef packet - #endif // NET_EATHENA_PROTOCOL_H diff --git a/src/net/eathena/recvpackets.h b/src/net/eathena/recvpackets.h new file mode 100644 index 000000000..e14b1252b --- /dev/null +++ b/src/net/eathena/recvpackets.h @@ -0,0 +1,28 @@ +/* + * The ManaPlus Client + * Copyright (C) 2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef NET_EATHENA_RECVPACKETS_H +#define NET_EATHENA_RECVPACKETS_H + +#include "net/recvpacketdefine.h" + +#include "net/eathena/packets.inc" + +#endif // NET_EATHENA_RECVPACKETS_H diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index ff43d233c..dd99dc77a 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -37,7 +37,8 @@ namespace Net { -MessageIn::MessageIn(const char *const data, const unsigned int length) : +MessageIn::MessageIn(const char *const data, + const unsigned int length) : mData(data), mLength(length), mPos(0), diff --git a/src/net/packetinfo.h b/src/net/packetinfo.h new file mode 100644 index 000000000..8c2609439 --- /dev/null +++ b/src/net/packetinfo.h @@ -0,0 +1,36 @@ +/* + * The ManaPlus Client + * Copyright (C) 2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef NET_PACKETINFO_H +#define NET_PACKETINFO_H + +struct PacketInfo +{ + PacketInfo() : + name(nullptr), + len(0) + { + } + + const char *name; + int len; +}; + +#endif // NET_PACKETINFO_H diff --git a/src/net/recvpacketdefine.h b/src/net/recvpacketdefine.h new file mode 100644 index 000000000..cde46f0c6 --- /dev/null +++ b/src/net/recvpacketdefine.h @@ -0,0 +1,26 @@ +/* + * The ManaPlus Client + * Copyright (C) 2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef NET_RECVPACKETDEFINE_H +#define NET_RECVPACKETDEFINE_H + +#define packet(pname, pid) mPackets[pid].name = #pname + +#endif // NET_RECVPACKETDEFINE_H diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp index 3bb66c6f2..11dab0d38 100644 --- a/src/net/tmwa/messagein.cpp +++ b/src/net/tmwa/messagein.cpp @@ -34,18 +34,19 @@ namespace TmwAthena { -MessageIn::MessageIn(const char *const data, const unsigned int length) : +MessageIn::MessageIn(const char *const data, + const unsigned int length) : Net::MessageIn(data, length) { } -void MessageIn::postInit() +void MessageIn::postInit(const char *const str) { // Read the message ID mId = readId(); IGNOREDEBUGLOG; DEBUGLOG2("Receive packet", 0, "MessageIn"); - readInt16("packet id"); + readInt16(str); } uint16_t MessageIn::readId() diff --git a/src/net/tmwa/messagein.h b/src/net/tmwa/messagein.h index 7d27b1188..93cb6e092 100644 --- a/src/net/tmwa/messagein.h +++ b/src/net/tmwa/messagein.h @@ -41,11 +41,12 @@ class MessageIn final : public Net::MessageIn /** * Constructor. */ - MessageIn(const char *const data, const unsigned int length); + MessageIn(const char *const data, + const unsigned int length); A_DELETE_COPY(MessageIn) - void postInit(); + void postInit(const char *const str); /**< Reads a short. */ int16_t readInt16(const char *const str) override final; diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index 97bbcd9c0..8095c1251 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -24,6 +24,8 @@ #include "logger.h" +#include "net/packetinfo.h" + #include "net/tmwa/messagehandler.h" #include "net/tmwa/messagein.h" #include "net/tmwa/packets.h" @@ -47,6 +49,8 @@ Network::Network() : { mInstance = this; memset(&mMessageHandlers[0], 0, sizeof(MessageHandler*) * 0xffff); + mPackets = new PacketInfo[messagesSize]; +#include "net/tmwa/recvpackets.h" } Network::~Network() @@ -109,7 +113,7 @@ void Network::dispatchMessages() len = readWord(2); MessageIn msg(mInBuffer, len); - msg.postInit(); + msg.postInit(mPackets[msgId].name); SDL_mutexV(mMutexIn); BLOCK_END("Network::dispatchMessages 2") BLOCK_START("Network::dispatchMessages 3") diff --git a/src/net/tmwa/packets.inc b/src/net/tmwa/packets.inc index b6402ed2b..3933b8379 100644 --- a/src/net/tmwa/packets.inc +++ b/src/net/tmwa/packets.inc @@ -294,3 +294,5 @@ packet(SMSG_BEING_MOVE3, 0x0225); packet(SMSG_MAP_MUSIC, 0x0227); packet(SMSG_NPC_CHANGETITLE, 0x0228); packet(SMSG_SCRIPT_MESSAGE, 0x0229); + +#undef packet diff --git a/src/net/tmwa/protocol.h b/src/net/tmwa/protocol.h index 564dfb8a7..508507e0e 100644 --- a/src/net/tmwa/protocol.h +++ b/src/net/tmwa/protocol.h @@ -27,6 +27,4 @@ #include "net/tmwa/packets.inc" -#undef packet - #endif // NET_TMWA_PROTOCOL_H diff --git a/src/net/tmwa/recvpackets.h b/src/net/tmwa/recvpackets.h new file mode 100644 index 000000000..59c12fec2 --- /dev/null +++ b/src/net/tmwa/recvpackets.h @@ -0,0 +1,28 @@ +/* + * The ManaPlus Client + * Copyright (C) 2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef NET_TMWA_RECVPACKETS_H +#define NET_TMWA_RECVPACKETS_H + +#include "net/recvpacketdefine.h" + +#include "net/tmwa/packets.inc" + +#endif // NET_TMWA_RECVPACKETS_H |