mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-05 21:22:07 +02:00
cleanup string grabbing for PacketType enum
This commit is contained in:
parent
288ee0e9e8
commit
0a64242160
4 changed files with 78 additions and 120 deletions
|
@ -55,8 +55,7 @@ bool IceServer::packetVersionMatch(const udt::Packet& packet) {
|
|||
if (headerVersion == versionForPacketType(headerType)) {
|
||||
return true;
|
||||
} else {
|
||||
qDebug() << "Packet version mismatch for packet" << headerType
|
||||
<< "(" << nameForPacketType(headerType) << ") from" << packet.getSenderSockAddr();
|
||||
qDebug() << "Packet version mismatch for packet" << headerType << " from" << packet.getSenderSockAddr();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <math.h>
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QMetaEnum>
|
||||
|
||||
const QSet<PacketType> NON_VERIFIED_PACKETS = QSet<PacketType>()
|
||||
<< PacketType::NodeJsonStats << PacketType::EntityQuery
|
||||
|
@ -46,60 +47,6 @@ PacketVersion versionForPacketType(PacketType packetType) {
|
|||
}
|
||||
}
|
||||
|
||||
#define PACKET_TYPE_NAME_LOOKUP(x) case x: return QString(#x);
|
||||
|
||||
QString nameForPacketType(PacketType packetType) {
|
||||
switch (packetType) {
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::Unknown);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::StunResponse);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::DomainList);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::Ping);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::PingReply);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::KillAvatar);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::AvatarData);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::InjectAudio);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::MixedAudio);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::MicrophoneAudioNoEcho);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::MicrophoneAudioWithEcho);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::BulkAvatarData);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::SilentAudioFrame);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::DomainListRequest);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::RequestAssignment);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::CreateAssignment);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::DomainConnectionDenied);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::MuteEnvironment);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::AudioStreamStats);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::OctreeStats);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::Jurisdiction);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::JurisdictionRequest);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::AvatarIdentity);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::AvatarBillboard);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::DomainConnectRequest);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::DomainServerRequireDTLS);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::NodeJsonStats);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::EntityQuery);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::EntityData);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::EntityErase);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::OctreeDataNack);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::StopNode);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::AudioEnvironment);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::EntityEditNack);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::ICEServerHeartbeat);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::DomainServerAddedNode);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::ICEServerQuery);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::ICEServerPeerInformation);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::ICEPing);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::ICEPingReply);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::EntityAdd);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::EntityEdit);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::DomainServerConnectionToken);
|
||||
PACKET_TYPE_NAME_LOOKUP(PacketType::NodeDisconnect)
|
||||
default:
|
||||
return QString("Type: ") + QString::number((int)packetType);
|
||||
}
|
||||
return QString("unexpected");
|
||||
}
|
||||
|
||||
uint qHash(const PacketType& key, uint seed) {
|
||||
// seems odd that Qt couldn't figure out this cast itself, but this fixes a compile error after switch to
|
||||
// strongly typed enum for PacketType
|
||||
|
@ -107,6 +54,10 @@ uint qHash(const PacketType& key, uint seed) {
|
|||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, const PacketType& type) {
|
||||
debug.nospace() << (uint8_t) type << " (" << qPrintable(nameForPacketType(type)) << ")";
|
||||
QMetaObject metaObject = PacketTypeEnum::staticMetaObject;
|
||||
QMetaEnum metaEnum = metaObject.enumerator(metaObject.enumeratorOffset());
|
||||
QString typeName = metaEnum.valueToKey((int) type);
|
||||
|
||||
debug.nospace().noquote() << (uint8_t) type << " (" << typeName << ")";
|
||||
return debug.space();
|
||||
}
|
||||
|
|
|
@ -18,71 +18,80 @@
|
|||
#include <map>
|
||||
|
||||
#include <QtCore/QCryptographicHash>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QSet>
|
||||
#include <QtCore/QUuid>
|
||||
|
||||
// If adding a new packet packetType, you can replace one marked usable or add at the end.
|
||||
// If you want the name of the packet packetType to be available for debugging or logging, update nameForPacketType() as well
|
||||
// This enum must hold 256 or fewer packet types (so the value is <= 255) since it is statically typed as a uint8_t
|
||||
enum class PacketType : uint8_t {
|
||||
Unknown,
|
||||
StunResponse,
|
||||
DomainList,
|
||||
Ping,
|
||||
PingReply,
|
||||
KillAvatar,
|
||||
AvatarData,
|
||||
InjectAudio,
|
||||
MixedAudio,
|
||||
MicrophoneAudioNoEcho,
|
||||
MicrophoneAudioWithEcho,
|
||||
BulkAvatarData,
|
||||
SilentAudioFrame,
|
||||
DomainListRequest,
|
||||
RequestAssignment,
|
||||
CreateAssignment,
|
||||
DomainConnectionDenied,
|
||||
MuteEnvironment,
|
||||
AudioStreamStats,
|
||||
DomainServerPathQuery,
|
||||
DomainServerPathResponse,
|
||||
DomainServerAddedNode,
|
||||
ICEServerPeerInformation,
|
||||
ICEServerQuery,
|
||||
OctreeStats,
|
||||
Jurisdiction,
|
||||
JurisdictionRequest,
|
||||
AssignmentClientStatus,
|
||||
NoisyMute,
|
||||
AvatarIdentity,
|
||||
AvatarBillboard,
|
||||
DomainConnectRequest,
|
||||
DomainServerRequireDTLS,
|
||||
NodeJsonStats,
|
||||
OctreeDataNack,
|
||||
StopNode,
|
||||
AudioEnvironment,
|
||||
EntityEditNack,
|
||||
ICEServerHeartbeat,
|
||||
ICEPing,
|
||||
ICEPingReply,
|
||||
EntityData,
|
||||
EntityQuery,
|
||||
EntityAdd,
|
||||
EntityErase,
|
||||
EntityEdit,
|
||||
DomainServerConnectionToken,
|
||||
DomainSettingsRequest,
|
||||
DomainSettings,
|
||||
AssetGet,
|
||||
AssetGetReply,
|
||||
AssetUpload,
|
||||
AssetUploadReply,
|
||||
AssetGetInfo,
|
||||
AssetGetInfoReply,
|
||||
NodeDisconnect
|
||||
// The enums are inside this PacketTypeEnum for run-time conversion of enum value to string via
|
||||
// Q_ENUMS, without requiring a macro that is called for each enum value.
|
||||
class PacketTypeEnum {
|
||||
Q_GADGET
|
||||
Q_ENUMS(Value)
|
||||
public:
|
||||
// If adding a new packet packetType, you can replace one marked usable or add at the end.
|
||||
// This enum must hold 256 or fewer packet types (so the value is <= 255) since it is statically typed as a uint8_t
|
||||
enum class Value : uint8_t {
|
||||
Unknown,
|
||||
StunResponse,
|
||||
DomainList,
|
||||
Ping,
|
||||
PingReply,
|
||||
KillAvatar,
|
||||
AvatarData,
|
||||
InjectAudio,
|
||||
MixedAudio,
|
||||
MicrophoneAudioNoEcho,
|
||||
MicrophoneAudioWithEcho,
|
||||
BulkAvatarData,
|
||||
SilentAudioFrame,
|
||||
DomainListRequest,
|
||||
RequestAssignment,
|
||||
CreateAssignment,
|
||||
DomainConnectionDenied,
|
||||
MuteEnvironment,
|
||||
AudioStreamStats,
|
||||
DomainServerPathQuery,
|
||||
DomainServerPathResponse,
|
||||
DomainServerAddedNode,
|
||||
ICEServerPeerInformation,
|
||||
ICEServerQuery,
|
||||
OctreeStats,
|
||||
Jurisdiction,
|
||||
JurisdictionRequest,
|
||||
AssignmentClientStatus,
|
||||
NoisyMute,
|
||||
AvatarIdentity,
|
||||
AvatarBillboard,
|
||||
DomainConnectRequest,
|
||||
DomainServerRequireDTLS,
|
||||
NodeJsonStats,
|
||||
OctreeDataNack,
|
||||
StopNode,
|
||||
AudioEnvironment,
|
||||
EntityEditNack,
|
||||
ICEServerHeartbeat,
|
||||
ICEPing,
|
||||
ICEPingReply,
|
||||
EntityData,
|
||||
EntityQuery,
|
||||
EntityAdd,
|
||||
EntityErase,
|
||||
EntityEdit,
|
||||
DomainServerConnectionToken,
|
||||
DomainSettingsRequest,
|
||||
DomainSettings,
|
||||
AssetGet,
|
||||
AssetGetReply,
|
||||
AssetUpload,
|
||||
AssetUploadReply,
|
||||
AssetGetInfo,
|
||||
AssetGetInfoReply,
|
||||
NodeDisconnect
|
||||
};
|
||||
};
|
||||
|
||||
using PacketType = PacketTypeEnum::Value;
|
||||
|
||||
const int NUM_BYTES_MD5_HASH = 16;
|
||||
|
||||
typedef char PacketVersion;
|
||||
|
@ -91,7 +100,6 @@ extern const QSet<PacketType> NON_VERIFIED_PACKETS;
|
|||
extern const QSet<PacketType> NON_SOURCED_PACKETS;
|
||||
extern const QSet<PacketType> RELIABLE_PACKETS;
|
||||
|
||||
QString nameForPacketType(PacketType packetType);
|
||||
PacketVersion versionForPacketType(PacketType packetType);
|
||||
|
||||
uint qHash(const PacketType& key, uint seed);
|
||||
|
|
|
@ -1890,8 +1890,8 @@ bool Octree::readSVOFromStream(unsigned long streamLength, QDataStream& inputStr
|
|||
versionForPacketType(expectedDataPacketType()), gotVersion);
|
||||
}
|
||||
} else {
|
||||
qCDebug(octree) << "SVO file type mismatch. Expected: " << nameForPacketType(expectedType)
|
||||
<< " Got: " << nameForPacketType(gotType);
|
||||
qCDebug(octree) << "SVO file type mismatch. Expected: " << expectedType
|
||||
<< " Got: " << gotType;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue