Skip to content

Commit

Permalink
hotfix of address and port for sending picking
Browse files Browse the repository at this point in the history
  • Loading branch information
ISPlatonov committed Nov 8, 2023
1 parent da68c5d commit a092eb8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Multiplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace Multiplayer
UdpManager::UdpManager(const sf::IpAddress& address_receive, const sf::IpAddress& address_send)
{
#ifdef CLIENT
port = sf::Socket::AnyPort;
port = Constants::getPORT_SEND(); // sf::Socket::AnyPort;
#else
port = Constants::getPORT_LISTEN();
#endif
Expand Down Expand Up @@ -169,7 +169,7 @@ namespace Multiplayer
//{
// std::cout << "its me" << std::endl;
//}
auto id = sf::IpAddress(player_data.getIp()).toString() + std::to_string(player_data.getPort());
auto id = sf::IpAddress(address_temp).toString() + std::to_string(port_temp);
sf::Uint32 time_now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
int ping = static_cast<int>(time_now) - static_cast<int>(player_data.getTime());
if (player_data_pool.count(id))
Expand All @@ -188,7 +188,7 @@ namespace Multiplayer
continue;
data.clear();
data << DataType::Object << obj_data;
send(data, sf::IpAddress(player_data.getIp()), player_data.getPort());
send(data, address_temp, port_temp);
sf::sleep(sf::milliseconds(1));
}
}
Expand All @@ -202,7 +202,7 @@ namespace Multiplayer
data.clear();
auto object_data = ObjectData(sf::Vector2f(0, 0), old_time, iter.first, Object::Passability::foreground);
data << DataType::Event << EventType::addObjectToInvectory << object_data;
send(data, sf::IpAddress(player_data.getIp()), player_data.getPort());
send(data, address_temp, port_temp);
}
}
}
Expand Down Expand Up @@ -271,7 +271,7 @@ namespace Multiplayer
// receive user
PlayerData player_data;
data >> player_data;
auto id = sf::IpAddress(player_data.getIp()).toString() + sf::IpAddress(player_data.getPort()).toString();
auto id = sf::IpAddress(address_temp).toString() + std::to_string(port_temp);
sf::Uint32 time_now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
int ping = static_cast<int>(time_now) - static_cast<int>(player_data.getTime());
if (player_data_pool.count(id))
Expand All @@ -294,7 +294,7 @@ namespace Multiplayer
send(data, sf::IpAddress(iter->second.getIp()), iter->second.getPort());
data.clear();
data << DataType::Event << EventType::addObjectToInvectory << object_data;
send(data, sf::IpAddress(player_data.getIp()), player_data.getPort());
send(data, address_temp, port_temp);
}
break;
}
Expand Down

0 comments on commit a092eb8

Please sign in to comment.