1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Chat.h"
#include "CommandScript.h"
#include "GameEventMgr.h"
#include "GameTime.h"
#include "Language.h"
#include "Timer.h"
using namespace Acore::ChatCommands;
using EventEntry = Variant<Hyperlink<gameevent>, uint16>;
class event_commandscript : public CommandScript
{
public:
event_commandscript() : CommandScript("event_commandscript") { }
ChatCommandTable GetCommands() const override
{
static ChatCommandTable eventCommandTable =
{
{ "activelist", HandleEventActiveListCommand, SEC_GAMEMASTER, Console::Yes },
{ "start", HandleEventStartCommand, SEC_GAMEMASTER, Console::Yes },
{ "stop", HandleEventStopCommand, SEC_GAMEMASTER, Console::Yes },
{ "info", HandleEventInfoCommand, SEC_GAMEMASTER, Console::Yes }
};
static ChatCommandTable commandTable =
{
{ "event", eventCommandTable }
};
return commandTable;
}
static bool HandleEventActiveListCommand(ChatHandler* handler)
{
uint32 counter = 0;
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
std::string active = handler->GetAcoreString(LANG_ACTIVE);
for (uint16 eventId : activeEvents)
{
GameEventData const& eventData = events[eventId];
if (handler->GetSession())
handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, eventId, eventId, eventData.Description, active);
else
handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, eventId, eventData.Description, active);
++counter;
}
if (counter == 0)
handler->SendSysMessage(LANG_NOEVENTFOUND);
return true;
}
static bool HandleEventInfoCommand(ChatHandler* handler, EventEntry const eventId)
{
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
if (std::size_t(eventId) >= events.size())
{
handler->SendErrorMessage(LANG_EVENT_NOT_EXIST);
return false;
}
GameEventData const& eventData = events[eventId];
if (!eventData.isValid())
{
handler->SendErrorMessage(LANG_EVENT_NOT_EXIST);
return false;
}
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
bool active = activeEvents.find(eventId) != activeEvents.end();
std::string activeStr = active ? handler->GetAcoreString(LANG_ACTIVE) : "";
std::string startTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.Start));
std::string endTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.End));
uint32 delay = sGameEventMgr->NextCheck(eventId);
time_t nextTime = GameTime::GetGameTime().count() + delay;
std::string nextStr = nextTime >= eventData.Start && nextTime < eventData.End ? Acore::Time::TimeToTimestampStr(Seconds(nextTime)) : "-";
std::string occurenceStr = secsToTimeString(eventData.Occurence * MINUTE, true);
std::string lengthStr = secsToTimeString(eventData.Length * MINUTE, true);
handler->PSendSysMessage(LANG_EVENT_INFO, uint16(eventId), eventData.Description, activeStr,
startTimeStr, endTimeStr, occurenceStr, lengthStr,
nextStr);
return true;
}
static bool HandleEventStartCommand(ChatHandler* handler, EventEntry const eventId)
{
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
if (*eventId < 1 || *eventId >= events.size())
{
handler->SendErrorMessage(LANG_EVENT_NOT_EXIST);
return false;
}
GameEventData const& eventData = events[eventId];
if (!eventData.isValid())
{
handler->SendErrorMessage(LANG_EVENT_NOT_EXIST);
return false;
}
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
if (activeEvents.find(eventId) != activeEvents.end())
{
handler->SendErrorMessage(LANG_EVENT_ALREADY_ACTIVE, uint16(eventId), eventData.Description);
return false;
}
handler->PSendSysMessage(LANG_EVENT_STARTED, uint16(eventId), eventData.Description);
sGameEventMgr->StartEvent(eventId, true);
return true;
}
static bool HandleEventStopCommand(ChatHandler* handler, EventEntry const eventId)
{
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
if (*eventId < 1 || *eventId >= events.size())
{
handler->SendErrorMessage(LANG_EVENT_NOT_EXIST);
return false;
}
GameEventData const& eventData = events[eventId];
if (!eventData.isValid())
{
handler->SendErrorMessage(LANG_EVENT_NOT_EXIST);
return false;
}
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
if (activeEvents.find(eventId) == activeEvents.end())
{
handler->SendErrorMessage(LANG_EVENT_NOT_ACTIVE, uint16(eventId), eventData.Description);
return false;
}
handler->PSendSysMessage(LANG_EVENT_STOPPED, uint16(eventId), eventData.Description);
sGameEventMgr->StopEvent(eventId, true);
return true;
}
};
void AddSC_event_commandscript()
{
new event_commandscript();
}
|