Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Ignore packet  (Read 4891 times)

0 Members and 1 Guest are viewing this topic.

shmonck

  • Newbie
  • *
  • Posts: 1
    • View Profile
Ignore packet
« 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.
« Last Edit: February 28, 2020, 02:15:35 pm by shmonck »

Fx8qkaoy

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Ignore packet
« Reply #1 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)

grazianobolla

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Ignore packet
« Reply #2 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?

Fx8qkaoy

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Ignore packet
« Reply #3 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

 

anything