1 /* bzflag
2  * Copyright (c) 1993-2021 Tim Riker
3  *
4  * This package is free software;  you can redistribute it and/or
5  * modify it under the terms of the license found in the file
6  * named COPYING that should have accompanied this file.
7  *
8  * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */
12 
13 #ifndef __SERVERLIST_H__
14 #define __SERVERLIST_H__
15 
16 #include "common.h"
17 
18 /* system interface headers */
19 #include <vector>
20 
21 /* common interface headers */
22 #include "ListServer.h"
23 #include "StartupInfo.h"
24 #include "ServerItem.h"
25 #include "ServerListCache.h"
26 #include "cURLManager.h"
27 
28 
29 /** The ServerList class contains links to the list server as well as
30  * any fetched list of servers.  The list handles cacheing of those
31  * server entries in case of list server unavailability.
32  */
33 class ServerList : cURLManager
34 {
35 
36 public:
37     ServerList();
38     virtual ~ServerList();
39 
40     void checkEchos(StartupInfo *_info);
41     void startServerPings(StartupInfo *_info);
42     bool searchActive() const;
43     bool serverFound() const;
44     const std::vector<ServerItem>& getServers();
45     std::vector<ServerItem>::size_type size();
46     int updateFromCache();
47     void collectData(char *ptr, int len);
48     void finalization(char *data, unsigned int length, bool good);
49 
50 public:
51     void addToList(ServerItem, bool doCache=false);
52     void markFav(const std::string &, bool);
53     void clear();
54 
55 private:
56     void readServerList();
57     void addToListWithLookup(ServerItem&);
58     void addCacheToList();
59     void _shutDown();
60 
61 private:
62     bool addedCacheToList;
63     int phase;
64     std::vector<ServerItem> servers;
65     ServerListCache* serverCache;
66     int pingBcastSocket;
67     struct sockaddr_in pingBcastAddr;
68     StartupInfo *startupInfo;
69 };
70 
71 #endif /* __SERVERLIST_H__ */
72 
73 // Local Variables: ***
74 // mode: C++ ***
75 // tab-width: 4 ***
76 // c-basic-offset: 4 ***
77 // indent-tabs-mode: nil ***
78 // End: ***
79 // ex: shiftwidth=4 tabstop=4
80