Commit d462158b by Thomas Brandého

remove characterData when disconnected

parent 81dcfc10
......@@ -40,19 +40,25 @@ bool MapInstance::isAvailable(std::string id)
return (m_characters.find(id) == m_characters.end());
}
void MapInstance::addCharacter(CharacterData *charac){
void MapInstance::addCharacter(CharacterData *charac)
{
m_characters[charac->id]=charac;
}
void MapInstance::removeCharacter(std::string id)
{
m_characters.erase(id);
}
void MapInstance::pushPlayerAction(PlayerDiff p_diff)
{
std::lock_guard<std::mutex> guard(m_mutex);
CharacterData* charac = m_characters[p_diff.id]; //get charac data of moving player
CharacterData* charac = m_characters[p_diff.id];
if(charac->action_turn < m_current_turn_id)
charac->action_turn = m_current_turn_id;
else
charac->action_turn++;
// getMapDiff of turn
MapDiff* diff;
if(m_mapdiffs.find(charac->action_turn) != m_mapdiffs.end())
{
......
......@@ -31,6 +31,7 @@ public:
TileType getTile(sf::Vector2i pos){return m_map->getTile(pos);}
void addCharacter(CharacterData* charac);
void removeCharacter(std::string id);
CharacterData* getCharacter(std::string id){return m_characters[id];}
sf::Packet& packCharacterData(sf::Packet &packet);
......
......@@ -235,6 +235,7 @@ void SocketHandler::removeDisconnectedPlayer(){
players_disconnected << PLAYER_REMOVE;
players_disconnected << player_remove;
m_clients.erase(to_erase);
m_server->getMap()->removeCharacter(player_remove.id);
}
m_to_erase.clear();
if(players_disconnected.getDataSize() != 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment