general cleanup, net debug switch

This commit is contained in:
scatterflower 2020-10-06 13:45:28 -05:00
parent e53fd2a02e
commit d76301cfcd
9 changed files with 32 additions and 39 deletions

View File

@ -23,6 +23,9 @@ MOC_DIR = $$PWD/build
RC_ICONS = resource/icon/akashi.ico RC_ICONS = resource/icon/akashi.ico
# Enable this to print network messages tothe console
#DEFINES += NET_DEBUG
SOURCES += src/advertiser.cpp \ SOURCES += src/advertiser.cpp \
src/aoclient.cpp \ src/aoclient.cpp \
src/aopacket.cpp \ src/aopacket.cpp \

View File

@ -45,13 +45,13 @@ void Advertiser::readData()
{ {
// The information coming back from the MS isn't very useful // The information coming back from the MS isn't very useful
// However, it can be useful to see it when debugging // However, it can be useful to see it when debugging
// TODO: master network debug switch #ifdef NET_DEBUG
// qDebug() << "From MS:" << socket->readAll(); qDebug() << "From MS:" << socket->readAll();
#endif
} }
void Advertiser::socketConnected() void Advertiser::socketConnected()
{ {
// TODO: fire a signal here, i18n
qDebug("Connected to the master server"); qDebug("Connected to the master server");
QString concat_ports; QString concat_ports;
if (ws_port == -1) if (ws_port == -1)
@ -66,15 +66,14 @@ void Advertiser::socketConnected()
QByteArray data = ao_packet.toUtf8(); QByteArray data = ao_packet.toUtf8();
socket->write(data); socket->write(data);
// TODO: master network debug switch #ifdef NET_DEBUG
// should be a separate one for MS as well qDebug() << "To MS:" << data;
// qDebug() << "To MS:" << data; #endif
socket->flush(); socket->flush();
} }
void Advertiser::socketDisconnected() void Advertiser::socketDisconnected()
{ {
// TODO: fire a signal here, i18n
qDebug("Connection to master server lost"); qDebug("Connection to master server lost");
} }

View File

