Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
cs_event.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
/* ScriptData
7
Name: event_commandscript
8
%Complete: 100
9
Comment: All event related commands
10
Category: commandscripts
11
EndScriptData */
12
13
#include "
Chat.h
"
14
#include "
GameEventMgr.h
"
15
#include "
Language.h
"
16
#include "
Player.h
"
17
#include "
ScriptMgr.h
"
18
19
class
event_commandscript
:
public
CommandScript
20
{
21
public
:
22
event_commandscript
() :
CommandScript
(
"event_commandscript"
) { }
23
24
std::vector<ChatCommand>
GetCommands
() const
OVERRIDE
25
{
26
static
std::vector<ChatCommand> eventCommandTable =
27
{
28
{
"activelist"
,
rbac::RBAC_PERM_COMMAND_EVENT_ACTIVELIST
,
true
, &
HandleEventActiveListCommand
,
""
, },
29
{
"start"
,
rbac::RBAC_PERM_COMMAND_EVENT_START
,
true
, &
HandleEventStartCommand
,
""
, },
30
{
"stop"
,
rbac::RBAC_PERM_COMMAND_EVENT_STOP
,
true
, &
HandleEventStopCommand
,
""
, },
31
{
""
,
rbac::RBAC_PERM_COMMAND_EVENT
,
true
, &
HandleEventInfoCommand
,
""
, },
32
};
33
static
std::vector<ChatCommand> commandTable =
34
{
35
{
"event"
,
rbac::RBAC_PERM_COMMAND_EVENT
,
false
, NULL,
""
, eventCommandTable },
36
};
37
return
commandTable;
38
}
39
40
static
bool
HandleEventActiveListCommand
(
ChatHandler
* handler,
char
const
*
/*args*/
)
41
{
42
uint32
counter = 0;
43
44
GameEventMgr::GameEventDataMap
const
& events =
sGameEventMgr
->GetEventMap();
45
GameEventMgr::ActiveEvents
const
& activeEvents =
sGameEventMgr
->GetActiveEventList();
46
47
char
const
* active = handler->
GetSkyFireString
(
LANG_ACTIVE
);
48
49
for
(GameEventMgr::ActiveEvents::const_iterator itr = activeEvents.begin(); itr != activeEvents.end(); ++itr)
50
{
51
uint32
eventId = *itr;
52
GameEventData
const
& eventData = events[eventId];
53
54
if
(handler->
GetSession
())
55
handler->
PSendSysMessage
(
LANG_EVENT_ENTRY_LIST_CHAT
, eventId, eventId, eventData.
description
.c_str(), active);
56
else
57
handler->
PSendSysMessage
(
LANG_EVENT_ENTRY_LIST_CONSOLE
, eventId, eventData.
description
.c_str(), active);
58
59
++counter;
60
}
61
62
if
(counter == 0)
63
handler->
SendSysMessage
(
LANG_NOEVENTFOUND
);
64
handler->
SetSentErrorMessage
(
true
);
65
66
return
true
;
67
}
68
69
static
bool
HandleEventInfoCommand
(
ChatHandler
* handler,
char
const
* args)
70
{
71
if
(!*args)
72
return
false
;
73
74
// id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
75
char
*
id
= handler->
extractKeyFromLink
((
char
*)args,
"Hgameevent"
);
76
if
(!
id
)
77
return
false
;
78
79
uint32
eventId = atoi(
id
);
80
81
GameEventMgr::GameEventDataMap
const
& events =
sGameEventMgr
->GetEventMap();
82
83
if
(eventId >= events.size())
84
{
85
handler->
SendSysMessage
(
LANG_EVENT_NOT_EXIST
);
86
handler->
SetSentErrorMessage
(
true
);
87
return
false
;
88
}
89
90
GameEventData
const
& eventData = events[eventId];
91
if
(!eventData.
isValid
())
92
{
93
handler->
SendSysMessage
(
LANG_EVENT_NOT_EXIST
);
94
handler->
SetSentErrorMessage
(
true
);
95
return
false
;
96
}
97
98
GameEventMgr::ActiveEvents
const
& activeEvents =
sGameEventMgr
->GetActiveEventList();
99
bool
active = activeEvents.find(eventId) != activeEvents.end();
100
char
const
* activeStr = active ? handler->
GetSkyFireString
(
LANG_ACTIVE
) :
""
;
101
102
std::string startTimeStr =
TimeToTimestampStr
(eventData.
start
);
103
std::string endTimeStr =
TimeToTimestampStr
(eventData.
end
);
104
105
uint32
delay =
sGameEventMgr
->NextCheck(eventId);
106
time_t nextTime = time(NULL) + delay;
107
std::string nextStr = nextTime >= eventData.
start
&& nextTime < eventData.
end
?
TimeToTimestampStr
(time(NULL) + delay) :
"-"
;
108
109
std::string occurenceStr =
secsToTimeString
(eventData.
occurence
*
MINUTE
);
110
std::string lengthStr =
secsToTimeString
(eventData.
length
*
MINUTE
);
111
112
handler->
PSendSysMessage
(
LANG_EVENT_INFO
, eventId, eventData.
description
.c_str(), activeStr,
113
startTimeStr.c_str(), endTimeStr.c_str(), occurenceStr.c_str(), lengthStr.c_str(),
114
nextStr.c_str());
115
return
true
;
116
}
117
118
static
bool
HandleEventStartCommand
(
ChatHandler
* handler,
char
const
* args)
119
{
120
if
(!*args)
121
return
false
;
122
123
// id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
124
char
*
id
= handler->
extractKeyFromLink
((
char
*)args,
"Hgameevent"
);
125
if
(!
id
)
126
return
false
;
127
128
int32
eventId = atoi(
id
);
129
130
GameEventMgr::GameEventDataMap
const
& events =
sGameEventMgr
->GetEventMap();
131
132
if
(eventId < 1 ||
uint32
(eventId) >= events.size())
133
{
134
handler->
SendSysMessage
(
LANG_EVENT_NOT_EXIST
);
135
handler->
SetSentErrorMessage
(
true
);
136
return
false
;
137
}
138
139
GameEventData
const
& eventData = events[eventId];
140
if
(!eventData.
isValid
())
141
{
142
handler->
SendSysMessage
(
LANG_EVENT_NOT_EXIST
);
143
handler->
SetSentErrorMessage
(
true
);
144
return
false
;
145
}
146
147
GameEventMgr::ActiveEvents
const
& activeEvents =
sGameEventMgr
->GetActiveEventList();
148
if
(activeEvents.find(eventId) != activeEvents.end())
149
{
150
handler->
PSendSysMessage
(
LANG_EVENT_ALREADY_ACTIVE
, eventId);
151
handler->
SetSentErrorMessage
(
true
);
152
return
false
;
153
}
154
155
sGameEventMgr
->StartEvent(eventId,
true
);
156
return
true
;
157
}
158
159
static
bool
HandleEventStopCommand
(
ChatHandler
* handler,
char
const
* args)
160
{
161
if
(!*args)
162
return
false
;
163
164
// id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
165
char
*
id
= handler->
extractKeyFromLink
((
char
*)args,
"Hgameevent"
);
166
if
(!
id
)
167
return
false
;
168
169
int32
eventId = atoi(
id
);
170
171
GameEventMgr::GameEventDataMap
const
& events =
sGameEventMgr
->GetEventMap();
172
173
if
(eventId < 1 ||
uint32
(eventId) >= events.size())
174
{
175
handler->
SendSysMessage
(
LANG_EVENT_NOT_EXIST
);
176
handler->
SetSentErrorMessage
(
true
);
177
return
false
;
178
}
179
180
GameEventData
const
& eventData = events[eventId];
181
if
(!eventData.
isValid
())
182
{
183
handler->
SendSysMessage
(
LANG_EVENT_NOT_EXIST
);
184
handler->
SetSentErrorMessage
(
true
);
185
return
false
;
186
}
187
188
GameEventMgr::ActiveEvents
const
& activeEvents =
sGameEventMgr
->GetActiveEventList();
189
190
if
(activeEvents.find(eventId) == activeEvents.end())
191
{
192
handler->
PSendSysMessage
(
LANG_EVENT_NOT_ACTIVE
, eventId);
193
handler->
SetSentErrorMessage
(
true
);
194
return
false
;
195
}
196
197
sGameEventMgr
->StopEvent(eventId,
true
);
198
return
true
;
199
}
200
};
201
202
void
AddSC_event_commandscript
()
203
{
204
new
event_commandscript
();
205
}
Chat.h
MINUTE
@ MINUTE
Definition
Common.h:119
int32
std::int32_t int32
Definition
Define.h:73
uint32
std::uint32_t uint32
Definition
Define.h:77
OVERRIDE
#define OVERRIDE
Definition
Define.h:60
GameEventMgr.h
sGameEventMgr
#define sGameEventMgr
Definition
GameEventMgr.h:170
Language.h
LANG_EVENT_INFO
@ LANG_EVENT_INFO
Definition
Language.h:591
LANG_EVENT_NOT_ACTIVE
@ LANG_EVENT_NOT_ACTIVE
Definition
Language.h:593
LANG_EVENT_ENTRY_LIST_CONSOLE
@ LANG_EVENT_ENTRY_LIST_CONSOLE
Definition
Language.h:893
LANG_EVENT_ENTRY_LIST_CHAT
@ LANG_EVENT_ENTRY_LIST_CHAT
Definition
Language.h:588
LANG_EVENT_ALREADY_ACTIVE
@ LANG_EVENT_ALREADY_ACTIVE
Definition
Language.h:592
LANG_ACTIVE
@ LANG_ACTIVE
Definition
Language.h:48
LANG_NOEVENTFOUND
@ LANG_NOEVENTFOUND
Definition
Language.h:589
LANG_EVENT_NOT_EXIST
@ LANG_EVENT_NOT_EXIST
Definition
Language.h:590
Player.h
ScriptMgr.h
TimeToTimestampStr
std::string TimeToTimestampStr(time_t t)
Definition
Util.cpp:213
secsToTimeString
std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
Definition
Util.cpp:127
ChatHandler
Definition
Chat.h:41
ChatHandler::GetSession
WorldSession * GetSession()
Definition
Chat.h:43
ChatHandler::extractKeyFromLink
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition
Chat.cpp:873
ChatHandler::PSendSysMessage
void PSendSysMessage(const char *format,...) ATTR_PRINTF(2
Definition
Chat.cpp:221
ChatHandler::SetSentErrorMessage
void SetSentErrorMessage(bool val)
Definition
Chat.h:114
ChatHandler::SendSysMessage
virtual void SendSysMessage(const char *str)
Definition
Chat.cpp:153
ChatHandler::GetSkyFireString
virtual const char * GetSkyFireString(int32 entry) const
Definition
Chat.cpp:68
CommandScript::CommandScript
CommandScript(const char *name)
Definition
ScriptMgr.cpp:1466
GameEventMgr::GameEventDataMap
std::vector< GameEventData > GameEventDataMap
Definition
GameEventMgr.h:93
GameEventMgr::ActiveEvents
std::set< uint16 > ActiveEvents
Definition
GameEventMgr.h:92
event_commandscript
Definition
cs_event.cpp:20
event_commandscript::HandleEventInfoCommand
static bool HandleEventInfoCommand(ChatHandler *handler, char const *args)
Definition
cs_event.cpp:69
event_commandscript::event_commandscript
event_commandscript()
Definition
cs_event.cpp:22
event_commandscript::GetCommands
std::vector< ChatCommand > GetCommands() const OVERRIDE
Definition
cs_event.cpp:24
event_commandscript::HandleEventActiveListCommand
static bool HandleEventActiveListCommand(ChatHandler *handler, char const *)
Definition
cs_event.cpp:40
event_commandscript::HandleEventStartCommand
static bool HandleEventStartCommand(ChatHandler *handler, char const *args)
Definition
cs_event.cpp:118
event_commandscript::HandleEventStopCommand
static bool HandleEventStopCommand(ChatHandler *handler, char const *args)
Definition
cs_event.cpp:159
AddSC_event_commandscript
void AddSC_event_commandscript()
Definition
cs_event.cpp:202
rbac::RBAC_PERM_COMMAND_EVENT_START
@ RBAC_PERM_COMMAND_EVENT_START
Definition
RBAC.h:257
rbac::RBAC_PERM_COMMAND_EVENT
@ RBAC_PERM_COMMAND_EVENT
Definition
RBAC.h:255
rbac::RBAC_PERM_COMMAND_EVENT_STOP
@ RBAC_PERM_COMMAND_EVENT_STOP
Definition
RBAC.h:258
rbac::RBAC_PERM_COMMAND_EVENT_ACTIVELIST
@ RBAC_PERM_COMMAND_EVENT_ACTIVELIST
Definition
RBAC.h:256
GameEventData
Definition
GameEventMgr.h:44
GameEventData::occurence
uint32 occurence
Definition
GameEventMgr.h:49
GameEventData::end
time_t end
Definition
GameEventMgr.h:47
GameEventData::isValid
bool isValid() const
Definition
GameEventMgr.h:58
GameEventData::length
uint32 length
Definition
GameEventMgr.h:50
GameEventData::start
time_t start
Definition
GameEventMgr.h:46
GameEventData::description
std::string description
Definition
GameEventMgr.h:55
src
server
scripts
Commands
cs_event.cpp
Generated on
for Project SkyFire Core by
1.17.0