From d76301cfcdf0302e87b59c3cbfa63fdff6d582d7 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Tue, 6 Oct 2020 13:45:28 -0500 Subject: [PATCH] general cleanup, net debug switch --- akashi.pro | 3 +++ src/advertiser.cpp | 13 ++++++------- src/aoclient.cpp | 17 +++++++++-------- src/aopacket.cpp | 4 +++- src/config_manager.cpp | 1 - src/db_manager.cpp | 3 --- src/main.cpp | 5 ----- src/packets.cpp | 16 ++++++++-------- src/server.cpp | 9 +++------ 9 files changed, 32 insertions(+), 39 deletions(-) diff --git a/akashi.pro b/akashi.pro index 408a25e..365150c 100644 --- a/akashi.pro +++ b/akashi.pro @@ -23,6 +23,9 @@ MOC_DIR = $$PWD/build RC_ICONS = resource/icon/akashi.ico +# Enable this to print network messages tothe console +#DEFINES += NET_DEBUG + SOURCES += src/advertiser.cpp \ src/aoclient.cpp \ src/aopacket.cpp \ diff --git a/src/advertiser.cpp b/src/advertiser.cpp index 8fe4352..31d2860 100644 --- a/src/advertiser.cpp +++ b/src/advertiser.cpp @@ -45,13 +45,13 @@ void Advertiser::readData() { // The information coming back from the MS isn't very useful // However, it can be useful to see it when debugging - // TODO: master network debug switch - // qDebug() << "From MS:" << socket->readAll(); +#ifdef NET_DEBUG + qDebug() << "From MS:" << socket->readAll(); +#endif } void Advertiser::socketConnected() { - // TODO: fire a signal here, i18n qDebug("Connected to the master server"); QString concat_ports; if (ws_port == -1) @@ -66,15 +66,14 @@ void Advertiser::socketConnected() QByteArray data = ao_packet.toUtf8(); socket->write(data); - // TODO: master network debug switch - // should be a separate one for MS as well - // qDebug() << "To MS:" << data; +#ifdef NET_DEBUG + qDebug() << "To MS:" << data; +#endif socket->flush(); } void Advertiser::socketDisconnected() { - // TODO: fire a signal here, i18n qDebug("Connection to master server lost"); } diff --git a/src/aoclient.cpp b/src/aoclient.cpp index d9f9bf3..1e10adc 100644 --- a/src/aoclient.cpp +++ b/src/aoclient.cpp @@ -35,7 +35,6 @@ AOClient::AOClient(Server* p_server, QTcpSocket* p_socket, QObject* parent) void AOClient::clientData() { QString data = QString::fromUtf8(socket->readAll()); - // qDebug() << "From" << remote_ip << ":" << data; if (is_partial) { data = partial_packet + data; @@ -55,7 +54,9 @@ void AOClient::clientData() void AOClient::clientDisconnected() { - //qDebug() << remote_ip.toString() << "disconnected"; +#ifdef NET_DEBUG + qDebug() << remote_ip.toString() << "disconnected"; +#endif if (joined) { server->player_count--; server->areas[current_area]->player_count--; @@ -70,17 +71,20 @@ void AOClient::clientDisconnected() void AOClient::handlePacket(AOPacket packet) { +#ifdef NET_DEBUG qDebug() << "Received packet:" << packet.header << ":" << packet.contents << "args length:" << packet.contents.length(); +#endif AreaData* area = server->areas[current_area]; PacketInfo info = packets.value(packet.header, {false, 0, &AOClient::pktDefault}); if (!checkAuth(info.acl_mask)) { - qDebug() << "Unauthenticated client" << getIpid() << "attempted to use privileged packet" << packet.header; return; } if (packet.contents.length() < info.minArgs) { +#ifdef NET_DEBUG qDebug() << "Invalid packet args length. Minimum is" << info.minArgs << "but only" << packet.contents.length() << "were given."; +#endif return; } @@ -89,7 +93,6 @@ void AOClient::handlePacket(AOPacket packet) void AOClient::changeArea(int new_area) { - // TODO: function to send chat messages with hostname automatically if (current_area == new_area) { sendServerMessage("You are already in area " + server->area_names[current_area]); return; @@ -174,7 +177,9 @@ void AOClient::fullArup() { void AOClient::sendPacket(AOPacket packet) { +#ifdef NET_DEBUG qDebug() << "Sent packet:" << packet.header << ":" << packet.contents; +#endif socket->write(packet.toUtf8()); socket->flush(); } @@ -207,7 +212,6 @@ void AOClient::setHwid(QString p_hwid) hash.addData(concat_ip_id.toUtf8()); ipid = hash.result().toHex().right(8); // Use the last 8 characters (4 bytes) - qDebug() << "IP:" << remote_ip.toString() << "HDID:" << p_hwid << "IPID:" << ipid; } void AOClient::sendServerMessage(QString message) @@ -225,11 +229,8 @@ bool AOClient::checkAuth(unsigned long long acl_mask) QSettings settings("config/config.ini", QSettings::IniFormat); settings.beginGroup("Options"); QString auth_type = settings.value("auth", "simple").toString(); - qDebug() << "auth type" << auth_type; if (auth_type == "advanced") { unsigned long long user_acl = server->db_manager->getACL(moderator_name); - qDebug() << "checking with advanced auth"; - qDebug() << "got acl" << QString::number(user_acl, 16).toUpper() << "for user" << moderator_name; return (user_acl & acl_mask) != 0; } else if (auth_type == "simple") { diff --git a/src/aopacket.cpp b/src/aopacket.cpp index e3bb94b..2d16997 100644 --- a/src/aopacket.cpp +++ b/src/aopacket.cpp @@ -29,8 +29,10 @@ AOPacket::AOPacket(QString p_packet) if (p_packet.at(0) == '#') { // The header is encrypted with FantaCrypt // This should never happen with AO2 2.4.3 or newer - // TODO: implement fantacrypt? maybe? qDebug() << "FantaCrypt packet received"; + header = "Unknown"; + packet_contents.append("Unknown"); + return; } else { header = packet_contents[0]; diff --git a/src/config_manager.cpp b/src/config_manager.cpp index e240b51..e6cc088 100644 --- a/src/config_manager.cpp +++ b/src/config_manager.cpp @@ -108,7 +108,6 @@ bool ConfigManager::updateConfig(int current_version) return false; } else { - // TODO: send signal config is out of date, and is being updated // Update the config as needed using a switch. This is nice because we // can fall through as we go up the version ladder. switch (current_version) { diff --git a/src/db_manager.cpp b/src/db_manager.cpp index 97de549..f23f20e 100644 --- a/src/db_manager.cpp +++ b/src/db_manager.cpp @@ -112,7 +112,6 @@ bool DBManager::createUser(QString username, QString salt, QString password, uns query.addBindValue(acl); query.exec(); - qDebug() << "Created user" << username << "with password" << password << "and salted with value" << salt << ": stored as" << salted_password; return true; } @@ -150,8 +149,6 @@ bool DBManager::authenticate(QString username, QString password) return false; QString stored_pass = query_pass.value(0).toString(); - qDebug() << "Found DB entry Salt:" << salt << "Stored Password:" << stored_pass << "Calculated Password:" << salted_password; - return salted_password == stored_pass; } diff --git a/src/main.cpp b/src/main.cpp index 1ba06ec..630965b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,8 +39,6 @@ int main(int argc, char* argv[]) QCoreApplication::setApplicationVersion("0.0.1"); std::atexit(cleanup); - qDebug("Main application started"); - ConfigManager config_manager; if (config_manager.initConfig()) { // Config is sound, so proceed with starting the server @@ -56,7 +54,6 @@ int main(int argc, char* argv[]) else { if (settings.advertise_server) { - // TODO: send signal advertiser started advertiser = new Advertiser(settings.ms_ip, settings.port, settings.ws_port, settings.local_port, @@ -64,8 +61,6 @@ int main(int argc, char* argv[]) advertiser->contactMasterServer(); } - // TODO: start the server here - // TODO: send signal server starting. server = new Server(settings.port, settings.ws_port); server->start(); } diff --git a/src/packets.cpp b/src/packets.cpp index 0304902..a921ca7 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -19,8 +19,9 @@ void AOClient::pktDefault(AreaData* area, int argc, QStringList argv, AOPacket packet) { - qDebug() << "Unimplemented packet:" << packet.header; - qDebug() << packet.contents; +#ifdef NET_DEBUG + qDebug() << "Unimplemented packet:" << packet.header << packet.contents; +#endif } void AOClient::pktHardwareId(AreaData* area, int argc, QStringList argv, AOPacket packet) @@ -44,7 +45,6 @@ void AOClient::pktSoftwareId(AreaData* area, int argc, QStringList argv, AOPacke // Full feature list as of AO 2.8.5 // The only ones that are critical to ensuring the server works are // "noencryption" and "fastloading" - // TODO: make the rest of these user configurable QStringList feature_list = { "noencryption", "yellowtext", "prezoom", "flipping", "customobjections", "fastloading", @@ -58,8 +58,9 @@ void AOClient::pktSoftwareId(AreaData* area, int argc, QStringList argv, AOPacke void AOClient::pktBeginLoad(AreaData* area, int argc, QStringList argv, AOPacket packet) { - // TODO: add user configurable content - // For testing purposes, we will just send enough to get things working + // Evidence isn't loaded during this part anymore + // As a result, we can always send "0" for evidence length + // Client only cares about what it gets from LE sendPacket("SI", {QString::number(server->characters.length()), "0", QString::number(server->area_names.length() + server->music_list.length())}); } @@ -141,7 +142,6 @@ void AOClient::pktSelectChar(AreaData* area, int argc, QStringList argv, AOPacke void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket packet) { - // TODO: validate, validate, validate AOPacket validated_packet = validateIcPacket(packet); if (validated_packet.header == "INVALID") return; @@ -232,7 +232,9 @@ void AOClient::pktWebSocketIp(AreaData* area, int argc, QStringList argv, AOPack socket->close(); return; } +#ifdef NET_DEBUG qDebug() << "ws ip set to" << argv[0]; +#endif remote_ip = QHostAddress(argv[0]); } } @@ -497,7 +499,5 @@ AOPacket AOClient::validateIcPacket(AOPacket packet) args.append(incoming_args[25].toString()); } - qDebug() << args.length(); - return AOPacket("MS", args); } diff --git a/src/server.cpp b/src/server.cpp index 65a8dbc..d60230d 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -33,11 +33,9 @@ Server::Server(int p_port, int p_ws_port, QObject* parent) : QObject(parent) void Server::start() { if (!server->listen(QHostAddress::Any, port)) { - // TODO: signal server start failed qDebug() << "Server error:" << server->errorString(); } else { - // TODO: signal server start success qDebug() << "Server listening on" << port; } @@ -68,7 +66,6 @@ void Server::start() } bg_file.close(); - // TODO: add verification that this exists QSettings areas_ini("config/areas.ini", QSettings::IniFormat); area_names = areas_ini.childGroups(); for (int i = 0; i < area_names.length(); i++) { @@ -78,7 +75,6 @@ void Server::start() // TODO: more area config areas[i]->background = areas_ini.value("background", "gs4").toString(); areas_ini.endGroup(); - qDebug() << "Added area" << area_name; } } @@ -108,8 +104,9 @@ void Server::clientConnected() // tsuserver4. It should disable fantacrypt // completely in any client 2.4.3 or newer client->sendPacket(decryptor); - - //qDebug() << client->remote_ip.toString() << "connected"; +#ifdef NET_DEBUG + qDebug() << client->remote_ip.toString() << "connected"; +#endif } void Server::updateCharsTaken(AreaData* area)