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