GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/generalhandler.cpp Lines: 1 126 0.8 %
Date: 2019-06-27 Branches: 0 188 0.0 %

Line Branch Exec Source
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
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#include "net/eathena/generalhandler.h"
24
25
#include "client.h"
26
27
#include "gui/windows/skilldialog.h"
28
#include "gui/windows/socialwindow.h"
29
30
#include "gui/widgets/tabs/chat/clantab.h"
31
#include "gui/widgets/tabs/chat/guildtab.h"
32
#include "gui/widgets/tabs/chat/partytab.h"
33
34
#include "net/eathena/adminhandler.h"
35
#include "net/eathena/auctionhandler.h"
36
#include "net/eathena/achievementhandler.h"
37
#include "net/eathena/attendancehandler.h"
38
#include "net/eathena/bankhandler.h"
39
#include "net/eathena/barterhandler.h"
40
#include "net/eathena/battlegroundhandler.h"
41
#include "net/eathena/beinghandler.h"
42
#include "net/eathena/buyingstorehandler.h"
43
#include "net/eathena/buysellhandler.h"
44
#include "net/eathena/cashshophandler.h"
45
#include "net/eathena/chathandler.h"
46
#include "net/eathena/clanhandler.h"
47
#include "net/eathena/charserverhandler.h"
48
#include "net/eathena/elementalhandler.h"
49
#include "net/eathena/familyhandler.h"
50
#include "net/eathena/friendshandler.h"
51
#include "net/eathena/gamehandler.h"
52
#include "net/eathena/guildhandler.h"
53
#include "net/eathena/homunculushandler.h"
54
#include "net/eathena/inventoryhandler.h"
55
#include "net/eathena/itemhandler.h"
56
#include "net/eathena/loginhandler.h"
57
#include "net/eathena/maphandler.h"
58
#include "net/eathena/mail2handler.h"
59
#include "net/eathena/mailhandler.h"
60
#include "net/eathena/markethandler.h"
61
#include "net/eathena/mercenaryhandler.h"
62
#include "net/eathena/network.h"
63
#include "net/eathena/npchandler.h"
64
#include "net/eathena/partyhandler.h"
65
#include "net/eathena/pethandler.h"
66
#include "net/eathena/playerhandler.h"
67
#include "net/eathena/refinehandler.h"
68
#include "net/eathena/roulettehandler.h"
69
#include "net/eathena/searchstorehandler.h"
70
#include "net/eathena/serverfeatures.h"
71
#include "net/eathena/tradehandler.h"
72
#include "net/eathena/skillhandler.h"
73
#include "net/eathena/questhandler.h"
74
#include "net/eathena/vendinghandler.h"
75
76
#include "utils/delete2.h"
77
#include "utils/gettext.h"
78
79
#include "debug.h"
80
81
namespace EAthena
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
    mMail2Handler(new Mail2Handler),
105
    mMailHandler(new MailHandler),
106
    mAuctionHandler(new AuctionHandler),
107
    mAchievementHandler(new AchievementHandler),
108
    mAttendanceHandler(new AttendanceHandler),
109
    mCashShopHandler(new CashShopHandler),
110
    mFamilyHandler(new FamilyHandler),
111
    mBankHandler(new BankHandler),
112
    mBattleGroundHandler(new BattleGroundHandler),
113
    mMercenaryHandler(new MercenaryHandler),
114
    mBuyingStoreHandler(new BuyingStoreHandler),
115
    mHomunculusHandler(new HomunculusHandler),
116
    mFriendsHandler(new FriendsHandler),
117
    mElementalHandler(new ElementalHandler),
118
    mMapHandler(new MapHandler),
119
    mMarketHandler(new MarketHandler),
120
    mBarterHandler(new BarterHandler),
121
    mVendingHandler(new VendingHandler),
122
    mRefineHandler(new RefineHandler),
123
    mRouletteHandler(new RouletteHandler),
124
    mSearchStoreHandler(new SearchStoreHandler)
125
{
126
    generalHandler = this;
127
    logger->log("Creating eathena 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(mMail2Handler)
154
    delete2(mMailHandler)
155
    delete2(mAuctionHandler)
156
    delete2(mAchievementHandler)
157
    delete2(mAttendanceHandler)
158
    delete2(mCashShopHandler)
159
    delete2(mFamilyHandler)
160
    delete2(mBankHandler)
161
    delete2(mBattleGroundHandler)
162
    delete2(mMercenaryHandler)
163
    delete2(mBuyingStoreHandler)
164
    delete2(mHomunculusHandler)
165
    delete2(mFriendsHandler)
166
    delete2(mElementalHandler)
167
    delete2(mMapHandler)
168
    delete2(mMarketHandler)
169
    delete2(mBarterHandler)
170
    delete2(mVendingHandler)
171
    delete2(mRefineHandler)
172
    delete2(mRouletteHandler)
173
    delete2(mSearchStoreHandler)
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
    Network::mInstance->flush();
219
    Network::mInstance->dispatchMessages();
220
221
    if (Network::mInstance->getState() == Network::NET_ERROR)
222
    {
223
        if (!Network::mInstance->getError().empty())
224
        {
225
            errorMessage = Network::mInstance->getError();
226
        }
227
        else
228
        {
229
            // TRANSLATORS: error message
230
            errorMessage = _("Got disconnected from server!");
231
        }
232
233
        client->setState(State::ERROR);
234
    }
235
}
236
237
void GeneralHandler::clearHandlers() const
238
{
239
    if (Network::mInstance != nullptr)
240
        Network::mInstance->clearHandlers();
241
}
242
243
void GeneralHandler::gameStarted() const
244
{
245
    if (skillDialog != nullptr)
246
        skillDialog->loadSkills();
247
}
248
249
void GeneralHandler::gameEnded() const
250
{
251
    if (socialWindow != nullptr)
252
    {
253
        socialWindow->removeTab(taGuild);
254
        socialWindow->removeTab(Ea::taParty);
255
    }
256
257
    delete2(guildTab)
258
    delete2(partyTab)
259
    delete2(clanTab)
260
}
261
262
2
}  // namespace EAthena