DDNet documentation
Loading...
Searching...
No Matches
playermapping.h
Go to the documentation of this file.
1#ifndef GAME_SERVER_PLAYERMAPPING_H
2#define GAME_SERVER_PLAYERMAPPING_H
3
5
7
8#include <game/teamscore.h>
9
10class CGameContext;
11class CPlayer;
12
13// The teeworlds 0.7 client and older ddnet clients
14// only support up to 64 clients. And also only up to 64 client ids (0-63).
15// The CPlayerMapping class manages a mapping of real server internal
16// client ids in the range of 0-127 and the fake client ids send to clients
17// in the range of 0-63.
18//
19// If a client does not support 128 slots the server will only show the 63 (64-1 for empty client for chat)
20// closest players (that closest selection currently tries to minimize changes by only changing when really required)
21// to the client. Because these 64 closest players are not
22// guaranteed to have client ids in the range of 0-63 we need to maintain a
23// fake client id list for every old client.
24//
25// Additionally there is the "See Others" feature which lets you cycle through a list of
26// all players manually in pause or spectator mode by holding right shift (+spectate).
27
29{
33
34 // Number of players per page for see others feature in +spectate
35 static constexpr int ms_MaxNumSeeOthers = 34;
36 // Teams are messy. Dont highlight teams bigger than 10 tees in playermapping so that big teams wont break anything
37 static constexpr int ms_MaxTeamSizePlayerMap = 10;
38
41
43 {
44 public:
45 void Init(int ClientId, CPlayerMapping *pPlayerMapping);
46 void InitPlayer(bool Timeout);
48 CPlayer *Player() const;
54 int *m_pMap;
56 void Update();
57 void Add(int MapId, int ClientId);
58 int Remove(int MapId);
59 void InsertNextEmpty(int ClientId);
60 int MapSize() const { return LEGACY_MAX_CLIENTS - m_NumReserved; }
61 // See others
68 void DoSeeOthers();
69 void CycleSeeOthers();
70 void UpdateSeeOthers() const;
71 void ResetSeeOthers();
73 void UpdatePlayerMap(int ClientId);
74
75public:
77 class CConfig *Config() { return m_pConfig; }
78 class IServer *Server() { return m_pServer; }
79
80 void Init(CGameContext *pGameServer);
81 void Tick();
82
83 void InitPlayerMap(int ClientId, bool Timeout = false) { m_aMap[ClientId].InitPlayer(Timeout); }
84 void UpdateTeamsState(int ClientId) { m_aMap[ClientId].m_UpdateTeamsState = true; }
85 void ForceInsertPlayer(int Insert, int ClientId) { m_aMap[ClientId].InsertNextEmpty(Insert); }
86
87 enum class ESeeOthersInd
88 {
89 NONE = -1,
90 PLAYER = 0,
91 BUTTON = 1,
92 };
93 int SeeOthersId() const;
94 bool DoSeeOthers(int ClientId, int SelectedId, bool DoByVote = false);
95 void ResetSeeOthers(int ClientId);
96 int TotalOverhang(int ClientId) const;
97 ESeeOthersInd SeeOthersInd(int ClientId, int MapId) const;
98 const char *SeeOthersName(int ClientId);
99 bool ReserveTeamSlots(int DDTeam) const;
100};
101
102#endif
Definition config.h:30
Definition gamecontext.h:114
Definition playermapping.h:43
void DoSeeOthers()
Definition playermapping.cpp:496
int MapSize() const
Definition playermapping.h:60
bool m_DoSeeOthersByVote
Definition playermapping.h:67
void CycleSeeOthers()
Definition playermapping.cpp:467
bool m_aReserved[MAX_CLIENTS]
Definition playermapping.h:52
void Add(int MapId, int ClientId)
Definition playermapping.cpp:185
int m_TotalOverhang
Definition playermapping.h:63
void Update()
Definition playermapping.cpp:227
int m_NumReserved
Definition playermapping.h:50
bool m_ResortReserved
Definition playermapping.h:53
int * m_pReverseMap
Definition playermapping.h:55
int m_SeeOthersPage
Definition playermapping.h:62
int m_NumSeeOthers
Definition playermapping.h:65
void UpdateSeeOthers() const
Definition playermapping.cpp:532
bool m_UpdateTeamsState
Definition playermapping.h:51
void InitPlayer(bool Timeout)
Definition playermapping.cpp:84
void InsertNextEmpty(int ClientId)
Definition playermapping.cpp:331
CPlayerMapping * m_pPlayerMapping
Definition playermapping.h:47
int * m_pMap
Definition playermapping.h:54
CPlayer * Player() const
Definition playermapping.cpp:79
void ResetSeeOthers()
Definition playermapping.cpp:522
int Remove(int MapId)
Definition playermapping.cpp:205
int m_ClientId
Definition playermapping.h:49
void Init(int ClientId, CPlayerMapping *pPlayerMapping)
Definition playermapping.cpp:64
int m_NumPages
Definition playermapping.h:64
bool m_aWasSeeOthers[MAX_CLIENTS]
Definition playermapping.h:66
Definition playermapping.h:29
static constexpr int ms_MaxTeamSizePlayerMap
Definition playermapping.h:37
int m_aTeamSizes[NUM_DDRACE_TEAMS]
Definition playermapping.h:39
void ResetSeeOthers(int ClientId)
Definition playermapping.cpp:376
class CConfig * m_pConfig
Definition playermapping.h:31
static constexpr int ms_MaxNumSeeOthers
Definition playermapping.h:35
class CGameContext * GameServer()
Definition playermapping.h:76
bool DoSeeOthers(int ClientId, int SelectedId, bool DoByVote=false)
Definition playermapping.cpp:360
const char * SeeOthersName(int ClientId)
Definition playermapping.cpp:446
void UpdatePlayerMap(int ClientId)
Definition playermapping.cpp:386
void Init(CGameContext *pGameServer)
Definition playermapping.cpp:12
int TotalOverhang(int ClientId) const
Definition playermapping.cpp:381
ESeeOthersInd SeeOthersInd(int ClientId, int MapId) const
Definition playermapping.cpp:437
void Tick()
Definition playermapping.cpp:23
void InitPlayerMap(int ClientId, bool Timeout=false)
Definition playermapping.h:83
char m_aSeeOthersName[MAX_NAME_LENGTH]
Definition playermapping.h:40
class CGameContext * m_pGameServer
Definition playermapping.h:30
void UpdateTeamsState(int ClientId)
Definition playermapping.h:84
ESeeOthersInd
Definition playermapping.h:88
@ PLAYER
Definition playermapping.h:90
@ BUTTON
Definition playermapping.h:91
@ NONE
Definition playermapping.h:89
class CPlayerMapping::CPlayerMap m_aMap[MAX_CLIENTS]
class IServer * Server()
Definition playermapping.h:78
int SeeOthersId() const
Definition playermapping.cpp:355
void ForceInsertPlayer(int Insert, int ClientId)
Definition playermapping.h:85
bool ReserveTeamSlots(int DDTeam) const
Definition playermapping.cpp:350
class IServer * m_pServer
Definition playermapping.h:32
class CConfig * Config()
Definition playermapping.h:77
Definition player.h:26
Definition server.h:38
@ LEGACY_MAX_CLIENTS
Definition protocol.h:92
@ MAX_CLIENTS
Definition protocol.h:89
@ MAX_NAME_LENGTH
Definition protocol.h:109
@ NUM_DDRACE_TEAMS
Definition teamscore.h:11