AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
event_commandscript Class Reference
Inheritance diagram for event_commandscript:
CommandScript ScriptObject

Public Member Functions

 event_commandscript ()
 
ChatCommandTable GetCommands () const override
 
virtual std::vector< Acore::ChatCommands::ChatCommandBuilderGetCommands () const =0
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
const std::string & GetName () const
 

Static Public Member Functions

static bool HandleEventActiveListCommand (ChatHandler *handler)
 
static bool HandleEventInfoCommand (ChatHandler *handler, EventEntry const eventId)
 
static bool HandleEventStartCommand (ChatHandler *handler, EventEntry const eventId)
 
static bool HandleEventStopCommand (ChatHandler *handler, EventEntry const eventId)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ event_commandscript()

event_commandscript::event_commandscript ( )
inline
40: CommandScript("event_commandscript") { }
Definition: ScriptMgr.h:850

Member Function Documentation

◆ GetCommands()

ChatCommandTable event_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

43 {
44 static ChatCommandTable eventCommandTable =
45 {
46 { "activelist", HandleEventActiveListCommand, SEC_GAMEMASTER, Console::Yes },
47 { "start", HandleEventStartCommand, SEC_GAMEMASTER, Console::Yes },
48 { "stop", HandleEventStopCommand, SEC_GAMEMASTER, Console::Yes },
49 { "info", HandleEventInfoCommand, SEC_GAMEMASTER, Console::Yes }
50 };
51 static ChatCommandTable commandTable =
52 {
53 { "event", eventCommandTable }
54 };
55 return commandTable;
56 }
@ SEC_GAMEMASTER
Definition: Common.h:68
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:50
static bool HandleEventStopCommand(ChatHandler *handler, EventEntry const eventId)
Definition: cs_event.cpp:164
static bool HandleEventInfoCommand(ChatHandler *handler, EventEntry const eventId)
Definition: cs_event.cpp:93
static bool HandleEventActiveListCommand(ChatHandler *handler)
Definition: cs_event.cpp:58
static bool HandleEventStartCommand(ChatHandler *handler, EventEntry const eventId)
Definition: cs_event.cpp:133

References HandleEventActiveListCommand(), HandleEventInfoCommand(), HandleEventStartCommand(), HandleEventStopCommand(), and SEC_GAMEMASTER.

◆ HandleEventActiveListCommand()

static bool event_commandscript::HandleEventActiveListCommand ( ChatHandler handler)
inlinestatic
59 {
60 uint32 counter = 0;
61
63 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
64
65 char const* active = handler->GetAcoreString(LANG_ACTIVE);
66
67 for (uint16 eventId : activeEvents)
68 {
69 GameEventData const& eventData = events[eventId];
70
71 if (handler->GetSession())
72 {
73 handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, eventId, eventId, eventData.description.c_str(), active);
74 }
75 else
76 {
77 handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, eventId, eventData.description.c_str(), active);
78 }
79
80 ++counter;
81 }
82
83 if (counter == 0)
84 {
86 }
87
88 handler->SetSentErrorMessage(true);
89
90 return true;
91 }
std::uint32_t uint32
Definition: Define.h:108
std::uint16_t uint16
Definition: Define.h:109
#define sGameEventMgr
Definition: GameEventMgr.h:186
@ LANG_EVENT_ENTRY_LIST_CONSOLE
Definition: Language.h:865
@ LANG_EVENT_ENTRY_LIST_CHAT
Definition: Language.h:626
@ LANG_ACTIVE
Definition: Language.h:67
@ LANG_NOEVENTFOUND
Definition: Language.h:627
events
Definition: boss_sartura.cpp:43
WorldSession * GetSession()
Definition: Chat.h:122
virtual char const * GetAcoreString(uint32 entry) const
Definition: Chat.cpp:42
void SetSentErrorMessage(bool val)
Definition: Chat.h:118
void PSendSysMessage(char const *fmt, Args &&... args)
Definition: Chat.h:60
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:103
Definition: GameEventMgr.h:57
std::string description
Definition: GameEventMgr.h:70
std::vector< GameEventData > GameEventDataMap
Definition: GameEventMgr.h:107
std::set< uint16 > ActiveEvents
Definition: GameEventMgr.h:106

References GameEventData::description, ChatHandler::GetAcoreString(), ChatHandler::GetSession(), LANG_ACTIVE, LANG_EVENT_ENTRY_LIST_CHAT, LANG_EVENT_ENTRY_LIST_CONSOLE, LANG_NOEVENTFOUND, ChatHandler::PSendSysMessage(), ChatHandler::SendSysMessage(), ChatHandler::SetSentErrorMessage(), and sGameEventMgr.

Referenced by GetCommands().

◆ HandleEventInfoCommand()

