2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Neirokan on 30.04.2020
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "UDPConnection.h"
|
2021-10-09 13:41:12 +03:00
|
|
|
#include "../utils/Time.h"
|
2021-10-16 20:22:55 +03:00
|
|
|
#include "../Consts.h"
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
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-10-16 20:22:55 +03:00
|
|
|
return Time::time() - lastMsg > Consts::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);
|
|
|
|
}
|