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/tmwa/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/partytab.h" |
32 |
|
|
|
33 |
|
|
#include "net/tmwa/adminhandler.h" |
34 |
|
|
#include "net/tmwa/beinghandler.h" |
35 |
|
|
#include "net/tmwa/buysellhandler.h" |
36 |
|
|
#include "net/tmwa/chathandler.h" |
37 |
|
|
#include "net/tmwa/clanhandler.h" |
38 |
|
|
#include "net/tmwa/charserverhandler.h" |
39 |
|
|
#include "net/tmwa/gamehandler.h" |
40 |
|
|
#include "net/tmwa/guildhandler.h" |
41 |
|
|
#include "net/tmwa/inventoryhandler.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" |
49 |
|
|
#include "net/tmwa/serverfeatures.h" |
50 |
|
|
#include "net/tmwa/tradehandler.h" |
51 |
|
|
#include "net/tmwa/skillhandler.h" |
52 |
|
|
#include "net/tmwa/questhandler.h" |
53 |
|
|
|
54 |
|
|
#include "net/tmwa/auctionhandler.h" |
55 |
|
|
#include "net/tmwa/achievementhandler.h" |
56 |
|
|
#include "net/tmwa/attendancehandler.h" |
57 |
|
|
#include "net/tmwa/bankhandler.h" |
58 |
|
|
#include "net/tmwa/barterhandler.h" |
59 |
|
|
#include "net/tmwa/battlegroundhandler.h" |
60 |
|
|
#include "net/tmwa/buyingstorehandler.h" |
61 |
|
|
#include "net/tmwa/cashshophandler.h" |
62 |
|
|
#include "net/tmwa/elementalhandler.h" |
63 |
|
|
#include "net/tmwa/familyhandler.h" |
64 |
|
|
#include "net/tmwa/friendshandler.h" |
65 |
|
|
#include "net/tmwa/homunculushandler.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" |
70 |
|
|
#include "net/tmwa/mercenaryhandler.h" |
71 |
|
|
#include "net/tmwa/refinehandler.h" |
72 |
|
|
#include "net/tmwa/roulettehandler.h" |
73 |
|
|
#include "net/tmwa/searchstorehandler.h" |
74 |
|
|
#include "net/tmwa/vendinghandler.h" |
75 |
|
|
|
76 |
|
|
#include "utils/delete2.h" |
77 |
|
|
#include "utils/gettext.h" |
78 |
|
|
|
79 |
|
|
#include "debug.h" |
80 |
|
|
|
81 |
|
|
namespace TmwAthena |
82 |
|
|
{ |
83 |
|
|
|
84 |
|
|
GeneralHandler::GeneralHandler() : |
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 |
|
|
|
130 |
|
|
GeneralHandler::~GeneralHandler() |
131 |
|
|
{ |
132 |
|
|
delete2(Network::mInstance) |
133 |
|
|
|
134 |
|
|
delete2(mAdminHandler) |
135 |
|
|
delete2(mBeingHandler) |
136 |
|
|
delete2(mBuySellHandler) |
137 |
|
|
delete2(mCharServerHandler) |
138 |
|
|
delete2(mChatHandler) |
139 |
|
|
delete2(mClanHandler) |
140 |
|
|
delete2(mGameHandler) |
141 |
|
|
delete2(mGuildHandler) |
142 |
|
|
delete2(mInventoryHandler) |
143 |
|
|
delete2(mItemHandler) |
144 |
|
|
delete2(mLoginHandler) |
145 |
|
|
delete2(mNpcHandler) |
146 |
|
|
delete2(mPartyHandler) |
147 |
|
|
delete2(mPetHandler) |
148 |
|
|
delete2(mPlayerHandler) |
149 |
|
|
delete2(mSkillHandler) |
150 |
|
|
delete2(mTradeHandler) |
151 |
|
|
delete2(mQuestHandler) |
152 |
|
|
delete2(mServerFeatures) |
153 |
|
|
delete2(mAuctionHandler) |
154 |
|
|
delete2(mAchievementHandler) |
155 |
|
|
delete2(mAttendanceHandler) |
156 |
|
|
delete2(mBankHandler) |
157 |
|
|
delete2(mBattleGroundHandler) |
158 |
|
|
delete2(mBuyingStoreHandler) |
159 |
|
|
delete2(mCashShopHandler) |
160 |
|
|
delete2(mElementalHandler) |
161 |
|
|
delete2(mFamilyHandler) |
162 |
|
|
delete2(mFriendsHandler) |
163 |
|
|
delete2(mHomunculusHandler) |
164 |
|
|
delete2(mMail2Handler) |
165 |
|
|
delete2(mMailHandler) |
166 |
|
|
delete2(mMapHandler) |
167 |
|
|
delete2(mMarketHandler) |
168 |
|
|
delete2(mBarterHandler) |
169 |
|
|
delete2(mMercenaryHandler) |
170 |
|
|
delete2(mRefineHandler) |
171 |
|
|
delete2(mRouletteHandler) |
172 |
|
|
delete2(mSearchStoreHandler) |
173 |
|
|
delete2(mVendingHandler) |
174 |
|
|
} |
175 |
|
|
|
176 |
|
|
void GeneralHandler::load() const |
177 |
|
|
{ |
178 |
|
|
new Network; |
179 |
|
|
Network::mInstance->registerHandlers(); |
180 |
|
|
} |
181 |
|
|
|
182 |
|
|
void GeneralHandler::reload() const |
183 |
|
|
{ |
184 |
|
|
if (Network::mInstance != nullptr) |
185 |
|
|
Network::mInstance->disconnect(); |
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); |
192 |
|
|
PartyHandler::reload(); |
193 |
|
|
} |
194 |
|
|
|
195 |
|
|
void GeneralHandler::reloadPartially() const |
196 |
|
|
{ |
197 |
|
|
PartyHandler::reload(); |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
void GeneralHandler::unload() const |
201 |
|
|
{ |
202 |
|
|
clearHandlers(); |
203 |
|
|
} |
204 |
|
|
|
205 |
|
|
void GeneralHandler::flushSend() const |
206 |
|
|
{ |
207 |
|
|
if (Network::mInstance == nullptr) |
208 |
|
|
return; |
209 |
|
|
|
210 |
|
|
Network::mInstance->flush(); |
211 |
|
|
} |
212 |
|
|
|
213 |
|
|
void GeneralHandler::flushNetwork() const |
214 |
|
|
{ |
215 |
|
|
if (Network::mInstance == nullptr) |
216 |
|
|
return; |
217 |
|
|
|
218 |
|
|
BLOCK_START("GeneralHandler::flushNetwork 1") |
219 |
|
|
Network::mInstance->flush(); |
220 |
|
|
BLOCK_END("GeneralHandler::flushNetwork 1") |
221 |
|
|
Network::mInstance->dispatchMessages(); |
222 |
|
|
|
223 |
|
|
BLOCK_START("GeneralHandler::flushNetwork 3") |
224 |
|
|
if (Network::mInstance->getState() == Network::NET_ERROR) |
225 |
|
|
{ |
226 |
|
|
if (!Network::mInstance->getError().empty()) |
227 |
|
|
{ |
228 |
|
|
errorMessage = Network::mInstance->getError(); |
229 |
|
|
} |
230 |
|
|
else |
231 |
|
|
{ |
232 |
|
|
// TRANSLATORS: error message |
233 |
|
|
errorMessage = _("Got disconnected from server!"); |
234 |
|
|
} |
235 |
|
|
|
236 |
|
|
client->setState(State::ERROR); |
237 |
|
|
} |
238 |
|
|
BLOCK_END("GeneralHandler::flushNetwork 3") |
239 |
|
|
} |
240 |
|
|
|
241 |
|
|
void GeneralHandler::clearHandlers() const |
242 |
|
|
{ |
243 |
|
|
if (Network::mInstance != nullptr) |
244 |
|
|
Network::mInstance->clearHandlers(); |
245 |
|
|
} |
246 |
|
|
|
247 |
|
|
void GeneralHandler::gameStarted() const |
248 |
|
|
{ |
249 |
|
|
if (skillDialog != nullptr) |
250 |
|
|
skillDialog->loadSkills(); |
251 |
|
|
} |
252 |
|
|
|
253 |
|
|
void GeneralHandler::gameEnded() const |
254 |
|
|
{ |
255 |
|
|
if (socialWindow != nullptr) |
256 |
|
|
socialWindow->removeTab(Ea::taParty); |
257 |
|
|
|
258 |
|
|
delete2(partyTab) |
259 |
|
|
} |
260 |
|
|
|
261 |
|
2 |
} // namespace TmwAthena |