TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
instance_commandscript Class Reference

Public Member Functions

 instance_commandscript ()
 
std::vector< ChatCommandGetCommands () const override
 
- Public Member Functions inherited from ScriptObject
const std::string & GetName () const
 

Static Public Member Functions

static std::string GetTimeString (uint64 time)
 
static bool HandleInstanceListBindsCommand (ChatHandler *handler, char const *)
 
static bool HandleInstanceUnbindCommand (ChatHandler *handler, char const *args)
 
static bool HandleInstanceStatsCommand (ChatHandler *handler, char const *)
 
static bool HandleInstanceSaveDataCommand (ChatHandler *handler, char const *)
 
static bool HandleInstanceSetBossStateCommand (ChatHandler *handler, char const *args)
 
static bool HandleInstanceGetBossStateCommand (ChatHandler *handler, char const *args)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name)
 
virtual ~ScriptObject ()
 

Constructor & Destructor Documentation

instance_commandscript::instance_commandscript ( )
inline
37 : CommandScript("instance_commandscript") { }
CommandScript(const char *name)
Definition: ScriptMgr.cpp:1616

Member Function Documentation

std::vector<ChatCommand> instance_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

40  {
41  static std::vector<ChatCommand> instanceCommandTable =
42  {
49  };
50 
51  static std::vector<ChatCommand> commandTable =
52  {
53  { "instance", rbac::RBAC_PERM_COMMAND_INSTANCE, true, NULL, "", instanceCommandTable },
54  };
55 
56  return commandTable;
57  }
static bool HandleInstanceListBindsCommand(ChatHandler *handler, char const *)
Definition: cs_instance.cpp:71
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: RBAC.h:319
static bool HandleInstanceUnbindCommand(ChatHandler *handler, char const *args)
Definition: cs_instance.cpp:111
static bool HandleInstanceSetBossStateCommand(ChatHandler *handler, char const *args)
Definition: cs_instance.cpp:191
static bool HandleInstanceStatsCommand(ChatHandler *handler, char const *)
Definition: cs_instance.cpp:157
static bool HandleInstanceSaveDataCommand(ChatHandler *handler, char const *)
Definition: cs_instance.cpp:168
static bool HandleInstanceGetBossStateCommand(ChatHandler *handler, char const *args)
Definition: cs_instance.cpp:260

+ Here is the call graph for this function:

