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
 
- 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
static bool HandleEventStopCommand(ChatHandler *handler, EventEntry const eventId)
Definition cs_event.cpp:153
static bool HandleEventInfoCommand(ChatHandler *handler, EventEntry const eventId)
Definition cs_event.cpp:86
static bool HandleEventActiveListCommand(ChatHandler *handler)
Definition cs_event.cpp:57
static bool HandleEventStartCommand(ChatHandler *handler, EventEntry const eventId)
Definition cs_event.cpp:124
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:46

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 std::string active = handler->GetAcoreString(LANG_ACTIVE);
65
66 for (uint16 eventId : activeEvents)
67 {
68 GameEventData const& eventData = events[eventId];
69
70 if (handler->GetSession())
71 handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, eventId, eventId, eventData.Description, active);
72 else
73 handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, eventId, eventData.Description, active);
74
75 ++counter;
76 }
77
78 if (counter == 0)
80
81 handler->SetSentErrorMessage(true);
82
83 return true;
84 }
std::uint32_t uint32
Definition Define.h:107
std::uint16_t uint16
Definition Define.h:108
#define sGameEventMgr
Definition GameEventMgr.h:201
@ LANG_EVENT_ENTRY_LIST_CONSOLE
Definition Language.h:893
@ LANG_EVENT_ENTRY_LIST_CHAT
Definition Language.h:644
@ LANG_ACTIVE
Definition Language.h:67
@ LANG_NOEVENTFOUND
Definition Language.h:645
events
Definition boss_sartura.cpp:43
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:211
WorldSession * GetSession()
Definition Chat.h:242
void SetSentErrorMessage(bool val)
Definition Chat.h:238
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:160
virtual std::string GetAcoreString(uint32 entry) const
Definition Chat.cpp:41
std::vector< GameEventData > GameEventDataMap
Definition GameEventMgr.h:107
std::set< uint16 > ActiveEvents
Definition GameEventMgr.h:106
Definition GameEventMgr.h:57
std::string Description
Definition GameEventMgr.h:70

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
87 {
89
90 if (std::size_t(eventId) >= events.size())
91 {
93 return false;
94 }
95
96 GameEventData const& eventData = events[eventId];
97 if (!eventData.isValid())
98 {
100 return false;
101 }
102
103 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
104 bool active = activeEvents.find(eventId) != activeEvents.end();
105 std::string activeStr = active ? handler->GetAcoreString(LANG_ACTIVE) : "";
106
107 std::string startTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.Start));
108 std::string endTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.End));
109
110 uint32 delay = sGameEventMgr->NextCheck(eventId);
111 time_t nextTime = GameTime::GetGameTime().count() + delay;
112 std::string nextStr = nextTime >= eventData.Start && nextTime < eventData.End ? Acore::Time::TimeToTimestampStr(Seconds(nextTime)) : "-";
113
114 std::string occurenceStr = secsToTimeString(eventData.Occurence * MINUTE, true);
115 std::string lengthStr = secsToTimeString(eventData.Length * MINUTE, true);
116
117 handler->PSendSysMessage(LANG_EVENT_INFO, uint16(eventId), eventData.Description, activeStr,
118 startTimeStr, endTimeStr, occurenceStr, lengthStr,
119 nextStr);
120
121 return true;
122 }
constexpr auto MINUTE
Definition Common.h:47
std::chrono::seconds Seconds
Seconds shorthand typedef.
Definition Duration.h:30
@ LANG_EVENT_INFO
Definition Language.h:647
@ LANG_EVENT_NOT_EXIST
Definition Language.h:646
std::string secsToTimeString(uint64 timeInSecs, bool shortText)
Definition Util.cpp:73
void SendErrorMessage(uint32 entry)
Definition Chat.cpp:216
AC_COMMON_API std::string TimeToTimestampStr(Seconds time=0s, std::string_view fmt={})
Definition Timer.cpp:272
Seconds GetGameTime()
Definition GameTime.cpp:38
time_t Start
Definition GameEventMgr.h:60
time_t End
Definition GameEventMgr.h:61
uint32 Length
Definition GameEventMgr.h:64
bool isValid() const
Definition GameEventMgr.h:73
uint32 Occurence
Definition GameEventMgr.h:63

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
125 {
127
128 if (*eventId < 1 || *eventId >= events.size())
129 {
131 return false;
132 }
133
134 GameEventData const& eventData = events[eventId];
135 if (!eventData.isValid())
136 {
138 return false;
139 }
140
141 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
142 if (activeEvents.find(eventId) != activeEvents.end())
143 {
144 handler->SendErrorMessage(LANG_EVENT_ALREADY_ACTIVE, uint16(eventId), eventData.Description);
145 return false;
146 }
147
148 handler->PSendSysMessage(LANG_EVENT_STARTED, uint16(eventId), eventData.Description);
149 sGameEventMgr->StartEvent(eventId, true);
150 return true;
151 }
@ LANG_EVENT_STARTED
Definition Language.h:664
@ LANG_EVENT_ALREADY_ACTIVE
Definition Language.h:648

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
154 {
156
157 if (*eventId < 1 || *eventId >= events.size())
158 {
160 return false;
161 }
162
163 GameEventData const& eventData = events[eventId];
164 if (!eventData.isValid())
165 {
167 return false;
168 }
169
170 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
171
172 if (activeEvents.find(eventId) == activeEvents.end())
173 {
174 handler->SendErrorMessage(LANG_EVENT_NOT_ACTIVE, uint16(eventId), eventData.Description);
175 return false;
176 }
177
178 handler->PSendSysMessage(LANG_EVENT_STOPPED, uint16(eventId), eventData.Description);
179 sGameEventMgr->StopEvent(eventId, true);
180 return true;
181 }
@ LANG_EVENT_NOT_ACTIVE
Definition Language.h:649
@ LANG_EVENT_STOPPED
Definition Language.h:665

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


The documentation for this class was generated from the following file: