SFML community forums

Help => Network => Topic started by: shmonck on February 28, 2020, 01:25:42 pm

Title: Ignore packet
Post by: shmonck on February 28, 2020, 01:25:42 pm
The code:
struct PacketData
{
 ClientData clientData;
 uint8_t header[1];
 sf::Packet packet;
 sf::Socket::Status status;
 time_point recieveTime;
};

...

while (!m_shutdown)
{
 if (!m_selector.wait(sf::seconds(1.0f)))
 {
  continue;
 }

 {
  size_t recieved;
  std::lock_guard<std::mutex> lock(m_socketMutex);
  packetData.status = m_socket.receive(packetData.header, 1, recieved, packetData.clientData.address, packetData.clientData.port);
 }

 const auto& isOnIgnoreList = std::find_if(m_ignoreList.begin(), m_ignoreList.end(), [&packetData](const ClientData& clientData) {return packetData.clientData == clientData; }) != m_ignoreList.end();

 if (isOnIgnoreList)
 {
  // HERE! How to ignore the packet without recieving it?
  continue;
 }

 ...
}
 

I'm trying to implement a "IP ban", and my question is: does SFML allow to somehow ignore the packet without actually receiving it? Because if I just ignore the packet, the selector.wait will return true all the time as there's data to read.

Also just noticed, the first .recieve returns an error and reads 0 bytes... why? There's only one socket in selector.
Title: Re: Ignore packet
Post by: Fx8qkaoy on February 29, 2020, 04:09:03 pm
The code:
struct PacketData
{
 ClientData clientData;
 uint8_t header[1];
 sf::Packet packet;
 sf::Socket::Status status;
 time_point recieveTime;
};

...

while (!m_shutdown)
{
 if (!m_selector.wait(sf::seconds(1.0f)))
 {
  continue;
 }

 {
  size_t recieved;
  std::lock_guard<std::mutex> lock(m_socketMutex);
  packetData.status = m_socket.receive(packetData.header, 1, recieved, packetData.clientData.address, packetData.clientData.port);
 }

 const auto& isOnIgnoreList = std::find_if(m_ignoreList.begin(), m_ignoreList.end(), [&packetData](const ClientData& clientData) {return packetData.clientData == clientData; }) != m_ignoreList.end();

 if (isOnIgnoreList)
 {
  // HERE! How to ignore the packet without recieving it?
  continue;
 }

 ...
}
 

I'm trying to implement a "IP ban", and my question is: does SFML allow to somehow ignore the packet without actually receiving it? Because if I just ignore the packet, the selector.wait will return true all the time as there's data to read.

Also just noticed, the first .recieve returns an error and reads 0 bytes... why? There's only one socket in selector.

The documentation doesn't say anything about blocking. U can do one of these 2 things:
- check the ip manually (not recommended due speed; it could been the way SFML would do that anyway if this was a core feature)
- modify one of the active firewalls (the closer to the global infrastructure the better; example: block on the router rather than ur pc if the router is dedicated for the server, so the packet won't reach the pc)
Title: Re: Ignore packet
Post by: grazianobolla on April 18, 2020, 03:35:54 am
There is not easy solution, maybe you can send two packets one with the game information and other only with the Ip address, you receive first the one with the Ip, if its on the list, you disconnect or remove that client.

Why you dont want to receive the packet? Its because of protection?
Title: Re: Ignore packet
Post by: Fx8qkaoy on April 20, 2020, 12:43:12 pm
There is not easy solution, maybe you can send two packets one with the game information and other only with the Ip address, you receive first the one with the Ip, if its on the list, you disconnect or remove that client.

Why you dont want to receive the packet? Its because of protection?

If u avoid receiving the packet, things would work way faster. Depends also on the size of the packet, and how big of bandwidth u wanna handle. As example for a game u would probably send relative small packets, so it doesn't matter anyway, which means checking the ip on the packet which also contains data is not a bad idea

Protection? It depends on ur app. As example, agains a DDOS, the firewall will show better results rather than checking the ip in ur code