Selaa lähdekoodia

Added basic logging

Ivan Savenko 1 vuosi sitten
vanhempi
sitoutus
ad547fcae0
2 muutettua tiedostoa jossa 20 lisäystä ja 3 poistoa
  1. 9 0
      lobby/EntryPoint.cpp
  2. 11 3
      lobby/LobbyServer.cpp

+ 9 - 0
lobby/EntryPoint.cpp

@@ -11,15 +11,24 @@
 
 #include "LobbyServer.h"
 
+#include "../lib/logging/CBasicLogConfigurator.h"
 #include "../lib/VCMIDirs.h"
 
 static const int LISTENING_PORT = 30303;
 
 int main(int argc, const char * argv[])
 {
+#ifndef VCMI_IOS
+	console = new CConsoleHandler();
+#endif
+	CBasicLogConfigurator logConfig(VCMIDirs::get().userLogsPath() / "VCMI_Lobby_log.txt", console);
+	logConfig.configureDefault();
+
 	auto databasePath = VCMIDirs::get().userDataPath() / "vcmiLobby.db";
+	logGlobal->info("Opening database %s", databasePath.string());
 
 	LobbyServer server(databasePath);
+	logGlobal->info("Starting server on port %d", LISTENING_PORT);
 
 	server.start(LISTENING_PORT);
 	server.run();

+ 11 - 3
lobby/LobbyServer.cpp

@@ -252,6 +252,9 @@ void LobbyServer::onPacketReceived(const NetworkConnectionPtr & connection, cons
 	// communication messages from vcmiclient
 	if(activeAccounts.count(connection))
 	{
+		std::string accountName = activeAccounts.at(connection).accountID;
+		logGlobal->info("%s: Received message of type %s", accountName, messageType);
+
 		if(messageType == "sendChatMessage")
 			return receiveSendChatMessage(connection, json);
 
@@ -267,20 +270,25 @@ void LobbyServer::onPacketReceived(const NetworkConnectionPtr & connection, cons
 		if(messageType == "declineInvite")
 			return receiveDeclineInvite(connection, json);
 
-		logGlobal->info("Received unexpected message of type %s from account %s", messageType, activeAccounts.at(connection).accountID);
+		logGlobal->warn("%s: Unknown message type: %s", accountName, messageType);
 		return;
 	}
 
 	// communication messages from vcmiserver
 	if(activeGameRooms.count(connection))
 	{
+		std::string roomName = activeGameRooms.at(connection).roomID;
+		logGlobal->info("%s: Received message of type %s", roomName, messageType);
+
 		if(messageType == "leaveGameRoom")
 			return receiveLeaveGameRoom(connection, json);
 
-		logGlobal->info("Received unexpected message of type %s from game room %s", messageType, activeGameRooms.at(connection).roomID);
+		logGlobal->warn("%s: Unknown message type: %s", roomName, messageType);
 		return;
 	}
 
+	logGlobal->info("(unauthorised): Received message of type %s", messageType);
+
 	// unauthorized connections - permit only login or register attempts
 	if(messageType == "clientLogin")
 		return receiveClientLogin(connection, json);
@@ -300,7 +308,7 @@ void LobbyServer::onPacketReceived(const NetworkConnectionPtr & connection, cons
 	// TODO: add logging of suspicious connections.
 	networkServer->closeConnection(connection);
 
-	logGlobal->info("Received unexpected message of type %s from not authorised account!", messageType);
+	logGlobal->info("(unauthorised): Unknown message type %s", messageType);
 }
 
 void LobbyServer::receiveSendChatMessage(const NetworkConnectionPtr & connection, const JsonNode & json)