Commit dc20249c by Anselme
parents 6cc2b90c ae98b994
......@@ -69,7 +69,7 @@ void SocketHandler::handleSocketMessage(sf::TcpSocket& socket)
sf::Packet packet_out;
ClientData& client = m_clients[&socket];
CharacterData new_charac;
CharacterData* new_charac = new CharacterData();
MapInstance* map = m_server->getMap();
if(safeReceive(socket,packet_in))
......@@ -87,31 +87,32 @@ void SocketHandler::handleSocketMessage(sf::TcpSocket& socket)
{
client.id = auth.name;
auth_answer.isOk = true;
new_charac.id = auth.name;
new_charac.color = auth.color;
new_charac->id = auth.name;
new_charac->color = auth.color;
do{
new_charac.position = sf::Vector2i(std::rand()%map->getWidth(), std::rand()%map->getHeight());
}while(map->getTile(new_charac.position) != FLOOR);
std::cout << "Spawning new player \"" << new_charac.id << "\" at position (" << new_charac.position.x << "," << new_charac.position.y << ")" << std::endl;
new_charac->position = sf::Vector2i(std::rand()%map->getWidth(), std::rand()%map->getHeight());
}while(map->getTile(new_charac->position) != FLOOR);
std::cout << "Spawning new player \"" << new_charac->id << "\" at position (" << new_charac->position.x << "," << new_charac->position.y << ")" << std::endl;
}
else
auth_answer.isOk = false;
packet_out << AUTH_ANSWER << auth_answer;
if(auth_answer.isOk){
packet_out << MAP_INIT << map->getMapData();
map->packCharacterData(packet_out);
packet_out << MAP_INIT << *map->getMapData();
packet_out = map->packCharacterData(packet_out);
}
safeSend(socket,packet_out);
if(auth_answer.isOk)
{
packet_out.clear();
PlayerAdd p_add;
p_add.id = new_charac.id;
p_add.color = new_charac.color;
p_add.pos = new_charac.position;
p_add.id = new_charac->id;
p_add.color = new_charac->color;
p_add.pos = new_charac->position;
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