mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Added basic logging
This commit is contained in:
parent
c9ebf32efd
commit
ad547fcae0
@ -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();
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user