GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/tmwa/generalhandler.cpp Lines: 1 112 0.9 %
Date: 2017-11-29 Branches: 0 170 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/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/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/bankhandler.h"
55
#include "net/tmwa/battlegroundhandler.h"
56
#include "net/tmwa/buyingstorehandler.h"
57
#include "net/tmwa/cashshophandler.h"
58
#include "net/tmwa/elementalhandler.h"
59
#include "net/tmwa/familyhandler.h"
60
#include "net/tmwa/friendshandler.h"
61
#include "net/tmwa/homunculushandler.h"
62
#include "net/tmwa/mail2handler.h"
63
#include "net/tmwa/mailhandler.h"
64
#include "net/tmwa/maphandler.h"
65
#include "net/tmwa/markethandler.h"
66
#include "net/tmwa/mercenaryhandler.h"
67
#include "net/tmwa/roulettehandler.h"
68
#include "net/tmwa/searchstorehandler.h"
69
#include "net/tmwa/vendinghandler.h"
70
71
#include "utils/delete2.h"
72
#include "utils/gettext.h"
73
74
#include "debug.h"
75
76
namespace TmwAthena
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
    mAuctionHandler(new AuctionHandler),
99
    mBankHandler(new BankHandler),
100
    mBattleGroundHandler(new BattleGroundHandler),
101
    mBuyingStoreHandler(new BuyingStoreHandler),
102
    mCashShopHandler(new CashShopHandler),
103
    mElementalHandler(new ElementalHandler),
104
    mFamilyHandler(new FamilyHandler),
105
    mFriendsHandler(new FriendsHandler),
106
    mHomunculusHandler(new HomunculusHandler),
107
    mMail2Handler(new Mail2Handler),
108
    mMailHandler(new MailHandler),
109
    mMapHandler(new MapHandler),
110
    mMarketHandler(new MarketHandler),
111
    mMercenaryHandler(new MercenaryHandler),
112
    mRouletteHandler(new RouletteHandler),
113
    mSearchStoreHandler(new SearchStoreHandler),
114
    mVendingHandler(new VendingHandler)
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(mAuctionHandler);
142
    delete2(mBankHandler);
143
    delete2(mBattleGroundHandler);
144
    delete2(mBuyingStoreHandler);
145
    delete2(mCashShopHandler);
146
    delete2(mElementalHandler);
147
    delete2(mFamilyHandler);
148
    delete2(mFriendsHandler);
149
    delete2(mHomunculusHandler);
150
    delete2(mMail2Handler);
151
    delete2(mMailHandler);
152
    delete2(mMapHandler);
153
    delete2(mMarketHandler);
154
    delete2(mMercenaryHandler);
155
    delete2(mRouletteHandler);
156
    delete2(mSearchStoreHandler);
157
    delete2(mVendingHandler);
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
    BLOCK_START("GeneralHandler::flushNetwork 1")
203
    Network::mInstance->flush();
204
    BLOCK_END("GeneralHandler::flushNetwork 1")
205
    Network::mInstance->dispatchMessages();
206
207
    BLOCK_START("GeneralHandler::flushNetwork 3")
208
    if (Network::mInstance->getState() == Network::NET_ERROR)
209
    {
210
        if (!Network::mInstance->getError().empty())
211
        {
212
            errorMessage = Network::mInstance->getError();
213
        }
214
        else
215
        {
216
            // TRANSLATORS: error message
217
            errorMessage = _("Got disconnected from server!");
218
        }
219
220
        client->setState(State::ERROR);
221
    }
222
    BLOCK_END("GeneralHandler::flushNetwork 3")
223
}
224
225
void GeneralHandler::clearHandlers() const
226
{
227
    if (Network::mInstance != nullptr)
228
        Network::mInstance->clearHandlers();
229
}
230
231
void GeneralHandler::gameStarted() const
232
{
233
    if (skillDialog != nullptr)
234
        skillDialog->loadSkills();
235
}
236
237
void GeneralHandler::gameEnded() const
238
{
239
    if (socialWindow != nullptr)
240
        socialWindow->removeTab(Ea::taParty);
241
242
    delete2(partyTab);
243
}
244
245
4
}  // namespace TmwAthena