mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
Added basic logging
This commit is contained in:
@@ -11,15 +11,24 @@
|
|||||||
|
|
||||||
#include "LobbyServer.h"
|
#include "LobbyServer.h"
|
||||||
|
|
||||||
|
#include "../lib/logging/CBasicLogConfigurator.h"
|
||||||
#include "../lib/VCMIDirs.h"
|
#include "../lib/VCMIDirs.h"
|
||||||
|
|
||||||
static const int LISTENING_PORT = 30303;
|
static const int LISTENING_PORT = 30303;
|
||||||
|
|
||||||
int main(int argc, const char * argv[])
|
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";
|
auto databasePath = VCMIDirs::get().userDataPath() / "vcmiLobby.db";
|
||||||
|
logGlobal->info("Opening database %s", databasePath.string());
|
||||||
|
|
||||||
LobbyServer server(databasePath);
|
LobbyServer server(databasePath);
|
||||||
|
logGlobal->info("Starting server on port %d", LISTENING_PORT);
|
||||||
|
|
||||||
server.start(LISTENING_PORT);
|
server.start(LISTENING_PORT);
|
||||||
server.run();
|
server.run();
|
||||||
|
|||||||
@@ -252,6 +252,9 @@ void LobbyServer::onPacketReceived(const NetworkConnectionPtr & connection, cons
|
|||||||
// communication messages from vcmiclient
|
// communication messages from vcmiclient
|
||||||
if(activeAccounts.count(connection))
|
if(activeAccounts.count(connection))
|
||||||
{
|
{
|
||||||
|
std::string accountName = activeAccounts.at(connection).accountID;
|
||||||
|
logGlobal->info("%s: Received message of type %s", accountName, messageType);
|
||||||
|
|
||||||
if(messageType == "sendChatMessage")
|
if(messageType == "sendChatMessage")
|
||||||
return receiveSendChatMessage(connection, json);
|
return receiveSendChatMessage(connection, json);
|
||||||
|
|
||||||
@@ -267,20 +270,25 @@ void LobbyServer::onPacketReceived(const NetworkConnectionPtr & connection, cons
|
|||||||
if(messageType == "declineInvite")
|
if(messageType == "declineInvite")
|
||||||
return receiveDeclineInvite(connection, json);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// communication messages from vcmiserver
|
// communication messages from vcmiserver
|
||||||
if(activeGameRooms.count(connection))
|
if(activeGameRooms.count(connection))
|
||||||
{
|
{
|
||||||
|
std::string roomName = activeGameRooms.at(connection).roomID;
|
||||||
|
logGlobal->info("%s: Received message of type %s", roomName, messageType);
|
||||||
|
|
||||||
if(messageType == "leaveGameRoom")
|
if(messageType == "leaveGameRoom")
|
||||||
return receiveLeaveGameRoom(connection, json);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logGlobal->info("(unauthorised): Received message of type %s", messageType);
|
||||||
|
|
||||||
// unauthorized connections - permit only login or register attempts
|
// unauthorized connections - permit only login or register attempts
|
||||||
if(messageType == "clientLogin")
|
if(messageType == "clientLogin")
|
||||||
return receiveClientLogin(connection, json);
|
return receiveClientLogin(connection, json);
|
||||||
@@ -300,7 +308,7 @@ void LobbyServer::onPacketReceived(const NetworkConnectionPtr & connection, cons
|
|||||||
// TODO: add logging of suspicious connections.
|
// TODO: add logging of suspicious connections.
|
||||||
networkServer->closeConnection(connection);
|
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)
|
void LobbyServer::receiveSendChatMessage(const NetworkConnectionPtr & connection, const JsonNode & json)
|
||||||
|
|||||||
Reference in New Issue
Block a user