From 854c72570f49f7ed57f35fce72bc91ebdc08d2ac Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 31 Aug 2015 19:59:51 +0300 Subject: Add ability to log received packet names to log file. Also add arrays with id to package info mapping for inbound packets. --- src/net/ea/network.cpp | 7 +++++-- src/net/ea/network.h | 4 ++++ src/net/eathena/messagein.cpp | 7 ++++--- src/net/eathena/messagein.h | 5 +++-- src/net/eathena/network.cpp | 6 +++++- src/net/eathena/packets.inc | 2 ++ src/net/eathena/protocol.h | 2 -- src/net/eathena/recvpackets.h | 28 ++++++++++++++++++++++++++++ src/net/messagein.cpp | 3 ++- src/net/packetinfo.h | 36 ++++++++++++++++++++++++++++++++++++ src/net/recvpacketdefine.h | 26 ++++++++++++++++++++++++++ src/net/tmwa/messagein.cpp | 7 ++++--- src/net/tmwa/messagein.h | 5 +++-- src/net/tmwa/network.cpp | 6 +++++- src/net/tmwa/packets.inc | 2 ++ src/net/tmwa/protocol.h | 2 -- src/net/tmwa/recvpackets.h | 28 ++++++++++++++++++++++++++++ 17 files changed, 157 insertions(+), 19 deletions(-) create mode 100644 src/net/eathena/recvpackets.h create mode 100644 src/net/packetinfo.h create mode 100644 src/net/recvpacketdefine.h create mode 100644 src/net/tmwa/recvpackets.h (limited to 'src/net') 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 . + */ + +#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 . + */ + +#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 . + */ + +#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 . + */ + +#ifndef NET_TMWA_RECVPACKETS_H +#define NET_TMWA_RECVPACKETS_H + +#include "net/recvpacketdefine.h" + +#include "net/tmwa/packets.inc" + +#endif // NET_TMWA_RECVPACKETS_H -- cgit v1.2.3-70-g09d2