mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Console: Improve ReadWinConsole logic and cosmetic changes (#26402)
* Core/Console: Improve ReadWinConsole logic and cosmetic changes
* Core/Console: Fixed possible appearance of weird characters in the console when printing the output of child processes
* Fix codestyle
* Removed auto
* Core/Misc: Explicit casting Difficulty values to uint8 before outputting to console
* Core/Misc: Cast Difficulty to uint32 for output to console
Co-authored-by: jackpoz <giacomopoz@gmail.com>
(cherry picked from commit 6c12f45f3b)
This commit is contained in:
@@ -55,9 +55,8 @@ public:
|
||||
std::streamsize write(char const* str, std::streamsize size)
|
||||
{
|
||||
std::string consoleStr(str, size);
|
||||
std::string utf8;
|
||||
if (consoleToUtf8(consoleStr, utf8))
|
||||
callback_(utf8);
|
||||
RemoveCRLF(consoleStr);
|
||||
callback_(consoleStr);
|
||||
return size;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -792,7 +792,7 @@ bool ReadWinConsole(std::string& str, size_t size /*= 256*/)
|
||||
HANDLE hConsole = GetStdHandle(STD_INPUT_HANDLE);
|
||||
DWORD read = 0;
|
||||
|
||||
if (!ReadConsoleW(hConsole, commandbuf, size, &read, nullptr))
|
||||
if (!ReadConsoleW(hConsole, commandbuf, size, &read, nullptr) || read == 0)
|
||||
{
|
||||
delete[] commandbuf;
|
||||
return false;
|
||||
@@ -812,13 +812,22 @@ bool WriteWinConsole(std::string_view str, bool error /*= false*/)
|
||||
return false;
|
||||
|
||||
HANDLE hConsole = GetStdHandle(error ? STD_ERROR_HANDLE : STD_OUTPUT_HANDLE);
|
||||
DWORD toWrite = wstr.size();
|
||||
DWORD write;
|
||||
DWORD write = 0;
|
||||
|
||||
return WriteConsoleW(hConsole, wstr.c_str(), wstr.size(), &write, nullptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
TC_COMMON_API Optional<std::size_t> RemoveCRLF(std::string & str)
|
||||
{
|
||||
std::size_t nextLineIndex = str.find_first_of("\r\n");
|
||||
if (nextLineIndex == std::string::npos)
|
||||
return std::nullopt;
|
||||
|
||||
str.erase(nextLineIndex);
|
||||
return nextLineIndex;
|
||||
}
|
||||
|
||||
std::string Trinity::Impl::ByteArrayToHexStr(uint8 const* bytes, size_t arrayLen, bool reverse /* = false */)
|
||||
{
|
||||
int32 init = 0;
|
||||
|
||||
@@ -333,6 +333,8 @@ TC_COMMON_API bool ReadWinConsole(std::string& str, size_t size = 256);
|
||||
TC_COMMON_API bool WriteWinConsole(std::string_view str, bool error = false);
|
||||
#endif
|
||||
|
||||
TC_COMMON_API Optional<std::size_t> RemoveCRLF(std::string& str);
|
||||
|
||||
TC_COMMON_API bool IsIPAddress(char const* ipaddress);
|
||||
|
||||
TC_COMMON_API uint32 CreatePIDFile(std::string const& filename);
|
||||
|
||||
@@ -20024,7 +20024,8 @@ InstancePlayerBind* Player::BindToInstance(InstanceSave* save, bool permanent, B
|
||||
bind.perm = permanent;
|
||||
bind.extendState = extendState;
|
||||
if (!load)
|
||||
TC_LOG_DEBUG("maps", "Player::BindToInstance: Player '%s' (%s) is now bound to map (ID: %d, Instance %d, Difficulty %d)", GetName().c_str(), GetGUID().ToString().c_str(), save->GetMapId(), save->GetInstanceId(), save->GetDifficultyID());
|
||||
TC_LOG_DEBUG("maps", "Player::BindToInstance: Player '%s' (%s) is now bound to map (ID: %d, Instance: %d, Difficulty: %d)",
|
||||
GetName().c_str(), GetGUID().ToString().c_str(), save->GetMapId(), save->GetInstanceId(), static_cast<uint32>(save->GetDifficultyID()));
|
||||
sScriptMgr->OnPlayerBindToInstance(this, save->GetDifficultyID(), save->GetMapId(), permanent, uint8(extendState));
|
||||
return &bind;
|
||||
}
|
||||
|
||||
@@ -2276,7 +2276,7 @@ InstanceGroupBind* Group::BindToInstance(InstanceSave* save, bool permanent, boo
|
||||
bind.perm = permanent;
|
||||
if (!load)
|
||||
TC_LOG_DEBUG("maps", "Group::BindToInstance: %s, storage id: %u is now bound to map %d, instance %d, difficulty %d",
|
||||
GetGUID().ToString().c_str(), m_dbStoreId, save->GetMapId(), save->GetInstanceId(), save->GetDifficultyID());
|
||||
GetGUID().ToString().c_str(), m_dbStoreId, save->GetMapId(), save->GetInstanceId(), static_cast<uint32>(save->GetDifficultyID()));
|
||||
|
||||
return &bind;
|
||||
}
|
||||
|
||||
@@ -617,7 +617,8 @@ void WorldSession::SendCalendarRaidLockoutUpdated(InstanceSave const* save)
|
||||
return;
|
||||
|
||||
ObjectGuid guid = _player->GetGUID();
|
||||
TC_LOG_DEBUG("network", "SMSG_CALENDAR_RAID_LOCKOUT_UPDATED [%s] Map: %u, Difficulty %u", guid.ToString().c_str(), save->GetMapId(), save->GetDifficultyID());
|
||||
TC_LOG_DEBUG("network", "SMSG_CALENDAR_RAID_LOCKOUT_UPDATED [%s] Map: %u, Difficulty %u",
|
||||
guid.ToString().c_str(), save->GetMapId(), static_cast<uint32>(save->GetDifficultyID()));
|
||||
|
||||
time_t currTime = GameTime::GetGameTime();
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ InstanceSave* InstanceSaveManager::AddInstanceSave(uint32 mapId, uint32 instance
|
||||
DifficultyEntry const* difficultyEntry = sDifficultyStore.LookupEntry(difficulty);
|
||||
if (!difficultyEntry || difficultyEntry->InstanceType != entry->InstanceType)
|
||||
{
|
||||
TC_LOG_ERROR("misc", "InstanceSaveManager::AddInstanceSave: mapid = %d, instanceid = %d, wrong dificalty %u!", mapId, instanceId, difficulty);
|
||||
TC_LOG_ERROR("misc", "InstanceSaveManager::AddInstanceSave: mapid = %d, instanceid = %d, wrong dificalty %u!", mapId, instanceId, static_cast<uint32>(difficulty));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -371,7 +371,7 @@ void InstanceSaveManager::LoadResetTimes()
|
||||
MapDifficultyEntry const* mapDiff = sDB2Manager.GetMapDifficultyData(mapid, difficulty);
|
||||
if (!mapDiff)
|
||||
{
|
||||
TC_LOG_ERROR("misc", "InstanceSaveManager::LoadResetTimes: invalid mapid(%u)/difficulty(%u) pair in instance_reset!", mapid, uint32(difficulty));
|
||||
TC_LOG_ERROR("misc", "InstanceSaveManager::LoadResetTimes: invalid mapid(%u)/difficulty(%u) pair in instance_reset!", mapid, static_cast<uint32>(difficulty));
|
||||
|
||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GLOBAL_INSTANCE_RESETTIME);
|
||||
stmt->setUInt16(0, uint16(mapid));
|
||||
@@ -646,7 +646,7 @@ void InstanceSaveManager::_ResetOrWarnAll(uint32 mapid, Difficulty difficulty, b
|
||||
MapEntry const* mapEntry = sMapStore.LookupEntry(mapid);
|
||||
if (!mapEntry->Instanceable())
|
||||
return;
|
||||
TC_LOG_DEBUG("misc", "InstanceSaveManager::ResetOrWarnAll: Processing map %s (%u) on difficulty %u (warn? %u)", mapEntry->MapName[sWorld->GetDefaultDbcLocale()], mapid, uint8(difficulty), warn);
|
||||
TC_LOG_DEBUG("misc", "InstanceSaveManager::ResetOrWarnAll: Processing map %s (%u) on difficulty %u (warn? %u)", mapEntry->MapName[sWorld->GetDefaultDbcLocale()], mapid, static_cast<uint32>(difficulty), warn);
|
||||
|
||||
time_t now = GameTime::GetGameTime();
|
||||
|
||||
|
||||
@@ -4017,7 +4017,7 @@ bool InstanceMap::AddPlayerToMap(Player* player, bool initPlayer /*= true*/)
|
||||
// cannot enter other instances if bound permanently
|
||||
if (playerBind->save != mapSave)
|
||||
{
|
||||
TC_LOG_ERROR("maps", "InstanceMap::Add: player %s %s is permanently bound to instance %s %d, %d, %d, %d, %d, %d but he is being put into instance %s %d, %d, %d, %d, %d, %d", player->GetName().c_str(), player->GetGUID().ToString().c_str(), GetMapName(), playerBind->save->GetMapId(), playerBind->save->GetInstanceId(), playerBind->save->GetDifficultyID(), playerBind->save->GetPlayerCount(), playerBind->save->GetGroupCount(), playerBind->save->CanReset(), GetMapName(), mapSave->GetMapId(), mapSave->GetInstanceId(), mapSave->GetDifficultyID(), mapSave->GetPlayerCount(), mapSave->GetGroupCount(), mapSave->CanReset());
|
||||
TC_LOG_ERROR("maps", "InstanceMap::Add: player %s %s is permanently bound to instance %s %d, %d, %d, %d, %d, %d but he is being put into instance %s %d, %d, %d, %d, %d, %d", player->GetName().c_str(), player->GetGUID().ToString().c_str(), GetMapName(), playerBind->save->GetMapId(), playerBind->save->GetInstanceId(), static_cast<uint32>(playerBind->save->GetDifficultyID()), playerBind->save->GetPlayerCount(), playerBind->save->GetGroupCount(), playerBind->save->CanReset(), GetMapName(), mapSave->GetMapId(), mapSave->GetInstanceId(), static_cast<uint32>(mapSave->GetDifficultyID()), mapSave->GetPlayerCount(), mapSave->GetGroupCount(), mapSave->CanReset());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -4029,9 +4029,9 @@ bool InstanceMap::AddPlayerToMap(Player* player, bool initPlayer /*= true*/)
|
||||
InstanceGroupBind* groupBind = group->GetBoundInstance(this);
|
||||
if (playerBind && playerBind->save != mapSave)
|
||||
{
|
||||
TC_LOG_ERROR("maps", "InstanceMap::Add: player %s %s is being put into instance %s %d, %d, %d, %d, %d, %d but he is in group %s and is bound to instance %d, %d, %d, %d, %d, %d!", player->GetName().c_str(), player->GetGUID().ToString().c_str(), GetMapName(), mapSave->GetMapId(), mapSave->GetInstanceId(), mapSave->GetDifficultyID(), mapSave->GetPlayerCount(), mapSave->GetGroupCount(), mapSave->CanReset(), group->GetLeaderGUID().ToString().c_str(), playerBind->save->GetMapId(), playerBind->save->GetInstanceId(), playerBind->save->GetDifficultyID(), playerBind->save->GetPlayerCount(), playerBind->save->GetGroupCount(), playerBind->save->CanReset());
|
||||
TC_LOG_ERROR("maps", "InstanceMap::Add: player %s %s is being put into instance %s %d, %d, %d, %d, %d, %d but he is in group %s and is bound to instance %d, %d, %d, %d, %d, %d!", player->GetName().c_str(), player->GetGUID().ToString().c_str(), GetMapName(), mapSave->GetMapId(), mapSave->GetInstanceId(), static_cast<uint32>(mapSave->GetDifficultyID()), mapSave->GetPlayerCount(), mapSave->GetGroupCount(), mapSave->CanReset(), group->GetLeaderGUID().ToString().c_str(), playerBind->save->GetMapId(), playerBind->save->GetInstanceId(), static_cast<uint32>(playerBind->save->GetDifficultyID()), playerBind->save->GetPlayerCount(), playerBind->save->GetGroupCount(), playerBind->save->CanReset());
|
||||
if (groupBind)
|
||||
TC_LOG_ERROR("maps", "InstanceMap::Add: the group is bound to the instance %s %d, %d, %d, %d, %d, %d", GetMapName(), groupBind->save->GetMapId(), groupBind->save->GetInstanceId(), groupBind->save->GetDifficultyID(), groupBind->save->GetPlayerCount(), groupBind->save->GetGroupCount(), groupBind->save->CanReset());
|
||||
TC_LOG_ERROR("maps", "InstanceMap::Add: the group is bound to the instance %s %d, %d, %d, %d, %d, %d", GetMapName(), groupBind->save->GetMapId(), groupBind->save->GetInstanceId(), static_cast<uint32>(groupBind->save->GetDifficultyID()), groupBind->save->GetPlayerCount(), groupBind->save->GetGroupCount(), groupBind->save->CanReset());
|
||||
//ABORT();
|
||||
return false;
|
||||
}
|
||||
@@ -4043,7 +4043,7 @@ bool InstanceMap::AddPlayerToMap(Player* player, bool initPlayer /*= true*/)
|
||||
// cannot jump to a different instance without resetting it
|
||||
if (groupBind->save != mapSave)
|
||||
{
|
||||
TC_LOG_ERROR("maps", "InstanceMap::Add: player %s %s is being put into instance %d, %d, %d but he is in group %s which is bound to instance %d, %d, %d!", player->GetName().c_str(), player->GetGUID().ToString().c_str(), mapSave->GetMapId(), mapSave->GetInstanceId(), mapSave->GetDifficultyID(), group->GetLeaderGUID().ToString().c_str(), groupBind->save->GetMapId(), groupBind->save->GetInstanceId(), groupBind->save->GetDifficultyID());
|
||||
TC_LOG_ERROR("maps", "InstanceMap::Add: player %s %s is being put into instance %d, %d, %d but he is in group %s which is bound to instance %d, %d, %d!", player->GetName().c_str(), player->GetGUID().ToString().c_str(), mapSave->GetMapId(), mapSave->GetInstanceId(), static_cast<uint32>(mapSave->GetDifficultyID()), group->GetLeaderGUID().ToString().c_str(), groupBind->save->GetMapId(), groupBind->save->GetInstanceId(), static_cast<uint32>(groupBind->save->GetDifficultyID()));
|
||||
TC_LOG_ERROR("maps", "MapSave players: %d, group count: %d", mapSave->GetPlayerCount(), mapSave->GetGroupCount());
|
||||
if (groupBind->save)
|
||||
TC_LOG_ERROR("maps", "GroupBind save players: %d, group count: %d", groupBind->save->GetPlayerCount(), groupBind->save->GetGroupCount());
|
||||
@@ -4242,7 +4242,7 @@ void InstanceMap::PermBindAllPlayers()
|
||||
InstanceSave* save = sInstanceSaveMgr->GetInstanceSave(GetInstanceId());
|
||||
if (!save)
|
||||
{
|
||||
TC_LOG_ERROR("maps", "Cannot bind players to instance map (Name: %s, Entry: %u, Difficulty: %u, ID: %u) because no instance save is available!", GetMapName(), GetId(), GetDifficultyID(), GetInstanceId());
|
||||
TC_LOG_ERROR("maps", "Cannot bind players to instance map (Name: %s, Entry: %u, Difficulty: %u, ID: %u) because no instance save is available!", GetMapName(), GetId(), static_cast<uint32>(GetDifficultyID()), GetInstanceId());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4259,11 +4259,11 @@ void InstanceMap::PermBindAllPlayers()
|
||||
{
|
||||
if (bind->save && bind->save->GetInstanceId() != save->GetInstanceId())
|
||||
{
|
||||
TC_LOG_ERROR("maps", "Player (%s, Name: %s) is in instance map (Name: %s, Entry: %u, Difficulty: %u, ID: %u) that is being bound, but already has a save for the map on ID %u!", player->GetGUID().ToString().c_str(), player->GetName().c_str(), GetMapName(), save->GetMapId(), save->GetDifficultyID(), save->GetInstanceId(), bind->save->GetInstanceId());
|
||||
TC_LOG_ERROR("maps", "Player (%s, Name: %s) is in instance map (Name: %s, Entry: %u, Difficulty: %u, ID: %u) that is being bound, but already has a save for the map on ID %u!", player->GetGUID().ToString().c_str(), player->GetName().c_str(), GetMapName(), save->GetMapId(), static_cast<uint32>(save->GetDifficultyID()), save->GetInstanceId(), bind->save->GetInstanceId());
|
||||
}
|
||||
else if (!bind->save)
|
||||
{
|
||||
TC_LOG_ERROR("maps", "Player (%s, Name: %s) is in instance map (Name: %s, Entry: %u, Difficulty: %u, ID: %u) that is being bound, but already has a bind (without associated save) for the map!", player->GetGUID().ToString().c_str(), player->GetName().c_str(), GetMapName(), save->GetMapId(), save->GetDifficultyID(), save->GetInstanceId());
|
||||
TC_LOG_ERROR("maps", "Player (%s, Name: %s) is in instance map (Name: %s, Entry: %u, Difficulty: %u, ID: %u) that is being bound, but already has a bind (without associated save) for the map!", player->GetGUID().ToString().c_str(), player->GetName().c_str(), GetMapName(), save->GetMapId(), static_cast<uint32>(save->GetDifficultyID()), save->GetInstanceId());
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -4312,7 +4312,7 @@ void InstanceMap::SetResetSchedule(bool on)
|
||||
sInstanceSaveMgr->ScheduleReset(on, save->GetResetTime(), InstanceSaveManager::InstResetEvent(0, GetId(), GetDifficultyID(), GetInstanceId()));
|
||||
else
|
||||
TC_LOG_ERROR("maps", "InstanceMap::SetResetSchedule: cannot turn schedule %s, there is no save information for instance (map [id: %u, name: %s], instance id: %u, difficulty: %u)",
|
||||
on ? "on" : "off", GetId(), GetMapName(), GetInstanceId(), GetDifficultyID());
|
||||
on ? "on" : "off", GetId(), GetMapName(), GetInstanceId(), static_cast<uint32>(GetDifficultyID()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -232,7 +232,7 @@ InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave* save,
|
||||
// some instances only have one difficulty
|
||||
sDB2Manager.GetDownscaledMapDifficultyData(GetId(), difficulty);
|
||||
|
||||
TC_LOG_DEBUG("maps", "MapInstanced::CreateInstance: %s map instance %d for %d created with difficulty %s", save ? "" : "new ", InstanceId, GetId(), difficulty ? "heroic" : "normal");
|
||||
TC_LOG_DEBUG("maps", "MapInstanced::CreateInstance: %s map instance %d for %d created with difficulty %u", save ? "" : "new ", InstanceId, GetId(), static_cast<uint32>(difficulty));
|
||||
|
||||
InstanceMap* map = new InstanceMap(GetId(), GetGridExpiry(), InstanceId, difficulty, this, team);
|
||||
ASSERT(map->IsDungeon());
|
||||
|
||||
@@ -430,7 +430,7 @@ struct boss_gothik : public BossAI
|
||||
{
|
||||
if (RAID_MODE(waves10,waves25).size() <= _waveCount) // bounds check
|
||||
{
|
||||
TC_LOG_INFO("scripts", "GothikAI: Wave count %d is out of range for difficulty %d.", _waveCount, GetDifficulty());
|
||||
TC_LOG_INFO("scripts", "GothikAI: Wave count %d is out of range for difficulty %d.", _waveCount, static_cast<uint32>(GetDifficulty()));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -130,10 +130,7 @@ void CliThread()
|
||||
|
||||
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
|
||||
if (!ReadWinConsole(command))
|
||||
{
|
||||
PrintCliPrefix();
|
||||
continue;
|
||||
}
|
||||
#else
|
||||
char* command_str = readline(CLI_PREFIX);
|
||||
::rl_bind_key('\t', ::rl_complete);
|
||||
@@ -146,18 +143,13 @@ void CliThread()
|
||||
|
||||
if (!command.empty())
|
||||
{
|
||||
std::size_t nextLineIndex = command.find_first_of("\r\n");
|
||||
if (nextLineIndex != std::string::npos)
|
||||
Optional<std::size_t> nextLineIndex = RemoveCRLF(command);
|
||||
if (nextLineIndex && *nextLineIndex == 0)
|
||||
{
|
||||
if (nextLineIndex == 0)
|
||||
{
|
||||
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
|
||||
PrintCliPrefix();
|
||||
PrintCliPrefix();
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
command.erase(nextLineIndex);
|
||||
continue;
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
Reference in New Issue
Block a user