summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-09-02 03:12:14 +0300
committerAndrei Karas <akaras@inbox.ru>2015-09-02 03:12:14 +0300
commit40730c4fa73d403cf7284a76d9b26f7ec662afa4 (patch)
tree3bf9dce3ca6297a06193cdcc19cfdfa914fc48b2
parentab8c8cdae07d96cb18276a95b41ddb856c864958 (diff)
downloadmanaverse-40730c4fa73d403cf7284a76d9b26f7ec662afa4.tar.gz
manaverse-40730c4fa73d403cf7284a76d9b26f7ec662afa4.tar.bz2
manaverse-40730c4fa73d403cf7284a76d9b26f7ec662afa4.tar.xz
manaverse-40730c4fa73d403cf7284a76d9b26f7ec662afa4.zip
Remove mNetwork field from MessageHandlers
-rw-r--r--src/net/eathena/charserverhandler.cpp8
-rw-r--r--src/net/eathena/gamehandler.cpp14
-rw-r--r--src/net/eathena/generalhandler.cpp64
-rw-r--r--src/net/eathena/loginhandler.cpp12
-rw-r--r--src/net/eathena/messagehandler.cpp10
-rw-r--r--src/net/eathena/messagehandler.h3
-rw-r--r--src/net/tmwa/charserverhandler.cpp8
-rw-r--r--src/net/tmwa/gamehandler.cpp14
-rw-r--r--src/net/tmwa/generalhandler.cpp65
-rw-r--r--src/net/tmwa/loginhandler.cpp12
-rw-r--r--src/net/tmwa/messagehandler.cpp10
-rw-r--r--src/net/tmwa/messagehandler.h3
12 files changed, 72 insertions, 151 deletions
diff --git a/src/net/eathena/charserverhandler.cpp b/src/net/eathena/charserverhandler.cpp
index 1fe9b1268..42e3dd7e4 100644
--- a/src/net/eathena/charserverhandler.cpp
+++ b/src/net/eathena/charserverhandler.cpp
@@ -239,11 +239,11 @@ void CharServerHandler::connect()
const Token &token =
static_cast<LoginHandler*>(loginHandler)->getToken();
- if (!mNetwork)
+ if (!Network::mInstance)
return;
- mNetwork->disconnect();
- mNetwork->connect(charServer);
+ Network::mInstance->disconnect();
+ Network::mInstance->connect(charServer);
createOutPacket(CMSG_CHAR_SERVER_CONNECT);
outMsg.writeBeingId(token.account_ID, "account id");
outMsg.writeInt32(token.session_ID1, "session id1");
@@ -252,7 +252,7 @@ void CharServerHandler::connect()
outMsg.writeInt8(Being::genderToInt(token.sex), "gender");
// We get 4 useless bytes before the real answer comes in (what are these?)
- mNetwork->skip(4);
+ Network::mInstance->skip(4);
}
void CharServerHandler::setCharCreateDialog(CharCreateDialog *const window)
diff --git a/src/net/eathena/gamehandler.cpp b/src/net/eathena/gamehandler.cpp
index dde0a10d5..9b2756058 100644
--- a/src/net/eathena/gamehandler.cpp
+++ b/src/net/eathena/gamehandler.cpp
@@ -110,10 +110,10 @@ void GameHandler::mapLoadedEvent() const
void GameHandler::connect()
{
- if (!mNetwork)
+ if (!Network::mInstance)
return;
- mNetwork->connect(mapServer);
+ Network::mInstance->connect(mapServer);
const Token &token = static_cast<LoginHandler*>(loginHandler)->getToken();
@@ -149,20 +149,20 @@ void GameHandler::connect()
}
*/
// We get 4 useless bytes before the real answer comes in (what are these?)
-// mNetwork->skip(4);
+// Network::mInstance->skip(4);
}
bool GameHandler::isConnected() const
{
- if (!mNetwork)
+ if (!Network::mInstance)
return false;
- return mNetwork->isConnected();
+ return Network::mInstance->isConnected();
}
void GameHandler::disconnect()
{
- if (mNetwork)
- mNetwork->disconnect();
+ if (Network::mInstance)
+ Network::mInstance->disconnect();
}
void GameHandler::quit() const
diff --git a/src/net/eathena/generalhandler.cpp b/src/net/eathena/generalhandler.cpp
index 7e81bf155..f57bcef35 100644
--- a/src/net/eathena/generalhandler.cpp
+++ b/src/net/eathena/generalhandler.cpp
@@ -140,7 +140,7 @@ GeneralHandler::GeneralHandler() :
GeneralHandler::~GeneralHandler()
{
- delete2(mNetwork);
+ delete2(Network::mInstance);
}
void GeneralHandler::handleMessage(Net::MessageIn &msg)
@@ -162,48 +162,14 @@ void GeneralHandler::handleMessage(Net::MessageIn &msg)
void GeneralHandler::load()
{
- mNetwork = new Network;
- mNetwork->registerHandlers();
-
- mNetwork->registerHandler(mAdminHandler);
- mNetwork->registerHandler(mBeingHandler);
- mNetwork->registerHandler(mBuySellHandler);
- mNetwork->registerHandler(mChatHandler);
- mNetwork->registerHandler(mCharServerHandler);
- mNetwork->registerHandler(mGameHandler);
- mNetwork->registerHandler(mGuildHandler);
- mNetwork->registerHandler(mInventoryHandler);
- mNetwork->registerHandler(mItemHandler);
- mNetwork->registerHandler(mLoginHandler);
- mNetwork->registerHandler(mNpcHandler);
- mNetwork->registerHandler(mPlayerHandler);
- mNetwork->registerHandler(mSkillHandler);
- mNetwork->registerHandler(mTradeHandler);
- mNetwork->registerHandler(mPartyHandler);
- mNetwork->registerHandler(mPetHandler);
- mNetwork->registerHandler(mQuestHandler);
- mNetwork->registerHandler(mMailHandler);
- mNetwork->registerHandler(mAuctionHandler);
- mNetwork->registerHandler(mCashShopHandler);
- mNetwork->registerHandler(mFamilyHandler);
- mNetwork->registerHandler(mBankHandler);
- mNetwork->registerHandler(mBattleGroundHandler);
- mNetwork->registerHandler(mMercenaryHandler);
- mNetwork->registerHandler(mBuyingStoreHandler);
- mNetwork->registerHandler(mHomunculusHandler);
- mNetwork->registerHandler(mFriendsHandler);
- mNetwork->registerHandler(mElementalHandler);
- mNetwork->registerHandler(mMapHandler);
- mNetwork->registerHandler(mMarketHandler);
- mNetwork->registerHandler(mVendingHandler);
- mNetwork->registerHandler(mSearchStoreHandler);
- mNetwork->registerHandler(mRouletteHandler);
+ new Network;
+ Network::mInstance->registerHandlers();
}
void GeneralHandler::reload()
{
- if (mNetwork)
- mNetwork->disconnect();
+ if (Network::mInstance)
+ Network::mInstance->disconnect();
static_cast<LoginHandler*>(mLoginHandler)->clearWorlds();
CharServerHandler *const charHandler = static_cast<CharServerHandler*>(
@@ -225,24 +191,24 @@ void GeneralHandler::unload()
void GeneralHandler::flushSend()
{
- if (!mNetwork)
+ if (!Network::mInstance)
return;
- mNetwork->flush();
+ Network::mInstance->flush();
}
void GeneralHandler::flushNetwork()
{
- if (!mNetwork)
+ if (!Network::mInstance)
return;
- mNetwork->flush();
- mNetwork->dispatchMessages();
+ Network::mInstance->flush();
+ Network::mInstance->dispatchMessages();
- if (mNetwork->getState() == Network::NET_ERROR)
+ if (Network::mInstance->getState() == Network::NET_ERROR)
{
- if (!mNetwork->getError().empty())
- errorMessage = mNetwork->getError();
+ if (!Network::mInstance->getError().empty())
+ errorMessage = Network::mInstance->getError();
else
errorMessage = _("Got disconnected from server!");
@@ -252,8 +218,8 @@ void GeneralHandler::flushNetwork()
void GeneralHandler::clearHandlers()
{
- if (mNetwork)
- mNetwork->clearHandlers();
+ if (Network::mInstance)
+ Network::mInstance->clearHandlers();
}
void GeneralHandler::gameStarted() const
diff --git a/src/net/eathena/loginhandler.cpp b/src/net/eathena/loginhandler.cpp
index cca2a90eb..9376d24b5 100644
--- a/src/net/eathena/loginhandler.cpp
+++ b/src/net/eathena/loginhandler.cpp
@@ -105,10 +105,10 @@ void LoginHandler::handleMessage(Net::MessageIn &msg)
void LoginHandler::connect()
{
- if (!mNetwork)
+ if (!Network::mInstance)
return;
- mNetwork->connect(mServer);
+ Network::mInstance->connect(mServer);
if (serverFeatures->haveServerVersion())
{
sendVersion();
@@ -122,16 +122,16 @@ void LoginHandler::connect()
bool LoginHandler::isConnected() const
{
- if (!mNetwork)
+ if (!Network::mInstance)
return false;
- return mNetwork->isConnected();
+ return Network::mInstance->isConnected();
}
void LoginHandler::disconnect()
{
- if (mNetwork && mNetwork->getServer() == mServer)
- mNetwork->disconnect();
+ if (Network::mInstance && Network::mInstance->getServer() == mServer)
+ Network::mInstance->disconnect();
}
void LoginHandler::changePassword(const std::string &restrict oldPassword,
diff --git a/src/net/eathena/messagehandler.cpp b/src/net/eathena/messagehandler.cpp
index bdfbe49e6..f8490ed1d 100644
--- a/src/net/eathena/messagehandler.cpp
+++ b/src/net/eathena/messagehandler.cpp
@@ -32,21 +32,19 @@ namespace EAthena
{
MessageHandler::MessageHandler() :
- Net::MessageHandler(),
- mNetwork(nullptr)
+ Net::MessageHandler()
{
}
MessageHandler::~MessageHandler()
{
- if (mNetwork)
- mNetwork->unregisterHandler(this);
+ if (Network::mInstance)
+ Network::mInstance->unregisterHandler(this);
}
void MessageHandler::setNetwork(Network *const network)
{
- assert(!(network && mNetwork));
- mNetwork = network;
+ assert(!(network && Network::mInstance));
}
} // namespace EAthena
diff --git a/src/net/eathena/messagehandler.h b/src/net/eathena/messagehandler.h
index 1bf84f449..4fa35c6a2 100644
--- a/src/net/eathena/messagehandler.h
+++ b/src/net/eathena/messagehandler.h
@@ -43,9 +43,6 @@ class MessageHandler notfinal : public Net::MessageHandler
virtual ~MessageHandler();
void setNetwork(Network *const network);
-
- protected:
- Network *mNetwork;
};
typedef MessageHandler* MessageHandlerPtr;
diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp
index 4666ba7b9..c5afb012e 100644
--- a/src/net/tmwa/charserverhandler.cpp
+++ b/src/net/tmwa/charserverhandler.cpp
@@ -174,11 +174,11 @@ void CharServerHandler::connect()
const Token &token =
static_cast<LoginHandler*>(loginHandler)->getToken();
- if (!mNetwork)
+ if (!Network::mInstance)
return;
- mNetwork->disconnect();
- mNetwork->connect(charServer);
+ Network::mInstance->disconnect();
+ Network::mInstance->connect(charServer);
createOutPacket(CMSG_CHAR_SERVER_CONNECT);
outMsg.writeBeingId(token.account_ID, "account id");
outMsg.writeInt32(token.session_ID1, "session id1");
@@ -197,7 +197,7 @@ void CharServerHandler::connect()
outMsg.writeInt8(Being::genderToInt(token.sex), "gender");
// We get 4 useless bytes before the real answer comes in (what are these?)
- mNetwork->skip(4);
+ Network::mInstance->skip(4);
}
void CharServerHandler::setCharCreateDialog(CharCreateDialog *const window)
diff --git a/src/net/tmwa/gamehandler.cpp b/src/net/tmwa/gamehandler.cpp
index a3af6118b..00537bf83 100644
--- a/src/net/tmwa/gamehandler.cpp
+++ b/src/net/tmwa/gamehandler.cpp
@@ -101,11 +101,11 @@ void GameHandler::mapLoadedEvent() const
void GameHandler::connect()
{
- if (!mNetwork)
+ if (!Network::mInstance)
return;
BLOCK_START("GameHandler::connect")
- mNetwork->connect(mapServer);
+ Network::mInstance->connect(mapServer);
const Token &token = static_cast<LoginHandler*>(loginHandler)->getToken();
if (client->getState() == STATE_CONNECT_GAME)
@@ -138,22 +138,22 @@ void GameHandler::connect()
}
*/
// We get 4 useless bytes before the real answer comes in (what are these?)
- mNetwork->skip(4);
+ Network::mInstance->skip(4);
BLOCK_END("GameHandler::connect")
}
bool GameHandler::isConnected() const
{
- if (!mNetwork)
+ if (!Network::mInstance)
return false;
- return mNetwork->isConnected();
+ return Network::mInstance->isConnected();
}
void GameHandler::disconnect()
{
BLOCK_START("GameHandler::disconnect")
- if (mNetwork)
- mNetwork->disconnect();
+ if (Network::mInstance)
+ Network::mInstance->disconnect();
BLOCK_END("GameHandler::disconnect")
}
diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp
index 9ffa8164f..5abce494b 100644
--- a/src/net/tmwa/generalhandler.cpp
+++ b/src/net/tmwa/generalhandler.cpp
@@ -154,7 +154,7 @@ GeneralHandler::GeneralHandler() :
GeneralHandler::~GeneralHandler()
{
- delete2(mNetwork);
+ delete2(Network::mInstance);
}
void GeneralHandler::handleMessage(Net::MessageIn &msg)
@@ -175,49 +175,14 @@ void GeneralHandler::handleMessage(Net::MessageIn &msg)
void GeneralHandler::load()
{
- mNetwork = new Network;
- mNetwork->registerHandlers();
-
- mNetwork->registerHandler(mAdminHandler);
- mNetwork->registerHandler(mBeingHandler);
- mNetwork->registerHandler(mBuySellHandler);
- mNetwork->registerHandler(mChatHandler);
- mNetwork->registerHandler(mCharServerHandler);
- mNetwork->registerHandler(mGameHandler);
- mNetwork->registerHandler(mGuildHandler);
- mNetwork->registerHandler(mInventoryHandler);
- mNetwork->registerHandler(mItemHandler);
- mNetwork->registerHandler(mLoginHandler);
- mNetwork->registerHandler(mNpcHandler);
- mNetwork->registerHandler(mPlayerHandler);
- mNetwork->registerHandler(mSkillHandler);
- mNetwork->registerHandler(mTradeHandler);
- mNetwork->registerHandler(mPartyHandler);
- mNetwork->registerHandler(mPetHandler);
- mNetwork->registerHandler(mQuestHandler);
-#ifdef EATHENA_SUPPORT
- mNetwork->registerHandler(mAuctionHandler);
- mNetwork->registerHandler(mBankHandler);
- mNetwork->registerHandler(mBattleGroundHandler);
- mNetwork->registerHandler(mBuyingStoreHandler);
- mNetwork->registerHandler(mCashShopHandler);
- mNetwork->registerHandler(mElementalHandler);
- mNetwork->registerHandler(mFamilyHandler);
- mNetwork->registerHandler(mFriendsHandler);
- mNetwork->registerHandler(mHomunculusHandler);
- mNetwork->registerHandler(mMailHandler);
- mNetwork->registerHandler(mMapHandler);
- mNetwork->registerHandler(mMarketHandler);
- mNetwork->registerHandler(mMercenaryHandler);
- mNetwork->registerHandler(mSearchStoreHandler);
- mNetwork->registerHandler(mVendingHandler);
-#endif
+ new Network;
+ Network::mInstance->registerHandlers();
}
void GeneralHandler::reload()
{
- if (mNetwork)
- mNetwork->disconnect();
+ if (Network::mInstance)
+ Network::mInstance->disconnect();
static_cast<LoginHandler*>(mLoginHandler)->clearWorlds();
CharServerHandler *const charHandler = static_cast<CharServerHandler*>(
@@ -239,28 +204,28 @@ void GeneralHandler::unload()
void GeneralHandler::flushSend()
{
- if (!mNetwork)
+ if (!Network::mInstance)
return;
- mNetwork->flush();
+ Network::mInstance->flush();
}
void GeneralHandler::flushNetwork()
{
- if (!mNetwork)
+ if (!Network::mInstance)
return;
BLOCK_START("GeneralHandler::flushNetwork 1")
- mNetwork->flush();
+ Network::mInstance->flush();
BLOCK_END("GeneralHandler::flushNetwork 1")
- mNetwork->dispatchMessages();
+ Network::mInstance->dispatchMessages();
BLOCK_START("GeneralHandler::flushNetwork 3")
- if (mNetwork->getState() == Network::NET_ERROR)
+ if (Network::mInstance->getState() == Network::NET_ERROR)
{
- if (!mNetwork->getError().empty())
+ if (!Network::mInstance->getError().empty())
{
- errorMessage = mNetwork->getError();
+ errorMessage = Network::mInstance->getError();
}
else
{
@@ -275,8 +240,8 @@ void GeneralHandler::flushNetwork()
void GeneralHandler::clearHandlers()
{
- if (mNetwork)
- mNetwork->clearHandlers();
+ if (Network::mInstance)
+ Network::mInstance->clearHandlers();
}
void GeneralHandler::gameStarted() const
diff --git a/src/net/tmwa/loginhandler.cpp b/src/net/tmwa/loginhandler.cpp
index 035f22fa1..177984d72 100644
--- a/src/net/tmwa/loginhandler.cpp
+++ b/src/net/tmwa/loginhandler.cpp
@@ -96,26 +96,26 @@ void LoginHandler::handleMessage(Net::MessageIn &msg)
void LoginHandler::connect()
{
- if (!mNetwork)
+ if (!Network::mInstance)
return;
- mNetwork->connect(mServer);
+ Network::mInstance->connect(mServer);
if (serverFeatures->haveServerVersion())
createOutPacket(CMSG_SERVER_VERSION_REQUEST);
}
bool LoginHandler::isConnected() const
{
- if (!mNetwork)
+ if (!Network::mInstance)
return false;
- return Ea::LoginRecv::mVersionResponse && mNetwork->isConnected();
+ return Ea::LoginRecv::mVersionResponse && Network::mInstance->isConnected();
}
void LoginHandler::disconnect()
{
- if (mNetwork && mNetwork->getServer() == mServer)
- mNetwork->disconnect();
+ if (Network::mInstance && Network::mInstance->getServer() == mServer)
+ Network::mInstance->disconnect();
}
void LoginHandler::changePassword(const std::string &restrict oldPassword,
diff --git a/src/net/tmwa/messagehandler.cpp b/src/net/tmwa/messagehandler.cpp
index 0537606b0..bc5e2fae7 100644
--- a/src/net/tmwa/messagehandler.cpp
+++ b/src/net/tmwa/messagehandler.cpp
@@ -32,21 +32,19 @@ namespace TmwAthena
{
MessageHandler::MessageHandler() :
- Net::MessageHandler(),
- mNetwork(nullptr)
+ Net::MessageHandler()
{
}
MessageHandler::~MessageHandler()
{
- if (mNetwork)
- mNetwork->unregisterHandler(this);
+ if (Network::mInstance)
+ Network::mInstance->unregisterHandler(this);
}
void MessageHandler::setNetwork(Network *const network)
{
- assert(!(network && mNetwork));
- mNetwork = network;
+ assert(!(network && Network::mInstance));
}
} // namespace TmwAthena
diff --git a/src/net/tmwa/messagehandler.h b/src/net/tmwa/messagehandler.h
index 047dd82ff..0ea8609af 100644
--- a/src/net/tmwa/messagehandler.h
+++ b/src/net/tmwa/messagehandler.h
@@ -43,9 +43,6 @@ class MessageHandler notfinal : public Net::MessageHandler
virtual ~MessageHandler();
void setNetwork(Network *const network);
-
- protected:
- Network *mNetwork;
};
typedef MessageHandler* MessageHandlerPtr;