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