Emergency 20 Dokumentation  4.2.0
SessionBase.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 //[-------------------------------------------------------]
16 
17 #include <qsf/math/Color3.h>
18 
19 #include <boost/noncopyable.hpp>
20 #include <boost/signals2.hpp>
21 
22 #include <unordered_map>
23 #include <list>
24 
25 
26 //[-------------------------------------------------------]
27 //[ Forward declarations ]
28 //[-------------------------------------------------------]
29 namespace qsf
30 {
31  class Map;
32  namespace game
33  {
34  class BitStream;
35  }
36 }
37 
38 
39 //[-------------------------------------------------------]
40 //[ Namespace ]
41 //[-------------------------------------------------------]
42 namespace em5
43 {
44  namespace multiplayer
45  {
46 
47 
48  //[-------------------------------------------------------]
49  //[ Classes ]
50  //[-------------------------------------------------------]
55  class EM5_API_EXPORT SessionBase : public boost::noncopyable
56  {
57 
58 
59  //[-------------------------------------------------------]
60  //[ Public definitions ]
61  //[-------------------------------------------------------]
62  public:
63  static const uint32 CHAT_HISTORY_SIZE;
64 
65  // Combined states for a multiplayer host and client (Contains also states which are only used by one part)
93  enum class State : uint8
94  {
95  NONE,
96  CONNECTING_TO_HOST,
97  CONNECTED_TO_HOST,
98  LOBBY,
99  LOADING_SCREEN,
100  IN_GAME,
101  POST_GAME,
102  POST_GAME_FINISH
103  };
104 
105  struct PlayerInfo
106  {
109  std::string playerName;
111  bool isReady;
112  bool hasMapLoaded; // Only internal for the host
113  bool isLocal; // Only internal for the local player
114  uint8 edition; // Only internal for the host
115  bool wantHighscoreSubmit; // Only internal for the host
116  uint16 ping; // Only internal for the host
117  bool pingAcknowleged; // Only internal for the host
118  qsf::Time lastPingRequestTime; // Only internal for the host
119  uint8 mapQuality; // Contains the map quality which the player has set via graphic settings
120  uint32 userData; // A user/game defined value, currently unused in EM5
121 
122  inline PlayerInfo() :
123  teamId(qsf::getUninitialized<uint16>()),
124  playerIndex(qsf::getUninitialized<uint32>()),
125  isReady(false),
126  hasMapLoaded(false),
127  isLocal(false),
128  edition(0),
129  wantHighscoreSubmit(false),
130  ping(0),
131  pingAcknowleged(true),
132  mapQuality(0),
133  userData(qsf::getUninitialized<uint32>())
134  {
135  // Nothing to do in here
136  }
137  };
138 
139  struct ChatMessage
140  {
142  std::string text;
143 
144  inline ChatMessage() :
145  playerIndex(qsf::getUninitialized<uint32>())
146  {
147  // Nothing to do in here
148  }
149 
150  inline ChatMessage(uint32 playerIndex, const std::string& text) :
151  playerIndex(playerIndex),
152  text(text)
153  {
154  // Nothing to do in here
155  }
156  };
157 
158 
159  //[-------------------------------------------------------]
160  //[ Public boost signals ]
161  //[-------------------------------------------------------]
162  public:
164  boost::signals2::signal<void(State, State)> currentStateChanged;
165 
167  boost::signals2::signal<void(const ChatMessage&)> chatMessage;
168 
170  boost::signals2::signal<void(uint32, const PlayerInfo&)> playerJoined;
171 
173  boost::signals2::signal<void(uint32, const PlayerInfo&)> playerLeft;
174 
176  boost::signals2::signal<void(uint32, bool)> playerChangeReady;
177 
179  boost::signals2::signal<void(uint32, uint32)> playerUserDataChanged;
180 
182  boost::signals2::signal<void(const GameModeUpdateData&)> gameModeDataChanged;
183 
184 
185  //[-------------------------------------------------------]
186  //[ Public static methods ]
187  //[-------------------------------------------------------]
188  public:
189  static void generateContentAuthenticationChecksums(ContentAuthenticationChecksums& checksums);
190 
191 
192  //[-------------------------------------------------------]
193  //[ Public methods ]
194  //[-------------------------------------------------------]
195  public:
200  SessionBase();
201 
206  virtual ~SessionBase();
207 
208  //[-------------------------------------------------------]
209  //[ Query configuration ]
210  //[-------------------------------------------------------]
211  uint32 getLocalPlayerIndex() const;
212  const std::string& getSessionName() const;
213  const std::string& getSessionPassword() const;
214  uint32 getMaximumPlayerCount() const;
215  qsf::GlobalAssetId getGlobalMapAssetId() const;
216  multiplayer::GameMode getGameMode() const;
217  uint32 getDuration() const; // Duration of the game session in minutes, 0 for endless mode
218  const std::string& getGameModificationString() const;
219  bool isUsingPlayerSeparation() const;
220 
221  uint8 getMapQualityToUse() const;
222 
223  //[-------------------------------------------------------]
224  //[ State ]
225  //[-------------------------------------------------------]
226  State getCurrentState() const;
227  const std::list<ChatMessage>& getChatHistory() const;
228  const std::unordered_map<uint32, PlayerInfo>& getPlayerList() const;
229  const PlayerInfo* getPlayerByIndex(uint32 playerIndex) const;
230  void sendChatMessage(const std::string& message);
231  OperationMessageHandlerManager& getOperationMessageHandlerManager();
232 
233 
234  //[-------------------------------------------------------]
235  //[ Public virtual methods ]
236  //[-------------------------------------------------------]
237  public:
242  virtual bool startup(qsf::Map& map) = 0;
243 
248  virtual void loadingFinished() = 0;
249 
250 
251  //[-------------------------------------------------------]
252  //[ Protected virtual methods ]
253  //[-------------------------------------------------------]
254  protected:
255  virtual void onSendChatMessage(const ChatMessage& chatMessage) = 0;
256  virtual void onChatMessageReceived(const ChatMessage& chatMessage);
257 
258 
259  //[-------------------------------------------------------]
260  //[ Protected methods ]
261  //[-------------------------------------------------------]
262  protected:
263  void setLocalPlayerIndex(uint32 localPlayerIndex);
264  void setSessionName(const std::string& name);
265  void setSessionPassword(const std::string& password);
266  void setMaximumPlayerCount(uint32 count);
267  void setGlobalMapAssetId(qsf::GlobalAssetId globalAssetId);
268  void setGameMode(multiplayer::GameMode mode);
269  void setDuration(uint32 duration);
270  void setGameModificationString(const std::string& string);
271  void setUsingPlayerSeparation(bool isUsingPlayerSeparation);
272  void setCurrentState(State state);
273  void addChatMessage(const ChatMessage& message);
274  void clearChatHistory();
275  void handleChatMessageData(uint64 dataSize, const qsf::game::BitStream& bitStream);
276  void setupGameSession();
277 
278  void onPlayerUserDataChanged(uint32 playerIndex, uint32 userData);
279 
284  void setupMap(qsf::Map& map);
285 
286 
287  //[-------------------------------------------------------]
288  //[ Protected data ]
289  //[-------------------------------------------------------]
290  protected:
291  std::unordered_map<uint32, PlayerInfo> mPlayerInfoMap;
292 
293 
294  //[-------------------------------------------------------]
295  //[ Private data ]
296  //[-------------------------------------------------------]
297  private:
298  // Configuration
299  std::string mSessionName;
300  std::string mSessionPassword;
301  uint32 mMaximumPlayerCount;
302  qsf::GlobalAssetId mGlobalMapAssetId;
303  multiplayer::GameMode mGameMode;
304  uint32 mDuration;
305  std::string mGameModificationString;
306  bool mUsingPlayerSeparation;
307 
308  // State
309  std::list<ChatMessage> mChatHistory;
310  State mCurrentState;
311  uint32 mLocalPlayerIndex;
312 
313  OperationMessageHandlerManager mOperationMessageHandlerManager;
314 
315 
316  };
317 
318 
319 //[-------------------------------------------------------]
320 //[ Namespace ]
321 //[-------------------------------------------------------]
322  } // multiplayer
323 } // em5
Definition: ActionPriority.h:13
uint16 teamId
Definition: SessionBase.h:107
boost::signals2::signal< void(uint32, uint32)> playerUserDataChanged
Definition: SessionBase.h:179
uint16 ping
Definition: SessionBase.h:116
uint32 playerIndex
A value of "qsf::getUninitialized()" refers to "SYSTEM" and may be used for game event / lobb...
Definition: SessionBase.h:141
uint8 edition
Definition: SessionBase.h:114
boost::signals2::signal< void(uint32, const PlayerInfo &)> playerLeft
Definition: SessionBase.h:173
bool wantHighscoreSubmit
Definition: SessionBase.h:115
Map class.
Definition: Map.h:93
unsigned int uint32
Definition: PlatformTypes.h:181
boost::signals2::signal< void(const GameModeUpdateData &)> gameModeDataChanged
Definition: SessionBase.h:182
uint8 mapQuality
Definition: SessionBase.h:119
#define EM5_API_EXPORT
Definition: Export.h:28
PlayerInfo()
Definition: SessionBase.h:122
bool isLocal
Definition: SessionBase.h:113
Definition: SessionBase.h:139
std::string text
Definition: SessionBase.h:142
boost::container::flat_map< qsf::NamedIdentifier, uint64 > ContentAuthenticationChecksums
Definition: OperationMessages.h:41
bool isReady
Definition: SessionBase.h:111
std::unordered_map< uint32, PlayerInfo > mPlayerInfoMap
key=playerIndex value=PlayerInfo
Definition: SessionBase.h:291
Definition: SessionBase.h:105
ChatMessage(uint32 playerIndex, const std::string &text)
Definition: SessionBase.h:150
ChatMessage()
Definition: SessionBase.h:144
EMERGENCY 5 Manager for operation message handler.
Definition: OperationMessageHandlerManager.h:40
uint64_t uint64
Definition: PlatformTypes.h:184
bool pingAcknowleged
Definition: SessionBase.h:117
Color class with red, green and blue component.
Definition: Color3.h:30
Game bit stream class (just a wrapper for linnet bit stream)
Definition: BitStream.h:40
State
Definition: SessionBase.h:93
GameMode
< Connected to CAMP
Definition: MatchmakingTypes.h:41
Definition: PickupPersonByParamedicAction.h:21
std::string playerName
Definition: SessionBase.h:109
T getUninitialized()
Definition: GetUninitialized.h:38
EMERGENCY 5 multiplayer session base class.
Definition: SessionBase.h:55
unsigned short uint16
Definition: PlatformTypes.h:178
boost::signals2::signal< void(uint32, bool)> playerChangeReady
Definition: SessionBase.h:176
uint32 userData
Definition: SessionBase.h:120
bool hasMapLoaded
Definition: SessionBase.h:112
uint32 playerIndex
Definition: SessionBase.h:108
static const uint32 CHAT_HISTORY_SIZE
Definition: SessionBase.h:63
boost::signals2::signal< void(const ChatMessage &)> chatMessage
Definition: SessionBase.h:167
boost::signals2::signal< void(State, State)> currentStateChanged
Definition: SessionBase.h:164
qsf::Time lastPingRequestTime
Definition: SessionBase.h:118
boost::signals2::signal< void(uint32, const PlayerInfo &)> playerJoined
Definition: SessionBase.h:170
uint64 GlobalAssetId
Definition: AssetSystemTypes.h:28
qsf::Color3 playerColor
Definition: SessionBase.h:110
unsigned char uint8
Definition: PlatformTypes.h:175
Data type for encapsulating time information. It might represents points in time and time spans...
Definition: Time.h:32