GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/net.cpp Lines: 4 34 11.8 %
Date: 2017-11-29 Branches: 0 30 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/net.h"
24
25
#include "configuration.h"
26
27
#include "net/loginhandler.h"
28
29
#ifdef TMWA_SUPPORT
30
#include "net/tmwa/generalhandler.h"
31
#endif  // TMWA_SUPPORT
32
33
#include "net/eathena/generalhandler.h"
34
35
#include "utils/delete2.h"
36
37
#include "debug.h"
38
39
int evolPacketOffset = 0;
40
41
namespace Net
42
{
43
    class AuctionHandler;
44
    class BankHandler;
45
    class BattleGroundHandler;
46
    class BuyingStoreHandler;
47
    class CashShopHandler;
48
    class ElementalHandler;
49
    class FamilyHandler;
50
    class FriendsHandler;
51
    class HomunculusHandler;
52
    class Mail2Handler;
53
    class MailHandler;
54
    class MapHandler;
55
    class MarketHandler;
56
    class MercenaryHandler;
57
    class SearchStoreHandler;
58
    class RouletteHandler;
59
    class VendingHandler;
60
    class AdminHandler;
61
    class BeingHandler;
62
    class BuySellHandler;
63
    class CharServerHandler;
64
    class ChatHandler;
65
    class GameHandler;
66
    class GuildHandler;
67
    class InventoryHandler;
68
    class NpcHandler;
69
    class PartyHandler;
70
    class PetHandler;
71
    class PlayerHandler;
72
    class QuestHandler;
73
    class ServerFeatures;
74
    class SkillHandler;
75
    class TradeHandler;
76
}  // namespace Net
77
78
Net::AdminHandler *adminHandler = nullptr;
79
Net::CharServerHandler *charServerHandler = nullptr;
80
Net::ChatHandler *chatHandler = nullptr;
81
Net::GeneralHandler *generalHandler = nullptr;
82
Net::InventoryHandler *inventoryHandler = nullptr;
83
Net::LoginHandler *loginHandler = nullptr;
84
Net::GameHandler *gameHandler = nullptr;
85
Net::GuildHandler *guildHandler = nullptr;
86
Net::NpcHandler *npcHandler = nullptr;
87
Net::PartyHandler *partyHandler = nullptr;
88
Net::PetHandler *petHandler = nullptr;
89
Net::PlayerHandler *playerHandler = nullptr;
90
Net::SkillHandler *skillHandler = nullptr;
91
Net::TradeHandler *tradeHandler = nullptr;
92
Net::BeingHandler *beingHandler = nullptr;
93
Net::BuySellHandler *buySellHandler = nullptr;
94
Net::ServerFeatures *serverFeatures = nullptr;
95
Net::AuctionHandler *auctionHandler = nullptr;
96
Net::BankHandler *bankHandler = nullptr;
97
Net::BattleGroundHandler *battleGroundHandler = nullptr;
98
Net::BuyingStoreHandler *buyingStoreHandler = nullptr;
99
Net::CashShopHandler *cashShopHandler = nullptr;
100
Net::ElementalHandler *elementalHandler = nullptr;
101
Net::FamilyHandler *familyHandler = nullptr;
102
Net::FriendsHandler *friendsHandler = nullptr;
103
Net::HomunculusHandler *homunculusHandler = nullptr;
104
Net::Mail2Handler *mail2Handler = nullptr;
105
Net::MailHandler *mailHandler = nullptr;
106
Net::MapHandler *mapHandler = nullptr;
107
Net::MarketHandler *marketHandler = nullptr;
108
Net::MercenaryHandler *mercenaryHandler = nullptr;
109
Net::RouletteHandler *rouletteHandler = nullptr;
110
Net::SearchStoreHandler *searchStoreHandler = nullptr;
111
Net::VendingHandler *vendingHandler = nullptr;
112
Net::QuestHandler *questHandler = nullptr;
113
114
namespace Net
115
{
116
ServerTypeT networkType = ServerType::UNKNOWN;
117
2
std::set<int> ignorePackets;
118
119
void connectToServer(const ServerInfo &server)
120
{
121
    BLOCK_START("Net::connectToServer")
122
    if (networkType == server.type &&
123
        generalHandler != nullptr)
124
    {
125
        generalHandler->reload();
126
    }
127
    else
128
    {
129
        if (networkType != ServerType::UNKNOWN &&
130
            generalHandler != nullptr)
131
        {
132
            generalHandler->unload();
133
            delete2(generalHandler);
134
        }
135
136
        switch (server.type)
137
        {
138
            case ServerType::EATHENA:
139
            case ServerType::EVOL2:
140
                new EAthena::GeneralHandler;
141
                break;
142
            case ServerType::TMWATHENA:
143
            case ServerType::UNKNOWN:
144
            default:
145
#ifdef TMWA_SUPPORT
146
                new TmwAthena::GeneralHandler;
147
#else  // TMWA_SUPPORT
148
149
                new EAthena::GeneralHandler;
150
#endif  // TMWA_SUPPORT
151
152
                break;
153
        }
154
155
        if (generalHandler != nullptr)
156
            generalHandler->load();
157
158
        networkType = server.type;
159
    }
160
161
    if (loginHandler != nullptr)
162
    {
163
        loginHandler->setServer(server);
164
        loginHandler->connect();
165
    }
166
    BLOCK_END("Net::connectToServer")
167
}
168
169
void unload()
170
{
171
    const GeneralHandler *const handler = generalHandler;
172
    if (handler != nullptr)
173
        handler->unload();
174
    ignorePackets.clear();
175
    delete2(generalHandler);
176
}
177
178
396
ServerTypeT getNetworkType()
179
{
180
396
    return networkType;
181
}
182
183
void loadIgnorePackets()
184
{
185
    const std::string str = config.getStringValue("ignorelogpackets");
186
    splitToIntSet(ignorePackets, str, ',');
187
}
188
189
bool isIgnorePacket(const int id)
190
{
191
    return ignorePackets.find(id) != ignorePackets.end();
192
}
193
194
4
}  // namespace Net