mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 23:03:12 +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)) {
|
if (headerVersion == versionForPacketType(headerType)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Packet version mismatch for packet" << headerType
|
qDebug() << "Packet version mismatch for packet" << headerType << " from" << packet.getSenderSockAddr();
|
||||||
<< "(" << nameForPacketType(headerType) << ") from" << packet.getSenderSockAddr();
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
|
#include <QtCore/QMetaEnum>
|
||||||
|
|
||||||
const QSet<PacketType> NON_VERIFIED_PACKETS = QSet<PacketType>()
|
const QSet<PacketType> NON_VERIFIED_PACKETS = QSet<PacketType>()
|
||||||
<< PacketType::NodeJsonStats << PacketType::EntityQuery
|
<< 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) {
|
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
|
// 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
|
// strongly typed enum for PacketType
|
||||||
|
@ -107,6 +54,10 @@ uint qHash(const PacketType& key, uint seed) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QDebug operator<<(QDebug debug, const PacketType& type) {
|
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();
|
return debug.space();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,71 +18,80 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include <QtCore/QCryptographicHash>
|
#include <QtCore/QCryptographicHash>
|
||||||
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QSet>
|
#include <QtCore/QSet>
|
||||||
#include <QtCore/QUuid>
|
#include <QtCore/QUuid>
|
||||||
|
|
||||||
// If adding a new packet packetType, you can replace one marked usable or add at the end.
|
// The enums are inside this PacketTypeEnum for run-time conversion of enum value to string via
|
||||||
// If you want the name of the packet packetType to be available for debugging or logging, update nameForPacketType() as well
|
// Q_ENUMS, without requiring a macro that is called for each enum value.
|
||||||
// This enum must hold 256 or fewer packet types (so the value is <= 255) since it is statically typed as a uint8_t
|
class PacketTypeEnum {
|
||||||
enum class PacketType : uint8_t {
|
Q_GADGET
|
||||||
Unknown,
|
Q_ENUMS(Value)
|
||||||
StunResponse,
|
public:
|
||||||
DomainList,
|
// If adding a new packet packetType, you can replace one marked usable or add at the end.
|
||||||
Ping,
|
// This enum must hold 256 or fewer packet types (so the value is <= 255) since it is statically typed as a uint8_t
|
||||||
PingReply,
|
enum class Value : uint8_t {
|
||||||
KillAvatar,
|
Unknown,
|
||||||
AvatarData,
|
StunResponse,
|
||||||
InjectAudio,
|
DomainList,
|
||||||
MixedAudio,
|
Ping,
|
||||||
MicrophoneAudioNoEcho,
|
PingReply,
|
||||||
MicrophoneAudioWithEcho,
|
KillAvatar,
|
||||||
BulkAvatarData,
|
AvatarData,
|
||||||
SilentAudioFrame,
|
InjectAudio,
|
||||||
DomainListRequest,
|
MixedAudio,
|
||||||
RequestAssignment,
|
MicrophoneAudioNoEcho,
|
||||||
CreateAssignment,
|
MicrophoneAudioWithEcho,
|
||||||
DomainConnectionDenied,
|
BulkAvatarData,
|
||||||
MuteEnvironment,
|
SilentAudioFrame,
|
||||||
AudioStreamStats,
|
DomainListRequest,
|
||||||
DomainServerPathQuery,
|
RequestAssignment,
|
||||||
DomainServerPathResponse,
|
CreateAssignment,
|
||||||
DomainServerAddedNode,
|
DomainConnectionDenied,
|
||||||
ICEServerPeerInformation,
|
MuteEnvironment,
|
||||||
ICEServerQuery,
|
AudioStreamStats,
|
||||||
OctreeStats,
|
DomainServerPathQuery,
|
||||||
Jurisdiction,
|
DomainServerPathResponse,
|
||||||
JurisdictionRequest,
|
DomainServerAddedNode,
|
||||||
AssignmentClientStatus,
|
ICEServerPeerInformation,
|
||||||
NoisyMute,
|
ICEServerQuery,
|
||||||
AvatarIdentity,
|
OctreeStats,
|
||||||
AvatarBillboard,
|
Jurisdiction,
|
||||||
DomainConnectRequest,
|
JurisdictionRequest,
|
||||||
DomainServerRequireDTLS,
|
AssignmentClientStatus,
|
||||||
NodeJsonStats,
|
NoisyMute,
|
||||||
OctreeDataNack,
|
AvatarIdentity,
|
||||||
StopNode,
|
AvatarBillboard,
|
||||||
AudioEnvironment,
|
DomainConnectRequest,
|
||||||
EntityEditNack,
|
DomainServerRequireDTLS,
|
||||||
ICEServerHeartbeat,
|
NodeJsonStats,
|
||||||
ICEPing,
|
OctreeDataNack,
|
||||||
ICEPingReply,
|
StopNode,
|
||||||
EntityData,
|
AudioEnvironment,
|
||||||
EntityQuery,
|
EntityEditNack,
|
||||||
EntityAdd,
|
ICEServerHeartbeat,
|
||||||
EntityErase,
|
ICEPing,
|
||||||
EntityEdit,
|
ICEPingReply,
|
||||||
DomainServerConnectionToken,
|
EntityData,
|
||||||
DomainSettingsRequest,
|
EntityQuery,
|
||||||
DomainSettings,
|
EntityAdd,
|
||||||
AssetGet,
|
EntityErase,
|
||||||
AssetGetReply,
|
EntityEdit,
|
||||||
AssetUpload,
|
DomainServerConnectionToken,
|
||||||
AssetUploadReply,
|
DomainSettingsRequest,
|
||||||
AssetGetInfo,
|
DomainSettings,
|
||||||
AssetGetInfoReply,
|
AssetGet,
|
||||||
NodeDisconnect
|
AssetGetReply,
|
||||||
|
AssetUpload,
|
||||||
|
AssetUploadReply,
|
||||||
|
AssetGetInfo,
|
||||||
|
AssetGetInfoReply,
|
||||||
|
NodeDisconnect
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using PacketType = PacketTypeEnum::Value;
|
||||||
|
|
||||||
const int NUM_BYTES_MD5_HASH = 16;
|
const int NUM_BYTES_MD5_HASH = 16;
|
||||||
|
|
||||||
typedef char PacketVersion;
|
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> NON_SOURCED_PACKETS;
|
||||||
extern const QSet<PacketType> RELIABLE_PACKETS;
|
extern const QSet<PacketType> RELIABLE_PACKETS;
|
||||||
|
|
||||||
QString nameForPacketType(PacketType packetType);
|
|
||||||
PacketVersion versionForPacketType(PacketType packetType);
|
PacketVersion versionForPacketType(PacketType packetType);
|
||||||
|
|
||||||
uint qHash(const PacketType& key, uint seed);
|
uint qHash(const PacketType& key, uint seed);
|
||||||
|
|
|
@ -1890,8 +1890,8 @@ bool Octree::readSVOFromStream(unsigned long streamLength, QDataStream& inputStr
|
||||||
versionForPacketType(expectedDataPacketType()), gotVersion);
|
versionForPacketType(expectedDataPacketType()), gotVersion);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qCDebug(octree) << "SVO file type mismatch. Expected: " << nameForPacketType(expectedType)
|
qCDebug(octree) << "SVO file type mismatch. Expected: " << expectedType
|
||||||
<< " Got: " << nameForPacketType(gotType);
|
<< " Got: " << gotType;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue