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