ManaPlus
generalhandler.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
25 
26 #include "client.h"
27 
30 
32 
33 #include "net/tmwa/adminhandler.h"
34 #include "net/tmwa/beinghandler.h"
36 #include "net/tmwa/chathandler.h"
37 #include "net/tmwa/clanhandler.h"
39 #include "net/tmwa/gamehandler.h"
40 #include "net/tmwa/guildhandler.h"
42 #include "net/tmwa/itemhandler.h"
43 #include "net/tmwa/loginhandler.h"
44 #include "net/tmwa/network.h"
45 #include "net/tmwa/npchandler.h"
46 #include "net/tmwa/partyhandler.h"
47 #include "net/tmwa/pethandler.h"
48 #include "net/tmwa/playerhandler.h"
50 #include "net/tmwa/tradehandler.h"
51 #include "net/tmwa/skillhandler.h"
52 #include "net/tmwa/questhandler.h"
53 
57 #include "net/tmwa/bankhandler.h"
58 #include "net/tmwa/barterhandler.h"
63 #include "net/tmwa/familyhandler.h"
66 #include "net/tmwa/mail2handler.h"
67 #include "net/tmwa/mailhandler.h"
68 #include "net/tmwa/maphandler.h"
69 #include "net/tmwa/markethandler.h"
71 #include "net/tmwa/refinehandler.h"
75 
76 #include "utils/delete2.h"
77 #include "utils/gettext.h"
78 
79 #include "debug.h"
80 
81 namespace TmwAthena
82 {
83 
85  mAdminHandler(new AdminHandler),
86  mBeingHandler(new BeingHandler),
87  mBuySellHandler(new BuySellHandler),
88  mCharServerHandler(new CharServerHandler),
89  mChatHandler(new ChatHandler),
90  mClanHandler(new ClanHandler),
91  mGameHandler(new GameHandler),
92  mGuildHandler(new GuildHandler),
93  mInventoryHandler(new InventoryHandler),
94  mItemHandler(new ItemHandler),
95  mLoginHandler(new LoginHandler),
96  mNpcHandler(new NpcHandler),
97  mPartyHandler(new PartyHandler),
98  mPetHandler(new PetHandler),
99  mPlayerHandler(new PlayerHandler),
100  mSkillHandler(new SkillHandler),
101  mTradeHandler(new TradeHandler),
102  mQuestHandler(new QuestHandler),
103  mServerFeatures(new ServerFeatures),
104  mAuctionHandler(new AuctionHandler),
105  mAchievementHandler(new AchievementHandler),
106  mAttendanceHandler(new AttendanceHandler),
107  mBankHandler(new BankHandler),
108  mBattleGroundHandler(new BattleGroundHandler),
109  mBuyingStoreHandler(new BuyingStoreHandler),
110  mCashShopHandler(new CashShopHandler),
111  mElementalHandler(new ElementalHandler),
112  mFamilyHandler(new FamilyHandler),
113  mFriendsHandler(new FriendsHandler),
114  mHomunculusHandler(new HomunculusHandler),
115  mMail2Handler(new Mail2Handler),
116  mMailHandler(new MailHandler),
117  mMapHandler(new MapHandler),
118  mMarketHandler(new MarketHandler),
119  mBarterHandler(new BarterHandler),
120  mMercenaryHandler(new MercenaryHandler),
121  mRefineHandler(new RefineHandler),
122  mRouletteHandler(new RouletteHandler),
123  mSearchStoreHandler(new SearchStoreHandler),
124  mVendingHandler(new VendingHandler)
125 {
126  generalHandler = this;
127  logger->log("Creating tmwa handler");
128 }
129 
131 {
133 
174 }
175 
177 {
178  new Network;
180 }
181 
183 {
184  if (Network::mInstance != nullptr)
186 
187  static_cast<LoginHandler*>(mLoginHandler)->clearWorlds();
188  const CharServerHandler *const charHandler =
189  static_cast<CharServerHandler*>(mCharServerHandler);
190  charHandler->setCharCreateDialog(nullptr);
191  charHandler->setCharSelectDialog(nullptr);
193 }
194 
196 {
198 }
199 
201 {
202  clearHandlers();
203 }
204 
206 {
207  if (Network::mInstance == nullptr)
208  return;
209 
211 }
212 
214 {
215  if (Network::mInstance == nullptr)
216  return;
217 
218  BLOCK_START("GeneralHandler::flushNetwork 1")
220  BLOCK_END("GeneralHandler::flushNetwork 1")
222 
223  BLOCK_START("GeneralHandler::flushNetwork 3")
224  if (Network::mInstance->getState() == Network::NET_ERROR)
225  {
227  {
229  }
230  else
231  {
232  // TRANSLATORS: error message
233  errorMessage = _("Got disconnected from server!");
234  }
235 
237  }
238  BLOCK_END("GeneralHandler::flushNetwork 3")
239 }
240 
242 {
243  if (Network::mInstance != nullptr)
245 }
246 
248 {
249  if (skillDialog != nullptr)
251 }
252 
254 {
255  if (socialWindow != nullptr)
257 
259 }
260 
261 } // namespace TmwAthena
void setState(const StateT state)
Definition: client.h:66
void setCharSelectDialog(CharSelectDialog *const window) const
void flush()
Definition: network.cpp:157
const std::string & getError() const
Definition: network.h:58
@ NET_ERROR
Definition: network.h:83
void disconnect()
Definition: network.cpp:139
static void reload()
void log(const char *const log_text,...)
Definition: logger.cpp:269
void loadSkills()
bool removeTab(Guild *const guild)
void setCharCreateDialog(CharCreateDialog *const window) const
BuyingStoreHandler * mBuyingStoreHandler
AdminHandler * mAdminHandler
RouletteHandler * mRouletteHandler
LoginHandler * mLoginHandler
InventoryHandler * mInventoryHandler
ElementalHandler * mElementalHandler
RefineHandler * mRefineHandler
PartyHandler * mPartyHandler
GuildHandler * mGuildHandler
AttendanceHandler * mAttendanceHandler
FamilyHandler * mFamilyHandler
PlayerHandler * mPlayerHandler
HomunculusHandler * mHomunculusHandler
TradeHandler * mTradeHandler
MarketHandler * mMarketHandler
BattleGroundHandler * mBattleGroundHandler
VendingHandler * mVendingHandler
AchievementHandler * mAchievementHandler
QuestHandler * mQuestHandler
SkillHandler * mSkillHandler
FriendsHandler * mFriendsHandler
CashShopHandler * mCashShopHandler
BeingHandler * mBeingHandler
ServerFeatures * mServerFeatures
BarterHandler * mBarterHandler
BuySellHandler * mBuySellHandler
CharServerHandler * mCharServerHandler
MercenaryHandler * mMercenaryHandler
AuctionHandler * mAuctionHandler
Mail2Handler * mMail2Handler
SearchStoreHandler * mSearchStoreHandler
void registerHandlers()
Definition: network.cpp:87
void dispatchMessages()
Definition: network.cpp:104
static Network * mInstance
Definition: network.h:54
void clearHandlers()
Definition: network.cpp:93
#define new
Definition: debug_new.h:147
#define delete2(var)
Definition: delete2.h:25
Client * client
Definition: client.cpp:118
std::string errorMessage
Definition: client.cpp:116
Net::GeneralHandler * generalHandler
Definition: net.cpp:88
#define _(s)
Definition: gettext.h:35
Logger * logger
Definition: logger.cpp:89
Party * taParty
Definition: partyrecv.cpp:48
@ ERROR
Definition: state.h:35
const char * getError()
Definition: sdltcpnet.cpp:99
PartyTab * partyTab
Definition: partytab.cpp:45
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
std::string empty
Definition: podict.cpp:26
SkillDialog * skillDialog
Definition: skilldialog.cpp:66
SocialWindow * socialWindow