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 |
|
|
|
24 |
|
|
#include "net/eathena/generalhandler.h" |
25 |
|
|
|
26 |
|
|
#include "client.h" |
27 |
|
|
|
28 |
|
|
#include "gui/windows/skilldialog.h" |
29 |
|
|
#include "gui/windows/socialwindow.h" |
30 |
|
|
|
31 |
|
|
#include "gui/widgets/tabs/chat/clantab.h" |
32 |
|
|
#include "gui/widgets/tabs/chat/guildtab.h" |
33 |
|
|
#include "gui/widgets/tabs/chat/partytab.h" |
34 |
|
|
|
35 |
|
|
#include "net/eathena/adminhandler.h" |
36 |
|
|
#include "net/eathena/auctionhandler.h" |
37 |
|
|
#include "net/eathena/achievementhandler.h" |
38 |
|
|
#include "net/eathena/attendancehandler.h" |
39 |
|
|
#include "net/eathena/bankhandler.h" |
40 |
|
|
#include "net/eathena/barterhandler.h" |
41 |
|
|
#include "net/eathena/battlegroundhandler.h" |
42 |
|
|
#include "net/eathena/beinghandler.h" |
43 |
|
|
#include "net/eathena/buyingstorehandler.h" |
44 |
|
|
#include "net/eathena/buysellhandler.h" |
45 |
|
|
#include "net/eathena/cashshophandler.h" |
46 |
|
|
#include "net/eathena/chathandler.h" |
47 |
|
|
#include "net/eathena/clanhandler.h" |
48 |
|
|
#include "net/eathena/charserverhandler.h" |
49 |
|
|
#include "net/eathena/elementalhandler.h" |
50 |
|
|
#include "net/eathena/familyhandler.h" |
51 |
|
|
#include "net/eathena/friendshandler.h" |
52 |
|
|
#include "net/eathena/gamehandler.h" |
53 |
|
|
#include "net/eathena/guildhandler.h" |
54 |
|
|
#include "net/eathena/homunculushandler.h" |
55 |
|
|
#include "net/eathena/inventoryhandler.h" |
56 |
|
|
#include "net/eathena/itemhandler.h" |
57 |
|
|
#include "net/eathena/loginhandler.h" |
58 |
|
|
#include "net/eathena/maphandler.h" |
59 |
|
|
#include "net/eathena/mail2handler.h" |
60 |
|
|
#include "net/eathena/mailhandler.h" |
61 |
|
|
#include "net/eathena/markethandler.h" |
62 |
|
|
#include "net/eathena/mercenaryhandler.h" |
63 |
|
|
#include "net/eathena/network.h" |
64 |
|
|
#include "net/eathena/npchandler.h" |
65 |
|
|
#include "net/eathena/partyhandler.h" |
66 |
|
|
#include "net/eathena/pethandler.h" |
67 |
|
|
#include "net/eathena/playerhandler.h" |
68 |
|
|
#include "net/eathena/refinehandler.h" |
69 |
|
|
#include "net/eathena/roulettehandler.h" |
70 |
|
|
#include "net/eathena/searchstorehandler.h" |
71 |
|
|
#include "net/eathena/serverfeatures.h" |
72 |
|
|
#include "net/eathena/tradehandler.h" |
73 |
|
|
#include "net/eathena/skillhandler.h" |
74 |
|
|
#include "net/eathena/questhandler.h" |
75 |
|
|
#include "net/eathena/vendinghandler.h" |
76 |
|
|
|
77 |
|
|
#include "utils/delete2.h" |
78 |
|
|
#include "utils/gettext.h" |
79 |
|
|
|
80 |
|
|
#include "debug.h" |
81 |
|
|
|
82 |
|
|
namespace EAthena |
83 |
|
|
{ |
84 |
|
|
|
85 |
|
|
GeneralHandler::GeneralHandler() : |
86 |
|
|
mAdminHandler(new AdminHandler), |
87 |
|
|
mBeingHandler(new BeingHandler), |
88 |
|
|
mBuySellHandler(new BuySellHandler), |
89 |
|
|
mCharServerHandler(new CharServerHandler), |
90 |
|
|
mChatHandler(new ChatHandler), |
91 |
|
|
mClanHandler(new ClanHandler), |
92 |
|
|
mGameHandler(new GameHandler), |
93 |
|
|
mGuildHandler(new GuildHandler), |
94 |
|
|
mInventoryHandler(new InventoryHandler), |
95 |
|
|
mItemHandler(new ItemHandler), |
96 |
|
|
mLoginHandler(new LoginHandler), |
97 |
|
|
mNpcHandler(new NpcHandler), |
98 |
|
|
mPartyHandler(new PartyHandler), |
99 |
|
|
mPetHandler(new PetHandler), |
100 |
|
|
mPlayerHandler(new PlayerHandler), |
101 |
|
|
mSkillHandler(new SkillHandler), |
102 |
|
|
mTradeHandler(new TradeHandler), |
103 |
|
|
mQuestHandler(new QuestHandler), |
104 |
|
|
mServerFeatures(new ServerFeatures), |
105 |
|
|
mMail2Handler(new Mail2Handler), |
106 |
|
|
mMailHandler(new MailHandler), |
107 |
|
|
mAuctionHandler(new AuctionHandler), |
108 |
|
|
mAchievementHandler(new AchievementHandler), |
109 |
|
|
mAttendanceHandler(new AttendanceHandler), |
110 |
|
|
mCashShopHandler(new CashShopHandler), |
111 |
|
|
mFamilyHandler(new FamilyHandler), |
112 |
|
|
mBankHandler(new BankHandler), |
113 |
|
|
mBattleGroundHandler(new BattleGroundHandler), |
114 |
|
|
mMercenaryHandler(new MercenaryHandler), |
115 |
|
|
mBuyingStoreHandler(new BuyingStoreHandler), |
116 |
|
|
mHomunculusHandler(new HomunculusHandler), |
117 |
|
|
mFriendsHandler(new FriendsHandler), |
118 |
|
|
mElementalHandler(new ElementalHandler), |
119 |
|
|
mMapHandler(new MapHandler), |
120 |
|
|
mMarketHandler(new MarketHandler), |
121 |
|
|
mBarterHandler(new BarterHandler), |
122 |
|
|
mVendingHandler(new VendingHandler), |
123 |
|
|
mRefineHandler(new RefineHandler), |
124 |
|
|
mRouletteHandler(new RouletteHandler), |
125 |
|
|
mSearchStoreHandler(new SearchStoreHandler) |
126 |
|
|
{ |
127 |
|
|
generalHandler = this; |
128 |
|
|
logger->log("Creating eathena handler"); |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
GeneralHandler::~GeneralHandler() |
132 |
|
|
{ |
133 |
|
|
delete2(Network::mInstance) |
134 |
|
|
|
135 |
|
|
delete2(mAdminHandler) |
136 |
|
|
delete2(mBeingHandler) |
137 |
|
|
delete2(mBuySellHandler) |
138 |
|
|
delete2(mCharServerHandler) |
139 |
|
|
delete2(mChatHandler) |
140 |
|
|
delete2(mClanHandler) |
141 |
|
|
delete2(mGameHandler) |
142 |
|
|
delete2(mGuildHandler) |
143 |
|
|
delete2(mInventoryHandler) |
144 |
|
|
delete2(mItemHandler) |
145 |
|
|
delete2(mLoginHandler) |
146 |
|
|
delete2(mNpcHandler) |
147 |
|
|
delete2(mPartyHandler) |
148 |
|
|
delete2(mPetHandler) |
149 |
|
|
delete2(mPlayerHandler) |
150 |
|
|
delete2(mSkillHandler) |
151 |
|
|
delete2(mTradeHandler) |
152 |
|
|
delete2(mQuestHandler) |
153 |
|
|
delete2(mServerFeatures) |
154 |
|
|
delete2(mMail2Handler) |
155 |
|
|
delete2(mMailHandler) |
156 |
|
|
delete2(mAuctionHandler) |
157 |
|
|
delete2(mAchievementHandler) |
158 |
|
|
delete2(mAttendanceHandler) |
159 |
|
|
delete2(mCashShopHandler) |
160 |
|
|
delete2(mFamilyHandler) |
161 |
|
|
delete2(mBankHandler) |
162 |
|
|
delete2(mBattleGroundHandler) |
163 |
|
|
delete2(mMercenaryHandler) |
164 |
|
|
delete2(mBuyingStoreHandler) |
165 |
|
|
delete2(mHomunculusHandler) |
166 |
|
|
delete2(mFriendsHandler) |
167 |
|
|
delete2(mElementalHandler) |
168 |
|
|
delete2(mMapHandler) |
169 |
|
|
delete2(mMarketHandler) |
170 |
|
|
delete2(mBarterHandler) |
171 |
|
|
delete2(mVendingHandler) |
172 |
|
|
delete2(mRefineHandler) |
173 |
|
|
delete2(mRouletteHandler) |
174 |
|
|
delete2(mSearchStoreHandler) |
175 |
|
|
} |
176 |
|
|
|
177 |
|
|
void GeneralHandler::load() const |
178 |
|
|
{ |
179 |
|
|
new Network; |
180 |
|
|
Network::mInstance->registerHandlers(); |
181 |
|
|
} |
182 |
|
|
|
183 |
|
|
void GeneralHandler::reload() const |
184 |
|
|
{ |
185 |
|
|
if (Network::mInstance != nullptr) |
186 |
|
|
Network::mInstance->disconnect(); |
187 |
|
|
|
188 |
|
|
static_cast<LoginHandler*>(mLoginHandler)->clearWorlds(); |
189 |
|
|
const CharServerHandler *const charHandler = |
190 |
|
|
static_cast<CharServerHandler*>(mCharServerHandler); |
191 |
|
|
charHandler->setCharCreateDialog(nullptr); |
192 |
|
|
charHandler->setCharSelectDialog(nullptr); |
193 |
|
|
PartyHandler::reload(); |
194 |
|
|
} |
195 |
|
|
|
196 |
|
|
void GeneralHandler::reloadPartially() const |
197 |
|
|
{ |
198 |
|
|
PartyHandler::reload(); |
199 |
|
|
} |
200 |
|
|
|
201 |
|
|
void GeneralHandler::unload() const |
202 |
|
|
{ |
203 |
|
|
clearHandlers(); |
204 |
|
|
} |
205 |
|
|
|
206 |
|
|
void GeneralHandler::flushSend() const |
207 |
|
|
{ |
208 |
|
|
if (Network::mInstance == nullptr) |
209 |
|
|
return; |
210 |
|
|
|
211 |
|
|
Network::mInstance->flush(); |
212 |
|
|
} |
213 |
|
|
|
214 |
|
|
void GeneralHandler::flushNetwork() const |
215 |
|
|
{ |
216 |
|
|
if (Network::mInstance == nullptr) |
217 |
|
|
return; |
218 |
|
|
|
219 |
|
|
Network::mInstance->flush(); |
220 |
|
|
Network::mInstance->dispatchMessages(); |
221 |
|
|
|
222 |
|
|
if (Network::mInstance->getState() == Network::NET_ERROR) |
223 |
|
|
{ |
224 |
|
|
if (!Network::mInstance->getError().empty()) |
225 |
|
|
{ |
226 |
|
|
errorMessage = Network::mInstance->getError(); |
227 |
|
|
} |
228 |
|
|
else |
229 |
|
|
{ |
230 |
|
|
// TRANSLATORS: error message |
231 |
|
|
errorMessage = _("Got disconnected from server!"); |
232 |
|
|
} |
233 |
|
|
|
234 |
|
|
client->setState(State::ERROR); |
235 |
|
|
} |
236 |
|
|
} |
237 |
|
|
|
238 |
|
|
void GeneralHandler::clearHandlers() const |
239 |
|
|
{ |
240 |
|
|
if (Network::mInstance != nullptr) |
241 |
|
|
Network::mInstance->clearHandlers(); |
242 |
|
|
} |
243 |
|
|
|
244 |
|
|
void GeneralHandler::gameStarted() const |
245 |
|
|
{ |
246 |
|
|
if (skillDialog != nullptr) |
247 |
|
|
skillDialog->loadSkills(); |
248 |
|
|
} |
249 |
|
|
|
250 |
|
|
void GeneralHandler::gameEnded() const |
251 |
|
|
{ |
252 |
|
|
if (socialWindow != nullptr) |
253 |
|
|
{ |
254 |
|
|
socialWindow->removeTab(taGuild); |
255 |
|
|
socialWindow->removeTab(Ea::taParty); |
256 |
|
|
} |
257 |
|
|
|
258 |
|
|
delete2(guildTab) |
259 |
|
|
delete2(partyTab) |
260 |
|
|
delete2(clanTab) |
261 |
|
|
} |
262 |
|
|
|
263 |
|
2 |
} // namespace EAthena |