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