Skip to content

Commit

Permalink
Improve readability and infos in verbose log (#13828)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Sep 22, 2023
1 parent 5949172 commit c311413
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 51 deletions.
7 changes: 4 additions & 3 deletions src/client/client.cpp
Expand Up @@ -1317,9 +1317,7 @@ void Client::sendChatMessage(const std::wstring &message)
m_chat_message_allowance -= 1.0f;

NetworkPacket pkt(TOSERVER_CHAT_MESSAGE, 2 + message.size() * sizeof(u16));

pkt << message;

Send(&pkt);
} else if (m_out_chat_queue.size() < (u16) max_queue_size || max_queue_size < 0) {
m_out_chat_queue.push(message);
Expand Down Expand Up @@ -1701,8 +1699,11 @@ void Client::typeChatMessage(const std::wstring &message)
if (message.empty())
return;

auto message_utf8 = wide_to_utf8(message);
infostream << "Typed chat message: \"" << message_utf8 << "\"" << std::endl;

// If message was consumed by script API, don't send it to server
if (m_mods_loaded && m_script->on_sending_message(wide_to_utf8(message)))
if (m_mods_loaded && m_script->on_sending_message(message_utf8))
return;

// Send to others
Expand Down
6 changes: 1 addition & 5 deletions src/client/content_cao.cpp
Expand Up @@ -357,7 +357,6 @@ bool GenericCAO::collideWithObjects() const

void GenericCAO::initialize(const std::string &data)
{
infostream<<"GenericCAO: Got init data"<<std::endl;
processInitData(data);

m_enable_shaders = g_settings->getBool("enable_shaders");
Expand Down Expand Up @@ -393,8 +392,7 @@ void GenericCAO::processInitData(const std::string &data)
}

const u8 num_messages = readU8(is);

for (int i = 0; i < num_messages; i++) {
for (u8 i = 0; i < num_messages; i++) {
std::string message = deSerializeString32(is);
processMessage(message);
}
Expand Down Expand Up @@ -1704,8 +1702,6 @@ void GenericCAO::processMessage(const std::string &data)
if (expire_visuals) {
expireVisuals();
} else {
infostream << "GenericCAO: properties updated but expiring visuals"
<< " not necessary" << std::endl;
if (textures_changed) {
// don't update while punch texture modifier is active
if (m_reset_textures_timer < 0)
Expand Down
11 changes: 1 addition & 10 deletions src/client/renderingengine.cpp
Expand Up @@ -195,16 +195,7 @@ void RenderingEngine::cleanupMeshCache()

bool RenderingEngine::setupTopLevelWindow()
{
// FIXME: It would make more sense for there to be a switch of some
// sort here that would call the correct toplevel setup methods for
// the environment Minetest is running in.

/* Setting general properties for the top level window */
verbosestream << "Client: Configuring general top level window properties"
<< std::endl;
bool result = setWindowIcon();

return result;
return setWindowIcon();
}

bool RenderingEngine::setWindowIcon()
Expand Down
2 changes: 0 additions & 2 deletions src/client/shader.cpp
Expand Up @@ -488,8 +488,6 @@ u32 ShaderSource::getShader(const std::string &name,
u32 ShaderSource::getShaderIdDirect(const std::string &name,
MaterialType material_type, NodeDrawType drawtype)
{
//infostream<<"getShaderIdDirect(): name=\""<<name<<"\""<<std::endl;

// Empty name means shader 0
if (name.empty()) {
infostream<<"getShaderIdDirect(): name is empty"<<std::endl;
Expand Down
4 changes: 3 additions & 1 deletion src/clientiface.cpp
Expand Up @@ -412,7 +412,9 @@ void RemoteClient::GetNextBlocks (
if (d > full_d_max) {
new_nearest_unsent_d = 0;
m_nothing_to_send_pause_timer = 2.0f;
infostream << "Server: Player " << m_name << ", RemoteClient " << peer_id << ": full map send completed after " << m_map_send_completion_timer << "s, restarting" << std::endl;
infostream << "Server: Player " << m_name << ", peer_id=" << peer_id
<< ": full map send completed after " << m_map_send_completion_timer
<< "s, restarting" << std::endl;
m_map_send_completion_timer = 0.0f;
} else {
if (nearest_sent_d != -1)
Expand Down
6 changes: 3 additions & 3 deletions src/itemdef.cpp
Expand Up @@ -353,14 +353,14 @@ class CItemDefManager: public IWritableItemDefManager
if (!inventory_overlay.empty())
cache_key += ":" + inventory_overlay;

infostream << "Lazily creating item texture and mesh for \""
<< cache_key << "\""<<std::endl;

// Skip if already in cache
auto it = m_clientcached.find(cache_key);
if (it != m_clientcached.end())
return it->second.get();

infostream << "Lazily creating item texture and mesh for \""
<< cache_key << "\"" << std::endl;

ITextureSource *tsrc = client->getTextureSource();

// Create new ClientCached
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Expand Up @@ -713,8 +713,8 @@ static void uninit_common()

static void startup_message()
{
infostream << PROJECT_NAME << " " << _("with")
<< " SER_FMT_VER_HIGHEST_READ="
infostream << PROJECT_NAME_C << " " << g_version_hash
<< "\nwith SER_FMT_VER_HIGHEST_READ="
<< (int)SER_FMT_VER_HIGHEST_READ << ", "
<< g_build_info << std::endl;
}
Expand Down
11 changes: 6 additions & 5 deletions src/mapblock.cpp
Expand Up @@ -91,14 +91,15 @@ bool MapBlock::onObjectsActivation()
if (m_static_objects.getAllStored().empty())
return false;

const auto count = m_static_objects.getStoredSize();
verbosestream << "MapBlock::onObjectsActivation(): "
<< "activating objects of block " << getPos() << " ("
<< m_static_objects.getStoredSize() << " objects)" << std::endl;
<< "activating " << count << "objects in block " << getPos()
<< std::endl;

if (m_static_objects.getStoredSize() > g_settings->getU16("max_objects_per_block")) {
if (count > g_settings->getU16("max_objects_per_block")) {
errorstream << "suspiciously large amount of objects detected: "
<< m_static_objects.getStoredSize() << " in "
<< getPos() << "; removing all of them." << std::endl;
<< count << " in " << getPos() << "; removing all of them."
<< std::endl;
// Clear stored list
m_static_objects.clearStored();
raiseModified(MOD_STATE_WRITE_NEEDED, MOD_REASON_TOO_MANY_OBJECTS);
Expand Down
13 changes: 0 additions & 13 deletions src/script/cpp_api/s_entity.cpp
Expand Up @@ -29,9 +29,6 @@ bool ScriptApiEntity::luaentity_Add(u16 id, const char *name)
{
SCRIPTAPI_PRECHECKHEADER

verbosestream<<"scriptapi_luaentity_add: id="<<id<<" name=\""
<<name<<"\""<<std::endl;

// Get core.registered_entities[name]
lua_getglobal(L, "core");
lua_getfield(L, -1, "registered_entities");
Expand Down Expand Up @@ -78,8 +75,6 @@ void ScriptApiEntity::luaentity_Activate(u16 id,
{
SCRIPTAPI_PRECHECKHEADER

verbosestream << "scriptapi_luaentity_activate: id=" << id << std::endl;

int error_handler = PUSH_ERROR_HANDLER(L);

// Get core.luaentities[id]
Expand All @@ -106,8 +101,6 @@ void ScriptApiEntity::luaentity_Deactivate(u16 id, bool removal)
{
SCRIPTAPI_PRECHECKHEADER

verbosestream << "scriptapi_luaentity_deactivate: id=" << id << std::endl;

int error_handler = PUSH_ERROR_HANDLER(L);

// Get the entity
Expand All @@ -132,8 +125,6 @@ void ScriptApiEntity::luaentity_Remove(u16 id)
{
SCRIPTAPI_PRECHECKHEADER

verbosestream << "scriptapi_luaentity_rm: id=" << id << std::endl;

// Get core.luaentities table
lua_getglobal(L, "core");
lua_getfield(L, -1, "luaentities");
Expand All @@ -152,8 +143,6 @@ std::string ScriptApiEntity::luaentity_GetStaticdata(u16 id)
{
SCRIPTAPI_PRECHECKHEADER

//infostream<<"scriptapi_luaentity_get_staticdata: id="<<id<<std::endl;

int error_handler = PUSH_ERROR_HANDLER(L);

// Get core.luaentities[id]
Expand Down Expand Up @@ -217,8 +206,6 @@ void ScriptApiEntity::luaentity_GetProperties(u16 id,
{
SCRIPTAPI_PRECHECKHEADER

//infostream<<"scriptapi_luaentity_get_properties: id="<<id<<std::endl;

// Get core.luaentities[id]
luaentity_get(L, id);

Expand Down
9 changes: 6 additions & 3 deletions src/server/luaentity_sao.cpp
Expand Up @@ -71,8 +71,12 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &d
break;
}
// create object
infostream << "LuaEntitySAO::create(name=\"" << name << "\" state=\""
<< state << "\")" << std::endl;
infostream << "LuaEntitySAO::create(name=\"" << name << "\" state is";
if (state.empty())
infostream << "empty";
else
infostream << state.size() << " bytes";
infostream << ")" << std::endl;

m_init_name = name;
m_init_state = state;
Expand Down Expand Up @@ -281,7 +285,6 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)

void LuaEntitySAO::getStaticData(std::string *result) const
{
verbosestream<<FUNCTION_NAME<<std::endl;
std::ostringstream os(std::ios::binary);
// version must be 1 to keep backwards-compatibility. See version2
writeU8(os, 1);
Expand Down
4 changes: 0 additions & 4 deletions src/serverenvironment.cpp
Expand Up @@ -2162,10 +2162,6 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete)
return false;
}

verbosestream << "ServerEnvironment::deactivateFarObjects(): "
<< "object id=" << id << " is not known by clients"
<< "; deleting" << std::endl;

// Tell the object about removal
obj->removingFromEnvironment();
// Deregister in scripting api
Expand Down

0 comments on commit c311413

Please sign in to comment.