general cleanup, net debug switch
This commit is contained in:
parent
e53fd2a02e
commit
d76301cfcd
@ -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 \
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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") {
|
||||
|
@ -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];
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user