GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/generalhandler.cpp Lines: 1 122 0.8 %
Date: 2018-12-09 Branches: 0 184 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-2018  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
#include "configuration.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/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/roulettehandler.h"
68
#include "net/eathena/searchstorehandler.h"
69
#include "net/eathena/serverfeatures.h"
70
#include "net/eathena/tradehandler.h"
71
#include "net/eathena/skillhandler.h"
72
#include "net/eathena/questhandler.h"
73
#include "net/eathena/vendinghandler.h"
74
75
#include "utils/delete2.h"
76
#include "utils/gettext.h"
77
78
#include "debug.h"
79
80
namespace EAthena
81
{
82
83
GeneralHandler::GeneralHandler() :
84
    mAdminHandler(new AdminHandler),
85
    mBeingHandler(new BeingHandler(config.getBoolValue("EnableSync"))),
86
    mBuySellHandler(new BuySellHandler),
87
    mCharServerHandler(new CharServerHandler),
88
    mChatHandler(new ChatHandler),
89
    mClanHandler(new ClanHandler),
90
    mGameHandler(new GameHandler),
91
    mGuildHandler(new GuildHandler),
92
    mInventoryHandler(new InventoryHandler),
93
    mItemHandler(new ItemHandler),
94
    mLoginHandler(new LoginHandler),
95
    mNpcHandler(new NpcHandler),
96
    mPartyHandler(new PartyHandler),
97
    mPetHandler(new PetHandler),
98
    mPlayerHandler(new PlayerHandler),
99
    mSkillHandler(new SkillHandler),
100
    mTradeHandler(new TradeHandler),
101
    mQuestHandler(new QuestHandler),
102
    mServerFeatures(new ServerFeatures),
103
    mMail2Handler(new Mail2Handler),
104
    mMailHandler(new MailHandler),
105
    mAuctionHandler(new AuctionHandler),
106
    mAchievementHandler(new AchievementHandler),
107
    mAttendanceHandler(new AttendanceHandler),
108
    mCashShopHandler(new CashShopHandler),
109
    mFamilyHandler(new FamilyHandler),
110
    mBankHandler(new BankHandler),
111
    mBattleGroundHandler(new BattleGroundHandler),
112
    mMercenaryHandler(new MercenaryHandler),
113
    mBuyingStoreHandler(new BuyingStoreHandler),
114
    mHomunculusHandler(new HomunculusHandler),
115
    mFriendsHandler(new FriendsHandler),
116
    mElementalHandler(new ElementalHandler),
117
    mMapHandler(new MapHandler),
118
    mMarketHandler(new MarketHandler),
119
    mVendingHandler(new VendingHandler),
120
    mRouletteHandler(new RouletteHandler),
121
    mSearchStoreHandler(new SearchStoreHandler)
122
{
123
    generalHandler = this;
124
    logger->log("Creating eathena handler");
125
}
126
127
GeneralHandler::~GeneralHandler()
128
{
129
    delete2(Network::mInstance)
130
131
    delete2(mAdminHandler)
132
    delete2(mBeingHandler)
133
    delete2(mBuySellHandler)
134
    delete2(mCharServerHandler)
135
    delete2(mChatHandler)
136
    delete2(mClanHandler)
137
    delete2(mGameHandler)
138
    delete2(mGuildHandler)
139
    delete2(mInventoryHandler)
140
    delete2(mItemHandler)
141
    delete2(mLoginHandler)
142
    delete2(mNpcHandler)
143
    delete2(mPartyHandler)
144
    delete2(mPetHandler)
145
    delete2(mPlayerHandler)
146
    delete2(mSkillHandler)
147
    delete2(mTradeHandler)
148
    delete2(mQuestHandler)
149
    delete2(mServerFeatures)
150
    delete2(mMail2Handler)
151
    delete2(mMailHandler)
152
    delete2(mAuctionHandler)
153
    delete2(mAchievementHandler)
154
    delete2(mAttendanceHandler)
155
    delete2(mCashShopHandler)
156
    delete2(mFamilyHandler)
157
    delete2(mBankHandler)
158
    delete2(mBattleGroundHandler)
159
    delete2(mMercenaryHandler)
160
    delete2(mBuyingStoreHandler)
161
    delete2(mHomunculusHandler)
162
    delete2(mFriendsHandler)
163
    delete2(mElementalHandler)
164
    delete2(mMapHandler)
165
    delete2(mMarketHandler)
166
    delete2(mVendingHandler)
167
    delete2(mRouletteHandler)
168
    delete2(mSearchStoreHandler)
169
}
170
171
void GeneralHandler::load() const
172
{
173
    new Network;
174
    Network::mInstance->registerHandlers();
175
}
176
177
void GeneralHandler::reload() const
178
{
179
    if (Network::mInstance != nullptr)
180
        Network::mInstance->disconnect();
181
182
    static_cast<LoginHandler*>(mLoginHandler)->clearWorlds();
183
    const CharServerHandler *const charHandler =
184
        static_cast<CharServerHandler*>(mCharServerHandler);
185
    charHandler->setCharCreateDialog(nullptr);
186
    charHandler->setCharSelectDialog(nullptr);
187
    PartyHandler::reload();
188
}
189
190
void GeneralHandler::reloadPartially() const
191
{
192
    PartyHandler::reload();
193
}
194
195
void GeneralHandler::unload() const
196
{
197
    clearHandlers();
198
}
199
200
void GeneralHandler::flushSend() const
201
{
202
    if (Network::mInstance == nullptr)
203
        return;
204
205
    Network::mInstance->flush();
206
}
207
208
void GeneralHandler::flushNetwork() const
209
{
210
    if (Network::mInstance == nullptr)
211
        return;
212
213
    Network::mInstance->flush();
214
    Network::mInstance->dispatchMessages();
215
216
    if (Network::mInstance->getState() == Network::NET_ERROR)
217
    {
218
        if (!Network::mInstance->getError().empty())
219
        {
220
            errorMessage = Network::mInstance->getError();
221
        }
222
        else
223
        {
224
            // TRANSLATORS: error message
225
            errorMessage = _("Got disconnected from server!");
226
        }
227
228
        client->setState(State::ERROR);
229
    }
230
}
231
232
void GeneralHandler::clearHandlers() const
233
{
234
    if (Network::mInstance != nullptr)
235
        Network::mInstance->clearHandlers();
236
}
237
238
void GeneralHandler::gameStarted() const
239
{
240
    if (skillDialog != nullptr)
241
        skillDialog->loadSkills();
242
}
243
244
void GeneralHandler::gameEnded() const
245
{
246
    if (socialWindow != nullptr)
247
    {
248
        socialWindow->removeTab(taGuild);
249
        socialWindow->removeTab(Ea::taParty);
250
    }
251
252
    delete2(guildTab)
253
    delete2(partyTab)
254
    delete2(clanTab)
255
}
256
257
2
}  // namespace EAthena