GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/tmwa/generalhandler.cpp Lines: 1 117 0.9 %
Date: 2018-09-20 Branches: 0 176 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
    logger->log("Creating tmwa handler");
122
}
123
124
GeneralHandler::~GeneralHandler()
125
{
126
    delete2(Network::mInstance);
127
128
    delete2(mAdminHandler);
129
    delete2(mBeingHandler);
130
    delete2(mBuySellHandler);
131
    delete2(mCharServerHandler);
132
    delete2(mChatHandler);
133
    delete2(mClanHandler);
134
    delete2(mGameHandler);
135
    delete2(mGuildHandler);
136
    delete2(mInventoryHandler);
137
    delete2(mItemHandler);
138
    delete2(mLoginHandler);
139
    delete2(mNpcHandler);
140
    delete2(mPartyHandler);
141
    delete2(mPetHandler);
142
    delete2(mPlayerHandler);
143
    delete2(mSkillHandler);
144
    delete2(mTradeHandler);
145
    delete2(mQuestHandler);
146
    delete2(mServerFeatures);
147
    delete2(mAuctionHandler);
148
    delete2(mAttendanceHandler);
149
    delete2(mBankHandler);
150
    delete2(mBattleGroundHandler);
151
    delete2(mBuyingStoreHandler);
152
    delete2(mCashShopHandler);
153
    delete2(mElementalHandler);
154
    delete2(mFamilyHandler);
155
    delete2(mFriendsHandler);
156
    delete2(mHomunculusHandler);
157
    delete2(mMail2Handler);
158
    delete2(mMailHandler);
159
    delete2(mMapHandler);
160
    delete2(mMarketHandler);
161
    delete2(mMercenaryHandler);
162
    delete2(mRouletteHandler);
163
    delete2(mSearchStoreHandler);
164
    delete2(mVendingHandler);
165
}
166
167
void GeneralHandler::load() const
168
{
169
    new Network;
170
    Network::mInstance->registerHandlers();
171
}
172
173
void GeneralHandler::reload() const
174
{
175
    if (Network::mInstance != nullptr)
176
        Network::mInstance->disconnect();
177
178
    static_cast<LoginHandler*>(mLoginHandler)->clearWorlds();
179
    const CharServerHandler *const charHandler =
180
        static_cast<CharServerHandler*>(mCharServerHandler);
181
    charHandler->setCharCreateDialog(nullptr);
182
    charHandler->setCharSelectDialog(nullptr);
183
    PartyHandler::reload();
184
}
185
186
void GeneralHandler::reloadPartially() const
187
{
188
    PartyHandler::reload();
189
}
190
191
void GeneralHandler::unload() const
192
{
193
    clearHandlers();
194
}
195
196
void GeneralHandler::flushSend() const
197
{
198
    if (Network::mInstance == nullptr)
199
        return;
200
201
    Network::mInstance->flush();
202
}
203
204
void GeneralHandler::flushNetwork() const
205
{
206
    if (Network::mInstance == nullptr)
207
        return;
208
209
    BLOCK_START("GeneralHandler::flushNetwork 1")
210
    Network::mInstance->flush();
211
    BLOCK_END("GeneralHandler::flushNetwork 1")
212
    Network::mInstance->dispatchMessages();
213
214
    BLOCK_START("GeneralHandler::flushNetwork 3")
215
    if (Network::mInstance->getState() == Network::NET_ERROR)
216
    {
217
        if (!Network::mInstance->getError().empty())
218
        {
219
            errorMessage = Network::mInstance->getError();
220
        }
221
        else
222
        {
223
            // TRANSLATORS: error message
224
            errorMessage = _("Got disconnected from server!");
225
        }
226
227
        client->setState(State::ERROR);
228
    }
229
    BLOCK_END("GeneralHandler::flushNetwork 3")
230
}
231
232
void GeneralHandler::clearHandlers() const
233
{
234
    if (Network::mInstance != nullptr)
235
        Network::mInstance->clearHandlers();
236
}
237
238
void GeneralHandler::gameStarted() const
239
{
240
    if (skillDialog != nullptr)
241
        skillDialog->loadSkills();
242
}
243
244
void GeneralHandler::gameEnded() const
245
{
246
    if (socialWindow != nullptr)
247
        socialWindow->removeTab(Ea::taParty);
248
249
    delete2(partyTab);
250
}
251
252
2
}  // namespace TmwAthena