Network: Fix some warnings

This commit is contained in:
SirLynix 2024-02-24 18:27:14 +01:00
parent 7956e1552b
commit edac2e4af5
4 changed files with 78 additions and 80 deletions

View File

@ -79,25 +79,25 @@ namespace Nz
Zombie = 9
};
enum ENetProtocolCommand
enum class ENetProtocolCommand
{
// Keeping the values is important for compatibility with the native ENet protocol
ENetProtocolCommand_Acknowledge = 1,
ENetProtocolCommand_BandwidthLimit = 10,
ENetProtocolCommand_Connect = 2,
ENetProtocolCommand_Disconnect = 4,
ENetProtocolCommand_None = 0,
ENetProtocolCommand_Ping = 5,
ENetProtocolCommand_SendFragment = 8,
ENetProtocolCommand_SendReliable = 6,
ENetProtocolCommand_SendUnreliable = 7,
ENetProtocolCommand_SendUnreliableFragment = 12,
ENetProtocolCommand_SendUnsequenced = 9,
ENetProtocolCommand_ThrottleConfigure = 11,
ENetProtocolCommand_VerifyConnect = 3,
ENetProtocolCommand_Count = 13,
Acknowledge = 1,
BandwidthLimit = 10,
Connect = 2,
Disconnect = 4,
None = 0,
Ping = 5,
SendFragment = 8,
SendReliable = 6,
SendUnreliable = 7,
SendUnreliableFragment = 12,
SendUnsequenced = 9,
ThrottleConfigure = 11,
VerifyConnect = 3,
Count = 13,
ENetProtocolCommand_Mask = 0x0F
Mask = 0x0F
};
enum ENetProtocolFlag

View File

