2009-05-08 13:28:41 +00:00
/*
* OpenClonk , http : //www.openclonk.org
*
2013-12-17 20:01:09 +00:00
* Copyright ( c ) 2004 - 2009 , RedWolf Design GmbH , http : //www.clonk.de/
2016-04-03 18:18:29 +00:00
* Copyright ( c ) 2013 - 2016 , The OpenClonk Team and contributors
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* Distributed under the terms of the ISC license ; see accompanying file
* " COPYING " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* " Clonk " is a registered trademark of Matthes Bender , used with permission .
* See accompanying file " TRADEMARK " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* To redistribute this file separately , substitute the full license texts
* for the above references .
2009-05-08 13:28:41 +00:00
*/
// network player management
// manages synchronization of the player info list in network mode (lobby and runtime)
// also handles player joins from the list
//
// Synchronization is centralized; i.e. clients send join request only
// (C4PlayerJoinRequest), and the host then broadcasts list changes to all clients
// (C4ControlPlayerInfo). PlayerInfo-controls are sent as host packets. In pause mode,
// they will be sent end executed directly, while in running mode exchange will be done
// via queue to ensure synchronization.
//
// Upon entering running mode, actual ControlQueue-PlayerJoin packets are sent by the
// host for all list entries [/added since the run mode was last left]. In running mode,
// the PlayerJoin-control will be sent directly after the PlayerInfo-control.
# ifndef INC_C4Network2Players
# define INC_C4Network2Players
2016-04-03 18:07:56 +00:00
# include "network/C4PacketBase.h"
2009-05-08 13:28:41 +00:00
// class predefs
class C4Network2Players ;
// network player management
class C4Network2Players
2010-03-28 17:58:21 +00:00
{
private :
class C4PlayerInfoList & rInfoList ; // list of player infos - points to Game.PlayerInfos
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
public :
C4Network2Players ( ) ; // ctor
2017-05-07 11:50:00 +00:00
~ C4Network2Players ( ) = default ; // dtor
2009-05-08 13:28:41 +00:00
2012-10-21 20:20:43 +00:00
void Init ( ) ; // add local players; add player file resources - should be called with net connections initialized
2010-03-28 17:58:21 +00:00
void Clear ( ) ; // clear all player infos
2015-12-12 19:09:42 +00:00
bool JoinLocalPlayer ( const char * szLocalPlayerFilename , bool initial = false ) ; // join a local player (to game or lobby) - sends to host/and or schedules for queue
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
public :
void SendUpdatedPlayers ( ) ; // send all player infos with updated flags to all clients (host only!)
void ResetUpdatedPlayers ( ) ; // resets all update-flags (host only!)
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
private :
void UpdateSavegameAssignments ( class C4ClientPlayerInfos * pNewInfo ) ; // resolve any savegame assignment conflicts of unjoined players; sets update-flags (host only!)
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
// add join-packet for given client players to control queue (host only!)
// if fSendInfo is true, the given info packet is sent via queue, too, and all players in it are marked as joined
void JoinUnjoinedPlayersInControlQueue ( class C4ClientPlayerInfos * pNewPacket ) ;
public :
// callbacks from network system
void HandlePacket ( char cStatus , const C4PacketBase * pPacket , class C4Network2IOConnection * pConn ) ;
void OnClientPart ( class C4Client * pPartClient ) ; // called when a client disconnects - deletes all player infos and removes all players
void OnStatusGoReached ( ) ; // called when game starts, or continues from pause mode: send any unsent player joins
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
// request (client) or directly process (host) an update to existing player infos
// calls HandlePlayerInfoUpdRequest on host
void RequestPlayerInfoUpdate ( const class C4ClientPlayerInfos & rRequest ) ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
// player info packet received; handle it (CID_PlayerInfo, host and clients)
void HandlePlayerInfo ( const class C4ClientPlayerInfos & rInfoPacket ) ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
// player join request received; handle it (PID_PlayerInfoUpdReq, host only)
// adjusts the player data (colors, etc.), and creates update packets/controls
void HandlePlayerInfoUpdRequest ( const class C4ClientPlayerInfos * pInfoPacket , bool fByHost ) ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
// some query fns
C4ClientPlayerInfos * GetLocalPlayerInfoPacket ( ) const ; // get player info packet for local client (created in Init())
C4ClientPlayerInfos * GetIndexedPlayerInfoPacket ( int iIndex ) ; // get player info packet by index
DWORD GetClientChatColor ( int idForClient , bool fLobby ) const ;
} ;
2009-05-08 13:28:41 +00:00
# endif // INC_C4Network2Players