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:144
static bool HandleEventInfoCommand(ChatHandler *handler, EventEntry const eventId)
Definition cs_event.cpp:77
static bool HandleEventActiveListCommand(ChatHandler *handler)
Definition cs_event.cpp:50
static bool HandleEventStartCommand(ChatHandler *handler, EventEntry const eventId)
Definition cs_event.cpp:115
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 return true;
75 }
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:898
@ LANG_EVENT_ENTRY_LIST_CHAT
Definition Language.h:649
@ LANG_ACTIVE
Definition Language.h:67
@ LANG_NOEVENTFOUND
Definition Language.h:650
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
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(), and sGameEventMgr.

Referenced by GetCommands().

◆ HandleEventInfoCommand()

static bool event_commandscript::HandleEventInfoCommand ( ChatHandler handler,
EventEntry const  eventId 
)
inlinestatic
78 {
80
81 if (std::size_t(eventId) >= events.size())
82 {
84 return false;
85 }
86
87 GameEventData const& eventData = events[eventId];
88 if (!eventData.isValid())
89 {
91 return false;
92 }
93
94 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
95 bool active = activeEvents.find(eventId) != activeEvents.end();
96 std::string activeStr = active ? handler->GetAcoreString(LANG_ACTIVE) : "";
97
98 std::string startTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.Start));
99 std::string endTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.End));
100
101 uint32 delay = sGameEventMgr->NextCheck(eventId);
102 time_t nextTime = GameTime::GetGameTime().count() + delay;
103 std::string nextStr = nextTime >= eventData.Start && nextTime < eventData.End ? Acore::Time::TimeToTimestampStr(Seconds(nextTime)) : "-";
104
105 std::string occurenceStr = secsToTimeString(eventData.Occurence * MINUTE, true);
106 std::string lengthStr = secsToTimeString(eventData.Length * MINUTE, true);
107
108 handler->PSendSysMessage(LANG_EVENT_INFO, uint16(eventId), eventData.Description, activeStr,
109 startTimeStr, endTimeStr, occurenceStr, lengthStr,
110 nextStr);
111
112 return true;
113 }
constexpr auto MINUTE
Definition Common.h:47
std::chrono::seconds Seconds
Seconds shorthand typedef.
Definition Duration.h:30
@ LANG_EVENT_INFO
Definition Language.h:652
@ LANG_EVENT_NOT_EXIST
Definition Language.h:651
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
116 {
118
119 if (*eventId < 1 || *eventId >= events.size())
120 {
122 return false;
123 }
124
125 GameEventData const& eventData = events[eventId];
126 if (!eventData.isValid())
127 {
129 return false;
130 }
131
132 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
133 if (activeEvents.find(eventId) != activeEvents.end())
134 {
135 handler->SendErrorMessage(LANG_EVENT_ALREADY_ACTIVE, uint16(eventId), eventData.Description);
136 return false;
137 }
138
139 handler->PSendSysMessage(LANG_EVENT_STARTED, uint16(eventId), eventData.Description);
140 sGameEventMgr->StartEvent(eventId, true);
141 return true;
142 }
@ LANG_EVENT_STARTED
Definition Language.h:669
@ LANG_EVENT_ALREADY_ACTIVE
Definition Language.h:653

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
145 {
147
148 if (*eventId < 1 || *eventId >= events.size())
149 {
151 return false;
152 }
153
154 GameEventData const& eventData = events[eventId];
155 if (!eventData.isValid())
156 {
158 return false;
159 }
160
161 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
162
163 if (activeEvents.find(eventId) == activeEvents.end())
164 {
165 handler->SendErrorMessage(LANG_EVENT_NOT_ACTIVE, uint16(eventId), eventData.Description);
166 return false;
167 }
168
169 handler->PSendSysMessage(LANG_EVENT_STOPPED, uint16(eventId), eventData.Description);
170 sGameEventMgr->StopEvent(eventId, true);
171 return true;
172 }
@ LANG_EVENT_NOT_ACTIVE
Definition Language.h:654
@ LANG_EVENT_STOPPED
Definition Language.h:670

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: