1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
|
/* bzflag
* Copyright (c) 1993-2025 Tim Riker
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the license found in the file
* named COPYING that should have accompanied this file.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef __PLAYERINFO_H__
#define __PLAYERINFO_H__
// bzflag global header
#include "global.h"
// system headers
#include <string>
#ifndef _WIN32
#include <unistd.h>
#include <sys/socket.h>
#endif
// common interface headers
#include "TimeKeeper.h"
#include "Team.h"
#include "Protocol.h"
#include "Flag.h"
#include "WordFilter.h"
#include "StateDatabase.h"
enum ClientState
{
PlayerNoExist,
PlayerInLimbo,
PlayerDead,
PlayerAlive
};
enum PlayerReplayState
{
ReplayNone,
ReplayReceiving,
ReplayStateful
};
#define SEND 1
#define RECEIVE 0
struct TeamInfo
{
public:
Team team;
TimeKeeper flagTimeout;
};
class PlayerInfo
{
public:
PlayerInfo(int _playerIndex);
int getPlayerIndex( void ) const
{
return playerIndex;
}
void setLastMsg(std::string msg);
const std::string& getLastMsg() const;
TimeKeeper getLastMsgTime() const;
void incSpamWarns();
int getSpamWarns() const;
void resetPlayer(bool ctf);
void setRestartOnBase(bool on);
bool shouldRestartAtBase();
bool isPlaying() const;
void signingOn();
bool isAlive() const;
void setAlive();
void setDead();
bool isPaused() const;
bool isAutoPilot() const;
bool isBot() const;
bool isHuman() const;
void *packUpdate(void *buf);
void *packId(void *buf);
bool unpackEnter(const void *buf, uint16_t &rejectCode, char *rejectMsg);
bool processEnter ( uint16_t &rejectCode, char *rejectMsg );
const char *getCallSign() const;
void setCallSign(const char * c);
const char *getMotto() const;
void setMotto(const char* _motto);
const char *getToken() const;
void setToken(const char * c);
void clearToken();
void *packVirtualFlagCapture(void *buf);
bool isTeam(TeamColor team) const;
bool isObserver() const;
TeamColor getTeam() const;
void setTeam (TeamColor team);
void wasARabbit();
void wasNotARabbit();
bool isARabbitKill(PlayerInfo &victim) const;
void resetFlag();
bool haveFlag() const;
int getFlag() const;
void setFlag(int flag);
bool isFlagTransitSafe();
double timeSinceLastFlagDrop();
const char *getClientVersion();
void setClientVersion(const char * c);
void getClientVersionNumbers(int& major, int& minor, int& revision);
double getPausedTime();
double getIdleTime();
std::string getIdleStat();
bool canBeRabbit(bool relaxing = false);
void setPaused(bool paused);
void setAutoPilot(bool autopilot);
bool isTooMuchIdling(float kickThresh);
bool hasStartedToNotRespond();
void hasSent();
bool hasPlayedEarly();
void setCompletelyAdded()
{
completelyAdded = true;
}
bool isCompletelyAdded()
{
return completelyAdded;
}
TimeKeeper getNextSpawnTime() const;
void setSpawnDelay(double delay);
bool waitingToSpawn() const;
void queueSpawn();
bool hasNeverSpawned() const;
bool isAllowedToSpawn() const;
bool notifiedOfSpawnable() const;
void setAllowedToSpawn(bool canSpawn);
void setNotifiedOfSpawnable(bool notified);
void setPlayedEarly(bool early = true);
void setReplayState(PlayerReplayState state);
void updateIdleTime();
PlayerReplayState getReplayState();
static void setCurrentTime(TimeKeeper tm);
static void setFilterParameters(bool callSignFiltering,
WordFilter &filterData,
bool simpleFiltering);
void setTrackerID(unsigned short int t);
unsigned short int trackerID();
static TimeKeeper now;
int endShotCredit;
int endShotShieldCredit;
PlayerType getType( void )
{
return type;
}
void setType( PlayerType t )
{
type = t;
}
void killedBy(PlayerId killer);
void flushKiller(PlayerId killer);
int howManyTimesKilledBy(PlayerId killer);
private:
std::map<int,int> deathCountMap;
void cleanMotto();
bool isCallSignReadable();
bool isMottoReadable();
int playerIndex;
bool restartOnBase;
// current state of player
ClientState state;
// Need to know if entered is already done
bool hasDoneEntering;
// type of player
PlayerType type;
// player's pseudonym
char callSign[CallSignLen];
// token from db server
char token[TokenLen];
// player's motto
char motto[MottoLen];
// version information from client
char clientVersion[VersionLen];
int clientVersionMajor;
int clientVersionMinor;
int clientVersionRevision;
// player's team
TeamColor team;
// true for dead rabbit until respawn
bool wasRabbit;
// flag index player has
int flag;
// addPlayer has completed for this player
bool completelyAdded;
TimeKeeper lastFlagDropTime;
// time of player's next allowed spawn
TimeKeeper nextSpawnTime;
// Requested a spawn?
bool allowedToSpawn;
bool notifiedSpawn;
bool wantsToSpawn;
bool neverSpawned;
// spam prevention
std::string lastMsgSent;
int spamWarns;
TimeKeeper lastMsgTime;
bool paused;
TimeKeeper pausedSince;
bool autopilot;
bool notResponding;
// Has the player been sent any replay 'faked' state
PlayerReplayState replayState;
// idle kick
TimeKeeper lastmsg;
TimeKeeper lastupdate;
// player played before countdown started
bool playedEarly;
// tracker id for position tracking
unsigned short int tracker;
// Error string
std::string errorString;
// just need one of these for
static WordFilter serverSpoofingFilter;
static bool callSignFiltering;
static WordFilter *filterData;
static bool simpleFiltering;
};
inline bool PlayerInfo::isPlaying() const
{
return state > PlayerInLimbo;
}
inline bool PlayerInfo::isHuman() const
{
return (type == TankPlayer) && hasDoneEntering;
}
inline bool PlayerInfo::haveFlag() const
{
return flag >= 0;
}
inline int PlayerInfo::getFlag() const
{
return flag;
}
inline const std::string& PlayerInfo::getLastMsg() const
{
return lastMsgSent;
}
inline TimeKeeper PlayerInfo::getLastMsgTime() const
{
return lastMsgTime;
}
inline int PlayerInfo::getSpamWarns() const
{
return spamWarns;
}
inline void PlayerInfo::incSpamWarns()
{
++spamWarns;
}
inline void PlayerInfo::setLastMsg(std::string msg)
{
lastMsgSent = msg;
lastMsgTime = now;
}
inline bool PlayerInfo::isAlive() const
{
return state == PlayerAlive;
}
inline bool PlayerInfo::isPaused() const
{
return paused;
}
inline bool PlayerInfo::isAutoPilot() const
{
return autopilot;
}
inline bool PlayerInfo::isBot() const
{
return type == ComputerPlayer;
}
inline bool PlayerInfo::isARabbitKill(PlayerInfo &victim) const
{
return wasRabbit || victim.team == RabbitTeam;
}
inline TimeKeeper PlayerInfo::getNextSpawnTime() const
{
return nextSpawnTime;
}
inline void PlayerInfo::setSpawnDelay(double delay)
{
nextSpawnTime = TimeKeeper::getCurrent();
nextSpawnTime += delay;
}
inline bool PlayerInfo::waitingToSpawn() const
{
return wantsToSpawn;
}
inline void PlayerInfo::queueSpawn()
{
wantsToSpawn = true;
}
inline bool PlayerInfo::hasNeverSpawned() const
{
return neverSpawned;
}
inline bool PlayerInfo::isAllowedToSpawn() const
{
return allowedToSpawn;
}
// Whether or not the player has been told if they cannot spawn
inline bool PlayerInfo::notifiedOfSpawnable() const
{
return notifiedSpawn;
}
#endif
// Local Variables: ***
// mode: C++ ***
// tab-width: 4 ***
// c-basic-offset: 4 ***
// indent-tabs-mode: nil ***
// End: ***
// ex: shiftwidth=4 tabstop=4
|