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