2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Neirokan on 30.04.2020
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "ReliableMsg.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
|
|
|
|
2021-10-31 11:39:08 +03:00
|
|
|
ReliableMsg::ReliableMsg(sf::Packet &packet, sf::IpAddress address, sf::Uint16 port) : packet(packet), address(address),
|
|
|
|
port(port),
|
|
|
|
lastTry(-std::numeric_limits<double>::max()),
|
|
|
|
firstTry(Time::time()) {}
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-31 11:39:08 +03:00
|
|
|
ReliableMsg::ReliableMsg(const ReliableMsg &msg) : packet(msg.packet), address(msg.address), port(msg.port),
|
|
|
|
lastTry(msg.lastTry), firstTry(msg.firstTry) {}
|
|
|
|
|
|
|
|
bool ReliableMsg::trySend(sf::UdpSocket &socket) {
|
2021-10-28 16:58:02 +03:00
|
|
|
if (Time::time() - firstTry > Consts::NETWORK_TIMEOUT) {
|
2021-09-13 15:53:43 +03:00
|
|
|
return false;
|
2021-10-28 16:58:02 +03:00
|
|
|
}
|
|
|
|
if (Time::time() - lastTry > Consts::NETWORK_RELIABLE_RETRY_TIME) {
|
2021-09-13 15:53:43 +03:00
|
|
|
lastTry = Time::time();
|
|
|
|
socket.send(packet, address, port);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|