diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/net/eathena/generalhandler.cpp | 6 | ||||
-rw-r--r-- | src/net/eathena/network.cpp | 25 | ||||
-rw-r--r-- | src/net/eathena/network.h | 4 | ||||
-rw-r--r-- | src/net/tmwa/generalhandler.cpp | 6 | ||||
-rw-r--r-- | src/net/tmwa/network.cpp | 25 | ||||
-rw-r--r-- | src/net/tmwa/network.h | 4 |
6 files changed, 20 insertions, 50 deletions
diff --git a/src/net/eathena/generalhandler.cpp b/src/net/eathena/generalhandler.cpp index d81a05d9d..7e81bf155 100644 --- a/src/net/eathena/generalhandler.cpp +++ b/src/net/eathena/generalhandler.cpp @@ -162,10 +162,8 @@ void GeneralHandler::handleMessage(Net::MessageIn &msg) void GeneralHandler::load() { - (new Network)->registerHandler(this); - - if (!mNetwork) - return; + mNetwork = new Network; + mNetwork->registerHandlers(); mNetwork->registerHandler(mAdminHandler); mNetwork->registerHandler(mBeingHandler); diff --git a/src/net/eathena/network.cpp b/src/net/eathena/network.cpp index fdafd6baf..33c530989 100644 --- a/src/net/eathena/network.cpp +++ b/src/net/eathena/network.cpp @@ -93,30 +93,28 @@ static const unsigned int messagesSize = 0xFFFFU; Network *Network::mInstance = nullptr; Network::Network() : - Ea::Network(), - mMessageHandlers(new MessageHandler*[messagesSize]) + Ea::Network() { mInstance = this; - memset(&mMessageHandlers[0], 0, sizeof(MessageHandler*) * 0xffff); mPackets = new PacketInfo[messagesSize]; -#include "net/eathena/recvpackets.inc" } Network::~Network() { clearHandlers(); - delete2Arr(mMessageHandlers); mInstance = nullptr; } +void Network::registerHandlers() +{ +#include "net/eathena/recvpackets.inc" +} + void Network::registerHandler(MessageHandler *const handler) { if (!handler) return; - for (const uint16_t *i = handler->handledMessages; *i; ++i) - mMessageHandlers[*i] = handler; - handler->setNetwork(this); } @@ -125,22 +123,11 @@ void Network::unregisterHandler(MessageHandler *const handler) if (!handler) return; - for (const uint16_t *i = handler->handledMessages; *i; ++i) - mMessageHandlers[*i] = nullptr; - handler->setNetwork(nullptr); } void Network::clearHandlers() { - for (size_t f = 0; f < messagesSize; f ++) - { - if (mMessageHandlers[f]) - { - mMessageHandlers[f]->setNetwork(nullptr); - mMessageHandlers[f] = nullptr; - } - } } void Network::dispatchMessages() diff --git a/src/net/eathena/network.h b/src/net/eathena/network.h index acfb9dd59..b393f17d8 100644 --- a/src/net/eathena/network.h +++ b/src/net/eathena/network.h @@ -54,14 +54,14 @@ class Network final : public Ea::Network void dispatchMessages(); + void registerHandlers(); + static Network *mInstance; protected: friend class MessageOut; static Network *instance() A_WARN_UNUSED; - - MessageHandler **mMessageHandlers; }; } // namespace EAthena diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index 4f03f490e..9ffa8164f 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -175,10 +175,8 @@ void GeneralHandler::handleMessage(Net::MessageIn &msg) void GeneralHandler::load() { - (new Network)->registerHandler(this); - - if (!mNetwork) - return; + mNetwork = new Network; + mNetwork->registerHandlers(); mNetwork->registerHandler(mAdminHandler); mNetwork->registerHandler(mBeingHandler); diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index cce906703..0e99f9dbd 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -74,30 +74,28 @@ static const unsigned int messagesSize = 0xFFFFU; Network *Network::mInstance = nullptr; Network::Network() : - Ea::Network(), - mMessageHandlers(new MessageHandler*[messagesSize]) + Ea::Network() { mInstance = this; - memset(&mMessageHandlers[0], 0, sizeof(MessageHandler*) * 0xffff); mPackets = new PacketInfo[messagesSize]; -#include "net/tmwa/recvpackets.inc" } Network::~Network() { clearHandlers(); - delete2Arr(mMessageHandlers); mInstance = nullptr; } +void Network::registerHandlers() +{ +#include "net/tmwa/recvpackets.inc" +} + void Network::registerHandler(MessageHandler *const handler) { if (!handler) return; - for (const uint16_t *i = handler->handledMessages; *i; ++i) - mMessageHandlers[*i] = handler; - handler->setNetwork(this); } @@ -106,22 +104,11 @@ void Network::unregisterHandler(MessageHandler *const handler) if (!handler) return; - for (const uint16_t *i = handler->handledMessages; *i; ++i) - mMessageHandlers[*i] = nullptr; - handler->setNetwork(nullptr); } void Network::clearHandlers() { - for (size_t f = 0; f < messagesSize; f ++) - { - if (mMessageHandlers[f]) - { - mMessageHandlers[f]->setNetwork(nullptr); - mMessageHandlers[f] = nullptr; - } - } } void Network::dispatchMessages() diff --git a/src/net/tmwa/network.h b/src/net/tmwa/network.h index 046314c88..473665576 100644 --- a/src/net/tmwa/network.h +++ b/src/net/tmwa/network.h @@ -55,14 +55,14 @@ class Network final : public Ea::Network void dispatchMessages(); + void registerHandlers(); + static Network *mInstance; protected: friend class MessageOut; static Network *instance() A_WARN_UNUSED; - - MessageHandler **mMessageHandlers; }; } // namespace TmwAthena |