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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - shmonck

Pages: [1]
1
Network / 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.

Pages: [1]