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
 
uint16 GetTotalAvailableHooks ()
 

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, uint16 totalAvailableHooks=0)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ event_commandscript()

event_commandscript::event_commandscript ( )
inline
39: CommandScript("event_commandscript") { }
Definition: CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable event_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

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

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

◆ HandleEventActiveListCommand()

static bool event_commandscript::HandleEventActiveListCommand ( ChatHandler handler)
inlinestatic
58 {
59 uint32 counter = 0;
60
62 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
63
64 char const* active = handler->GetAcoreString(LANG_ACTIVE);
65
66 for (uint16 eventId : activeEvents)
67 {
68 GameEventData const& eventData = events[eventId];
69
70 if (handler->GetSession())
71 {
72 handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, eventId, eventId, eventData.description, active);
73 }
74 else
75 {
76 handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, eventId, eventData.description, active);
77 }
78
79 ++counter;
80 }
81
82 if (counter == 0)
83 {
85 }
86
87 handler->SetSentErrorMessage(true);
88
89 return true;
90 }
std::uint32_t uint32
Definition: Define.h:107
std::uint16_t uint16
Definition: Define.h:108
events
Definition: boss_sartura.cpp:43
@ LANG_EVENT_ENTRY_LIST_CONSOLE
Definition: Language.h:892
@ LANG_EVENT_ENTRY_LIST_CHAT
Definition: Language.h:643
@ LANG_ACTIVE
Definition: Language.h:67
@ LANG_NOEVENTFOUND
Definition: Language.h:644
#define sGameEventMgr
Definition: GameEventMgr.h:186
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:210
WorldSession * GetSession()
Definition: Chat.h:242
virtual char const * GetAcoreString(uint32 entry) const
Definition: Chat.cpp:40
void SetSentErrorMessage(bool val)
Definition: Chat.h:238
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:159
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
93 {
95
96 if (std::size_t(eventId) >= events.size())
97 {
99 return false;
100 }
101
102 GameEventData const& eventData = events[eventId];
103 if (!eventData.isValid())
104 {
106 return false;
107 }
108
109 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
110 bool active = activeEvents.find(eventId) != activeEvents.end();
111 char const* activeStr = active ? handler->GetAcoreString(LANG_ACTIVE) : "";
112
113 std::string startTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.start));
114 std::string endTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.end));
115
116 uint32 delay = sGameEventMgr->NextCheck(eventId);
117 time_t nextTime = GameTime::GetGameTime().count() + delay;
118 std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? Acore::Time::TimeToTimestampStr(Seconds(nextTime)) : "-";
119
120 std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE, true);
121 std::string lengthStr = secsToTimeString(eventData.length * MINUTE, true);
122
123 handler->PSendSysMessage(LANG_EVENT_INFO, uint16(eventId), eventData.description, activeStr,
124 startTimeStr, endTimeStr, occurenceStr, lengthStr,
125 nextStr);
126
127 return true;
128 }
constexpr auto MINUTE
Definition: Common.h:47
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:646
@ LANG_EVENT_NOT_EXIST
Definition: Language.h:645
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:215
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
131 {
133
134 if (*eventId < 1 || *eventId >= events.size())
135 {
137 return false;
138 }
139
140 GameEventData const& eventData = events[eventId];
141 if (!eventData.isValid())
142 {
144 return false;
145 }
146
147 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
148 if (activeEvents.find(eventId) != activeEvents.end())
149 {
150 handler->SendErrorMessage(LANG_EVENT_ALREADY_ACTIVE, uint16(eventId), eventData.description);
151 return false;
152 }
153
154 handler->PSendSysMessage(LANG_EVENT_STARTED, uint16(eventId), eventData.description);
155 sGameEventMgr->StartEvent(eventId, true);
156 return true;
157 }
@ LANG_EVENT_STARTED
Definition: Language.h:663
@ LANG_EVENT_ALREADY_ACTIVE
Definition: Language.h:647

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
160 {
162
163 if (*eventId < 1 || *eventId >= events.size())
164 {
166 return false;
167 }
168
169 GameEventData const& eventData = events[eventId];
170 if (!eventData.isValid())
171 {
173 return false;
174 }
175
176 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
177
178 if (activeEvents.find(eventId) == activeEvents.end())
179 {
180 handler->SendErrorMessage(LANG_EVENT_NOT_ACTIVE, uint16(eventId), eventData.description);
181 return false;
182 }
183
184 handler->PSendSysMessage(LANG_EVENT_STOPPED, uint16(eventId), eventData.description);
185 sGameEventMgr->StopEvent(eventId, true);
186 return true;
187 }
@ LANG_EVENT_NOT_ACTIVE
Definition: Language.h:648
@ LANG_EVENT_STOPPED
Definition: Language.h:664

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().