mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-15 18:49:54 +00:00
34893ff631
Unfortunately, the handshake attempt limit implemented in4ebfcc4a21
for 0.7 and then ported over to 0.6 ina3a341fee6
does not appear to work properly, which is why gathering more information on it is important.
176 lines
3.2 KiB
C++
176 lines
3.2 KiB
C++
//
|
|
// Created by koncord on 05.01.16.
|
|
//
|
|
|
|
#include "Player.hpp"
|
|
#include "Networking.hpp"
|
|
|
|
TPlayers Players::players;
|
|
TSlots Players::slots;
|
|
|
|
using namespace std;
|
|
|
|
void Players::deletePlayer(RakNet::RakNetGUID guid)
|
|
{
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Deleting player with guid %lu", guid.g);
|
|
|
|
if (players[guid] != 0)
|
|
{
|
|
CellController::get()->deletePlayer(players[guid]);
|
|
|
|
LOG_APPEND(Log::LOG_INFO, "- Emptying slot %i", players[guid]->getId());
|
|
|
|
slots[players[guid]->getId()] = 0;
|
|
delete players[guid];
|
|
players.erase(guid);
|
|
}
|
|
}
|
|
|
|
void Players::newPlayer(RakNet::RakNetGUID guid)
|
|
{
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Creating new player with guid %lu", guid.g);
|
|
|
|
players[guid] = new Player(guid);
|
|
players[guid]->cell.blank();
|
|
players[guid]->npc.blank();
|
|
players[guid]->npcStats.blank();
|
|
players[guid]->creatureStats.blank();
|
|
players[guid]->charClass.blank();
|
|
players[guid]->scale = 1;
|
|
players[guid]->isWerewolf = false;
|
|
|
|
for (unsigned 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];
|
|
slots[i]->setId(i);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
Player *Players::getPlayer(RakNet::RakNetGUID guid)
|
|
{
|
|
if (players.count(guid) == 0)
|
|
return nullptr;
|
|
return players[guid];
|
|
}
|
|
|
|
TPlayers *Players::getPlayers()
|
|
{
|
|
return &players;
|
|
}
|
|
|
|
unsigned short Players::getLastPlayerId()
|
|
{
|
|
return slots.rbegin()->first;
|
|
}
|
|
|
|
Player::Player(RakNet::RakNetGUID guid) : BasePlayer(guid)
|
|
{
|
|
handshakeCounter = 0;
|
|
loadState = NOTLOADED;
|
|
}
|
|
|
|
Player::~Player()
|
|
{
|
|
|
|
}
|
|
|
|
unsigned short Player::getId()
|
|
{
|
|
return id;
|
|
}
|
|
|
|
void Player::setId(unsigned short id)
|
|
{
|
|
this->id = id;
|
|
}
|
|
|
|
bool Player::isHandshaked()
|
|
{
|
|
return handshakeCounter == numeric_limits<int>::max();
|
|
}
|
|
|
|
void Player::setHandshake()
|
|
{
|
|
handshakeCounter = numeric_limits<int>::max();
|
|
}
|
|
|
|
void Player::incrementHandshakeAttempts()
|
|
{
|
|
handshakeCounter++;
|
|
}
|
|
|
|
int Player::getHandshakeAttempts()
|
|
{
|
|
return handshakeCounter;
|
|
}
|
|
|
|
|
|
void Player::setLoadState(int state)
|
|
{
|
|
loadState = state;
|
|
}
|
|
|
|
int Player::getLoadState()
|
|
{
|
|
return loadState;
|
|
}
|
|
|
|
Player *Players::getPlayer(unsigned short id)
|
|
{
|
|
if (slots.find(id) == slots.end())
|
|
return nullptr;
|
|
return slots[id];
|
|
}
|
|
|
|
CellController::TContainer *Player::getCells()
|
|
{
|
|
return &cells;
|
|
}
|
|
|
|
void Player::sendToLoaded(mwmp::PlayerPacket *myPacket)
|
|
{
|
|
std::list <Player*> plList;
|
|
|
|
for (auto cell : cells)
|
|
for (auto pl : *cell)
|
|
plList.push_back(pl);
|
|
|
|
plList.sort();
|
|
plList.unique();
|
|
|
|
for (auto pl : plList)
|
|
{
|
|
if (pl == this) continue;
|
|
myPacket->setPlayer(this);
|
|
myPacket->Send(pl->guid);
|
|
}
|
|
}
|
|
|
|
void Player::forEachLoaded(std::function<void(Player *pl, Player *other)> func)
|
|
{
|
|
std::list <Player*> plList;
|
|
|
|
for (auto cell : cells)
|
|
{
|
|
for (auto pl : *cell)
|
|
{
|
|
if (pl != nullptr && !pl->npc.mName.empty())
|
|
plList.push_back(pl);
|
|
}
|
|
}
|
|
|
|
plList.sort();
|
|
plList.unique();
|
|
|
|
for (auto pl : plList)
|
|
{
|
|
if (pl == this) continue;
|
|
func(this, pl);
|
|
}
|
|
}
|