diff --git a/settings/default/network.lua b/settings/default/network.lua index 9234f21b14f..fd162104d46 100644 --- a/settings/default/network.lua +++ b/settings/default/network.lua @@ -30,8 +30,9 @@ xi.settings.network = SEARCH_PORT = 54002, - HTTP_HOST = "localhost", - HTTP_PORT = 8080, + ENABLE_HTTP = false, + HTTP_HOST = "localhost", + HTTP_PORT = 8088, -- Central message server settings (ensure these are the same on both all map servers and the central (lobby) server ZMQ_IP = "127.0.0.1", diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 57656f13c2c..4292847eaad 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -36,6 +36,8 @@ set(COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/xirand.h ${CMAKE_CURRENT_SOURCE_DIR}/utils.cpp ${CMAKE_CURRENT_SOURCE_DIR}/utils.h + ${CMAKE_CURRENT_SOURCE_DIR}/vana_time.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/vana_time.h ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp # auto-generated ${CMAKE_CURRENT_SOURCE_DIR}/version.h ${CMAKE_CURRENT_SOURCE_DIR}/watchdog.cpp diff --git a/src/map/vana_time.cpp b/src/common/vana_time.cpp similarity index 99% rename from src/map/vana_time.cpp rename to src/common/vana_time.cpp index de43b84866f..b87f8f8ad09 100644 --- a/src/map/vana_time.cpp +++ b/src/common/vana_time.cpp @@ -19,11 +19,10 @@ =========================================================================== */ -#include "../common/logging.h" +#include "common/logging.h" #include -#include "utils/zoneutils.h" #include "vana_time.h" CVanaTime* CVanaTime::_instance = nullptr; diff --git a/src/map/vana_time.h b/src/common/vana_time.h similarity index 100% rename from src/map/vana_time.h rename to src/common/vana_time.h diff --git a/src/map/CMakeLists.txt b/src/map/CMakeLists.txt index e0c5371e822..13a914b545d 100644 --- a/src/map/CMakeLists.txt +++ b/src/map/CMakeLists.txt @@ -124,8 +124,6 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/unitychat.h ${CMAKE_CURRENT_SOURCE_DIR}/universal_container.cpp ${CMAKE_CURRENT_SOURCE_DIR}/universal_container.h - ${CMAKE_CURRENT_SOURCE_DIR}/vana_time.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/vana_time.h ${CMAKE_CURRENT_SOURCE_DIR}/weapon_skill.cpp ${CMAKE_CURRENT_SOURCE_DIR}/weapon_skill.h ${CMAKE_CURRENT_SOURCE_DIR}/zone_entities.cpp diff --git a/src/map/conquest_system.cpp b/src/map/conquest_system.cpp index 192f617aad5..ca395ad53ce 100644 --- a/src/map/conquest_system.cpp +++ b/src/map/conquest_system.cpp @@ -20,10 +20,12 @@ */ #include "conquest_system.h" + +#include "common/vana_time.h" + #include "entities/charentity.h" #include "utils/charutils.h" #include "utils/zoneutils.h" -#include "vana_time.h" #include "packets/conquest_map.h" diff --git a/src/map/daily_system.cpp b/src/map/daily_system.cpp index 33372a0d9ec..a2d4d8409c9 100644 --- a/src/map/daily_system.cpp +++ b/src/map/daily_system.cpp @@ -1,4 +1,26 @@ +/* +=========================================================================== + +Copyright (c) 2022 LandSandBoat Dev Teams + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see http://www.gnu.org/licenses/ + +=========================================================================== +*/ + #include "daily_system.h" + #include "items/item.h" #include "utils/charutils.h" #include "utils/itemutils.h" @@ -11,7 +33,10 @@ namespace daily std::vector sundries1DialItems; std::vector sundries2DialItems; std::vector specialDialItems; - std::vector gobbieJunk = { + + // clang-format off + std::vector gobbieJunk = + { 2542, // Goblin Mess Tin 2543, // Goblin Weel 4324, // Hobgoblin Chocolate @@ -21,10 +46,10 @@ namespace daily 4495, // Goblin Chocolate 4539 // Goblin Pie }; + // clang-format on uint16 SelectItem(CCharEntity* player, uint8 dial) { - uint16 selection; std::vector* dialItems = &gobbieJunk; switch (dial) { @@ -59,7 +84,7 @@ namespace daily break; } } - selection = xirand::GetRandomElement(dialItems); + uint16 selection = xirand::GetRandomElement(dialItems); // Check if Rare item is already owned and substitute with Goblin trash item. if ((itemutils::GetItem(selection)->getFlag() & ITEM_FLAG_RARE) > 0 && charutils::HasItem(player, selection)) @@ -166,32 +191,4 @@ namespace daily ShowError("Failed to load daily tally items"); } } - - void UpdateDailyTallyPoints() - { - uint16 dailyTallyLimit = settings::get("main.DAILY_TALLY_LIMIT"); - uint16 dailyTallyAmount = settings::get("main.DAILY_TALLY_AMOUNT"); - - const char* fmtQuery = "UPDATE char_points \ - SET char_points.daily_tally = LEAST(%u, char_points.daily_tally + %u) \ - WHERE char_points.daily_tally > -1;"; - - int32 ret = sql->Query(fmtQuery, dailyTallyLimit, dailyTallyAmount); - - if (ret == SQL_ERROR) - { - ShowError("Failed to update daily tally points"); - } - else - { - ShowDebug("Distributed daily tally points"); - } - - fmtQuery = "DELETE FROM char_vars WHERE varname = 'gobbieBoxUsed';"; - - if (sql->Query(fmtQuery, dailyTallyAmount) == SQL_ERROR) - { - ShowError("Failed to delete daily tally char_vars entries"); - } - } } // namespace daily diff --git a/src/map/daily_system.h b/src/map/daily_system.h index cceba3c7c8f..f20e1e285fc 100644 --- a/src/map/daily_system.h +++ b/src/map/daily_system.h @@ -1,3 +1,24 @@ +/* +=========================================================================== + +Copyright (c) 2023 LandSandBoat Dev Teams + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see http://www.gnu.org/licenses/ + +=========================================================================== +*/ + #ifndef _DAILYSYSTEM_H #define _DAILYSYSTEM_H #include "map.h" @@ -6,7 +27,6 @@ namespace daily { uint16 SelectItem(CCharEntity* player, uint8 dial); void LoadDailyItems(); - void UpdateDailyTallyPoints(); } // namespace daily #endif //_DAILYSYSTEM_H diff --git a/src/map/items/item_usable.cpp b/src/map/items/item_usable.cpp index b9c5510602f..204b69f3d4e 100644 --- a/src/map/items/item_usable.cpp +++ b/src/map/items/item_usable.cpp @@ -19,12 +19,12 @@ =========================================================================== */ -#include "common/utils.h" - #include "item_usable.h" -#include "../map.h" -#include "../vana_time.h" +#include "common/utils.h" +#include "common/vana_time.h" + +#include "map.h" CItemUsable::CItemUsable(uint16 id) : CItem(id) diff --git a/src/map/lua/luautils.cpp b/src/map/lua/luautils.cpp index ef10424a561..bf2f8b73121 100644 --- a/src/map/lua/luautils.cpp +++ b/src/map/lua/luautils.cpp @@ -19,9 +19,12 @@ =========================================================================== */ +#include "luautils.h" + #include "common/filewatcher.h" #include "common/logging.h" #include "common/utils.h" +#include "common/vana_time.h" #include "common/version.h" #include @@ -43,7 +46,6 @@ #include "lua_trade_container.h" #include "lua_trigger_area.h" #include "lua_zone.h" -#include "luautils.h" #include "ability.h" #include "ai/ai_container.h" @@ -93,7 +95,6 @@ #include "utils/moduleutils.h" #include "utils/serverutils.h" #include "utils/zoneutils.h" -#include "vana_time.h" #include "weapon_skill.h" void ReportErrorToPlayer(CBaseEntity* PEntity, std::string const& message = "") noexcept diff --git a/src/map/map.cpp b/src/map/map.cpp index 3ff83f7c83d..0428ffb58b5 100755 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -19,12 +19,15 @@ along with this program. If not, see http://www.gnu.org/licenses/ =========================================================================== */ +#include "map.h" + #include "common/blowfish.h" #include "common/console_service.h" #include "common/logging.h" #include "common/md52.h" #include "common/timer.h" #include "common/utils.h" +#include "common/vana_time.h" #include "common/version.h" #include "common/zlib.h" @@ -37,7 +40,6 @@ along with this program. If not, see http://www.gnu.org/licenses/ #include "ability.h" #include "job_points.h" #include "linkshell.h" -#include "map.h" #include "message.h" #include "mob_spell_list.h" #include "packet_guard.h" @@ -47,7 +49,6 @@ along with this program. If not, see http://www.gnu.org/licenses/ #include "status_effect_container.h" #include "time_server.h" #include "transport.h" -#include "vana_time.h" #include "zone.h" #include "zone_entities.h" diff --git a/src/map/packets/auction_house.cpp b/src/map/packets/auction_house.cpp index d16b7606a0a..ab665b57994 100644 --- a/src/map/packets/auction_house.cpp +++ b/src/map/packets/auction_house.cpp @@ -19,16 +19,16 @@ =========================================================================== */ +#include "auction_house.h" + #include "common/socket.h" +#include "common/vana_time.h" #include -#include "auction_house.h" - -#include "../entities/charentity.h" -#include "../map.h" -#include "../utils/itemutils.h" -#include "../vana_time.h" +#include "entities/charentity.h" +#include "map.h" +#include "utils/itemutils.h" bool IsAuctionOpen = true; // Trading is allowed at the auction diff --git a/src/map/packets/bazaar_item.cpp b/src/map/packets/bazaar_item.cpp index ca557b32033..19048ef34b4 100644 --- a/src/map/packets/bazaar_item.cpp +++ b/src/map/packets/bazaar_item.cpp @@ -19,15 +19,15 @@ =========================================================================== */ +#include "bazaar_item.h" + #include "common/socket.h" #include "common/utils.h" +#include "common/vana_time.h" #include -#include "bazaar_item.h" - -#include "../utils/itemutils.h" -#include "../vana_time.h" +#include "utils/itemutils.h" CBazaarItemPacket::CBazaarItemPacket(CItem* PItem, uint8 SlotID, uint16 Tax) { diff --git a/src/map/packets/char_check.cpp b/src/map/packets/char_check.cpp index a803a3eb445..0c3eb858d97 100644 --- a/src/map/packets/char_check.cpp +++ b/src/map/packets/char_check.cpp @@ -19,16 +19,16 @@ =========================================================================== */ +#include "char_check.h" + #include "common/socket.h" #include "common/utils.h" +#include "common/vana_time.h" #include -#include "char_check.h" - -#include "../entities/charentity.h" -#include "../utils/itemutils.h" -#include "../vana_time.h" +#include "entities/charentity.h" +#include "utils/itemutils.h" CCheckPacket::CCheckPacket(CCharEntity* PChar, CCharEntity* PTarget) { diff --git a/src/map/packets/char_update.cpp b/src/map/packets/char_update.cpp index d2b4054db66..d0f71c2b05f 100644 --- a/src/map/packets/char_update.cpp +++ b/src/map/packets/char_update.cpp @@ -19,19 +19,19 @@ =========================================================================== */ +#include "char_update.h" + #include "common/logging.h" #include "common/socket.h" +#include "common/vana_time.h" #include -#include "char_update.h" - -#include "../ai/ai_container.h" -#include "../ai/states/death_state.h" -#include "../entities/charentity.h" -#include "../status_effect_container.h" -#include "../utils/itemutils.h" -#include "../vana_time.h" +#include "ai/ai_container.h" +#include "ai/states/death_state.h" +#include "entities/charentity.h" +#include "status_effect_container.h" +#include "utils/itemutils.h" CCharUpdatePacket::CCharUpdatePacket(CCharEntity* PChar) { diff --git a/src/map/packets/inventory_item.cpp b/src/map/packets/inventory_item.cpp index 09f835489a6..096956cd841 100644 --- a/src/map/packets/inventory_item.cpp +++ b/src/map/packets/inventory_item.cpp @@ -19,15 +19,15 @@ =========================================================================== */ +#include "inventory_item.h" + #include "common/socket.h" #include "common/utils.h" +#include "common/vana_time.h" #include -#include "inventory_item.h" - -#include "../utils/itemutils.h" -#include "../vana_time.h" +#include "utils/itemutils.h" CInventoryItemPacket::CInventoryItemPacket(CItem* PItem, uint8 LocationID, uint8 SlotID) { diff --git a/src/map/packets/trade_update.cpp b/src/map/packets/trade_update.cpp index 6a08a4bc871..9bb235b7235 100644 --- a/src/map/packets/trade_update.cpp +++ b/src/map/packets/trade_update.cpp @@ -19,15 +19,15 @@ =========================================================================== */ +#include "trade_update.h" + #include "common/socket.h" #include "common/utils.h" +#include "common/vana_time.h" #include -#include "../utils/itemutils.h" -#include "../vana_time.h" - -#include "trade_update.h" +#include "utils/itemutils.h" CTradeUpdatePacket::CTradeUpdatePacket(CItem* PItem, uint8 SlotID) { diff --git a/src/map/packets/zone_in.cpp b/src/map/packets/zone_in.cpp index b5d98578f3a..d9a335519f8 100644 --- a/src/map/packets/zone_in.cpp +++ b/src/map/packets/zone_in.cpp @@ -21,12 +21,13 @@ #include "zone_in.h" +#include "common/vana_time.h" + #include "entities/charentity.h" #include "utils/zoneutils.h" #include "instance.h" #include "status_effect_container.h" -#include "vana_time.h" #include "zone.h" // Returns the Model ID of the mog house to be used diff --git a/src/map/roe.cpp b/src/map/roe.cpp index c016d68b35a..718518c0ff1 100644 --- a/src/map/roe.cpp +++ b/src/map/roe.cpp @@ -18,14 +18,17 @@ =========================================================================== */ + +#include "roe.h" + +#include "common/vana_time.h" + #include #include "lua/luautils.h" #include "packets/chat_message.h" -#include "roe.h" #include "utils/charutils.h" #include "utils/zoneutils.h" -#include "vana_time.h" #include "packets/char_spells.h" #include "packets/roe_questlog.h" diff --git a/src/map/time_server.cpp b/src/map/time_server.cpp index 514fbd3f26d..83324bc75ac 100644 --- a/src/map/time_server.cpp +++ b/src/map/time_server.cpp @@ -19,7 +19,10 @@ =========================================================================== */ -#include "../common/logging.h" +#include "time_server.h" + +#include "common/logging.h" +#include "common/vana_time.h" #include "conquest_system.h" #include "daily_system.h" @@ -27,14 +30,12 @@ #include "latent_effect_container.h" #include "lua/luautils.h" #include "roe.h" -#include "time_server.h" #include "timetriggers.h" #include "transport.h" #include "utils/guildutils.h" #include "utils/instanceutils.h" #include "utils/moduleutils.h" #include "utils/zoneutils.h" -#include "vana_time.h" int32 time_server(time_point tick, CTaskMgr::CTask* PTask) { @@ -94,11 +95,6 @@ int32 time_server(time_point tick, CTaskMgr::CTask* PTask) { if (tick > (lastTickedJstMidnight + 1h)) { - if (settings::get("main.ENABLE_DAILY_TALLY")) - { - daily::UpdateDailyTallyPoints(); - } - if (settings::get("main.ENABLE_ROE")) { roeutils::CycleDailyRecords(); diff --git a/src/map/timetriggers.cpp b/src/map/timetriggers.cpp index 048f3d9c1a2..e3bb446ce2b 100644 --- a/src/map/timetriggers.cpp +++ b/src/map/timetriggers.cpp @@ -20,8 +20,10 @@ */ #include "timetriggers.h" + +#include "common/vana_time.h" + #include "lua/luautils.h" -#include "vana_time.h" std::unique_ptr CTriggerHandler::_instance; diff --git a/src/map/transport.cpp b/src/map/transport.cpp index 7df7353784b..b94802a7ab6 100644 --- a/src/map/transport.cpp +++ b/src/map/transport.cpp @@ -21,15 +21,17 @@ #include "transport.h" -#include "../common/timer.h" +#include "common/timer.h" +#include "common/vana_time.h" + +#include + #include "entities/charentity.h" #include "map.h" #include "packets/entity_update.h" #include "packets/event.h" #include "utils/zoneutils.h" -#include "vana_time.h" #include "zone.h" -#include std::unique_ptr CTransportHandler::_instance; diff --git a/src/map/utils/charutils.cpp b/src/map/utils/charutils.cpp index 91d5ca3f859..a34cb5067fd 100644 --- a/src/map/utils/charutils.cpp +++ b/src/map/utils/charutils.cpp @@ -24,6 +24,7 @@ along with this program. If not, see http://www.gnu.org/licenses/ #include "common/sql.h" #include "common/timer.h" #include "common/utils.h" +#include "common/vana_time.h" #include #include @@ -31,70 +32,69 @@ along with this program. If not, see http://www.gnu.org/licenses/ #include #include -#include "../lua/luautils.h" - -#include "../ai/ai_container.h" -#include "../ai/states/attack_state.h" -#include "../ai/states/item_state.h" - -#include "../packets/char_abilities.h" -#include "../packets/char_appearance.h" -#include "../packets/char_equip.h" -#include "../packets/char_health.h" -#include "../packets/char_job_extra.h" -#include "../packets/char_jobs.h" -#include "../packets/char_recast.h" -#include "../packets/char_skills.h" -#include "../packets/char_stats.h" -#include "../packets/char_sync.h" -#include "../packets/char_update.h" -#include "../packets/chat_message.h" -#include "../packets/conquest_map.h" -#include "../packets/delivery_box.h" -#include "../packets/inventory_assign.h" -#include "../packets/inventory_finish.h" -#include "../packets/inventory_item.h" -#include "../packets/inventory_modify.h" -#include "../packets/key_items.h" -#include "../packets/linkshell_equip.h" -#include "../packets/menu_jobpoints.h" -#include "../packets/menu_merit.h" -#include "../packets/message_basic.h" -#include "../packets/message_combat.h" -#include "../packets/message_special.h" -#include "../packets/message_standard.h" -#include "../packets/monipulator1.h" -#include "../packets/monipulator2.h" -#include "../packets/quest_mission_log.h" -#include "../packets/roe_sparkupdate.h" -#include "../packets/server_ip.h" -#include "../packets/timer_bar_util.h" - -#include "../ability.h" -#include "../alliance.h" -#include "../conquest_system.h" -#include "../grades.h" -#include "../item_container.h" -#include "../latent_effect_container.h" -#include "../linkshell.h" -#include "../map.h" -#include "../message.h" -#include "../mob_modifier.h" -#include "../recast_container.h" -#include "../roe.h" -#include "../spell.h" -#include "../status_effect_container.h" -#include "../trait.h" -#include "../treasure_pool.h" -#include "../unitychat.h" -#include "../universal_container.h" -#include "../vana_time.h" -#include "../weapon_skill.h" - -#include "../entities/automatonentity.h" -#include "../entities/charentity.h" -#include "../entities/mobentity.h" -#include "../entities/petentity.h" +#include "lua/luautils.h" + +#include "ai/ai_container.h" +#include "ai/states/attack_state.h" +#include "ai/states/item_state.h" + +#include "packets/char_abilities.h" +#include "packets/char_appearance.h" +#include "packets/char_equip.h" +#include "packets/char_health.h" +#include "packets/char_job_extra.h" +#include "packets/char_jobs.h" +#include "packets/char_recast.h" +#include "packets/char_skills.h" +#include "packets/char_stats.h" +#include "packets/char_sync.h" +#include "packets/char_update.h" +#include "packets/chat_message.h" +#include "packets/conquest_map.h" +#include "packets/delivery_box.h" +#include "packets/inventory_assign.h" +#include "packets/inventory_finish.h" +#include "packets/inventory_item.h" +#include "packets/inventory_modify.h" +#include "packets/key_items.h" +#include "packets/linkshell_equip.h" +#include "packets/menu_jobpoints.h" +#include "packets/menu_merit.h" +#include "packets/message_basic.h" +#include "packets/message_combat.h" +#include "packets/message_special.h" +#include "packets/message_standard.h" +#include "packets/monipulator1.h" +#include "packets/monipulator2.h" +#include "packets/quest_mission_log.h" +#include "packets/roe_sparkupdate.h" +#include "packets/server_ip.h" +#include "packets/timer_bar_util.h" + +#include "ability.h" +#include "alliance.h" +#include "conquest_system.h" +#include "grades.h" +#include "item_container.h" +#include "latent_effect_container.h" +#include "linkshell.h" +#include "map.h" +#include "message.h" +#include "mob_modifier.h" +#include "recast_container.h" +#include "roe.h" +#include "spell.h" +#include "status_effect_container.h" +#include "trait.h" +#include "treasure_pool.h" +#include "unitychat.h" +#include "universal_container.h" +#include "weapon_skill.h" + +#include "entities/automatonentity.h" +#include "entities/charentity.h" +#include "entities/mobentity.h" +#include "entities/petentity.h" #include "battleutils.h" #include "blueutils.h" diff --git a/src/map/utils/gardenutils.cpp b/src/map/utils/gardenutils.cpp index be9be308e04..d3e67ba97ec 100644 --- a/src/map/utils/gardenutils.cpp +++ b/src/map/utils/gardenutils.cpp @@ -23,14 +23,15 @@ #include "gardenutils.h" +#include "common/vana_time.h" + #include -#include "../entities/charentity.h" -#include "../item_container.h" -#include "../items/item_flowerpot.h" -#include "../map.h" -#include "../packets/inventory_item.h" -#include "../vana_time.h" +#include "entities/charentity.h" +#include "item_container.h" +#include "items/item_flowerpot.h" +#include "map.h" +#include "packets/inventory_item.h" #define MAX_RESULTID 2500 diff --git a/src/map/utils/guildutils.cpp b/src/map/utils/guildutils.cpp index 648317ad56b..b2c586133d9 100644 --- a/src/map/utils/guildutils.cpp +++ b/src/map/utils/guildutils.cpp @@ -19,17 +19,19 @@ =========================================================================== */ +#include "guildutils.h" + +#include "common/vana_time.h" + #include -#include "../items/item_shop.h" +#include "items/item_shop.h" -#include "../guild.h" -#include "../item_container.h" -#include "../map.h" -#include "../vana_time.h" #include "charutils.h" -#include "guildutils.h" +#include "guild.h" +#include "item_container.h" #include "itemutils.h" +#include "map.h" #include "serverutils.h" // TODO: During the closure of the guild, all viewing products of the goods are sent 0x86 with information about the closure of the guild diff --git a/src/map/utils/synthutils.cpp b/src/map/utils/synthutils.cpp index 3f732409c64..170ada632d7 100644 --- a/src/map/utils/synthutils.cpp +++ b/src/map/utils/synthutils.cpp @@ -19,33 +19,34 @@ =========================================================================== */ +#include "synthutils.h" + #include "common/logging.h" #include "common/socket.h" #include "common/utils.h" +#include "common/vana_time.h" #include #include -#include "../packets/char_skills.h" -#include "../packets/char_update.h" -#include "../packets/inventory_assign.h" -#include "../packets/inventory_finish.h" -#include "../packets/inventory_item.h" -#include "../packets/message_basic.h" -#include "../packets/synth_animation.h" -#include "../packets/synth_message.h" -#include "../packets/synth_result.h" - -#include "../anticheat.h" -#include "../item_container.h" -#include "../map.h" -#include "../roe.h" -#include "../trade_container.h" -#include "../vana_time.h" +#include "packets/char_skills.h" +#include "packets/char_update.h" +#include "packets/inventory_assign.h" +#include "packets/inventory_finish.h" +#include "packets/inventory_item.h" +#include "packets/message_basic.h" +#include "packets/synth_animation.h" +#include "packets/synth_message.h" +#include "packets/synth_result.h" + +#include "anticheat.h" +#include "item_container.h" +#include "map.h" +#include "roe.h" +#include "trade_container.h" #include "charutils.h" #include "itemutils.h" -#include "synthutils.h" #include "zoneutils.h" namespace synthutils diff --git a/src/map/zone.cpp b/src/map/zone.cpp index 3b213e95893..4b876cfe1e4 100644 --- a/src/map/zone.cpp +++ b/src/map/zone.cpp @@ -20,13 +20,16 @@ */ // TODO: -// нужно разделить класс czone на базовый и наследников. уже нарисовались: Standard, Rezident, Instance и Dinamis -// у каждой из указанных зон особое поведение +// It is necessary to divide the Czone class into basic and heirs. Already painted: Standard, Rezident, Instance and Dinamis +// Each of these zones has special behavior + +#include "zone.h" #include "common/logging.h" #include "common/socket.h" #include "common/timer.h" #include "common/utils.h" +#include "common/vana_time.h" #include @@ -42,8 +45,6 @@ #include "status_effect_container.h" #include "treasure_pool.h" #include "unitychat.h" -#include "vana_time.h" -#include "zone.h" #include "zone_entities.h" #include "entities/automatonentity.h" @@ -151,12 +152,6 @@ CZone::~CZone() destroy(m_zoneEntities); } -/************************************************************************ - * * - * Функции доступа к полям класса * - * * - ************************************************************************/ - ZONEID CZone::GetID() { return m_zoneID; @@ -332,13 +327,6 @@ zoneLine_t* CZone::GetZoneLine(uint32 zoneLineID) return nullptr; } -/************************************************************************ - * * - * Загружаем ZoneLines, необходимые для правильного перемещения между * - * зонами. * - * * - ************************************************************************/ - void CZone::LoadZoneLines() { TracyZoneScoped; @@ -405,12 +393,6 @@ void CZone::LoadZoneWeather() } } -/************************************************************************ - * * - * Загружаем настройки зоны из базы * - * * - ************************************************************************/ - void CZone::LoadZoneSettings() { TracyZoneScoped; diff --git a/src/map/zone.h b/src/map/zone.h index 20ef955f7e7..1c13592a4da 100644 --- a/src/map/zone.h +++ b/src/map/zone.h @@ -25,6 +25,7 @@ #include "common/cbasetypes.h" #include "common/mmo.h" #include "common/taskmgr.h" +#include "common/vana_time.h" #include #include @@ -36,7 +37,6 @@ #include "navmesh.h" #include "packets/weather.h" #include "trigger_area.h" -#include "vana_time.h" enum ZONEID : uint16 { diff --git a/src/world/http_server.cpp b/src/world/http_server.cpp index 7ab8be095b4..9e0c30b99d1 100644 --- a/src/world/http_server.cpp +++ b/src/world/http_server.cpp @@ -30,92 +30,102 @@ using json = nlohmann::json; HTTPServer::HTTPServer() { + if (!settings::get("network.ENABLE_HTTP")) + { + return; + } + + ts = std::make_unique(1); + // NOTE: Everything registered in here happens off the main thread, so lock any global resources // : you might be using. LockingUpdate(); - // clang-format off - m_httpServer.Get("/api", [&](httplib::Request const& req, httplib::Response& res) - { - res.set_content("Hello LSB API", "text/plain"); - }); + auto host = settings::get("network.HTTP_HOST"); + auto port = settings::get("network.HTTP_PORT"); - m_httpServer.Get("/api/sessions", [&](httplib::Request const& req, httplib::Response& res) + // clang-format off + ts->schedule([this, host, port]() { - LockingUpdate(); - - std::unique_lock lock(m_updateBottleneck); - json j; - j = m_apiDataCache.activeSessionCount; - res.set_content(j.dump(), "application/json"); - }); + m_httpServer.Get("/api", [&](httplib::Request const& req, httplib::Response& res) + { + res.set_content("Hello LSB API", "text/plain"); + }); - m_httpServer.Get("/api/zones", [&](httplib::Request const& req, httplib::Response& res) - { - LockingUpdate(); + m_httpServer.Get("/api/sessions", [&](httplib::Request const& req, httplib::Response& res) + { + LockingUpdate(); - std::unique_lock lock(m_updateBottleneck); - json j = m_apiDataCache.zonePlayerCounts; - res.set_content(j.dump(), "application/json"); - }); + std::unique_lock lock(m_updateBottleneck); + json j; + j = m_apiDataCache.activeSessionCount; + res.set_content(j.dump(), "application/json"); + }); - m_httpServer.Get(R"(/api/zones/(\d+))", [&](httplib::Request const& req, httplib::Response& res) - { - auto maybeZoneId = req.matches[1].str(); - uint16 zoneId = std::strtol(maybeZoneId.c_str(), nullptr, 10); - if (zoneId && zoneId < ZONEID::MAX_ZONEID) + m_httpServer.Get("/api/zones", [&](httplib::Request const& req, httplib::Response& res) { LockingUpdate(); std::unique_lock lock(m_updateBottleneck); - json j = m_apiDataCache.zonePlayerCounts[zoneId]; + json j = m_apiDataCache.zonePlayerCounts; res.set_content(j.dump(), "application/json"); - } - else + }); + + m_httpServer.Get(R"(/api/zones/(\d+))", [&](httplib::Request const& req, httplib::Response& res) { - res.status = 404; - } - }); + auto maybeZoneId = req.matches[1].str(); + uint16 zoneId = std::strtol(maybeZoneId.c_str(), nullptr, 10); + if (zoneId && zoneId < ZONEID::MAX_ZONEID) + { + LockingUpdate(); - m_httpServer.Get("/api/settings", [&](httplib::Request const& req, httplib::Response& res) - { - // TODO: Cache these - json j; - j["SERVER_NAME"] = settings::get("main.SERVER_NAME"); - j["EXP_RATE"] = settings::get("main.EXP_RATE"); - j["ENABLE_TRUST_CASTING"] = settings::get("main.ENABLE_TRUST_CASTING"); - j["MAX_LEVEL"] = settings::get("main.MAX_LEVEL"); - res.set_content(j.dump(), "application/json"); - }); + std::unique_lock lock(m_updateBottleneck); + json j = m_apiDataCache.zonePlayerCounts[zoneId]; + res.set_content(j.dump(), "application/json"); + } + else + { + res.status = 404; + } + }); - m_httpServer.set_error_handler([](httplib::Request const& /*req*/, httplib::Response& res) - { - auto str = fmt::format("

Error Status: {} ({})

", res.status, httplib::detail::status_message(res.status)); - res.set_content(str, "text/html"); - }); + m_httpServer.Get("/api/settings", [&](httplib::Request const& req, httplib::Response& res) + { + // TODO: Cache these + json j; + j["SERVER_NAME"] = settings::get("main.SERVER_NAME"); + j["EXP_RATE"] = settings::get("main.EXP_RATE"); + j["ENABLE_TRUST_CASTING"] = settings::get("main.ENABLE_TRUST_CASTING"); + j["MAX_LEVEL"] = settings::get("main.MAX_LEVEL"); + res.set_content(j.dump(), "application/json"); + }); - m_httpServer.set_logger([](httplib::Request const& req, httplib::Response const& res) - { - // https://developer.mozilla.org/en-US/docs/Web/HTTP/Status - if (res.status >= 500) + m_httpServer.set_error_handler([](httplib::Request const& /*req*/, httplib::Response& res) { - ShowError(fmt::format("Server Error: {} ({})", res.status, httplib::detail::status_message(res.status))); - return; - } - else if (res.status >= 400) + auto str = fmt::format("

Error Status: {} ({})

", res.status, httplib::detail::status_message(res.status)); + res.set_content(str, "text/html"); + }); + + m_httpServer.set_logger([](httplib::Request const& req, httplib::Response const& res) { - ShowError(fmt::format("Client Error: {} ({})", res.status, httplib::detail::status_message(res.status))); - return; - } + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Status + if (res.status >= 500) + { + ShowError(fmt::format("Server Error: {} ({})", res.status, httplib::detail::status_message(res.status))); + return; + } + else if (res.status >= 400) + { + ShowError(fmt::format("Client Error: {} ({})", res.status, httplib::detail::status_message(res.status))); + return; + } + }); + + ShowInfo(fmt::format("Starting HTTP Server on http://{}:{}/api", host, port)); + m_httpServer.listen(host, port); }); // clang-format on - - auto host = settings::get("network.HTTP_HOST"); - auto port = settings::get("network.HTTP_PORT"); - - ShowInfo(fmt::format("Starting HTTP Server on http://{}:{}/api", host, port)); - m_httpServer.listen(host, port); } HTTPServer::~HTTPServer() diff --git a/src/world/http_server.h b/src/world/http_server.h index e3ce277d37b..9dbda179b7c 100644 --- a/src/world/http_server.h +++ b/src/world/http_server.h @@ -21,11 +21,13 @@ along with this program. If not, see http://www.gnu.org/licenses/ #pragma once #include "common/logging.h" + #include "map/zone.h" #include #include +#include class HTTPServer { @@ -40,6 +42,8 @@ class HTTPServer std::mutex m_updateBottleneck; std::atomic m_lastUpdate; + std::unique_ptr ts; + struct APIDataCache { uint32 activeSessionCount; diff --git a/src/world/world_server.cpp b/src/world/world_server.cpp index 044e8a03ea4..2236743d247 100644 --- a/src/world/world_server.cpp +++ b/src/world/world_server.cpp @@ -24,11 +24,125 @@ along with this program. If not, see http://www.gnu.org/licenses/ #include "common/console_service.h" #include "common/logging.h" +namespace +{ + std::unique_ptr sql; +} // namespace + +void UpdateDailyTallyPoints() +{ + uint16 dailyTallyLimit = settings::get("main.DAILY_TALLY_LIMIT"); + uint16 dailyTallyAmount = settings::get("main.DAILY_TALLY_AMOUNT"); + + const char* fmtQuery = "UPDATE char_points \ + SET char_points.daily_tally = LEAST(%u, char_points.daily_tally + %u) \ + WHERE char_points.daily_tally > -1;"; + + int32 ret = sql->Query(fmtQuery, dailyTallyLimit, dailyTallyAmount); + + if (ret == SQL_ERROR) + { + ShowError("Failed to update daily tally points"); + } + else + { + ShowDebug("Distributed daily tally points"); + } + + fmtQuery = "DELETE FROM char_vars WHERE varname = 'gobbieBoxUsed';"; + + if (sql->Query(fmtQuery, dailyTallyAmount) == SQL_ERROR) + { + ShowError("Failed to delete daily tally char_vars entries"); + } +} + +int32 time_server(time_point tick, CTaskMgr::CTask* PTask) +{ + TracyZoneScoped; + TIMETYPE VanadielTOTD = CVanaTime::getInstance()->SyncTime(); + + // Weekly update for conquest (sunday at midnight) + static time_point lastConquestTally = tick - 1h; + static time_point lastConquestUpdate = tick - 1h; + if (CVanaTime::getInstance()->getJstWeekDay() == 1 && CVanaTime::getInstance()->getJstHour() == 0 && CVanaTime::getInstance()->getJstMinute() == 0) + { + if (tick > (lastConquestTally + 1h)) + { + lastConquestTally = tick; + } + } + // Hourly conquest update + else if (CVanaTime::getInstance()->getJstMinute() == 0) + { + if (tick > (lastConquestUpdate + 1h)) + { + lastConquestUpdate = tick; + } + } + + // Vanadiel Hour + static time_point lastVHourlyUpdate = tick - 4800ms; + if (CVanaTime::getInstance()->getMinute() == 0) + { + if (tick > (lastVHourlyUpdate + 4800ms)) + { + lastVHourlyUpdate = tick; + } + } + + // JST Midnight + static time_point lastTickedJstMidnight = tick - 1h; + if (CVanaTime::getInstance()->getJstHour() == 0 && CVanaTime::getInstance()->getJstMinute() == 0) + { + if (tick > (lastTickedJstMidnight + 1h)) + { + if (settings::get("main.ENABLE_DAILY_TALLY")) + { + UpdateDailyTallyPoints(); + } + + lastTickedJstMidnight = tick; + } + } + + // 4-hour RoE Timed blocks + static time_point lastTickedRoeBlock = tick - 1h; + if (CVanaTime::getInstance()->getJstHour() % 4 == 0 && CVanaTime::getInstance()->getJstMinute() == 0) + { + if (tick > (lastTickedRoeBlock + 1h)) + { + lastTickedRoeBlock = tick; + } + } + + // Vanadiel Day + static time_point lastVDailyUpdate = tick - 4800ms; + if (CVanaTime::getInstance()->getHour() == 0 && CVanaTime::getInstance()->getMinute() == 0) + { + if (tick > (lastVDailyUpdate + 4800ms)) + { + lastVDailyUpdate = tick; + } + } + + if (VanadielTOTD != TIME_NONE) + { + } + + return 0; +} + WorldServer::WorldServer(int argc, char** argv) : Application("world", argc, argv) , messageServer(std::make_unique(std::ref(m_RequestExit))) , httpServer(std::make_unique()) { + // Anonymous namespace preparation + sql = std::make_unique(); + + // Tasks + CTaskMgr::getInstance()->AddTask("time_server", server_clock::now(), nullptr, CTaskMgr::TASK_INTERVAL, time_server, 2400ms); } WorldServer::~WorldServer() @@ -37,4 +151,5 @@ WorldServer::~WorldServer() void WorldServer::Tick() { + Application::Tick(); } diff --git a/src/world/world_server.h b/src/world/world_server.h index 60fb0b7d958..372128f0326 100644 --- a/src/world/world_server.h +++ b/src/world/world_server.h @@ -21,6 +21,7 @@ along with this program. If not, see http://www.gnu.org/licenses/ #pragma once #include "common/application.h" +#include "common/taskmgr.h" #include "besieged_system.h" #include "campaign_system.h"