vectozavr-shooter/engine/network/UDPConnection.cpp

45 lines
818 B
C++
Raw Normal View History

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
{
return Time::time() - lastMsg > TIMEOUT_SECONDS;
}
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);
}