2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Neirokan on 30.04.2020
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "UDPConnection.h"
|
|
|
|
#include "utils/Time.h"
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
UDPConnection::UDPConnection(sf::Uint16 id, sf::IpAddress ip, sf::Uint16 port) : _id(id), _ip(ip), _port(port), lastMsg(Time::time()) {}
|
|
|
|
|
|
|
|
sf::Uint16 UDPConnection::id() const
|
|
|
|
{
|
|
|
|
return _id;
|
|
|
|
}
|
|
|
|
|
|
|
|
const sf::IpAddress& UDPConnection::ip() const
|
|
|
|
{
|
|
|
|
return _ip;
|
|
|
|
}
|
|
|
|
|
|
|
|
sf::Uint16 UDPConnection::port() const
|
|
|
|
{
|
|
|
|
return _port;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UDPConnection::timeout() const
|
|
|
|
{
|
2021-09-20 12:47:42 +03:00
|
|
|
return Time::time() - lastMsg > Network::TIMEOUT;
|
2021-09-13 15:53:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool UDPConnection::same(sf::IpAddress& ip, sf::Uint16 port) const
|
|
|
|
{
|
|
|
|
return _ip == ip && _port == port;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UDPConnection::update()
|
|
|
|
{
|
|
|
|
lastMsg = Time::time();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UDPConnection::send(sf::UdpSocket& socket, sf::Packet& packet)
|
|
|
|
{
|
|
|
|
socket.send(packet, _ip, _port);
|
|
|
|
}
|