summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/HTTPServer/HTTPMessage.cpp3
-rw-r--r--src/Mobs/Monster.cpp3
-rw-r--r--src/Protocol/MojangAPI.cpp52
-rw-r--r--src/Protocol/MojangAPI.h4
-rw-r--r--src/Protocol/Protocol17x.cpp11
-rw-r--r--src/StringUtils.cpp47
-rw-r--r--src/StringUtils.h7
-rw-r--r--src/WorldStorage/NBTChunkSerializer.cpp10
-rw-r--r--src/WorldStorage/WSSAnvil.cpp7
9 files changed, 69 insertions, 75 deletions
diff --git a/src/HTTPServer/HTTPMessage.cpp b/src/HTTPServer/HTTPMessage.cpp
index 4226352e9..65d73fd87 100644
--- a/src/HTTPServer/HTTPMessage.cpp
+++ b/src/HTTPServer/HTTPMessage.cpp
@@ -35,8 +35,7 @@ cHTTPMessage::cHTTPMessage(eKind a_Kind) :
void cHTTPMessage::AddHeader(const AString & a_Key, const AString & a_Value)
{
- AString Key = a_Key;
- StrToLower(Key);
+ AString Key = StrToLower(a_Key);
cNameValueMap::iterator itr = m_Headers.find(Key);
if (itr == m_Headers.end())
{
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index a9889b62f..fe8a7346f 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -718,8 +718,7 @@ AString cMonster::MobTypeToString(cMonster::eType a_MobType)
cMonster::eType cMonster::StringToMobType(const AString & a_Name)
{
- AString lcName(a_Name);
- StrToLower(lcName);
+ AString lcName = StrToLower(a_Name);
// Binary-search for the lowercase name:
int lo = 0, hi = ARRAYCOUNT(g_MobTypeNames) - 1;
diff --git a/src/Protocol/MojangAPI.cpp b/src/Protocol/MojangAPI.cpp
index 9fdf07380..a7aea5490 100644
--- a/src/Protocol/MojangAPI.cpp
+++ b/src/Protocol/MojangAPI.cpp
@@ -190,8 +190,7 @@ void cMojangAPI::Start(cIniFile & a_SettingsIni)
AString cMojangAPI::GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_UseOnlyCached)
{
// Convert the playername to lowercase:
- AString lcPlayerName(a_PlayerName);
- StrToLower(lcPlayerName);
+ AString lcPlayerName = StrToLower(a_PlayerName);
// Request the cache to query the name if not yet cached:
if (!a_UseOnlyCached)
@@ -219,7 +218,7 @@ AString cMojangAPI::GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_U
AString cMojangAPI::GetPlayerNameFromUUID(const AString & a_UUID, bool a_UseOnlyCached)
{
// Normalize the UUID to lowercase short format that is used as the map key:
- AString UUID = StrToLower(MakeUUIDShort(a_UUID));
+ AString UUID = MakeUUIDShort(a_UUID);
// Retrieve from caches:
{
@@ -260,8 +259,7 @@ AStringVector cMojangAPI::GetUUIDsFromPlayerNames(const AStringVector & a_Player
AStringVector PlayerNames;
for (AStringVector::const_iterator itr = a_PlayerNames.begin(), end = a_PlayerNames.end(); itr != end; ++itr)
{
- AString Lower(*itr);
- PlayerNames.push_back(StrToLower(Lower));
+ PlayerNames.push_back(StrToLower(*itr));
} // for itr - a_PlayerNames[]
// Request the cache to populate any names not yet contained:
@@ -292,12 +290,11 @@ AStringVector cMojangAPI::GetUUIDsFromPlayerNames(const AStringVector & a_Player
void cMojangAPI::AddPlayerNameToUUIDMapping(const AString & a_PlayerName, const AString & a_UUID)
{
- AString lcName(a_PlayerName);
- AString UUID = StrToLower(MakeUUIDShort(a_UUID));
+ AString UUID = MakeUUIDShort(a_UUID);
Int64 Now = time(NULL);
{
cCSLock Lock(m_CSNameToUUID);
- m_NameToUUID[StrToLower(lcName)] = sProfile(a_PlayerName, UUID, "", "", Now);
+ m_NameToUUID[StrToLower(a_PlayerName)] = sProfile(a_PlayerName, UUID, "", "", Now);
}
{
cCSLock Lock(m_CSUUIDToName);
@@ -311,12 +308,11 @@ void cMojangAPI::AddPlayerNameToUUIDMapping(const AString & a_PlayerName, const
void cMojangAPI::AddPlayerProfile(const AString & a_PlayerName, const AString & a_UUID, const Json::Value & a_Properties)
{
- AString lcName(a_PlayerName);
- AString UUID = StrToLower(MakeUUIDShort(a_UUID));
+ AString UUID = MakeUUIDShort(a_UUID);
Int64 Now = time(NULL);
{
cCSLock Lock(m_CSNameToUUID);
- m_NameToUUID[StrToLower(lcName)] = sProfile(a_PlayerName, UUID, "", "", Now);
+ m_NameToUUID[StrToLower(a_PlayerName)] = sProfile(a_PlayerName, UUID, "", "", Now);
}
{
cCSLock Lock(m_CSUUIDToName);
@@ -395,13 +391,13 @@ AString cMojangAPI::MakeUUIDShort(const AString & a_UUID)
{
case 32:
{
- // Already is a short UUID
- return a_UUID;
+ // Already is a short UUID, only lowercase
+ return StrToLower(a_UUID);
}
case 36:
{
- // Remove the dashes from the string:
+ // Remove the dashes from the string by appending together the parts between them:
AString res;
res.reserve(32);
res.append(a_UUID, 0, 8);
@@ -409,7 +405,7 @@ AString cMojangAPI::MakeUUIDShort(const AString & a_UUID)
res.append(a_UUID, 14, 4);
res.append(a_UUID, 19, 4);
res.append(a_UUID, 24, 12);
- return res;
+ return StrToLower(res);
}
}
LOGWARNING("%s: Not an UUID: \"%s\".", __FUNCTION__, a_UUID.c_str());
@@ -427,8 +423,8 @@ AString cMojangAPI::MakeUUIDDashed(const AString & a_UUID)
{
case 36:
{
- // Already is a dashed UUID
- return a_UUID;
+ // Already is a dashed UUID, only lowercase
+ return StrToLower(a_UUID);
}
case 32:
@@ -445,7 +441,7 @@ AString cMojangAPI::MakeUUIDDashed(const AString & a_UUID)
res.append(a_UUID, 16, 4);
res.push_back('-');
res.append(a_UUID, 20, 12);
- return res;
+ return StrToLower(res);
}
}
LOGWARNING("%s: Not an UUID: \"%s\".", __FUNCTION__, a_UUID.c_str());
@@ -487,9 +483,8 @@ void cMojangAPI::LoadCachesFromDisk(void)
AString PlayerName = stmt.getColumn(0);
AString UUID = stmt.getColumn(1);
Int64 DateTime = stmt.getColumn(2);
- AString lcPlayerName = PlayerName;
- UUID = StrToLower(MakeUUIDShort(UUID));
- m_NameToUUID[StrToLower(lcPlayerName)] = sProfile(PlayerName, UUID, "", "", DateTime);
+ UUID = MakeUUIDShort(UUID);
+ m_NameToUUID[StrToLower(PlayerName)] = sProfile(PlayerName, UUID, "", "", DateTime);
m_UUIDToName[UUID] = sProfile(PlayerName, UUID, "", "", DateTime);
}
}
@@ -502,9 +497,8 @@ void cMojangAPI::LoadCachesFromDisk(void)
AString Textures = stmt.getColumn(2);
AString TexturesSignature = stmt.getColumn(2);
Int64 DateTime = stmt.getColumn(4);
- AString lcPlayerName = PlayerName;
- UUID = StrToLower(MakeUUIDShort(UUID));
- m_UUIDToProfile[StrToLower(lcPlayerName)] = sProfile(PlayerName, UUID, Textures, TexturesSignature, DateTime);
+ UUID = MakeUUIDShort(UUID);
+ m_UUIDToProfile[UUID] = sProfile(PlayerName, UUID, Textures, TexturesSignature, DateTime);
}
}
}
@@ -669,13 +663,12 @@ void cMojangAPI::CacheNamesToUUIDs(const AStringVector & a_PlayerNames)
{
Json::Value & Val = root[idx];
AString JsonName = Val.get("name", "").asString();
- AString JsonUUID = StrToLower(MakeUUIDShort(Val.get("id", "").asString()));
+ AString JsonUUID = MakeUUIDShort(Val.get("id", "").asString());
if (JsonUUID.empty())
{
continue;
}
- AString lcName = JsonName;
- m_NameToUUID[StrToLower(lcName)] = sProfile(JsonName, JsonUUID, "", "", Now);
+ m_NameToUUID[StrToLower(JsonName)] = sProfile(JsonName, JsonUUID, "", "", Now);
} // for idx - root[]
} // cCSLock (m_CSNameToUUID)
@@ -686,7 +679,7 @@ void cMojangAPI::CacheNamesToUUIDs(const AStringVector & a_PlayerNames)
{
Json::Value & Val = root[idx];
AString JsonName = Val.get("name", "").asString();
- AString JsonUUID = StrToLower(MakeUUIDShort(Val.get("id", "").asString()));
+ AString JsonUUID = MakeUUIDShort(Val.get("id", "").asString());
if (JsonUUID.empty())
{
continue;
@@ -796,9 +789,8 @@ void cMojangAPI::CacheUUIDToProfile(const AString & a_UUID)
m_UUIDToName[a_UUID] = sProfile(PlayerName, a_UUID, Properties, Now);
}
{
- AString lcPlayerName(PlayerName);
cCSLock Lock(m_CSNameToUUID);
- m_NameToUUID[StrToLower(lcPlayerName)] = sProfile(PlayerName, a_UUID, Properties, Now);
+ m_NameToUUID[StrToLower(PlayerName)] = sProfile(PlayerName, a_UUID, Properties, Now);
}
}
diff --git a/src/Protocol/MojangAPI.h b/src/Protocol/MojangAPI.h
index 08e799c73..6ed37625e 100644
--- a/src/Protocol/MojangAPI.h
+++ b/src/Protocol/MojangAPI.h
@@ -40,12 +40,12 @@ public:
// tolua_begin
- /** Converts the given UUID to its short form (32 bytes, no dashes).
+ /** Normalizes the given UUID to its short form (32 bytes, no dashes, lowercase).
Logs a warning and returns empty string if not a UUID.
Note: only checks the string's length, not the actual content. */
static AString MakeUUIDShort(const AString & a_UUID);
- /** Converts the given UUID to its dashed form (36 bytes, 4 dashes).
+ /** Normalizes the given UUID to its dashed form (36 bytes, 4 dashes, lowercase).
Logs a warning and returns empty string if not a UUID.
Note: only checks the string's length, not the actual content. */
static AString MakeUUIDDashed(const AString & a_UUID);
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index f419c01a7..8f3399b2f 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -3032,15 +3032,14 @@ void cProtocol176::SendPlayerSpawn(const cPlayer & a_Player)
Pkt.WriteString(cMojangAPI::MakeUUIDDashed(a_Player.GetClientHandle()->GetUUID()));
Pkt.WriteString(a_Player.GetName());
- const Json::Value & Properties = m_Client->GetProperties();
- const Json::Value::const_iterator End = Properties.end();
+ const Json::Value & Properties = a_Player.GetClientHandle()->GetProperties();
Pkt.WriteVarInt(Properties.size());
- for (Json::Value::iterator itr = Properties.begin(); itr != End; ++itr)
+ for (Json::Value::iterator itr = Properties.begin(), end = Properties.end(); itr != end; ++itr)
{
- Pkt.WriteString(((Json::Value)*itr).get("name", "").toStyledString());
- Pkt.WriteString(((Json::Value)*itr).get("value", "").toStyledString());
- Pkt.WriteString(((Json::Value)*itr).get("signature", "").toStyledString());
+ Pkt.WriteString(((Json::Value)*itr).get("name", "").asString());
+ Pkt.WriteString(((Json::Value)*itr).get("value", "").asString());
+ Pkt.WriteString(((Json::Value)*itr).get("signature", "").asString());
}
Pkt.WriteFPInt(a_Player.GetPosX());
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp
index decce8065..5f88cbf64 100644
--- a/src/StringUtils.cpp
+++ b/src/StringUtils.cpp
@@ -196,16 +196,9 @@ AString TrimString(const AString & str)
-AString & StrToUpper(AString & s)
+AString & InPlaceLowercase(AString & s)
{
- AString::iterator i = s.begin();
- AString::iterator end = s.end();
-
- while (i != end)
- {
- *i = (char)toupper(*i);
- ++i;
- }
+ std::transform(s.begin(), s.end(), s.begin(), ::tolower);
return s;
}
@@ -213,16 +206,9 @@ AString & StrToUpper(AString & s)
-AString & StrToLower(AString & s)
+AString & InPlaceUppercase(AString & s)
{
- AString::iterator i = s.begin();
- AString::iterator end = s.end();
-
- while (i != end)
- {
- *i = (char)tolower(*i);
- ++i;
- }
+ std::transform(s.begin(), s.end(), s.begin(), ::toupper);
return s;
}
@@ -232,12 +218,19 @@ AString & StrToLower(AString & s)
AString StrToLower(const AString & s)
{
- AString res;
- res.resize(s.size());
- for (AString::iterator itr = res.begin(), end = res.end(); itr != end; ++itr)
- {
- *itr = (char)tolower(*itr);
- }
+ AString res(s);
+ std::transform(res.begin(), res.end(), res.begin(), ::tolower);
+ return res;
+}
+
+
+
+
+
+AString StrToUpper(const AString & s)
+{
+ AString res(s);
+ std::transform(res.begin(), res.end(), res.begin(), ::toupper);
return res;
}
@@ -251,10 +244,8 @@ int NoCaseCompare(const AString & s1, const AString & s2)
// MSVC has stricmp that compares case-insensitive:
return _stricmp(s1.c_str(), s2.c_str());
#else
- // Do it the hard way:
- AString s1Copy(s1);
- AString s2Copy(s2);
- return StrToUpper(s1Copy).compare(StrToUpper(s2Copy));
+ // Do it the hard way - convert both strings to lowercase:
+ return StrToLower(s1).compare(StrToLower(s2));
#endif // else _MSC_VER
}
diff --git a/src/StringUtils.h b/src/StringUtils.h
index 65363382d..142aaf59b 100644
--- a/src/StringUtils.h
+++ b/src/StringUtils.h
@@ -43,10 +43,13 @@ extern AStringVector StringSplitAndTrim(const AString & str, const AString & del
extern AString TrimString(const AString & str); // tolua_export
/// In-place string conversion to uppercase; returns the same string
-extern AString & StrToUpper(AString & s);
+extern AString & InPlaceUppercase(AString & s);
/// In-place string conversion to lowercase; returns the same string
-extern AString & StrToLower(AString & s);
+extern AString & InPlaceLowercase(AString & s);
+
+/** Returns an upper-cased copy of the string */
+extern AString StrToUpper(const AString & s);
/** Returns a lower-cased copy of the string */
extern AString StrToLower(const AString & s);
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index ecda9b8fd..e435a1b1f 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -570,8 +570,14 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
case cMonster::mtWolf:
{
const cWolf & Wolf = *((cWolf *)a_Monster);
- m_Writer.AddString("Owner", Wolf.GetOwnerName());
- m_Writer.AddString("OwnerUUID", Wolf.GetOwnerUUID());
+ if (!Wolf.GetOwnerName().empty())
+ {
+ m_Writer.AddString("Owner", Wolf.GetOwnerName());
+ }
+ if (!Wolf.GetOwnerUUID().empty())
+ {
+ m_Writer.AddString("OwnerUUID", Wolf.GetOwnerUUID());
+ }
m_Writer.AddByte("Sitting", Wolf.IsSitting() ? 1 : 0);
m_Writer.AddByte("Angry", Wolf.IsAngry() ? 1 : 0);
m_Writer.AddInt("CollarColor", Wolf.GetCollarColor());
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 434f1e21f..a9c9ae4b5 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -2495,7 +2495,7 @@ void cWSSAnvil::LoadWolfOwner(cWolf & a_Wolf, const cParsedNBT & a_NBT, int a_Ta
int OwnerUUIDIdx = a_NBT.FindChildByName(a_TagIdx, "OwnerUUID");
if (OwnerUUIDIdx > 0)
{
- OwnerUUID = cMojangAPI::MakeUUIDShort(a_NBT.GetString(OwnerUUIDIdx));
+ OwnerUUID = a_NBT.GetString(OwnerUUIDIdx);
}
int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner");
if (OwnerIdx > 0)
@@ -2520,6 +2520,11 @@ void cWSSAnvil::LoadWolfOwner(cWolf & a_Wolf, const cParsedNBT & a_NBT, int a_Ta
return;
}
}
+ else
+ {
+ // Normalize the UUID:
+ OwnerUUID = cMojangAPI::MakeUUIDShort(OwnerUUID);
+ }
// Convert UUID to name, if needed:
if (OwnerName.empty())