Once again use RakNetGUID as index for player map everywhere

Because of frequent server crashes, I tried to simplify the player map indexes with commit c91e240664, but it had no noticeable effect and was later partially reverted by Koncord in commit 902e968fd9, apparently for reasons of readability.

For the sake of consistency, this commit completes his reversion.
pull/112/merge
David Cernat 8 years ago
parent 234266755e
commit 843e84ba26

@ -25,7 +25,7 @@
using namespace mwmp;
using namespace std;
std::map<uint64_t, DedicatedPlayer *> Players::players;
std::map<RakNet::RakNetGUID, DedicatedPlayer *> Players::players;
DedicatedPlayer::DedicatedPlayer(RakNet::RakNetGUID guid) : BasePlayer(guid)
{
@ -51,7 +51,7 @@ void Players::createPlayer(RakNet::RakNetGUID guid)
MWWorld::Ptr player = world->getPlayerPtr();
ESM::NPC npc = *player.get<ESM::NPC>()->mBase;
DedicatedPlayer *dedicPlayer = players[guid.g];
DedicatedPlayer *dedicPlayer = players[guid];
npc.mRace = dedicPlayer->Npc()->mRace;
npc.mHead = dedicPlayer->Npc()->mHead;
@ -95,7 +95,7 @@ void Players::createPlayer(RakNet::RakNetGUID guid)
dedicPlayer->ptr.getBase()->canChangeCell = true;
dedicPlayer->updatePtr(world->moveObject(dedicPlayer->ptr, cellStore, newPos.pos[0], newPos.pos[1], newPos.pos[2]));
npc.mId = players[guid.g]->ptr.get<ESM::NPC>()->mBase->mId;
npc.mId = players[guid]->ptr.get<ESM::NPC>()->mBase->mId;
MWWorld::ESMStore *store = const_cast<MWWorld::ESMStore *>(&world->getStore());
MWWorld::Store<ESM::NPC> *esm_store = const_cast<MWWorld::Store<ESM::NPC> *> (&store->get<ESM::NPC>());
@ -112,41 +112,41 @@ void Players::createPlayer(RakNet::RakNetGUID guid)
dedicPlayer->guid = guid;
dedicPlayer->state = 2;
world->enable(players[guid.g]->ptr);
world->enable(players[guid]->ptr);
}
void Players::cleanUp()
{
for (std::map <uint64_t, DedicatedPlayer *>::iterator it = players.begin(); it != players.end(); it++)
for (std::map <RakNet::RakNetGUID, DedicatedPlayer *>::iterator it = players.begin(); it != players.end(); it++)
delete it->second;
}
void Players::disconnectPlayer(RakNet::RakNetGUID guid)
{
if (players[guid.g]->state > 1)
if (players[guid]->state > 1)
{
players[guid.g]->state = 1;
players[guid]->state = 1;
// Remove player's marker
players[guid.g]->setMarkerState(false);
players[guid]->setMarkerState(false);
MWBase::World *world = MWBase::Environment::get().getWorld();
world->disable(players[guid.g]->getPtr());
world->disable(players[guid]->getPtr());
// Move player to ToddTest
ESM::Position newPos;
world->findInteriorPosition("ToddTest", newPos);
MWWorld::CellStore *store = world->getInterior("ToddTest");
players[guid.g]->getPtr().getBase()->canChangeCell = true;
world->moveObject(players[guid.g]->getPtr(), store, newPos.pos[0], newPos.pos[1], newPos.pos[2]);
players[guid]->getPtr().getBase()->canChangeCell = true;
world->moveObject(players[guid]->getPtr(), store, newPos.pos[0], newPos.pos[1], newPos.pos[2]);
}
}
DedicatedPlayer *Players::getPlayer(RakNet::RakNetGUID guid)
{
return players[guid.g];
return players[guid];
}
MWWorld::Ptr DedicatedPlayer::getLiveCellPtr()
@ -221,7 +221,7 @@ void DedicatedPlayer::move(float dt)
void Players::update(float dt)
{
for (std::map <uint64_t, DedicatedPlayer *>::iterator it = players.begin(); it != players.end(); it++)
for (std::map <RakNet::RakNetGUID, DedicatedPlayer *>::iterator it = players.begin(); it != players.end(); it++)
{
DedicatedPlayer *pl = it->second;
if (pl == 0) continue;
@ -281,9 +281,9 @@ DedicatedPlayer *Players::newPlayer(RakNet::RakNetGUID guid)
LOG_APPEND(Log::LOG_INFO, "- Creating new DedicatedPlayer with guid %lu",
guid.g);
players[guid.g] = new DedicatedPlayer(guid);
players[guid.g]->state = 0;
return players[guid.g];
players[guid] = new DedicatedPlayer(guid);
players[guid]->state = 0;
return players[guid];
}
void DedicatedPlayer::updateEquipment()
@ -396,7 +396,7 @@ const std::string DedicatedPlayer::getAnim()
DedicatedPlayer *Players::getPlayer(const MWWorld::Ptr &ptr)
{
std::map <uint64_t, DedicatedPlayer *>::iterator it = players.begin();
std::map <RakNet::RakNetGUID, DedicatedPlayer *>::iterator it = players.begin();
for (; it != players.end(); it++)
{

@ -34,7 +34,7 @@ namespace mwmp
static DedicatedPlayer *getPlayer(const MWWorld::Ptr &ptr);
static void update(float dt);
private:
static std::map<uint64_t, DedicatedPlayer *> players;
static std::map<RakNet::RakNetGUID, DedicatedPlayer *> players;
};
class DedicatedPlayer : public BasePlayer

Loading…
Cancel
Save