You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw-tes3mp/apps/openmw-mp/Player.cpp

136 lines
2.4 KiB
C++

//
// Created by koncord on 05.01.16.
//
#include "Player.hpp"
#include "Networking.hpp"
TPlayers Players::players;
TSlots Players::slots;
void Players::DeletePlayer(RakNet::RakNetGUID guid)
{
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Deleting player with guid %lu",
guid.g);
if (players[guid.g] != 0)
{
LOG_APPEND(Log::LOG_INFO, "- Emptying slot %i",
players[guid.g]->GetID());
slots[players[guid.g]->GetID()] = 0;
delete players[guid.g];
players.erase(guid.g);
}
}
void Players::NewPlayer(RakNet::RakNetGUID guid)
{
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Creating new player with guid %lu",
guid.g);
players[guid.g] = new Player(guid);
players[guid.g]->GetCell()->blank();
players[guid.g]->Npc()->blank();
players[guid.g]->NpcStats()->blank();
players[guid.g]->CreatureStats()->blank();
players[guid.g]->charClass.blank();
for (int i = 0; i < mwmp::Networking::Get().MaxConnections(); i++)
{
if (slots[i] == 0)
{
LOG_APPEND(Log::LOG_INFO, "- Storing in slot %i",
i);
slots[i] = players[guid.g];
slots[i]->SetID(i);
break;
}
}
}
Player *Players::GetPlayer(RakNet::RakNetGUID guid)
{
return players[guid.g];
}
std::map<uint64_t, Player*> *Players::GetPlayers()
{
return &players;
}
Player::Player(RakNet::RakNetGUID guid) : BasePlayer(guid)
{
handshake = false;
loaded = false;
lastAttacker = 0;
}
Player::~Player()
{
}
unsigned short Player::GetID()
{
return id;
}
void Player::SetID(unsigned short id)
{
this->id = id;
}
void Player::Handshake()
{
handshake = true;
}
bool Player::isHandshaked()
{
return handshake;
}
8 years ago
void Player::Loaded(int state)
{
8 years ago
loaded = state;
}
8 years ago
int Player::LoadedState()
{
return loaded;
}
Player *Players::GetPlayer(unsigned short id)
{
if (slots.find(id) == slots.end())
return nullptr;
return slots[id];
}
void Player::setLastAttackerId(unsigned short pid)
{
lastAttacker = pid;
}
void Player::resetLastAttacker()
{
lastAttacker = id;
}
unsigned short Player::getLastAttackerId()
{
return lastAttacker;
}
void Player::setLastAttackerTime(std::chrono::steady_clock::time_point time)
{
lastAttackerTime = time;
}
std::chrono::steady_clock::time_point Player::getLastAttackerTime()
{
return lastAttackerTime;
}