Logging cleanup (#69)

* Mac OS X 10.6 & More C++03 Support

* Fix SDL2 options.txt loading for C++03

* Output/Logging Overhaul
* Added StandardOut class
* Renamed LOGX macros to LOG_X
* Removed LogMsg macros in favor of LOG_X
* Added console window for debug Windows builds

* Updated Xcode Project
+ StandardOut.hpp
+ StandardOut.cpp

* StandardOut_windows
* Replaced the Windows #ifdefs in StandardOut with StandardOut_windows

---------

Co-authored-by: Brent Da Mage <BrentDaMage@users.noreply.github.com>
This commit is contained in:
Brent
2023-08-28 02:55:41 -05:00
committed by GitHub
parent f7915a1dab
commit 5c1ea03747
43 changed files with 326 additions and 207 deletions

View File

@@ -8,14 +8,15 @@
#include <RakPeer.h>
#include "ClientSideNetworkHandler.hpp"
#include "common/Utils.hpp"
#include "client/gui/screens/StartMenuScreen.hpp"
// This lets you make the client shut up and not log events in the debug console.
#define VERBOSE_CLIENT
#if defined(ORIGINAL_CODE) || defined(VERBOSE_CLIENT)
#define puts_ignorable(str) puts(str)
#define printf_ignorable(str, ...) printf(str, __VA_ARGS__)
#define puts_ignorable(str) LOG_I(str)
#define printf_ignorable(str, ...) LOG_I(str, __VA_ARGS__)
#else
#define puts_ignorable(str)
#define printf_ignorable(str, ...)
@@ -42,7 +43,7 @@ void ClientSideNetworkHandler::levelGenerated(Level* level)
void ClientSideNetworkHandler::onConnect(const RakNet::RakNetGUID& rakGuid) // server guid
{
RakNet::RakNetGUID localGuid = ((RakNet::RakPeer*)m_pServerPeer)->GetMyGUID();
printf_ignorable("onConnect, server guid: %s, local guid: %s\n", rakGuid.ToString(), localGuid.ToString());
printf_ignorable("onConnect, server guid: %s, local guid: %s", rakGuid.ToString(), localGuid.ToString());
m_serverGUID = rakGuid;
@@ -167,7 +168,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& rakGuid, MovePla
Entity* pEntity = m_pLevel->getEntity(packet->m_id);
if (!pEntity)
{
LogMsg("No player with id %d", packet->m_id);
LOG_E("No player with id %d", packet->m_id);
return;
}
@@ -181,7 +182,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& rakGuid, PlaceBl
Player* pPlayer = (Player*)m_pLevel->getEntity(pPlaceBlockPkt->m_playerID);
if (!pPlayer)
{
LogMsg("No player with id %d", pPlaceBlockPkt->m_playerID);
LOG_E("No player with id %d", pPlaceBlockPkt->m_playerID);
return;
}
@@ -218,7 +219,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& rakGuid, RemoveB
Player* pPlayer = (Player*)m_pLevel->getEntity(pRemoveBlockPkt->m_playerID);
if (!pPlayer)
{
LogMsg("No player with id %d", pRemoveBlockPkt->m_playerID);
LOG_E("No player with id %d", pRemoveBlockPkt->m_playerID);
return;
}
@@ -260,14 +261,14 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& rakGuid, ChunkDa
{
if (!m_pLevel)
{
puts("Level @ handle ChunkDataPacket is 0");
LOG_E("Level @ handle ChunkDataPacket is 0");
return;
}
LevelChunk* pChunk = m_pLevel->getChunkSource()->create(pChunkDataPkt->m_x, pChunkDataPkt->m_z);
if (!pChunk || pChunk->isEmpty())
{
puts("Failed to find write-able chunk");
LOG_E("Failed to find write-able chunk");
// @BUG: Not trying again.
return;
}
@@ -348,17 +349,15 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& rakGuid, PlayerE
if (!pPlayer)
return;
#ifndef ORIGINAL_CODE
if (!Item::items[pPlayerEquipmentPkt->m_itemID])
{
LogMsg("That item %d doesn't actually exist!", pPlayerEquipmentPkt->m_itemID);
LOG_W("That item %d doesn't actually exist!", pPlayerEquipmentPkt->m_itemID);
return;
}
#endif
if (pPlayer->m_guid == m_pServerPeer->GetMyGUID())
{
puts("Attempted to modify local player's inventory");
LOG_W("Attempted to modify local player's inventory");
return;
}
@@ -374,7 +373,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, LevelDataP
bs->Read(magicNum);
if (magicNum != compMagic && magicNum != uncompMagic)
{
LogMsg("Error, invalid level data packet with magic %d", magicNum);
LOG_E("Invalid level data packet with magic %d", magicNum);
return;
}
@@ -386,7 +385,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, LevelDataP
bs->Read(uncompSize);
bs->Read(compSize);
LogMsg("Decompressing level data. Compressed: %d bytes, uncompressed: %d bytes", compSize, uncompSize);
LOG_I("Decompressing level data. Compressed: %d bytes, uncompressed: %d bytes", compSize, uncompSize);
// Read the compressed data.
uint8_t* pCompData = new uint8_t[compSize];
@@ -399,7 +398,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, LevelDataP
// If we couldn't, bail
if (!pUncompData)
{
LogMsg("Error, can't decompress level data");
LOG_E("Failed to decompress level data!");
return;
}
@@ -421,7 +420,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, LevelDataP
if (chunksX != C_MAX_CHUNKS_X || chunksZ != C_MAX_CHUNKS_Z)
{
LogMsg("Error, we don't yet support a level of size %d x %d chunks. Some chunks may disappear or be regenerated.", chunksX, chunksZ);
LOG_E("We don't yet support a level of size %d x %d chunks. Some chunks may disappear or be regenerated.", chunksX, chunksZ);
}
for (int x = 0; x < chunksX; x++)
@@ -433,7 +432,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, LevelDataP
if (magicNum != chunkSepMagic)
{
_FAIL_BECAUSE_INVALID:
LogMsg("Error, aborting because level data is invalid, reading chunk %d, %d. Magic: %d", x, z, magicNum);
LOG_E("Aborting because level data is invalid, reading chunk %d, %d. Magic: %d", x, z, magicNum);
return;
}
@@ -445,7 +444,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, LevelDataP
LevelChunk* pChunk = m_pLevel->getChunk(x, z);
if (!pChunk || pChunk->isEmpty())
LogMsg("Error, no chunk at %d, %d", x, z);
LOG_E("No chunk at %d, %d", x, z);
// continue reading anyway to skip over the offending chunk

View File

@@ -7,13 +7,14 @@
********************************************************************/
#include "ServerSideNetworkHandler.hpp"
#include "common/Utils.hpp"
// This lets you make the server shut up and not log events in the debug console.
#define VERBOSE_SERVER
#if defined(ORIGINAL_CODE) || defined(VERBOSE_SERVER)
#define puts_ignorable(str) puts(str)
#define printf_ignorable(str, ...) printf(str, __VA_ARGS__)
#define puts_ignorable(str) LOG_I(str)
#define printf_ignorable(str, ...) LOG_I(str, __VA_ARGS__)
#else
#define puts_ignorable(str)
#define printf_ignorable(str, ...)
@@ -60,7 +61,7 @@ void ServerSideNetworkHandler::levelGenerated(Level* level)
void ServerSideNetworkHandler::onNewClient(const RakNet::RakNetGUID& guid)
{
printf_ignorable("onNewClient, client guid: %s\n", guid.ToString());
printf_ignorable("onNewClient, client guid: %s", guid.ToString());
}
void ServerSideNetworkHandler::onDisconnect(const RakNet::RakNetGUID& guid)
@@ -98,7 +99,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, LoginPacke
// if they're already online, fail
if (getPlayerByGUID(guid))
{
printf("That player is already in the world!\n");
LOG_E("That player is already in the world!");
return;
}
@@ -152,7 +153,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, MessagePac
OnlinePlayer* pOP = getPlayerByGUID(guid);
if (!pOP)
{
printf("MessagePacket: That jerk %s doesn't actually exist\n", guid.ToString());
LOG_W("MessagePacket: That jerk %s doesn't actually exist", guid.ToString());
return;
}
@@ -163,7 +164,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, MessagePac
if (msg[0] == '/')
{
printf("CMD: %s: %s\n", pOP->m_pPlayer->m_name.c_str(), msg.c_str());
LOG_I("CMD: %s: %s", pOP->m_pPlayer->m_name.c_str(), msg.c_str());
std::stringstream ss(msg);
ss.get(); // skip the /
@@ -190,7 +191,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, MessagePac
return;
}
printf("MSG: <%s> %s\n", pOP->m_pPlayer->m_name.c_str(), msg.c_str());
LOG_I("MSG: <%s> %s", pOP->m_pPlayer->m_name.c_str(), msg.c_str());
// send everyone the message
std::string gameMessage = "<" + pOP->m_pPlayer->m_name + "> " + msg;
@@ -268,21 +269,21 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, PlayerEqui
Player* pPlayer = (Player*)m_pLevel->getEntity(packet->m_playerID);
if (!pPlayer)
{
LogMsg("No player with id %d", packet->m_playerID);
LOG_W("No player with id %d", packet->m_playerID);
return;
}
#ifndef ORIGINAL_CODE
if (!Item::items[packet->m_itemID])
{
LogMsg("That item %d doesn't actually exist!", packet->m_itemID);
LOG_W("That item %d doesn't actually exist!", packet->m_itemID);
return;
}
#endif
if (pPlayer->m_guid == m_pRakNetPeer->GetMyGUID())
{
puts("Attempted to modify local player's inventory");
LOG_W("Attempted to modify local player's inventory");
return;
}
@@ -304,7 +305,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, RequestChu
LevelChunk* pChunk = m_pLevel->getChunk(packet->m_x, packet->m_z);
if (!pChunk)
{
LogMsg("No chunk at %d, %d", packet->m_x, packet->m_z);
LOG_E("No chunk at %d, %d", packet->m_x, packet->m_z);
return;
}

View File

@@ -61,7 +61,7 @@ void LevelDataPacket::write(RakNet::BitStream* pbs)
if (pCompressedData)
{
float ratio = 100.0f * float(compSize) / float(uncompSize);
//LogMsg("Compression ratio: %.2f (%d comp, %d uncomp)", ratio, int(compSize), int(uncompSize));
//LOG_I("Compression ratio: %.2f (%d comp, %d uncomp)", ratio, int(compSize), int(uncompSize));
int cs2 = int(compSize), us2 = int(uncompSize);
bs.Reset();
@@ -73,7 +73,7 @@ void LevelDataPacket::write(RakNet::BitStream* pbs)
}
else
{
//LogMsg("Level not compressed.");
//LOG_I("Level not compressed.");
}
pbs->Write(bs);