summaryrefslogtreecommitdiff
path: root/src/net/eathena
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/eathena')
-rw-r--r--src/net/eathena/network.cpp78
-rw-r--r--src/net/eathena/network.h2
2 files changed, 29 insertions, 51 deletions
diff --git a/src/net/eathena/network.cpp b/src/net/eathena/network.cpp
index b72f78487..419459e35 100644
--- a/src/net/eathena/network.cpp
+++ b/src/net/eathena/network.cpp
@@ -110,7 +110,7 @@ short packet_lengths[] =
static constexpr const int packet_lengths_size
= static_cast<int>(sizeof(packet_lengths) / sizeof (short));
-static constexpr const unsigned int messagesSize = 0xffff;
+static constexpr const int messagesSize = 0xffff;
Network *Network::mInstance = nullptr;
Network::Network() :
@@ -167,23 +167,42 @@ void Network::dispatchMessages()
{
while (messageReady())
{
- MessageIn *const msg = getNextMessage();
+ SDL_mutexP(mMutex);
+ const int msgId = readWord(0);
+ int len = -1;
+ if (msgId == SMSG_SERVER_VERSION_RESPONSE)
+ {
+ len = 10;
+ }
+ else if (msgId == SMSG_UPDATE_HOST2)
+ {
+ len = -1;
+ }
+ else
+ {
+ if (msgId >= 0 && msgId < packet_lengths_size)
+ len = packet_lengths[msgId];
+ }
+
+ if (len == -1)
+ len = readWord(2);
- if (msg->getLength() == 0)
+ MessageIn msg(mInBuffer, len);
+ SDL_mutexV(mMutex);
+
+ if (len == 0)
logger->safeError("Zero length packet received. Exiting.");
- const int id = msg->getId();
- if (id >= 0 && id < messagesSize)
+ if (msgId >= 0 && msgId < messagesSize)
{
- MessageHandler *const handler = mMessageHandlers[id];
+ MessageHandler *const handler = mMessageHandlers[msgId];
if (handler)
- handler->handleMessage(*msg);
+ handler->handleMessage(msg);
else
- logger->log("Unhandled packet: %x", msg->getId());
+ logger->log("Unhandled packet: %x", msgId);
}
- skip(msg->getLength());
- delete msg;
+ skip(len);
}
}
@@ -212,45 +231,6 @@ bool Network::messageReady()
return ret;
}
-MessageIn *Network::getNextMessage()
-{
- while (!messageReady())
- {
- if (mState == NET_ERROR)
- break;
- }
-
- SDL_mutexP(mMutex);
- const int msgId = readWord(0);
- int len = -1;
- if (msgId == SMSG_SERVER_VERSION_RESPONSE)
- {
- len = 10;
- }
- else if (msgId == SMSG_UPDATE_HOST2)
- {
- len = -1;
- }
- else
- {
- if (msgId >= 0 && msgId < packet_lengths_size)
- len = packet_lengths[msgId];
- }
-
- if (len == -1)
- len = readWord(2);
-
-#ifdef ENABLEDEBUGLOG
- logger->dlog(strprintf("Received packet 0x%x of length %d\n",
- msgId, len));
-#endif
-
- MessageIn *const msg = new MessageIn(mInBuffer, len);
- SDL_mutexV(mMutex);
-
- return msg;
-}
-
Network *Network::instance()
{
return mInstance;
diff --git a/src/net/eathena/network.h b/src/net/eathena/network.h
index e2405f63d..c2f6e0bb6 100644
--- a/src/net/eathena/network.h
+++ b/src/net/eathena/network.h
@@ -60,8 +60,6 @@ class Network final : public Ea::Network
bool messageReady();
- MessageIn *getNextMessage() A_WARN_UNUSED;
-
void dispatchMessages();
protected: