ManaPlus
net.cpp
Go to the documentation of this file.
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
32 #endif // TMWA_SUPPORT
33 
35 
36 #include "utils/delete2.h"
37 
38 #include "debug.h"
39 
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 
124 
125 namespace Net
126 {
128 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  {
137  }
138  else
139  {
141  generalHandler != nullptr)
142  {
145  }
146 
147  switch (server.type)
148  {
149  case ServerType::EATHENA:
150  case ServerType::EVOL2:
152  break;
154  case ServerType::UNKNOWN:
155  default:
156 #ifdef TMWA_SUPPORT
158 #else // TMWA_SUPPORT
159 
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);
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();
187 }
188 
190 {
191  return networkType;
192 }
193 
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 } // namespace Net
std::string getStringValue(const std::string &key) const
virtual void reload() const =0
virtual void unload() const =0
virtual void load() const =0
void setServer(const ServerInfo &server)
Definition: loginhandler.h:43
virtual void connect() const =0
ServerTypeT type
Definition: serverinfo.h:42
Configuration config
#define delete2(var)
Definition: delete2.h:25
bool isIgnorePacket(const int id)
Definition: net.cpp:200
void connectToServer(const ServerInfo &server)
Definition: net.cpp:130
std::set< int > ignorePackets
Definition: net.cpp:128
void unload()
Definition: net.cpp:180
void loadIgnorePackets()
Definition: net.cpp:194
ServerTypeT getNetworkType()
Definition: net.cpp:189
ServerTypeT networkType
Definition: net.cpp:127
Net::GuildHandler * guildHandler
Definition: net.cpp:92
Net::HomunculusHandler * homunculusHandler
Definition: net.cpp:112
Net::BuyingStoreHandler * buyingStoreHandler
Definition: net.cpp:107
Net::BattleGroundHandler * battleGroundHandler
Definition: net.cpp:106
Net::FamilyHandler * familyHandler
Definition: net.cpp:110
Net::RefineHandler * refineHandler
Definition: net.cpp:119
Net::LoginHandler * loginHandler
Definition: net.cpp:90
Net::BankHandler * bankHandler
Definition: net.cpp:105
Net::RouletteHandler * rouletteHandler
Definition: net.cpp:120
Net::Mail2Handler * mail2Handler
Definition: net.cpp:113
Net::AdminHandler * adminHandler
Definition: net.cpp:84
Net::AuctionHandler * auctionHandler
Definition: net.cpp:102
Net::PartyHandler * partyHandler
Definition: net.cpp:94
Net::PetHandler * petHandler
Definition: net.cpp:95
Net::AchievementHandler * achievementHandler
Definition: net.cpp:103
Net::GeneralHandler * generalHandler
Definition: net.cpp:88
Net::MercenaryHandler * mercenaryHandler
Definition: net.cpp:118
Net::VendingHandler * vendingHandler
Definition: net.cpp:122
Net::BuySellHandler * buySellHandler
Definition: net.cpp:100
Net::QuestHandler * questHandler
Definition: net.cpp:123
Net::TradeHandler * tradeHandler
Definition: net.cpp:98
Net::BarterHandler * barterHandler
Definition: net.cpp:117
Net::SkillHandler * skillHandler
Definition: net.cpp:97
Net::ClanHandler * clanHandler
Definition: net.cpp:87
Net::MailHandler * mailHandler
Definition: net.cpp:114
Net::CharServerHandler * charServerHandler
Definition: net.cpp:85
Net::BeingHandler * beingHandler
Definition: net.cpp:99
Net::GameHandler * gameHandler
Definition: net.cpp:91
Net::InventoryHandler * inventoryHandler
Definition: net.cpp:89
Net::ServerFeatures * serverFeatures
Definition: net.cpp:101
Net::NpcHandler * npcHandler
Definition: net.cpp:93
Net::AttendanceHandler * attendanceHandler
Definition: net.cpp:104
Net::CashShopHandler * cashShopHandler
Definition: net.cpp:108
Net::ChatHandler * chatHandler
Definition: net.cpp:86
Net::MarketHandler * marketHandler
Definition: net.cpp:116
Net::MapHandler * mapHandler
Definition: net.cpp:115
Net::SearchStoreHandler * searchStoreHandler
Definition: net.cpp:121
Net::ElementalHandler * elementalHandler
Definition: net.cpp:109
int evolPacketOffset
Definition: net.cpp:40
Net::PlayerHandler * playerHandler
Definition: net.cpp:96
Net::FriendsHandler * friendsHandler
Definition: net.cpp:111
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
ServerType ::T ServerTypeT
Definition: servertype.h:36
void splitToIntSet(std::set< int > &tokens, const std::string &text, const char separator)