diff options
| author | Shauren <shauren.trinity@gmail.com> | 2023-05-13 15:46:27 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2023-05-13 15:46:27 +0200 |
| commit | 3260b94dd627b7b0c7114f94bb97d108b005af3e (patch) | |
| tree | 980d58d6db4a3d20785f8bca881d36f79d0f5755 /src/server/game/Chat | |
| parent | c4d40085964109893c76d301b6f7d99f03838fa0 (diff) | |
Core/Misc: Replace string to int conversion functions from Common.h with c++17 std::from_chars based ones Trinity::StringTo
Diffstat (limited to 'src/server/game/Chat')
| -rw-r--r-- | src/server/game/Chat/Channels/Channel.cpp | 11 | ||||
| -rw-r--r-- | src/server/game/Chat/Chat.cpp | 75 | ||||
| -rw-r--r-- | src/server/game/Chat/Chat.h | 1 | ||||
| -rw-r--r-- | src/server/game/Chat/LanguageMgr.cpp | 6 |
4 files changed, 15 insertions, 78 deletions
diff --git a/src/server/game/Chat/Channels/Channel.cpp b/src/server/game/Chat/Channels/Channel.cpp index 3398503d270..dc423a55986 100644 --- a/src/server/game/Chat/Channels/Channel.cpp +++ b/src/server/game/Chat/Channels/Channel.cpp @@ -77,9 +77,16 @@ Channel::Channel(ObjectGuid const& guid, std::string const& name, uint32 team /* for (std::string_view guid : Trinity::Tokenize(banList, ' ', false)) { // legacy db content might not have 0x prefix, account for that - std::string bannedGuidStr(guid.size() > 2 && guid.substr(0, 2) == "0x" ? guid.substr(2) : guid); + if (guid.size() > 2 && guid.substr(0, 2) == "0x") + guid.remove_suffix(2); + + Optional<uint64> high = Trinity::StringTo<uint64>(guid.substr(0, 16), 16); + Optional<uint64> low = Trinity::StringTo<uint64>(guid.substr(16, 16), 16); + if (!high || !low) + continue; + ObjectGuid banned; - banned.SetRawValue(uint64(strtoull(bannedGuidStr.substr(0, 16).c_str(), nullptr, 16)), uint64(strtoull(bannedGuidStr.substr(16).c_str(), nullptr, 16))); + banned.SetRawValue(*high, *low); if (!banned) continue; diff --git a/src/server/game/Chat/Chat.cpp b/src/server/game/Chat/Chat.cpp index b1b1a221c2f..832d14631bc 100644 --- a/src/server/game/Chat/Chat.cpp +++ b/src/server/game/Chat/Chat.cpp @@ -22,18 +22,15 @@ #include "ChatCommand.h" #include "ChatPackets.h" #include "Common.h" -#include "DatabaseEnv.h" -#include "DB2Stores.h" #include "GridNotifiersImpl.h" #include "Group.h" #include "Language.h" -#include "Log.h" #include "ObjectAccessor.h" #include "ObjectMgr.h" #include "Optional.h" #include "Player.h" #include "Realm.h" -#include "ScriptMgr.h" +#include "StringConvert.h" #include "World.h" #include "WorldSession.h" #include <boost/algorithm/string/replace.hpp> @@ -413,72 +410,6 @@ Creature* ChatHandler::GetCreatureFromPlayerMapByDbGuid(ObjectGuid::LowType lowg return creature; } -enum SpellLinkType -{ - SPELL_LINK_SPELL = 0, - SPELL_LINK_TALENT = 1, - SPELL_LINK_ENCHANT = 2, - SPELL_LINK_TRADE = 3, - SPELL_LINK_GLYPH = 4 -}; - -static char const* const spellKeys[] = -{ - "Hspell", // normal spell - "Htalent", // talent spell - "Henchant", // enchanting recipe spell - "Htrade", // profession/skill spell - "Hglyph", // glyph - nullptr -}; - -uint32 ChatHandler::extractSpellIdFromLink(char* text) -{ - // number or [name] Shift-click form |color|Henchant:recipe_spell_id|h[prof_name: recipe_name]|h|r - // number or [name] Shift-click form |color|Hglyph:glyph_slot_id:glyph_prop_id|h[%s]|h|r - // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r - // number or [name] Shift-click form |color|Htalent:talent_id, rank|h[name]|h|r - // number or [name] Shift-click form |color|Htrade:spell_id, skill_id, max_value, cur_value|h[name]|h|r - int type = 0; - char* param1_str = nullptr; - char* idS = extractKeyFromLink(text, spellKeys, &type, ¶m1_str); - if (!idS) - return 0; - - uint32 id = atoul(idS); - - switch (type) - { - case SPELL_LINK_SPELL: - return id; - case SPELL_LINK_TALENT: - { - // talent - TalentEntry const* talentEntry = sTalentStore.LookupEntry(id); - if (!talentEntry) - return 0; - - return talentEntry->SpellID; - } - case SPELL_LINK_ENCHANT: - case SPELL_LINK_TRADE: - return id; - case SPELL_LINK_GLYPH: - { - uint32 glyph_prop_id = param1_str ? atoul(param1_str) : 0; - - GlyphPropertiesEntry const* glyphPropEntry = sGlyphPropertiesStore.LookupEntry(glyph_prop_id); - if (!glyphPropEntry) - return 0; - - return glyphPropEntry->SpellID; - } - } - - // unknown type? - return 0; -} - enum GuidLinkType { GUID_LINK_PLAYER = 0, // must be first for selection in not link case @@ -526,13 +457,13 @@ ObjectGuid::LowType ChatHandler::extractLowGuidFromLink(char* text, HighGuid& gu case GUID_LINK_CREATURE: { guidHigh = HighGuid::Creature; - ObjectGuid::LowType lowguid = atoull(idS); + ObjectGuid::LowType lowguid = Trinity::StringTo<ObjectGuid::LowType>(idS).value_or(UI64LIT(0)); return lowguid; } case GUID_LINK_GAMEOBJECT: { guidHigh = HighGuid::GameObject; - ObjectGuid::LowType lowguid = atoull(idS); + ObjectGuid::LowType lowguid = Trinity::StringTo<ObjectGuid::LowType>(idS).value_or(UI64LIT(0)); return lowguid; } } diff --git a/src/server/game/Chat/Chat.h b/src/server/game/Chat/Chat.h index 53a49cc058c..2d9b49fb6b5 100644 --- a/src/server/game/Chat/Chat.h +++ b/src/server/game/Chat/Chat.h @@ -98,7 +98,6 @@ class TC_GAME_API ChatHandler char* extractKeyFromLink(char* text, char const* linkType, char** something1 = nullptr); char* extractKeyFromLink(char* text, char const* const* linkTypes, int* found_idx, char** something1 = nullptr); char* extractQuotedArg(char* args); - uint32 extractSpellIdFromLink(char* text); ObjectGuid::LowType extractLowGuidFromLink(char* text, HighGuid& guidHigh); bool GetPlayerGroupAndGUIDByName(const char* cname, Player*& player, Group*& group, ObjectGuid& guid, bool offline = false); std::string extractPlayerNameFromLink(char* text); diff --git a/src/server/game/Chat/LanguageMgr.cpp b/src/server/game/Chat/LanguageMgr.cpp index d383f152513..9fc877944bc 100644 --- a/src/server/game/Chat/LanguageMgr.cpp +++ b/src/server/game/Chat/LanguageMgr.cpp @@ -237,7 +237,7 @@ std::string LanguageMgr::Translate(std::string const& msg, uint32 language, Loca for (size_t i = 0; i < length; ++i) { if (str[i] >= 'A' && str[i] <= 'Z') - result += char(toupper(replacementWord[i])); + result += charToUpper(replacementWord[i]); else result += replacementWord[i]; } @@ -252,9 +252,9 @@ std::string LanguageMgr::Translate(std::string const& msg, uint32 language, Loca for (size_t i = 0; i < length; ++i) { if (isUpper(wstrSourceWord[i])) - result += char(toupper(replacementWord[i])); + result += charToUpper(replacementWord[i]); else - result += char(tolower(replacementWord[i])); + result += charToLower(replacementWord[i]); } } break; |