@ -35,7 +35,6 @@ AOClient::AOClient(Server* p_server, QTcpSocket* p_socket, QObject* parent)
void AOClient::clientData() void AOClient::clientData()
{ {
QString data = QString::fromUtf8(socket->readAll()); QString data = QString::fromUtf8(socket->readAll());
// qDebug() << "From" << remote_ip << ":" << data;
if (is_partial) { if (is_partial) {
data = partial_packet + data; data = partial_packet + data;
@ -55,7 +54,9 @@ void AOClient::clientData()
void AOClient::clientDisconnected() void AOClient::clientDisconnected()
{ {
//qDebug() << remote_ip.toString() << "disconnected"; #ifdef NET_DEBUG
qDebug() << remote_ip.toString() << "disconnected";
#endif
if (joined) { if (joined) {
server->player_count--; server->player_count--;
server->areas[current_area]->player_count--; server->areas[current_area]->player_count--;
@ -70,17 +71,20 @@ void AOClient::clientDisconnected()
void AOClient::handlePacket(AOPacket packet) void AOClient::handlePacket(AOPacket packet)
{ {
#ifdef NET_DEBUG
qDebug() << "Received packet:" << packet.header << ":" << packet.contents << "args length:" << packet.contents.length(); qDebug() << "Received packet:" << packet.header << ":" << packet.contents << "args length:" << packet.contents.length();
#endif
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
PacketInfo info = packets.value(packet.header, {false, 0, &AOClient::pktDefault}); PacketInfo info = packets.value(packet.header, {false, 0, &AOClient::pktDefault});
if (!checkAuth(info.acl_mask)) { if (!checkAuth(info.acl_mask)) {
qDebug() << "Unauthenticated client" << getIpid() << "attempted to use privileged packet" << packet.header;
return; return;
} }
if (packet.contents.length() < info.minArgs) { 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."; qDebug() << "Invalid packet args length. Minimum is" << info.minArgs << "but only" << packet.contents.length() << "were given.";
#endif
return; return;
} }
@ -89,7 +93,6 @@ void AOClient::handlePacket(AOPacket packet)
void AOClient::changeArea(int new_area) void AOClient::changeArea(int new_area)
{ {
// TODO: function to send chat messages with hostname automatically
if (current_area == new_area) { if (current_area == new_area) {
sendServerMessage("You are already in area " + server->area_names[current_area]); sendServerMessage("You are already in area " + server->area_names[current_area]);
return; return;
@ -174,7 +177,9 @@ void AOClient::fullArup() {
void AOClient::sendPacket(AOPacket packet) void AOClient::sendPacket(AOPacket packet)
{ {
#ifdef NET_DEBUG
qDebug() << "Sent packet:" << packet.header << ":" << packet.contents; qDebug() << "Sent packet:" << packet.header << ":" << packet.contents;
#endif
socket->write(packet.toUtf8()); socket->write(packet.toUtf8());
socket->flush(); socket->flush();
} }
@ -207,7 +212,6 @@ void AOClient::setHwid(QString p_hwid)
hash.addData(concat_ip_id.toUtf8()); hash.addData(concat_ip_id.toUtf8());
ipid = hash.result().toHex().right(8); // Use the last 8 characters (4 bytes) 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) void AOClient::sendServerMessage(QString message)
@ -225,11 +229,8 @@ bool AOClient::checkAuth(unsigned long long acl_mask)
QSettings settings("config/config.ini", QSettings::IniFormat); QSettings settings("config/config.ini", QSettings::IniFormat);
settings.beginGroup("Options"); settings.beginGroup("Options");
QString auth_type = settings.value("auth", "simple").toString(); QString auth_type = settings.value("auth", "simple").toString();
qDebug() << "auth type" << auth_type;
if (auth_type == "advanced") { if (auth_type == "advanced") {
unsigned long long user_acl = server->db_manager->getACL(moderator_name); 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; return (user_acl & acl_mask) != 0;
} }
else if (auth_type == "simple") { else if (auth_type == "simple") {

View File

@ -29,8 +29,10 @@ AOPacket::AOPacket(QString p_packet)
if (p_packet.at(0) == '#') { if (p_packet.at(0) == '#') {
// The header is encrypted with FantaCrypt // The header is encrypted with FantaCrypt
// This should never happen with AO2 2.4.3 or newer // This should never happen with AO2 2.4.3 or newer
// TODO: implement fantacrypt? maybe?
qDebug() << "FantaCrypt packet received"; qDebug() << "FantaCrypt packet received";
header = "Unknown";
packet_contents.append("Unknown");
return;
} }
else { else {
header = packet_contents[0]; header = packet_contents[0];

View File

@ -108,7 +108,6 @@ bool ConfigManager::updateConfig(int current_version)
return false; return false;
} }
else { 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 // Update the config as needed using a switch. This is nice because we
// can fall through as we go up the version ladder. // can fall through as we go up the version ladder.
switch (current_version) { switch (current_version) {

View File

@ -112,7 +112,6 @@ bool DBManager::createUser(QString username, QString salt, QString password, uns
query.addBindValue(acl); query.addBindValue(acl);
query.exec(); query.exec();
qDebug() << "Created user" << username << "with password" << password << "and salted with value" << salt << ": stored as" << salted_password;
return true; return true;
} }
@ -150,8 +149,6 @@ bool DBManager::authenticate(QString username, QString password)
return false; return false;
QString stored_pass = query_pass.value(0).toString(); 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; return salted_password == stored_pass;
} }

View File

@ -39,8 +39,6 @@ int main(int argc, char* argv[])
QCoreApplication::setApplicationVersion("0.0.1"); QCoreApplication::setApplicationVersion("0.0.1");
std::atexit(cleanup); std::atexit(cleanup);
qDebug("Main application started");
ConfigManager config_manager; ConfigManager config_manager;
if (config_manager.initConfig()) { if (config_manager.initConfig()) {
// Config is sound, so proceed with starting the server // Config is sound, so proceed with starting the server
@ -56,7 +54,6 @@ int main(int argc, char* argv[])
else { else {
if (settings.advertise_server) { if (settings.advertise_server) {
// TODO: send signal advertiser started
advertiser = advertiser =
new Advertiser(settings.ms_ip, settings.port, new Advertiser(settings.ms_ip, settings.port,
settings.ws_port, settings.local_port, settings.ws_port, settings.local_port,
@ -64,8 +61,6 @@ int main(int argc, char* argv[])
advertiser->contactMasterServer(); advertiser->contactMasterServer();
} }
// TODO: start the server here
// TODO: send signal server starting.
server = new Server(settings.port, settings.ws_port); server = new Server(settings.port, settings.ws_port);
server->start(); server->start();
} }

View File

@ -19,8 +19,9 @@
void AOClient::pktDefault(AreaData* area, int argc, QStringList argv, AOPacket packet) void AOClient::pktDefault(AreaData* area, int argc, QStringList argv, AOPacket packet)
{ {
qDebug() << "Unimplemented packet:" << packet.header; #ifdef NET_DEBUG
qDebug() << packet.contents; qDebug() << "Unimplemented packet:" << packet.header << packet.contents;
#endif
} }
void AOClient::pktHardwareId(AreaData* area, int argc, QStringList argv, AOPacket packet) 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 // Full feature list as of AO 2.8.5
// The only ones that are critical to ensuring the server works are // The only ones that are critical to ensuring the server works are
// "noencryption" and "fastloading" // "noencryption" and "fastloading"
// TODO: make the rest of these user configurable
QStringList feature_list = { QStringList feature_list = {
"noencryption", "yellowtext", "prezoom", "noencryption", "yellowtext", "prezoom",
"flipping", "customobjections", "fastloading", "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) void AOClient::pktBeginLoad(AreaData* area, int argc, QStringList argv, AOPacket packet)
{ {
// TODO: add user configurable content // Evidence isn't loaded during this part anymore
// For testing purposes, we will just send enough to get things working // 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())}); 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) void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket packet)
{ {
// TODO: validate, validate, validate
AOPacket validated_packet = validateIcPacket(packet); AOPacket validated_packet = validateIcPacket(packet);
if (validated_packet.header == "INVALID") if (validated_packet.header == "INVALID")
return; return;
@ -232,7 +232,9 @@ void AOClient::pktWebSocketIp(AreaData* area, int argc, QStringList argv, AOPack
socket->close(); socket->close();
return; return;
} }
#ifdef NET_DEBUG
qDebug() << "ws ip set to" << argv[0]; qDebug() << "ws ip set to" << argv[0];
#endif
remote_ip = QHostAddress(argv[0]); remote_ip = QHostAddress(argv[0]);
} }
} }
@ -497,7 +499,5 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
args.append(incoming_args[25].toString()); args.append(incoming_args[25].toString());
} }
qDebug() << args.length();
return AOPacket("MS", args); return AOPacket("MS", args);
} }

View File

@ -33,11 +33,9 @@ Server::Server(int p_port, int p_ws_port, QObject* parent) : QObject(parent)
void Server::start() void Server::start()
{ {
if (!server->listen(QHostAddress::Any, port)) { if (!server->listen(QHostAddress::Any, port)) {
// TODO: signal server start failed
qDebug() << "Server error:" << server->errorString(); qDebug() << "Server error:" << server->errorString();
} }
else { else {
// TODO: signal server start success
qDebug() << "Server listening on" << port; qDebug() << "Server listening on" << port;
} }
@ -68,7 +66,6 @@ void Server::start()
} }
bg_file.close(); bg_file.close();
// TODO: add verification that this exists
QSettings areas_ini("config/areas.ini", QSettings::IniFormat); QSettings areas_ini("config/areas.ini", QSettings::IniFormat);
area_names = areas_ini.childGroups(); area_names = areas_ini.childGroups();
for (int i = 0; i < area_names.length(); i++) { for (int i = 0; i < area_names.length(); i++) {
@ -78,7 +75,6 @@ void Server::start()
// TODO: more area config // TODO: more area config
areas[i]->background = areas_ini.value("background", "gs4").toString(); areas[i]->background = areas_ini.value("background", "gs4").toString();
areas_ini.endGroup(); areas_ini.endGroup();
qDebug() << "Added area" << area_name;
} }
} }
@ -108,8 +104,9 @@ void Server::clientConnected()
// tsuserver4. It should disable fantacrypt // tsuserver4. It should disable fantacrypt
// completely in any client 2.4.3 or newer // completely in any client 2.4.3 or newer
client->sendPacket(decryptor); client->sendPacket(decryptor);
#ifdef NET_DEBUG
//qDebug() << client->remote_ip.toString() << "connected"; qDebug() << client->remote_ip.toString() << "connected";
#endif
} }
void Server::updateCharsTaken(AreaData* area) void Server::updateCharsTaken(AreaData* area)