@ -16,13 +16,14 @@
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Network/Algorithm.hpp>
#include <Nazara/Network/ENetPeer.hpp>
#include <NazaraUtils/EnumArray.hpp>
#include <NazaraUtils/OffsetOf.hpp>
namespace Nz
{
namespace
{
constexpr std::size_t s_enetCommandSizes[ENetProtocolCommand_Count] =
constexpr EnumArray<ENetProtocolCommand, std::size_t> s_enetCommandSizes =
{
0,
sizeof(ENetProtocolAcknowledge),
@ -109,7 +110,7 @@ namespace Nz
ENetPeer& peer = m_peers[peerId];
peer.InitOutgoing(channelCount, remoteAddress, ++m_randomSeed, windowSize);
ENetProtocol command(ENetProtocolCommand_Connect | ENetProtocolFlag_Acknowledge, 0xFF);
ENetProtocol command(UInt8(ENetProtocolCommand::Connect) | UInt8(ENetProtocolFlag_Acknowledge), 0xFF);
command.connect.channelCount = HostToNet(static_cast<UInt32>(channelCount));
command.connect.connectID = peer.m_connectID;
command.connect.data = HostToNet(data);
@ -468,7 +469,7 @@ namespace Nz
windowSize = std::max(windowSize, NetToHost(command->connect.windowSize));
windowSize = Clamp<UInt32>(windowSize, ENetConstants::ENetProtocol_MinimumWindowSize, ENetConstants::ENetProtocol_MaximumWindowSize);
ENetProtocol verifyCommand(ENetProtocolCommand_VerifyConnect | ENetProtocolFlag_Acknowledge, 0xFF);
ENetProtocol verifyCommand(UInt8(ENetProtocolCommand::VerifyConnect) | UInt8(ENetProtocolFlag_Acknowledge), 0xFF);
verifyCommand.verifyConnect.connectID = peer->m_connectID;
verifyCommand.verifyConnect.incomingSessionID = peer->m_outgoingSessionID;
verifyCommand.verifyConnect.outgoingSessionID = peer->m_incomingSessionID;
@ -565,30 +566,30 @@ namespace Nz
if (currentData + sizeof(ENetProtocolCommandHeader) > &m_receivedData[m_receivedDataLength])
break;
UInt8 commandNumber = command->header.command & ENetProtocolCommand_Mask;
if (commandNumber >= ENetProtocolCommand_Count)
ENetProtocolCommand commandType = static_cast<ENetProtocolCommand>(command->header.command & UInt8(ENetProtocolCommand::Mask));
if (commandType >= ENetProtocolCommand::Count)
break;
std::size_t commandSize = s_enetCommandSizes[commandNumber];
std::size_t commandSize = s_enetCommandSizes[commandType];
if (commandSize == 0 || currentData + commandSize > &m_receivedData[m_receivedDataLength])
break;
currentData += commandSize;
if (!peer && commandNumber != ENetProtocolCommand_Connect)
if (!peer && commandType != ENetProtocolCommand::Connect)
break;
command->header.reliableSequenceNumber = NetToHost(command->header.reliableSequenceNumber);
switch (commandNumber)
switch (commandType)
{
case ENetProtocolCommand_Acknowledge:
case ENetProtocolCommand::Acknowledge:
if (!peer->HandleAcknowledge(command, event))
return commandError();
break;
case ENetProtocolCommand_Connect:
case ENetProtocolCommand::Connect:
if (peer)
return commandError();
@ -598,61 +599,61 @@ namespace Nz
break;
case ENetProtocolCommand_VerifyConnect:
case ENetProtocolCommand::VerifyConnect:
if (!peer->HandleVerifyConnect(command, event))
return commandError();
break;
case ENetProtocolCommand_Disconnect:
case ENetProtocolCommand::Disconnect:
if (!peer->HandleDisconnect(command))
return commandError();
break;
case ENetProtocolCommand_Ping:
case ENetProtocolCommand::Ping:
if (!peer->HandlePing(command))
return commandError();
break;
case ENetProtocolCommand_SendReliable:
case ENetProtocolCommand::SendReliable:
if (!peer->HandleSendReliable(command, &currentData))
return commandError();
break;
case ENetProtocolCommand_SendUnreliable:
case ENetProtocolCommand::SendUnreliable:
if (!peer->HandleSendUnreliable(command, &currentData))
return commandError();
break;
case ENetProtocolCommand_SendUnsequenced:
case ENetProtocolCommand::SendUnsequenced:
if (!peer->HandleSendUnsequenced(command, &currentData))
return commandError();
break;
case ENetProtocolCommand_SendFragment:
case ENetProtocolCommand::SendFragment:
if (!peer->HandleSendFragment(command, &currentData))
return commandError();
break;
case ENetProtocolCommand_BandwidthLimit:
case ENetProtocolCommand::BandwidthLimit:
if (!peer->HandleBandwidthLimit(command))
return commandError();
break;
case ENetProtocolCommand_ThrottleConfigure:
case ENetProtocolCommand::ThrottleConfigure:
if (!peer->HandleThrottleConfigure(command))
return commandError();
break;
case ENetProtocolCommand_SendUnreliableFragment:
case ENetProtocolCommand::SendUnreliableFragment:
if (!peer->HandleSendUnreliableFragment(command, &currentData))
return commandError();
@ -684,7 +685,7 @@ namespace Nz
break;
case ENetPeerState::AcknowledgingDisconnect:
if ((command->header.command & ENetProtocolCommand_Mask) == ENetProtocolCommand_Disconnect)
if (commandType == ENetProtocolCommand::Disconnect)
peer->QueueAcknowledgement(command, sentTime);
break;
@ -832,13 +833,13 @@ namespace Nz
UInt16 reliableSequenceNumber = HostToNet(acknowledgement.command.header.reliableSequenceNumber);
command.header.command = ENetProtocolCommand_Acknowledge;
command.header.command = UInt8(ENetProtocolCommand::Acknowledge);
command.header.channelID = acknowledgement.command.header.channelID;
command.header.reliableSequenceNumber = reliableSequenceNumber;
command.acknowledge.receivedReliableSequenceNumber = reliableSequenceNumber;
command.acknowledge.receivedSentTime = HostToNet(UInt16(acknowledgement.sentTime));
if ((acknowledgement.command.header.command & ENetProtocolCommand_Mask) == ENetProtocolCommand_Disconnect)
if (static_cast<ENetProtocolCommand>(acknowledgement.command.header.command & UInt8(ENetProtocolCommand::Mask)) == ENetProtocolCommand::Disconnect)
peer->DispatchState(ENetPeerState::Zombie);
++m_bufferCount;
@ -895,8 +896,7 @@ namespace Nz
canPing = false;
assert((outgoingCommand->command.header.command & ENetProtocolCommand_Mask) < ENetProtocolCommand_Count);
std::size_t commandSize = s_enetCommandSizes[outgoingCommand->command.header.command & ENetProtocolCommand_Mask];
std::size_t commandSize = GetCommandSize(outgoingCommand->command.header.command);
if (m_commandCount >= m_commands.size() || m_bufferCount + 1 >= m_buffers.size() || peer->GetMtu() - m_packetSize < commandSize ||
(outgoingCommand->packet && UInt16(peer->GetMtu() - m_packetSize) < UInt16(commandSize + outgoingCommand->fragmentLength)))
{
@ -1167,8 +1167,7 @@ namespace Nz
{
auto outgoingCommand = currentCommand;
assert((outgoingCommand->command.header.command & ENetProtocolCommand_Mask) < ENetProtocolCommand_Count);
std::size_t commandSize = s_enetCommandSizes[outgoingCommand->command.header.command & ENetProtocolCommand_Mask];
std::size_t commandSize = GetCommandSize(outgoingCommand->command.header.command);
if (m_commandCount >= m_commands.size() || m_bufferCount + 1 >= m_buffers.size() || peer->m_mtu - m_packetSize < commandSize ||
(outgoingCommand->packet && peer->m_mtu - m_packetSize < commandSize + outgoingCommand->fragmentLength))
@ -1366,7 +1365,7 @@ namespace Nz
if (!peer.IsConnected())
continue;
ENetProtocol command(ENetProtocolCommand_BandwidthLimit | ENetProtocolFlag_Acknowledge, 0xFF);
ENetProtocol command(UInt8(ENetProtocolCommand::BandwidthLimit) | UInt8(ENetProtocolFlag_Acknowledge), 0xFF);
command.bandwidthLimit.outgoingBandwidth = HostToNet(m_outgoingBandwidth);
if (peer.m_incomingBandwidthThrottleEpoch == currentTime)
@ -1381,8 +1380,8 @@ namespace Nz
std::size_t ENetHost::GetCommandSize(UInt8 commandNumber)
{
assert((commandNumber & ENetProtocolCommand_Mask) < ENetProtocolCommand_Count);
return s_enetCommandSizes[commandNumber & ENetProtocolCommand_Mask];
assert((commandNumber & UInt8(ENetProtocolCommand::Mask)) < UInt8(ENetProtocolCommand::Count));
return s_enetCommandSizes[static_cast<ENetProtocolCommand>(commandNumber & UInt8(ENetProtocolCommand::Mask))];
}
bool ENetHost::Initialize()

View File

@ -28,7 +28,7 @@ namespace Nz
ResetQueues();
ENetProtocol command(ENetProtocolCommand_Disconnect, 0xFF);
ENetProtocol command(UInt8(ENetProtocolCommand::Disconnect), 0xFF);
command.disconnect.data = HostToNet(data);
if (IsConnected())
@ -72,7 +72,7 @@ namespace Nz
{
ResetQueues();
ENetProtocol command(ENetProtocolCommand_Disconnect | ENetProtocolFlag_Unsequenced, 0xFF);
ENetProtocol command(UInt8(ENetProtocolCommand::Disconnect) | UInt8(ENetProtocolFlag_Unsequenced), 0xFF);
command.disconnect.data = HostToNet(data);
QueueOutgoingCommand(command);
@ -88,7 +88,7 @@ namespace Nz
return;
ENetProtocol command;
command.header.command = ENetProtocolCommand_Ping | ENetProtocolFlag_Acknowledge;
command.header.command = UInt8(ENetProtocolCommand::Ping) | UInt8(ENetProtocolFlag_Acknowledge);
command.header.channelID = 0xFF;
QueueOutgoingCommand(command);
}
@ -214,12 +214,12 @@ namespace Nz
if ((packetRef->flags & (ENetPacketFlag::Reliable | ENetPacketFlag::UnreliableFragment)) == ENetPacketFlag::UnreliableFragment &&
channel.outgoingUnreliableSequenceNumber < 0xFFFF)
{
commandNumber = ENetProtocolCommand_SendUnreliableFragment;
commandNumber = UInt8(ENetProtocolCommand::SendUnreliableFragment);
startSequenceNumber = HostToNet<UInt16>(channel.outgoingUnreliableSequenceNumber + 1);
}
else
{
commandNumber = ENetProtocolCommand_SendFragment | ENetProtocolFlag_Acknowledge;
commandNumber = UInt8(ENetProtocolCommand::SendFragment) | UInt8(ENetProtocolFlag_Acknowledge);
startSequenceNumber = HostToNet<UInt16>(channel.outgoingReliableSequenceNumber + 1);
}
@ -257,17 +257,17 @@ namespace Nz
if ((packetRef->flags & (ENetPacketFlag::Reliable | ENetPacketFlag::Unsequenced)) == ENetPacketFlag::Unsequenced)
{
command.header.command = ENetProtocolCommand_SendUnsequenced | ENetProtocolFlag_Unsequenced;
command.header.command = UInt8(ENetProtocolCommand::SendUnsequenced) | UInt8(ENetProtocolFlag_Unsequenced);
command.sendUnsequenced.dataLength = HostToNet(SafeCast<UInt16>(packetRef->data.GetSize()));
}
else if (packetRef->flags & ENetPacketFlag::Reliable || channel.outgoingUnreliableSequenceNumber >= 0xFFFF)
{
command.header.command = ENetProtocolCommand_SendReliable | ENetProtocolFlag_Acknowledge;
command.header.command = UInt8(ENetProtocolCommand::SendReliable) | UInt8(ENetProtocolFlag_Acknowledge);
command.sendReliable.dataLength = HostToNet(SafeCast<UInt16>(packetRef->data.GetSize()));
}
else
{
command.header.command = ENetProtocolCommand_SendUnreliable;
command.header.command = UInt8(ENetProtocolCommand::SendUnreliable);
command.sendUnreliable.dataLength = HostToNet(SafeCast<UInt16>(packetRef->data.GetSize()));
}
@ -282,7 +282,7 @@ namespace Nz
m_packetThrottleAcceleration = acceleration;
m_packetThrottleDeceleration = deceleration;
ENetProtocol command(ENetProtocolCommand_ThrottleConfigure | ENetProtocolFlag_Acknowledge, 0xFF);
ENetProtocol command(UInt8(ENetProtocolCommand::ThrottleConfigure) | UInt8(ENetProtocolFlag_Acknowledge), 0xFF);
command.throttleConfigure.packetThrottleInterval = HostToNet(interval);
command.throttleConfigure.packetThrottleAcceleration = HostToNet(acceleration);
command.throttleConfigure.packetThrottleDeceleration = HostToNet(deceleration);
@ -387,7 +387,7 @@ namespace Nz
{
IncomingCommmand& incomingCommand = *currentCommand;
if ((incomingCommand.command.header.command & ENetProtocolCommand_Mask) == ENetProtocolCommand_SendUnsequenced)
if ((incomingCommand.command.header.command & UInt8(ENetProtocolCommand::Mask)) == UInt8(ENetProtocolCommand::SendUnsequenced))
continue;
if (incomingCommand.reliableSequenceNumber == channel.incomingReliableSequenceNumber)
@ -504,14 +504,14 @@ namespace Nz
switch (m_state)
{
case ENetPeerState::AcknowledgingConnect:
if (commandNumber != ENetProtocolCommand_VerifyConnect)
if (commandNumber != ENetProtocolCommand::VerifyConnect)
return false;
m_host->NotifyConnect(this, event, true);
break;
case ENetPeerState::Disconnecting:
if (commandNumber != ENetProtocolCommand_Disconnect)
if (commandNumber != ENetProtocolCommand::Disconnect)
return false;
m_host->NotifyDisconnect(this, event, false);
@ -648,7 +648,7 @@ namespace Nz
if (incomingCommand.reliableSequenceNumber < startSequenceNumber)
break;
if ((incomingCommand.command.header.command & ENetProtocolCommand_Mask) != ENetProtocolCommand_SendFragment ||
if ((incomingCommand.command.header.command & UInt8(ENetProtocolCommand::Mask)) != UInt8(ENetProtocolCommand::SendFragment) ||
totalLength != incomingCommand.packet->data.GetSize() || fragmentCount != incomingCommand.fragments.GetSize())
return false;
@ -776,7 +776,7 @@ namespace Nz
if (incomingCommand.unreliableSequenceNumber < startSequenceNumber)
break;
if ((incomingCommand.command.header.command & ENetProtocolCommand_Mask) != ENetProtocolCommand_SendUnreliableFragment ||
if ((incomingCommand.command.header.command & UInt8(ENetProtocolCommand::Mask)) != UInt8(ENetProtocolCommand::SendUnreliableFragment) ||
totalLength != incomingCommand.packet->data.GetSize() || fragmentCount != incomingCommand.fragments.GetSize())
return false;
@ -1001,7 +1001,7 @@ namespace Nz
found = true;
if (currentCommand->sendAttempts < 1)
return ENetProtocolCommand_None;
return ENetProtocolCommand::None;
if (currentCommand->reliableSequenceNumber == reliableSequenceNumber &&
currentCommand->command.header.channelID == channelId)
@ -1009,13 +1009,13 @@ namespace Nz
}
if (currentCommand == m_outgoingReliableCommands.end())
return ENetProtocolCommand_None;
return ENetProtocolCommand::None;
wasSent = false;
}
if (!found) //< Really useful?
return ENetProtocolCommand_None;
return ENetProtocolCommand::None;
if (channelId < m_channels.size())
{
@ -1030,7 +1030,7 @@ namespace Nz
}
}
ENetProtocolCommand commandNumber = static_cast<ENetProtocolCommand>(currentCommand->command.header.command & ENetProtocolCommand_Mask);
ENetProtocolCommand commandNumber = static_cast<ENetProtocolCommand>(currentCommand->command.header.command & UInt8(ENetProtocolCommand::Mask));
if (currentCommand->packet && wasSent)
{
@ -1127,7 +1127,7 @@ namespace Nz
Channel& channel = m_channels[command.header.channelID];
if ((command.header.command & ENetProtocolCommand_Mask) != ENetProtocolCommand_SendUnsequenced)
if ((command.header.command & UInt8(ENetProtocolCommand::Mask)) != UInt8(ENetProtocolCommand::SendUnsequenced))
{
reliableSequenceNumber = command.header.reliableSequenceNumber;
reliableWindow = static_cast<UInt16>(reliableSequenceNumber / ENetConstants::ENetPeer_ReliableWindowSize);
@ -1143,10 +1143,10 @@ namespace Nz
std::list<IncomingCommmand>* commandList = nullptr;
std::list<IncomingCommmand>::reverse_iterator currentCommand;
switch (command.header.command & ENetProtocolCommand_Mask)
switch (static_cast<ENetProtocolCommand>(command.header.command & UInt8(ENetProtocolCommand::Mask)))
{
case ENetProtocolCommand_SendFragment:
case ENetProtocolCommand_SendReliable:
case ENetProtocolCommand::SendFragment:
case ENetProtocolCommand::SendReliable:
{
if (reliableSequenceNumber == channel.incomingReliableSequenceNumber)
return discardCommand();
@ -1177,8 +1177,8 @@ namespace Nz
break;
}
case ENetProtocolCommand_SendUnreliable:
case ENetProtocolCommand_SendUnreliableFragment:
case ENetProtocolCommand::SendUnreliable:
case ENetProtocolCommand::SendUnreliableFragment:
{
unreliableSequenceNumber = NetToHost(command.sendUnreliable.unreliableSequenceNumber);
@ -1191,7 +1191,7 @@ namespace Nz
{
IncomingCommmand& incomingCommand = *currentCommand;
if ((command.header.command & ENetProtocolCommand_Mask) == ENetProtocolCommand_SendUnsequenced) //< wtf
if ((command.header.command & UInt8(ENetProtocolCommand::Mask)) == UInt8(ENetProtocolCommand::SendUnsequenced)) //< wtf
continue;
if (reliableSequenceNumber >= channel.incomingReliableSequenceNumber)
@ -1220,7 +1220,7 @@ namespace Nz
break;
}
case ENetProtocolCommand_SendUnsequenced:
case ENetProtocolCommand::SendUnsequenced:
{
commandList = &channel.incomingUnreliableCommands;
@ -1251,10 +1251,10 @@ namespace Nz
auto it = commandList->insert(currentCommand.base(), incomingCommand);
switch (command.header.command & ENetProtocolCommand_Mask)
switch (static_cast<ENetProtocolCommand>(command.header.command & UInt8(ENetProtocolCommand::Mask)))
{
case ENetProtocolCommand_SendFragment:
case ENetProtocolCommand_SendReliable:
case ENetProtocolCommand::SendFragment:
case ENetProtocolCommand::SendReliable:
DispatchIncomingReliableCommands(channel);
break;
@ -1325,13 +1325,13 @@ namespace Nz
outgoingCommand.roundTripTimeoutLimit = 0;
outgoingCommand.command.header.reliableSequenceNumber = HostToNet(outgoingCommand.reliableSequenceNumber);
switch (outgoingCommand.command.header.command & ENetProtocolCommand_Mask)
switch (static_cast<ENetProtocolCommand>(outgoingCommand.command.header.command & UInt8(ENetProtocolCommand::Mask)))
{
case ENetProtocolCommand_SendUnreliable:
case ENetProtocolCommand::SendUnreliable:
outgoingCommand.command.sendUnreliable.unreliableSequenceNumber = HostToNet(outgoingCommand.unreliableSequenceNumber);
break;
case ENetProtocolCommand_SendUnsequenced:
case ENetProtocolCommand::SendUnsequenced:
outgoingCommand.command.sendUnsequenced.unsequencedGroup = HostToNet(m_outgoingUnsequencedGroup);
break;

View File

@ -12,7 +12,6 @@
#include <emscripten/fetch.h>
#endif
namespace Nz
{
#ifndef NAZARA_PLATFORM_WEB
@ -178,7 +177,7 @@ namespace Nz
if (m_progressCallback)
{
curl_xferinfo_callback progressCallback = [](void* userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) -> int
curl_xferinfo_callback progressCallback = [](void* userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t /*ultotal*/, curl_off_t /*ulnow*/) -> int
{
WebRequest* request = static_cast<WebRequest*>(userdata);
if (!request->m_progressCallback(SafeCast<UInt64>(dlnow), SafeCast<UInt64>(dltotal)))