static bool event_commandscript::HandleEventInfoCommand ( ChatHandler handler,
EventEntry const  eventId 
)
inlinestatic
94 {
96
97 if (std::size_t(eventId) >= events.size())
98 {
100 handler->SetSentErrorMessage(true);
101 return false;
102 }
103
104 GameEventData const& eventData = events[eventId];
105 if (!eventData.isValid())
106 {
108 handler->SetSentErrorMessage(true);
109 return false;
110 }
111
112 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
113 bool active = activeEvents.find(eventId) != activeEvents.end();
114 char const* activeStr = active ? handler->GetAcoreString(LANG_ACTIVE) : "";
115
116 std::string startTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.start));
117 std::string endTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.end));
118
119 uint32 delay = sGameEventMgr->NextCheck(eventId);
120 time_t nextTime = GameTime::GetGameTime().count() + delay;
121 std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? Acore::Time::TimeToTimestampStr(Seconds(nextTime)) : "-";
122
123 std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE, true);
124 std::string lengthStr = secsToTimeString(eventData.length * MINUTE, true);
125
126 handler->PSendSysMessage(LANG_EVENT_INFO, uint16(eventId), eventData.description.c_str(), activeStr,
127 startTimeStr.c_str(), endTimeStr.c_str(), occurenceStr.c_str(), lengthStr.c_str(),
128 nextStr.c_str());
129
130 return true;
131 }
constexpr auto MINUTE
Definition: Common.h:56
std::chrono::seconds Seconds
Seconds shorthand typedef.
Definition: Duration.h:30
std::string secsToTimeString(uint64 timeInSecs, bool shortText)
Definition: Util.cpp:74
@ LANG_EVENT_INFO
Definition: Language.h:629
@ LANG_EVENT_NOT_EXIST
Definition: Language.h:628
AC_COMMON_API std::string TimeToTimestampStr(Seconds time=0s, std::string_view fmt={})
Definition: Timer.cpp:272
Seconds GetGameTime()
Definition: GameTime.cpp:38
uint32 occurence
Definition: GameEventMgr.h:63
time_t end
Definition: GameEventMgr.h:61
bool isValid() const
Definition: GameEventMgr.h:73
uint32 length
Definition: GameEventMgr.h:64
time_t start
Definition: GameEventMgr.h:60

References GameEventData::description, GameEventData::end, ChatHandler::GetAcoreString(), GameTime::GetGameTime(), GameEventData::isValid(), LANG_ACTIVE, LANG_EVENT_INFO, LANG_EVENT_NOT_EXIST, GameEventData::length, MINUTE, GameEventData::occurence, ChatHandler::PSendSysMessage(), secsToTimeString(), ChatHandler::SendSysMessage(), ChatHandler::SetSentErrorMessage(), sGameEventMgr, GameEventData::start, and Acore::Time::TimeToTimestampStr().

Referenced by GetCommands().

◆ HandleEventStartCommand()

static bool event_commandscript::HandleEventStartCommand ( ChatHandler handler,
EventEntry const  eventId 
)
inlinestatic
134 {
136
137 if (*eventId < 1 || *eventId >= events.size())
138 {
140 handler->SetSentErrorMessage(true);
141 return false;
142 }
143
144 GameEventData const& eventData = events[eventId];
145 if (!eventData.isValid())
146 {
148 handler->SetSentErrorMessage(true);
149 return false;
150 }
151
152 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
153 if (activeEvents.find(eventId) != activeEvents.end())
154 {
156 handler->SetSentErrorMessage(true);
157 return false;
158 }
159
160 sGameEventMgr->StartEvent(eventId, true);
161 return true;
162 }
@ LANG_EVENT_ALREADY_ACTIVE
Definition: Language.h:630

References GameEventData::isValid(), LANG_EVENT_ALREADY_ACTIVE, LANG_EVENT_NOT_EXIST, ChatHandler::PSendSysMessage(), ChatHandler::SendSysMessage(), ChatHandler::SetSentErrorMessage(), and sGameEventMgr.

Referenced by GetCommands().

◆ HandleEventStopCommand()

static bool event_commandscript::HandleEventStopCommand ( ChatHandler handler,
EventEntry const  eventId 
)
inlinestatic
165 {
167
168 if (*eventId < 1 || *eventId >= events.size())
169 {
171 handler->SetSentErrorMessage(true);
172 return false;
173 }
174
175 GameEventData const& eventData = events[eventId];
176 if (!eventData.isValid())
177 {
179 handler->SetSentErrorMessage(true);
180 return false;
181 }
182
183 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
184
185 if (activeEvents.find(eventId) == activeEvents.end())
186 {
187 handler->PSendSysMessage(LANG_EVENT_NOT_ACTIVE, uint16(eventId));
188 handler->SetSentErrorMessage(true);
189 return false;
190 }
191
192 sGameEventMgr->StopEvent(eventId, true);
193 return true;
194 }
@ LANG_EVENT_NOT_ACTIVE
Definition: Language.h:631

References GameEventData::isValid(), LANG_EVENT_NOT_ACTIVE, LANG_EVENT_NOT_EXIST, ChatHandler::PSendSysMessage(), ChatHandler::SendSysMessage(), ChatHandler::SetSentErrorMessage(), and sGameEventMgr.

Referenced by GetCommands().