aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Server/Packets
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2025-11-02 17:19:01 +0100
committerShauren <shauren.trinity@gmail.com>2025-11-02 17:19:01 +0100
commit57489f4ca9ea320678426bb70d2941c60ef9f33c (patch)
tree470f27ed72de80f9033c28851e4b43df2e3c6146 /src/server/game/Server/Packets
parent9d1bdda6d877c58b4fb0c0085a3cfa4bc802893e (diff)
Core/PacketIO: Reduce the number of catch blocks in WorldSession::Update
Diffstat (limited to 'src/server/game/Server/Packets')
-rw-r--r--src/server/game/Server/Packets/PacketUtilities.cpp21
-rw-r--r--src/server/game/Server/Packets/PacketUtilities.h23
2 files changed, 30 insertions, 14 deletions
diff --git a/src/server/game/Server/Packets/PacketUtilities.cpp b/src/server/game/Server/Packets/PacketUtilities.cpp
index 4227833e6b0..34fc9923379 100644
--- a/src/server/game/Server/Packets/PacketUtilities.cpp
+++ b/src/server/game/Server/Packets/PacketUtilities.cpp
@@ -20,20 +20,29 @@
#include "StringFormat.h"
#include <utf8.h>
-WorldPackets::InvalidStringValueException::InvalidStringValueException(std::string_view value) : ByteBufferInvalidValueException("string", value), _value(value)
+WorldPackets::InvalidStringValueException::InvalidStringValueException(char const* type, std::string_view value)
+ : ByteBufferInvalidValueException(type, value), _value(value)
{
}
-WorldPackets::InvalidUtf8ValueException::InvalidUtf8ValueException(std::string_view value) : InvalidStringValueException(value)
+WorldPackets::InvalidUtf8ValueException::InvalidUtf8ValueException(std::string_view value)
+ : InvalidStringValueException("utf8 string", value)
{
}
-WorldPackets::InvalidHyperlinkException::InvalidHyperlinkException(std::string_view value) : InvalidStringValueException(value)
+WorldPackets::InvalidHyperlinkException::InvalidHyperlinkException(std::string_view value, Reason reason)
+ : InvalidStringValueException(GetReasonText(reason), value), _reason(reason)
{
}
-WorldPackets::IllegalHyperlinkException::IllegalHyperlinkException(std::string_view value) : InvalidStringValueException(value)
+char const* WorldPackets::InvalidHyperlinkException::GetReasonText(Reason reason)
{
+ switch (reason)
+ {
+ case Malformed: return "malformed hyperlink";
+ case NotAllowed: return "not allowed hyperlink";
+ default: return "hyperlink";
+ }
}
bool WorldPackets::Strings::Utf8::Validate(std::string_view value)
@@ -46,14 +55,14 @@ bool WorldPackets::Strings::Utf8::Validate(std::string_view value)
bool WorldPackets::Strings::Hyperlinks::Validate(std::string_view value)
{
if (!Trinity::Hyperlinks::CheckAllLinks(value))
- throw InvalidHyperlinkException(value);
+ throw InvalidHyperlinkException(value, InvalidHyperlinkException::Malformed);
return true;
}
bool WorldPackets::Strings::NoHyperlinks::Validate(std::string_view value)
{
if (value.find('|') != std::string::npos)
- throw IllegalHyperlinkException(value);
+ throw InvalidHyperlinkException(value, InvalidHyperlinkException::NotAllowed);
return true;
}
diff --git a/src/server/game/Server/Packets/PacketUtilities.h b/src/server/game/Server/Packets/PacketUtilities.h
index 3170b11b180..055df04cd90 100644
--- a/src/server/game/Server/Packets/PacketUtilities.h
+++ b/src/server/game/Server/Packets/PacketUtilities.h
@@ -30,7 +30,7 @@ namespace WorldPackets
class InvalidStringValueException : public ByteBufferInvalidValueException
{
public:
- InvalidStringValueException(std::string_view value);
+ explicit InvalidStringValueException(char const* type, std::string_view value);
std::string const& GetInvalidValue() const { return _value; }
@@ -41,19 +41,26 @@ namespace WorldPackets
class InvalidUtf8ValueException : public InvalidStringValueException
{
public:
- InvalidUtf8ValueException(std::string_view value);
+ explicit InvalidUtf8ValueException(std::string_view value);
};
class InvalidHyperlinkException : public InvalidStringValueException
{
public:
- InvalidHyperlinkException(std::string_view value);
- };
+ enum Reason : uint8
+ {
+ Malformed,
+ NotAllowed
+ };
- class IllegalHyperlinkException : public InvalidStringValueException
- {
- public:
- IllegalHyperlinkException(std::string_view value);
+ explicit InvalidHyperlinkException(std::string_view value, Reason reason);
+
+ Reason GetReason() const { return _reason; }
+
+ private:
+ static char const* GetReasonText(Reason reason);
+
+ Reason _reason;
};
namespace Strings