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
32: CommandScript("event_commandscript") { }
Definition CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable event_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

35 {
36 static ChatCommandTable eventCommandTable =
37 {
38 { "activelist", HandleEventActiveListCommand, SEC_GAMEMASTER, Console::Yes },
39 { "start", HandleEventStartCommand, SEC_GAMEMASTER, Console::Yes },
40 { "stop", HandleEventStopCommand, SEC_GAMEMASTER, Console::Yes },
41 { "info", HandleEventInfoCommand, SEC_GAMEMASTER, Console::Yes }
42 };
43 static ChatCommandTable commandTable =
44 {
45 { "event", eventCommandTable }
46 };
47 return commandTable;
48 }
@ SEC_GAMEMASTER
Definition Common.h:59
static bool HandleEventStopCommand(ChatHandler *handler, EventEntry const eventId)
Definition cs_event.cpp:146
static bool HandleEventInfoCommand(ChatHandler *handler, EventEntry const eventId)
Definition cs_event.cpp:79
static bool HandleEventActiveListCommand(ChatHandler *handler)
Definition cs_event.cpp:50
static bool HandleEventStartCommand(ChatHandler *handler, EventEntry const eventId)
Definition cs_event.cpp:117
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
51 {
52 uint32 counter = 0;
53
55 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
56
57 std::string active = handler->GetAcoreString(LANG_ACTIVE);
58
59 for (uint16 eventId : activeEvents)
60 {
61 GameEventData const& eventData = events[eventId];
62
63 if (handler->GetSession())
64 handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, eventId, eventId, eventData.Description, active);
65 else
66 handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, eventId, eventData.Description, active);
67
68 ++counter;
69 }
70
71 if (counter == 0)
73
74 handler->SetSentErrorMessage(true);
75
76 return true;
77 }
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
80 {
82
83 if (std::size_t(eventId) >= events.size())
84 {
86 return false;
87 }
88
89 GameEventData const& eventData = events[eventId];
90 if (!eventData.isValid())
91 {
93 return false;
94 }
95
96 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
97 bool active = activeEvents.find(eventId) != activeEvents.end();
98 std::string activeStr = active ? handler->GetAcoreString(LANG_ACTIVE) : "";
99
100 std::string startTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.Start));
101 std::string endTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.End));
102
103 uint32 delay = sGameEventMgr->NextCheck(eventId);
104 time_t nextTime = GameTime::GetGameTime().count() + delay;
105 std::string nextStr = nextTime >= eventData.Start && nextTime < eventData.End ? Acore::Time::TimeToTimestampStr(Seconds(nextTime)) : "-";
106
107 std::string occurenceStr = secsToTimeString(eventData.Occurence * MINUTE, true);
108 std::string lengthStr = secsToTimeString(eventData.Length * MINUTE, true);
109
110 handler->PSendSysMessage(LANG_EVENT_INFO, uint16(eventId), eventData.Description, activeStr,
111 startTimeStr, endTimeStr, occurenceStr, lengthStr,
112 nextStr);
113
114 return true;
115 }
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
118 {
120
121 if (*eventId < 1 || *eventId >= events.size())
122 {
124 return false;
125 }
126
127 GameEventData const& eventData = events[eventId];
128 if (!eventData.isValid())
129 {
131 return false;
132 }
133
134 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
135 if (activeEvents.find(eventId) != activeEvents.end())
136 {
137 handler->SendErrorMessage(LANG_EVENT_ALREADY_ACTIVE, uint16(eventId), eventData.Description);
138 return false;
139 }
140
141 handler->PSendSysMessage(LANG_EVENT_STARTED, uint16(eventId), eventData.Description);
142 sGameEventMgr->StartEvent(eventId, true);
143 return true;
144 }
@ 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
147 {
149
150 if (*eventId < 1 || *eventId >= events.size())
151 {
153 return false;
154 }
155
156 GameEventData const& eventData = events[eventId];
157 if (!eventData.isValid())
158 {
160 return false;
161 }
162
163 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
164
165 if (activeEvents.find(eventId) == activeEvents.end())
166 {
167 handler->SendErrorMessage(LANG_EVENT_NOT_ACTIVE, uint16(eventId), eventData.Description);
168 return false;
169 }
170
171 handler->PSendSysMessage(LANG_EVENT_STOPPED, uint16(eventId), eventData.Description);
172 sGameEventMgr->StopEvent(eventId, true);
173 return true;
174 }
@ 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: