Commit 034adfca by Anselme

fixed reset, added dynamic input to command line server

parent c2f63e7f
......@@ -70,6 +70,7 @@ sf::Packet& operator >>(sf::Packet& packet, MapKoban& map)
for(unsigned int i=0; i<map.m_tiles.size(); ++i)
packet >> (int&)map.m_tiles[i];
sf::Uint32 nbCrates;
map.m_crates.clear();
packet >> nbCrates;
for(unsigned int i=0; i<nbCrates; ++i)
{
......
......@@ -8,6 +8,13 @@
#include "common/mapkoban.h"
#include <common/defines.h>
#include <serverlib/server.h>
#include <thread>
void launchServer(Server* server, bool* running)
{
while(*running)
server->update();
}
int main(int argc, char ** argv)
{
......@@ -34,9 +41,24 @@ int main(int argc, char ** argv)
}
// launching server
bool running = true;
Server* server = new Server(port);
while(true)
server->update();
std::thread* serverThread = new std::thread(launchServer, server, &running);
while(running)
{
std::string input;
std::cin >> input;
if(input.compare("exit") == 0)
running = false;
else if(input.compare("reset") == 0)
server->resetMap();
else
std::cout << "available commands : exit, reset" << std::endl;
}
serverThread->join();
return EXIT_SUCCESS;
}
......@@ -46,7 +46,6 @@ void MapInstance::update()
void MapInstance::setMapData(const MapKoban &new_map)
{
m_map = new_map;
m_current_turn_id = 0;
sf::Packet packet;
packet << MAP_INIT << m_current_turn_id << m_map;
SocketHandler* socket_handler = m_server->getSocketHandler();
......@@ -79,7 +78,11 @@ bool MapInstance::teleportPlayer(const sf::String &id, sf::Vector2i pos)
{
if(m_characters.count(id) > 0)
{
// moving player
CharacterData* player = m_characters[id];
player->position = pos;
// sending packet to teleport the player sprite
PlayerRemove player_remove;
player_remove.id = id;
PlayerAdd player_add;
......
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