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 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
7 |
|
|
* |
8 |
|
|
* This file is part of The ManaPlus Client. |
9 |
|
|
* |
10 |
|
|
* This program is free software; you can redistribute it and/or modify |
11 |
|
|
* it under the terms of the GNU General Public License as published by |
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
13 |
|
|
* any later version. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU General Public License |
21 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#include "net/net.h" |
25 |
|
|
|
26 |
|
|
#include "configuration.h" |
27 |
|
|
|
28 |
|
|
#include "net/loginhandler.h" |
29 |
|
|
|
30 |
|
|
#ifdef TMWA_SUPPORT |
31 |
|
|
#include "net/tmwa/generalhandler.h" |
32 |
|
|
#endif // TMWA_SUPPORT |
33 |
|
|
|
34 |
|
|
#include "net/eathena/generalhandler.h" |
35 |
|
|
|
36 |
|
|
#include "utils/delete2.h" |
37 |
|
|
|
38 |
|
|
#include "debug.h" |
39 |
|
|
|
40 |
|
|
int evolPacketOffset = 0; |
41 |
|
|
|
42 |
|
|
namespace Net |
43 |
|
|
{ |
44 |
|
|
class AuctionHandler; |
45 |
|
|
class AchievementHandler; |
46 |
|
|
class AttendanceHandler; |
47 |
|
|
class BankHandler; |
48 |
|
|
class BarterHandler; |
49 |
|
|
class BattleGroundHandler; |
50 |
|
|
class BuyingStoreHandler; |
51 |
|
|
class CashShopHandler; |
52 |
|
|
class ElementalHandler; |
53 |
|
|
class FamilyHandler; |
54 |
|
|
class FriendsHandler; |
55 |
|
|
class HomunculusHandler; |
56 |
|
|
class Mail2Handler; |
57 |
|
|
class MailHandler; |
58 |
|
|
class MapHandler; |
59 |
|
|
class MarketHandler; |
60 |
|
|
class MercenaryHandler; |
61 |
|
|
class SearchStoreHandler; |
62 |
|
|
class RefineHandler; |
63 |
|
|
class RouletteHandler; |
64 |
|
|
class VendingHandler; |
65 |
|
|
class AdminHandler; |
66 |
|
|
class BeingHandler; |
67 |
|
|
class BuySellHandler; |
68 |
|
|
class CharServerHandler; |
69 |
|
|
class ChatHandler; |
70 |
|
|
class ClanHandler; |
71 |
|
|
class GameHandler; |
72 |
|
|
class GuildHandler; |
73 |
|
|
class InventoryHandler; |
74 |
|
|
class NpcHandler; |
75 |
|
|
class PartyHandler; |
76 |
|
|
class PetHandler; |
77 |
|
|
class PlayerHandler; |
78 |
|
|
class QuestHandler; |
79 |
|
|
class ServerFeatures; |
80 |
|
|
class SkillHandler; |
81 |
|
|
class TradeHandler; |
82 |
|
|
} // namespace Net |
83 |
|
|
|
84 |
|
|
Net::AdminHandler *adminHandler = nullptr; |
85 |
|
|
Net::CharServerHandler *charServerHandler = nullptr; |
86 |
|
|
Net::ChatHandler *chatHandler = nullptr; |
87 |
|
|
Net::ClanHandler *clanHandler = nullptr; |
88 |
|
|
Net::GeneralHandler *generalHandler = nullptr; |
89 |
|
|
Net::InventoryHandler *inventoryHandler = nullptr; |
90 |
|
|
Net::LoginHandler *loginHandler = nullptr; |
91 |
|
|
Net::GameHandler *gameHandler = nullptr; |
92 |
|
|
Net::GuildHandler *guildHandler = nullptr; |
93 |
|
|
Net::NpcHandler *npcHandler = nullptr; |
94 |
|
|
Net::PartyHandler *partyHandler = nullptr; |
95 |
|
|
Net::PetHandler *petHandler = nullptr; |
96 |
|
|
Net::PlayerHandler *playerHandler = nullptr; |
97 |
|
|
Net::SkillHandler *skillHandler = nullptr; |
98 |
|
|
Net::TradeHandler *tradeHandler = nullptr; |
99 |
|
|
Net::BeingHandler *beingHandler = nullptr; |
100 |
|
|
Net::BuySellHandler *buySellHandler = nullptr; |
101 |
|
|
Net::ServerFeatures *serverFeatures = nullptr; |
102 |
|
|
Net::AuctionHandler *auctionHandler = nullptr; |
103 |
|
|
Net::AchievementHandler *achievementHandler = nullptr; |
104 |
|
|
Net::AttendanceHandler *attendanceHandler = nullptr; |
105 |
|
|
Net::BankHandler *bankHandler = nullptr; |
106 |
|
|
Net::BattleGroundHandler *battleGroundHandler = nullptr; |
107 |
|
|
Net::BuyingStoreHandler *buyingStoreHandler = nullptr; |
108 |
|
|
Net::CashShopHandler *cashShopHandler = nullptr; |
109 |
|
|
Net::ElementalHandler *elementalHandler = nullptr; |
110 |
|
|
Net::FamilyHandler *familyHandler = nullptr; |
111 |
|
|
Net::FriendsHandler *friendsHandler = nullptr; |
112 |
|
|
Net::HomunculusHandler *homunculusHandler = nullptr; |
113 |
|
|
Net::Mail2Handler *mail2Handler = nullptr; |
114 |
|
|
Net::MailHandler *mailHandler = nullptr; |
115 |
|
|
Net::MapHandler *mapHandler = nullptr; |
116 |
|
|
Net::MarketHandler *marketHandler = nullptr; |
117 |
|
|
Net::BarterHandler *barterHandler = nullptr; |
118 |
|
|
Net::MercenaryHandler *mercenaryHandler = nullptr; |
119 |
|
|
Net::RefineHandler *refineHandler = nullptr; |
120 |
|
|
Net::RouletteHandler *rouletteHandler = nullptr; |
121 |
|
|
Net::SearchStoreHandler *searchStoreHandler = nullptr; |
122 |
|
|
Net::VendingHandler *vendingHandler = nullptr; |
123 |
|
|
Net::QuestHandler *questHandler = nullptr; |
124 |
|
|
|
125 |
|
|
namespace Net |
126 |
|
|
{ |
127 |
|
|
ServerTypeT networkType = ServerType::UNKNOWN; |
128 |
|
1 |
std::set<int> ignorePackets; |
129 |
|
|
|
130 |
|
|
void connectToServer(const ServerInfo &server) |
131 |
|
|
{ |
132 |
|
|
BLOCK_START("Net::connectToServer") |
133 |
|
|
if (networkType == server.type && |
134 |
|
|
generalHandler != nullptr) |
135 |
|
|
{ |
136 |
|
|
generalHandler->reload(); |
137 |
|
|
} |
138 |
|
|
else |
139 |
|
|
{ |
140 |
|
|
if (networkType != ServerType::UNKNOWN && |
141 |
|
|
generalHandler != nullptr) |
142 |
|
|
{ |
143 |
|
|
generalHandler->unload(); |
144 |
|
|
delete2(generalHandler) |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
switch (server.type) |
148 |
|
|
{ |
149 |
|
|
case ServerType::EATHENA: |
150 |
|
|
case ServerType::EVOL2: |
151 |
|
|
new EAthena::GeneralHandler; |
152 |
|
|
break; |
153 |
|
|
case ServerType::TMWATHENA: |
154 |
|
|
case ServerType::UNKNOWN: |
155 |
|
|
default: |
156 |
|
|
#ifdef TMWA_SUPPORT |
157 |
|
|
new TmwAthena::GeneralHandler; |
158 |
|
|
#else // TMWA_SUPPORT |
159 |
|
|
|
160 |
|
|
new EAthena::GeneralHandler; |
161 |
|
|
#endif // TMWA_SUPPORT |
162 |
|
|
|
163 |
|
|
break; |
164 |
|
|
} |
165 |
|
|
|
166 |
|
|
if (generalHandler != nullptr) |
167 |
|
|
generalHandler->load(); |
168 |
|
|
|
169 |
|
|
networkType = server.type; |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
if (loginHandler != nullptr) |
173 |
|
|
{ |
174 |
|
|
loginHandler->setServer(server); |
175 |
|
|
loginHandler->connect(); |
176 |
|
|
} |
177 |
|
|
BLOCK_END("Net::connectToServer") |
178 |
|
|
} |
179 |
|
|
|
180 |
|
|
void unload() |
181 |
|
|
{ |
182 |
|
|
const GeneralHandler *const handler = generalHandler; |
183 |
|
|
if (handler != nullptr) |
184 |
|
|
handler->unload(); |
185 |
|
|
ignorePackets.clear(); |
186 |
|
|
delete2(generalHandler) |
187 |
|
|
} |
188 |
|
|
|
189 |
|
304 |
ServerTypeT getNetworkType() |
190 |
|
|
{ |
191 |
|
304 |
return networkType; |
192 |
|
|
} |
193 |
|
|
|
194 |
|
|
void loadIgnorePackets() |
195 |
|
|
{ |
196 |
|
|
const std::string str = config.getStringValue("ignorelogpackets"); |
197 |
|
|
splitToIntSet(ignorePackets, str, ','); |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
bool isIgnorePacket(const int id) |
201 |
|
|
{ |
202 |
|
|
return ignorePackets.find(id) != ignorePackets.end(); |
203 |
|
|
} |
204 |
|
|
|
205 |
|
2 |
} // namespace Net |