Emergency 20 Dokumentation  4.2.0
MultiplayerServerDataSource.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2018 Promotion Software GmbH
2 
3 
4 //[-------------------------------------------------------]
5 //[ Header guard ]
6 //[-------------------------------------------------------]
7 #pragma once
8 
9 
10 //[-------------------------------------------------------]
11 //[ Includes ]
12 //[-------------------------------------------------------]
14 
15 #include <qsf/asset/AssetProxy.h>
16 
17 #include <Rocket/Controls/DataSource.h>
18 
19 
20 //[-------------------------------------------------------]
21 //[ Forward declarations ]
22 //[-------------------------------------------------------]
23 namespace em5
24 {
25  class MatchmakingClient;
26 }
27 
28 
29 //[-------------------------------------------------------]
30 //[ Namespace ]
31 //[-------------------------------------------------------]
32 namespace em5
33 {
34 
35 
36  //[-------------------------------------------------------]
37  //[ Classes ]
38  //[-------------------------------------------------------]
43  class MultiplayerServerDataSource : public Rocket::Controls::DataSource
44  {
45 
46 
47  //[-------------------------------------------------------]
48  //[ Public definitions ]
49  //[-------------------------------------------------------]
50  public:
52  {
61  };
62 
63 
64  //[-------------------------------------------------------]
65  //[ Public methods ]
66  //[-------------------------------------------------------]
67  public:
68  explicit MultiplayerServerDataSource();
70 
75  void sortTable(SortColumn sortColumn);
76 
82  void disconnectFromMatchmakingServer(bool destroy = false);
83 
88  void updateHostList();
89 
90  const multiplayer::HostEntry& getHostEntryFromRowIndex(int rowIndex) const;
91 
92 
93  //[-------------------------------------------------------]
94  //[ Public virtual Rocket::Controls::DataSource methods ]
95  //[-------------------------------------------------------]
96  public:
97  virtual void GetRow(Rocket::Core::StringList& row, const Rocket::Core::String& table, int rowIndex, const Rocket::Core::StringList& columns) override;
98  virtual int GetNumRows(const Rocket::Core::String& table) override;
99 
100 
101  //[-------------------------------------------------------]
102  //[ Private definitions ]
103  //[-------------------------------------------------------]
104  private:
109  struct TableData
110  {
111  Rocket::Core::String locked;
113  Rocket::Core::String server;
114  Rocket::Core::String count;
115  Rocket::Core::String maxcount;
116  Rocket::Core::String mapName;
118  Rocket::Core::String duration;
119  Rocket::Core::String latency;
120  size_t hostEntryIndex;
121 
122  // Static sorting functions
123  static bool compareBools(Rocket::Core::String& a, Rocket::Core::String& b)
124  {
125  return (b == "true");
126  }
127 
128  static bool compareStrings(Rocket::Core::String& a, Rocket::Core::String& b)
129  {
130  return a.ToLower() < b.ToLower();
131  }
132 
133  static bool compareNumbers(Rocket::Core::String& a, Rocket::Core::String& b)
134  {
135  try
136  {
137  return std::stoi(a.CString()) < std::stoi(b.CString());
138  }
139  catch (boost::bad_lexical_cast)
140  {
141  return true;
142  }
143  }
144 
145  // Functors for sorting (less)
146  struct sortLocked
147  {
148  bool operator() (TableData* a, TableData* b)
149  {
150  return compareBools(a->locked, b->locked);
151  }
152  };
153 
154  struct sortName
155  {
156  bool operator() (TableData* a, TableData* b)
157  {
158  return compareStrings(a->name, b->name);
159  }
160  };
161 
162  struct sortCount
163  {
164  bool operator() (TableData* a, TableData* b)
165  {
166  return compareNumbers(a->count, b->count);
167  }
168  };
169 
170  struct sortMap
171  {
172  bool operator() (TableData* a, TableData* b)
173  {
174  return compareStrings(a->mapName, b->mapName);
175  }
176  };
177 
178  struct sortMode
179  {
180  bool operator() (TableData* a, TableData* b)
181  {
182  return compareNumbers(a->mode, b->mode);
183  }
184  };
185 
187  {
188  bool operator() (TableData* a, TableData* b)
189  {
190  return compareNumbers(a->duration, b->duration);
191  }
192  };
193 
194  struct sortLatency
195  {
196  bool operator() (TableData* a, TableData* b)
197  {
198  return compareNumbers(a->latency, b->latency);
199  }
200  };
201  };
202 
203 
204  //[-------------------------------------------------------]
205  //[ Private methods ]
206  //[-------------------------------------------------------]
207  private:
208  // MatchmakingClient signals
209  void setConnected();
210  void setConnectFailed();
211  void setConnectionLost();
212  void setHostList(const std::vector<multiplayer::HostEntry>& hostEntries);
213 
218  void deleteHostListEntries();
219 
220 
221  //[-------------------------------------------------------]
222  //[ Private data ]
223  //[-------------------------------------------------------]
224  private:
225  std::vector<TableData*> mTableData;
226  std::vector<multiplayer::HostEntry> mHostEntryList;
227  SortColumn mSortColumn;
228  std::shared_ptr<MatchmakingClient> mMatchmakingClient;
229 
230 
231  };
232 
233 
234 //[-------------------------------------------------------]
235 //[ Namespace ]
236 //[-------------------------------------------------------]
237 } // em5
Definition: ActionPriority.h:13
Definition: MultiplayerServerDataSource.h:146
bool operator()(TableData *a, TableData *b)
Definition: MultiplayerServerDataSource.h:156
void disconnectFromMatchmakingServer(bool destroy=false)
Definition: MultiplayerServerDataSource.h:178
virtual int GetNumRows(const Rocket::Core::String &table) override
SortColumn
Definition: MultiplayerServerDataSource.h:51
Definition: MultiplayerServerDataSource.h:53
void sortTable(SortColumn sortColumn)
Sort the table vector.
Definition: MultiplayerServerDataSource.h:57
bool operator()(TableData *a, TableData *b)
Definition: MultiplayerServerDataSource.h:196
Definition: MultiplayerServerDataSource.h:55
Definition: MultiplayerServerDataSource.h:54
Definition: MultiplayerServerDataSource.h:194
const multiplayer::HostEntry & getHostEntryFromRowIndex(int rowIndex) const
bool operator()(TableData *a, TableData *b)
Definition: MultiplayerServerDataSource.h:148
void updateHostList()
Update the list.
bool operator()(TableData *a, TableData *b)
Definition: MultiplayerServerDataSource.h:164
bool connectToMatchmakingServer()
Connect/Disconnect to the server.
bool operator()(TableData *a, TableData *b)
Definition: MultiplayerServerDataSource.h:172
Definition: MultiplayerServerDataSource.h:162
Definition: MiniMapWindow.h:43
Definition: MultiplayerServerDataSource.h:186
Definition: MultiplayerServerDataSource.h:60
bool operator()(TableData *a, TableData *b)
Definition: MultiplayerServerDataSource.h:180
Definition: MultiplayerServerDataSource.h:170
Definition: MultiplayerServerDataSource.h:58
virtual void GetRow(Rocket::Core::StringList &row, const Rocket::Core::String &table, int rowIndex, const Rocket::Core::StringList &columns) override
Multiplayer server data source.
Definition: MultiplayerServerDataSource.h:43
Definition: MultiplayerServerDataSource.h:59
Definition: MultiplayerServerDataSource.h:154
bool operator()(TableData *a, TableData *b)
Definition: MultiplayerServerDataSource.h:188
Definition: MultiplayerServerDataSource.h:56
Definition: MatchmakingTypes.h:47