SuperTuxKart
servers_manager.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2013-2015 Glenn De Jonghe
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef HEADER_SERVERS_MANAGER_HPP
20 #define HEADER_SERVERS_MANAGER_HPP
21 
22 #include <irrString.h>
23 
24 #include <atomic>
25 #include <map>
26 #include <memory>
27 #include <string>
28 #include <vector>
29 
30 namespace Online { class XMLRequest; }
31 class Server;
32 class SocketAddress;
33 class XMLNode;
34 
39 struct ServerList
40 {
42  std::vector<std::shared_ptr<Server> > m_servers;
43  std::atomic_bool m_list_updated;
44  ServerList() { m_list_updated.store(false); }
45 };
46 
48 {
49 private:
51  std::vector<SocketAddress> m_broadcast_address;
52 
53  // ------------------------------------------------------------------------
55  // ------------------------------------------------------------------------
56  ~ServersManager();
57  // ------------------------------------------------------------------------
58  void setWanServers(bool success, const XMLNode* input);
59  // ------------------------------------------------------------------------
60  void setLanServers(const std::map<irr::core::stringw,
61  std::shared_ptr<Server> >& servers);
62 
63  std::vector<SocketAddress> getDefaultBroadcastAddresses();
64  void addAllBroadcastAddresses(const SocketAddress &a, int len,
65  std::vector<SocketAddress>* result);
66 public:
67  // ------------------------------------------------------------------------
68  // Singleton
69  static ServersManager* get();
70  // ------------------------------------------------------------------------
71  static void deallocate();
72  // ------------------------------------------------------------------------
73  std::vector<SocketAddress> getBroadcastAddresses(bool ipv6);
74  // ------------------------------------------------------------------------
75  std::shared_ptr<ServerList> getWANRefreshRequest() const;
76  // ------------------------------------------------------------------------
77  std::shared_ptr<ServerList> getLANRefreshRequest() const;
78 
79 }; // class ServersManager
80 #endif // HEADER_SERVERS_MANAGER_HPP
Definition: server.hpp:44
Definition: servers_manager.hpp:48
std::vector< SocketAddress > getDefaultBroadcastAddresses()
Sets a list of default broadcast addresses which is used in case no valid broadcast address is found.
Definition: servers_manager.cpp:339
std::vector< SocketAddress > m_broadcast_address
List of broadcast addresses to use.
Definition: servers_manager.hpp:51
std::vector< SocketAddress > getBroadcastAddresses(bool ipv6)
Returns a list of all possible broadcast addresses on this machine.
Definition: servers_manager.cpp:404
std::shared_ptr< ServerList > getLANRefreshRequest() const
Returns a LAN update-list-of-servers request.
Definition: servers_manager.cpp:185
std::shared_ptr< ServerList > getWANRefreshRequest() const
Returns a WAN update-list-of-servers request.
Definition: servers_manager.cpp:99
void addAllBroadcastAddresses(const SocketAddress &a, int len, std::vector< SocketAddress > *result)
This masks various possible broadcast addresses.
Definition: servers_manager.cpp:373
Describes a IPv4 or IPv6 address in sockaddr_in(6) format, suitable in using with sendto.
Definition: socket_address.hpp:47
utility class used to parse XML files
Definition: xml_node.hpp:48
Definition: servers_manager.hpp:40
std::vector< std::shared_ptr< Server > > m_servers
List of servers.
Definition: servers_manager.hpp:42