From 11066acdb3e98d1ec2b5ec7e78cc105c489d94ca Mon Sep 17 00:00:00 2001 From: Salanto Date: Sun, 28 Feb 2021 00:45:54 +0100 Subject: [PATCH] Add method to configure the server name + Remove some redundant code to make use of this method --- include/server.h | 2 ++ src/aoclient.cpp | 15 +++------------ src/server.cpp | 8 ++++++++ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/server.h b/include/server.h index 4e7d823..d9597fb 100644 --- a/include/server.h +++ b/include/server.h @@ -49,6 +49,7 @@ class Server : public QObject { void updateCharsTaken(AreaData* area); void broadcast(AOPacket packet, int area_index); void broadcast(AOPacket packet); + QString getServerName(); QVector clients; @@ -59,6 +60,7 @@ class Server : public QObject { QStringList music_list; QStringList backgrounds; DBManager* db_manager; + QString server_name; signals: diff --git a/src/aoclient.cpp b/src/aoclient.cpp index abe7ccc..215d539 100644 --- a/src/aoclient.cpp +++ b/src/aoclient.cpp @@ -216,26 +216,17 @@ void AOClient::setHwid(QString p_hwid) void AOClient::sendServerMessage(QString message) { - QSettings config("config/config.ini", QSettings::IniFormat); - config.beginGroup("Options"); - QString hostname = config.value("hostname", "Server").toString(); - sendPacket("CT", {hostname, message, "1"}); + sendPacket("CT", {server->getServerName(), 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); + server->broadcast(AOPacket("CT", {server->getServerName(), 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"})); + server->broadcast(AOPacket("CT", {server->getServerName(), message, "1"})); } bool AOClient::checkAuth(unsigned long long acl_mask) diff --git a/src/server.cpp b/src/server.cpp index 690a4f2..d0a038b 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -147,6 +147,14 @@ void Server::broadcast(AOPacket packet) } } +QString Server::getServerName() +{ + QSettings settings("config/config.ini", QSettings::IniFormat); + settings.beginGroup("Options"); + QString server_name = settings.value("server_name", "Akashi").toString(); + return server_name; +} + AOClient* Server::getClient(QString ipid) { for (AOClient* client : clients) {