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