Merge pull request #11145 from AdmiralCurtiss/send-packet-check
Check return values of ENet functions when sending packet.
This commit is contained in:
commit
e28878616f
|
@ -4,6 +4,7 @@
|
||||||
#include "Common/ENetUtil.h"
|
#include "Common/ENetUtil.h"
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
#include "Common/Logging/Log.h"
|
||||||
|
|
||||||
namespace ENetUtil
|
namespace ENetUtil
|
||||||
{
|
{
|
||||||
|
@ -35,4 +36,24 @@ int ENET_CALLBACK InterceptCallback(ENetHost* host, ENetEvent* event)
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SendPacket(ENetPeer* socket, const sf::Packet& packet, u8 channel_id)
|
||||||
|
{
|
||||||
|
ENetPacket* epac =
|
||||||
|
enet_packet_create(packet.getData(), packet.getDataSize(), ENET_PACKET_FLAG_RELIABLE);
|
||||||
|
if (!epac)
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(NETPLAY, "Failed to create ENetPacket ({} bytes).", packet.getDataSize());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int result = enet_peer_send(socket, channel_id, epac);
|
||||||
|
if (result != 0)
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(NETPLAY, "Failed to send ENetPacket (error code {}).", result);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
} // namespace ENetUtil
|
} // namespace ENetUtil
|
||||||
|
|
|
@ -5,8 +5,13 @@
|
||||||
|
|
||||||
#include <enet/enet.h>
|
#include <enet/enet.h>
|
||||||
|
|
||||||
|
#include <SFML/Network/Packet.hpp>
|
||||||
|
|
||||||
|
#include "Common/CommonTypes.h"
|
||||||
|
|
||||||
namespace ENetUtil
|
namespace ENetUtil
|
||||||
{
|
{
|
||||||
void WakeupThread(ENetHost* host);
|
void WakeupThread(ENetHost* host);
|
||||||
int ENET_CALLBACK InterceptCallback(ENetHost* host, ENetEvent* event);
|
int ENET_CALLBACK InterceptCallback(ENetHost* host, ENetEvent* event);
|
||||||
|
bool SendPacket(ENetPeer* socket, const sf::Packet& packet, u8 channel_id);
|
||||||
} // namespace ENetUtil
|
} // namespace ENetUtil
|
||||||
|
|
|
@ -1465,9 +1465,7 @@ void NetPlayClient::OnGameDigestAbort()
|
||||||
|
|
||||||
void NetPlayClient::Send(const sf::Packet& packet, const u8 channel_id)
|
void NetPlayClient::Send(const sf::Packet& packet, const u8 channel_id)
|
||||||
{
|
{
|
||||||
ENetPacket* epac =
|
ENetUtil::SendPacket(m_server, packet, channel_id);
|
||||||
enet_packet_create(packet.getData(), packet.getDataSize(), ENET_PACKET_FLAG_RELIABLE);
|
|
||||||
enet_peer_send(m_server, channel_id, epac);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetPlayClient::DisplayPlayersPing()
|
void NetPlayClient::DisplayPlayersPing()
|
||||||
|
|
|
@ -2008,9 +2008,7 @@ void NetPlayServer::SendToClients(const sf::Packet& packet, const PlayerId skip_
|
||||||
|
|
||||||
void NetPlayServer::Send(ENetPeer* socket, const sf::Packet& packet, const u8 channel_id)
|
void NetPlayServer::Send(ENetPeer* socket, const sf::Packet& packet, const u8 channel_id)
|
||||||
{
|
{
|
||||||
ENetPacket* epac =
|
ENetUtil::SendPacket(socket, packet, channel_id);
|
||||||
enet_packet_create(packet.getData(), packet.getDataSize(), ENET_PACKET_FLAG_RELIABLE);
|
|
||||||
enet_peer_send(socket, channel_id, epac);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetPlayServer::KickPlayer(PlayerId player)
|
void NetPlayServer::KickPlayer(PlayerId player)
|
||||||
|
|
Loading…
Reference in New Issue