static std::string instance_commandscript::GetTimeString ( uint64  time)
inlinestatic
60  {
61  uint64 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
62  std::ostringstream ss;
63  if (days)
64  ss << days << "d ";
65  if (hours)
66  ss << hours << "h ";
67  ss << minute << 'm';
68  return ss.str();
69  }
Definition: Common.h:98
Definition: Common.h:97
Definition: Common.h:99
uint64_t uint64
Definition: Define.h:149
float hours()
Definition: units.h:107
float days()
Definition: units.h:112

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool instance_commandscript::HandleInstanceGetBossStateCommand ( ChatHandler handler,
char const args 
)
inlinestatic
261  {
262  if (!*args)
263  return false;
264 
265  char* param1 = strtok((char*)args, " ");
266  char* param2 = strtok(nullptr, " ");
267  uint32 encounterId = 0;
268  Player* player = nullptr;
269  std::string playerName;
270 
271  // Character name must be provided when using this from console.
272  if (!param1 || (!param2 && !handler->GetSession()))
273  {
275  handler->SetSentErrorMessage(true);
276  return false;
277  }
278 
279  if (!param2)
280  player = handler->GetSession()->GetPlayer();
281  else
282  {
283  playerName = param2;
284  if (normalizePlayerName(playerName))
285  player = ObjectAccessor::FindPlayerByName(playerName);
286  }
287 
288  if (!player)
289  {
291  handler->SetSentErrorMessage(true);
292  return false;
293  }
294 
295  InstanceMap* map = player->GetMap()->ToInstanceMap();
296  if (!map)
297  {
299  handler->SetSentErrorMessage(true);
300  return false;
301  }
302 
303  if (!map->GetInstanceScript())
304  {
306  handler->SetSentErrorMessage(true);
307  return false;
308  }
309 
310  encounterId = atoi(param1);
311 
312  if (encounterId > map->GetInstanceScript()->GetEncounterCount())
313  {
315  handler->SetSentErrorMessage(true);
316  return false;
317  }
318 
319  uint32 state = map->GetInstanceScript()->GetBossState(encounterId);
320  std::string stateName = InstanceScript::GetBossStateName(state);
321  handler->PSendSysMessage(LANG_COMMAND_INST_GET_BOSS_STATE, encounterId, state, stateName);
322  return true;
323  }
Definition: Language.h:1126
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
Definition: Language.h:43
Player * GetPlayer() const
Definition: WorldSession.h:927
bool normalizePlayerName(std::string &name)
Definition: ObjectMgr.cpp:133
Definition: Language.h:1124
Definition: Map.h:758
InstanceMap * ToInstanceMap()
Definition: Map.h:495
uint32_t uint32
Definition: Define.h:150
TC_GAME_API Player * FindPlayerByName(std::string const &name)
Definition: ObjectAccessor.cpp:220
uint32 GetEncounterCount() const
Definition: InstanceScript.h:254
Definition: Language.h:139
InstanceScript * GetInstanceScript()
Definition: Map.h:769
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
static std::string GetBossStateName(uint8 state)
Definition: InstanceScript.cpp:654
EncounterState GetBossState(uint32 id) const
Definition: InstanceScript.h:227
Definition: Language.h:509
Definition: Language.h:1123

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool instance_commandscript::HandleInstanceListBindsCommand ( ChatHandler handler,
char const  
)
inlinestatic
72  {
73  Player* player = handler->getSelectedPlayer();
74  if (!player)
75  player = handler->GetSession()->GetPlayer();
76 
77  uint32 counter = 0;
78  for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
79  {
80  Player::BoundInstancesMap &binds = player->GetBoundInstances(Difficulty(i));
81  for (Player::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
82  {
83  InstanceSave* save = itr->second.save;
84  std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
85  handler->PSendSysMessage(LANG_COMMAND_LIST_BIND_INFO, itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", itr->second.extendState == EXTEND_STATE_EXPIRED ? "expired" : itr->second.extendState == EXTEND_STATE_EXTENDED ? "yes" : "no", save->GetDifficultyID(), save->CanReset() ? "yes" : "no", timeleft.c_str());
86  counter++;
87  }
88  }
90 
91  counter = 0;
92  if (Group* group = player->GetGroup())
93  {
94  for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
95  {
96  Group::BoundInstancesMap &binds = group->GetBoundInstances(Difficulty(i));
97  for (Group::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
98  {
99  InstanceSave* save = itr->second.save;
100  std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
101  handler->PSendSysMessage(LANG_COMMAND_LIST_BIND_INFO, itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", "-", save->GetDifficultyID(), save->CanReset() ? "yes" : "no", timeleft.c_str());
102  counter++;
103  }
104  }
105  }
107 
108  return true;
109  }
Definition: Language.h:1114
Difficulty
Definition: DBCEnums.h:402
std::unordered_map< uint32, InstanceGroupBind > BoundInstancesMap
Definition: Group.h:207
Definition: DBCEnums.h:426
arena_t NULL
Definition: jemalloc_internal.h:624
Player * GetPlayer() const
Definition: WorldSession.h:927
static std::string GetTimeString(uint64 time)
Definition: cs_instance.cpp:59
uint32_t uint32
Definition: Define.h:150
Definition: InstanceSaveMgr.h:44
Player * getSelectedPlayer()
Definition: Chat.cpp:579
Difficulty GetDifficultyID() const
Definition: InstanceSaveMgr.h:121
Definition: Language.h:1115
WorldSession * GetSession()
Definition: Chat.h:59
uint8_t uint8
Definition: Define.h:152
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
bool CanReset() const
Definition: InstanceSaveMgr.h:116
uint32 GetInstanceId() const
Definition: InstanceSaveMgr.h:64
time_t GetResetTime() const
Definition: InstanceSaveMgr.h:74
Definition: Group.h:191
Definition: Language.h:1113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool instance_commandscript::HandleInstanceSaveDataCommand ( ChatHandler handler,
char const  
)
inlinestatic
169  {
170  Player* player = handler->GetSession()->GetPlayer();
171  InstanceMap* map = player->GetMap()->ToInstanceMap();
172  if (!map)
173  {
175  handler->SetSentErrorMessage(true);
176  return false;
177  }
178 
179  if (!map->GetInstanceScript())
180  {
182  handler->SetSentErrorMessage(true);
183  return false;
184  }
185 
186  map->GetInstanceScript()->SaveToDB();
187 
188  return true;
189  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
Player * GetPlayer() const
Definition: WorldSession.h:927
Definition: Language.h:1124
Definition: Map.h:758
void SaveToDB()
Definition: InstanceScript.cpp:39
InstanceMap * ToInstanceMap()
Definition: Map.h:495
InstanceScript * GetInstanceScript()
Definition: Map.h:769
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: Language.h:1123

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool instance_commandscript::HandleInstanceSetBossStateCommand ( ChatHandler handler,
char const args 
)
inlinestatic
192  {
193  if (!*args)
194  return false;
195 
196  char* param1 = strtok((char*)args, " ");
197  char* param2 = strtok(nullptr, " ");
198  char* param3 = strtok(nullptr, " ");
199  uint32 encounterId = 0;
200  int32 state = 0;
201  Player* player = nullptr;
202  std::string playerName;
203 
204  // Character name must be provided when using this from console.
205  if (!param2 || (!param3 && !handler->GetSession()))
206  {
208  handler->SetSentErrorMessage(true);
209  return false;
210  }
211 
212  if (!param3)
213  player = handler->GetSession()->GetPlayer();
214  else
215  {
216  playerName = param3;
217  if (normalizePlayerName(playerName))
218  player = ObjectAccessor::FindPlayerByName(playerName);
219  }
220 
221  if (!player)
222  {
224  handler->SetSentErrorMessage(true);
225  return false;
226  }
227 
228  InstanceMap* map = player->GetMap()->ToInstanceMap();
229  if (!map)
230  {
232  handler->SetSentErrorMessage(true);
233  return false;
234  }
235 
236  if (!map->GetInstanceScript())
237  {
239  handler->SetSentErrorMessage(true);
240  return false;
241  }
242 
243  encounterId = atoi(param1);
244  state = atoi(param2);
245 
246  // Reject improper values.
247  if (state > TO_BE_DECIDED || encounterId > map->GetInstanceScript()->GetEncounterCount())
248  {
250  handler->SetSentErrorMessage(true);
251  return false;
252  }
253 
254  map->GetInstanceScript()->SetBossState(encounterId, EncounterState(state));
255  std::string stateName = InstanceScript::GetBossStateName(state);
256  handler->PSendSysMessage(LANG_COMMAND_INST_SET_BOSS_STATE, encounterId, state, stateName);
257  return true;
258  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
Definition: Language.h:1125
Definition: Language.h:43
EncounterState
Definition: InstanceScript.h:56
Player * GetPlayer() const
Definition: WorldSession.h:927
bool normalizePlayerName(std::string &name)
Definition: ObjectMgr.cpp:133
Definition: Language.h:1124
Definition: Map.h:758
InstanceMap * ToInstanceMap()
Definition: Map.h:495
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
TC_GAME_API Player * FindPlayerByName(std::string const &name)
Definition: ObjectAccessor.cpp:220
virtual bool SetBossState(uint32 id, EncounterState state)
Definition: InstanceScript.cpp:273
uint32 GetEncounterCount() const
Definition: InstanceScript.h:254
Definition: Language.h:139
InstanceScript * GetInstanceScript()
Definition: Map.h:769
WorldSession * GetSession()
Definition: Chat.h:59
Definition: InstanceScript.h:63
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
static std::string GetBossStateName(uint8 state)
Definition: InstanceScript.cpp:654
Definition: Language.h:509
Definition: Language.h:1123

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool instance_commandscript::HandleInstanceStatsCommand ( ChatHandler handler,
char const  
)
inlinestatic
158  {
159  handler->PSendSysMessage(LANG_COMMAND_INST_STAT_LOADED_INST, sMapMgr->GetNumInstances());
160  handler->PSendSysMessage(LANG_COMMAND_INST_STAT_PLAYERS_IN, sMapMgr->GetNumPlayersInInstances());
161  handler->PSendSysMessage(LANG_COMMAND_INST_STAT_SAVES, sInstanceSaveMgr->GetNumInstanceSaves());
162  handler->PSendSysMessage(LANG_COMMAND_INST_STAT_PLAYERSBOUND, sInstanceSaveMgr->GetNumBoundPlayersTotal());
163  handler->PSendSysMessage(LANG_COMMAND_INST_STAT_GROUPSBOUND, sInstanceSaveMgr->GetNumBoundGroupsTotal());
164 
165  return true;
166  }
Definition: Language.h:1118
Definition: Language.h:1119
Definition: Language.h:1122
#define sInstanceSaveMgr
Definition: InstanceSaveMgr.h:243
#define sMapMgr
Definition: MapManager.h:194
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: Language.h:1120
Definition: Language.h:1121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool instance_commandscript::HandleInstanceUnbindCommand ( ChatHandler handler,
char const args 
)
inlinestatic
112  {
113  if (!*args)
114  return false;
115 
116  Player* player = handler->getSelectedPlayer();
117  if (!player)
118  player = handler->GetSession()->GetPlayer();
119 
120  char* map = strtok((char*)args, " ");
121  char* pDiff = strtok(NULL, " ");
122  int8 diff = -1;
123  if (pDiff)
124  diff = atoi(pDiff);
125  uint16 counter = 0;
126  uint16 MapId = 0;
127 
128  if (strcmp(map, "all") != 0)
129  {
130  MapId = uint16(atoi(map));
131  if (!MapId)
132  return false;
133  }
134 
135  for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
136  {
137  Player::BoundInstancesMap &binds = player->GetBoundInstances(Difficulty(i));
138  for (Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
139  {
140  InstanceSave* save = itr->second.save;
141  if (itr->first != player->GetMapId() && (!MapId || MapId == itr->first) && (diff == -1 || diff == save->GetDifficultyID()))
142  {
143  std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
144  handler->PSendSysMessage(LANG_COMMAND_INST_UNBIND_UNBINDING, itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficultyID(), save->CanReset() ? "yes" : "no", timeleft.c_str());
145  player->UnbindInstance(itr, Difficulty(i));
146  counter++;
147  }
148  else
149  ++itr;
150  }
151  }
153 
154  return true;
155  }
Difficulty
Definition: DBCEnums.h:402
int8_t int8
Definition: Define.h:148
Definition: DBCEnums.h:426
Definition: Language.h:1116
arena_t NULL
Definition: jemalloc_internal.h:624
Player * GetPlayer() const
Definition: WorldSession.h:927
Definition: Language.h:1117
uint16_t uint16
Definition: g3dmath.h:166
static std::string GetTimeString(uint64 time)
Definition: cs_instance.cpp:59
uint16_t uint16
Definition: Define.h:151
Definition: InstanceSaveMgr.h:44
Player * getSelectedPlayer()
Definition: Chat.cpp:579
Difficulty GetDifficultyID() const
Definition: InstanceSaveMgr.h:121
WorldSession * GetSession()
Definition: Chat.h:59
uint8_t uint8
Definition: Define.h:152
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
bool CanReset() const
Definition: InstanceSaveMgr.h:116
uint32 GetInstanceId() const
Definition: InstanceSaveMgr.h:64
time_t GetResetTime() const
Definition: InstanceSaveMgr.h:74

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


The documentation for this class was generated from the following file: