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