From 8e52dd0579b6217f27032f50b05aae0bed849cb1 Mon Sep 17 00:00:00 2001 From: hg <4683435+hgtw@users.noreply.github.com> Date: Fri, 18 Sep 2020 20:46:23 -0400 Subject: [PATCH] Add expedition lock messages --- common/servertalk.h | 8 ++++++++ zone/expedition.cpp | 41 +++++++++++++++++++++++++++++++---------- zone/expedition.h | 11 ++++++++++- zone/lua_expedition.cpp | 24 +++++++++++++++++++++++- zone/lua_expedition.h | 3 +++ zone/lua_parser.cpp | 3 ++- 6 files changed, 77 insertions(+), 13 deletions(-) diff --git a/common/servertalk.h b/common/servertalk.h index 32e3cd812..0b66ea474 100644 --- a/common/servertalk.h +++ b/common/servertalk.h @@ -2051,6 +2051,14 @@ struct ServerExpeditionLockout_Struct { char event_name[256]; }; +struct ServerExpeditionLockState_Struct { + uint32 expedition_id; + uint32 sender_zone_id; + uint16 sender_instance_id; + uint8 enabled; + uint8 lock_msg; // 0: none, 1: closing 2: trial begin +}; + struct ServerExpeditionSetting_Struct { uint32 expedition_id; uint32 sender_zone_id; diff --git a/zone/expedition.cpp b/zone/expedition.cpp index 1b134bd28..f7adc1e1d 100644 --- a/zone/expedition.cpp +++ b/zone/expedition.cpp @@ -42,6 +42,9 @@ const char* const DZADD_INVITE_WARNING_TIMER = "%s - %sD:%sH:%sM"; const char* const KICKPLAYERS_EVERYONE = "Everyone"; // message string 8312 added in September 08 2020 Test patch (used by both dz and shared tasks) const char* const CREATE_NOT_ALL_ADDED = "Not all players in your {} were added to the {}. The {} can take a maximum of {} players, and your {} has {}."; +// various expeditions re-use these strings when locking +constexpr char LOCK_CLOSE[] = "Your expedition is nearing its close. You cannot bring any additional people into your expedition at this time."; +constexpr char LOCK_BEGIN[] = "The trial has begun. You cannot bring any additional people into your expedition at this time."; const int32_t Expedition::REPLAY_TIMER_ID = -1; const int32_t Expedition::EVENT_TIMER_ID = 1; @@ -198,7 +201,7 @@ void Expedition::CacheExpeditions(MySQLRequestResult& results) bool is_locked = (strtoul(row[col::is_locked], nullptr, 10) != 0); expedition->SetReplayLockoutOnMemberJoin(add_replay_on_join); - expedition->SetLocked(is_locked); + expedition->SetLocked(is_locked, ExpeditionLockMessage::None); zone->expedition_cache.emplace(expedition_id, std::move(expedition)); } @@ -1114,10 +1117,23 @@ void Expedition::DzKickPlayers(Client* requester) requester->MessageString(Chat::Red, EXPEDITION_REMOVED, KICKPLAYERS_EVERYONE, m_expedition_name.c_str()); } -void Expedition::SetLocked(bool lock_expedition, bool update_db) +void Expedition::SetLocked( + bool lock_expedition, ExpeditionLockMessage lock_msg, bool update_db, uint32_t msg_color) { m_is_locked = lock_expedition; + if (m_is_locked && lock_msg != ExpeditionLockMessage::None && m_dynamiczone.IsCurrentZoneDzInstance()) + { + auto msg = (lock_msg == ExpeditionLockMessage::Close) ? LOCK_CLOSE : LOCK_BEGIN; + for (const auto& client_iter : entity_list.GetClientList()) + { + if (client_iter.second) + { + client_iter.second->Message(msg_color, msg); + } + } + } + if (update_db) { ExpeditionDatabase::UpdateLockState(m_id, lock_expedition); @@ -1813,6 +1829,18 @@ void Expedition::HandleWorldMessage(ServerPacket* pack) break; } case ServerOP_ExpeditionLockState: + { + auto buf = reinterpret_cast(pack->pBuffer); + if (zone && !zone->IsZone(buf->sender_zone_id, buf->sender_instance_id)) + { + auto expedition = Expedition::FindCachedExpeditionByID(buf->expedition_id); + if (expedition) + { + expedition->SetLocked(buf->enabled, static_cast(buf->lock_msg)); + } + } + break; + } case ServerOP_ExpeditionReplayOnJoin: { auto buf = reinterpret_cast(pack->pBuffer); @@ -1821,14 +1849,7 @@ void Expedition::HandleWorldMessage(ServerPacket* pack) auto expedition = Expedition::FindCachedExpeditionByID(buf->expedition_id); if (expedition) { - if (pack->opcode == ServerOP_ExpeditionLockState) - { - expedition->SetLocked(buf->enabled); - } - else if (pack->opcode == ServerOP_ExpeditionReplayOnJoin) - { - expedition->SetReplayLockoutOnMemberJoin(buf->enabled); - } + expedition->SetReplayLockoutOnMemberJoin(buf->enabled); } } break; diff --git a/zone/expedition.h b/zone/expedition.h index 16e62a5d1..23d57f359 100644 --- a/zone/expedition.h +++ b/zone/expedition.h @@ -23,6 +23,7 @@ #include "dynamiczone.h" #include "expedition_lockout_timer.h" +#include "../common/eq_constants.h" #include #include #include @@ -49,6 +50,13 @@ enum class ExpeditionMemberStatus : uint8_t LinkDead }; +enum class ExpeditionLockMessage : uint8_t +{ + None = 0, + Close, + Begin +}; + struct ExpeditionMember { uint32_t char_id = 0; @@ -114,7 +122,8 @@ public: void SetMemberStatus(Client* client, ExpeditionMemberStatus status); void SetNewLeader(uint32_t new_leader_id, const std::string& new_leader_name); void SwapMember(Client* add_client, const std::string& remove_char_name); - void SetLocked(bool lock_expedition, bool update_db = false); + void SetLocked(bool lock_expedition, ExpeditionLockMessage lock_msg, + bool update_db = false, uint32_t msg_color = Chat::Yellow); void AddLockout(const std::string& event_name, uint32_t seconds); void AddReplayLockout(uint32_t seconds); diff --git a/zone/lua_expedition.cpp b/zone/lua_expedition.cpp index 18ab84c96..1b3d66f78 100644 --- a/zone/lua_expedition.cpp +++ b/zone/lua_expedition.cpp @@ -152,7 +152,17 @@ void Lua_Expedition::SetCompass(std::string zone_name, float x, float y, float z void Lua_Expedition::SetLocked(bool lock_expedition) { Lua_Safe_Call_Void(); - self->SetLocked(lock_expedition, true); + self->SetLocked(lock_expedition, ExpeditionLockMessage::None, true); +} + +void Lua_Expedition::SetLocked(bool lock_expedition, int lock_msg) { + Lua_Safe_Call_Void(); + self->SetLocked(lock_expedition, static_cast(lock_msg), true); +} + +void Lua_Expedition::SetLocked(bool lock_expedition, int lock_msg, uint32_t msg_color) { + Lua_Safe_Call_Void(); + self->SetLocked(lock_expedition, static_cast(lock_msg), true, msg_color); } void Lua_Expedition::SetLootEventByNPCTypeID(uint32_t npc_type_id, std::string event_name) { @@ -222,6 +232,8 @@ luabind::scope lua_register_expedition() { .def("SetCompass", (void(Lua_Expedition::*)(uint32_t, float, float, float))&Lua_Expedition::SetCompass) .def("SetCompass", (void(Lua_Expedition::*)(std::string, float, float, float))&Lua_Expedition::SetCompass) .def("SetLocked", (void(Lua_Expedition::*)(bool))&Lua_Expedition::SetLocked) + .def("SetLocked", (void(Lua_Expedition::*)(bool, int))&Lua_Expedition::SetLocked) + .def("SetLocked", (void(Lua_Expedition::*)(bool, int, uint32_t))&Lua_Expedition::SetLocked) .def("SetLootEventByNPCTypeID", (void(Lua_Expedition::*)(uint32_t, std::string))&Lua_Expedition::SetLootEventByNPCTypeID) .def("SetLootEventBySpawnID", (void(Lua_Expedition::*)(uint32_t, std::string))&Lua_Expedition::SetLootEventBySpawnID) .def("SetReplayLockoutOnMemberJoin", (void(Lua_Expedition::*)(bool))&Lua_Expedition::SetReplayLockoutOnMemberJoin) @@ -232,4 +244,14 @@ luabind::scope lua_register_expedition() { .def("UpdateLockoutDuration", (void(Lua_Expedition::*)(std::string, uint32_t, bool))&Lua_Expedition::UpdateLockoutDuration); } +luabind::scope lua_register_expedition_lock_messages() { + return luabind::class_("ExpeditionLockMessage") + .enum_("constants") + [ + luabind::value("None", static_cast(ExpeditionLockMessage::None)), + luabind::value("Close", static_cast(ExpeditionLockMessage::Close)), + luabind::value("Begin", static_cast(ExpeditionLockMessage::Begin)) + ]; +} + #endif // LUA_EQEMU diff --git a/zone/lua_expedition.h b/zone/lua_expedition.h index 553472be7..97c74b57e 100644 --- a/zone/lua_expedition.h +++ b/zone/lua_expedition.h @@ -39,6 +39,7 @@ namespace luabind { } luabind::scope lua_register_expedition(); +luabind::scope lua_register_expedition_lock_messages(); class Lua_Expedition : public Lua_Ptr { @@ -74,6 +75,8 @@ public: void SetCompass(uint32_t zone_id, float x, float y, float z); void SetCompass(std::string zone_name, float x, float y, float z); void SetLocked(bool lock_expedition); + void SetLocked(bool lock_expedition, int lock_msg); + void SetLocked(bool lock_expedition, int lock_msg, uint32_t color); void SetLootEventByNPCTypeID(uint32_t npc_type_id, std::string event_name); void SetLootEventBySpawnID(uint32_t spawn_id, std::string event_name); void SetReplayLockoutOnMemberJoin(bool enable); diff --git a/zone/lua_parser.cpp b/zone/lua_parser.cpp index 063386713..494e3e0e2 100644 --- a/zone/lua_parser.cpp +++ b/zone/lua_parser.cpp @@ -1110,7 +1110,8 @@ void LuaParser::MapFunctions(lua_State *L) { lua_register_ruleb(), lua_register_journal_speakmode(), lua_register_journal_mode(), - lua_register_expedition() + lua_register_expedition(), + lua_register_expedition_lock_messages() ]; } catch(std::exception &ex) {