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