diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 10e58a24f..a9f1deb9c 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -673,7 +673,7 @@ void Networking::NewPlayer(RakNet::RakNetGUID guid) for (TPlayers::iterator pl = players->begin(); pl != players->end(); pl++) //sending other players to new player { // If we are iterating over the new player, don't send the packets below - if (pl->first == guid) continue; + if (pl->first == guid.g) continue; playerController->GetPacket(ID_GAME_BASE_INFO)->Send(pl->second, guid); playerController->GetPacket(ID_GAME_DYNAMICSTATS)->Send(pl->second, guid); diff --git a/apps/openmw-mp/Player.cpp b/apps/openmw-mp/Player.cpp index 371f0d726..0a9e11bd1 100644 --- a/apps/openmw-mp/Player.cpp +++ b/apps/openmw-mp/Player.cpp @@ -13,17 +13,20 @@ void Players::DeletePlayer(RakNet::RakNetGUID guid) LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Deleting player with guid %lu", guid.g); - if (players[guid] != 0) + LOG_APPEND(Log::LOG_INFO, "- %i players remaining before", + players.size()); + + if (players[guid.g] != 0) { LOG_APPEND(Log::LOG_INFO, "- Emptying slot %i", - players[guid]->GetID()); + players[guid.g]->GetID()); - slots[players[guid]->GetID()] = 0; - delete players[guid]; - players.erase(guid); + slots[players[guid.g]->GetID()] = 0; + delete players[guid.g]; + players.erase(guid.g); } - LOG_APPEND(Log::LOG_INFO, "- %i remaining", + LOG_APPEND(Log::LOG_INFO, "- %i players remaining after", players.size()); } @@ -32,12 +35,12 @@ 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]->GetCell()->blank(); - players[guid]->Npc()->blank(); - players[guid]->NpcStats()->blank(); - players[guid]->CreatureStats()->blank(); - players[guid]->charClass.blank(); + 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++) { @@ -46,7 +49,7 @@ void Players::NewPlayer(RakNet::RakNetGUID guid) LOG_APPEND(Log::LOG_INFO, "- Storing in slot %i", i); - slots[i] = players[guid]; + slots[i] = players[guid.g]; slots[i]->SetID(i); break; } @@ -55,10 +58,10 @@ void Players::NewPlayer(RakNet::RakNetGUID guid) Player *Players::GetPlayer(RakNet::RakNetGUID guid) { - return players[guid]; + return players[guid.g]; } -std::map *Players::GetPlayers() +std::map *Players::GetPlayers() { return &players; } diff --git a/apps/openmw-mp/Player.hpp b/apps/openmw-mp/Player.hpp index 5dfdf9038..9960b5d54 100644 --- a/apps/openmw-mp/Player.hpp +++ b/apps/openmw-mp/Player.hpp @@ -18,7 +18,7 @@ #include struct Player; -typedef std::map TPlayers; +typedef std::map TPlayers; typedef std::map TSlots; class Players diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index d79977095..92814c021 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -24,7 +24,7 @@ using namespace mwmp; using namespace std; -std::map Players::players; +std::map Players::players; DedicatedPlayer::DedicatedPlayer(RakNet::RakNetGUID guid) : BasePlayer(guid) { @@ -50,7 +50,7 @@ void Players::CreatePlayer(RakNet::RakNetGUID guid) MWWorld::Ptr player = world->getPlayerPtr(); ESM::NPC npc = *player.get()->mBase; - DedicatedPlayer *dedicPlayer = players[guid]; + DedicatedPlayer *dedicPlayer = players[guid.g]; npc.mRace = dedicPlayer->Npc()->mRace; npc.mHead = dedicPlayer->Npc()->mHead; @@ -94,7 +94,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]->ptr.get()->mBase->mId; + npc.mId = players[guid.g]->ptr.get()->mBase->mId; MWWorld::ESMStore *store = const_cast(&world->getStore()); MWWorld::Store *esm_store = const_cast *> (&store->get()); @@ -111,41 +111,41 @@ void Players::CreatePlayer(RakNet::RakNetGUID guid) dedicPlayer->guid = guid; dedicPlayer->state = 2; - world->enable(players[guid]->ptr); + world->enable(players[guid.g]->ptr); } void Players::CleanUp() { - for (std::map ::iterator it = players.begin(); it != players.end(); it++) + for (std::map ::iterator it = players.begin(); it != players.end(); it++) delete it->second; } void Players::DisconnectPlayer(RakNet::RakNetGUID guid) { - if (players[guid]->state > 1) + if (players[guid.g]->state > 1) { - players[guid]->state = 1; + players[guid.g]->state = 1; // Remove player's marker - players[guid]->setMarkerState(false); + players[guid.g]->setMarkerState(false); MWBase::World *world = MWBase::Environment::get().getWorld(); - world->disable(players[guid]->getPtr()); + world->disable(players[guid.g]->getPtr()); // Move player to ToddTest ESM::Position newPos; world->findInteriorPosition("ToddTest", newPos); MWWorld::CellStore *store = world->getInterior("ToddTest"); - players[guid]->getPtr().getBase()->canChangeCell = true; - world->moveObject(players[guid]->getPtr(), store, newPos.pos[0], newPos.pos[1], newPos.pos[2]); + players[guid.g]->getPtr().getBase()->canChangeCell = true; + world->moveObject(players[guid.g]->getPtr(), store, newPos.pos[0], newPos.pos[1], newPos.pos[2]); } } DedicatedPlayer *Players::GetPlayer(RakNet::RakNetGUID guid) { - return players[guid]; + return players[guid.g]; } MWWorld::Ptr DedicatedPlayer::getLiveCellPtr() @@ -222,7 +222,7 @@ void Players::Update(float dt) { static float timer = 0; timer += dt; - for (std::map ::iterator it = players.begin(); it != players.end(); it++) + for (std::map ::iterator it = players.begin(); it != players.end(); it++) { DedicatedPlayer *pl = it->second; if (pl == 0) continue; @@ -287,9 +287,9 @@ DedicatedPlayer *Players::NewPlayer(RakNet::RakNetGUID guid) LOG_APPEND(Log::LOG_INFO, "- Creating new DedicatedPlayer with guid %lu", guid.g); - players[guid] = new DedicatedPlayer(guid); - players[guid]->state = 0; - return players[guid]; + players[guid.g] = new DedicatedPlayer(guid); + players[guid.g]->state = 0; + return players[guid.g]; } void DedicatedPlayer::UpdateInventory() @@ -402,7 +402,7 @@ const std::string DedicatedPlayer::GetAnim() DedicatedPlayer *Players::GetPlayer(const MWWorld::Ptr &ptr) { - std::map ::iterator it = players.begin(); + std::map ::iterator it = players.begin(); for (; it != players.end(); it++) { diff --git a/apps/openmw/mwmp/DedicatedPlayer.hpp b/apps/openmw/mwmp/DedicatedPlayer.hpp index e42b27322..00c200542 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.hpp +++ b/apps/openmw/mwmp/DedicatedPlayer.hpp @@ -30,7 +30,7 @@ namespace mwmp static DedicatedPlayer *GetPlayer(const MWWorld::Ptr &ptr); static void Update(float dt); private: - static std::map players; + static std::map players; }; class DedicatedPlayer : public BasePlayer