From 2422287753d52ec6b0044be9b54c44ad742f7833 Mon Sep 17 00:00:00 2001 From: Salanto Date: Wed, 20 Jan 2021 14:49:07 +0100 Subject: [PATCH] Add sendServerMessageArea and sendServerBroadcast + Update some prior created commands to use them + Change style of global messages + Change style of need messages + Pretend to fix some formatting since I don't understand indentation --- include/aoclient.h | 2 ++ src/aoclient.cpp | 21 ++++++++++++++++++++- src/commands.cpp | 29 +++++++++++++++-------------- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/include/aoclient.h b/include/aoclient.h index 4fd9bac..d3f25dd 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -88,6 +88,8 @@ class AOClient : public QObject { void arup(ARUPType type, bool broadcast); void fullArup(); void sendServerMessage(QString message); + void sendServerMessageArea(QString message); + void sendServerBroadcast(QString message); bool checkAuth(unsigned long long acl_mask); // Packet headers diff --git a/src/aoclient.cpp b/src/aoclient.cpp index 1e10adc..abe7ccc 100644 --- a/src/aoclient.cpp +++ b/src/aoclient.cpp @@ -216,7 +216,26 @@ void AOClient::setHwid(QString p_hwid) void AOClient::sendServerMessage(QString message) { - sendPacket("CT", {"Server", message, "1"}); + QSettings config("config/config.ini", QSettings::IniFormat); + config.beginGroup("Options"); + QString hostname = config.value("hostname", "Server").toString(); + sendPacket("CT", {hostname, message, "1"}); +} + +void AOClient::sendServerMessageArea(QString message) +{ + QSettings config("config/config.ini", QSettings::IniFormat); + config.beginGroup("Options"); + QString hostname = config.value("hostname", "Server").toString(); + server->broadcast(AOPacket("CT", {hostname, message, "1"}), current_area); +} + +void AOClient::sendServerBroadcast(QString message) +{ + QSettings config("config/config.ini", QSettings::IniFormat); + config.beginGroup("Options"); + QString hostname = config.value("hostname", "Server").toString(); + server->broadcast(AOPacket("CT", {hostname, message, "1"})); } bool AOClient::checkAuth(unsigned long long acl_mask) diff --git a/src/commands.cpp b/src/commands.cpp index 7fec9e8..93c6eac 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -374,8 +374,9 @@ void AOClient::cmdPos(int argc, QStringList argv) void AOClient::cmdG(int argc, QStringList argv) { QString sender_name = ooc_name; + QString sender_area = server->area_names.value(current_area); QString sender_message = argv.join(" "); - server->broadcast(AOPacket("CT", {"[G]" + sender_name, sender_message+ "."})); + server->broadcast(AOPacket("CT", {"[" + sender_area + "]" + sender_name, sender_message})); return; } @@ -383,7 +384,7 @@ void AOClient::cmdNeed(int argc, QStringList argv) { QString sender_area = server->area_names.value(current_area); QString sender_message = argv.join(" "); - server->broadcast(AOPacket("CT", {"=== Advert ===","[" + sender_area + "] needs " + sender_message+ "."})); + sendServerBroadcast({"=== Advert ===\n[" + sender_area + "] needs " + sender_message+ "."}); } void AOClient::cmdFlip(int argc, QStringList argv) @@ -403,15 +404,15 @@ void AOClient::cmdRoll(int argc, QStringList argv) if (argc == 0) { QString dice_result = QString::number(AOClient::genRand(1, 6)); - server->broadcast(AOPacket("CT",{"Roll",sender_name + " rolled " + dice_result + " out of 6"}), current_area); + sendServerMessageArea(sender_name + " rolled " + dice_result + " out of 6"); } else if (argc == 1) { int amount_faces = argv[0].toInt(); if (1 <= amount_faces and amount_faces <= max_roll_faces) { - QString dice_result = QString::number(AOClient::genRand(1, amount_faces)); - server->broadcast(AOPacket("CT",{"Roll",sender_name + " rolled " + dice_result + " out of " + argv[0]}), current_area); + QString dice_result = QString::number(AOClient::genRand(1, amount_faces)); + sendServerMessageArea(sender_name + " rolled " + dice_result + " out of " + argv[0]); } else { @@ -434,10 +435,10 @@ void AOClient::cmdRoll(int argc, QStringList argv) } else { - dice_results = dice_results.append(dice_result + ","); + dice_results = dice_results.append(dice_result + ","); } } - server->broadcast(AOPacket("CT",{"Roll",sender_name + " rolled (" + dice_results + ") out of " + argv[0]}), current_area); + sendServerMessageArea(sender_name + " rolled (" + dice_results + ") out of " + argv[0]); } else { @@ -456,16 +457,16 @@ void AOClient::cmdRollP(int argc, QStringList argv) { QString dice_result = QString::number(AOClient::genRand(1, 6)); sendServerMessage(sender_name + " rolled " + dice_result + " out of 6"); - server->broadcast(AOPacket("CT",{"Roll",sender_name + " rolled in secret."}), current_area); + sendServerMessageArea((sender_name + " rolled in secret.")); } else if (argc == 1) { int amount_faces = argv[0].toInt(); if (1 <= amount_faces and amount_faces <= max_roll_faces) { - QString dice_result = QString::number(AOClient::genRand(1, amount_faces)); - sendServerMessage(sender_name + " rolled " + dice_result + " out of " + argv[0]); - server->broadcast(AOPacket("CT",{"Roll",sender_name + " rolled in secret."}), current_area); + QString dice_result = QString::number(AOClient::genRand(1, amount_faces)); + sendServerMessage(sender_name + " rolled " + dice_result + " out of " + argv[0]); + sendServerMessageArea((sender_name + " rolled in secret."));; } else { @@ -488,11 +489,11 @@ void AOClient::cmdRollP(int argc, QStringList argv) } else { - dice_results = dice_results.append(dice_result + ","); + dice_results = dice_results.append(dice_result + ","); } } - sendServerMessage(sender_name + " rolled " + dice_results + " out of " + argv[0]); - server->broadcast(AOPacket("CT",{"Roll",sender_name + " rolled in secret."}), current_area); + sendServerMessage(sender_name + " rolled " + dice_results + " out of " + argv[0]); + sendServerMessageArea((sender_name + " rolled in secret."));; } else {