Commit e7a5c8aa by Thomas Brandého

register new character at the right time

parent 7729977a
#include "mapinstance.h"
#include <iostream>
#include "common/playermessage.h"
#include "common/operator.h"
#include "data.h"
......@@ -160,6 +162,7 @@ std::string MapInstance::findPlayer(sf::Vector2i pos)
sf::Packet& MapInstance::packCharacterData(sf::Packet &packet)
{
for(std::pair<std::string,CharacterData*> charac : m_characters){
std::cout << "Packing player " << charac.second->id << std::endl;
PlayerAdd pa;
pa.id = charac.second->id;
pa.color = charac.second->color;
......
......@@ -92,6 +92,7 @@ void SocketHandler::handleSocketMessage(sf::TcpSocket& socket)
do{
new_charac->position = sf::Vector2i(std::rand()%map->getWidth(), std::rand()%map->getHeight());
}while(map->getTile(new_charac->position) != FLOOR);
m_server->getMap()->addCharacter(new_charac);
std::cout << "Spawning new player \"" << new_charac->id << "\" at position (" << new_charac->position.x << "," << new_charac->position.y << ")" << std::endl;
}
else
......@@ -112,7 +113,6 @@ void SocketHandler::handleSocketMessage(sf::TcpSocket& socket)
p_add.turn_id = m_server->getMap()->getCurrentTurn(); // = current turn
packet_out << PLAYER_ADD << p_add;
broadcastMessage(packet_out);
m_server->getMap()->addCharacter(new_charac);
client.authenticated = true;
}
break;
......
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