openmw-tes3coop/apps/openmw-mp/Player.hpp

85 lines
1.9 KiB
C++
Raw Permalink Normal View History

//
// Created by koncord on 05.01.16.
//
#ifndef OPENMW_PLAYER_HPP
#define OPENMW_PLAYER_HPP
#include <map>
#include <string>
#include <chrono>
#include <RakNetTypes.h>
#include <components/esm/npcstats.hpp>
#include <components/esm/cellid.hpp>
#include <components/esm/loadnpc.hpp>
#include <components/esm/loadcell.hpp>
2016-08-18 22:32:39 +00:00
#include <components/openmw-mp/Log.hpp>
#include <components/openmw-mp/Base/BasePlayer.hpp>
#include <components/openmw-mp/Packets/Player/PlayerPacket.hpp>
2017-02-19 05:26:42 +00:00
#include "Cell.hpp"
#include "CellController.hpp"
struct Player;
typedef std::map<RakNet::RakNetGUID, Player*> TPlayers;
typedef std::map<unsigned short, Player*> TSlots;
class Players
{
public:
static void newPlayer(const RakNet::RakNetGUID &guid);
static void deletePlayer(const RakNet::RakNetGUID &guid);
static Player *getPlayer(const RakNet::RakNetGUID &guid);
static Player *getPlayer(unsigned short id);
static TPlayers *getPlayers();
static unsigned short getLastPlayerId();
static bool doesPlayerExist(const RakNet::RakNetGUID &guid);
private:
static TPlayers players;
static TSlots slots;
};
class Player : public mwmp::BasePlayer
{
2017-02-19 05:26:42 +00:00
friend class Cell;
public:
const unsigned int InvalidID = (unsigned int) -1;
2016-09-18 07:52:13 +00:00
enum
{
NOTLOADED=0,
LOADED,
2018-10-30 04:56:50 +00:00
POSTLOADED,
KICKED
2016-09-18 07:52:13 +00:00
};
Player(const RakNet::RakNetGUID &guid);
unsigned int getId();
void setId(unsigned short id);
bool isHandshaked();
int getHandshakeAttempts();
void incrementHandshakeAttempts();
void setHandshake();
void setLoadState(int state);
int getLoadState();
2016-09-18 03:48:08 +00:00
virtual ~Player();
CellController::TContainer *getCells();
void sendToLoaded(mwmp::PlayerPacket *myPacket);
2017-02-19 05:26:42 +00:00
void forEachLoaded(std::function<void(Player *pl, Player *other)> func);
2017-02-19 09:42:39 +00:00
private:
2017-02-19 05:26:42 +00:00
CellController::TContainer cells;
int loadState;
int handshakeCounter;
unsigned int id;
};
#endif //OPENMW_PLAYER_HPP