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: CommandScript.h:25

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:61
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:49
static bool HandleEventStopCommand(ChatHandler *handler, EventEntry const eventId)
Definition: cs_event.cpp:160
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:131

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:874
@ 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:139
virtual char const * GetAcoreString(uint32 entry) const
Definition: Chat.cpp:42
void SetSentErrorMessage(bool val)
Definition: Chat.h:135
void PSendSysMessage(char const *fmt, Args &&... args)
Definition: Chat.h:60
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:101
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 return false;
101 }
102
103 GameEventData const& eventData = events[eventId];
104 if (!eventData.isValid())
105 {
107 return false;
108 }
109
110 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
111 bool active = activeEvents.find(eventId) != activeEvents.end();
112 char const* activeStr = active ? handler->GetAcoreString(LANG_ACTIVE) : "";
113
114 std::string startTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.start));
115 std::string endTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.end));
116
117 uint32 delay = sGameEventMgr->NextCheck(eventId);
118 time_t nextTime = GameTime::GetGameTime().count() + delay;
119 std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? Acore::Time::TimeToTimestampStr(Seconds(nextTime)) : "-";
120
121 std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE, true);
122 std::string lengthStr = secsToTimeString(eventData.length * MINUTE, true);
123
124 handler->PSendSysMessage(LANG_EVENT_INFO, uint16(eventId), eventData.description.c_str(), activeStr,
125 startTimeStr.c_str(), endTimeStr.c_str(), occurenceStr.c_str(), lengthStr.c_str(),
126 nextStr.c_str());
127
128 return true;
129 }
constexpr auto MINUTE
Definition: Common.h:49
std::chrono::seconds Seconds
Seconds shorthand typedef.
Definition: Duration.h:30
std::string secsToTimeString(uint64 timeInSecs, bool shortText)
Definition: Util.cpp:73
@ 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
void SendErrorMessage(uint32 entry)
Definition: Chat.cpp:152
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::SendErrorMessage(), sGameEventMgr, GameEventData::start, and Acore::Time::TimeToTimestampStr().

Referenced by GetCommands().

◆ HandleEventStartCommand()

static bool event_commandscript::HandleEventStartCommand ( ChatHandler handler,
EventEntry const  eventId 
)
inlinestatic
132 {
134
135 if (*eventId < 1 || *eventId >= events.size())
136 {
138 return false;
139 }
140
141 GameEventData const& eventData = events[eventId];
142 if (!eventData.isValid())
143 {
145 return false;
146 }
147
148 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
149 if (activeEvents.find(eventId) != activeEvents.end())
150 {
151 handler->SendErrorMessage(LANG_EVENT_ALREADY_ACTIVE, uint16(eventId), eventData.description.c_str());
152 return false;
153 }
154
155 handler->PSendSysMessage(LANG_EVENT_STARTED, uint16(eventId), eventData.description.c_str());
156 sGameEventMgr->StartEvent(eventId, true);
157 return true;
158 }
@ LANG_EVENT_STARTED
Definition: Language.h:648
@ LANG_EVENT_ALREADY_ACTIVE
Definition: Language.h:630

References GameEventData::description, GameEventData::isValid(), LANG_EVENT_ALREADY_ACTIVE, LANG_EVENT_NOT_EXIST, LANG_EVENT_STARTED, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), and sGameEventMgr.

Referenced by GetCommands().

◆ HandleEventStopCommand()

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

References GameEventData::description, GameEventData::isValid(), LANG_EVENT_NOT_ACTIVE, LANG_EVENT_NOT_EXIST, LANG_EVENT_STOPPED, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), and sGameEventMgr.

Referenced by GetCommands().