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.
This commit is contained in:
David Cernat 2016-11-19 22:16:21 +02:00
parent 234266755e
commit 843e84ba26
2 changed files with 18 additions and 18 deletions

View file

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

View file

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