Commit f1492c56 by Thomas Brandého

Super Pouic git status

parent e7a5c8aa
......@@ -150,15 +150,6 @@ void Client::connectToServer(Client* client, const std::string &address, unsigne
}
}
void Client::receiveMap()
{
sf::Packet packet;
m_server.setBlocking(true);
if (m_server.receive(packet) == sf::Socket::Done){
packet >> m_map;
}
}
void Client::update(sf::RenderWindow& window)
{
if(window.isOpen())
......
......@@ -28,7 +28,6 @@ class Client
bool m_authenticated;
static void connectToServer(Client* client, const std::string &address, unsigned short port, const std::string &name, unsigned int color);
void receiveMap();
bool safeReceive(sf::Packet& packet);
void handlePackets();
......
......@@ -24,7 +24,7 @@ void MapInstance::update()
filterMapDiff();
sf::Packet packet;
packet << MAP_DIFF;
packet << m_mapdiffs[m_current_turn_id];
packet << *m_mapdiffs[m_current_turn_id];
m_server->getSocketHandler()->broadcastMessage(packet);
m_server->getSocketHandler()->removeDisconnectedPlayer();
......
......@@ -25,164 +25,14 @@ void Server::updateSockets(SocketHandler* socket_handler){
socket_handler->update();
}
/*
void Server::handleSocketMessage(sf::TcpSocket& socket){
sf::Packet packet_in;
sf::Packet packet_out;
ClientData& charac = m_clients[&socket];
if(safeReceive(socket,packet_in)){
int header;
packet_in >> header;
switch (header) {
case AUTH:
{
std::cout << "Received Auth Message" << std::endl;
AuthMessage auth;
AuthAnswer auth_ans;
packet_in >> auth;
if (m_id_list.count(auth.name) == 0){
charac.id = auth.name;
m_id_list.insert(auth.name);
charac.color = auth.color;
do{
charac.position = sf::Vector2i(std::rand()%m_map.getWidth(), std::rand()%m_map.getHeight());
}while(m_map.getTile(charac.position) != FLOOR);
auth_ans.isOk = true;
charac.authenticated = true;
std::cout << "Spawning new player \"" << charac.id << "\" at position (" << charac.position.x << "," << charac.position.y << ")" << std::endl;
}else{
auth_ans.isOk = false;
}
packet_out << AUTH_ANSWER;
packet_out << auth_ans;
if (auth_ans.isOk){
packet_out << MAP_INIT;
packet_out << m_map;
for(auto player : m_clients){
PlayerAdd p_add;
p_add.id = player.second.id;
p_add.color = player.second.color;
p_add.pos = player.second.position;
p_add.turn_id = m_map.getTurn();
packet_out << PLAYER_ADD;
packet_out << p_add;
}
}
safeSend(socket,packet_out);
if (auth_ans.isOk){
packet_out.clear();
PlayerAdd p_add;
p_add.id = charac.id;
p_add.color = charac.color;
p_add.pos = charac.position;
p_add.turn_id = m_map.getTurn();
packet_out << PLAYER_ADD;
packet_out << p_add;
for(auto player : m_clients){
if(player.second.id.compare(charac.id) != 0)
safeSend((*player.first), packet_out);
}
}
break;
}
case MOVE:
{
Move m;
packet_in >> m;
PlayerDiff pm;
pm.id = charac.id;
pm.dir = m.dir;
pm.action = MOVING;
std::lock_guard<std::mutex> guard(m_mutex);
m_diff.players.push_back(pm);
break;
}
case TAUNT:
{
Taunt t;
packet_in >> t;
PlayerDiff pm;
pm.id = charac.id;
pm.dir = (Direction)t.type;
pm.action = IDLE;
std::lock_guard<std::mutex> guard(m_mutex);
m_diff.players.push_back(pm);
break;
}
default:
std::cout << "invalid packet" << std::endl;
charac.socket_error_count++;
if(charac.socket_error_count > CONNECTION_ERROR_THRESHOLD){
m_ip_timeout_table.insert(socket.getRemoteAddress());
m_selector.remove(socket);
socket.disconnect();
delete(&socket);
m_to_erase.push_back(&socket);
}
break;
}
}
}*/
/*
PlayerAction Server::resolveMove(sf::Vector2i pos, Direction dir)
{
sf::Vector2i target = pos + dir;
switch(m_map.getTile(target)){
case FLOOR:
{
//check if there is a crate on this tile
int crateId = m_map.findCrate(target);
std::string playerId = findPlayer(target);
if(crateId != NO_CRATE)
{
sf::Vector2i dest = target+dir;
switch(m_map.getTile(dest))
{
case FLOOR:
{
int targetCrateId = m_map.findCrate(dest);
std::string targetPlayerId = findPlayer(dest);
if(targetCrateId == NO_CRATE && targetPlayerId.empty())
{
m_map.getCrate(crateId).position = dest;
return PUSHING;
}else
return BLOCKED;
}
case WALL:
default:
return BLOCKED;
}
}else if(!playerId.empty())
{
return BLOCKED;
}
else
return MOVING;
}
case WALL:
default:
return BLOCKED;
}
}*/
void Server::update()
{
sf::sleep(sf::seconds(REFRESH_TIME) - m_clock.getElapsedTime());
std::cout << "turn:" << m_map->getCurrentTurn() << " time elapsed : " << m_clock.getElapsedTime().asSeconds() << std::endl;
m_clock.restart();
m_map->update();
// std::cout << "turn:" << m_map->getTurn() << " time elapsed : " << m_clock.getElapsedTime().asSeconds() << std::endl;
}
......@@ -165,7 +165,6 @@ bool SocketHandler::safeReceive(sf::TcpSocket &socket, sf::Packet &packet, bool
status = socket.receive(packet);
switch (status) {
case sf::Socket::Done:
std::cout << "receive ok" << std::endl;
return true;
case sf::Socket::NotReady:
std::cout << "receive not ready" << std::endl;
......@@ -197,7 +196,6 @@ bool SocketHandler::safeSend(sf::TcpSocket &socket, sf::Packet &packet, bool blo
status = socket.send(packet);
switch (status) {
case sf::Socket::Done:
std::cout << "send ok" << std::endl;
return true;
case sf::Socket::NotReady:
std::cout << "socket not ready" << std::endl;
......
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