HoverRace  2.0
RoomList.h
Go to the documentation of this file.
1 
2 // RoomList.h
3 //
4 // Copyright (c) 2009, 2014-2016 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include "../../engine/Net/CancelFlag.h"
25 
26 namespace HoverRace {
27 namespace Client {
28 
33 class RoomList
34 {
35  public:
36  RoomList();
37  ~RoomList();
38 
39  public:
40  void LoadFromUrl(const std::string &url,
41  std::shared_ptr<Net::CancelFlag> cancelFlag = {});
42  void LoadFromStream(std::istream &in);
43 
44  public:
45  class IpAddr
46  {
47  std::string s;
48  unsigned long ud;
49  public:
50  operator std::string() const { return s; }
51  operator unsigned long() const { return ud; }
52  friend std::istream &operator>>(std::istream &in, IpAddr &ip);
53  };
54  struct Server
55  {
56  std::string name;
58  int port;
59  std::string path;
60 
61  friend std::istream &operator>>(std::istream &in, Server &server);
62  };
63  struct Banner : public Server
64  {
65  int delay;
66  std::string clickUrl;
68  std::string cookie;
69 
70  friend std::istream &operator>>(std::istream &in, Banner &server);
71  };
72 
73  typedef std::vector<Server*> rooms_t;
74  typedef std::vector<Banner*> banners_t;
75 
76  const Server &GetScoreServer() const { return scoreServer; }
77 
78  const rooms_t &GetRooms() const { return rooms; }
79  const Server *GetSelectedRoom() const { return selectedRoom; }
80  void SetSelectedRoom(size_t index);
81 
82  const banners_t &GetBanners() const { return banners; }
83  bool HasBanners() const { return !banners.empty(); }
84  Banner *GetCurrentBanner() const { return curBanner; }
85  Banner *NextBanner();
86  Banner *PeekNextBanner() const;
87 
88  private:
90  rooms_t rooms;
92  banners_t banners;
94  size_t curBannerIdx;
95 };
96 typedef std::shared_ptr<RoomList> RoomListPtr;
97 
98 std::istream &operator>>(std::istream &in, RoomList::IpAddr &ip);
99 std::istream &operator>>(std::istream &in, RoomList::Server &server);
100 std::istream &operator>>(std::istream &in, RoomList::Banner &banner);
101 
102 } // namespace Client
103 } // namespace HoverRace
104 
Banner * PeekNextBanner() const
Definition: RoomList.cpp:166
int port
Definition: RoomList.h:58
Definition: RoomList.h:45
std::string path
Request URI (formerly mURL)
Definition: RoomList.h:59
Server * selectedRoom
Definition: RoomList.h:91
RoomList()
Definition: RoomList.cpp:32
Banner * GetCurrentBanner() const
Definition: RoomList.h:84
const banners_t & GetBanners() const
Definition: RoomList.h:82
IpAddr addr
IPv4 packed address.
Definition: RoomList.h:57
unsigned long ud
As packed 32-bit number.
Definition: RoomList.h:48
bool HasBanners() const
Definition: RoomList.h:83
Server scoreServer
Definition: RoomList.h:89
Banner * NextBanner()
Rotate to the next banner in the banner list.
Definition: RoomList.cpp:154
std::shared_ptr< RoomList > RoomListPtr
Definition: RoomList.h:96
size_t curBannerIdx
Definition: RoomList.h:94
void SetSelectedRoom(size_t index)
Set the currently-selected room index.
Definition: RoomList.cpp:144
~RoomList()
Definition: RoomList.cpp:37
const Server & GetScoreServer() const
Definition: RoomList.h:76
std::string name
Server name.
Definition: RoomList.h:56
void LoadFromUrl(const std::string &url, std::shared_ptr< Net::CancelFlag > cancelFlag={})
Load the roomlist from a URL.
Definition: RoomList.cpp:59
const Server * GetSelectedRoom() const
Definition: RoomList.h:79
void LoadFromStream(std::istream &in)
Definition: RoomList.cpp:71
std::string cookie
Storage for cookie info after banner is loaded (formerly mLastCookie).
Definition: RoomList.h:68
std::string s
As original string.
Definition: RoomList.h:47
banners_t banners
Definition: RoomList.h:92
std::vector< Banner * > banners_t
Definition: RoomList.h:74
Definition: RoomList.h:63
bool indirectClick
Get the click URL from the server instead of navigating directly.
Definition: RoomList.h:67
std::string clickUrl
Banner click URL.
Definition: RoomList.h:66
Definition: Announcement.h:24
const rooms_t & GetRooms() const
Definition: RoomList.h:78
int delay
Delay in seconds (formerly mDelay)
Definition: RoomList.h:65
Definition: RoomList.h:54
rooms_t rooms
Definition: RoomList.h:90
Server room list.
Definition: RoomList.h:33
friend std::istream & operator>>(std::istream &in, IpAddr &ip)
std::vector< Server * > rooms_t
Definition: RoomList.h:73
Banner * curBanner
Definition: RoomList.h:93