TrinityCore
cs_event.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18/* ScriptData
19Name: event_commandscript
20%Complete: 100
21Comment: All event related commands
22Category: commandscripts
23EndScriptData */
24
25#include "ScriptMgr.h"
26#include "Chat.h"
27#include "ChatCommand.h"
28#include "GameEventMgr.h"
29#include "GameTime.h"
30#include "Language.h"
31#include "RBAC.h"
32
33using namespace Trinity::ChatCommands;
34
36{
37public:
38 event_commandscript() : CommandScript("event_commandscript") { }
39
41 {
42 static ChatCommandTable eventCommandTable =
43 {
48 };
49 static ChatCommandTable commandTable =
50 {
51 { "event", eventCommandTable },
52 };
53 return commandTable;
54 }
55
57 {
58 uint32 counter = 0;
59
60 GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
61 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
62
63 char const* active = handler->GetTrinityString(LANG_ACTIVE);
64
65 for (uint16 eventId : activeEvents)
66 {
67 GameEventData const& eventData = events[eventId];
68
69 if (handler->GetSession())
70 handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, eventId, eventId, eventData.description.c_str(), active);
71 else
72 handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, eventId, eventData.description.c_str(), active);
73
74 ++counter;
75 }
76
77 if (counter == 0)
79 handler->SetSentErrorMessage(true);
80
81 return true;
82 }
83
85 {
86 GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
87
88 if (*eventId >= events.size())
89 {
91 handler->SetSentErrorMessage(true);
92 return false;
93 }
94
95 GameEventData const& eventData = events[*eventId];
96 if (!eventData.isValid())
97 {
99 handler->SetSentErrorMessage(true);
100 return false;
101 }
102
103 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
104 bool active = activeEvents.find(eventId) != activeEvents.end();
105 char const* activeStr = active ? handler->GetTrinityString(LANG_ACTIVE) : "";
106
107 std::string startTimeStr = TimeToTimestampStr(eventData.start);
108 std::string endTimeStr = TimeToTimestampStr(eventData.end);
109
110 uint32 delay = sGameEventMgr->NextCheck(eventId);
111 time_t nextTime = GameTime::GetGameTime() + delay;
112 std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? TimeToTimestampStr(GameTime::GetGameTime() + delay) : "-";
113
114 std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE);
115 std::string lengthStr = secsToTimeString(eventData.length * MINUTE);
116
117 handler->PSendSysMessage(LANG_EVENT_INFO, eventId, eventData.description.c_str(), activeStr,
118 startTimeStr.c_str(), endTimeStr.c_str(), occurenceStr.c_str(), lengthStr.c_str(),
119 nextStr.c_str());
120 return true;
121 }
122
124 {
125 GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
126
127 if (*eventId < 1 || *eventId >= events.size())
128 {
130 handler->SetSentErrorMessage(true);
131 return false;
132 }
133
134 GameEventData const& eventData = events[*eventId];
135 if (!eventData.isValid())
136 {
138 handler->SetSentErrorMessage(true);
139 return false;
140 }
141
142 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
143 if (activeEvents.find(eventId) != activeEvents.end())
144 {
146 handler->SetSentErrorMessage(true);
147 return false;
148 }
149
150 sGameEventMgr->StartEvent(eventId, true);
151 return true;
152 }
153
155 {
156 GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
157
158 if (*eventId < 1 || *eventId >= events.size())
159 {
161 handler->SetSentErrorMessage(true);
162 return false;
163 }
164
165 GameEventData const& eventData = events[*eventId];
166 if (!eventData.isValid())
167 {
169 handler->SetSentErrorMessage(true);
170 return false;
171 }
172
173 GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
174
175 if (activeEvents.find(eventId) == activeEvents.end())
176 {
177 handler->PSendSysMessage(LANG_EVENT_NOT_ACTIVE, eventId);
178 handler->SetSentErrorMessage(true);
179 return false;
180 }
181
182 sGameEventMgr->StopEvent(eventId, true);
183 return true;
184 }
185};
186
188{
190}
@ MINUTE
Definition: Common.h:29
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
#define sGameEventMgr
Definition: GameEventMgr.h:177
@ LANG_EVENT_INFO
Definition: Language.h:671
@ LANG_EVENT_NOT_ACTIVE
Definition: Language.h:673
@ LANG_EVENT_ENTRY_LIST_CONSOLE
Definition: Language.h:876
@ LANG_EVENT_ENTRY_LIST_CHAT
Definition: Language.h:668
@ LANG_EVENT_ALREADY_ACTIVE
Definition: Language.h:672
@ LANG_ACTIVE
Definition: Language.h:67
@ LANG_NOEVENTFOUND
Definition: Language.h:669
@ LANG_EVENT_NOT_EXIST
Definition: Language.h:670
Role Based Access Control related classes definition.
std::string TimeToTimestampStr(time_t t)
Definition: Util.cpp:290
std::string secsToTimeString(uint64 timeInSecs, TimeFormat timeFormat, bool hoursOnly)
Definition: Util.cpp:115
WorldSession * GetSession()
Definition: Chat.h:42
void PSendSysMessage(const char *fmt, Args &&... args)
Definition: Chat.h:57
void SetSentErrorMessage(bool val)
Definition: Chat.h:114
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:113
virtual char const * GetTrinityString(uint32 entry) const
Definition: Chat.cpp:48
std::vector< GameEventData > GameEventDataMap
Definition: GameEventMgr.h:103
std::set< uint16 > ActiveEvents
Definition: GameEventMgr.h:102
static bool HandleEventActiveListCommand(ChatHandler *handler)
Definition: cs_event.cpp:56
static bool HandleEventStartCommand(ChatHandler *handler, Variant< Hyperlink< gameevent >, uint16 > eventId)
Definition: cs_event.cpp:123
static bool HandleEventInfoCommand(ChatHandler *handler, Variant< Hyperlink< gameevent >, uint16 > eventId)
Definition: cs_event.cpp:84
static bool HandleEventStopCommand(ChatHandler *handler, Variant< Hyperlink< gameevent >, uint16 > eventId)
Definition: cs_event.cpp:154
ChatCommandTable GetCommands() const override
Definition: cs_event.cpp:40
void AddSC_event_commandscript()
Definition: cs_event.cpp:187
time_t GetGameTime()
Definition: GameTime.cpp:44
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:49
@ RBAC_PERM_COMMAND_EVENT_START
Definition: RBAC.h:241
@ RBAC_PERM_COMMAND_EVENT_STOP
Definition: RBAC.h:242
@ RBAC_PERM_COMMAND_EVENT_ACTIVELIST
Definition: RBAC.h:240
@ RBAC_PERM_COMMAND_EVENT_INFO
Definition: RBAC.h:239
uint32 occurence
Definition: GameEventMgr.h:67
bool isValid() const
Definition: GameEventMgr.h:77
std::string description
Definition: GameEventMgr.h:74