diff --git a/bin/config_sample/backgrounds.txt b/bin/config_sample/backgrounds.txt new file mode 100644 index 0000000..7a3316d --- /dev/null +++ b/bin/config_sample/backgrounds.txt @@ -0,0 +1,22 @@ +Anime +birthday +Christmas +CountyCourt +CruiseCourt +default +DGSEnglishCourt +DGSJapanCourt +DualDestinies +EnglishCourt +gs4 +GS4Night +HD +Khura'in +NewCourt +RuinedCourt +Sky +SpaceCourt +Themis +TouhouCourt +WitchTrialCourt +Zetta \ No newline at end of file diff --git a/include/aoclient.h b/include/aoclient.h index 00a8c34..9596fd3 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -57,6 +57,7 @@ class AOClient : public QObject { NONE = 0ULL, KICK = 1ULL << 0, BAN = 1ULL << 1, + BGLOCK = 1ULL << 2, SUPER = ~0ULL }; @@ -137,6 +138,9 @@ class AOClient : public QObject { void cmdKick(int argc, QStringList argv); void cmdChangeAuth(int argc, QStringList argv); void cmdSetRootPass(int argc, QStringList argv); + void cmdSetBackground(int argc, QStringList argv); + void cmdBgLock(int argc, QStringList argv); + void cmdBgUnlock(int argc, QStringList argv); // Command helper functions QStringList buildAreaList(int area_idx); @@ -157,7 +161,11 @@ class AOClient : public QObject { {"ban", {ACLFlags::BAN, 2, &AOClient::cmdBan}}, {"kick", {ACLFlags::KICK, 2, &AOClient::cmdKick}}, {"changeauth", {ACLFlags::SUPER, 0, &AOClient::cmdChangeAuth}}, - {"rootpass", {ACLFlags::SUPER, 1, &AOClient::cmdSetRootPass}} + {"rootpass", {ACLFlags::SUPER, 1, &AOClient::cmdSetRootPass}}, + {"background", {ACLFlags::NONE, 1, &AOClient::cmdSetBackground}}, + {"bg", {ACLFlags::NONE, 1, &AOClient::cmdSetBackground}}, + {"bglock", {ACLFlags::BGLOCK, 0, &AOClient::cmdBgLock}}, + {"bgunlock", {ACLFlags::BGLOCK, 0, &AOClient::cmdBgUnlock}} }; QString partial_packet; diff --git a/include/area_data.h b/include/area_data.h index f725656..32c6f08 100644 --- a/include/area_data.h +++ b/include/area_data.h @@ -39,6 +39,7 @@ class AreaData { bool showname_allowed; bool locking_allowed; bool iniswap_allowed; + bool bg_locked; int def_hp; int pro_hp; diff --git a/include/server.h b/include/server.h index 11b1ec0..b4a8a4a 100644 --- a/include/server.h +++ b/include/server.h @@ -56,6 +56,7 @@ class Server : public QObject { QVector areas; QStringList area_names; QStringList music_list; + QStringList backgrounds; DBManager* db_manager; signals: diff --git a/src/aoclient.cpp b/src/aoclient.cpp index 79af190..ccfd0ec 100644 --- a/src/aoclient.cpp +++ b/src/aoclient.cpp @@ -108,9 +108,10 @@ void AOClient::changeArea(int new_area) server->areas[current_area]->player_count--; current_area = new_area; arup(ARUPType::PLAYER_COUNT, true); - // send hp, bn, le + // send le sendPacket("HP", {"1", QString::number(server->areas[new_area]->def_hp)}); sendPacket("HP", {"2", QString::number(server->areas[new_area]->pro_hp)}); + sendPacket("BN", {server->areas[new_area]->background}); if (server->areas[current_area]->characters_taken[current_char]) { server->updateCharsTaken(server->areas[current_area]); current_char = ""; diff --git a/src/area_data.cpp b/src/area_data.cpp index 31fb4b5..0dd9454 100644 --- a/src/area_data.cpp +++ b/src/area_data.cpp @@ -34,4 +34,5 @@ AreaData::AreaData(QStringList characters, QString p_name, int p_index) status = "FREE"; def_hp = 10; pro_hp = 10; + bg_locked = false; } diff --git a/src/commands.cpp b/src/commands.cpp index 1dfc187..c3e576b 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -165,6 +165,40 @@ void AOClient::cmdSetRootPass(int argc, QStringList argv) server->db_manager->createUser("root", salt, argv[0], ACLFlags::SUPER); } +void AOClient::cmdSetBackground(int argc, QStringList argv) +{ + // TODO: area locks in areas.ini + // TODO: sendServerMessage but area broadcast + AreaData* area = server->areas[current_area]; + if (authenticated || !area->bg_locked) { + if (server->backgrounds.contains(argv[0])) { + area->background = argv[0]; + server->broadcast(AOPacket("BN", {argv[0]}), current_area); + server->broadcast(AOPacket("CT", {"Server", current_char + " changed the background to " + argv[0], "1"}), current_area); + } + else { + sendServerMessage("Invalid background name."); + } + } + else { + sendServerMessage("This area's background is locked."); + } +} + +void AOClient::cmdBgLock(int argc, QStringList argv) +{ + AreaData* area = server->areas[current_area]; + area->bg_locked = true; + server->broadcast(AOPacket("CT", {"Server", current_char + " locked the background.", "1"}), current_area); +} + +void AOClient::cmdBgUnlock(int argc, QStringList argv) +{ + AreaData* area = server->areas[current_area]; + area->bg_locked = false; + server->broadcast(AOPacket("CT", {"Server", current_char + " unlocked the background.", "1"}), current_area); +} + QStringList AOClient::buildAreaList(int area_idx) { QStringList entries; diff --git a/src/config_manager.cpp b/src/config_manager.cpp index 3d5b75c..e240b51 100644 --- a/src/config_manager.cpp +++ b/src/config_manager.cpp @@ -33,6 +33,7 @@ bool ConfigManager::initConfig() QFileInfo areas_info("config/areas.ini"); QFileInfo characters_info("config/characters.txt"); QFileInfo music_info("config/music.txt"); + QFileInfo backgrounds_info("config/backgrounds.txt"); if (!fileExists(&areas_info)) { qCritical() << "areas.ini doesn't exist!"; @@ -53,6 +54,10 @@ bool ConfigManager::initConfig() qCritical() << "music.txt doesn't exist!"; return false; } + if (!fileExists(&backgrounds_info)) { + qCritical() << "backgrounds.txt doesn't exist!"; + return false; + } config.beginGroup("Info"); QString config_version = config.value("version", "none").toString(); diff --git a/src/packets.cpp b/src/packets.cpp index a031299..b1bb755 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -85,6 +85,7 @@ void AOClient::pktLoadingDone(AreaData* area, int argc, QStringList argv, AOPack sendPacket("HP", {"1", QString::number(area->def_hp)}); sendPacket("HP", {"2", QString::number(area->pro_hp)}); sendPacket("FA", server->area_names); + sendPacket("BN", {area->background}); sendPacket("OPPASS", {"DEADBEEF"}); sendPacket("DONE"); } diff --git a/src/server.cpp b/src/server.cpp index 8362f3c..74f175f 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -61,6 +61,13 @@ void Server::start() if(music_list[0].contains(".")) // Add a default category if none exists music_list.insert(0, "==Music=="); + QFile bg_file("config/backgrounds.txt"); + bg_file.open(QIODevice::ReadOnly | QIODevice::Text); + while (!bg_file.atEnd()) { + backgrounds.append(bg_file.readLine().trimmed()); + } + bg_file.close(); + // TODO: add verification that this exists QSettings areas_ini("config/areas.ini", QSettings::IniFormat); area_names = areas_ini.childGroups();