TrinityCore
Loading...
Searching...
No Matches
PacketUtilities.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "PacketUtilities.h"
19#include "Hyperlinks.h"
20#include "StringFormat.h"
21#include <utf8.h>
22
24 : ByteBufferInvalidValueException(type, value), _value(value)
25{
26}
27
32
34 : InvalidStringValueException(GetReasonText(reason), value), _reason(reason)
35{
36}
37
39{
40 switch (reason)
41 {
42 case Malformed: return "malformed hyperlink";
43 case NotAllowed: return "not allowed hyperlink";
44 default: return "hyperlink";
45 }
46}
47
48void WorldPackets::Strings::ByteSize::Validate(std::string_view value, std::size_t maxSize)
49{
50 if (std::size_t size = value.size(); size > maxSize)
51 OnInvalidArraySize(size, maxSize);
52}
53
54void WorldPackets::Strings::Utf8::Validate(std::string_view value)
55{
56 if (!utf8::is_valid(value.begin(), value.end()))
57 throw InvalidUtf8ValueException(value);
58}
59
65
67{
68 if (value.find('|') != std::string::npos)
70}
71
72void WorldPackets::OnInvalidArraySize(std::size_t requestedSize, std::size_t sizeLimit)
73{
74 throw PacketArrayMaxCapacityException(requestedSize, sizeLimit);
75}
76
78 : ByteBufferException(Trinity::StringFormat("Attempted to read more array elements from packet {} than allowed {}", requestedSize, sizeLimit))
79{
80}
static char const * GetReasonText(Reason reason)
InvalidHyperlinkException(std::string_view value, Reason reason)
InvalidStringValueException(char const *type, std::string_view value)
InvalidUtf8ValueException(std::string_view value)
PacketArrayMaxCapacityException(std::size_t requestedSize, std::size_t sizeLimit)
void OnInvalidArraySize(std::size_t requestedSize, std::size_t sizeLimit)
static void Validate(std::string_view value, std::size_t maxSize)
static void Validate(std::string_view value)