DDraceNetwork Docs
player.h
Go to the documentation of this file.
1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef GAME_SERVER_PLAYER_H
4#define GAME_SERVER_PLAYER_H
5
6#include <base/vmath.h>
7
9
10#include <game/alloc.h>
11#include <game/server/save.h>
12
13#include "teeinfo.h"
14
15#include <memory>
16#include <optional>
17
18class CCharacter;
19class CGameContext;
20class IServer;
23
24enum
25{
26 WEAPON_GAME = -3, // team switching etc
27 WEAPON_SELF = -2, // console kill command
28 WEAPON_WORLD = -1, // death tiles etc
29};
30
31// player object
33{
35
36public:
37 CPlayer(CGameContext *pGameServer, uint32_t UniqueClientId, int ClientId, int Team);
38 ~CPlayer();
39
40 void Reset();
41
42 void TryRespawn();
43 void Respawn(bool WeakHook = false); // with WeakHook == true the character will be spawned after all calls of Tick from other Players
44 CCharacter *ForceSpawn(vec2 Pos); // required for loading savegames
45 void SetTeam(int Team, bool DoChatMsg = true);
46 int GetTeam() const { return m_Team; }
47 int GetCid() const { return m_ClientId; }
48 uint32_t GetUniqueCid() const { return m_UniqueClientId; }
49 int GetClientVersion() const;
50 bool SetTimerType(int TimerType);
51
52 void Tick();
53 void PostTick();
54
55 // will be called after all Tick and PostTick calls from other players
56 void PostPostTick();
57 void Snap(int SnappingClient);
58 void FakeSnap();
59
60 void OnDirectInput(CNetObj_PlayerInput *pNewInput);
63 void OnDisconnect();
64
65 void KillCharacter(int Weapon = WEAPON_GAME, bool SendKillMsg = true);
67 const CCharacter *GetCharacter() const;
68
69 void SpectatePlayerName(const char *pName);
70
71 //---------------------------------------------------------
72 // this is used for snapping so we know how we can clip the view for the player
76
77 // states if the client is chatting, accessing a menu etc.
79
80 // used for snapping to just update latency if the scoreboard is active
82
83 int m_SentSnaps = 0;
84
85 // used for spectator mode
87
89
90 //
91 int m_Vote;
93 //
107
109
111
114 std::optional<int> m_Score;
119
120 // network latency calculations
121 struct
122 {
126 int m_Avg;
127 int m_Min;
128 int m_Max;
130
131private:
132 const uint32_t m_UniqueClientId;
136
138 IServer *Server() const;
139
140 //
145
148 int64_t m_LastPause;
149 bool m_Afk;
150
155
156public:
157 enum
158 {
162 };
163
164 enum
165 {
172 };
173
174 bool m_DND;
178
179 void ProcessPause();
180 int Pause(int State, bool Force);
181 int ForcePause(int Time);
182 int IsPaused() const;
183 bool CanSpec() const;
184
185 bool IsPlaying() const;
187 int64_t m_Last_Team;
193
195
197
198 void UpdatePlaytime();
199 void AfkTimer();
200 void SetAfk(bool Afk);
201 void SetInitialAfk(bool Afk);
202 bool IsAfk() const { return m_Afk; }
203
208
211
214
215 int GetDefaultEmote() const;
216 void OverrideDefaultEmote(int Emote, int Tick);
217 bool CanOverrideDefaultEmote() const;
218
222 std::shared_ptr<CScorePlayerResult> m_ScoreQueryResult;
223 std::shared_ptr<CScorePlayerResult> m_ScoreFinishResult;
227 int m_SwapTargetsClientId; //Client ID of the swap target for the given player
229
231
233};
234
235#endif
#define MACRO_ALLOC_POOL_ID()
Definition: alloc.h:36
Definition: character.h:30
Definition: gamecontext.h:79
Definition: player.h:33
int m_TimerType
Definition: player.h:213
int64_t m_LastSqlQuery
Definition: player.h:220
int m_ShowOthers
Definition: player.h:188
bool m_SpecTeam
Definition: player.h:191
@ TIMERTYPE_GAMETIMER
Definition: player.h:167
@ TIMERTYPE_DEFAULT
Definition: player.h:166
@ TIMERTYPE_BROADCAST
Definition: player.h:168
@ TIMERTYPE_SIXUP
Definition: player.h:170
@ TIMERTYPE_NONE
Definition: player.h:171
@ TIMERTYPE_GAMETIMER_AND_BROADCAST
Definition: player.h:169
void OverrideDefaultEmote(int Emote, int Tick)
Definition: player.cpp:745
int GetClientVersion() const
Definition: player.cpp:560
void SpectatePlayerName(const char *pName)
Definition: player.cpp:856
int m_AccumMin
Definition: player.h:124
void SetTeam(int Team, bool DoChatMsg=true)
Definition: player.cpp:608
bool m_IsReady
Definition: player.h:88
bool m_Moderating
Definition: player.h:196
bool m_LastBroadcastImportance
Definition: player.h:207
int m_Paused
Definition: player.h:146
int m_Team
Definition: player.h:144
void SetInitialAfk(bool Afk)
Definition: player.cpp:720
void KillCharacter(int Weapon=WEAPON_GAME, bool SendKillMsg=true)
Definition: player.cpp:579
vec2 m_ShowDistance
Definition: player.h:190
const uint32_t m_UniqueClientId
Definition: player.h:132
bool m_BirthdayAnnounced
Definition: player.h:228
CGameContext * GameServer() const
Definition: player.h:137
IServer * Server() const
Definition: player.cpp:20
int m_LastKill
Definition: player.h:102
bool m_Spawning
Definition: player.h:141
struct CPlayer::@263 m_Latency
int m_SpectatorId
Definition: player.h:86
int GetTeam() const
Definition: player.h:46
std::shared_ptr< CScorePlayerResult > m_ScoreQueryResult
Definition: player.h:222
int m_DieTick
Definition: player.h:112
int64_t m_EligibleForFinishCheck
Definition: player.h:225
void FakeSnap()
Definition: player.cpp:455
@ PAUSE_NONE
Definition: player.h:159
@ PAUSE_SPEC
Definition: player.h:161
@ PAUSE_PAUSED
Definition: player.h:160
void ProcessScoreResult(CScorePlayerResult &Result)
Definition: player.cpp:871
int m_VotePos
Definition: player.h:92
int GetDefaultEmote() const
Definition: player.cpp:737
CPlayer(CGameContext *pGameServer, uint32_t UniqueClientId, int ClientId, int Team)
Definition: player.cpp:22
bool IsAfk() const
Definition: player.h:202
CCharacter * m_pCharacter
Definition: player.h:133
void PostTick()
Definition: player.cpp:279
int m_aCurLatency[MAX_CLIENTS]
Definition: player.h:81
int m_TeamChangeTick
Definition: player.h:118
void OnPredictedEarlyInput(CNetObj_PlayerInput *pNewInput)
Definition: player.cpp:545
int m_Avg
Definition: player.h:126
CGameContext * m_pGameServer
Definition: player.h:135
CTeeInfo m_TeeInfos
Definition: player.h:110
int64_t m_ForcePauseTime
Definition: player.h:147
int m_DefEmote
Definition: player.h:151
int m_AccumMax
Definition: player.h:125
int m_OverrideEmoteReset
Definition: player.h:153
int m_LastChangeInfo
Definition: player.h:99
int m_LastActionTick
Definition: player.h:117
int m_LastInvited
Definition: player.h:106
int m_LastWhisperTo
Definition: player.h:105
int m_LastVoteTry
Definition: player.h:95
CSaveTee m_LastTeleTee
Definition: player.h:232
int m_ChatScore
Definition: player.h:194
void AfkTimer()
Definition: player.cpp:706
int m_PreviousDieTick
Definition: player.h:113
void Snap(int SnappingClient)
Definition: player.cpp:308
int m_LastSetSpectatorMode
Definition: player.h:98
int m_aLastCommands[4]
Definition: player.h:103
vec2 m_ViewPos
Definition: player.h:73
int64_t m_LastPlaytime
Definition: player.h:204
void OnDisconnect()
Definition: player.cpp:497
int m_Vote
Definition: player.h:91
std::shared_ptr< CScorePlayerResult > m_ScoreFinishResult
Definition: player.h:223
bool m_Afk
Definition: player.h:149
int m_RescueMode
Definition: player.h:230
int m_Max
Definition: player.h:128
bool m_EyeEmoteEnabled
Definition: player.h:212
void ProcessPause()
Definition: player.cpp:762
int m_LastVoteCall
Definition: player.h:94
int m_ClientId
Definition: player.h:143
bool m_ShowAll
Definition: player.h:189
int IsPaused() const
Definition: player.cpp:846
int m_SendVoteIndex
Definition: player.h:108
int ForcePause(int Time)
Definition: player.cpp:832
int m_OverrideEmote
Definition: player.h:152
void UpdatePlaytime()
Definition: player.cpp:701
int m_NumInputs
Definition: player.h:134
std::optional< int > m_Score
Definition: player.h:114
void OnPredictedInput(CNetObj_PlayerInput *pNewInput)
Definition: player.cpp:504
char m_aTimeoutCode[64]
Definition: player.h:177
void TryRespawn()
Definition: player.cpp:683
int GetCid() const
Definition: player.h:47
bool m_NotEligibleForFinish
Definition: player.h:224
int m_SwapTargetsClientId
Definition: player.h:227
int m_LastSetTeam
Definition: player.h:97
int64_t m_Last_KickVote
Definition: player.h:186
int64_t m_LastBroadcast
Definition: player.h:206
int m_LastCommandPos
Definition: player.h:104
CNetObj_PlayerInput * m_pLastTarget
Definition: player.h:209
int m_Min
Definition: player.h:127
bool m_ForceBalanced
Definition: player.h:116
bool m_LastTargetInit
Definition: player.h:210
void SetAfk(bool Afk)
Definition: player.cpp:711
uint32_t GetUniqueCid() const
Definition: player.h:48
int m_TuneZoneOld
Definition: player.h:75
int m_PlayerFlags
Definition: player.h:78
int Pause(int State, bool Force)
Definition: player.cpp:778
CCharacter * ForceSpawn(vec2 Pos)
Definition: player.cpp:599
void PostPostTick()
Definition: player.cpp:299
void Reset()
Definition: player.cpp:41
int m_TuneZone
Definition: player.h:74
int m_Accum
Definition: player.h:123
bool m_FirstPacket
Definition: player.h:219
int64_t m_LastPause
Definition: player.h:148
int m_LastEmote
Definition: player.h:100
CCharacter * GetCharacter()
Definition: player.cpp:565
~CPlayer()
Definition: player.cpp:33
void OnDirectInput(CNetObj_PlayerInput *pNewInput)
Definition: player.cpp:524
bool m_DND
Definition: player.h:174
bool CanSpec() const
Definition: player.cpp:757
bool m_WeakHookSpawn
Definition: player.h:142
bool SetTimerType(int TimerType)
Definition: player.cpp:637
int64_t m_LastEyeEmote
Definition: player.h:205
bool m_VotedForPractice
Definition: player.h:226
bool CanOverrideDefaultEmote() const
Definition: player.cpp:752
int m_LastEmoteGlobal
Definition: player.h:101
void Tick()
Definition: player.cpp:162
int m_SentSnaps
Definition: player.h:83
bool IsPlaying() const
Definition: player.cpp:851
int m_JoinTick
Definition: player.h:115
bool m_Halloween
Definition: player.h:154
bool m_Whispers
Definition: player.h:175
int m_LastChat
Definition: player.h:96
void Respawn(bool WeakHook=false)
Definition: player.cpp:590
bool m_NinjaJetpack
Definition: player.h:192
int64_t m_FirstVoteTick
Definition: player.h:176
int64_t m_Last_Team
Definition: player.h:187
Definition: save.h:34
Definition: teeinfo.h:7
Definition: server.h:30
@ MAX_CLIENTS
Definition: protocol.h:88
@ WEAPON_SELF
Definition: player.h:27
@ WEAPON_GAME
Definition: player.h:26
@ WEAPON_WORLD
Definition: player.h:28
Definition: protocol.h:360
Definition: scoreworker.h:27