diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6ea55e5..81bcd7b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -45,7 +45,7 @@ jobs: - name: qmake and build run: | cd $GITHUB_WORKSPACE - qmake + qmake project-akashi.pro make mv bin/config_sample bin/config @@ -62,52 +62,50 @@ jobs: name: akashi-linux path: bin/ - coverage: - needs: build-linux - runs-on: ubuntu-latest + # coverage: + # runs-on: ubuntu-latest - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 + # steps: + # # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + # - uses: actions/checkout@v2 - - name: Install dependencies - uses: awalsh128/cache-apt-pkgs-action@latest - with: - packages: qt5-qmake libqt5websockets5-dev g++ make - version: 1.0 + # - name: Install dependencies + # uses: awalsh128/cache-apt-pkgs-action@latest + # with: + # packages: qt5-qmake libqt5websockets5-dev g++ make + # version: 1.0 - # Runs a set of commands using the runners shell - - name: qmake and build - run: | - cd $GITHUB_WORKSPACE - qmake CONFIG+=coverage - make + # # Runs a set of commands using the runners shell + # - name: qmake and build + # run: | + # cd $GITHUB_WORKSPACE + # qmake CONFIG+=coverage project-akashi.pro + # make - - name: Run tests - run: | - cd ${{github.workspace}}/bin_tests/ - for test in ./unittest_*; do - LD_LIBRARY_PATH=../bin:$LD_LIBRARY_PATH ./$test - done; + # - name: Run tests + # run: | + # cd ${{github.workspace}}/bin_tests/ + # for test in ./unittest_*; do + # LD_LIBRARY_PATH=../bin:$LD_LIBRARY_PATH ./$test + # done; - - name: Copy coverage files - run: | - cd ${{github.workspace}}/core - gcov *.o - cd .. - mkdir coverage - cp core/*.gcov coverage/ + # - name: Copy coverage files + # run: | + # mkdir coverage + # cd ${{github.workspace}} + # gcov *.o + # cp *.gcov ../coverage/ - - name: Codecov - uses: codecov/codecov-action@v3.1.0 - with: - files: coverage/* + # - name: Codecov + # uses: codecov/codecov-action@v3.1.0 + # with: + # files: coverage/* - - name: Upload coverage files - uses: actions/upload-artifact@v2 - with: - name: coverage statistics - path: coverage/ + # - name: Upload coverage files + # uses: actions/upload-artifact@v2 + # with: + # name: coverage statistics + # path: coverage/ build-windows: needs: formatting-check @@ -132,7 +130,7 @@ jobs: - name: Build run: | cd $Env:GITHUB_WORKSPACE - qmake "CONFIG += qtquickcompiler" akashi.pro + qmake "CONFIG += qtquickcompiler" project-akashi.pro nmake windeployqt bin\akashi.exe --release --no-opengl-sw mv bin\config_sample bin\config diff --git a/akashi.pro b/akashi.pro index 49f5a02..f72facb 100644 --- a/akashi.pro +++ b/akashi.pro @@ -1,13 +1,33 @@ -TEMPLATE = subdirs +QT += network websockets core sql -SUBDIRS += \ - core \ - akashi \ - tests +TEMPLATE = app -akashi.subdirs = akashi -core.subdirs = core -core.tests = tests +CONFIG += c++2a console -# How to make subdirs not suck. Simple, use depends. -akashi.depends = core +coverage { + LIBS += -lgcov +} + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +QMAKE_CXXFLAGS_WARN_OFF -= -Wunused-parameter + +DESTDIR = $$PWD/bin + +RC_ICONS = resource/icon/akashi.ico + +INCLUDEPATH += src + +SOURCES += \ + src/main.cpp + +LIBS += -L$$PWD/bin -lcore diff --git a/akashi/akashi.pro b/akashi/akashi.pro deleted file mode 100644 index 1d08e7b..0000000 --- a/akashi/akashi.pro +++ /dev/null @@ -1,38 +0,0 @@ -QT += network websockets core sql -QT -= gui -TEMPLATE = app - -unix:CONFIG += c++1z console -win32: CONFIG+=c++2a console - -coverage { - LIBS += -lgcov -} - -# The following define makes your compiler emit warnings if you use -# any Qt feature that has been marked deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -QMAKE_CXXFLAGS_WARN_OFF -= -Wunused-parameter - -DESTDIR = $$PWD/../bin -OBJECTS_DIR = $$PWD/../build -MOC_DIR = $$PWD/../build - -RC_ICONS = resource/icon/akashi.ico - -SOURCES += main.cpp - -# Include the akashi library -win32: LIBS += -L$$PWD/../bin/ -lcore -else:unix: LIBS += -L$$PWD/../bin/ -lcore - -INCLUDEPATH += $$PWD/../core -DEPENDPATH += $$PWD/../core diff --git a/core.pro b/core.pro new file mode 100644 index 0000000..127946e --- /dev/null +++ b/core.pro @@ -0,0 +1,126 @@ +QT += network websockets core sql + +TEMPLATE = lib + +# shared static is required by Windows. +CONFIG += shared static c++2a + +coverage { + QMAKE_CXXFLAGS += --coverage -g -Og # -fprofile-arcs -ftest-coverage + LIBS += -lgcov + CONFIG -= static +} + +# Needed so that Windows doesn't do `release/` and `debug/` subfolders +# in the output directory. +CONFIG -= \ + copy_dir_files \ + debug_and_release \ + debug_and_release_target + +DESTDIR = $$PWD/bin + +# You can make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +# Enable this to print network messages to the console +# DEFINES += NET_DEBUG + +INCLUDEPATH += src + +SOURCES += \ + src/acl_roles_handler.cpp \ + src/aoclient.cpp \ + src/network/aopacket.cpp \ + src/network/network_socket.cpp \ + src/area_data.cpp \ + src/command_extension.cpp \ + src/commands/area.cpp \ + src/commands/authentication.cpp \ + src/commands/casing.cpp \ + src/commands/command_helper.cpp \ + src/commands/messaging.cpp \ + src/commands/moderation.cpp \ + src/commands/music.cpp \ + src/commands/roleplay.cpp \ + src/config_manager.cpp \ + src/db_manager.cpp \ + src/discord.cpp \ + src/packets.cpp \ + src/playerstateobserver.cpp \ + src/server.cpp \ + src/testimony_recorder.cpp \ + src/advertiser.cpp \ + src/logger/u_logger.cpp \ + src/logger/writer_modcall.cpp \ + src/logger/writer_full.cpp \ + src/music_manager.cpp \ + src/packet/packet_factory.cpp \ + src/packet/packet_generic.cpp \ + src/packet/packet_hi.cpp \ + src/packet/packet_id.cpp \ + src/packet/packet_askchaa.cpp \ + src/packet/packet_casea.cpp \ + src/packet/packet_cc.cpp \ + src/packet/packet_ch.cpp \ + src/packet/packet_ct.cpp \ + src/packet/packet_de.cpp \ + src/packet/packet_ee.cpp \ + src/packet/packet_hp.cpp \ + src/packet/packet_mc.cpp \ + src/packet/packet_ms.cpp \ + src/packet/packet_pe.cpp \ + src/packet/packet_pl.cpp \ + src/packet/packet_pw.cpp \ + src/packet/packet_rc.cpp \ + src/packet/packet_rd.cpp \ + src/packet/packet_rm.cpp \ + src/packet/packet_rt.cpp \ + src/packet/packet_setcase.cpp \ + src/packet/packet_zz.cpp + +HEADERS += src/aoclient.h \ + src/acl_roles_handler.h \ + src/akashidefs.h \ + src/akashiutils.h \ + src/network/aopacket.h \ + src/network/network_socket.h \ + src/area_data.h \ + src/command_extension.h \ + src/config_manager.h \ + src/data_types.h \ + src/db_manager.h \ + src/discord.h \ + src/playerstateobserver.h \ + src/server.h \ + src/typedefs.h \ + src/advertiser.h \ + src/logger/u_logger.h \ + src/logger/writer_modcall.h \ + src/logger/writer_full.h \ + src/music_manager.h \ + src/packet/packet_factory.h \ + src/packet/packet_info.h \ + src/packet/packet_generic.h \ + src/packet/packet_hi.h \ + src/packet/packet_id.h \ + src/packet/packet_askchaa.h \ + src/packet/packet_casea.h \ + src/packet/packet_cc.h \ + src/packet/packet_ch.h \ + src/packet/packet_ct.h \ + src/packet/packet_de.h \ + src/packet/packet_ee.h \ + src/packet/packet_hp.h \ + src/packet/packet_mc.h \ + src/packet/packet_ms.h \ + src/packet/packet_pe.h \ + src/packet/packet_pl.h \ + src/packet/packet_pw.h \ + src/packet/packet_rc.h \ + src/packet/packet_rd.h \ + src/packet/packet_rm.h \ + src/packet/packet_rt.h \ + src/packet/packet_setcase.h \ + src/packet/packet_zz.h diff --git a/core/core.pro b/core/core.pro deleted file mode 100644 index aabe536..0000000 --- a/core/core.pro +++ /dev/null @@ -1,124 +0,0 @@ -QT += network websockets core sql -QT -= gui - -TEMPLATE = lib - -# Apparently, Windows needs a static config to make a dynamic library? -# Look, I dunno. -# Linux works just fine with `shared` only. -unix: CONFIG += shared static c++1z -win32: CONFIG+= shared static c++2a - -coverage { - QMAKE_CXXFLAGS += --coverage -g -Og # -fprofile-arcs -ftest-coverage - LIBS += -lgcov - CONFIG -= static -} - -# Needed so that Windows doesn't do `release/` and `debug/` subfolders -# in the output directory. -CONFIG -= \ - copy_dir_files \ - debug_and_release \ - debug_and_release_target - -DESTDIR = $$PWD/../bin - -# You can make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -# Enable this to print network messages to the console -# DEFINES += NET_DEBUG - -SOURCES += \ - src/acl_roles_handler.cpp \ - src/aoclient.cpp \ - src/network/aopacket.cpp \ - src/network/network_socket.cpp \ - src/area_data.cpp \ - src/command_extension.cpp \ - src/commands/area.cpp \ - src/commands/authentication.cpp \ - src/commands/casing.cpp \ - src/commands/command_helper.cpp \ - src/commands/messaging.cpp \ - src/commands/moderation.cpp \ - src/commands/music.cpp \ - src/commands/roleplay.cpp \ - src/config_manager.cpp \ - src/db_manager.cpp \ - src/discord.cpp \ - src/packets.cpp \ - src/server.cpp \ - src/testimony_recorder.cpp \ - src/advertiser.cpp \ - src/logger/u_logger.cpp \ - src/logger/writer_modcall.cpp \ - src/logger/writer_full.cpp \ - src/music_manager.cpp \ - src/packet/packet_factory.cpp \ - src/packet/packet_generic.cpp \ - src/packet/packet_hi.cpp \ - src/packet/packet_id.cpp \ - src/packet/packet_askchaa.cpp \ - src/packet/packet_casea.cpp \ - src/packet/packet_cc.cpp \ - src/packet/packet_ch.cpp \ - src/packet/packet_ct.cpp \ - src/packet/packet_de.cpp \ - src/packet/packet_ee.cpp \ - src/packet/packet_hp.cpp \ - src/packet/packet_mc.cpp \ - src/packet/packet_ms.cpp \ - src/packet/packet_pe.cpp \ - src/packet/packet_pw.cpp \ - src/packet/packet_rc.cpp \ - src/packet/packet_rd.cpp \ - src/packet/packet_rm.cpp \ - src/packet/packet_rt.cpp \ - src/packet/packet_setcase.cpp \ - src/packet/packet_zz.cpp - -HEADERS += include/aoclient.h \ - include/acl_roles_handler.h \ - include/akashidefs.h \ - include/akashiutils.h \ - include/network/aopacket.h \ - include/network/network_socket.h \ - include/area_data.h \ - include/command_extension.h \ - include/config_manager.h \ - include/data_types.h \ - include/db_manager.h \ - include/discord.h \ - include/server.h \ - include/typedefs.h \ - include/advertiser.h \ - include/logger/u_logger.h \ - include/logger/writer_modcall.h \ - include/logger/writer_full.h \ - include/music_manager.h \ - include/packet/packet_factory.h \ - include/packet/packet_info.h \ - include/packet/packet_generic.h \ - include/packet/packet_hi.h \ - include/packet/packet_id.h \ - include/packet/packet_askchaa.h \ - include/packet/packet_casea.h \ - include/packet/packet_cc.h \ - include/packet/packet_ch.h \ - include/packet/packet_ct.h \ - include/packet/packet_de.h \ - include/packet/packet_ee.h \ - include/packet/packet_hp.h \ - include/packet/packet_mc.h \ - include/packet/packet_ms.h \ - include/packet/packet_pe.h \ - include/packet/packet_pw.h \ - include/packet/packet_rc.h \ - include/packet/packet_rd.h \ - include/packet/packet_rm.h \ - include/packet/packet_rt.h \ - include/packet/packet_setcase.h \ - include/packet/packet_zz.h diff --git a/project-akashi.pro b/project-akashi.pro new file mode 100644 index 0000000..7023122 --- /dev/null +++ b/project-akashi.pro @@ -0,0 +1,12 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + core \ + akashi \ + tests + +core.file = core.pro +core.tests = tests +tests.depends = core +akashi.file = akashi.pro +akashi.depends = core diff --git a/akashi/resource/icon/16.png b/resource/icon/16.png similarity index 100% rename from akashi/resource/icon/16.png rename to resource/icon/16.png diff --git a/akashi/resource/icon/256.png b/resource/icon/256.png similarity index 100% rename from akashi/resource/icon/256.png rename to resource/icon/256.png diff --git a/akashi/resource/icon/32.png b/resource/icon/32.png similarity index 100% rename from akashi/resource/icon/32.png rename to resource/icon/32.png diff --git a/akashi/resource/icon/akashi.ico b/resource/icon/akashi.ico similarity index 100% rename from akashi/resource/icon/akashi.ico rename to resource/icon/akashi.ico diff --git a/core/src/acl_roles_handler.cpp b/src/acl_roles_handler.cpp similarity index 99% rename from core/src/acl_roles_handler.cpp rename to src/acl_roles_handler.cpp index 81540cc..e55ac3b 100644 --- a/core/src/acl_roles_handler.cpp +++ b/src/acl_roles_handler.cpp @@ -1,4 +1,4 @@ -#include "include/acl_roles_handler.h" +#include "acl_roles_handler.h" #include #include diff --git a/core/include/acl_roles_handler.h b/src/acl_roles_handler.h similarity index 100% rename from core/include/acl_roles_handler.h rename to src/acl_roles_handler.h diff --git a/core/src/advertiser.cpp b/src/advertiser.cpp similarity index 98% rename from core/src/advertiser.cpp rename to src/advertiser.cpp index 424f007..5a6f285 100644 --- a/core/src/advertiser.cpp +++ b/src/advertiser.cpp @@ -15,9 +15,9 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/advertiser.h" +#include "advertiser.h" -#include "include/config_manager.h" +#include "config_manager.h" Advertiser::Advertiser() { diff --git a/core/include/advertiser.h b/src/advertiser.h similarity index 100% rename from core/include/advertiser.h rename to src/advertiser.h diff --git a/core/include/akashidefs.h b/src/akashidefs.h similarity index 100% rename from core/include/akashidefs.h rename to src/akashidefs.h diff --git a/core/include/akashiutils.h b/src/akashiutils.h similarity index 100% rename from core/include/akashiutils.h rename to src/akashiutils.h diff --git a/core/src/aoclient.cpp b/src/aoclient.cpp similarity index 86% rename from core/src/aoclient.cpp rename to src/aoclient.cpp index d3c705c..73c2f48 100644 --- a/core/src/aoclient.cpp +++ b/src/aoclient.cpp @@ -15,14 +15,13 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/aoclient.h" +#include "aoclient.h" -#include "include/area_data.h" -#include "include/command_extension.h" -#include "include/config_manager.h" -#include "include/db_manager.h" -#include "include/packet/packet_factory.h" -#include "include/server.h" +#include "area_data.h" +#include "command_extension.h" +#include "config_manager.h" +#include "packet/packet_factory.h" +#include "server.h" const QMap AOClient::COMMANDS{ {"login", {{ACLRole::NONE}, 0, &AOClient::cmdLogin}}, @@ -156,25 +155,26 @@ void AOClient::clientDisconnected() qDebug() << m_remote_ip.toString() << "disconnected"; #endif if (m_joined) { - server->getAreaById(m_current_area)->clientLeftArea(server->getCharID(m_current_char), m_id); + server->getAreaById(areaId()) + ->removeClient(server->getCharID(character()), clientId()); arup(ARUPType::PLAYER_COUNT, true); } - if (m_current_char != "") { - server->updateCharsTaken(server->getAreaById(m_current_area)); + if (character() != "") { + server->updateCharsTaken(server->getAreaById(areaId())); } bool l_updateLocks = false; const QVector l_areas = server->getAreas(); for (AreaData *l_area : l_areas) { - l_updateLocks = l_updateLocks || l_area->removeOwner(m_id); + l_updateLocks = l_updateLocks || l_area->removeOwner(clientId()); } if (l_updateLocks) arup(ARUPType::LOCKED, true); arup(ARUPType::CM, true); - emit clientSuccessfullyDisconnected(m_id); + emit clientSuccessfullyDisconnected(clientId()); } void AOClient::handlePacket(AOPacket *packet) @@ -182,7 +182,7 @@ void AOClient::handlePacket(AOPacket *packet) #ifdef NET_DEBUG qDebug() << "Received packet:" << packet->getPacketInfo().header << ":" << packet->getContent() << "args length:" << packet->getContent().length(); #endif - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); if (packet->getContent().join("").size() > 16384) { return; @@ -211,28 +211,30 @@ void AOClient::handlePacket(AOPacket *packet) void AOClient::changeArea(int new_area) { - if (m_current_area == new_area) { - sendServerMessage("You are already in area " + server->getAreaName(m_current_area)); + if (areaId() == new_area) { + sendServerMessage("You are already in area " + server->getAreaName(areaId())); return; } - if (server->getAreaById(new_area)->lockStatus() == AreaData::LockStatus::LOCKED && !server->getAreaById(new_area)->invited().contains(m_id) && !checkPermission(ACLRole::BYPASS_LOCKS)) { + if (server->getAreaById(new_area)->lockStatus() == AreaData::LockStatus::LOCKED && !server->getAreaById(new_area)->invited().contains(clientId()) && !checkPermission(ACLRole::BYPASS_LOCKS)) { sendServerMessage("Area " + server->getAreaName(new_area) + " is locked."); return; } - if (m_current_char != "") { - server->getAreaById(m_current_area)->changeCharacter(server->getCharID(m_current_char), -1); - server->updateCharsTaken(server->getAreaById(m_current_area)); + if (character() != "") { + server->getAreaById(areaId()) + ->changeCharacter(server->getCharID(character()), -1); + server->updateCharsTaken(server->getAreaById(areaId())); } - server->getAreaById(m_current_area)->clientLeftArea(m_char_id, m_id); + server->getAreaById(areaId())->removeClient(m_char_id, clientId()); bool l_character_taken = false; - if (server->getAreaById(new_area)->charactersTaken().contains(server->getCharID(m_current_char))) { - m_current_char = ""; + if (server->getAreaById(new_area)->charactersTaken().contains( + server->getCharID(character()))) { + setCharacter(""); m_char_id = -1; l_character_taken = true; } - server->getAreaById(new_area)->clientJoinedArea(m_char_id, m_id); - m_current_area = new_area; + server->getAreaById(new_area)->addClient(m_char_id, clientId()); + setAreaId(new_area); arup(ARUPType::PLAYER_COUNT, true); sendEvidenceList(server->getAreaById(new_area)); sendPacket("HP", {"1", QString::number(server->getAreaById(new_area)->defHP())}); @@ -241,9 +243,9 @@ void AOClient::changeArea(int new_area) if (l_character_taken) { sendPacket("DONE"); } - const QList l_timers = server->getAreaById(m_current_area)->timers(); + const QList l_timers = server->getAreaById(areaId())->timers(); for (QTimer *l_timer : l_timers) { - int l_timer_id = server->getAreaById(m_current_area)->timers().indexOf(l_timer) + 1; + int l_timer_id = server->getAreaById(areaId())->timers().indexOf(l_timer) + 1; if (l_timer->isActive()) { sendPacket("TI", {QString::number(l_timer_id), "2"}); sendPacket("TI", {QString::number(l_timer_id), "0", QString::number(QTime(0, 0).msecsTo(QTime(0, 0).addMSecs(l_timer->remainingTime())))}); @@ -252,17 +254,17 @@ void AOClient::changeArea(int new_area) sendPacket("TI", {QString::number(l_timer_id), "3"}); } } - sendServerMessage("You moved to area " + server->getAreaName(m_current_area)); - if (server->getAreaById(m_current_area)->sendAreaMessageOnJoin()) - sendServerMessage(server->getAreaById(m_current_area)->areaMessage()); + sendServerMessage("You moved to area " + server->getAreaName(areaId())); + if (server->getAreaById(areaId())->sendAreaMessageOnJoin()) + sendServerMessage(server->getAreaById(areaId())->areaMessage()); - if (server->getAreaById(m_current_area)->lockStatus() == AreaData::LockStatus::SPECTATABLE) - sendServerMessage("Area " + server->getAreaName(m_current_area) + " is spectate-only; to chat IC you will need to be invited by the CM."); + if (server->getAreaById(areaId())->lockStatus() == AreaData::LockStatus::SPECTATABLE) + sendServerMessage("Area " + server->getAreaName(areaId()) + " is spectate-only; to chat IC you will need to be invited by the CM."); } bool AOClient::changeCharacter(int char_id) { - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); if (char_id >= server->getCharacterCount()) return false; @@ -271,20 +273,21 @@ bool AOClient::changeCharacter(int char_id) return false; } - bool l_successfulChange = l_area->changeCharacter(server->getCharID(m_current_char), char_id); + bool l_successfulChange = l_area->changeCharacter(server->getCharID(character()), + char_id); if (char_id < 0) { - m_current_char = ""; + setCharacter(""); m_char_id = char_id; setSpectator(true); } if (l_successfulChange == true) { QString l_char_selected = server->getCharacterById(char_id); - m_current_char = l_char_selected; + setCharacter(l_char_selected); m_pos = ""; server->updateCharsTaken(l_area); - sendPacket("PV", {QString::number(m_id), "CID", QString::number(char_id)}); + sendPacket("PV", {QString::number(clientId()), "CID", QString::number(char_id)}); return true; } return false; @@ -366,7 +369,7 @@ void AOClient::arup(ARUPType type, bool broadcast) const QList l_owner_ids = l_area->owners(); for (int l_owner_id : l_owner_ids) { AOClient *l_owner = server->getClientByID(l_owner_id); - l_area_owners.append("[" + QString::number(l_owner->m_id) + "] " + l_owner->m_current_char); + l_area_owners.append("[" + QString::number(l_owner->clientId()) + "] " + l_owner->character()); } l_arup_data.append(l_area_owners.join(", ")); } @@ -400,9 +403,6 @@ void AOClient::fullArup() void AOClient::sendPacket(AOPacket *packet) { -#ifdef NET_DEBUG - qDebug() << "Sent packet:" << packet->getPacketInfo().header << ":" << packet->getContent(); -#endif m_socket->write(packet); } @@ -438,7 +438,8 @@ void AOClient::sendServerMessage(QString message) void AOClient::sendServerMessageArea(QString message) { - server->broadcast(PacketFactory::createPacket("CT", {ConfigManager::serverName(), message, "1"}), m_current_area); + server->broadcast(PacketFactory::createPacket("CT", {ConfigManager::serverName(), message, "1"}), + areaId()); } void AOClient::sendServerBroadcast(QString message) @@ -452,7 +453,7 @@ bool AOClient::checkPermission(ACLRole::Permission f_permission) const return true; } - if ((f_permission == ACLRole::CM) && server->getAreaById(m_current_area)->owners().contains(m_id)) { + if ((f_permission == ACLRole::CM) && server->getAreaById(areaId())->owners().contains(clientId())) { return true; // I'm sorry for this hack. } @@ -490,6 +491,49 @@ bool AOClient::isAuthenticated() const Server *AOClient::getServer() { return server; } +int AOClient::clientId() const +{ + return m_id; +} + +QString AOClient::name() const { return m_ooc_name; } + +void AOClient::setName(const QString &f_name) +{ + m_ooc_name = f_name; + Q_EMIT nameChanged(m_ooc_name); +} + +int AOClient::areaId() const +{ + return m_current_area; +} + +void AOClient::setAreaId(const int f_area_id) +{ + m_current_area = f_area_id; + Q_EMIT areaIdChanged(m_current_area); +} + +QString AOClient::character() const +{ + return m_current_char; +} + +void AOClient::setCharacter(const QString &f_character) +{ + m_current_char = f_character; + Q_EMIT characterChanged(m_current_char); +} + +QString AOClient::characterName() const { return m_showname; } + +void AOClient::setCharacterName(const QString &f_showname) +{ + m_showname = f_showname; + Q_EMIT characterNameChanged(m_showname); +} + void AOClient::setSpectator(bool f_spectator) { m_is_spectator = f_spectator; @@ -507,17 +551,18 @@ void AOClient::onAfkTimeout() m_is_afk = true; } -AOClient::AOClient(Server *p_server, NetworkSocket *socket, QObject *parent, int user_id, MusicManager *p_manager) : +AOClient::AOClient( + Server *p_server, NetworkSocket *socket, QObject *parent, int user_id, MusicManager *p_manager) : QObject(parent), - m_id(user_id), m_remote_ip(socket->peerAddress()), m_password(""), m_joined(false), - m_current_area(0), - m_current_char(""), m_socket(socket), m_music_manager(p_manager), m_last_wtce_time(0), + m_id(user_id), + m_current_area(0), + m_current_char(""), server(p_server), is_partial(false) { diff --git a/core/include/aoclient.h b/src/aoclient.h similarity index 99% rename from core/include/aoclient.h rename to src/aoclient.h index e8763ef..258c26c 100644 --- a/core/include/aoclient.h +++ b/src/aoclient.h @@ -26,9 +26,9 @@ #include #include -#include "include/acl_roles_handler.h" -#include "include/network/aopacket.h" -#include "include/network/network_socket.h" +#include "acl_roles_handler.h" +#include "network/aopacket.h" +#include "network/network_socket.h" class AreaData; class DBManager; @@ -141,10 +141,19 @@ class AOClient : public QObject */ Server *getServer(); - /** - * @brief The user ID of the client. - */ - int m_id; + int clientId() const; + + QString name() const; + void setName(const QString &f_name); + + QString character() const; + void setCharacter(const QString &f_character); + + QString characterName() const; + void setCharacterName(const QString &f_showname); + + int areaId() const; + void setAreaId(const int f_area_id); /** * @brief The IP address of the client. @@ -167,16 +176,6 @@ class AOClient : public QObject */ bool m_joined; - /** - * @brief The ID of the area the client is currently in. - */ - int m_current_area; - - /** - * @brief The internal name of the character the client is currently using. - */ - QString m_current_char; - /** * @brief The internal name of the character the client is iniswapped to. * @@ -651,7 +650,27 @@ class AOClient : public QObject */ void joined(); + void nameChanged(const QString &); + void characterChanged(const QString &); + void characterNameChanged(const QString &); + void areaIdChanged(int); + private: + /** + * @brief The user ID of the client. + */ + int m_id; + + /** + * @brief The ID of the area the client is currently in. + */ + int m_current_area; + + /** + * @brief The internal name of the character the client is currently using. + */ + QString m_current_char; + /** * @brief A pointer to the Server, used for updating server variables that depend on the client (e.g. amount of players in an area). */ diff --git a/core/src/area_data.cpp b/src/area_data.cpp similarity index 98% rename from core/src/area_data.cpp rename to src/area_data.cpp index 3af70d3..5ed4885 100644 --- a/core/src/area_data.cpp +++ b/src/area_data.cpp @@ -18,10 +18,10 @@ #include -#include "include/area_data.h" -#include "include/config_manager.h" -#include "include/music_manager.h" -#include "include/packet/packet_factory.h" +#include "area_data.h" +#include "config_manager.h" +#include "music_manager.h" +#include "packet/packet_factory.h" AreaData::AreaData(QString p_name, int p_index, MusicManager *p_music_manager = nullptr) : m_index(p_index), @@ -89,7 +89,7 @@ const QMap AreaData::map_statuses = { {"gaming", AreaData::Status::GAMING}, }; -void AreaData::clientLeftArea(int f_charId, int f_userId) +void AreaData::removeClient(int f_charId, int f_userId) { --m_playerCount; @@ -99,7 +99,7 @@ void AreaData::clientLeftArea(int f_charId, int f_userId) m_joined_ids.removeAll(f_userId); } -void AreaData::clientJoinedArea(int f_charId, int f_userId) +void AreaData::addClient(int f_charId, int f_userId) { ++m_playerCount; diff --git a/core/include/area_data.h b/src/area_data.h similarity index 99% rename from core/include/area_data.h rename to src/area_data.h index 3632432..25419e0 100644 --- a/core/include/area_data.h +++ b/src/area_data.h @@ -26,7 +26,7 @@ #include #include -#include "include/network/aopacket.h" +#include "network/aopacket.h" class ConfigManager; class Logger; @@ -230,7 +230,7 @@ class AreaData : public QObject * @param f_userId The user ID of the client who left. The default value is '-1', This ID is technically * impossible. */ - void clientLeftArea(int f_charId = -1, int f_userId = -1); + void removeClient(int f_charId = -1, int f_userId = -1); /** * @brief A client in the area joined recently. @@ -243,7 +243,7 @@ class AreaData : public QObject * @param f_userId The user ID of the client who left. The default value is '-1', This ID is technically * impossible. */ - void clientJoinedArea(int f_charId = -1, int f_userId = -1); + void addClient(int f_charId = -1, int f_userId = -1); /** * @brief Returns a copy of the list of owners of this area. diff --git a/core/src/command_extension.cpp b/src/command_extension.cpp similarity index 98% rename from core/src/command_extension.cpp rename to src/command_extension.cpp index 53eaf8d..27e001a 100644 --- a/core/src/command_extension.cpp +++ b/src/command_extension.cpp @@ -1,9 +1,9 @@ -#include "include/command_extension.h" +#include "command_extension.h" #include #include -#include "include/akashidefs.h" +#include "akashidefs.h" CommandExtension::CommandExtension() {} diff --git a/core/include/command_extension.h b/src/command_extension.h similarity index 99% rename from core/include/command_extension.h rename to src/command_extension.h index c2647da..669388b 100644 --- a/core/include/command_extension.h +++ b/src/command_extension.h @@ -6,7 +6,7 @@ #include #include -#include "include/acl_roles_handler.h" +#include "acl_roles_handler.h" class CommandExtension { diff --git a/core/src/commands/area.cpp b/src/commands/area.cpp similarity index 81% rename from core/src/commands/area.cpp rename to src/commands/area.cpp index 51a790f..8e4b153 100644 --- a/core/src/commands/area.cpp +++ b/src/commands/area.cpp @@ -15,30 +15,30 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/aoclient.h" +#include "aoclient.h" -#include "include/area_data.h" -#include "include/config_manager.h" -#include "include/packet/packet_factory.h" -#include "include/server.h" +#include "area_data.h" +#include "config_manager.h" +#include "packet/packet_factory.h" +#include "server.h" // This file is for commands under the area category in aoclient.h // Be sure to register the command in the header before adding it here! void AOClient::cmdCM(int argc, QStringList argv) { - QString l_sender_name = m_ooc_name; - AreaData *l_area = server->getAreaById(m_current_area); + QString l_sender_name = name(); + AreaData *l_area = server->getAreaById(areaId()); if (l_area->isProtected()) { sendServerMessage("This area is protected, you may not become CM."); return; } else if (l_area->owners().isEmpty()) { // no one owns this area, and it's not protected - l_area->addOwner(m_id); + l_area->addOwner(clientId()); sendServerMessageArea(l_sender_name + " is now CM in this area."); arup(ARUPType::CM, true); } - else if (!l_area->owners().contains(m_id)) { // there is already a CM, and it isn't us + else if (!l_area->owners().contains(clientId())) { // there is already a CM, and it isn't us sendServerMessage("You cannot become a CM in this area."); } else if (argc == 1) { // we are CM, and we want to make ID argv[0] also CM @@ -52,12 +52,12 @@ void AOClient::cmdCM(int argc, QStringList argv) sendServerMessage("Unable to find client with ID " + argv[0] + "."); return; } - if (l_area->owners().contains(l_owner_candidate->m_id)) { + if (l_area->owners().contains(l_owner_candidate->clientId())) { sendServerMessage("User is already a CM in this area."); return; } - l_area->addOwner(l_owner_candidate->m_id); - sendServerMessageArea(l_owner_candidate->m_ooc_name + " is now CM in this area."); + l_area->addOwner(l_owner_candidate->clientId()); + sendServerMessageArea(l_owner_candidate->name() + " is now CM in this area."); arup(ARUPType::CM, true); } else { @@ -67,7 +67,7 @@ void AOClient::cmdCM(int argc, QStringList argv) void AOClient::cmdUnCM(int argc, QStringList argv) { - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); int l_uid; if (l_area->owners().isEmpty()) { @@ -75,7 +75,7 @@ void AOClient::cmdUnCM(int argc, QStringList argv) return; } else if (argc == 0) { - l_uid = m_id; + l_uid = clientId(); sendServerMessage("You are no longer CM in this area."); } else if (checkPermission(ACLRole::UNCM) && argc >= 1) { @@ -94,7 +94,7 @@ void AOClient::cmdUnCM(int argc, QStringList argv) sendServerMessage("No client with that ID found."); return; } - sendServerMessage(l_target->m_ooc_name + " was successfully unCMed."); + sendServerMessage(l_target->name() + " was successfully unCMed."); l_target->sendServerMessage("You have been unCMed by a moderator."); } else { @@ -113,7 +113,7 @@ void AOClient::cmdInvite(int argc, QStringList argv) { Q_UNUSED(argc); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); bool ok; int l_invited_id = argv[0].toInt(&ok); if (!ok) { @@ -138,7 +138,7 @@ void AOClient::cmdUnInvite(int argc, QStringList argv) { Q_UNUSED(argc); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); bool ok; int l_uninvited_id = argv[0].toInt(&ok); if (!ok) { @@ -168,7 +168,7 @@ void AOClient::cmdLock(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *area = server->getAreaById(m_current_area); + AreaData *area = server->getAreaById(areaId()); if (area->lockStatus() == AreaData::LockStatus::LOCKED) { sendServerMessage("This area is already locked."); return; @@ -177,8 +177,8 @@ void AOClient::cmdLock(int argc, QStringList argv) area->lock(); const QVector l_clients = server->getClients(); for (AOClient *l_client : l_clients) { - if (l_client->m_current_area == m_current_area && l_client->hasJoined()) { - area->invite(l_client->m_id); + if (l_client->areaId() == areaId() && l_client->hasJoined()) { + area->invite(l_client->clientId()); } } arup(ARUPType::LOCKED, true); @@ -189,7 +189,7 @@ void AOClient::cmdSpectatable(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); if (l_area->lockStatus() == AreaData::LockStatus::SPECTATABLE) { sendServerMessage("This area is already in spectate mode."); return; @@ -198,8 +198,8 @@ void AOClient::cmdSpectatable(int argc, QStringList argv) l_area->spectatable(); const QVector l_clients = server->getClients(); for (AOClient *l_client : l_clients) { - if (l_client->m_current_area == m_current_area && l_client->hasJoined()) { - l_area->invite(l_client->m_id); + if (l_client->areaId() == areaId() && l_client->hasJoined()) { + l_area->invite(l_client->clientId()); } } arup(ARUPType::LOCKED, true); @@ -210,7 +210,7 @@ void AOClient::cmdUnLock(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); if (l_area->lockStatus() == AreaData::LockStatus::FREE) { sendServerMessage("This area is not locked."); return; @@ -241,7 +241,7 @@ void AOClient::cmdGetArea(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - QStringList l_entries = buildAreaList(m_current_area); + QStringList l_entries = buildAreaList(areaId()); sendServerMessage(l_entries.join("\n")); } @@ -262,7 +262,7 @@ void AOClient::cmdAreaKick(int argc, QStringList argv) { Q_UNUSED(argc); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); bool ok; int l_idx = argv[0].toInt(&ok); @@ -270,7 +270,7 @@ void AOClient::cmdAreaKick(int argc, QStringList argv) sendServerMessage("That does not look like a valid ID."); return; } - if (server->getAreaById(m_current_area)->owners().contains(l_idx)) { + if (server->getAreaById(areaId())->owners().contains(l_idx)) { sendServerMessage("You cannot kick another CM!"); return; } @@ -279,12 +279,12 @@ void AOClient::cmdAreaKick(int argc, QStringList argv) sendServerMessage("No client with that ID found."); return; } - else if (l_client_to_kick->m_current_area != m_current_area) { + else if (l_client_to_kick->areaId() != areaId()) { sendServerMessage("That client is not in this area."); return; } l_client_to_kick->changeArea(0); - l_area->uninvite(l_client_to_kick->m_id); + l_area->uninvite(l_client_to_kick->clientId()); sendServerMessage("Client " + argv[0] + " kicked back to area 0."); } @@ -294,19 +294,19 @@ void AOClient::cmdSetBackground(int argc, QStringList argv) Q_UNUSED(argc); QString f_background = argv.join(" "); - AreaData *area = server->getAreaById(m_current_area); + AreaData *area = server->getAreaById(areaId()); if (m_authenticated || !area->bgLocked()) { if (server->getBackgrounds().contains(f_background, Qt::CaseInsensitive) || area->ignoreBgList() == true) { area->setBackground(f_background); - server->broadcast(PacketFactory::createPacket("BN", {f_background}), m_current_area); + server->broadcast(PacketFactory::createPacket("BN", {f_background}), areaId()); QString ambience_name = ConfigManager::ambience()->value(f_background + "/ambience").toString(); if (ambience_name != "") { - server->broadcast(PacketFactory::createPacket("MC", {ambience_name, "-1", m_showname, "1", "1"}), m_current_area); + server->broadcast(PacketFactory::createPacket("MC", {ambience_name, "-1", characterName(), "1", "1"}), areaId()); } else { - server->broadcast(PacketFactory::createPacket("MC", {"~stop.mp3", "-1", m_showname, "1", "1"}), m_current_area); + server->broadcast(PacketFactory::createPacket("MC", {"~stop.mp3", "-1", characterName(), "1", "1"}), areaId()); } - sendServerMessageArea(m_current_char + " changed the background to " + f_background); + sendServerMessageArea(character() + " changed the background to " + f_background); } else { sendServerMessage("Invalid background name."); @@ -322,13 +322,13 @@ void AOClient::cmdBgLock(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); if (l_area->bgLocked() == false) { l_area->toggleBgLock(); }; - server->broadcast(PacketFactory::createPacket("CT", {ConfigManager::serverName(), m_current_char + " locked the background.", "1"}), m_current_area); + server->broadcast(PacketFactory::createPacket("CT", {ConfigManager::serverName(), character() + " locked the background.", "1"}), areaId()); } void AOClient::cmdBgUnlock(int argc, QStringList argv) @@ -336,25 +336,25 @@ void AOClient::cmdBgUnlock(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); if (l_area->bgLocked() == true) { l_area->toggleBgLock(); }; - server->broadcast(PacketFactory::createPacket("CT", {ConfigManager::serverName(), m_current_char + " unlocked the background.", "1"}), m_current_area); + server->broadcast(PacketFactory::createPacket("CT", {ConfigManager::serverName(), character() + " unlocked the background.", "1"}), areaId()); } void AOClient::cmdStatus(int argc, QStringList argv) { Q_UNUSED(argc); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); QString l_arg = argv[0].toLower(); if (l_area->changeStatus(l_arg)) { arup(ARUPType::STATUS, true); - server->broadcast(PacketFactory::createPacket("CT", {ConfigManager::serverName(), m_current_char + " changed status to " + l_arg.toUpper(), "1"}), m_current_area); + server->broadcast(PacketFactory::createPacket("CT", {ConfigManager::serverName(), character() + " changed status to " + l_arg.toUpper(), "1"}), areaId()); } else { const QStringList keys = AreaData::map_statuses.keys(); @@ -367,7 +367,7 @@ void AOClient::cmdJudgeLog(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); if (l_area->judgelog().isEmpty()) { sendServerMessage("There have been no judge actions in this area."); return; @@ -388,7 +388,7 @@ void AOClient::cmdIgnoreBgList(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); l_area->toggleIgnoreBgList(); QString l_state = l_area->ignoreBgList() ? "ignored." : "enforced."; sendServerMessage("BG list in this area is now " + l_state); @@ -396,7 +396,7 @@ void AOClient::cmdIgnoreBgList(int argc, QStringList argv) void AOClient::cmdAreaMessage(int argc, QStringList argv) { - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); if (argc == 0) { sendServerMessage(l_area->areaMessage()); return; @@ -413,7 +413,7 @@ void AOClient::cmdToggleAreaMessageOnJoin(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); l_area->toggleAreaMessageJoin(); QString l_state = l_area->sendAreaMessageOnJoin() ? "enabled." : "disabled."; sendServerMessage("Sending message on area join is now " + l_state); @@ -424,7 +424,7 @@ void AOClient::cmdToggleWtce(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); l_area->toggleWtceAllowed(); QString l_state = l_area->isWtceAllowed() ? "enabled." : "disabled."; sendServerMessage("Using testimony animations is now " + l_state); @@ -435,7 +435,7 @@ void AOClient::cmdToggleShouts(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); l_area->toggleShoutAllowed(); QString l_state = l_area->isShoutAllowed() ? "enabled." : "disabled."; sendServerMessage("Using shouts is now " + l_state); @@ -446,7 +446,7 @@ void AOClient::cmdClearAreaMessage(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); l_area->clearAreaMessage(); if (l_area->sendAreaMessageOnJoin()) // Turn off the automatic sending. cmdToggleAreaMessageOnJoin(0, QStringList{}); // Dummy values. diff --git a/core/src/commands/authentication.cpp b/src/commands/authentication.cpp similarity index 98% rename from core/src/commands/authentication.cpp rename to src/commands/authentication.cpp index e1f2ae5..39a04c8 100644 --- a/core/src/commands/authentication.cpp +++ b/src/commands/authentication.cpp @@ -15,12 +15,12 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/aoclient.h" +#include "aoclient.h" -#include "include/config_manager.h" -#include "include/crypto_helper.h" -#include "include/db_manager.h" -#include "include/server.h" +#include "config_manager.h" +#include "crypto_helper.h" +#include "db_manager.h" +#include "server.h" // This file is for commands under the authentication category in aoclient.h // Be sure to register the command in the header before adding it here! diff --git a/core/src/commands/casing.cpp b/src/commands/casing.cpp similarity index 88% rename from core/src/commands/casing.cpp rename to src/commands/casing.cpp index 00f151d..982d399 100644 --- a/core/src/commands/casing.cpp +++ b/src/commands/casing.cpp @@ -15,20 +15,20 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/aoclient.h" +#include "aoclient.h" -#include "include/area_data.h" -#include "include/config_manager.h" -#include "include/packet/packet_factory.h" -#include "include/server.h" +#include "area_data.h" +#include "config_manager.h" +#include "packet/packet_factory.h" +#include "server.h" // This file is for commands under the casing category in aoclient.h // Be sure to register the command in the header before adding it here! void AOClient::cmdDoc(int argc, QStringList argv) { - QString l_sender_name = m_ooc_name; - AreaData *l_area = server->getAreaById(m_current_area); + QString l_sender_name = name(); + AreaData *l_area = server->getAreaById(areaId()); if (argc == 0) { sendServerMessage("Document: " + l_area->document()); } @@ -43,8 +43,8 @@ void AOClient::cmdClearDoc(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - QString l_sender_name = m_ooc_name; - AreaData *l_area = server->getAreaById(m_current_area); + QString l_sender_name = name(); + AreaData *l_area = server->getAreaById(areaId()); l_area->changeDoc("No document."); sendServerMessageArea(l_sender_name + " cleared the document."); } @@ -53,7 +53,7 @@ void AOClient::cmdEvidenceMod(int argc, QStringList argv) { Q_UNUSED(argc); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); argv[0] = argv[0].toLower(); if (argv[0] == "cm") l_area->setEviMod(AreaData::EvidenceMod::CM); @@ -77,7 +77,7 @@ void AOClient::cmdEvidence_Swap(int argc, QStringList argv) { Q_UNUSED(argc); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); int l_ev_size = l_area->evidence().size() - 1; if (l_ev_size < 0) { @@ -111,7 +111,7 @@ void AOClient::cmdTestify(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); if (l_area->testimonyRecording() == AreaData::TestimonyRecording::RECORDING) { sendServerMessage("Testimony recording is already in progress. Please stop it before starting a new one."); } @@ -127,11 +127,11 @@ void AOClient::cmdExamine(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); if (l_area->testimony().size() - 1 > 0) { l_area->restartTestimony(); - server->broadcast(PacketFactory::createPacket("RT", {"testimony2"}), m_current_area); - server->broadcast(PacketFactory::createPacket("MS", {l_area->testimony()[0]}), m_current_area); + server->broadcast(PacketFactory::createPacket("RT", {"testimony2"}), areaId()); + server->broadcast(PacketFactory::createPacket("MS", {l_area->testimony()[0]}), areaId()); return; } if (l_area->testimonyRecording() == AreaData::TestimonyRecording::PLAYBACK) @@ -145,7 +145,7 @@ void AOClient::cmdTestimony(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); if (l_area->testimony().size() - 1 < 1) { sendServerMessage("Unable to display empty testimony."); return; @@ -165,7 +165,7 @@ void AOClient::cmdDeleteStatement(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); int l_c_statement = l_area->statement(); if (l_area->testimony().size() - 1 == 0) { sendServerMessage("Unable to delete statement. No statements saved in this area."); @@ -181,7 +181,7 @@ void AOClient::cmdUpdateStatement(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - server->getAreaById(m_current_area)->setTestimonyRecording(AreaData::TestimonyRecording::UPDATE); + server->getAreaById(areaId())->setTestimonyRecording(AreaData::TestimonyRecording::UPDATE); sendServerMessage("The next IC-Message will replace the last displayed replay message."); } @@ -190,9 +190,9 @@ void AOClient::cmdPauseTestimony(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); l_area->setTestimonyRecording(AreaData::TestimonyRecording::STOPPED); - server->broadcast(PacketFactory::createPacket("RT", {"testimony1", "1"}), m_current_area); + server->broadcast(PacketFactory::createPacket("RT", {"testimony1", "1"}), areaId()); sendServerMessage("Testimony has been stopped."); } @@ -201,8 +201,8 @@ void AOClient::cmdAddStatement(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - if (server->getAreaById(m_current_area)->statement() < ConfigManager::maxStatements()) { - server->getAreaById(m_current_area)->setTestimonyRecording(AreaData::TestimonyRecording::ADD); + if (server->getAreaById(areaId())->statement() < ConfigManager::maxStatements()) { + server->getAreaById(areaId())->setTestimonyRecording(AreaData::TestimonyRecording::ADD); sendServerMessage("The next IC-Message will be inserted into the testimony."); } else @@ -221,7 +221,7 @@ void AOClient::cmdSaveTestimony(int argc, QStringList argv) l_permission_found = true; if (l_permission_found) { - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); if (l_area->testimony().size() - 1 <= 0) { sendServerMessage("Can't save an empty testimony."); return; @@ -259,7 +259,7 @@ void AOClient::cmdLoadTestimony(int argc, QStringList argv) { Q_UNUSED(argc); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); QDir l_dir_testimony("storage/testimony"); if (!l_dir_testimony.exists()) { sendServerMessage("Unable to load testimonies. Testimony storage not found."); diff --git a/core/src/commands/command_helper.cpp b/src/commands/command_helper.cpp similarity index 90% rename from core/src/commands/command_helper.cpp rename to src/commands/command_helper.cpp index b985591..13715ed 100644 --- a/core/src/commands/command_helper.cpp +++ b/src/commands/command_helper.cpp @@ -15,12 +15,12 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/aoclient.h" +#include "aoclient.h" -#include "include/area_data.h" -#include "include/config_manager.h" -#include "include/packet/packet_factory.h" -#include "include/server.h" +#include "area_data.h" +#include "config_manager.h" +#include "packet/packet_factory.h" +#include "server.h" // This file is for functions used by various commands, defined in the command helper function category in aoclient.h // Be sure to register the command in the header before adding it here! @@ -54,16 +54,16 @@ QStringList AOClient::buildAreaList(int area_idx) entries.append("[" + QString::number(area->playerCount()) + " users][" + QVariant::fromValue(area->status()).toString().replace("_", "-") + "]"); const QVector l_clients = server->getClients(); for (AOClient *l_client : l_clients) { - if (l_client->m_current_area == area_idx && l_client->hasJoined()) { - QString char_entry = "[" + QString::number(l_client->m_id) + "] " + l_client->m_current_char; - if (l_client->m_current_char == "") + if (l_client->areaId() == area_idx && l_client->hasJoined()) { + QString char_entry = "[" + QString::number(l_client->clientId()) + "] " + l_client->character(); + if (l_client->character() == "") char_entry += "Spectator"; - if (l_client->m_showname != "") - char_entry += " (" + l_client->m_showname + ")"; - if (area->owners().contains(l_client->m_id)) + if (l_client->characterName() != "") + char_entry += " (" + l_client->characterName() + ")"; + if (area->owners().contains(l_client->clientId())) char_entry.insert(0, "[CM] "); if (m_authenticated) - char_entry += " (" + l_client->getIpid() + "): " + l_client->m_ooc_name; + char_entry += " (" + l_client->getIpid() + "): " + l_client->name(); if (l_client->m_is_afk) char_entry += " [AFK]"; entries.append(char_entry); @@ -103,9 +103,9 @@ void AOClient::diceThrower(int sides, int dice, bool p_roll, int roll_modifier) return; } if (roll_modifier) - sendServerMessageArea(m_ooc_name + " rolled a " + QString::number(dice) + "d" + QString::number(sides) + "+" + QString::number(roll_modifier) + ". Results: " + total_results); + sendServerMessageArea(name() + " rolled a " + QString::number(dice) + "d" + QString::number(sides) + "+" + QString::number(roll_modifier) + ". Results: " + total_results); else - sendServerMessageArea(m_ooc_name + " rolled a " + QString::number(dice) + "d" + QString::number(sides) + ". Results: " + total_results); + sendServerMessageArea(name() + " rolled a " + QString::number(dice) + "d" + QString::number(sides) + ". Results: " + total_results); } QString AOClient::getAreaTimer(int area_idx, int timer_idx) @@ -232,5 +232,5 @@ void AOClient::sendNotice(QString f_notice, bool f_global) if (f_global) server->broadcast(l_packet); else - server->broadcast(l_packet, m_current_area); + server->broadcast(l_packet, areaId()); } diff --git a/core/src/commands/messaging.cpp b/src/commands/messaging.cpp similarity index 92% rename from core/src/commands/messaging.cpp rename to src/commands/messaging.cpp index bfb351a..d53153c 100644 --- a/core/src/commands/messaging.cpp +++ b/src/commands/messaging.cpp @@ -15,11 +15,11 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/aoclient.h" +#include "aoclient.h" -#include "include/area_data.h" -#include "include/packet/packet_factory.h" -#include "include/server.h" +#include "area_data.h" +#include "packet/packet_factory.h" +#include "server.h" // This file is for commands under the messaging category in aoclient.h // Be sure to register the command in the header before adding it here! @@ -29,7 +29,7 @@ void AOClient::cmdPos(int argc, QStringList argv) Q_UNUSED(argc); changePosition(argv[0]); - updateEvidenceList(server->getAreaById(m_current_area)); + updateEvidenceList(server->getAreaById(areaId())); } void AOClient::cmdForcePos(int argc, QStringList argv) @@ -57,7 +57,7 @@ void AOClient::cmdForcePos(int argc, QStringList argv) else if (argv[1] == "*") { // force all clients in the area const QVector l_clients = server->getClients(); for (AOClient *l_client : l_clients) { - if (l_client->m_current_area == m_current_area) + if (l_client->areaId() == areaId()) l_targets.append(l_client); } } @@ -73,8 +73,8 @@ void AOClient::cmdG(int argc, QStringList argv) { Q_UNUSED(argc); - QString l_sender_name = m_ooc_name; - QString l_sender_area = server->getAreaName(m_current_area); + QString l_sender_name = name(); + QString l_sender_area = server->getAreaName(areaId()); QString l_sender_message = argv.join(" "); // Better readability thanks to AwesomeAim. AOPacket *l_mod_packet = PacketFactory::createPacket("CT", {"[G][" + m_ipid + "][" + l_sender_area + "]" + l_sender_name, l_sender_message}); @@ -87,7 +87,7 @@ void AOClient::cmdNeed(int argc, QStringList argv) { Q_UNUSED(argc); - QString l_sender_area = server->getAreaName(m_current_area); + QString l_sender_area = server->getAreaName(areaId()); QString l_sender_message = argv.join(" "); server->broadcast(PacketFactory::createPacket("CT", {"=== Advert ===\n[" + l_sender_area + "] needs " + l_sender_message + "."}), Server::TARGET_TYPE::ADVERT); } @@ -114,7 +114,7 @@ void AOClient::cmdRandomChar(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); int l_selected_char_id; bool l_taken = true; while (l_taken) { @@ -158,7 +158,7 @@ void AOClient::cmdPM(int argc, QStringList argv) return; } QString l_message = argv.join(" "); //...which means it will not end up as part of the message - l_target_client->sendServerMessage("Message from " + m_ooc_name + " (" + QString::number(m_id) + "): " + l_message); + l_target_client->sendServerMessage("Message from " + name() + " (" + QString::number(clientId()) + "): " + l_message); sendServerMessage("PM sent to " + QString::number(l_target_id) + ". Message: " + l_message); } @@ -173,7 +173,7 @@ void AOClient::cmdM(int argc, QStringList argv) { Q_UNUSED(argc); - QString l_sender_name = m_ooc_name; + QString l_sender_name = name(); QString l_sender_message = argv.join(" "); server->broadcast(PacketFactory::createPacket("CT", {"[M]" + l_sender_name, l_sender_message}), Server::TARGET_TYPE::MODCHAT); } @@ -182,8 +182,8 @@ void AOClient::cmdGM(int argc, QStringList argv) { Q_UNUSED(argc); - QString l_sender_name = m_ooc_name; - QString l_sender_area = server->getAreaName(m_current_area); + QString l_sender_name = name(); + QString l_sender_area = server->getAreaName(areaId()); QString l_sender_message = argv.join(" "); server->broadcast(PacketFactory::createPacket("CT", {"[G][" + l_sender_area + "]" + "[" + l_sender_name + "][M]", l_sender_message}), Server::TARGET_TYPE::MODCHAT); } @@ -192,9 +192,9 @@ void AOClient::cmdLM(int argc, QStringList argv) { Q_UNUSED(argc); - QString l_sender_name = m_ooc_name; + QString l_sender_name = name(); QString l_sender_message = argv.join(" "); - server->broadcast(PacketFactory::createPacket("CT", {"[" + l_sender_name + "][M]", l_sender_message}), m_current_area); + server->broadcast(PacketFactory::createPacket("CT", {"[" + l_sender_name + "][M]", l_sender_message}), areaId()); } void AOClient::cmdGimp(int argc, QStringList argv) @@ -410,7 +410,7 @@ void AOClient::cmdCharCurse(int argc, QStringList argv) } if (argc == 1) { - l_target->m_charcurse_list.append(server->getCharID(l_target->m_current_char)); + l_target->m_charcurse_list.append(server->getCharID(l_target->character())); } else { argv.removeFirst(); @@ -430,13 +430,13 @@ void AOClient::cmdCharCurse(int argc, QStringList argv) l_target->m_is_charcursed = true; // Kick back to char select screen - if (!l_target->m_charcurse_list.contains(server->getCharID(l_target->m_current_char))) { + if (!l_target->m_charcurse_list.contains(server->getCharID(l_target->character()))) { l_target->changeCharacter(-1); - server->updateCharsTaken(server->getAreaById(m_current_area)); + server->updateCharsTaken(server->getAreaById(areaId())); l_target->sendPacket("DONE"); } else { - server->updateCharsTaken(server->getAreaById(m_current_area)); + server->updateCharsTaken(server->getAreaById(areaId())); } l_target->sendServerMessage("You have been charcursed!"); @@ -467,7 +467,7 @@ void AOClient::cmdUnCharCurse(int argc, QStringList argv) } l_target->m_is_charcursed = false; l_target->m_charcurse_list.clear(); - server->updateCharsTaken(server->getAreaById(m_current_area)); + server->updateCharsTaken(server->getAreaById(areaId())); sendServerMessage("Uncharcursed player."); l_target->sendServerMessage("You were uncharcursed."); } @@ -516,13 +516,13 @@ void AOClient::cmdA(int argc, QStringList argv) } AreaData *l_area = server->getAreaById(l_area_id); - if (!l_area->owners().contains(m_id)) { + if (!l_area->owners().contains(clientId())) { sendServerMessage("You are not CM in that area."); return; } argv.removeAt(0); - QString l_sender_name = m_ooc_name; + QString l_sender_name = name(); QString l_ooc_message = argv.join(" "); server->broadcast(PacketFactory::createPacket("CT", {"[CM]" + l_sender_name, l_ooc_message}), l_area_id); } @@ -532,11 +532,11 @@ void AOClient::cmdS(int argc, QStringList argv) Q_UNUSED(argc); int l_all_areas = server->getAreaCount() - 1; - QString l_sender_name = m_ooc_name; + QString l_sender_name = name(); QString l_ooc_message = argv.join(" "); for (int i = 0; i <= l_all_areas; i++) { - if (server->getAreaById(i)->owners().contains(m_id)) + if (server->getAreaById(i)->owners().contains(clientId())) server->broadcast(PacketFactory::createPacket("CT", {"[CM]" + l_sender_name, l_ooc_message}), i); } } diff --git a/core/src/commands/moderation.cpp b/src/commands/moderation.cpp similarity index 96% rename from core/src/commands/moderation.cpp rename to src/commands/moderation.cpp index fb68b01..cca4dbc 100644 --- a/core/src/commands/moderation.cpp +++ b/src/commands/moderation.cpp @@ -15,13 +15,13 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/aoclient.h" +#include "aoclient.h" -#include "include/area_data.h" -#include "include/command_extension.h" -#include "include/config_manager.h" -#include "include/db_manager.h" -#include "include/server.h" +#include "area_data.h" +#include "command_extension.h" +#include "config_manager.h" +#include "db_manager.h" +#include "server.h" // This file is for commands under the moderation category in aoclient.h // Be sure to register the command in the header before adding it here! @@ -146,10 +146,10 @@ void AOClient::cmdMods(int argc, QStringList argv) l_entries << "Moderator: " + l_client->m_moderator_name; l_entries << "Role:" << l_client->m_acl_role_id; } - l_entries << "OOC name: " + l_client->m_ooc_name; - l_entries << "ID: " + QString::number(l_client->m_id); - l_entries << "Area: " + QString::number(l_client->m_current_area); - l_entries << "Character: " + l_client->m_current_char; + l_entries << "OOC name: " + l_client->name(); + l_entries << "ID: " + QString::number(l_client->clientId()); + l_entries << "Area: " + QString::number(l_client->areaId()); + l_entries << "Character: " + l_client->character(); l_online_count++; } } @@ -441,8 +441,8 @@ void AOClient::cmdAllowBlankposting(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - QString l_sender_name = m_ooc_name; - AreaData *l_area = server->getAreaById(m_current_area); + QString l_sender_name = name(); + AreaData *l_area = server->getAreaById(areaId()); l_area->toggleBlankposting(); if (l_area->blankpostingAllowed() == false) { sendServerMessageArea(l_sender_name + " has set blankposting in the area to forbidden."); @@ -508,7 +508,7 @@ void AOClient::cmdForceImmediate(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); l_area->toggleImmediate(); QString l_state = l_area->forceImmediate() ? "on." : "off."; sendServerMessage("Forced immediate text processing in this area is now " + l_state); @@ -519,7 +519,7 @@ void AOClient::cmdAllowIniswap(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); l_area->toggleIniswap(); QString state = l_area->iniswapAllowed() ? "allowed." : "disallowed."; sendServerMessage("Iniswapping in this area is now " + state); @@ -535,7 +535,7 @@ void AOClient::cmdPermitSaving(int argc, QStringList argv) return; } l_client->m_testimony_saving = true; - sendServerMessage("Testimony saving has been enabled for client " + QString::number(l_client->m_id)); + sendServerMessage("Testimony saving has been enabled for client " + QString::number(l_client->clientId())); } void AOClient::cmdKickUid(int argc, QStringList argv) @@ -623,7 +623,7 @@ void AOClient::cmdClearCM(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); foreach (int l_client_id, l_area->owners()) { l_area->removeOwner(l_client_id); } diff --git a/core/src/commands/music.cpp b/src/commands/music.cpp similarity index 83% rename from core/src/commands/music.cpp rename to src/commands/music.cpp index 6cdfbfd..17b7a9f 100644 --- a/core/src/commands/music.cpp +++ b/src/commands/music.cpp @@ -15,12 +15,12 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/aoclient.h" +#include "aoclient.h" -#include "include/area_data.h" -#include "include/music_manager.h" -#include "include/packet/packet_factory.h" -#include "include/server.h" +#include "area_data.h" +#include "music_manager.h" +#include "packet/packet_factory.h" +#include "server.h" // This file is for commands under the music category in aoclient.h // Be sure to register the command in the header before adding it here! @@ -33,21 +33,21 @@ void AOClient::cmdPlay(int argc, QStringList argv) sendServerMessage("You are blocked from changing the music."); return; } - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); const ACLRole l_role = server->getACLRolesHandler()->getRoleById(m_acl_role_id); - if (!l_area->owners().contains(m_id) && !l_area->isPlayEnabled() && !l_role.checkPermission(ACLRole::CM)) { // Make sure we have permission to play music + if (!l_area->owners().contains(clientId()) && !l_area->isPlayEnabled() && !l_role.checkPermission(ACLRole::CM)) { // Make sure we have permission to play music sendServerMessage("Free music play is disabled in this area."); return; } QString l_song = argv.join(" "); - if (m_showname.isEmpty()) { - l_area->changeMusic(m_current_char, l_song); + if (characterName().isEmpty()) { + l_area->changeMusic(character(), l_song); } else { - l_area->changeMusic(m_showname, l_song); + l_area->changeMusic(characterName(), l_song); } - AOPacket *music_change = PacketFactory::createPacket("MC", {l_song, QString::number(server->getCharID(m_current_char)), m_showname, "1", "0"}); - server->broadcast(music_change, m_current_area); + AOPacket *music_change = PacketFactory::createPacket("MC", {l_song, QString::number(server->getCharID(character())), characterName(), "1", "0"}); + server->broadcast(music_change, areaId()); } void AOClient::cmdPlayAmbience(int argc, QStringList argv) @@ -58,15 +58,15 @@ void AOClient::cmdPlayAmbience(int argc, QStringList argv) sendServerMessage("You are blocked from changing the ambience."); return; } - AreaData *l_area = server->getAreaById(m_current_area); - if (!l_area->owners().contains(m_id) && !l_area->isPlayEnabled()) { // Make sure we have permission to play music + AreaData *l_area = server->getAreaById(areaId()); + if (!l_area->owners().contains(clientId()) && !l_area->isPlayEnabled()) { // Make sure we have permission to play music sendServerMessage("Free ambience play is disabled in this area."); return; } QString l_song = argv.join(" "); l_area->changeAmbience(l_song); - AOPacket *music_change = PacketFactory::createPacket("MC", {l_song, "-1", m_showname, "1", "1"}); - server->broadcast(music_change, m_current_area); + AOPacket *music_change = PacketFactory::createPacket("MC", {l_song, "-1", characterName(), "1", "1"}); + server->broadcast(music_change, areaId()); } void AOClient::cmdCurrentMusic(int argc, QStringList argv) @@ -74,7 +74,7 @@ void AOClient::cmdCurrentMusic(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); if (!l_area->currentMusic().isEmpty() && !l_area->currentMusic().contains("~stop.mp3")) // dummy track for stopping music sendServerMessage("The current song is " + l_area->currentMusic() + " played by " + l_area->musicPlayerBy()); else @@ -140,7 +140,7 @@ void AOClient::cmdToggleMusic(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); l_area->toggleMusic(); QString l_state = l_area->isMusicAllowed() ? "allowed." : "disallowed."; sendServerMessage("Music in this area is now " + l_state); @@ -151,7 +151,7 @@ void AOClient::cmdToggleJukebox(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); l_area->toggleJukebox(); QString l_state = l_area->isjukeboxEnabled() ? "enabled." : "disabled."; sendServerMessageArea("The jukebox in this area has been " + l_state); @@ -172,13 +172,13 @@ void AOClient::cmdAddSong(int argc, QStringList argv) bool l_success = false; if (l_argv.size() == 1) { QString l_song_name = l_argv.value(0); - l_success = m_music_manager->addCustomSong(l_song_name, l_song_name, 0, m_current_area); + l_success = m_music_manager->addCustomSong(l_song_name, l_song_name, 0, areaId()); } if (l_argv.size() == 2) { QString l_song_name = l_argv.value(0); QString l_true_name = l_argv.value(1); - l_success = m_music_manager->addCustomSong(l_song_name, l_true_name, 0, m_current_area); + l_success = m_music_manager->addCustomSong(l_song_name, l_true_name, 0, areaId()); } if (l_argv.size() == 3) { @@ -188,7 +188,7 @@ void AOClient::cmdAddSong(int argc, QStringList argv) int l_song_duration = l_argv.value(2).toInt(&ok); if (!ok) l_song_duration = 0; - l_success = m_music_manager->addCustomSong(l_song_name, l_true_name, l_song_duration, m_current_area); + l_success = m_music_manager->addCustomSong(l_song_name, l_true_name, l_song_duration, areaId()); } if (l_argv.size() >= 4) { @@ -203,7 +203,7 @@ void AOClient::cmdAddSong(int argc, QStringList argv) void AOClient::cmdAddCategory(int argc, QStringList argv) { Q_UNUSED(argc); - bool l_success = m_music_manager->addCustomCategory(argv.join(" "), m_current_area); + bool l_success = m_music_manager->addCustomCategory(argv.join(" "), areaId()); QString l_message = l_success ? "succeeded." : "failed."; sendServerMessage("The addition of the category has " + l_message); } @@ -211,7 +211,7 @@ void AOClient::cmdAddCategory(int argc, QStringList argv) void AOClient::cmdRemoveCategorySong(int argc, QStringList argv) { Q_UNUSED(argc); - bool l_success = m_music_manager->removeCategorySong(argv.join(" "), m_current_area); + bool l_success = m_music_manager->removeCategorySong(argv.join(" "), areaId()); QString l_message = l_success ? "succeeded." : "failed."; sendServerMessage("The removal of the entry has " + l_message); } @@ -220,7 +220,7 @@ void AOClient::cmdToggleRootlist(int argc, QStringList argv) { Q_UNUSED(argc); Q_UNUSED(argv); - bool l_status = m_music_manager->toggleRootEnabled(m_current_area); + bool l_status = m_music_manager->toggleRootEnabled(areaId()); QString l_message = (l_status) ? "enabled." : "disabled."; sendServerMessage("Global musiclist has been " + l_message); } @@ -229,7 +229,7 @@ void AOClient::cmdClearCustom(int argc, QStringList argv) { Q_UNUSED(argc); Q_UNUSED(argv); - m_music_manager->clearCustomList(m_current_area); + m_music_manager->clearCustomList(areaId()); sendServerMessage("Custom songs have been cleared."); } @@ -238,12 +238,12 @@ void AOClient::cmdJukeboxSkip(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - QString l_name = m_current_char; - if (!m_showname.isEmpty()) { - l_name = m_showname; + QString l_name = character(); + if (!characterName().isEmpty()) { + l_name = characterName(); } - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); if (l_area->isjukeboxEnabled()) { if (l_area->getJukeboxQueueSize() >= 1) { diff --git a/core/src/commands/roleplay.cpp b/src/commands/roleplay.cpp similarity index 91% rename from core/src/commands/roleplay.cpp rename to src/commands/roleplay.cpp index 3175f1b..6e39e80 100644 --- a/core/src/commands/roleplay.cpp +++ b/src/commands/roleplay.cpp @@ -15,12 +15,12 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/aoclient.h" +#include "aoclient.h" -#include "include/area_data.h" -#include "include/config_manager.h" -#include "include/packet/packet_factory.h" -#include "include/server.h" +#include "area_data.h" +#include "config_manager.h" +#include "packet/packet_factory.h" +#include "server.h" // This file is for commands under the roleplay category in aoclient.h // Be sure to register the command in the header before adding it here! @@ -30,7 +30,7 @@ void AOClient::cmdFlip(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - QString l_sender_name = m_ooc_name; + QString l_sender_name = name(); QStringList l_faces = {"heads", "tails"}; QString l_face = l_faces[AOClient::genRand(0, 1)]; sendServerMessageArea(l_sender_name + " flipped a coin and got " + l_face + "."); @@ -150,7 +150,7 @@ void AOClient::cmdRollP(int argc, QStringList argv) void AOClient::cmdTimer(int argc, QStringList argv) { - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); // Called without arguments // Shows a brief of all timers @@ -207,8 +207,8 @@ void AOClient::cmdTimer(int argc, QStringList argv) l_requested_timer->start(); sendServerMessage("Set timer " + QString::number(l_timer_id) + " to " + argv[1] + "."); AOPacket *l_update_timer = PacketFactory::createPacket("TI", {QString::number(l_timer_id), "0", QString::number(QTime(0, 0).msecsTo(l_requested_time))}); - l_is_global ? server->broadcast(l_show_timer) : server->broadcast(l_show_timer, m_current_area); // Show the timer - l_is_global ? server->broadcast(l_update_timer) : server->broadcast(l_update_timer, m_current_area); + l_is_global ? server->broadcast(l_show_timer) : server->broadcast(l_show_timer, areaId()); // Show the timer + l_is_global ? server->broadcast(l_update_timer) : server->broadcast(l_update_timer, areaId()); return; } // Otherwise, update the state of the timer @@ -217,22 +217,22 @@ void AOClient::cmdTimer(int argc, QStringList argv) l_requested_timer->start(); sendServerMessage("Started timer " + QString::number(l_timer_id) + "."); AOPacket *l_update_timer = PacketFactory::createPacket("TI", {QString::number(l_timer_id), "0", QString::number(QTime(0, 0).msecsTo(QTime(0, 0).addMSecs(l_requested_timer->remainingTime())))}); - l_is_global ? server->broadcast(l_show_timer) : server->broadcast(l_show_timer, m_current_area); - l_is_global ? server->broadcast(l_update_timer) : server->broadcast(l_update_timer, m_current_area); + l_is_global ? server->broadcast(l_show_timer) : server->broadcast(l_show_timer, areaId()); + l_is_global ? server->broadcast(l_update_timer) : server->broadcast(l_update_timer, areaId()); } else if (argv[1] == "pause" || argv[1] == "stop") { l_requested_timer->setInterval(l_requested_timer->remainingTime()); l_requested_timer->stop(); sendServerMessage("Stopped timer " + QString::number(l_timer_id) + "."); AOPacket *l_update_timer = PacketFactory::createPacket("TI", {QString::number(l_timer_id), "1", QString::number(QTime(0, 0).msecsTo(QTime(0, 0).addMSecs(l_requested_timer->interval())))}); - l_is_global ? server->broadcast(l_update_timer) : server->broadcast(l_update_timer, m_current_area); + l_is_global ? server->broadcast(l_update_timer) : server->broadcast(l_update_timer, areaId()); } else if (argv[1] == "hide" || argv[1] == "unset") { l_requested_timer->setInterval(0); l_requested_timer->stop(); sendServerMessage("Hid timer " + QString::number(l_timer_id) + "."); // Hide the timer - l_is_global ? server->broadcast(l_hide_timer) : server->broadcast(l_hide_timer, m_current_area); + l_is_global ? server->broadcast(l_hide_timer) : server->broadcast(l_hide_timer, areaId()); } } } @@ -241,10 +241,10 @@ void AOClient::cmdNoteCard(int argc, QStringList argv) { Q_UNUSED(argc); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); QString l_notecard = argv.join(" "); - l_area->addNotecard(m_current_char, l_notecard); - sendServerMessageArea(m_current_char + " wrote a note card."); + l_area->addNotecard(character(), l_notecard); + sendServerMessageArea(character() + " wrote a note card."); } void AOClient::cmdNoteCardClear(int argc, QStringList argv) @@ -252,9 +252,9 @@ void AOClient::cmdNoteCardClear(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); - if (!l_area->addNotecard(m_current_char, QString())) { - sendServerMessageArea(m_current_char + " erased their note card."); + AreaData *l_area = server->getAreaById(areaId()); + if (!l_area->addNotecard(character(), QString())) { + sendServerMessageArea(character() + " erased their note card."); } } @@ -263,7 +263,7 @@ void AOClient::cmdNoteCardReveal(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - AreaData *l_area = server->getAreaById(m_current_area); + AreaData *l_area = server->getAreaById(areaId()); const QStringList l_notecards = l_area->getNotecards(); if (l_notecards.isEmpty()) { @@ -287,7 +287,7 @@ void AOClient::cmd8Ball(int argc, QStringList argv) } else { QString l_response = ConfigManager::magic8BallAnswers().at((genRand(1, ConfigManager::magic8BallAnswers().size() - 1))); - QString l_sender_name = m_ooc_name; + QString l_sender_name = name(); QString l_sender_message = argv.join(" "); sendServerMessageArea(l_sender_name + " asked the magic 8-ball, \"" + l_sender_message + "\" and the answer is: " + l_response); @@ -301,7 +301,7 @@ void AOClient::cmdSubTheme(int argc, QStringList argv) QString l_subtheme = argv.join(" "); const QVector l_clients = server->getClients(); for (AOClient *l_client : l_clients) { - if (l_client->m_current_area == m_current_area) + if (l_client->areaId() == areaId()) l_client->sendPacket("ST", {l_subtheme, "1"}); } sendServerMessageArea("Subtheme was set to " + l_subtheme); diff --git a/core/src/config_manager.cpp b/src/config_manager.cpp similarity index 99% rename from core/src/config_manager.cpp rename to src/config_manager.cpp index 81b9649..c65a46c 100644 --- a/core/src/config_manager.cpp +++ b/src/config_manager.cpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/config_manager.h" +#include "config_manager.h" #include #include diff --git a/core/include/config_manager.h b/src/config_manager.h similarity index 99% rename from core/include/config_manager.h rename to src/config_manager.h index 3ac98bd..9fd4e1f 100644 --- a/core/include/config_manager.h +++ b/src/config_manager.h @@ -35,8 +35,8 @@ #include #include -#include "include/data_types.h" -#include "include/typedefs.h" +#include "data_types.h" +#include "typedefs.h" /** * @brief The config file handler class. diff --git a/core/include/crypto_helper.h b/src/crypto_helper.h similarity index 100% rename from core/include/crypto_helper.h rename to src/crypto_helper.h diff --git a/core/include/data_types.h b/src/data_types.h similarity index 100% rename from core/include/data_types.h rename to src/data_types.h diff --git a/core/src/db_manager.cpp b/src/db_manager.cpp similarity index 99% rename from core/src/db_manager.cpp rename to src/db_manager.cpp index b724684..a06b0f7 100644 --- a/core/src/db_manager.cpp +++ b/src/db_manager.cpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/db_manager.h" +#include "db_manager.h" DBManager::DBManager() : DRIVER("QSQLITE") diff --git a/core/include/db_manager.h b/src/db_manager.h similarity index 99% rename from core/include/db_manager.h rename to src/db_manager.h index 117d236..6b20d51 100644 --- a/core/include/db_manager.h +++ b/src/db_manager.h @@ -28,8 +28,8 @@ #include #include -#include "include/acl_roles_handler.h" -#include "include/crypto_helper.h" +#include "acl_roles_handler.h" +#include "crypto_helper.h" /** * @brief A class used to handle database interaction. diff --git a/core/src/discord.cpp b/src/discord.cpp similarity index 99% rename from core/src/discord.cpp rename to src/discord.cpp index bd79182..806dd1a 100644 --- a/core/src/discord.cpp +++ b/src/discord.cpp @@ -15,9 +15,9 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/discord.h" +#include "discord.h" -#include "include/config_manager.h" +#include "config_manager.h" Discord::Discord(QObject *parent) : QObject(parent) diff --git a/core/include/discord.h b/src/discord.h similarity index 100% rename from core/include/discord.h rename to src/discord.h diff --git a/core/src/logger/u_logger.cpp b/src/logger/u_logger.cpp similarity index 99% rename from core/src/logger/u_logger.cpp rename to src/logger/u_logger.cpp index eeb99d9..5c1ab29 100644 --- a/core/src/logger/u_logger.cpp +++ b/src/logger/u_logger.cpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/logger/u_logger.h" +#include "logger/u_logger.h" ULogger::ULogger(QObject *parent) : QObject(parent) diff --git a/core/include/logger/u_logger.h b/src/logger/u_logger.h similarity index 98% rename from core/include/logger/u_logger.h rename to src/logger/u_logger.h index bc3ef38..d08e19d 100644 --- a/core/include/logger/u_logger.h +++ b/src/logger/u_logger.h @@ -18,9 +18,9 @@ #ifndef U_LOGGER_H #define U_LOGGER_H -#include "include/config_manager.h" -#include "include/logger/writer_full.h" -#include "include/logger/writer_modcall.h" +#include "config_manager.h" +#include "logger/writer_full.h" +#include "logger/writer_modcall.h" #include #include #include diff --git a/core/src/logger/writer_full.cpp b/src/logger/writer_full.cpp similarity index 98% rename from core/src/logger/writer_full.cpp rename to src/logger/writer_full.cpp index 914c1a8..434608f 100644 --- a/core/src/logger/writer_full.cpp +++ b/src/logger/writer_full.cpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/logger/writer_full.h" +#include "logger/writer_full.h" WriterFull::WriterFull(QObject *parent) : QObject(parent) diff --git a/core/include/logger/writer_full.h b/src/logger/writer_full.h similarity index 100% rename from core/include/logger/writer_full.h rename to src/logger/writer_full.h diff --git a/core/src/logger/writer_modcall.cpp b/src/logger/writer_modcall.cpp similarity index 98% rename from core/src/logger/writer_modcall.cpp rename to src/logger/writer_modcall.cpp index ddaaca4..93e8996 100644 --- a/core/src/logger/writer_modcall.cpp +++ b/src/logger/writer_modcall.cpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/logger/writer_modcall.h" +#include "logger/writer_modcall.h" WriterModcall::WriterModcall(QObject *parent) : QObject(parent) diff --git a/core/include/logger/writer_modcall.h b/src/logger/writer_modcall.h similarity index 100% rename from core/include/logger/writer_modcall.h rename to src/logger/writer_modcall.h diff --git a/akashi/main.cpp b/src/main.cpp similarity index 97% rename from akashi/main.cpp rename to src/main.cpp index f94091a..0b6db05 100644 --- a/akashi/main.cpp +++ b/src/main.cpp @@ -15,8 +15,8 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include -#include +#include "config_manager.h" +#include "server.h" #include diff --git a/core/src/music_manager.cpp b/src/music_manager.cpp similarity index 98% rename from core/src/music_manager.cpp rename to src/music_manager.cpp index ad6c40e..ba40f56 100644 --- a/core/src/music_manager.cpp +++ b/src/music_manager.cpp @@ -1,7 +1,7 @@ -#include "include/music_manager.h" +#include "music_manager.h" -#include "include/config_manager.h" -#include "include/packet/packet_factory.h" +#include "config_manager.h" +#include "packet/packet_factory.h" MusicManager::MusicManager(QStringList f_cdns, MusicList f_root_list, QStringList f_root_ordered, QObject *parent) : QObject(parent), diff --git a/core/include/music_manager.h b/src/music_manager.h similarity index 99% rename from core/include/music_manager.h rename to src/music_manager.h index 357c960..0e9b145 100644 --- a/core/include/music_manager.h +++ b/src/music_manager.h @@ -23,8 +23,8 @@ #include #include -#include "include/network/aopacket.h" -#include "include/typedefs.h" +#include "network/aopacket.h" +#include "typedefs.h" class ConfigManager; diff --git a/core/src/network/aopacket.cpp b/src/network/aopacket.cpp similarity index 83% rename from core/src/network/aopacket.cpp rename to src/network/aopacket.cpp index 43afe5f..7bf85b2 100644 --- a/core/src/network/aopacket.cpp +++ b/src/network/aopacket.cpp @@ -15,29 +15,30 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/network/aopacket.h" +#include "network/aopacket.h" -#include "include/packet/packet_askchaa.h" -#include "include/packet/packet_casea.h" -#include "include/packet/packet_cc.h" -#include "include/packet/packet_ch.h" -#include "include/packet/packet_ct.h" -#include "include/packet/packet_de.h" -#include "include/packet/packet_ee.h" -#include "include/packet/packet_factory.h" -#include "include/packet/packet_hi.h" -#include "include/packet/packet_hp.h" -#include "include/packet/packet_id.h" -#include "include/packet/packet_mc.h" -#include "include/packet/packet_ms.h" -#include "include/packet/packet_pe.h" -#include "include/packet/packet_pw.h" -#include "include/packet/packet_rc.h" -#include "include/packet/packet_rd.h" -#include "include/packet/packet_rm.h" -#include "include/packet/packet_rt.h" -#include "include/packet/packet_setcase.h" -#include "include/packet/packet_zz.h" +#include "packet/packet_askchaa.h" +#include "packet/packet_casea.h" +#include "packet/packet_cc.h" +#include "packet/packet_ch.h" +#include "packet/packet_ct.h" +#include "packet/packet_de.h" +#include "packet/packet_ee.h" +#include "packet/packet_factory.h" +#include "packet/packet_hi.h" +#include "packet/packet_hp.h" +#include "packet/packet_id.h" +#include "packet/packet_mc.h" +#include "packet/packet_ms.h" +#include "packet/packet_pe.h" +#include "packet/packet_pl.h" +#include "packet/packet_pw.h" +#include "packet/packet_rc.h" +#include "packet/packet_rd.h" +#include "packet/packet_rm.h" +#include "packet/packet_rt.h" +#include "packet/packet_setcase.h" +#include "packet/packet_zz.h" AOPacket::AOPacket(QStringList p_contents) : m_content(p_contents), @@ -132,4 +133,7 @@ void AOPacket::registerPackets() PacketFactory::registerClass("RT"); PacketFactory::registerClass("SETCASE"); PacketFactory::registerClass("ZZ"); + PacketFactory::registerClass("PL"); + PacketFactory::registerClass("PLU"); + PacketFactory::registerClass("PU"); } diff --git a/core/include/network/aopacket.h b/src/network/aopacket.h similarity index 97% rename from core/include/network/aopacket.h rename to src/network/aopacket.h index 7027e58..c97a479 100644 --- a/core/include/network/aopacket.h +++ b/src/network/aopacket.h @@ -23,9 +23,9 @@ #include #include -#include "include/aoclient.h" -#include "include/area_data.h" -#include "include/packet/packet_info.h" +#include "aoclient.h" +#include "area_data.h" +#include "packet/packet_info.h" class AOClient; @@ -113,7 +113,6 @@ class AOPacket virtual PacketInfo getPacketInfo() const = 0; virtual void handlePacket(AreaData *area, AOClient &client) const = 0; - virtual bool validatePacket() const = 0; static void registerPackets(); diff --git a/core/src/network/network_socket.cpp b/src/network/network_socket.cpp similarity index 98% rename from core/src/network/network_socket.cpp rename to src/network/network_socket.cpp index b846c5d..758ab6e 100644 --- a/core/src/network/network_socket.cpp +++ b/src/network/network_socket.cpp @@ -15,8 +15,8 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/network/network_socket.h" -#include "include/packet/packet_factory.h" +#include "network/network_socket.h" +#include "packet/packet_factory.h" NetworkSocket::NetworkSocket(QTcpSocket *f_socket, QObject *parent) : QObject(parent) diff --git a/core/include/network/network_socket.h b/src/network/network_socket.h similarity index 99% rename from core/include/network/network_socket.h rename to src/network/network_socket.h index f3c463c..193fa11 100644 --- a/core/include/network/network_socket.h +++ b/src/network/network_socket.h @@ -23,7 +23,7 @@ #include #include -#include "include/network/aopacket.h" +#include "network/aopacket.h" class AOPacket; diff --git a/core/src/packet/packet_askchaa.cpp b/src/packet/packet_askchaa.cpp similarity index 74% rename from core/src/packet/packet_askchaa.cpp rename to src/packet/packet_askchaa.cpp index 4e71e16..263111d 100644 --- a/core/src/packet/packet_askchaa.cpp +++ b/src/packet/packet_askchaa.cpp @@ -1,6 +1,6 @@ -#include "include/packet/packet_askchaa.h" -#include "include/config_manager.h" -#include "include/server.h" +#include "packet/packet_askchaa.h" +#include "config_manager.h" +#include "server.h" #include @@ -26,11 +26,3 @@ void PacketAskchaa::handlePacket(AreaData *area, AOClient &client) const // Client only cares about what it gets from LE client.sendPacket("SI", {QString::number(client.getServer()->getCharacterCount()), "0", QString::number(client.getServer()->getAreaCount() + client.getServer()->getMusicList().length())}); } - -bool PacketAskchaa::validatePacket() const -{ - if (m_content.size() > 0) { // Too many arguments. - return false; - } - return true; -} diff --git a/core/include/packet/packet_askchaa.h b/src/packet/packet_askchaa.h similarity index 77% rename from core/include/packet/packet_askchaa.h rename to src/packet/packet_askchaa.h index 8db348f..e19917c 100644 --- a/core/include/packet/packet_askchaa.h +++ b/src/packet/packet_askchaa.h @@ -1,7 +1,7 @@ #ifndef PACKET_ASKCHAA_H #define PACKET_ASKCHAA_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketAskchaa : public AOPacket { @@ -9,6 +9,5 @@ class PacketAskchaa : public AOPacket PacketAskchaa(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; }; #endif diff --git a/core/src/packet/packet_casea.cpp b/src/packet/packet_casea.cpp similarity index 82% rename from core/src/packet/packet_casea.cpp rename to src/packet/packet_casea.cpp index b811696..a083512 100644 --- a/core/src/packet/packet_casea.cpp +++ b/src/packet/packet_casea.cpp @@ -1,7 +1,7 @@ -#include "include/packet/packet_casea.h" -#include "include/akashiutils.h" -#include "include/packet/packet_factory.h" -#include "include/server.h" +#include "packet/packet_casea.h" +#include "akashiutils.h" +#include "packet/packet_factory.h" +#include "server.h" #include @@ -41,7 +41,7 @@ void PacketCasea::handlePacket(AreaData *area, AOClient &client) const if (l_needed_roles.isEmpty()) return; - QString l_message = "=== Case Announcement ===\r\n" + (client.m_ooc_name == "" ? client.m_current_char : client.m_ooc_name) + " needs " + l_needed_roles.join(", ") + " for " + (l_case_title == "" ? "a case" : l_case_title) + "!"; + QString l_message = "=== Case Announcement ===\r\n" + (client.name() == "" ? client.character() : client.name()) + " needs " + l_needed_roles.join(", ") + " for " + (l_case_title == "" ? "a case" : l_case_title) + "!"; QList l_clients_to_alert; // here lies morton, RIP @@ -70,13 +70,3 @@ void PacketCasea::handlePacket(AreaData *area, AOClient &client) const // at least 7 arguments despite only using the first 6. Cera, i kneel. you have truly broken me. } } - -bool PacketCasea::validatePacket() const -{ - for (int i = 1; i < m_content.size(); i++) { - if (!AkashiUtils::checkArgType(m_content.at(i))) { - return false; - } - } - return true; -} diff --git a/core/include/packet/packet_casea.h b/src/packet/packet_casea.h similarity index 76% rename from core/include/packet/packet_casea.h rename to src/packet/packet_casea.h index 0212917..4217143 100644 --- a/core/include/packet/packet_casea.h +++ b/src/packet/packet_casea.h @@ -1,7 +1,7 @@ #ifndef PACKET_CASEA_H #define PACKET_CASEA_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketCasea : public AOPacket { @@ -9,6 +9,5 @@ class PacketCasea : public AOPacket PacketCasea(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; }; #endif diff --git a/core/src/packet/packet_cc.cpp b/src/packet/packet_cc.cpp similarity index 82% rename from core/src/packet/packet_cc.cpp rename to src/packet/packet_cc.cpp index 5d203f2..bd0cedd 100644 --- a/core/src/packet/packet_cc.cpp +++ b/src/packet/packet_cc.cpp @@ -1,7 +1,7 @@ -#include "include/packet/packet_cc.h" -#include "include/akashiutils.h" -#include "include/config_manager.h" -#include "include/server.h" +#include "packet/packet_cc.h" +#include "akashiutils.h" +#include "config_manager.h" +#include "server.h" #include @@ -46,8 +46,3 @@ void PacketCC::handlePacket(AreaData *area, AOClient &client) const client.setSpectator(false); } } - -bool PacketCC::validatePacket() const -{ - return AkashiUtils::checkArgType(m_content.at(1)); -} diff --git a/core/include/packet/packet_cc.h b/src/packet/packet_cc.h similarity index 76% rename from core/include/packet/packet_cc.h rename to src/packet/packet_cc.h index 51342ca..85ad146 100644 --- a/core/include/packet/packet_cc.h +++ b/src/packet/packet_cc.h @@ -1,7 +1,7 @@ #ifndef PACKET_CC_H #define PACKET_CC_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketCC : public AOPacket { @@ -9,6 +9,5 @@ class PacketCC : public AOPacket PacketCC(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; }; #endif diff --git a/core/src/packet/packet_ch.cpp b/src/packet/packet_ch.cpp similarity index 71% rename from core/src/packet/packet_ch.cpp rename to src/packet/packet_ch.cpp index f583f15..3880d57 100644 --- a/core/src/packet/packet_ch.cpp +++ b/src/packet/packet_ch.cpp @@ -1,6 +1,6 @@ -#include "include/packet/packet_ch.h" -#include "include/akashiutils.h" -#include "include/server.h" +#include "packet/packet_ch.h" +#include "akashiutils.h" +#include "server.h" #include @@ -26,8 +26,3 @@ void PacketCH::handlePacket(AreaData *area, AOClient &client) const // It is now used for ping measurement client.sendPacket("CHECK"); } - -bool PacketCH::validatePacket() const -{ - return AkashiUtils::checkArgType(m_content.at(0)); -} diff --git a/core/include/packet/packet_ch.h b/src/packet/packet_ch.h similarity index 76% rename from core/include/packet/packet_ch.h rename to src/packet/packet_ch.h index 815b802..3bec198 100644 --- a/core/include/packet/packet_ch.h +++ b/src/packet/packet_ch.h @@ -1,7 +1,7 @@ #ifndef PACKET_CH_H #define PACKET_CH_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketCH : public AOPacket { @@ -9,6 +9,5 @@ class PacketCH : public AOPacket PacketCH(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; }; #endif diff --git a/core/src/packet/packet_ct.cpp b/src/packet/packet_ct.cpp similarity index 56% rename from core/src/packet/packet_ct.cpp rename to src/packet/packet_ct.cpp index 924fee6..f08137f 100644 --- a/core/src/packet/packet_ct.cpp +++ b/src/packet/packet_ct.cpp @@ -1,8 +1,8 @@ -#include "include/packet/packet_ct.h" -#include "include/akashidefs.h" -#include "include/config_manager.h" -#include "include/packet/packet_factory.h" -#include "include/server.h" +#include "packet/packet_ct.h" +#include "akashidefs.h" +#include "config_manager.h" +#include "packet/packet_factory.h" +#include "server.h" #include @@ -27,11 +27,11 @@ void PacketCT::handlePacket(AreaData *area, AOClient &client) const return; } - client.m_ooc_name = client.dezalgo(m_content[0]).replace(QRegExp("\\[|\\]|\\{|\\}|\\#|\\$|\\%|\\&"), ""); // no fucky wucky shit here - if (client.m_ooc_name.isEmpty() || client.m_ooc_name == ConfigManager::serverName()) // impersonation & empty name protection + client.setName(client.dezalgo(m_content[0]).replace(QRegExp("\\[|\\]|\\{|\\}|\\#|\\$|\\%|\\&"), "")); // no fucky wucky shit here + if (client.name().isEmpty() || client.name() == ConfigManager::serverName()) // impersonation & empty name protection return; - if (client.m_ooc_name.length() > 30) { + if (client.name().length() > 30) { client.sendServerMessage("Your name is too long! Please limit it to under 30 characters."); return; } @@ -44,7 +44,7 @@ void PacketCT::handlePacket(AreaData *area, AOClient &client) const QString l_message = client.dezalgo(m_content[1]); if (l_message.length() == 0 || l_message.length() > ConfigManager::maxCharacters()) return; - AOPacket *final_packet = PacketFactory::createPacket("CT", {client.m_ooc_name, l_message, "0"}); + AOPacket *final_packet = PacketFactory::createPacket("CT", {client.name(), l_message, "0"}); if (l_message.at(0) == '/') { QStringList l_cmd_argv = l_message.split(" ", akashi::SkipEmptyParts); QString l_command = l_cmd_argv[0].trimmed().toLower(); @@ -53,17 +53,11 @@ void PacketCT::handlePacket(AreaData *area, AOClient &client) const int l_cmd_argc = l_cmd_argv.length(); client.handleCommand(l_command, l_cmd_argc, l_cmd_argv); - emit client.logCMD((client.m_current_char + " " + client.m_showname), client.m_ipid, client.m_ooc_name, l_command, l_cmd_argv, client.getServer()->getAreaById(client.m_current_area)->name()); + emit client.logCMD((client.character() + " " + client.characterName()), client.m_ipid, client.name(), l_command, l_cmd_argv, client.getServer()->getAreaById(client.areaId())->name()); return; } else { - client.getServer()->broadcast(final_packet, client.m_current_area); + client.getServer()->broadcast(final_packet, client.areaId()); } - emit client.logOOC((client.m_current_char + " " + client.m_showname), client.m_ooc_name, client.m_ipid, area->name(), l_message); -} - -bool PacketCT::validatePacket() const -{ - // Nothing to validate. - return true; + emit client.logOOC((client.character() + " " + client.characterName()), client.name(), client.m_ipid, area->name(), l_message); } diff --git a/core/include/packet/packet_ct.h b/src/packet/packet_ct.h similarity index 76% rename from core/include/packet/packet_ct.h rename to src/packet/packet_ct.h index e1ffa5a..8fd76cb 100644 --- a/core/include/packet/packet_ct.h +++ b/src/packet/packet_ct.h @@ -1,7 +1,7 @@ #ifndef PACKET_CT_H #define PACKET_CT_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketCT : public AOPacket { @@ -9,6 +9,5 @@ class PacketCT : public AOPacket PacketCT(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; }; #endif diff --git a/core/src/packet/packet_de.cpp b/src/packet/packet_de.cpp similarity index 75% rename from core/src/packet/packet_de.cpp rename to src/packet/packet_de.cpp index e8064af..1d6314f 100644 --- a/core/src/packet/packet_de.cpp +++ b/src/packet/packet_de.cpp @@ -1,6 +1,6 @@ -#include "include/packet/packet_de.h" -#include "include/akashiutils.h" -#include "include/server.h" +#include "packet/packet_de.h" +#include "akashiutils.h" +#include "server.h" #include @@ -29,8 +29,3 @@ void PacketDE::handlePacket(AreaData *area, AOClient &client) const } client.sendEvidenceList(area); } - -bool PacketDE::validatePacket() const -{ - return AkashiUtils::checkArgType(m_content.at(0)); -} diff --git a/core/include/packet/packet_de.h b/src/packet/packet_de.h similarity index 76% rename from core/include/packet/packet_de.h rename to src/packet/packet_de.h index 9dc2739..a94346e 100644 --- a/core/include/packet/packet_de.h +++ b/src/packet/packet_de.h @@ -1,7 +1,7 @@ #ifndef PACKET_DE_H #define PACKET_DE_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketDE : public AOPacket { @@ -9,6 +9,5 @@ class PacketDE : public AOPacket PacketDE(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; }; #endif diff --git a/core/src/packet/packet_ee.cpp b/src/packet/packet_ee.cpp similarity index 77% rename from core/src/packet/packet_ee.cpp rename to src/packet/packet_ee.cpp index 5d5f69f..7cce453 100644 --- a/core/src/packet/packet_ee.cpp +++ b/src/packet/packet_ee.cpp @@ -1,6 +1,6 @@ -#include "include/packet/packet_ee.h" -#include "include/akashiutils.h" -#include "include/server.h" +#include "packet/packet_ee.h" +#include "akashiutils.h" +#include "server.h" #include @@ -30,8 +30,3 @@ void PacketEE::handlePacket(AreaData *area, AOClient &client) const } client.sendEvidenceList(area); } - -bool PacketEE::validatePacket() const -{ - return AkashiUtils::checkArgType(m_content.at(0)); -} diff --git a/core/include/packet/packet_ee.h b/src/packet/packet_ee.h similarity index 76% rename from core/include/packet/packet_ee.h rename to src/packet/packet_ee.h index 71d2aa5..d40d1e1 100644 --- a/core/include/packet/packet_ee.h +++ b/src/packet/packet_ee.h @@ -1,7 +1,7 @@ #ifndef PACKET_EE_H #define PACKET_EE_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketEE : public AOPacket { @@ -9,6 +9,5 @@ class PacketEE : public AOPacket PacketEE(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; }; #endif diff --git a/core/src/packet/packet_factory.cpp b/src/packet/packet_factory.cpp similarity index 92% rename from core/src/packet/packet_factory.cpp rename to src/packet/packet_factory.cpp index 4584d6a..0d067ba 100644 --- a/core/src/packet/packet_factory.cpp +++ b/src/packet/packet_factory.cpp @@ -1,5 +1,5 @@ -#include "include/packet/packet_factory.h" -#include "include/packet/packet_generic.h" +#include "packet/packet_factory.h" +#include "packet/packet_generic.h" AOPacket *PacketFactory::createPacket(QString header, QStringList contents) { @@ -21,7 +21,7 @@ AOPacket *PacketFactory::createPacket(QString raw_packet) } if (raw_packet.at(0) == '#' || raw_packet.contains("%")) { - qDebug() << "FantaCrypt or otherwise invalid packet received"; + qDebug() << "FantaCrypt or otherwise invalid packet received:" << raw_packet; return PacketFactory::createPacket("Unknown", {"Unknown"}); } diff --git a/core/include/packet/packet_factory.h b/src/packet/packet_factory.h similarity index 94% rename from core/include/packet/packet_factory.h rename to src/packet/packet_factory.h index 3ef76d6..09f4b84 100644 --- a/core/include/packet/packet_factory.h +++ b/src/packet/packet_factory.h @@ -1,4 +1,4 @@ -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketFactory { diff --git a/core/src/packet/packet_generic.cpp b/src/packet/packet_generic.cpp similarity index 84% rename from core/src/packet/packet_generic.cpp rename to src/packet/packet_generic.cpp index 8a6e77b..b61fa9b 100644 --- a/core/src/packet/packet_generic.cpp +++ b/src/packet/packet_generic.cpp @@ -1,4 +1,4 @@ -#include "include/packet/packet_generic.h" +#include "packet/packet_generic.h" #include @@ -24,8 +24,3 @@ void PacketGeneric::handlePacket(AreaData *area, AOClient &client) const qDebug() << "ERROR: Cannot handle generic packet: " << header; qDebug() << "Packet is either unimplemented, or is meant to be sent to client"; } - -bool PacketGeneric::validatePacket() const -{ - return true; -} diff --git a/core/include/packet/packet_generic.h b/src/packet/packet_generic.h similarity index 80% rename from core/include/packet/packet_generic.h rename to src/packet/packet_generic.h index d7ac4db..78881a9 100644 --- a/core/include/packet/packet_generic.h +++ b/src/packet/packet_generic.h @@ -1,7 +1,7 @@ #ifndef PACKET_GENERIC_H #define PACKET_GENERIC_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketGeneric : public AOPacket { @@ -9,7 +9,6 @@ class PacketGeneric : public AOPacket PacketGeneric(QString header, QStringList contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; private: QString header; diff --git a/core/src/packet/packet_hi.cpp b/src/packet/packet_hi.cpp similarity index 79% rename from core/src/packet/packet_hi.cpp rename to src/packet/packet_hi.cpp index b946ee1..5c7a2c4 100644 --- a/core/src/packet/packet_hi.cpp +++ b/src/packet/packet_hi.cpp @@ -1,7 +1,7 @@ -#include "include/packet/packet_hi.h" -#include "include/akashiutils.h" -#include "include/db_manager.h" -#include "include/server.h" +#include "packet/packet_hi.h" +#include "akashiutils.h" +#include "db_manager.h" +#include "server.h" #include @@ -47,11 +47,5 @@ void PacketHI::handlePacket(AreaData *area, AOClient &client) const return; } - client.sendPacket("ID", {QString::number(client.m_id), "akashi", QCoreApplication::applicationVersion()}); -} - -bool PacketHI::validatePacket() const -{ - // We can always convert a string to a string. No point in checking. - return true; + client.sendPacket("ID", {QString::number(client.clientId()), "akashi", QCoreApplication::applicationVersion()}); } diff --git a/core/include/packet/packet_hi.h b/src/packet/packet_hi.h similarity index 78% rename from core/include/packet/packet_hi.h rename to src/packet/packet_hi.h index 01291bd..4b74722 100644 --- a/core/include/packet/packet_hi.h +++ b/src/packet/packet_hi.h @@ -1,7 +1,7 @@ #ifndef PACKET_HI_H #define PACKET_HI_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketHI : public AOPacket { @@ -9,7 +9,6 @@ class PacketHI : public AOPacket PacketHI(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; private: QString header; diff --git a/core/src/packet/packet_hp.cpp b/src/packet/packet_hp.cpp similarity index 74% rename from core/src/packet/packet_hp.cpp rename to src/packet/packet_hp.cpp index f27c8f9..0e50e98 100644 --- a/core/src/packet/packet_hp.cpp +++ b/src/packet/packet_hp.cpp @@ -1,7 +1,7 @@ -#include "include/packet/packet_hp.h" -#include "include/akashiutils.h" -#include "include/packet/packet_factory.h" -#include "include/server.h" +#include "packet/packet_hp.h" +#include "akashiutils.h" +#include "packet/packet_factory.h" +#include "server.h" #include @@ -39,12 +39,3 @@ void PacketHP::handlePacket(AreaData *area, AOClient &client) const client.updateJudgeLog(area, &client, "updated the penalties"); } - -bool PacketHP::validatePacket() const -{ - if (!AkashiUtils::checkArgType(m_content.at(0))) - return false; - if (!AkashiUtils::checkArgType(m_content.at(1))) - return false; - return true; -} diff --git a/core/include/packet/packet_hp.h b/src/packet/packet_hp.h similarity index 76% rename from core/include/packet/packet_hp.h rename to src/packet/packet_hp.h index 21b8ccd..68c7196 100644 --- a/core/include/packet/packet_hp.h +++ b/src/packet/packet_hp.h @@ -1,7 +1,7 @@ #ifndef PACKET_HP_H #define PACKET_HP_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketHP : public AOPacket { @@ -9,6 +9,5 @@ class PacketHP : public AOPacket PacketHP(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; }; #endif diff --git a/core/src/packet/packet_id.cpp b/src/packet/packet_id.cpp similarity index 93% rename from core/src/packet/packet_id.cpp rename to src/packet/packet_id.cpp index 0a38cc8..30b1bbd 100644 --- a/core/src/packet/packet_id.cpp +++ b/src/packet/packet_id.cpp @@ -1,6 +1,6 @@ -#include "include/packet/packet_id.h" -#include "include/config_manager.h" -#include "include/server.h" +#include "packet/packet_id.h" +#include "config_manager.h" +#include "server.h" #include @@ -69,8 +69,3 @@ void PacketID::handlePacket(AreaData *area, AOClient &client) const client.sendPacket("ASS", {l_asset_url}); } } - -bool PacketID::validatePacket() const -{ - return true; -} diff --git a/core/include/packet/packet_id.h b/src/packet/packet_id.h similarity index 76% rename from core/include/packet/packet_id.h rename to src/packet/packet_id.h index bb50547..1703150 100644 --- a/core/include/packet/packet_id.h +++ b/src/packet/packet_id.h @@ -1,7 +1,7 @@ #ifndef PACKET_ID_H #define PACKET_ID_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketID : public AOPacket { @@ -9,6 +9,5 @@ class PacketID : public AOPacket PacketID(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; }; #endif diff --git a/core/include/packet/packet_info.h b/src/packet/packet_info.h similarity index 90% rename from core/include/packet/packet_info.h rename to src/packet/packet_info.h index 9581b24..5d4636d 100644 --- a/core/include/packet/packet_info.h +++ b/src/packet/packet_info.h @@ -1,7 +1,7 @@ #ifndef PACKET_INFO_H #define PACKET_INFO_H -#include "include/acl_roles_handler.h" +#include "acl_roles_handler.h" /// Describes a packet's interpretation details. class PacketInfo diff --git a/core/src/packet/packet_mc.cpp b/src/packet/packet_mc.cpp similarity index 78% rename from core/src/packet/packet_mc.cpp rename to src/packet/packet_mc.cpp index 710b916..5c7e7d9 100644 --- a/core/src/packet/packet_mc.cpp +++ b/src/packet/packet_mc.cpp @@ -1,7 +1,7 @@ -#include "include/packet/packet_mc.h" -#include "include/music_manager.h" -#include "include/packet/packet_factory.h" -#include "include/server.h" +#include "packet/packet_mc.h" +#include "music_manager.h" +#include "packet/packet_factory.h" +#include "server.h" #include @@ -29,7 +29,7 @@ void PacketMC::handlePacket(AreaData *area, AOClient &client) const // argument is a valid song QString l_argument = m_content[0]; - if (client.getServer()->getMusicList().contains(l_argument) || client.m_music_manager->isCustom(client.m_current_area, l_argument) || l_argument == "~stop.mp3") { // ~stop.mp3 is a dummy track used by 2.9+ + if (client.getServer()->getMusicList().contains(l_argument) || client.m_music_manager->isCustom(client.areaId(), l_argument) || l_argument == "~stop.mp3") { // ~stop.mp3 is a dummy track used by 2.9+ // We have a song here if (client.m_is_spectator) { @@ -67,19 +67,19 @@ void PacketMC::handlePacket(AreaData *area, AOClient &client) const if (l_final_song != "~stop.mp3") { // We might have an aliased song. We check for its real songname and send it to the clients. - QPair l_song = client.m_music_manager->songInformation(l_final_song, client.m_current_area); + QPair l_song = client.m_music_manager->songInformation(l_final_song, client.areaId()); l_final_song = l_song.first; } - AOPacket *l_music_change = PacketFactory::createPacket("MC", {l_final_song, m_content[1], client.m_showname, "1", "0", l_effects}); - client.getServer()->broadcast(l_music_change, client.m_current_area); + AOPacket *l_music_change = PacketFactory::createPacket("MC", {l_final_song, m_content[1], client.characterName(), "1", "0", l_effects}); + client.getServer()->broadcast(l_music_change, client.areaId()); // Since we can't ensure a user has their showname set, we check if its empty to prevent //"played by ." in /currentmusic. - if (client.m_showname.isEmpty()) { - area->changeMusic(client.m_current_char, l_final_song); + if (client.characterName().isEmpty()) { + area->changeMusic(client.character(), l_final_song); return; } - area->changeMusic(client.m_showname, l_final_song); + area->changeMusic(client.characterName(), l_final_song); return; } @@ -91,8 +91,3 @@ void PacketMC::handlePacket(AreaData *area, AOClient &client) const } } } - -bool PacketMC::validatePacket() const -{ - return true; -} diff --git a/core/include/packet/packet_mc.h b/src/packet/packet_mc.h similarity index 76% rename from core/include/packet/packet_mc.h rename to src/packet/packet_mc.h index d3c271c..ee3ed0f 100644 --- a/core/include/packet/packet_mc.h +++ b/src/packet/packet_mc.h @@ -1,7 +1,7 @@ #ifndef PACKET_MC_H #define PACKET_MC_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketMC : public AOPacket { @@ -9,6 +9,5 @@ class PacketMC : public AOPacket PacketMC(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; }; #endif diff --git a/core/src/packet/packet_ms.cpp b/src/packet/packet_ms.cpp similarity index 93% rename from core/src/packet/packet_ms.cpp rename to src/packet/packet_ms.cpp index 9720670..f0a060b 100644 --- a/core/src/packet/packet_ms.cpp +++ b/src/packet/packet_ms.cpp @@ -1,7 +1,7 @@ -#include "include/packet/packet_ms.h" -#include "include/config_manager.h" -#include "include/packet/packet_factory.h" -#include "include/server.h" +#include "packet/packet_ms.h" +#include "config_manager.h" +#include "packet/packet_factory.h" +#include "server.h" #include @@ -37,8 +37,8 @@ void PacketMS::handlePacket(AreaData *area, AOClient &client) const if (client.m_pos != "") validated_packet->setContentField(5, client.m_pos); - client.getServer()->broadcast(validated_packet, client.m_current_area); - emit client.logIC((client.m_current_char + " " + client.m_showname), client.m_ooc_name, client.m_ipid, client.getServer()->getAreaById(client.m_current_area)->name(), client.m_last_message); + client.getServer()->broadcast(validated_packet, client.areaId()); + emit client.logIC((client.character() + " " + client.characterName()), client.name(), client.m_ipid, client.getServer()->getAreaById(client.areaId())->name(), client.m_last_message); area->updateLastICMessage(validated_packet->getContent()); area->startMessageFloodguard(ConfigManager::messageFloodguard()); @@ -59,11 +59,11 @@ AOPacket *PacketMS::validateIcPacket(AOClient &client) const AOPacket *l_invalid = PacketFactory::createPacket("INVALID", {}); QStringList l_args; - if (client.isSpectator() || client.m_current_char.isEmpty() || !client.m_joined) + if (client.isSpectator() || client.character().isEmpty() || !client.m_joined) // Spectators cannot use IC return l_invalid; - AreaData *area = client.getServer()->getAreaById(client.m_current_area); - if (area->lockStatus() == AreaData::LockStatus::SPECTATABLE && !area->invited().contains(client.m_id) && !client.checkPermission(ACLRole::BYPASS_LOCKS)) + AreaData *area = client.getServer()->getAreaById(client.areaId()); + if (area->lockStatus() == AreaData::LockStatus::SPECTATABLE && !area->invited().contains(client.clientId()) && !client.checkPermission(ACLRole::BYPASS_LOCKS)) // Non-invited players cannot speak in spectatable areas return l_invalid; @@ -100,7 +100,7 @@ AOPacket *PacketMS::validateIcPacket(AOClient &client) const l_args.append(l_incoming_args[1].toString()); // char name - if (client.m_current_char.toLower() != l_incoming_args[2].toString().toLower()) { + if (client.character().toLower() != l_incoming_args[2].toString().toLower()) { // Selected char is different from supplied folder name // This means the user is INI-swapped if (!area->iniswapAllowed()) { @@ -166,7 +166,7 @@ AOPacket *PacketMS::validateIcPacket(AOClient &client) const if (client.m_pos != l_incoming_args[5].toString()) { client.m_pos = l_incoming_args[5].toString(); client.m_pos.replace("../", "").replace("..\\", ""); - client.updateEvidenceList(client.getServer()->getAreaById(client.m_current_area)); + client.updateEvidenceList(client.getServer()->getAreaById(client.areaId())); } // sfx name @@ -246,7 +246,7 @@ AOPacket *PacketMS::validateIcPacket(AOClient &client) const if (l_incoming_args.length() >= 19) { // showname QString l_incoming_showname = client.dezalgo(l_incoming_args[15].toString().trimmed()); - if (!(l_incoming_showname == client.m_current_char || l_incoming_showname.isEmpty()) && !area->shownameAllowed()) { + if (!(l_incoming_showname == client.character() || l_incoming_showname.isEmpty()) && !area->shownameAllowed()) { client.sendServerMessage("Shownames are not allowed in this area!"); return l_invalid; } @@ -259,7 +259,7 @@ AOPacket *PacketMS::validateIcPacket(AOClient &client) const if (l_incoming_showname.isEmpty() && !l_incoming_args[15].toString().isEmpty()) l_incoming_showname = " "; l_args.append(l_incoming_showname); - client.m_showname = l_incoming_showname; + client.setCharacterName(l_incoming_showname); // other char id // things get a bit hairy here @@ -376,9 +376,9 @@ AOPacket *PacketMS::validateIcPacket(AOClient &client) const } // Testimony playback - QString client_name = client.m_ooc_name; + QString client_name = client.name(); if (client_name == "") { - client_name = client.m_current_char; // fallback in case of empty ooc name + client_name = client.character(); // fallback in case of empty ooc name } if (area->testimonyRecording() == AreaData::TestimonyRecording::RECORDING || area->testimonyRecording() == AreaData::TestimonyRecording::ADD) { if (!l_args[5].startsWith("wit")) @@ -387,7 +387,7 @@ AOPacket *PacketMS::validateIcPacket(AOClient &client) const if (area->statement() == -1) { l_args[4] = "~~-- " + l_args[4] + " --"; l_args[14] = "3"; - client.getServer()->broadcast(PacketFactory::createPacket("RT", {"testimony1"}), client.m_current_area); + client.getServer()->broadcast(PacketFactory::createPacket("RT", {"testimony1"}), client.areaId()); } client.addStatement(l_args); } @@ -463,8 +463,3 @@ QRegularExpressionMatch PacketMS::isTestimonyJumpCommand(QString message) const QRegularExpression jump("(?>)(?[0,1,2,3,4,5,6,7,8,9]+)"); return jump.match(message); } - -bool PacketMS::validatePacket() const -{ - return true; -} diff --git a/core/include/packet/packet_ms.h b/src/packet/packet_ms.h similarity index 83% rename from core/include/packet/packet_ms.h rename to src/packet/packet_ms.h index 0411a19..4caf40e 100644 --- a/core/include/packet/packet_ms.h +++ b/src/packet/packet_ms.h @@ -1,7 +1,7 @@ #ifndef PACKET_MS_H #define PACKET_MS_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketMS : public AOPacket { @@ -9,7 +9,6 @@ class PacketMS : public AOPacket PacketMS(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; private: AOPacket *validateIcPacket(AOClient &client) const; diff --git a/core/src/packet/packet_pe.cpp b/src/packet/packet_pe.cpp similarity index 81% rename from core/src/packet/packet_pe.cpp rename to src/packet/packet_pe.cpp index 272c052..810bf4a 100644 --- a/core/src/packet/packet_pe.cpp +++ b/src/packet/packet_pe.cpp @@ -1,5 +1,5 @@ -#include "include/packet/packet_pe.h" -#include "include/server.h" +#include "packet/packet_pe.h" +#include "server.h" #include @@ -25,8 +25,3 @@ void PacketPE::handlePacket(AreaData *area, AOClient &client) const area->appendEvidence(l_evi); client.sendEvidenceList(area); } - -bool PacketPE::validatePacket() const -{ - return true; -} diff --git a/core/include/packet/packet_pe.h b/src/packet/packet_pe.h similarity index 76% rename from core/include/packet/packet_pe.h rename to src/packet/packet_pe.h index f35dc7b..40ed413 100644 --- a/core/include/packet/packet_pe.h +++ b/src/packet/packet_pe.h @@ -1,7 +1,7 @@ #ifndef PACKET_PE_H #define PACKET_PE_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketPE : public AOPacket { @@ -9,6 +9,5 @@ class PacketPE : public AOPacket PacketPE(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; }; #endif diff --git a/src/packet/packet_pl.cpp b/src/packet/packet_pl.cpp new file mode 100644 index 0000000..9d979ab --- /dev/null +++ b/src/packet/packet_pl.cpp @@ -0,0 +1,88 @@ +#include "packet_pl.h" + +#include + +PacketPL::PacketPL(QStringList &contents) : + AOPacket(contents) +{} + +PacketPL::PacketPL(const QList &f_player_list) : + AOPacket(QStringList{""}) +{ + + QJsonArray player_list_json; + for (const PlayerData &player : f_player_list) { + QJsonObject player_json; + + player_json["id"] = player.id; + player_json["name"] = player.name; + player_json["character"] = player.character; + player_json["character_name"] = player.character_name; + player_json["area_id"] = player.area_id; + + player_list_json.append(player_json); + } + + setContentField(0, QJsonDocument(player_list_json).toJson(QJsonDocument::Compact)); +} + +PacketInfo PacketPL::getPacketInfo() const { return PacketInfo{.acl_permission = ACLRole::NONE, .min_args = 1, .header = "PL"}; } + +void PacketPL::handlePacket(AreaData *area, AOClient &client) const +{ + Q_UNUSED(area); + Q_UNUSED(client); +} + +PacketPLU::PacketPLU(QStringList &contents) : + AOPacket(contents) +{} + +PacketPLU::PacketPLU(int f_id, UpdateType f_type) : + AOPacket(QStringList{""}) +{ + QJsonObject data_json; + data_json["id"] = f_id; + data_json["type"] = f_type; + + setContentField(0, QJsonDocument(data_json).toJson(QJsonDocument::Compact)); +} + +PacketInfo PacketPLU::getPacketInfo() const { return PacketInfo{.acl_permission = ACLRole::NONE, .min_args = 1, .header = "PLU"}; } + +void PacketPLU::handlePacket(AreaData *area, AOClient &client) const +{ + Q_UNUSED(area); + Q_UNUSED(client); +} + +PacketPU::PacketPU(QStringList &contents) : + AOPacket(contents) +{} + +PacketPU::PacketPU(int f_id, DataType f_type, const QString &f_data) : + AOPacket(QStringList{""}) +{ + QJsonObject data_json; + data_json["id"] = f_id; + data_json["type"] = f_type; + data_json["data"] = f_data; + + setContentField(0, QJsonDocument(data_json).toJson(QJsonDocument::Compact)); +} + +PacketPU::PacketPU(int f_id, DataType f_type, int f_data) : + PacketPU(f_id, f_type, QString::number(f_data)) +{ +} + +PacketInfo PacketPU::getPacketInfo() const +{ + return PacketInfo{.acl_permission = ACLRole::NONE, .min_args = 1, .header = "PU"}; +} + +void PacketPU::handlePacket(AreaData *area, AOClient &client) const +{ + Q_UNUSED(area); + Q_UNUSED(client); +} diff --git a/src/packet/packet_pl.h b/src/packet/packet_pl.h new file mode 100644 index 0000000..be6337d --- /dev/null +++ b/src/packet/packet_pl.h @@ -0,0 +1,59 @@ +#pragma once + +#include "network/aopacket.h" + +#include +#include +#include +#include + +class PacketPL : public AOPacket +{ + public: + struct PlayerData + { + int id; + QString name; + QString character; + QString character_name; + int area_id = -1; + }; + + PacketPL(QStringList &contents); + PacketPL(const QList &f_player_list); + PacketInfo getPacketInfo() const override; + void handlePacket(AreaData *area, AOClient &client) const override; +}; + +class PacketPLU : public AOPacket +{ + public: + enum UpdateType + { + AddPlayerUpdate, + RemovePlayerUpdate, + }; + + PacketPLU(QStringList &contents); + PacketPLU(int f_id, UpdateType f_type); + PacketInfo getPacketInfo() const override; + void handlePacket(AreaData *area, AOClient &client) const override; +}; + +class PacketPU : public AOPacket +{ + public: + enum DataType + { + NameData, + CharacterData, + CharacterNameData, + AreaIdData, + }; + + PacketPU(QStringList &contents); + PacketPU(int f_id, DataType f_type, const QString &f_data); + PacketPU(int f_id, DataType f_type, int f_data); + PacketInfo getPacketInfo() const override; + void handlePacket(AreaData *area, AOClient &client) const override; +}; diff --git a/core/src/packet/packet_pw.cpp b/src/packet/packet_pw.cpp similarity index 76% rename from core/src/packet/packet_pw.cpp rename to src/packet/packet_pw.cpp index dcaf84a..38395a1 100644 --- a/core/src/packet/packet_pw.cpp +++ b/src/packet/packet_pw.cpp @@ -1,5 +1,5 @@ -#include "include/packet/packet_pw.h" -#include "include/server.h" +#include "packet/packet_pw.h" +#include "server.h" #include @@ -23,8 +23,3 @@ void PacketPW::handlePacket(AreaData *area, AOClient &client) const client.m_password = m_content[0]; } - -bool PacketPW::validatePacket() const -{ - return true; -} diff --git a/core/include/packet/packet_pw.h b/src/packet/packet_pw.h similarity index 76% rename from core/include/packet/packet_pw.h rename to src/packet/packet_pw.h index 7a9ddba..22db02a 100644 --- a/core/include/packet/packet_pw.h +++ b/src/packet/packet_pw.h @@ -1,7 +1,7 @@ #ifndef PACKET_PW_H #define PACKET_PW_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketPW : public AOPacket { @@ -9,6 +9,5 @@ class PacketPW : public AOPacket PacketPW(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; }; #endif diff --git a/core/src/packet/packet_rc.cpp b/src/packet/packet_rc.cpp similarity index 77% rename from core/src/packet/packet_rc.cpp rename to src/packet/packet_rc.cpp index 02d429c..966667d 100644 --- a/core/src/packet/packet_rc.cpp +++ b/src/packet/packet_rc.cpp @@ -1,5 +1,5 @@ -#include "include/packet/packet_rc.h" -#include "include/server.h" +#include "packet/packet_rc.h" +#include "server.h" #include @@ -23,8 +23,3 @@ void PacketRC::handlePacket(AreaData *area, AOClient &client) const client.sendPacket("SC", client.getServer()->getCharacters()); } - -bool PacketRC::validatePacket() const -{ - return true; -} diff --git a/core/include/packet/packet_rc.h b/src/packet/packet_rc.h similarity index 76% rename from core/include/packet/packet_rc.h rename to src/packet/packet_rc.h index f7fb1bf..2640478 100644 --- a/core/include/packet/packet_rc.h +++ b/src/packet/packet_rc.h @@ -1,7 +1,7 @@ #ifndef PACKET_RC_H #define PACKET_RC_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketRC : public AOPacket { @@ -9,6 +9,5 @@ class PacketRC : public AOPacket PacketRC(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; }; #endif diff --git a/core/src/packet/packet_rd.cpp b/src/packet/packet_rd.cpp similarity index 91% rename from core/src/packet/packet_rd.cpp rename to src/packet/packet_rd.cpp index 6756488..3366e18 100644 --- a/core/src/packet/packet_rd.cpp +++ b/src/packet/packet_rd.cpp @@ -1,6 +1,6 @@ -#include "include/packet/packet_rd.h" -#include "include/config_manager.h" -#include "include/server.h" +#include "packet/packet_rd.h" +#include "config_manager.h" +#include "server.h" #include @@ -62,11 +62,6 @@ void PacketRD::handlePacket(AreaData *area, AOClient &client) const } } emit client.joined(); - area->clientJoinedArea(-1, client.m_id); + area->addClient(-1, client.clientId()); client.arup(client.ARUPType::PLAYER_COUNT, true); // Tell everyone there is a new player } - -bool PacketRD::validatePacket() const -{ - return true; -} diff --git a/core/include/packet/packet_rd.h b/src/packet/packet_rd.h similarity index 76% rename from core/include/packet/packet_rd.h rename to src/packet/packet_rd.h index 4f51b87..2613d01 100644 --- a/core/include/packet/packet_rd.h +++ b/src/packet/packet_rd.h @@ -1,7 +1,7 @@ #ifndef PACKET_RD_H #define PACKET_RD_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketRD : public AOPacket { @@ -9,6 +9,5 @@ class PacketRD : public AOPacket PacketRD(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; }; #endif diff --git a/core/src/packet/packet_rm.cpp b/src/packet/packet_rm.cpp similarity index 78% rename from core/src/packet/packet_rm.cpp rename to src/packet/packet_rm.cpp index 99f2ce2..5140a4a 100644 --- a/core/src/packet/packet_rm.cpp +++ b/src/packet/packet_rm.cpp @@ -1,5 +1,5 @@ -#include "include/packet/packet_rm.h" -#include "include/server.h" +#include "packet/packet_rm.h" +#include "server.h" #include @@ -23,8 +23,3 @@ void PacketRM::handlePacket(AreaData *area, AOClient &client) const client.sendPacket("SM", client.getServer()->getAreaNames() + client.getServer()->getMusicList()); } - -bool PacketRM::validatePacket() const -{ - return true; -} diff --git a/core/include/packet/packet_rm.h b/src/packet/packet_rm.h similarity index 76% rename from core/include/packet/packet_rm.h rename to src/packet/packet_rm.h index 91b4b8e..b5fd5b0 100644 --- a/core/include/packet/packet_rm.h +++ b/src/packet/packet_rm.h @@ -1,7 +1,7 @@ #ifndef PACKET_RM_H #define PACKET_RM_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketRM : public AOPacket { @@ -9,6 +9,5 @@ class PacketRM : public AOPacket PacketRM(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; }; #endif diff --git a/core/src/packet/packet_rt.cpp b/src/packet/packet_rt.cpp similarity index 81% rename from core/src/packet/packet_rt.cpp rename to src/packet/packet_rt.cpp index 104e3d4..98eb5da 100644 --- a/core/src/packet/packet_rt.cpp +++ b/src/packet/packet_rt.cpp @@ -1,6 +1,6 @@ -#include "include/packet/packet_rt.h" -#include "include/packet/packet_factory.h" -#include "include/server.h" +#include "packet/packet_rt.h" +#include "packet/packet_factory.h" +#include "server.h" #include @@ -33,11 +33,6 @@ void PacketRT::handlePacket(AreaData *area, AOClient &client) const if (QDateTime::currentDateTime().toSecsSinceEpoch() - client.m_last_wtce_time <= 5) return; client.m_last_wtce_time = QDateTime::currentDateTime().toSecsSinceEpoch(); - client.getServer()->broadcast(PacketFactory::createPacket("RT", m_content), client.m_current_area); + client.getServer()->broadcast(PacketFactory::createPacket("RT", m_content), client.areaId()); client.updateJudgeLog(area, &client, "WT/CE"); } - -bool PacketRT::validatePacket() const -{ - return true; -} diff --git a/core/include/packet/packet_rt.h b/src/packet/packet_rt.h similarity index 76% rename from core/include/packet/packet_rt.h rename to src/packet/packet_rt.h index 604fd8d..9d2c854 100644 --- a/core/include/packet/packet_rt.h +++ b/src/packet/packet_rt.h @@ -1,7 +1,7 @@ #ifndef PACKET_RT_H #define PACKET_RT_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketRT : public AOPacket { @@ -9,6 +9,5 @@ class PacketRT : public AOPacket PacketRT(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; }; #endif diff --git a/core/src/packet/packet_setcase.cpp b/src/packet/packet_setcase.cpp similarity index 83% rename from core/src/packet/packet_setcase.cpp rename to src/packet/packet_setcase.cpp index 9303194..a929a02 100644 --- a/core/src/packet/packet_setcase.cpp +++ b/src/packet/packet_setcase.cpp @@ -1,5 +1,5 @@ -#include "include/packet/packet_setcase.h" -#include "include/server.h" +#include "packet/packet_setcase.h" +#include "server.h" #include @@ -31,8 +31,3 @@ void PacketSetcase::handlePacket(AreaData *area, AOClient &client) const } client.m_casing_preferences = l_prefs_list; } - -bool PacketSetcase::validatePacket() const -{ - return true; -} diff --git a/core/include/packet/packet_setcase.h b/src/packet/packet_setcase.h similarity index 77% rename from core/include/packet/packet_setcase.h rename to src/packet/packet_setcase.h index 1df3b13..c9628fb 100644 --- a/core/include/packet/packet_setcase.h +++ b/src/packet/packet_setcase.h @@ -1,7 +1,7 @@ #ifndef PACKET_SETCASE_H #define PACKET_SETCASE_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketSetcase : public AOPacket { @@ -9,6 +9,5 @@ class PacketSetcase : public AOPacket PacketSetcase(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; }; #endif diff --git a/core/src/packet/packet_zz.cpp b/src/packet/packet_zz.cpp similarity index 65% rename from core/src/packet/packet_zz.cpp rename to src/packet/packet_zz.cpp index 69a31c2..92bc4ef 100644 --- a/core/src/packet/packet_zz.cpp +++ b/src/packet/packet_zz.cpp @@ -1,7 +1,7 @@ -#include "include/packet/packet_zz.h" -#include "include/config_manager.h" -#include "include/packet/packet_factory.h" -#include "include/server.h" +#include "packet/packet_zz.h" +#include "config_manager.h" +#include "packet/packet_factory.h" +#include "server.h" #include @@ -21,9 +21,9 @@ PacketInfo PacketZZ::getPacketInfo() const void PacketZZ::handlePacket(AreaData *area, AOClient &client) const { - QString l_name = client.m_ooc_name; - if (client.m_ooc_name.isEmpty()) - l_name = client.m_current_char; + QString l_name = client.name(); + if (client.name().isEmpty()) + l_name = client.character(); QString l_areaName = area->name(); @@ -39,19 +39,14 @@ void PacketZZ::handlePacket(AreaData *area, AOClient &client) const if (l_client->m_authenticated) l_client->sendPacket(PacketFactory::createPacket("ZZ", {l_modcallNotice})); } - emit client.logModcall((client.m_current_char + " " + client.m_showname), client.m_ipid, client.m_ooc_name, client.getServer()->getAreaById(client.m_current_area)->name()); + emit client.logModcall((client.character() + " " + client.characterName()), client.m_ipid, client.name(), client.getServer()->getAreaById(client.areaId())->name()); if (ConfigManager::discordModcallWebhookEnabled()) { - QString l_name = client.m_ooc_name; - if (client.m_ooc_name.isEmpty()) - l_name = client.m_current_char; + QString l_name = client.name(); + if (client.name().isEmpty()) + l_name = client.character(); QString l_areaName = area->name(); emit client.getServer()->modcallWebhookRequest(l_name, l_areaName, m_content.value(0), client.getServer()->getAreaBuffer(l_areaName)); } } - -bool PacketZZ::validatePacket() const -{ - return true; -} diff --git a/core/include/packet/packet_zz.h b/src/packet/packet_zz.h similarity index 76% rename from core/include/packet/packet_zz.h rename to src/packet/packet_zz.h index 8920863..086a601 100644 --- a/core/include/packet/packet_zz.h +++ b/src/packet/packet_zz.h @@ -1,7 +1,7 @@ #ifndef PACKET_ZZ_H #define PACKET_ZZ_H -#include "include/network/aopacket.h" +#include "network/aopacket.h" class PacketZZ : public AOPacket { @@ -9,6 +9,5 @@ class PacketZZ : public AOPacket PacketZZ(QStringList &contents); virtual PacketInfo getPacketInfo() const; virtual void handlePacket(AreaData *area, AOClient &client) const; - virtual bool validatePacket() const; }; #endif diff --git a/core/src/packets.cpp b/src/packets.cpp similarity index 88% rename from core/src/packets.cpp rename to src/packets.cpp index 2bef526..e7a433e 100644 --- a/core/src/packets.cpp +++ b/src/packets.cpp @@ -15,23 +15,23 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/aoclient.h" +#include "aoclient.h" #include -#include "include/akashidefs.h" -#include "include/area_data.h" -#include "include/config_manager.h" -#include "include/db_manager.h" -#include "include/music_manager.h" -#include "include/packet/packet_factory.h" -#include "include/server.h" +#include "akashidefs.h" +#include "area_data.h" +#include "config_manager.h" +#include "db_manager.h" +#include "music_manager.h" +#include "packet/packet_factory.h" +#include "server.h" void AOClient::sendEvidenceList(AreaData *area) const { const QVector l_clients = server->getClients(); for (AOClient *l_client : l_clients) { - if (l_client->m_current_area == m_current_area) + if (l_client->areaId() == areaId()) l_client->updateEvidenceList(area); } } @@ -85,8 +85,8 @@ bool AOClient::checkEvidenceAccess(AreaData *area) void AOClient::updateJudgeLog(AreaData *area, AOClient *client, QString action) { QString l_timestamp = QTime::currentTime().toString("hh:mm:ss"); - QString l_uid = QString::number(client->m_id); - QString l_char_name = client->m_current_char; + QString l_uid = QString::number(client->clientId()); + QString l_char_name = client->character(); QString l_ipid = client->getIpid(); QString l_message = action; QString l_logmessage = QString("[%1]: [%2] %3 (%4) %5").arg(l_timestamp, l_uid, l_char_name, l_ipid, l_message); @@ -116,8 +116,8 @@ void AOClient::loginAttempt(QString message) sendPacket("AUTH", {"0"}); // Client: "Login unsuccessful." sendServerMessage("Incorrect password."); } - emit logLogin((m_current_char + " " + m_showname), m_ooc_name, "Moderator", - m_ipid, server->getAreaById(m_current_area)->name(), m_authenticated); + emit logLogin((character() + " " + characterName()), name(), "Moderator", + m_ipid, server->getAreaById(areaId())->name(), m_authenticated); break; case DataTypes::AuthType::ADVANCED: QStringList l_login = message.split(" "); @@ -142,8 +142,8 @@ void AOClient::loginAttempt(QString message) sendPacket("AUTH", {"0"}); // Client: "Login unsuccessful." sendServerMessage("Incorrect password."); } - emit logLogin((m_current_char + " " + m_showname), m_ooc_name, username, m_ipid, - server->getAreaById(m_current_area)->name(), m_authenticated); + emit logLogin((character() + " " + characterName()), name(), username, m_ipid, + server->getAreaById(areaId())->name(), m_authenticated); break; } sendServerMessage("Exiting login prompt."); diff --git a/src/playerstateobserver.cpp b/src/playerstateobserver.cpp new file mode 100644 index 0000000..64a82de --- /dev/null +++ b/src/playerstateobserver.cpp @@ -0,0 +1,81 @@ +#include "playerstateobserver.h" + +PlayerStateObserver::PlayerStateObserver(QObject *parent) : + QObject{parent} +{} + +PlayerStateObserver::~PlayerStateObserver() {} + +void PlayerStateObserver::registerClient(AOClient *client) +{ + Q_ASSERT(!m_client_list.contains(client)); + + PacketPLU packet(client->clientId(), PacketPLU::AddPlayerUpdate); + sendToClientList(packet); + + m_client_list.append(client); + + connect(client, &AOClient::nameChanged, this, &PlayerStateObserver::notifyNameChanged); + connect(client, &AOClient::characterChanged, this, &PlayerStateObserver::notifyCharacterChanged); + connect(client, &AOClient::characterNameChanged, this, &PlayerStateObserver::notifyCharacterNameChanged); + connect(client, &AOClient::areaIdChanged, this, &PlayerStateObserver::notifyAreaIdChanged); + + { // provide the player list to the new client + QList data_list; + for (AOClient *i_client : qAsConst(m_client_list)) { + PacketPL::PlayerData data; + data.id = i_client->clientId(); + data.name = i_client->name(); + data.character = i_client->character(); + data.character_name = i_client->characterName(); + data.area_id = i_client->areaId(); + data_list.append(data); + } + + PacketPL packet(data_list); + client->sendPacket(&packet); + } +} + +void PlayerStateObserver::unregisterClient(AOClient *client) +{ + Q_ASSERT(m_client_list.contains(client)); + + disconnect(client, nullptr, this, nullptr); + + m_client_list.removeAll(client); + + PacketPLU packet(client->clientId(), PacketPLU::RemovePlayerUpdate); + sendToClientList(packet); +} + +void PlayerStateObserver::sendToClientList(const AOPacket &packet) +{ + for (AOClient *client : qAsConst(m_client_list)) { + client->sendPacket(&const_cast(packet)); + } +} + +void PlayerStateObserver::notifyNameChanged(const QString &name) +{ + qDebug() << "PlayerStateObserver::notifyNameChanged" << qobject_cast(sender())->clientId() << name; + sendToClientList(PacketPU(qobject_cast(sender())->clientId(), PacketPU::NameData, name)); +} + +void PlayerStateObserver::notifyCharacterChanged(const QString &character) +{ + qDebug() << "PlayerStateObserver::notifyCharacterChanged" << qobject_cast(sender())->clientId() << character; + sendToClientList(PacketPU(qobject_cast(sender())->clientId(), PacketPU::CharacterData, character)); +} + +void PlayerStateObserver::notifyCharacterNameChanged(const QString &characterName) +{ + qDebug() << "PlayerStateObserver::notifyCharacterNameChanged" << qobject_cast(sender())->clientId() << characterName; + sendToClientList(PacketPU(qobject_cast(sender())->clientId(), PacketPU::CharacterNameData, characterName)); +} + +void PlayerStateObserver::notifyAreaIdChanged(int areaId) +{ + qDebug() << "PlayerStateObserver::notifyAreaIdChanged" << qobject_cast(sender())->clientId() << areaId; + sendToClientList(PacketPU(qobject_cast(sender())->clientId(), PacketPU::AreaIdData, areaId)); +} diff --git a/src/playerstateobserver.h b/src/playerstateobserver.h new file mode 100644 index 0000000..7cb8f96 --- /dev/null +++ b/src/playerstateobserver.h @@ -0,0 +1,29 @@ +#pragma once + +#include "aoclient.h" +#include "packet/packet_pl.h" + +#include +#include +#include + +class PlayerStateObserver : public QObject +{ + public: + explicit PlayerStateObserver(QObject *parent = nullptr); + virtual ~PlayerStateObserver(); + + void registerClient(AOClient *client); + void unregisterClient(AOClient *client); + + private: + QList m_client_list; + + void sendToClientList(const AOPacket &packet); + + private Q_SLOTS: + void notifyNameChanged(const QString &name); + void notifyCharacterChanged(const QString &character); + void notifyCharacterNameChanged(const QString &characterName); + void notifyAreaIdChanged(int areaId); +}; diff --git a/core/src/server.cpp b/src/server.cpp similarity index 97% rename from core/src/server.cpp rename to src/server.cpp index 8074495..9eeead7 100644 --- a/core/src/server.cpp +++ b/src/server.cpp @@ -15,20 +15,20 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/server.h" +#include "server.h" -#include "include/acl_roles_handler.h" -#include "include/advertiser.h" -#include "include/aoclient.h" -#include "include/area_data.h" -#include "include/command_extension.h" -#include "include/config_manager.h" -#include "include/db_manager.h" -#include "include/discord.h" -#include "include/logger/u_logger.h" -#include "include/music_manager.h" -#include "include/network/network_socket.h" -#include "include/packet/packet_factory.h" +#include "acl_roles_handler.h" +#include "advertiser.h" +#include "aoclient.h" +#include "area_data.h" +#include "command_extension.h" +#include "config_manager.h" +#include "db_manager.h" +#include "discord.h" +#include "logger/u_logger.h" +#include "music_manager.h" +#include "network/network_socket.h" +#include "packet/packet_factory.h" Server::Server(int p_port, int p_ws_port, QObject *parent) : QObject(parent), @@ -180,6 +180,7 @@ void Server::clientConnected() NetworkSocket *l_socket = new NetworkSocket(socket, socket); AOClient *client = new AOClient(this, l_socket, l_socket, user_id, music_manager); m_clients_ids.insert(user_id, client); + m_player_state_observer.registerClient(client); int multiclient_count = 1; bool is_at_multiclient_limit = false; @@ -267,6 +268,7 @@ void Server::ws_clientConnected() int user_id = m_available_ids.pop(); AOClient *client = new AOClient(this, l_socket, l_socket, user_id, music_manager); m_clients_ids.insert(user_id, client); + m_player_state_observer.registerClient(client); int multiclient_count = 1; bool is_at_multiclient_limit = false; @@ -344,7 +346,7 @@ void Server::updateCharsTaken(AreaData *area) AOPacket *response_cc = PacketFactory::createPacket("CharsCheck", chars_taken); for (AOClient *l_client : qAsConst(m_clients)) { - if (l_client->m_current_area == area->index()) { + if (l_client->areaId() == area->index()) { if (!l_client->m_is_charcursed) l_client->sendPacket(response_cc); else { @@ -619,8 +621,9 @@ void Server::handleDiscordIntegration() void Server::markIDFree(const int &f_user_id) { - m_available_ids.push(f_user_id); + m_player_state_observer.unregisterClient(m_clients_ids[f_user_id]); m_clients_ids.insert(f_user_id, nullptr); + m_available_ids.push(f_user_id); } void Server::hookupAOClient(AOClient *client) diff --git a/core/include/server.h b/src/server.h similarity index 99% rename from core/include/server.h rename to src/server.h index 9485441..d9b4a30 100644 --- a/core/include/server.h +++ b/src/server.h @@ -31,7 +31,8 @@ #include #include -#include "include/network/aopacket.h" +#include "network/aopacket.h" +#include "playerstateobserver.h" class ACLRolesHandler; class Advertiser; @@ -481,6 +482,7 @@ class Server : public QObject * @brief Collection of all clients with their userID as key. */ QHash m_clients_ids; + PlayerStateObserver m_player_state_observer; /** * @brief Stack of all available IDs for clients. When this is empty the server diff --git a/core/src/testimony_recorder.cpp b/src/testimony_recorder.cpp similarity index 92% rename from core/src/testimony_recorder.cpp rename to src/testimony_recorder.cpp index cae278c..1940ed8 100644 --- a/core/src/testimony_recorder.cpp +++ b/src/testimony_recorder.cpp @@ -15,18 +15,18 @@ // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////////////// -#include "include/aoclient.h" +#include "aoclient.h" -#include "include/area_data.h" -#include "include/config_manager.h" -#include "include/server.h" +#include "area_data.h" +#include "config_manager.h" +#include "server.h" void AOClient::addStatement(QStringList packet) { if (checkTestimonySymbols(packet[4])) { return; } - AreaData *area = server->getAreaById(m_current_area); + AreaData *area = server->getAreaById(areaId()); int c_statement = area->statement(); if (c_statement >= -1) { if (area->testimonyRecording() == AreaData::TestimonyRecording::RECORDING) { @@ -59,7 +59,7 @@ QStringList AOClient::updateStatement(QStringList packet) if (checkTestimonySymbols(packet[4])) { return packet; } - AreaData *area = server->getAreaById(m_current_area); + AreaData *area = server->getAreaById(areaId()); int c_statement = area->statement(); area->setTestimonyRecording(AreaData::TestimonyRecording::PLAYBACK); if (c_statement <= 0 || area->testimony()[c_statement].empty()) @@ -75,7 +75,7 @@ QStringList AOClient::updateStatement(QStringList packet) void AOClient::clearTestimony() { - AreaData *area = server->getAreaById(m_current_area); + AreaData *area = server->getAreaById(areaId()); area->clearTestimony(); } diff --git a/core/include/typedefs.h b/src/typedefs.h similarity index 100% rename from core/include/typedefs.h rename to src/typedefs.h diff --git a/tests/tests_common.pri b/tests/tests_common.pri index f50decc..cae326c 100644 --- a/tests/tests_common.pri +++ b/tests/tests_common.pri @@ -11,8 +11,6 @@ coverage { DESTDIR = $$PWD/../bin_tests -win32: LIBS += -L$$PWD/../bin/ -lcore -else:unix: LIBS += -L$$PWD/../bin/ -lcore +INCLUDEPATH += $$PWD/../src -INCLUDEPATH += $$PWD/../core -DEPENDPATH += $$PWD/../core +LIBS += -L$$PWD/../bin -lcore diff --git a/tests/unittest_acl_roles_handler/tst_unittest_acl_roles_handler.cpp b/tests/unittest_acl_roles_handler/tst_unittest_acl_roles_handler.cpp index 8518198..36d585a 100644 --- a/tests/unittest_acl_roles_handler/tst_unittest_acl_roles_handler.cpp +++ b/tests/unittest_acl_roles_handler/tst_unittest_acl_roles_handler.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include "acl_roles_handler.h" namespace tests { namespace unittests { diff --git a/tests/unittest_acl_roles_handler/unittest_acl_roles_handler.pro b/tests/unittest_acl_roles_handler/unittest_acl_roles_handler.pro index 384aea9..a7cd07d 100644 --- a/tests/unittest_acl_roles_handler/unittest_acl_roles_handler.pro +++ b/tests/unittest_acl_roles_handler/unittest_acl_roles_handler.pro @@ -2,4 +2,5 @@ QT -= gui include(../tests_common.pri) -SOURCES += tst_unittest_acl_roles_handler.cpp +SOURCES += \ + tst_unittest_acl_roles_handler.cpp diff --git a/tests/unittest_akashi_utils/tst_unittest_akashi_utils.cpp b/tests/unittest_akashi_utils/tst_unittest_akashi_utils.cpp index 2225e0c..cba0f94 100644 --- a/tests/unittest_akashi_utils/tst_unittest_akashi_utils.cpp +++ b/tests/unittest_akashi_utils/tst_unittest_akashi_utils.cpp @@ -1,4 +1,4 @@ -#include "include/akashiutils.h" +#include "akashiutils.h" #include namespace tests { diff --git a/tests/unittest_akashi_utils/unittest_akashi_utils.pro b/tests/unittest_akashi_utils/unittest_akashi_utils.pro index 66c7980..747f68b 100644 --- a/tests/unittest_akashi_utils/unittest_akashi_utils.pro +++ b/tests/unittest_akashi_utils/unittest_akashi_utils.pro @@ -2,4 +2,5 @@ QT -= gui include(../tests_common.pri) -SOURCES += tst_unittest_akashi_utils.cpp +SOURCES += \ + tst_unittest_akashi_utils.cpp diff --git a/tests/unittest_aopacket/tst_unittest_aopacket.cpp b/tests/unittest_aopacket/tst_unittest_aopacket.cpp index 87d9ffe..dceea96 100644 --- a/tests/unittest_aopacket/tst_unittest_aopacket.cpp +++ b/tests/unittest_aopacket/tst_unittest_aopacket.cpp @@ -1,8 +1,8 @@ #include #include -#include "include/network/aopacket.h" -#include "include/packet/packet_factory.h" +#include "network/aopacket.h" +#include "packet/packet_factory.h" namespace tests { namespace unittests { diff --git a/tests/unittest_aopacket/unittest_aopacket.pro b/tests/unittest_aopacket/unittest_aopacket.pro index d8f3ba0..548bbf9 100644 --- a/tests/unittest_aopacket/unittest_aopacket.pro +++ b/tests/unittest_aopacket/unittest_aopacket.pro @@ -2,4 +2,5 @@ QT -= gui include(../tests_common.pri) -SOURCES += tst_unittest_aopacket.cpp +SOURCES += \ + tst_unittest_aopacket.cpp diff --git a/tests/unittest_area/tst_unittest_area.cpp b/tests/unittest_area/tst_unittest_area.cpp index f7c10fd..1b00d67 100644 --- a/tests/unittest_area/tst_unittest_area.cpp +++ b/tests/unittest_area/tst_unittest_area.cpp @@ -1,6 +1,6 @@ #include -#include +#include "area_data.h" Q_DECLARE_METATYPE(AreaData::Side); @@ -78,14 +78,14 @@ void Area::clientJoinLeave() { { // There must be exactly one client in the area, and it must have a charid of 5 and userid 0. - m_area->clientJoinedArea(5, 0); + m_area->addClient(5, 0); QCOMPARE(m_area->joinedIDs().size(), 1); QCOMPARE(m_area->charactersTaken().at(0), 5); } { // No clients must be left in the area. - m_area->clientLeftArea(5, 0); + m_area->removeClient(5, 0); QCOMPARE(m_area->joinedIDs().size(), 0); } @@ -153,7 +153,7 @@ void Area::changeCharacter() { { // A client with a charid of 6 and userid 0 joins. There's only them in there. - m_area->clientJoinedArea(6, 0); + m_area->addClient(6, 0); QCOMPARE(m_area->charactersTaken().size(), 1); QCOMPARE(m_area->charactersTaken().at(0), 6); diff --git a/tests/unittest_area/unittest_area.pro b/tests/unittest_area/unittest_area.pro index cd33e8d..162d0e1 100644 --- a/tests/unittest_area/unittest_area.pro +++ b/tests/unittest_area/unittest_area.pro @@ -2,4 +2,5 @@ QT -= gui include(../tests_common.pri) -SOURCES += tst_unittest_area.cpp +SOURCES += \ + tst_unittest_area.cpp diff --git a/tests/unittest_command_extension/tst_unittest_command_extension.cpp b/tests/unittest_command_extension/tst_unittest_command_extension.cpp index 0faceca..990c28b 100644 --- a/tests/unittest_command_extension/tst_unittest_command_extension.cpp +++ b/tests/unittest_command_extension/tst_unittest_command_extension.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include "command_extension.h" namespace tests { namespace unittests { diff --git a/tests/unittest_command_extension/unittest_command_extension.pro b/tests/unittest_command_extension/unittest_command_extension.pro index 98503d0..cbfda84 100644 --- a/tests/unittest_command_extension/unittest_command_extension.pro +++ b/tests/unittest_command_extension/unittest_command_extension.pro @@ -2,5 +2,6 @@ QT -= gui include(../tests_common.pri) -SOURCES += \ +SOURCES += \ + \ tst_unittest_command_extension.cpp diff --git a/tests/unittest_config_manager/tst_unittest_config_manager.cpp b/tests/unittest_config_manager/tst_unittest_config_manager.cpp index 236761b..93a4fa3 100644 --- a/tests/unittest_config_manager/tst_unittest_config_manager.cpp +++ b/tests/unittest_config_manager/tst_unittest_config_manager.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include "config_manager.h" namespace tests { namespace unittests { diff --git a/tests/unittest_config_manager/unittest_config_manager.pro b/tests/unittest_config_manager/unittest_config_manager.pro index 8b37fcd..795f30e 100644 --- a/tests/unittest_config_manager/unittest_config_manager.pro +++ b/tests/unittest_config_manager/unittest_config_manager.pro @@ -2,4 +2,5 @@ QT -= gui include(../tests_common.pri) -SOURCES += tst_unittest_config_manager.cpp +SOURCES += \ + tst_unittest_config_manager.cpp diff --git a/tests/unittest_crypto/tst_unittest_crypto.cpp b/tests/unittest_crypto/tst_unittest_crypto.cpp index 0f107a2..338401e 100644 --- a/tests/unittest_crypto/tst_unittest_crypto.cpp +++ b/tests/unittest_crypto/tst_unittest_crypto.cpp @@ -1,6 +1,6 @@ #include -#include +#include "crypto_helper.h" namespace tests { namespace unittests { diff --git a/tests/unittest_crypto/unittest_crypto.pro b/tests/unittest_crypto/unittest_crypto.pro index d9cb213..1fab236 100644 --- a/tests/unittest_crypto/unittest_crypto.pro +++ b/tests/unittest_crypto/unittest_crypto.pro @@ -2,4 +2,5 @@ QT -= gui include(../tests_common.pri) -SOURCES += tst_unittest_crypto.cpp +SOURCES += \ + tst_unittest_crypto.cpp diff --git a/tests/unittest_music_manager/tst_unittest_music_manager.cpp b/tests/unittest_music_manager/tst_unittest_music_manager.cpp index 2b9e3a1..b21580d 100644 --- a/tests/unittest_music_manager/tst_unittest_music_manager.cpp +++ b/tests/unittest_music_manager/tst_unittest_music_manager.cpp @@ -1,6 +1,6 @@ #include -#include +#include "music_manager.h" namespace tests { namespace unittests { diff --git a/tests/unittest_music_manager/unittest_music_manager.pro b/tests/unittest_music_manager/unittest_music_manager.pro index 1b94722..0cb2cc9 100644 --- a/tests/unittest_music_manager/unittest_music_manager.pro +++ b/tests/unittest_music_manager/unittest_music_manager.pro @@ -2,4 +2,5 @@ QT -= gui include(../tests_common.pri) -SOURCES += tst_unittest_music_manager.cpp +SOURCES += \ + tst_unittest_music_manager.cpp