summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-03-27 19:44:23 +0100
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-03-27 20:18:11 +0100
commit712ca58c011123505c807266dcc8d9d84ca1aa44 (patch)
tree27c0dfe49f21bffe25007f70475be3223d3fa851 /src/net
parentff5e1957dd4fde40e41e4c5e4b9e04e1f36e5ef2 (diff)
downloadmana-client-712ca58c011123505c807266dcc8d9d84ca1aa44.tar.gz
mana-client-712ca58c011123505c807266dcc8d9d84ca1aa44.tar.bz2
mana-client-712ca58c011123505c807266dcc8d9d84ca1aa44.tar.xz
mana-client-712ca58c011123505c807266dcc8d9d84ca1aa44.zip
Made eAthena's Network class statically accessible
Now the instance doesn't need to be passed into the MessageOut class anymore. Expect a lot of cleanup in the next commit.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/ea/network.cpp9
-rw-r--r--src/net/ea/network.h6
-rw-r--r--src/net/messageout.cpp11
-rw-r--r--src/net/messageout.h4
4 files changed, 18 insertions, 12 deletions
diff --git a/src/net/ea/network.cpp b/src/net/ea/network.cpp
index e17b8f3b..4aecb268 100644
--- a/src/net/ea/network.cpp
+++ b/src/net/ea/network.cpp
@@ -91,6 +91,8 @@ int networkThread(void *data)
return 0;
}
+Network *Network::mInstance = 0;
+
Network::Network():
mSocket(0),
mAddress(), mPort(0),
@@ -102,6 +104,7 @@ Network::Network():
mWorkerThread(0)
{
mMutex = SDL_CreateMutex();
+ mInstance = this;
}
Network::~Network()
@@ -112,6 +115,7 @@ Network::~Network()
disconnect();
SDL_DestroyMutex(mMutex);
+ mInstance = 0;
delete[] mInBuffer;
delete[] mOutBuffer;
@@ -420,6 +424,11 @@ void Network::receive()
SDLNet_FreeSocketSet(set);
}
+Network *Network::instance()
+{
+ return mInstance;
+}
+
void Network::setError(const std::string &error)
{
logger->log("Network error: %s", error.c_str());
diff --git a/src/net/ea/network.h b/src/net/ea/network.h
index 651b1182..40d563aa 100644
--- a/src/net/ea/network.h
+++ b/src/net/ea/network.h
@@ -85,7 +85,9 @@ class Network
NET_ERROR
};
- protected:
+ private:
+ static Network *instance();
+
void setError(const std::string &error);
Uint16 readWord(int pos);
@@ -113,6 +115,8 @@ class Network
typedef std::map<Uint16, MessageHandler*> MessageHandlers;
typedef MessageHandlers::iterator MessageHandlerIterator;
MessageHandlers mMessageHandlers;
+
+ static Network *mInstance;
};
#endif
diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp
index 4cb4dc36..35e9a425 100644
--- a/src/net/messageout.cpp
+++ b/src/net/messageout.cpp
@@ -33,21 +33,16 @@
#include <cstring>
#include <string>
-#ifdef TMWSERV_SUPPORT
MessageOut::MessageOut(short id):
mData(0),
-#else
-MessageOut::MessageOut(Network *network):
- mNetwork(network),
-#endif
mDataSize(0),
mPos(0)
{
-#ifdef TMWSERV_SUPPORT
- writeInt16(id);
-#else
+#ifdef EATHENA_SUPPORT
+ mNetwork = Network::instance();
mData = mNetwork->mOutBuffer + mNetwork->mOutSize;
#endif
+ writeInt16(id);
}
#ifdef TMWSERV_SUPPORT
diff --git a/src/net/messageout.h b/src/net/messageout.h
index 1ddd040d..9dc31525 100644
--- a/src/net/messageout.h
+++ b/src/net/messageout.h
@@ -43,15 +43,13 @@ class MessageOut
/**
* Constructor.
*/
-#ifdef TMWSERV_SUPPORT
MessageOut(short id);
+#ifdef TMWSERV_SUPPORT
/**
* Destructor.
*/
~MessageOut();
-#else
- MessageOut(Network *network);
#endif
void writeInt8(Sint8 value); /**< Writes a byte. */