GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/tmwa/generalhandler.cpp Lines: 1 123 0.8 %
Date: 2019-08-19 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-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/tmwa/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/partytab.h"
31
32
#include "net/tmwa/adminhandler.h"
33
#include "net/tmwa/beinghandler.h"
34
#include "net/tmwa/buysellhandler.h"
35
#include "net/tmwa/chathandler.h"
36
#include "net/tmwa/clanhandler.h"
37
#include "net/tmwa/charserverhandler.h"
38
#include "net/tmwa/gamehandler.h"
39
#include "net/tmwa/guildhandler.h"
40
#include "net/tmwa/inventoryhandler.h"
41
#include "net/tmwa/itemhandler.h"
42
#include "net/tmwa/loginhandler.h"
43
#include "net/tmwa/network.h"
44
#include "net/tmwa/npchandler.h"
45
#include "net/tmwa/partyhandler.h"
46
#include "net/tmwa/pethandler.h"
47
#include "net/tmwa/playerhandler.h"
48
#include "net/tmwa/serverfeatures.h"
49
#include "net/tmwa/tradehandler.h"
50
#include "net/tmwa/skillhandler.h"
51
#include "net/tmwa/questhandler.h"
52
53
#include "net/tmwa/auctionhandler.h"
54
#include "net/tmwa/achievementhandler.h"
55
#include "net/tmwa/attendancehandler.h"
56
#include "net/tmwa/bankhandler.h"
57
#include "net/tmwa/barterhandler.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/refinehandler.h"
71
#include "net/tmwa/roulettehandler.h"
72
#include "net/tmwa/searchstorehandler.h"
73
#include "net/tmwa/vendinghandler.h"
74
75
#include "utils/delete2.h"
76
#include "utils/gettext.h"
77
78
#include "debug.h"
79
80
namespace TmwAthena
81
{
82
83
GeneralHandler::GeneralHandler() :
84
    mAdminHandler(new AdminHandler),
85
    mBeingHandler(new BeingHandler),
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
    mAuctionHandler(new AuctionHandler),
104
    mAchievementHandler(new AchievementHandler),
105
    mAttendanceHandler(new AttendanceHandler),
106
    mBankHandler(new BankHandler),
107
    mBattleGroundHandler(new BattleGroundHandler),
108
    mBuyingStoreHandler(new BuyingStoreHandler),
109
    mCashShopHandler(new CashShopHandler),
110
    mElementalHandler(new ElementalHandler),
111
    mFamilyHandler(new FamilyHandler),
112
    mFriendsHandler(new FriendsHandler),
113
    mHomunculusHandler(new HomunculusHandler),
114
    mMail2Handler(new Mail2Handler),
115
    mMailHandler(new MailHandler),
116
    mMapHandler(new MapHandler),
117
    mMarketHandler(new MarketHandler),
118
    mBarterHandler(new BarterHandler),
119
    mMercenaryHandler(new MercenaryHandler),
120
    mRefineHandler(new RefineHandler),
121
    mRouletteHandler(new RouletteHandler),
122
    mSearchStoreHandler(new SearchStoreHandler),
123
    mVendingHandler(new VendingHandler)
124
{
125
    generalHandler = this;
126
    logger->log("Creating tmwa handler");
127
}
128
129
GeneralHandler::~GeneralHandler()
130
{
131
    delete2(Network::mInstance)
132
133
    delete2(mAdminHandler)
134
    delete2(mBeingHandler)
135
    delete2(mBuySellHandler)
136
    delete2(mCharServerHandler)
137
    delete2(mChatHandler)
138
    delete2(mClanHandler)
139
    delete2(mGameHandler)
140
    delete2(mGuildHandler)
141
    delete2(mInventoryHandler)
142
    delete2(mItemHandler)
143
    delete2(mLoginHandler)
144
    delete2(mNpcHandler)
145
    delete2(mPartyHandler)
146
    delete2(mPetHandler)
147
    delete2(mPlayerHandler)
148
    delete2(mSkillHandler)
149
    delete2(mTradeHandler)
150
    delete2(mQuestHandler)
151
    delete2(mServerFeatures)
152
    delete2(mAuctionHandler)
153
    delete2(mAchievementHandler)
154
    delete2(mAttendanceHandler)
155
    delete2(mBankHandler)
156
    delete2(mBattleGroundHandler)
157
    delete2(mBuyingStoreHandler)
158
    delete2(mCashShopHandler)
159
    delete2(mElementalHandler)
160
    delete2(mFamilyHandler)
161
    delete2(mFriendsHandler)
162
    delete2(mHomunculusHandler)
163
    delete2(mMail2Handler)
164
    delete2(mMailHandler)
165
    delete2(mMapHandler)
166
    delete2(mMarketHandler)
167
    delete2(mBarterHandler)
168
    delete2(mMercenaryHandler)
169
    delete2(mRefineHandler)
170
    delete2(mRouletteHandler)
171
    delete2(mSearchStoreHandler)
172
    delete2(mVendingHandler)
173
}
174
175
void GeneralHandler::load() const
176
{
177
    new Network;
178
    Network::mInstance->registerHandlers();
179
}
180
181
void GeneralHandler::reload() const
182
{
183
    if (Network::mInstance != nullptr)
184
        Network::mInstance->disconnect();
185
186
    static_cast<LoginHandler*>(mLoginHandler)->clearWorlds();
187
    const CharServerHandler *const charHandler =
188
        static_cast<CharServerHandler*>(mCharServerHandler);
189
    charHandler->setCharCreateDialog(nullptr);
190
    charHandler->setCharSelectDialog(nullptr);
191
    PartyHandler::reload();
192
}
193
194
void GeneralHandler::reloadPartially() const
195
{
196
    PartyHandler::reload();
197
}
198
199
void GeneralHandler::unload() const
200
{
201
    clearHandlers();
202
}
203
204
void GeneralHandler::flushSend() const
205
{
206
    if (Network::mInstance == nullptr)
207
        return;
208
209
    Network::mInstance->flush();
210
}
211
212
void GeneralHandler::flushNetwork() const
213
{
214
    if (Network::mInstance == nullptr)
215
        return;
216
217
    BLOCK_START("GeneralHandler::flushNetwork 1")
218
    Network::mInstance->flush();
219
    BLOCK_END("GeneralHandler::flushNetwork 1")
220
    Network::mInstance->dispatchMessages();
221
222
    BLOCK_START("GeneralHandler::flushNetwork 3")
223
    if (Network::mInstance->getState() == Network::NET_ERROR)
224
    {
225
        if (!Network::mInstance->getError().empty())
226
        {
227
            errorMessage = Network::mInstance->getError();
228
        }
229
        else
230
        {
231
            // TRANSLATORS: error message
232
            errorMessage = _("Got disconnected from server!");
233
        }
234
235
        client->setState(State::ERROR);
236
    }
237
    BLOCK_END("GeneralHandler::flushNetwork 3")
238
}
239
240
void GeneralHandler::clearHandlers() const
241
{
242
    if (Network::mInstance != nullptr)
243
        Network::mInstance->clearHandlers();
244
}
245
246
void GeneralHandler::gameStarted() const
247
{
248
    if (skillDialog != nullptr)
249
        skillDialog->loadSkills();
250
}
251
252
void GeneralHandler::gameEnded() const
253
{
254
    if (socialWindow != nullptr)
255
        socialWindow->removeTab(Ea::taParty);
256
257
    delete2(partyTab)
258
}
259
260
2
}  // namespace TmwAthena