use UTF8ToUTF16 more (#695)

This commit is contained in:
Daniel Seiler 2022-08-02 15:56:20 +02:00 committed by GitHub
parent 9ee219ea42
commit a429489846
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 68 additions and 72 deletions

View File

@ -599,7 +599,7 @@ void ChatPacketHandler::HandleTeamKick(Packet* packet) {
if (kicked != nullptr) { if (kicked != nullptr) {
kickedId = kicked->playerID; kickedId = kicked->playerID;
} else { } else {
kickedId = playerContainer.GetId(GeneralUtils::ASCIIToUTF16(kickedPlayer)); kickedId = playerContainer.GetId(GeneralUtils::UTF8ToUTF16(kickedPlayer));
} }
if (kickedId == LWOOBJID_EMPTY) return; if (kickedId == LWOOBJID_EMPTY) return;
@ -690,7 +690,7 @@ void ChatPacketHandler::HandleTeamStatusRequest(Packet* packet) {
playerContainer.TeamStatusUpdate(team); playerContainer.TeamStatusUpdate(team);
const auto leaderName = GeneralUtils::ASCIIToUTF16(std::string(data->playerName.c_str())); const auto leaderName = GeneralUtils::UTF8ToUTF16(data->playerName);
for (const auto memberId : team->memberIDs) { for (const auto memberId : team->memberIDs) {
auto* otherMember = playerContainer.GetPlayerData(memberId); auto* otherMember = playerContainer.GetPlayerData(memberId);

View File

@ -35,7 +35,7 @@ void PlayerContainer::InsertPlayer(Packet* packet) {
inStream.Read(data->muteExpire); inStream.Read(data->muteExpire);
data->sysAddr = packet->systemAddress; data->sysAddr = packet->systemAddress;
mNames[data->playerID] = GeneralUtils::ASCIIToUTF16(std::string(data->playerName.c_str())); mNames[data->playerID] = GeneralUtils::UTF8ToUTF16(data->playerName);
mPlayers.insert(std::make_pair(data->playerID, data)); mPlayers.insert(std::make_pair(data->playerID, data));
Game::logger->Log("PlayerContainer", "Added user: %s (%llu), zone: %i", data->playerName.c_str(), data->playerID, data->zoneID.GetMapID()); Game::logger->Log("PlayerContainer", "Added user: %s (%llu), zone: %i", data->playerName.c_str(), data->playerID, data->zoneID.GetMapID());
@ -71,7 +71,7 @@ void PlayerContainer::RemovePlayer(Packet* packet) {
auto* team = GetTeam(playerID); auto* team = GetTeam(playerID);
if (team != nullptr) { if (team != nullptr) {
const auto memberName = GeneralUtils::ASCIIToUTF16(std::string(player->playerName.c_str())); const auto memberName = GeneralUtils::UTF8ToUTF16(std::string(player->playerName.c_str()));
for (const auto memberId : team->memberIDs) { for (const auto memberId : team->memberIDs) {
auto* otherMember = GetPlayerData(memberId); auto* otherMember = GetPlayerData(memberId);
@ -221,8 +221,8 @@ void PlayerContainer::AddMember(TeamData* team, LWOOBJID playerID) {
if (leader == nullptr || member == nullptr) return; if (leader == nullptr || member == nullptr) return;
const auto leaderName = GeneralUtils::ASCIIToUTF16(std::string(leader->playerName.c_str())); const auto leaderName = GeneralUtils::UTF8ToUTF16(leader->playerName);
const auto memberName = GeneralUtils::ASCIIToUTF16(std::string(member->playerName.c_str())); const auto memberName = GeneralUtils::UTF8ToUTF16(member->playerName);
ChatPacketHandler::SendTeamInviteConfirm(member, false, leader->playerID, leader->zoneID, team->lootFlag, 0, 0, leaderName); ChatPacketHandler::SendTeamInviteConfirm(member, false, leader->playerID, leader->zoneID, team->lootFlag, 0, 0, leaderName);
@ -309,7 +309,7 @@ void PlayerContainer::DisbandTeam(TeamData* team) {
if (otherMember == nullptr) continue; if (otherMember == nullptr) continue;
const auto memberName = GeneralUtils::ASCIIToUTF16(std::string(otherMember->playerName.c_str())); const auto memberName = GeneralUtils::UTF8ToUTF16(otherMember->playerName);
ChatPacketHandler::SendTeamSetLeader(otherMember, LWOOBJID_EMPTY); ChatPacketHandler::SendTeamSetLeader(otherMember, LWOOBJID_EMPTY);
ChatPacketHandler::SendTeamRemovePlayer(otherMember, true, false, false, team->local, team->leaderID, otherMember->playerID, memberName); ChatPacketHandler::SendTeamRemovePlayer(otherMember, true, false, false, team->local, team->leaderID, otherMember->playerID, memberName);
@ -331,7 +331,7 @@ void PlayerContainer::TeamStatusUpdate(TeamData* team) {
if (leader == nullptr) return; if (leader == nullptr) return;
const auto leaderName = GeneralUtils::ASCIIToUTF16(std::string(leader->playerName.c_str())); const auto leaderName = GeneralUtils::UTF8ToUTF16(leader->playerName);
for (const auto memberId : team->memberIDs) { for (const auto memberId : team->memberIDs) {
auto* otherMember = GetPlayerData(memberId); auto* otherMember = GetPlayerData(memberId);

View File

@ -49,7 +49,7 @@ LDFBaseData* LDFBaseData::DataFromString(const std::string& format) {
switch (type) { switch (type) {
case LDF_TYPE_UTF_16: { case LDF_TYPE_UTF_16: {
std::u16string data = GeneralUtils::ASCIIToUTF16(dataArray[1]); std::u16string data = GeneralUtils::UTF8ToUTF16(dataArray[1]);
return new LDFData<std::u16string>(key, data); return new LDFData<std::u16string>(key, data);
} }

View File

@ -8,23 +8,12 @@ CDRailActivatorComponentTable::CDRailActivatorComponentTable() {
entry.id = tableData.getIntField(0); entry.id = tableData.getIntField(0);
std::string startAnimation(tableData.getStringField(1, "")); entry.startAnimation = GeneralUtils::ASCIIToUTF16(tableData.getStringField(1, ""));
entry.startAnimation = GeneralUtils::ASCIIToUTF16(startAnimation); entry.loopAnimation = GeneralUtils::ASCIIToUTF16(tableData.getStringField(2, ""));
entry.stopAnimation = GeneralUtils::ASCIIToUTF16(tableData.getStringField(3, ""));
std::string loopAnimation(tableData.getStringField(2, "")); entry.startSound = GeneralUtils::ASCIIToUTF16(tableData.getStringField(4, ""));
entry.loopAnimation = GeneralUtils::ASCIIToUTF16(loopAnimation); entry.loopSound = GeneralUtils::ASCIIToUTF16(tableData.getStringField(5, ""));
entry.stopSound = GeneralUtils::ASCIIToUTF16(tableData.getStringField(6, ""));
std::string stopAnimation(tableData.getStringField(3, ""));
entry.stopAnimation = GeneralUtils::ASCIIToUTF16(stopAnimation);
std::string startSound(tableData.getStringField(4, ""));
entry.startSound = GeneralUtils::ASCIIToUTF16(startSound);
std::string loopSound(tableData.getStringField(5, ""));
entry.loopSound = GeneralUtils::ASCIIToUTF16(loopSound);
std::string stopSound(tableData.getStringField(6, ""));
entry.stopSound = GeneralUtils::ASCIIToUTF16(stopSound);
std::string loopEffectString(tableData.getStringField(7, "")); std::string loopEffectString(tableData.getStringField(7, ""));
entry.loopEffectID = EffectPairFromString(loopEffectString); entry.loopEffectID = EffectPairFromString(loopEffectString);

View File

@ -45,7 +45,7 @@ std::u16string Leaderboard::ToString() const {
index++; index++;
} }
return GeneralUtils::ASCIIToUTF16(leaderboard); return GeneralUtils::UTF8ToUTF16(leaderboard);
} }
std::vector<LeaderboardEntry> Leaderboard::GetEntries() { std::vector<LeaderboardEntry> Leaderboard::GetEntries() {

View File

@ -228,7 +228,7 @@ void CharacterComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
const tinyxml2::XMLAttribute* rocketConfig = character->FindAttribute("lcbp"); const tinyxml2::XMLAttribute* rocketConfig = character->FindAttribute("lcbp");
if (rocketConfig) { if (rocketConfig) {
m_LastRocketConfig = GeneralUtils::ASCIIToUTF16(std::string(rocketConfig->Value())); m_LastRocketConfig = GeneralUtils::ASCIIToUTF16(rocketConfig->Value());
} else { } else {
m_LastRocketConfig = u""; m_LastRocketConfig = u"";
} }
@ -262,7 +262,7 @@ void CharacterComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
character->QueryInt64Attribute("gid", &gid); character->QueryInt64Attribute("gid", &gid);
if (gid != 0) { if (gid != 0) {
std::string guildname(gn); std::string guildname(gn);
m_GuildName = GeneralUtils::ASCIIToUTF16(guildname); m_GuildName = GeneralUtils::UTF8ToUTF16(guildname);
m_GuildID = gid; m_GuildID = gid;
m_DirtySocialInfo = true; m_DirtySocialInfo = true;
} }

View File

@ -121,8 +121,8 @@ void PetComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpd
if (tamed) { if (tamed) {
outBitStream->Write(m_ModerationStatus); outBitStream->Write(m_ModerationStatus);
const auto nameData = GeneralUtils::ASCIIToUTF16(m_Name); const auto nameData = GeneralUtils::UTF8ToUTF16(m_Name);
const auto ownerNameData = GeneralUtils::ASCIIToUTF16(m_OwnerName); const auto ownerNameData = GeneralUtils::UTF8ToUTF16(m_OwnerName);
outBitStream->Write(static_cast<uint8_t>(nameData.size())); outBitStream->Write(static_cast<uint8_t>(nameData.size()));
for (const auto c : nameData) { for (const auto c : nameData) {
@ -567,7 +567,7 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) {
std::string petName = tamer->GetCharacter()->GetName(); std::string petName = tamer->GetCharacter()->GetName();
petName += "'s Pet"; petName += "'s Pet";
GameMessages::SendAddPetToPlayer(m_Tamer, 0, GeneralUtils::ASCIIToUTF16(petName), petSubKey, m_Parent->GetLOT(), tamer->GetSystemAddress()); GameMessages::SendAddPetToPlayer(m_Tamer, 0, GeneralUtils::UTF8ToUTF16(petName), petSubKey, m_Parent->GetLOT(), tamer->GetSystemAddress());
GameMessages::SendRegisterPetID(m_Tamer, m_Parent->GetObjectID(), tamer->GetSystemAddress()); GameMessages::SendRegisterPetID(m_Tamer, m_Parent->GetObjectID(), tamer->GetSystemAddress());
@ -634,7 +634,7 @@ void PetComponent::RequestSetPetName(std::u16string name) {
//Save our pet's new name to the db: //Save our pet's new name to the db:
SetPetNameForModeration(GeneralUtils::UTF16ToWTF8(name)); SetPetNameForModeration(GeneralUtils::UTF16ToWTF8(name));
GameMessages::SendSetPetName(m_Owner, GeneralUtils::ASCIIToUTF16(m_Name), m_DatabaseId, owner->GetSystemAddress()); GameMessages::SendSetPetName(m_Owner, GeneralUtils::UTF8ToUTF16(m_Name), m_DatabaseId, owner->GetSystemAddress());
GameMessages::SendSetPetNameModerated(m_Owner, m_DatabaseId, m_ModerationStatus, owner->GetSystemAddress()); GameMessages::SendSetPetNameModerated(m_Owner, m_DatabaseId, m_ModerationStatus, owner->GetSystemAddress());
} }
@ -665,9 +665,11 @@ void PetComponent::RequestSetPetName(std::u16string name) {
EntityManager::Instance()->SerializeEntity(m_Parent); EntityManager::Instance()->SerializeEntity(m_Parent);
GameMessages::SendSetPetName(m_Tamer, GeneralUtils::ASCIIToUTF16(m_Name), m_DatabaseId, tamer->GetSystemAddress()); std::u16string u16name = GeneralUtils::UTF8ToUTF16(m_Name);
GameMessages::SendSetPetName(m_Tamer, GeneralUtils::ASCIIToUTF16(m_Name), LWOOBJID_EMPTY, tamer->GetSystemAddress()); std::u16string u16ownerName = GeneralUtils::UTF8ToUTF16(m_OwnerName);
GameMessages::SendPetNameChanged(m_Parent->GetObjectID(), m_ModerationStatus, GeneralUtils::ASCIIToUTF16(m_Name), GeneralUtils::ASCIIToUTF16(m_OwnerName), UNASSIGNED_SYSTEM_ADDRESS); GameMessages::SendSetPetName(m_Tamer, u16name, m_DatabaseId, tamer->GetSystemAddress());
GameMessages::SendSetPetName(m_Tamer, u16name, LWOOBJID_EMPTY, tamer->GetSystemAddress());
GameMessages::SendPetNameChanged(m_Parent->GetObjectID(), m_ModerationStatus, u16name, u16ownerName, UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::SendSetPetNameModerated(m_Tamer, m_DatabaseId, m_ModerationStatus, tamer->GetSystemAddress()); GameMessages::SendSetPetNameModerated(m_Tamer, m_DatabaseId, m_ModerationStatus, tamer->GetSystemAddress());
GameMessages::SendNotifyPetTamingMinigame( GameMessages::SendNotifyPetTamingMinigame(
@ -877,7 +879,7 @@ void PetComponent::Activate(Item* item, bool registerPet, bool fromTaming) {
m_OwnerName = owner->GetCharacter()->GetName(); m_OwnerName = owner->GetCharacter()->GetName();
if (updatedModerationStatus) { if (updatedModerationStatus) {
GameMessages::SendSetPetName(m_Owner, GeneralUtils::ASCIIToUTF16(m_Name), m_DatabaseId, owner->GetSystemAddress()); GameMessages::SendSetPetName(m_Owner, GeneralUtils::UTF8ToUTF16(m_Name), m_DatabaseId, owner->GetSystemAddress());
GameMessages::SendSetPetNameModerated(m_Owner, m_DatabaseId, m_ModerationStatus, owner->GetSystemAddress()); GameMessages::SendSetPetNameModerated(m_Owner, m_DatabaseId, m_ModerationStatus, owner->GetSystemAddress());
} }
@ -892,7 +894,7 @@ void PetComponent::Activate(Item* item, bool registerPet, bool fromTaming) {
owner->GetCharacter()->SetPlayerFlag(69, true); owner->GetCharacter()->SetPlayerFlag(69, true);
if (registerPet) { if (registerPet) {
GameMessages::SendAddPetToPlayer(m_Owner, 0, GeneralUtils::ASCIIToUTF16(m_Name), m_DatabaseId, m_Parent->GetLOT(), owner->GetSystemAddress()); GameMessages::SendAddPetToPlayer(m_Owner, 0, GeneralUtils::UTF8ToUTF16(m_Name), m_DatabaseId, m_Parent->GetLOT(), owner->GetSystemAddress());
GameMessages::SendRegisterPetID(m_Owner, m_Parent->GetObjectID(), owner->GetSystemAddress()); GameMessages::SendRegisterPetID(m_Owner, m_Parent->GetObjectID(), owner->GetSystemAddress());

View File

@ -978,6 +978,8 @@ void GameMessages::SendSetNetworkScriptVar(Entity* entity, const SystemAddress&
bitStream.Write(entity->GetObjectID()); bitStream.Write(entity->GetObjectID());
bitStream.Write((uint16_t)GAME_MSG_SET_NETWORK_SCRIPT_VAR); bitStream.Write((uint16_t)GAME_MSG_SET_NETWORK_SCRIPT_VAR);
// FIXME: this is a bad place to need to do a conversion because we have no clue whether data is utf8 or plain ascii
// an this has performance implications
const auto u16Data = GeneralUtils::ASCIIToUTF16(data); const auto u16Data = GeneralUtils::ASCIIToUTF16(data);
uint32_t dataSize = static_cast<uint32_t>(u16Data.size()); uint32_t dataSize = static_cast<uint32_t>(u16Data.size());
@ -3188,7 +3190,7 @@ void GameMessages::HandleClientTradeRequest(RakNet::BitStream* inStream, Entity*
i64Invitee, i64Invitee,
bNeedInvitePopUp, bNeedInvitePopUp,
entity->GetObjectID(), entity->GetObjectID(),
GeneralUtils::ASCIIToUTF16(entity->GetCharacter()->GetName()), GeneralUtils::UTF8ToUTF16(entity->GetCharacter()->GetName()),
invitee->GetSystemAddress() invitee->GetSystemAddress()
); );
} }
@ -5086,7 +5088,8 @@ void GameMessages::HandleNotifyServerLevelProcessingComplete(RakNet::BitStream*
wss << "name=0:"; wss << "name=0:";
wss << character->GetName(); wss << character->GetName();
std::u16string attrs = GeneralUtils::ASCIIToUTF16(wss.str()); // FIXME: only really need utf8 conversion for the name, so move that up?
std::u16string attrs = GeneralUtils::UTF8ToUTF16(wss.str());
std::u16string wsText = u"UI_LEVEL_PROGRESSION_LEVELUP_MESSAGE"; std::u16string wsText = u"UI_LEVEL_PROGRESSION_LEVELUP_MESSAGE";
GameMessages::SendBroadcastTextToChatbox(entity, UNASSIGNED_SYSTEM_ADDRESS, attrs, wsText); GameMessages::SendBroadcastTextToChatbox(entity, UNASSIGNED_SYSTEM_ADDRESS, attrs, wsText);

View File

@ -14,19 +14,19 @@ void GameMessages::PropertyDataMessage::Serialize(RakNet::BitStream& stream) con
stream.Write<uint16_t>(VendorMapId); // - vendor map id stream.Write<uint16_t>(VendorMapId); // - vendor map id
stream.Write<uint32_t>(cloneId); // clone id stream.Write<uint32_t>(cloneId); // clone id
const auto& name = GeneralUtils::ASCIIToUTF16(Name); const auto& name = GeneralUtils::UTF8ToUTF16(Name);
stream.Write(uint32_t(name.size())); stream.Write(uint32_t(name.size()));
for (uint32_t i = 0; i < name.size(); ++i) { for (uint32_t i = 0; i < name.size(); ++i) {
stream.Write(uint16_t(name[i])); stream.Write(uint16_t(name[i]));
} }
const auto& description = GeneralUtils::ASCIIToUTF16(Description); const auto& description = GeneralUtils::UTF8ToUTF16(Description);
stream.Write(uint32_t(description.size())); stream.Write(uint32_t(description.size()));
for (uint32_t i = 0; i < description.size(); ++i) { for (uint32_t i = 0; i < description.size(); ++i) {
stream.Write(uint16_t(description[i])); stream.Write(uint16_t(description[i]));
} }
const auto& owner = GeneralUtils::ASCIIToUTF16(OwnerName); const auto& owner = GeneralUtils::UTF8ToUTF16(OwnerName);
stream.Write(uint32_t(owner.size())); stream.Write(uint32_t(owner.size()));
for (uint32_t i = 0; i < owner.size(); ++i) { for (uint32_t i = 0; i < owner.size(); ++i) {
stream.Write(uint16_t(owner[i])); stream.Write(uint16_t(owner[i]));
@ -68,7 +68,7 @@ void GameMessages::PropertyDataMessage::Serialize(RakNet::BitStream& stream) con
else stream.Write<uint32_t>(REJECTION_STATUS_PENDING); else stream.Write<uint32_t>(REJECTION_STATUS_PENDING);
// Does this go here??? // Does this go here???
// const auto& rejectionReasonConverted = GeneralUtils::ASCIIToUTF16(rejectionReason); // const auto& rejectionReasonConverted = GeneralUtils::UTF8ToUTF16(rejectionReason);
// stream.Write(uint32_t(rejectionReasonConverted.size())); // stream.Write(uint32_t(rejectionReasonConverted.size()));
// for (uint32_t i = 0; i < rejectionReasonConverted.size(); ++i) { // for (uint32_t i = 0; i < rejectionReasonConverted.size(); ++i) {
// stream.Write(uint16_t(rejectionReasonConverted[i])); // stream.Write(uint16_t(rejectionReasonConverted[i]));

View File

@ -3,19 +3,19 @@
void PropertySelectQueryProperty::Serialize(RakNet::BitStream& stream) const { void PropertySelectQueryProperty::Serialize(RakNet::BitStream& stream) const {
stream.Write(CloneId); stream.Write(CloneId);
const auto& owner = GeneralUtils::ASCIIToUTF16(OwnerName); const auto& owner = GeneralUtils::UTF8ToUTF16(OwnerName);
stream.Write(uint32_t(owner.size())); stream.Write(uint32_t(owner.size()));
for (uint32_t i = 0; i < owner.size(); ++i) { for (uint32_t i = 0; i < owner.size(); ++i) {
stream.Write(static_cast<uint16_t>(owner[i])); stream.Write(static_cast<uint16_t>(owner[i]));
} }
const auto& name = GeneralUtils::ASCIIToUTF16(Name); const auto& name = GeneralUtils::UTF8ToUTF16(Name);
stream.Write(uint32_t(name.size())); stream.Write(uint32_t(name.size()));
for (uint32_t i = 0; i < name.size(); ++i) { for (uint32_t i = 0; i < name.size(); ++i) {
stream.Write(static_cast<uint16_t>(name[i])); stream.Write(static_cast<uint16_t>(name[i]));
} }
const auto& description = GeneralUtils::ASCIIToUTF16(Description); const auto& description = GeneralUtils::UTF8ToUTF16(Description);
stream.Write(uint32_t(description.size())); stream.Write(uint32_t(description.size()));
for (uint32_t i = 0; i < description.size(); ++i) { for (uint32_t i = 0; i < description.size(); ++i) {
stream.Write(static_cast<uint16_t>(description[i])); stream.Write(static_cast<uint16_t>(description[i]));

View File

@ -290,9 +290,9 @@ void Mail::HandleDataRequest(RakNet::BitStream* packet, const SystemAddress& sys
while (res->next()) { while (res->next()) {
bitStream.Write(res->getUInt64(1)); //MailID bitStream.Write(res->getUInt64(1)); //MailID
/*std::u16string subject = GeneralUtils::ASCIIToUTF16(res->getString(7)); /*std::u16string subject = GeneralUtils::UTF8ToUTF16(res->getString(7));
std::u16string body = GeneralUtils::ASCIIToUTF16(res->getString(8)); std::u16string body = GeneralUtils::UTF8ToUTF16(res->getString(8));
std::u16string sender = GeneralUtils::ASCIIToUTF16(res->getString(3)); std::u16string sender = GeneralUtils::UTF8ToUTF16(res->getString(3));
WriteToPacket(&bitStream, subject, 50); WriteToPacket(&bitStream, subject, 50);
WriteToPacket(&bitStream, body, 400); WriteToPacket(&bitStream, body, 400);

View File

@ -173,7 +173,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
std::stringstream message; std::stringstream message;
message << character->GetName() << " changed their PVP flag to " << std::to_string(character->GetPvpEnabled()) << "!"; message << character->GetName() << " changed their PVP flag to " << std::to_string(character->GetPvpEnabled()) << "!";
ChatPackets::SendSystemMessage(UNASSIGNED_SYSTEM_ADDRESS, GeneralUtils::ASCIIToUTF16(message.str()), true); ChatPackets::SendSystemMessage(UNASSIGNED_SYSTEM_ADDRESS, GeneralUtils::UTF8ToUTF16(message.str()), true);
return; return;
} }
@ -189,7 +189,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
ChatPackets::SendSystemMessage( ChatPackets::SendSystemMessage(
sysAddr, sysAddr,
GeneralUtils::ASCIIToUTF16(player == entity ? name + " (you)" : name) GeneralUtils::UTF8ToUTF16(player == entity ? name + " (you)" : name)
); );
} }
} }
@ -678,6 +678,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
return; return;
} }
// FIXME: use fallible ASCIIToUTF16 conversion, because non-ascii isn't valid anyway
GameMessages::SendPlayFXEffect(entity->GetObjectID(), effectID, GeneralUtils::ASCIIToUTF16(args[1]), args[2]); GameMessages::SendPlayFXEffect(entity->GetObjectID(), effectID, GeneralUtils::ASCIIToUTF16(args[1]), args[2]);
} }
@ -829,7 +830,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
name += arg + " "; name += arg + " ";
} }
GameMessages::SendSetName(entity->GetObjectID(), GeneralUtils::ASCIIToUTF16(name), UNASSIGNED_SYSTEM_ADDRESS); GameMessages::SendSetName(entity->GetObjectID(), GeneralUtils::UTF8ToUTF16(name), UNASSIGNED_SYSTEM_ADDRESS);
} }
if (chatCommand == "title" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { if (chatCommand == "title" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
@ -839,7 +840,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
name += arg + " "; name += arg + " ";
} }
GameMessages::SendSetName(entity->GetObjectID(), GeneralUtils::ASCIIToUTF16(name), UNASSIGNED_SYSTEM_ADDRESS); GameMessages::SendSetName(entity->GetObjectID(), GeneralUtils::UTF8ToUTF16(name), UNASSIGNED_SYSTEM_ADDRESS);
} }
if ((chatCommand == "teleport" || chatCommand == "tele") && entity->GetGMLevel() >= GAME_MASTER_LEVEL_JUNIOR_MODERATOR) { if ((chatCommand == "teleport" || chatCommand == "tele") && entity->GetGMLevel() >= GAME_MASTER_LEVEL_JUNIOR_MODERATOR) {
@ -971,7 +972,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
delete result; delete result;
if (accountId == 0) { if (accountId == 0) {
ChatPackets::SendSystemMessage(sysAddr, u"Count not find player of name: " + GeneralUtils::ASCIIToUTF16(args[0])); ChatPackets::SendSystemMessage(sysAddr, u"Count not find player of name: " + GeneralUtils::UTF8ToUTF16(args[0]));
return; return;
} }
@ -1023,7 +1024,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
const auto timeStr = GeneralUtils::ASCIIToUTF16(std::string(buffer)); const auto timeStr = GeneralUtils::ASCIIToUTF16(std::string(buffer));
ChatPackets::SendSystemMessage(sysAddr, u"Muted: " + GeneralUtils::ASCIIToUTF16(args[0]) + u" until " + timeStr); ChatPackets::SendSystemMessage(sysAddr, u"Muted: " + GeneralUtils::UTF8ToUTF16(args[0]) + u" until " + timeStr);
//Notify chat about it //Notify chat about it
CBITSTREAM; CBITSTREAM;
@ -1042,15 +1043,15 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
if (args.size() == 1) { if (args.size() == 1) {
auto* player = Player::GetPlayer(args[0]); auto* player = Player::GetPlayer(args[0]);
std::u16string username = GeneralUtils::UTF8ToUTF16(args[0]);
if (player == nullptr) { if (player == nullptr) {
ChatPackets::SendSystemMessage(sysAddr, u"Count not find player of name: " + GeneralUtils::ASCIIToUTF16(args[0])); ChatPackets::SendSystemMessage(sysAddr, u"Count not find player of name: " + username);
return; return;
} }
Game::server->Disconnect(player->GetSystemAddress(), SERVER_DISCON_KICK); Game::server->Disconnect(player->GetSystemAddress(), SERVER_DISCON_KICK);
ChatPackets::SendSystemMessage(sysAddr, u"Kicked: " + GeneralUtils::ASCIIToUTF16(args[0])); ChatPackets::SendSystemMessage(sysAddr, u"Kicked: " + username);
} else { } else {
ChatPackets::SendSystemMessage(sysAddr, u"Correct usage: /kick <username>"); ChatPackets::SendSystemMessage(sysAddr, u"Correct usage: /kick <username>");
} }
@ -1077,7 +1078,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
delete result; delete result;
if (accountId == 0) { if (accountId == 0) {
ChatPackets::SendSystemMessage(sysAddr, u"Count not find player of name: " + GeneralUtils::ASCIIToUTF16(args[0])); ChatPackets::SendSystemMessage(sysAddr, u"Count not find player of name: " + GeneralUtils::UTF8ToUTF16(args[0]));
return; return;
} }
@ -1165,7 +1166,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
while (!tables.eof()) { while (!tables.eof()) {
std::string message = std::to_string(tables.getIntField(0)) + " - " + tables.getStringField(1); std::string message = std::to_string(tables.getIntField(0)) + " - " + tables.getStringField(1);
ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(message, message.size())); ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::UTF8ToUTF16(message, message.size()));
tables.nextRow(); tables.nextRow();
} }
} }
@ -1222,12 +1223,12 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
auto requestedPlayer = Player::GetPlayer(requestedPlayerToSetLevelOf); auto requestedPlayer = Player::GetPlayer(requestedPlayerToSetLevelOf);
if (!requestedPlayer) { if (!requestedPlayer) {
ChatPackets::SendSystemMessage(sysAddr, u"No player found with username: (" + GeneralUtils::ASCIIToUTF16(requestedPlayerToSetLevelOf) + u")."); ChatPackets::SendSystemMessage(sysAddr, u"No player found with username: (" + GeneralUtils::UTF8ToUTF16(requestedPlayerToSetLevelOf) + u").");
return; return;
} }
if (!requestedPlayer->GetOwner()) { if (!requestedPlayer->GetOwner()) {
ChatPackets::SendSystemMessage(sysAddr, u"No entity found with username: (" + GeneralUtils::ASCIIToUTF16(requestedPlayerToSetLevelOf) + u")."); ChatPackets::SendSystemMessage(sysAddr, u"No entity found with username: (" + GeneralUtils::UTF8ToUTF16(requestedPlayerToSetLevelOf) + u").");
return; return;
} }
@ -1269,7 +1270,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
if (requestedPlayerToSetLevelOf != "") { if (requestedPlayerToSetLevelOf != "") {
ChatPackets::SendSystemMessage( ChatPackets::SendSystemMessage(
sysAddr, u"Set " + GeneralUtils::ASCIIToUTF16(requestedPlayerToSetLevelOf) + u"'s level to " + GeneralUtils::to_u16string(requestedLevel) + sysAddr, u"Set " + GeneralUtils::UTF8ToUTF16(requestedPlayerToSetLevelOf) + u"'s level to " + GeneralUtils::to_u16string(requestedLevel) +
u" and UScore to " + GeneralUtils::to_u16string(characterComponent->GetUScore()) + u" and UScore to " + GeneralUtils::to_u16string(characterComponent->GetUScore()) +
u". Relog to see changes."); u". Relog to see changes.");
} else { } else {
@ -1437,8 +1438,8 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
}); });
} else { } else {
std::string msg = "ZoneID not found or allowed: "; std::string msg = "ZoneID not found or allowed: ";
msg.append(args[0]); msg.append(args[0]); // FIXME: unnecessary utf16 re-encoding just for error
ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(msg, msg.size())); ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::UTF8ToUTF16(msg, msg.size()));
} }
} }
@ -1572,17 +1573,18 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
GameConfig::SetValue(args[0], args[1]); GameConfig::SetValue(args[0], args[1]);
ChatPackets::SendSystemMessage( ChatPackets::SendSystemMessage(
sysAddr, u"Set config value: " + GeneralUtils::ASCIIToUTF16(args[0]) + u" to " + GeneralUtils::ASCIIToUTF16(args[1]) sysAddr, u"Set config value: " + GeneralUtils::UTF8ToUTF16(args[0]) + u" to " + GeneralUtils::UTF8ToUTF16(args[1])
); );
} }
if (chatCommand == "config-get" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() >= 1) { if (chatCommand == "config-get" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() >= 1) {
const auto& value = GameConfig::GetValue(args[0]); const auto& value = GameConfig::GetValue(args[0]);
std::u16string u16key = GeneralUtils::UTF8ToUTF16(args[0]);
if (value.empty()) { if (value.empty()) {
ChatPackets::SendSystemMessage(sysAddr, u"No value found for " + GeneralUtils::ASCIIToUTF16(args[0])); ChatPackets::SendSystemMessage(sysAddr, u"No value found for " + u16key);
} else { } else {
ChatPackets::SendSystemMessage(sysAddr, u"Value for " + GeneralUtils::ASCIIToUTF16(args[0]) + u": " + GeneralUtils::ASCIIToUTF16(value)); ChatPackets::SendSystemMessage(sysAddr, u"Value for " + u16key + u": " + GeneralUtils::UTF8ToUTF16(value));
} }
} }
@ -1672,7 +1674,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
if (!GeneralUtils::TryParse(args[0], component)) { if (!GeneralUtils::TryParse(args[0], component)) {
component = -1; component = -1;
ldf = GeneralUtils::ASCIIToUTF16(args[0]); ldf = GeneralUtils::UTF8ToUTF16(args[0]);
isLDF = true; isLDF = true;
} }
@ -1755,10 +1757,10 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
EntityManager::Instance()->SerializeEntity(closest); EntityManager::Instance()->SerializeEntity(closest);
} else if (args[1] == "-a" && args.size() >= 3) { } else if (args[1] == "-a" && args.size() >= 3) {
GameMessages::SendPlayAnimation(closest, GeneralUtils::ASCIIToUTF16(args[2])); GameMessages::SendPlayAnimation(closest, GeneralUtils::UTF8ToUTF16(args[2]));
} else if (args[1] == "-s") { } else if (args[1] == "-s") {
for (auto* entry : closest->GetSettings()) { for (auto* entry : closest->GetSettings()) {
ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(entry->GetString())); ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::UTF8ToUTF16(entry->GetString()));
} }
ChatPackets::SendSystemMessage(sysAddr, u"------"); ChatPackets::SendSystemMessage(sysAddr, u"------");