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
6#include <generated/protocol7.h>
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 (or vanilla 0.6: ids 0-15)
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) or call vote menu.
27
29{
30public:
32 {
33 public:
35 m_SkipTimeoutedId(false),
36 m_ClearSlots(false)
37 {
38 }
41 };
42
43private:
47
48 // Number of players per page for see others feature in +spectate
49 // (128 - (64 - 2)) / 2 + 1 reserved slots for max 2 pages. We want to show some players still on screen, as we have enough slots with 64 slots
50 static constexpr int ms_MaxNumSeeOthers = 34;
51 // 16 - 2 - 1 is max for 16p clients, keep local char. MaxNumSeeOthers() will take care if reserved players take up more space.
52 static constexpr int ms_MaxNumSeeOthersVanilla = 13;
53 // Teams are messy. Dont highlight teams bigger than 10 tees in playermapping so that big teams wont break anything
54 static constexpr int ms_MaxTeamSizePlayerMap = 10;
55 // Dont reserve more than half of the 62 slots for players in teams, the rest is needed for the closest tees
56 static constexpr int ms_MaxTotalTeamSizePlayerMap = 30;
57
61
63 {
64 public:
65 void Init(int ClientId, CPlayerMapping *pPlayerMapping);
66 void InitPlayer(CSixupCfg SixupCfg);
68 CPlayer *Player() const;
74 int *m_pMap;
76 void Update();
77 void Add(int MapId, int ClientId);
78 int Remove(int MapId);
79 void InsertNextEmptyOrReplace(int ClientId);
80 int MapSize() const;
81 // See others
89 void DoSeeOthers();
90 void CycleSeeOthers();
91 void UpdateSeeOthers() const;
92 void ResetSeeOthers();
93 int MaxNumSeeOthers();
95 void UpdatePlayerMap(int ClientId);
96
97public:
99 class CConfig *Config() { return m_pConfig; }
100 class IServer *Server() { return m_pServer; }
101
102 void Init(CGameContext *pGameServer);
103 void Tick();
104
105 void InitPlayerMap(int ClientId, CSixupCfg SixupCfg = CSixupCfg()) { m_aMap[ClientId].InitPlayer(SixupCfg); }
106 void UpdateTeamsState(int ClientId) { m_aMap[ClientId].m_UpdateTeamsState = true; }
107 void ForceInsertPlayer(int Insert, int ClientId) { m_aMap[ClientId].InsertNextEmptyOrReplace(Insert); }
108
109 enum class ESeeOthersInd
110 {
111 NONE = -1,
112 PLAYER = 0,
113 BUTTON = 1,
114 };
115 int SeeOthersId(int ClientId) const;
116 bool DoSeeOthers(int ClientId, int SelectedId, bool DoByVote = false);
117 void ResetSeeOthers(int ClientId);
118 int TotalOverhang(int ClientId) const;
119 ESeeOthersInd SeeOthersInd(int ClientId, int MapId) const;
120 const char *SeeOthersName(int ClientId);
121 bool ReserveTeamSlots(int DDTeam, int ClientId) const;
122};
123
124#endif
Definition config.h:30
Definition gamecontext.h:114
Definition playermapping.h:63
void DoSeeOthers()
Definition playermapping.cpp:557
int MaxNumSeeOthers()
Definition playermapping.cpp:593
int MapSize() const
Definition playermapping.cpp:395
void InsertNextEmptyOrReplace(int ClientId)
Definition playermapping.cpp:340
bool m_DoSeeOthersByVote
Definition playermapping.h:88
void CycleSeeOthers()
Definition playermapping.cpp:529
void InitPlayer(CSixupCfg SixupCfg)
Definition playermapping.cpp:86
bool m_aReserved[MAX_CLIENTS]
Definition playermapping.h:72
void Add(int MapId, int ClientId)
Definition playermapping.cpp:194
int m_TotalOverhang
Definition playermapping.h:83
void Update()
Definition playermapping.cpp:236
int m_NumReserved
Definition playermapping.h:70
bool m_ResortReserved
Definition playermapping.h:73
int * m_pReverseMap
Definition playermapping.h:75
int m_SeeOthersPage
Definition playermapping.h:82
int m_NumSeeOthers
Definition playermapping.h:85
void UpdateSeeOthers() const
Definition playermapping.cpp:610
bool m_UpdateTeamsState
Definition playermapping.h:71
CPlayerMapping * m_pPlayerMapping
Definition playermapping.h:67
int * m_pMap
Definition playermapping.h:74
CPlayer * Player() const
Definition playermapping.cpp:81
void ResetSeeOthers()
Definition playermapping.cpp:583
int Remove(int MapId)
Definition playermapping.cpp:214
int m_ClientId
Definition playermapping.h:69
void Init(int ClientId, CPlayerMapping *pPlayerMapping)
Definition playermapping.cpp:65
int m_LastSeeOthersVoteTick
Definition playermapping.h:87
int m_NumPages
Definition playermapping.h:84
bool m_aWasSeeOthers[MAX_CLIENTS]
Definition playermapping.h:86
Definition playermapping.h:32
bool m_ClearSlots
Definition playermapping.h:40
CSixupCfg()
Definition playermapping.h:34
bool m_SkipTimeoutedId
Definition playermapping.h:39
Definition playermapping.h:29
static constexpr int ms_MaxTeamSizePlayerMap
Definition playermapping.h:54
int m_aTeamSizes[NUM_DDRACE_TEAMS]
Definition playermapping.h:58
void ResetSeeOthers(int ClientId)
Definition playermapping.cpp:431
class CConfig * m_pConfig
Definition playermapping.h:45
static constexpr int ms_MaxNumSeeOthers
Definition playermapping.h:50
class CGameContext * GameServer()
Definition playermapping.h:98
bool DoSeeOthers(int ClientId, int SelectedId, bool DoByVote=false)
Definition playermapping.cpp:411
static constexpr int ms_MaxTotalTeamSizePlayerMap
Definition playermapping.h:56
const char * SeeOthersName(int ClientId)
Definition playermapping.cpp:508
void UpdatePlayerMap(int ClientId)
Definition playermapping.cpp:441
bool ReserveTeamSlots(int DDTeam, int ClientId) const
Definition playermapping.cpp:400
void Init(CGameContext *pGameServer)
Definition playermapping.cpp:12
int TotalOverhang(int ClientId) const
Definition playermapping.cpp:436
ESeeOthersInd SeeOthersInd(int ClientId, int MapId) const
Definition playermapping.cpp:499
void Tick()
Definition playermapping.cpp:24
char m_aSeeOthersName[MAX_NAME_LENGTH]
Definition playermapping.h:60
class CGameContext * m_pGameServer
Definition playermapping.h:44
void UpdateTeamsState(int ClientId)
Definition playermapping.h:106
ESeeOthersInd
Definition playermapping.h:110
class CPlayerMapping::CPlayerMap m_aMap[MAX_CLIENTS]
int SeeOthersId(int ClientId) const
Definition playermapping.cpp:406
class IServer * Server()
Definition playermapping.h:100
void InitPlayerMap(int ClientId, CSixupCfg SixupCfg=CSixupCfg())
Definition playermapping.h:105
void ForceInsertPlayer(int Insert, int ClientId)
Definition playermapping.h:107
static constexpr int ms_MaxNumSeeOthersVanilla
Definition playermapping.h:52
class IServer * m_pServer
Definition playermapping.h:46
class CConfig * Config()
Definition playermapping.h:99
bool m_ReserveAnyTeamSlots
Definition playermapping.h:59
Definition player.h:29
Definition server.h:38
@ MAX_CLIENTS
Definition protocol.h:89
@ MAX_NAME_LENGTH
Definition protocol.h:109
@ NUM_DDRACE_TEAMS
Definition teamscore.h:11