Make logger automatically put a newline (#675)

at the end of the line
remove all the newlines in log calls
This commit is contained in:
Aaron Kimbrell
2022-07-24 21:26:51 -05:00
committed by GitHub
parent a7fb6eb3f3
commit e97ae92624
86 changed files with 1249 additions and 1252 deletions

View File

@@ -26,7 +26,7 @@ InstanceManager::~InstanceManager() {
}
Instance * InstanceManager::GetInstance(LWOMAPID mapID, bool isFriendTransfer, LWOCLONEID cloneID) {
mLogger->Log("InstanceManager", "Searching for an instance for mapID %i/%i\n", mapID, cloneID);
mLogger->Log("InstanceManager", "Searching for an instance for mapID %i/%i", mapID, cloneID);
Instance* instance = FindInstance(mapID, isFriendTransfer, cloneID);
if (instance) return instance;
@@ -78,10 +78,10 @@ Instance * InstanceManager::GetInstance(LWOMAPID mapID, bool isFriendTransfer, L
m_Instances.push_back(instance);
if (instance) {
mLogger->Log("InstanceManager", "Created new instance: %i/%i/%i with min/max %i/%i\n", mapID, m_LastInstanceID, cloneID, softCap, maxPlayers);
mLogger->Log("InstanceManager", "Created new instance: %i/%i/%i with min/max %i/%i", mapID, m_LastInstanceID, cloneID, softCap, maxPlayers);
return instance;
}
else mLogger->Log("InstanceManager", "Failed to create a new instance!\n");
else mLogger->Log("InstanceManager", "Failed to create a new instance!");
return nullptr;
}
@@ -92,7 +92,7 @@ bool InstanceManager::IsPortInUse(uint32_t port) {
return true;
}
}
return false;
}
@@ -102,7 +102,7 @@ uint32_t InstanceManager::GetFreePort() {
for (Instance* i : m_Instances) {
usedPorts.push_back(i->GetPort());
}
std::sort(usedPorts.begin(), usedPorts.end());
int portIdx = 0;
@@ -142,7 +142,7 @@ std::vector<Instance*> InstanceManager::GetInstances() const
void InstanceManager::AddInstance(Instance* instance) {
if (instance == nullptr) return;
m_Instances.push_back(instance);
}
@@ -152,9 +152,9 @@ void InstanceManager::RemoveInstance(Instance* instance) {
if (m_Instances[i] == instance)
{
instance->SetShutdownComplete(true);
RedirectPendingRequests(instance);
delete m_Instances[i];
m_Instances.erase(m_Instances.begin() + i);
@@ -174,7 +174,7 @@ void InstanceManager::ReadyInstance(Instance* instance)
{
const auto& zoneId = instance->GetZoneID();
Game::logger->Log("InstanceManager", "Responding to pending request %llu -> %i (%i)\n", request, zoneId.GetMapID(), zoneId.GetCloneID());
Game::logger->Log("InstanceManager", "Responding to pending request %llu -> %i (%i)", request, zoneId.GetMapID(), zoneId.GetCloneID());
MasterPackets::SendZoneTransferResponse(
Game::server,
@@ -188,7 +188,7 @@ void InstanceManager::ReadyInstance(Instance* instance)
instance->GetPort()
);
}
pending.clear();
}
@@ -201,10 +201,10 @@ void InstanceManager::RequestAffirmation(Instance* instance, const PendingInstan
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_AFFIRM_TRANSFER_REQUEST);
bitStream.Write(request.id);
Game::server->Send(&bitStream, instance->GetSysAddr(), false);
Game::logger->Log("MasterServer", "Sent affirmation request %llu to %i/%i\n", request.id,
Game::logger->Log("MasterServer", "Sent affirmation request %llu to %i/%i", request.id,
static_cast<int>(instance->GetZoneID().GetMapID()),
static_cast<int>(instance->GetZoneID().GetCloneID())
);
@@ -217,7 +217,7 @@ void InstanceManager::AffirmTransfer(Instance* instance, const uint64_t transfer
for (auto i = 0u; i < pending.size(); ++i)
{
const auto& request = pending[i];
if (request.id != transferID) continue;
const auto& zoneId = instance->GetZoneID();
@@ -233,7 +233,7 @@ void InstanceManager::AffirmTransfer(Instance* instance, const uint64_t transfer
instance->GetIP(),
instance->GetPort()
);
pending.erase(pending.begin() + i);
break;
@@ -243,7 +243,7 @@ void InstanceManager::AffirmTransfer(Instance* instance, const uint64_t transfer
void InstanceManager::RedirectPendingRequests(Instance* instance)
{
const auto& zoneId = instance->GetZoneID();
for (const auto& request : instance->GetPendingAffirmations())
{
auto* in = Game::im->GetInstance(zoneId.GetMapID(), false, zoneId.GetCloneID());
@@ -270,11 +270,11 @@ Instance* InstanceManager::GetInstanceBySysAddr(SystemAddress& sysAddr) {
}
bool InstanceManager::IsInstanceFull(Instance* instance, bool isFriendTransfer) {
if (!isFriendTransfer && instance->GetSoftCap() > instance->GetCurrentClientCount())
if (!isFriendTransfer && instance->GetSoftCap() > instance->GetCurrentClientCount())
return false;
else if (isFriendTransfer && instance->GetHardCap() > instance->GetCurrentClientCount())
else if (isFriendTransfer && instance->GetHardCap() > instance->GetCurrentClientCount())
return false;
return true;
}
@@ -308,7 +308,7 @@ Instance* InstanceManager::CreatePrivateInstance(LWOMAPID mapID, LWOCLONEID clon
}
int maxPlayers = 999;
uint32_t port = GetFreePort();
instance = new Instance(mExternalIP, port, mapID, ++m_LastInstanceID, cloneID, maxPlayers, maxPlayers, true, password);
@@ -339,7 +339,7 @@ Instance* InstanceManager::CreatePrivateInstance(LWOMAPID mapID, LWOCLONEID clon
m_Instances.push_back(instance);
if (instance) return instance;
else mLogger->Log("InstanceManager", "Failed to create a new instance!\n");
else mLogger->Log("InstanceManager", "Failed to create a new instance!");
return instance;
}
@@ -355,7 +355,7 @@ Instance* InstanceManager::FindPrivateInstance(const std::string& password)
continue;
}
mLogger->Log("InstanceManager", "Password: %s == %s => %d\n", password.c_str(), instance->GetPassword().c_str(), password == instance->GetPassword());
mLogger->Log("InstanceManager", "Password: %s == %s => %d", password.c_str(), instance->GetPassword().c_str(), password == instance->GetPassword());
if (instance->GetPassword() == password)
{
@@ -375,7 +375,7 @@ int InstanceManager::GetSoftCap(LWOMAPID mapID) {
return zone->population_soft_cap;
}
}
return 8;
}
@@ -405,10 +405,10 @@ bool Instance::GetShutdownComplete() const
void Instance::Shutdown()
{
CBITSTREAM;
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_SHUTDOWN);
Game::server->Send(&bitStream, this->m_SysAddr, false);
Game::logger->Log("Instance", "Triggered world shutdown\n");
Game::logger->Log("Instance", "Triggered world shutdown");
}

View File

@@ -75,16 +75,16 @@ int main(int argc, char** argv) {
Game::logger = SetupLogger();
if (!Game::logger) return EXIT_FAILURE;
Game::logger->Log("MasterServer", "Starting Master server...\n");
Game::logger->Log("MasterServer", "Version: %i.%i\n", PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR);
Game::logger->Log("MasterServer", "Compiled on: %s\n", __TIMESTAMP__);
Game::logger->Log("MasterServer", "Starting Master server...");
Game::logger->Log("MasterServer", "Version: %i.%i", PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR);
Game::logger->Log("MasterServer", "Compiled on: %s", __TIMESTAMP__);
//Read our config:
dConfig config("masterconfig.ini");
Game::config = &config;
Game::logger->SetLogToConsole(bool(std::stoi(config.GetValue("log_to_console"))));
Game::logger->SetLogDebugStatements(config.GetValue("log_debug_statements") == "1");
if (argc > 1 && (strcmp(argv[1], "-m") == 0 || strcmp(argv[1], "--migrations") == 0)) {
//Connect to the MySQL Database
std::string mysql_host = config.GetValue("mysql_host");
@@ -95,23 +95,23 @@ int main(int argc, char** argv) {
try {
Database::Connect(mysql_host, mysql_database, mysql_username, mysql_password);
} catch (sql::SQLException& ex) {
Game::logger->Log("MasterServer", "Got an error while connecting to the database: %s\n", ex.what());
Game::logger->Log("MigrationRunner", "Migrations not run\n");
Game::logger->Log("MasterServer", "Got an error while connecting to the database: %s", ex.what());
Game::logger->Log("MigrationRunner", "Migrations not run");
return EXIT_FAILURE;
}
MigrationRunner::RunMigrations();
Game::logger->Log("MigrationRunner", "Finished running migrations\n");
Game::logger->Log("MigrationRunner", "Finished running migrations");
return EXIT_SUCCESS;
}
}
else {
//Check CDClient exists
const std::string cdclient_path = "./res/CDServer.sqlite";
std::ifstream cdclient_fd(cdclient_path);
if (!cdclient_fd.good()) {
Game::logger->Log("WorldServer", "%s could not be opened\n", cdclient_path.c_str());
Game::logger->Log("WorldServer", "%s could not be opened", cdclient_path.c_str());
return EXIT_FAILURE;
}
cdclient_fd.close();
@@ -120,9 +120,9 @@ int main(int argc, char** argv) {
try {
CDClientDatabase::Connect(cdclient_path);
} catch (CppSQLite3Exception& e) {
Game::logger->Log("WorldServer", "Unable to connect to CDServer SQLite Database\n");
Game::logger->Log("WorldServer", "Error: %s\n", e.errorMessage());
Game::logger->Log("WorldServer", "Error Code: %i\n", e.errorCode());
Game::logger->Log("WorldServer", "Unable to connect to CDServer SQLite Database");
Game::logger->Log("WorldServer", "Error: %s", e.errorMessage());
Game::logger->Log("WorldServer", "Error Code: %i", e.errorCode());
return EXIT_FAILURE;
}
@@ -130,10 +130,10 @@ int main(int argc, char** argv) {
try {
CDClientManager::Instance()->Initialize();
} catch (CppSQLite3Exception& e) {
Game::logger->Log("WorldServer", "Failed to initialize CDServer SQLite Database\n");
Game::logger->Log("WorldServer", "May be caused by corrupted file: %s\n", cdclient_path.c_str());
Game::logger->Log("WorldServer", "Error: %s\n", e.errorMessage());
Game::logger->Log("WorldServer", "Error Code: %i\n", e.errorCode());
Game::logger->Log("WorldServer", "Failed to initialize CDServer SQLite Database");
Game::logger->Log("WorldServer", "May be caused by corrupted file: %s", cdclient_path.c_str());
Game::logger->Log("WorldServer", "Error: %s", e.errorMessage());
Game::logger->Log("WorldServer", "Error Code: %i", e.errorCode());
return EXIT_FAILURE;
}
@@ -146,7 +146,7 @@ int main(int argc, char** argv) {
try {
Database::Connect(mysql_host, mysql_database, mysql_username, mysql_password);
} catch (sql::SQLException& ex) {
Game::logger->Log("MasterServer", "Got an error while connecting to the database: %s\n", ex.what());
Game::logger->Log("MasterServer", "Got an error while connecting to the database: %s", ex.what());
return EXIT_FAILURE;
}
}
@@ -368,14 +368,14 @@ dLogger* SetupLogger() {
void HandlePacket(Packet* packet) {
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION) {
Game::logger->Log("MasterServer", "A server has disconnected\n");
Game::logger->Log("MasterServer", "A server has disconnected");
//Since this disconnection is intentional, we'll just delete it as
//we'll start a new one anyway if needed:
Instance* instance =
Game::im->GetInstanceBySysAddr(packet->systemAddress);
if (instance) {
Game::logger->Log("MasterServer", "Actually disconnected from zone %i clone %i instance %i port %i\n", instance->GetMapID(), instance->GetCloneID(), instance->GetInstanceID(), instance->GetPort());
Game::logger->Log("MasterServer", "Actually disconnected from zone %i clone %i instance %i port %i", instance->GetMapID(), instance->GetCloneID(), instance->GetInstanceID(), instance->GetPort());
Game::im->RemoveInstance(instance); //Delete the old
}
@@ -385,7 +385,7 @@ void HandlePacket(Packet* packet) {
}
if (packet->data[0] == ID_CONNECTION_LOST) {
Game::logger->Log("MasterServer", "A server has lost the connection\n");
Game::logger->Log("MasterServer", "A server has lost the connection");
Instance* instance =
Game::im->GetInstanceBySysAddr(packet->systemAddress);
@@ -403,7 +403,7 @@ void HandlePacket(Packet* packet) {
if (packet->data[1] == MASTER) {
switch (packet->data[3]) {
case MSG_MASTER_REQUEST_PERSISTENT_ID: {
Game::logger->Log("MasterServer", "A persistent ID req\n");
Game::logger->Log("MasterServer", "A persistent ID req");
RakNet::BitStream inStream(packet->data, packet->length, false);
uint64_t header = inStream.Read(header);
uint64_t requestID = 0;
@@ -415,7 +415,7 @@ void HandlePacket(Packet* packet) {
}
case MSG_MASTER_REQUEST_ZONE_TRANSFER: {
Game::logger->Log("MasterServer","Received zone transfer req\n");
Game::logger->Log("MasterServer","Received zone transfer req");
RakNet::BitStream inStream(packet->data, packet->length, false);
uint64_t header = inStream.Read(header);
uint64_t requestID = 0;
@@ -431,18 +431,18 @@ void HandlePacket(Packet* packet) {
Instance* in = Game::im->GetInstance(zoneID, false, zoneClone);
for (auto* instance : Game::im->GetInstances()) {
Game::logger->Log("MasterServer", "Instance: %i/%i/%i -> %i\n",instance->GetMapID(), instance->GetCloneID(),instance->GetInstanceID(), instance == in);
Game::logger->Log("MasterServer", "Instance: %i/%i/%i -> %i",instance->GetMapID(), instance->GetCloneID(),instance->GetInstanceID(), instance == in);
}
if (!in->GetIsReady()) //Instance not ready, make a pending request
{
in->GetPendingRequests().push_back({ requestID, static_cast<bool>(mythranShift), packet->systemAddress });
Game::logger->Log("MasterServer", "Server not ready, adding pending request %llu %i %i\n", requestID, zoneID, zoneClone);
Game::logger->Log("MasterServer", "Server not ready, adding pending request %llu %i %i", requestID, zoneID, zoneClone);
break;
}
//Instance is ready, transfer
Game::logger->Log("MasterServer", "Responding to transfer request %llu for zone %i %i\n", requestID, zoneID, zoneClone);
Game::logger->Log("MasterServer", "Responding to transfer request %llu for zone %i %i", requestID, zoneID, zoneClone);
Game::im->RequestAffirmation(in, { requestID, static_cast<bool>(mythranShift), packet->systemAddress });
break;
}
@@ -494,7 +494,7 @@ void HandlePacket(Packet* packet) {
chatServerMasterPeerSysAddr = copy;
}
Game::logger->Log("MasterServer", "Received server info, instance: %i port: %i\n", theirInstanceID, theirPort);
Game::logger->Log("MasterServer", "Received server info, instance: %i port: %i", theirInstanceID, theirPort);
break;
}
@@ -526,7 +526,7 @@ void HandlePacket(Packet* packet) {
}
activeSessions.insert(std::make_pair(sessionKey, username));
Game::logger->Log("MasterServer", "Got sessionKey %i for user %s\n", sessionKey, username.c_str());
Game::logger->Log("MasterServer", "Got sessionKey %i for user %s", sessionKey, username.c_str());
break;
}
@@ -564,7 +564,7 @@ void HandlePacket(Packet* packet) {
instance->AddPlayer(Player());
}
else {
printf("Instance missing? What?\n");
printf("Instance missing? What?");
}
break;
}
@@ -622,7 +622,7 @@ void HandlePacket(Packet* packet) {
inStream.Read(requestID);
inStream.Read(mythranShift);
uint32_t len;
inStream.Read<uint32_t>(len);
@@ -633,7 +633,7 @@ void HandlePacket(Packet* packet) {
auto* instance = Game::im->FindPrivateInstance(password.c_str());
Game::logger->Log( "MasterServer", "Join private zone: %llu %d %s %p\n", requestID, mythranShift, password.c_str(), instance);
Game::logger->Log( "MasterServer", "Join private zone: %llu %d %s %p", requestID, mythranShift, password.c_str(), instance);
if (instance == nullptr) {
return;
@@ -656,16 +656,16 @@ void HandlePacket(Packet* packet) {
inStream.Read(zoneID);
inStream.Read(instanceID);
Game::logger->Log("MasterServer", "Got world ready %i %i\n",zoneID, instanceID);
Game::logger->Log("MasterServer", "Got world ready %i %i",zoneID, instanceID);
auto* instance = Game::im->FindInstance(zoneID, instanceID);
if (instance == nullptr) {
Game::logger->Log("MasterServer","Failed to find zone to ready\n");
Game::logger->Log("MasterServer","Failed to find zone to ready");
return;
}
Game::logger->Log("MasterServer", "Ready zone %i\n", zoneID);
Game::logger->Log("MasterServer", "Ready zone %i", zoneID);
Game::im->ReadyInstance(instance);
break;
}
@@ -677,7 +677,7 @@ void HandlePacket(Packet* packet) {
int zoneID;
inStream.Read(zoneID);
Game::logger->Log("MasterServer", "Prepping zone %i\n", zoneID);
Game::logger->Log("MasterServer", "Prepping zone %i", zoneID);
Game::im->GetInstance(zoneID, false, 0);
break;
}
@@ -690,7 +690,7 @@ void HandlePacket(Packet* packet) {
inStream.Read(requestID);
Game::logger->Log("MasterServer","Got affirmation of transfer %llu\n",requestID);
Game::logger->Log("MasterServer","Got affirmation of transfer %llu",requestID);
auto* instance =Game::im->GetInstanceBySysAddr(packet->systemAddress);
@@ -698,7 +698,7 @@ void HandlePacket(Packet* packet) {
return;
Game::im->AffirmTransfer(instance, requestID);
Game::logger->Log("MasterServer", "Affirmation complete %llu\n",requestID);
Game::logger->Log("MasterServer", "Affirmation complete %llu",requestID);
break;
}
@@ -712,19 +712,19 @@ void HandlePacket(Packet* packet) {
return;
}
Game::logger->Log("MasterServer", "Got shutdown response from zone %i clone %i instance %i port %i\n", instance->GetMapID(), instance->GetCloneID(), instance->GetInstanceID(), instance->GetPort());
Game::logger->Log("MasterServer", "Got shutdown response from zone %i clone %i instance %i port %i", instance->GetMapID(), instance->GetCloneID(), instance->GetInstanceID(), instance->GetPort());
instance->SetIsShuttingDown(true);
break;
}
case MSG_MASTER_SHUTDOWN_UNIVERSE: {
Game::logger->Log("MasterServer","Received shutdown universe command, shutting down in 10 minutes.\n");
Game::logger->Log("MasterServer","Received shutdown universe command, shutting down in 10 minutes.");
shouldShutdown = true;
break;
}
default:
Game::logger->Log("MasterServer","Unknown master packet ID from server: %i\n",packet->data[3]);
Game::logger->Log("MasterServer","Unknown master packet ID from server: %i",packet->data[3]);
}
}
}
@@ -780,7 +780,7 @@ void ShutdownSequence() {
auto* objIdManager = ObjectIDManager::TryInstance();
if (objIdManager != nullptr) {
objIdManager->SaveToDatabase();
Game::logger->Log("MasterServer", "Saved ObjectIDTracker to DB\n");
Game::logger->Log("MasterServer", "Saved ObjectIDTracker to DB");
}
auto t = std::chrono::high_resolution_clock::now();
@@ -790,7 +790,7 @@ void ShutdownSequence() {
exit(EXIT_SUCCESS);
}
Game::logger->Log("MasterServer", "Attempting to shutdown instances, max 60 seconds...\n");
Game::logger->Log("MasterServer", "Attempting to shutdown instances, max 60 seconds...");
while (true) {
@@ -800,7 +800,7 @@ void ShutdownSequence() {
Game::server->DeallocatePacket(packet);
packet = nullptr;
}
auto done = true;
for (auto* instance : Game::im->GetInstances()) {
@@ -814,7 +814,7 @@ void ShutdownSequence() {
}
if (done) {
Game::logger->Log("MasterServer", "Finished shutting down MasterServer!\n");
Game::logger->Log("MasterServer", "Finished shutting down MasterServer!");
break;
}
@@ -824,7 +824,7 @@ void ShutdownSequence() {
ticks++;
if (ticks == 600 * 6) {
Game::logger->Log("MasterServer", "Finished shutting down by timeout!\n");
Game::logger->Log("MasterServer", "Finished shutting down by timeout!");
break;
}
}

View File

@@ -40,8 +40,8 @@ void ObjectIDManager::Initialize(dLogger *logger) {
delete stmt;
} catch (sql::SQLException &e) {
mLogger->Log("ObjectIDManager", "Unable to fetch max persistent object "
"ID in use. Defaulting to 1.\n");
mLogger->Log("ObjectIDManager", "SQL error: %s\n", e.what());
"ID in use. Defaulting to 1.");
mLogger->Log("ObjectIDManager", "SQL error: %s", e.what());
this->currentPersistentID = 1;
}
}