OpenClonk
C4Network2Players.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2004-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2013-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 // network player management
17 // manages synchronization of the player info list in network mode (lobby and runtime)
18 // also handles player joins from the list
19 //
20 // Synchronization is centralized; i.e. clients send join request only
21 // (C4PlayerJoinRequest), and the host then broadcasts list changes to all clients
22 // (C4ControlPlayerInfo). PlayerInfo-controls are sent as host packets. In pause mode,
23 // they will be sent end executed directly, while in running mode exchange will be done
24 // via queue to ensure synchronization.
25 //
26 // Upon entering running mode, actual ControlQueue-PlayerJoin packets are sent by the
27 // host for all list entries [/added since the run mode was last left]. In running mode,
28 // the PlayerJoin-control will be sent directly after the PlayerInfo-control.
29 
30 #ifndef INC_C4Network2Players
31 #define INC_C4Network2Players
32 
33 #include "network/C4PacketBase.h"
34 
35 // class predefs
36 class C4Network2Players;
37 
38 // network player management
40 {
41 private:
42  class C4PlayerInfoList &rInfoList; // list of player infos - points to Game.PlayerInfos
43 
44 public:
45  C4Network2Players(); // ctor
46  ~C4Network2Players() = default; // dtor
47 
48  void Init(); // add local players; add player file resources - should be called with net connections initialized
49  void Clear(); // clear all player infos
50  bool JoinLocalPlayer(const char *szLocalPlayerFilename, bool initial=false); // join a local player (to game or lobby) - sends to host/and or schedules for queue
51 
52 public:
53  void SendUpdatedPlayers(); // send all player infos with updated flags to all clients (host only!)
54  void ResetUpdatedPlayers(); // resets all update-flags (host only!)
55 
56 private:
57  void UpdateSavegameAssignments(class C4ClientPlayerInfos *pNewInfo); // resolve any savegame assignment conflicts of unjoined players; sets update-flags (host only!)
58 
59  // add join-packet for given client players to control queue (host only!)
60  // if fSendInfo is true, the given info packet is sent via queue, too, and all players in it are marked as joined
61  void JoinUnjoinedPlayersInControlQueue(class C4ClientPlayerInfos *pNewPacket);
62 public:
63  // callbacks from network system
64  void HandlePacket(char cStatus, const C4PacketBase *pPacket, class C4Network2IOConnection *pConn);
65  void OnClientPart(class C4Client *pPartClient); // called when a client disconnects - deletes all player infos and removes all players
66  void OnStatusGoReached(); // called when game starts, or continues from pause mode: send any unsent player joins
67 
68  // request (client) or directly process (host) an update to existing player infos
69  // calls HandlePlayerInfoUpdRequest on host
70  void RequestPlayerInfoUpdate(const class C4ClientPlayerInfos &rRequest);
71 
72  // player info packet received; handle it (CID_PlayerInfo, host and clients)
73  void HandlePlayerInfo(const class C4ClientPlayerInfos &rInfoPacket);
74 
75  // player join request received; handle it (PID_PlayerInfoUpdReq, host only)
76  // adjusts the player data (colors, etc.), and creates update packets/controls
77  void HandlePlayerInfoUpdRequest(const class C4ClientPlayerInfos *pInfoPacket, bool fByHost);
78 
79  // some query fns
80  C4ClientPlayerInfos *GetLocalPlayerInfoPacket() const; // get player info packet for local client (created in Init())
81  C4ClientPlayerInfos *GetIndexedPlayerInfoPacket(int iIndex); // get player info packet by index
82  DWORD GetClientChatColor(int idForClient, bool fLobby) const;
83 };
84 
85 #endif // INC_C4Network2Players
uint32_t DWORD
C4ClientPlayerInfos * GetIndexedPlayerInfoPacket(int iIndex)
void OnClientPart(class C4Client *pPartClient)
DWORD GetClientChatColor(int idForClient, bool fLobby) const
void HandlePlayerInfo(const class C4ClientPlayerInfos &rInfoPacket)
void HandlePlayerInfoUpdRequest(const class C4ClientPlayerInfos *pInfoPacket, bool fByHost)
C4ClientPlayerInfos * GetLocalPlayerInfoPacket() const
bool JoinLocalPlayer(const char *szLocalPlayerFilename, bool initial=false)
~C4Network2Players()=default
void RequestPlayerInfoUpdate(const class C4ClientPlayerInfos &rRequest)
void HandlePacket(char cStatus, const C4PacketBase *pPacket, class C4Network2IOConnection *pConn)