From be3c1cf049d3df146d18acfb7cbead2ef3f660f1 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 28 Mar 2013 23:21:07 +0300 Subject: improve generalhandler class. --- src/depricatedevent.h | 2 - src/game.cpp | 7 +-- src/net/eathena/generalhandler.cpp | 118 ++++++++++++++++--------------------- src/net/eathena/generalhandler.h | 22 ++++--- src/net/generalhandler.h | 3 + src/net/tmwa/generalhandler.cpp | 118 +++++++++++++++++-------------------- src/net/tmwa/generalhandler.h | 23 ++++---- 7 files changed, 131 insertions(+), 162 deletions(-) diff --git a/src/depricatedevent.h b/src/depricatedevent.h index 14f73ddc7..cc6658b7f 100644 --- a/src/depricatedevent.h +++ b/src/depricatedevent.h @@ -41,10 +41,8 @@ enum DepricatedEvents EVENT_CONSTRUCTED = 0, EVENT_DESTRUCTED, EVENT_ENGINESINITALIZING, - EVENT_GUIWINDOWSLOADED, EVENT_GUIWINDOWSLOADING, EVENT_GUIWINDOWSUNLOADED, - EVENT_GUIWINDOWSUNLOADING, EVENT_SERVERNOTICE, EVENT_STATECHANGE, EVENT_UPDATEATTRIBUTE, diff --git a/src/game.cpp b/src/game.cpp index 7c5138c7d..ac22d8724 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -80,6 +80,7 @@ #include "gui/widgets/spellshortcutcontainer.h" #include "gui/widgets/tradetab.h" +#include "net/generalhandler.h" #include "net/gamehandler.h" #include "net/packetcounters.h" #include "net/playerhandler.h" @@ -313,8 +314,7 @@ static void createGuiWindows() if (player_node) player_node->updateStatus(); - DepricatedEvent::trigger(CHANNEL_GAME, - DepricatedEvent(EVENT_GUIWINDOWSLOADED)); + Net::getGeneralHandler()->gameStarted(); } #define del_0(X) { delete X; X = nullptr; } @@ -324,8 +324,7 @@ static void createGuiWindows() */ static void destroyGuiWindows() { - DepricatedEvent::trigger(CHANNEL_GAME, - DepricatedEvent(EVENT_GUIWINDOWSUNLOADING)); + Net::getGeneralHandler()->gameEnded(); logger->setChatWindow(nullptr); if (whoIsOnline) diff --git a/src/net/eathena/generalhandler.cpp b/src/net/eathena/generalhandler.cpp index d34edff7c..ad59ce664 100644 --- a/src/net/eathena/generalhandler.cpp +++ b/src/net/eathena/generalhandler.cpp @@ -107,8 +107,6 @@ GeneralHandler::GeneralHandler() : stats.push_back(ItemDB::Stat("luck", _("Luck %+d"))); ItemDB::setStatsList(stats); - - listen(CHANNEL_GAME); } GeneralHandler::~GeneralHandler() @@ -119,12 +117,11 @@ GeneralHandler::~GeneralHandler() void GeneralHandler::handleMessage(Net::MessageIn &msg) { - int code; - switch (msg.getId()) { case SMSG_CONNECTION_PROBLEM: - code = msg.readInt8(); + { + const int code = msg.readInt8(); logger->log("Connection problem: %i", code); switch (code) @@ -158,6 +155,7 @@ void GeneralHandler::handleMessage(Net::MessageIn &msg) } Client::setState(STATE_ERROR); break; + } default: break; @@ -194,11 +192,10 @@ void GeneralHandler::reload() mNetwork->disconnect(); static_cast(mLoginHandler.get())->clearWorlds(); - static_cast( - mCharServerHandler.get())->setCharCreateDialog(nullptr); - static_cast( - mCharServerHandler.get())->setCharSelectDialog(nullptr); - + CharServerHandler *charHandler = static_cast( + mCharServerHandler.get()); + charHandler->setCharCreateDialog(nullptr); + charHandler->setCharSelectDialog(nullptr); static_cast(mPartyHandler.get())->reload(); } @@ -237,70 +234,55 @@ void GeneralHandler::clearHandlers() mNetwork->clearHandlers(); } -void GeneralHandler::processEvent(Channels channel, - const DepricatedEvent &event) +void GeneralHandler::gameStarted() const { - if (channel == CHANNEL_GAME) - { - if (event.getName() == EVENT_GUIWINDOWSLOADED) - { - if (inventoryWindow) - inventoryWindow->setSplitAllowed(false); - if (skillDialog) - skillDialog->loadSkills(); - - if (!statusWindow) - return; - - // protection against double addition attributes. - statusWindow->clearAttributes(); - - statusWindow->addAttribute(STR, _("Strength"), "str", true, ""); - statusWindow->addAttribute(AGI, _("Agility"), "agi", true, ""); - statusWindow->addAttribute(VIT, _("Vitality"), "vit", true, ""); - statusWindow->addAttribute(INT, _("Intelligence"), - "int", true, ""); - statusWindow->addAttribute(DEX, _("Dexterity"), "dex", true, ""); - statusWindow->addAttribute(LUK, _("Luck"), "luk", true, ""); - - statusWindow->addAttribute(ATK, _("Attack")); - statusWindow->addAttribute(DEF, _("Defense")); - statusWindow->addAttribute(MATK, _("M.Attack")); - statusWindow->addAttribute(MDEF, _("M.Defense")); - // xgettext:no-c-format - statusWindow->addAttribute(HIT, _("% Accuracy")); - // xgettext:no-c-format - statusWindow->addAttribute(FLEE, _("% Evade")); - // xgettext:no-c-format - statusWindow->addAttribute(CRIT, _("% Critical")); - statusWindow->addAttribute(PlayerInfo::ATTACK_DELAY, - _("Attack Delay")); - statusWindow->addAttribute(PlayerInfo::WALK_SPEED, - _("Walk Delay")); - statusWindow->addAttribute(PlayerInfo::ATTACK_RANGE, - _("Attack Range")); - statusWindow->addAttribute(PlayerInfo::ATTACK_SPEED, - _("Damage per sec.")); - } - else if (event.getName() == EVENT_GUIWINDOWSUNLOADING) - { - if (socialWindow) - { - socialWindow->removeTab(Ea::taGuild); - socialWindow->removeTab(Ea::taParty); - } + if (inventoryWindow) + inventoryWindow->setSplitAllowed(false); + if (skillDialog) + skillDialog->loadSkills(); - delete Ea::guildTab; - Ea::guildTab = nullptr; + if (!statusWindow) + return; - delete Ea::partyTab; - Ea::partyTab = nullptr; - } - } + // protection against double addition attributes. + statusWindow->clearAttributes(); + + statusWindow->addAttribute(STR, _("Strength"), "str", true, ""); + statusWindow->addAttribute(AGI, _("Agility"), "agi", true, ""); + statusWindow->addAttribute(VIT, _("Vitality"), "vit", true, ""); + statusWindow->addAttribute(INT, _("Intelligence"), "int", true, ""); + statusWindow->addAttribute(DEX, _("Dexterity"), "dex", true, ""); + statusWindow->addAttribute(LUK, _("Luck"), "luk", true, ""); + + statusWindow->addAttribute(ATK, _("Attack")); + statusWindow->addAttribute(DEF, _("Defense")); + statusWindow->addAttribute(MATK, _("M.Attack")); + statusWindow->addAttribute(MDEF, _("M.Defense")); + // xgettext:no-c-format + statusWindow->addAttribute(HIT, _("% Accuracy")); + // xgettext:no-c-format + statusWindow->addAttribute(FLEE, _("% Evade")); + // xgettext:no-c-format + statusWindow->addAttribute(CRIT, _("% Critical")); + statusWindow->addAttribute(PlayerInfo::ATTACK_DELAY, _("Attack Delay")); + statusWindow->addAttribute(PlayerInfo::WALK_SPEED, _("Walk Delay")); + statusWindow->addAttribute(PlayerInfo::ATTACK_RANGE, _("Attack Range")); + statusWindow->addAttribute(PlayerInfo::ATTACK_SPEED, _("Damage per sec.")); } -void GeneralHandler::requestOnlineList() +void GeneralHandler::gameEnded() const { + if (socialWindow) + { + socialWindow->removeTab(Ea::taGuild); + socialWindow->removeTab(Ea::taParty); + } + + delete Ea::guildTab; + Ea::guildTab = nullptr; + + delete Ea::partyTab; + Ea::partyTab = nullptr; } } // namespace EAthena diff --git a/src/net/eathena/generalhandler.h b/src/net/eathena/generalhandler.h index 184f30bdc..d2fba855d 100644 --- a/src/net/eathena/generalhandler.h +++ b/src/net/eathena/generalhandler.h @@ -34,8 +34,7 @@ namespace EAthena { class GeneralHandler final : public MessageHandler, - public Net::GeneralHandler, - public Listener + public Net::GeneralHandler { public: GeneralHandler(); @@ -44,24 +43,23 @@ class GeneralHandler final : public MessageHandler, ~GeneralHandler(); - void handleMessage(Net::MessageIn &msg); + void handleMessage(Net::MessageIn &msg) override; - void load(); + void load() override; - void reload(); + void reload() override; - void unload(); + void unload() override; - void flushNetwork(); + void flushNetwork() override; - void clearHandlers(); + void clearHandlers() override; - void processEvent(Channels channel, - const DepricatedEvent &event) override; + void reloadPartially() override; - void reloadPartially(); + void gameStarted() const override; - void requestOnlineList(); + void gameEnded() const override; protected: MessageHandlerPtr mAdminHandler; diff --git a/src/net/generalhandler.h b/src/net/generalhandler.h index 24fbb9639..aeb8d8e09 100644 --- a/src/net/generalhandler.h +++ b/src/net/generalhandler.h @@ -44,6 +44,9 @@ class GeneralHandler virtual void reloadPartially() = 0; + virtual void gameStarted() const = 0; + + virtual void gameEnded() const = 0; }; } // namespace Net diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index f6a78372e..b1a555d4f 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -109,8 +109,6 @@ GeneralHandler::GeneralHandler() : stats.push_back(ItemDB::Stat("luck", _("Luck %+d"))); ItemDB::setStatsList(stats); - - listen(CHANNEL_GAME); } GeneralHandler::~GeneralHandler() @@ -122,12 +120,12 @@ GeneralHandler::~GeneralHandler() void GeneralHandler::handleMessage(Net::MessageIn &msg) { BLOCK_START("GeneralHandler::handleMessage") - int code; switch (msg.getId()) { case SMSG_CONNECTION_PROBLEM: - code = msg.readInt8(); + { + const int code = msg.readInt8(); logger->log("Connection problem: %i", code); switch (code) @@ -161,9 +159,11 @@ void GeneralHandler::handleMessage(Net::MessageIn &msg) } Client::setState(STATE_ERROR); break; + } default: break; + } BLOCK_END("GeneralHandler::handleMessage") } @@ -199,11 +199,10 @@ void GeneralHandler::reload() mNetwork->disconnect(); static_cast(mLoginHandler.get())->clearWorlds(); - static_cast( - mCharServerHandler.get())->setCharCreateDialog(nullptr); - static_cast( - mCharServerHandler.get())->setCharSelectDialog(nullptr); - + CharServerHandler *charHandler = static_cast( + mCharServerHandler.get()); + charHandler->setCharCreateDialog(nullptr); + charHandler->setCharSelectDialog(nullptr); static_cast(mPartyHandler.get())->reload(); } @@ -246,66 +245,55 @@ void GeneralHandler::clearHandlers() mNetwork->clearHandlers(); } -void GeneralHandler::processEvent(Channels channel, - const DepricatedEvent &event) +void GeneralHandler::gameStarted() const { - if (channel == CHANNEL_GAME) - { - if (event.getName() == EVENT_GUIWINDOWSLOADED) - { - if (inventoryWindow) - inventoryWindow->setSplitAllowed(false); - if (skillDialog) - skillDialog->loadSkills(); - - if (!statusWindow) - return; - - // protection against double addition attributes. - statusWindow->clearAttributes(); - - statusWindow->addAttribute(STR, _("Strength"), "str", true, ""); - statusWindow->addAttribute(AGI, _("Agility"), "agi", true, ""); - statusWindow->addAttribute(VIT, _("Vitality"), "vit", true, ""); - statusWindow->addAttribute(INT, _("Intelligence"), - "int", true, ""); - statusWindow->addAttribute(DEX, _("Dexterity"), "dex", true, ""); - statusWindow->addAttribute(LUK, _("Luck"), "luk", true, ""); - - statusWindow->addAttribute(ATK, _("Attack")); - statusWindow->addAttribute(DEF, _("Defense")); - statusWindow->addAttribute(MATK, _("M.Attack")); - statusWindow->addAttribute(MDEF, _("M.Defense")); - // xgettext:no-c-format - statusWindow->addAttribute(HIT, _("% Accuracy")); - // xgettext:no-c-format - statusWindow->addAttribute(FLEE, _("% Evade")); - // xgettext:no-c-format - statusWindow->addAttribute(CRIT, _("% Critical")); - statusWindow->addAttribute(PlayerInfo::ATTACK_DELAY, - _("Attack Delay")); - statusWindow->addAttribute(PlayerInfo::WALK_SPEED, - _("Walk Delay")); - statusWindow->addAttribute(PlayerInfo::ATTACK_RANGE, - _("Attack Range")); - statusWindow->addAttribute(PlayerInfo::ATTACK_SPEED, - _("Damage per sec.")); - } - else if (event.getName() == EVENT_GUIWINDOWSUNLOADING) - { - if (socialWindow) - { - socialWindow->removeTab(Ea::taGuild); - socialWindow->removeTab(Ea::taParty); - } + if (inventoryWindow) + inventoryWindow->setSplitAllowed(false); + if (skillDialog) + skillDialog->loadSkills(); - delete Ea::guildTab; - Ea::guildTab = nullptr; + if (!statusWindow) + return; - delete Ea::partyTab; - Ea::partyTab = nullptr; - } + // protection against double addition attributes. + statusWindow->clearAttributes(); + + statusWindow->addAttribute(STR, _("Strength"), "str", true, ""); + statusWindow->addAttribute(AGI, _("Agility"), "agi", true, ""); + statusWindow->addAttribute(VIT, _("Vitality"), "vit", true, ""); + statusWindow->addAttribute(INT, _("Intelligence"), "int", true, ""); + statusWindow->addAttribute(DEX, _("Dexterity"), "dex", true, ""); + statusWindow->addAttribute(LUK, _("Luck"), "luk", true, ""); + + statusWindow->addAttribute(ATK, _("Attack")); + statusWindow->addAttribute(DEF, _("Defense")); + statusWindow->addAttribute(MATK, _("M.Attack")); + statusWindow->addAttribute(MDEF, _("M.Defense")); + // xgettext:no-c-format + statusWindow->addAttribute(HIT, _("% Accuracy")); + // xgettext:no-c-format + statusWindow->addAttribute(FLEE, _("% Evade")); + // xgettext:no-c-format + statusWindow->addAttribute(CRIT, _("% Critical")); + statusWindow->addAttribute(PlayerInfo::ATTACK_DELAY, _("Attack Delay")); + statusWindow->addAttribute(PlayerInfo::WALK_SPEED, _("Walk Delay")); + statusWindow->addAttribute(PlayerInfo::ATTACK_RANGE, _("Attack Range")); + statusWindow->addAttribute(PlayerInfo::ATTACK_SPEED, _("Damage per sec.")); +} + +void GeneralHandler::gameEnded() const +{ + if (socialWindow) + { + socialWindow->removeTab(Ea::taGuild); + socialWindow->removeTab(Ea::taParty); } + + delete Ea::guildTab; + Ea::guildTab = nullptr; + + delete Ea::partyTab; + Ea::partyTab = nullptr; } } // namespace TmwAthena diff --git a/src/net/tmwa/generalhandler.h b/src/net/tmwa/generalhandler.h index e1254e18f..c25b7e7a3 100644 --- a/src/net/tmwa/generalhandler.h +++ b/src/net/tmwa/generalhandler.h @@ -33,8 +33,8 @@ namespace TmwAthena { -class GeneralHandler final : public MessageHandler, public Net::GeneralHandler, - public Listener +class GeneralHandler final : public MessageHandler, + public Net::GeneralHandler { public: GeneralHandler(); @@ -43,22 +43,23 @@ class GeneralHandler final : public MessageHandler, public Net::GeneralHandler, ~GeneralHandler(); - void handleMessage(Net::MessageIn &msg); + void handleMessage(Net::MessageIn &msg) override; - void load(); + void load() override; - void reload(); + void reload() override; - void unload(); + void unload() override; - void flushNetwork(); + void flushNetwork() override; - void clearHandlers(); + void clearHandlers() override; - void processEvent(Channels channel, - const DepricatedEvent &event) override; + void reloadPartially() override; - void reloadPartially(); + void gameStarted() const override; + + void gameEnded() const override; protected: MessageHandlerPtr mAdminHandler; -- cgit v1.2.3-60-g2f50