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

Public Member Functions

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

Static Public Member Functions

static bool HandleArenaCreateCommand (ChatHandler *handler, char const *args)
 
static bool HandleArenaDisbandCommand (ChatHandler *handler, char const *args)
 
static bool HandleArenaRenameCommand (ChatHandler *handler, char const *_args)
 
static bool HandleArenaCaptainCommand (ChatHandler *handler, char const *args)
 
static bool HandleArenaInfoCommand (ChatHandler *handler, char const *args)
 
static bool HandleArenaLookupCommand (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

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

Member Function Documentation

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

Implements CommandScript.

38  {
39  static std::vector<ChatCommand> arenaCommandTable =
40  {
47  };
48  static std::vector<ChatCommand> commandTable =
49  {
50  { "arena", rbac::RBAC_PERM_COMMAND_ARENA, false, NULL, "", arenaCommandTable },
51  };
52  return commandTable;
53  }
static bool HandleArenaRenameCommand(ChatHandler *handler, char const *_args)
Definition: cs_arena.cpp:155
static bool HandleArenaDisbandCommand(ChatHandler *handler, char const *args)
Definition: cs_arena.cpp:116
arena_t NULL
Definition: jemalloc_internal.h:624
static bool HandleArenaCaptainCommand(ChatHandler *handler, char const *args)
Definition: cs_arena.cpp:217
static bool HandleArenaLookupCommand(ChatHandler *handler, char const *args)
Definition: cs_arena.cpp:320
static bool HandleArenaInfoCommand(ChatHandler *handler, char const *args)
Definition: cs_arena.cpp:295
Definition: RBAC.h:139
static bool HandleArenaCreateCommand(ChatHandler *handler, char const *args)
Definition: cs_arena.cpp:55

+ Here is the call graph for this function:

static bool arena_commandscript::HandleArenaCaptainCommand ( ChatHandler handler,
char const args 
)
inlinestatic
218  {
219  if (!*args)
220  return false;
221 
222  char* idStr;
223  char* nameStr;
224  handler->extractOptFirstArg((char*)args, &idStr, &nameStr);
225  if (!idStr)
226  return false;
227 
228  uint32 teamId = atoi(idStr);
229  if (!teamId)
230  return false;
231 
232  Player* target;
233  ObjectGuid targetGuid;
234  if (!handler->extractPlayerTarget(nameStr, &target, &targetGuid))
235  return false;
236 
237  ArenaTeam* arena = sArenaTeamMgr->GetArenaTeamById(teamId);
238 
239  if (!arena)
240  {
242  handler->SetSentErrorMessage(true);
243  return false;
244  }
245 
246  if (!target)
247  {
249  handler->SetSentErrorMessage(true);
250  return false;
251  }
252 
253  if (arena->IsFighting())
254  {
256  handler->SetSentErrorMessage(true);
257  return false;
258  }
259 
260  if (!arena->IsMember(targetGuid))
261  {
262  handler->PSendSysMessage(LANG_ARENA_ERROR_NOT_MEMBER, nameStr, arena->GetName().c_str());
263  handler->SetSentErrorMessage(true);
264  return false;
265  }
266 
267  if (arena->GetCaptain() == targetGuid)
268  {
269  handler->PSendSysMessage(LANG_ARENA_ERROR_CAPTAIN, nameStr, arena->GetName().c_str());
270  handler->SetSentErrorMessage(true);
271  return false;
272  }
273 
274  arena->SetCaptain(targetGuid);
275 
276  std::string oldCaptainName;
277  if (!ObjectMgr::GetPlayerNameByGUID(arena->GetCaptain(), oldCaptainName))
278  {
279  handler->SetSentErrorMessage(true);
280  return false;
281  }
282 
283  handler->PSendSysMessage(LANG_ARENA_CAPTAIN, arena->GetName().c_str(), arena->GetId(), oldCaptainName.c_str(), target->GetName().c_str());
284  if (handler->GetSession())
285  TC_LOG_DEBUG("bg.arena", "GameMaster: %s [%s] promoted player: %s [%s] to leader of arena team \"%s\"[Id: %u]",
286  handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUID().ToString().c_str(),
287  target->GetName().c_str(), target->GetGUID().ToString().c_str(), arena->GetName().c_str(), arena->GetId());
288  else
289  TC_LOG_DEBUG("bg.arena", "Console: promoted player: %s [%s] to leader of arena team \"%s\"[Id: %u]",
290  target->GetName().c_str(), target->GetGUID().ToString().c_str(), arena->GetName().c_str(), arena->GetId());
291 
292  return true;
293  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
Definition: Language.h:846
std::string const & GetName() const
Definition: ArenaTeam.h:130
bool IsMember(ObjectGuid guid) const
Definition: ArenaTeam.cpp:486
Definition: Language.h:847
void SetCaptain(ObjectGuid guid)
Definition: ArenaTeam.cpp:278
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Player * GetPlayer() const
Definition: WorldSession.h:927
bool extractPlayerTarget(char *args, Player **player, ObjectGuid *player_guid=NULL, std::string *player_name=NULL)
Definition: Chat.cpp:945
Definition: Language.h:851
uint32 GetId() const
Definition: ArenaTeam.h:124
Definition: Language.h:775
uint32_t uint32
Definition: Define.h:150
static bool GetPlayerNameByGUID(ObjectGuid const &guid, std::string &name)
Definition: ObjectMgr.cpp:2258
Definition: ArenaTeam.h:112
Definition: Language.h:841
Definition: Language.h:844
bool IsFighting() const
Definition: ArenaTeam.cpp:781
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
#define sArenaTeamMgr
Definition: ArenaTeamMgr.h:53
void extractOptFirstArg(char *args, char **arg1, char **arg2)
Definition: Chat.cpp:998
Definition: ObjectGuid.h:189
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
ObjectGuid GetCaptain() const
Definition: ArenaTeam.h:129

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool arena_commandscript::HandleArenaCreateCommand ( ChatHandler handler,
char const args 
)
inlinestatic
56  {
57  if (!*args)
58  return false;
59 
60  Player* target;
61  if (!handler->extractPlayerTarget(*args != '"' ? (char*)args : NULL, &target))
62  return false;
63 
64  char* tailStr = *args != '"' ? strtok(NULL, "") : (char*)args;
65  if (!tailStr)
66  return false;
67 
68  char* name = handler->extractQuotedArg(tailStr);
69  if (!name)
70  return false;
71 
72  char* typeStr = strtok(NULL, "");
73  if (!typeStr)
74  return false;
75 
76  int8 type = atoi(typeStr);
77  if (sArenaTeamMgr->GetArenaTeamByName(name))
78  {
80  handler->SetSentErrorMessage(true);
81  return false;
82  }
83 
84  if (type == 2 || type == 3 || type == 5 )
85  {
86  if (Player::GetArenaTeamIdFromDB(target->GetGUID(), type) != 0)
87  {
88  handler->PSendSysMessage(LANG_ARENA_ERROR_SIZE, target->GetName().c_str());
89  handler->SetSentErrorMessage(true);
90  return false;
91  }
92 
93  ArenaTeam* arena = new ArenaTeam();
94 
95  if (!arena->Create(target->GetGUID(), type, name, 4293102085, 101, 4293253939, 4, 4284049911))
96  {
97  delete arena;
99  handler->SetSentErrorMessage(true);
100  return false;
101  }
102 
103  sArenaTeamMgr->AddArenaTeam(arena);
104  handler->PSendSysMessage(LANG_ARENA_CREATE, arena->GetName().c_str(), arena->GetId(), arena->GetType(), arena->GetCaptain().ToString().c_str());
105  }
106  else
107  {
108  handler->SendSysMessage(LANG_BAD_VALUE);
109  handler->SetSentErrorMessage(true);
110  return false;
111  }
112 
113  return true;
114  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
int8_t int8
Definition: Define.h:148
uint32 GetType() const
Definition: ArenaTeam.h:125
std::string const & GetName() const
Definition: ArenaTeam.h:130
Definition: Language.h:843
char * extractQuotedArg(char *args)
Definition: Chat.cpp:1016
arena_t NULL
Definition: jemalloc_internal.h:624
bool extractPlayerTarget(char *args, Player **player, ObjectGuid *player_guid=NULL, std::string *player_name=NULL)
Definition: Chat.cpp:945
uint32 GetId() const
Definition: ArenaTeam.h:124
bool Create(ObjectGuid captainGuid, uint8 type, std::string const &teamName, uint32 backgroundColor, uint8 emblemStyle, uint32 emblemColor, uint8 borderStyle, uint32 borderColor)
Definition: ArenaTeam.cpp:44
Definition: Language.h:139
Definition: ArenaTeam.h:112
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
#define sArenaTeamMgr
Definition: ArenaTeamMgr.h:53
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
std::string ToString() const
Definition: ObjectGuid.cpp:99
ObjectGuid GetCaptain() const
Definition: ArenaTeam.h:129
Definition: Language.h:842
Definition: Language.h:848

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool arena_commandscript::HandleArenaDisbandCommand ( ChatHandler handler,
char const args 
)
inlinestatic
117  {
118  if (!*args)
119  return false;
120 
121  uint32 teamId = atoi((char*)args);
122  if (!teamId)
123  return false;
124 
125  ArenaTeam* arena = sArenaTeamMgr->GetArenaTeamById(teamId);
126 
127  if (!arena)
128  {
130  handler->SetSentErrorMessage(true);
131  return false;
132  }
133 
134  if (arena->IsFighting())
135  {
137  handler->SetSentErrorMessage(true);
138  return false;
139  }
140 
141  std::string name = arena->GetName();
142  arena->Disband();
143  if (handler->GetSession())
144  TC_LOG_DEBUG("bg.arena", "GameMaster: %s [%s] disbanded arena team type: %u [Id: %u].",
145  handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUID().ToString().c_str(), arena->GetType(), teamId);
146  else
147  TC_LOG_DEBUG("bg.arena", "Console: disbanded arena team type: %u [Id: %u].", arena->GetType(), teamId);
148 
149  delete(arena);
150 
151  handler->PSendSysMessage(LANG_ARENA_DISBAND, name.c_str(), teamId);
152  return true;
153  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
void Disband(WorldSession *session)
Definition: ArenaTeam.cpp:336
uint32 GetType() const
Definition: ArenaTeam.h:125
std::string const & GetName() const
Definition: ArenaTeam.h:130
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Player * GetPlayer() const
Definition: WorldSession.h:927
uint32_t uint32
Definition: Define.h:150
Definition: Language.h:849
Definition: ArenaTeam.h:112
Definition: Language.h:841
Definition: Language.h:844
bool IsFighting() const
Definition: ArenaTeam.cpp:781
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
#define sArenaTeamMgr
Definition: ArenaTeamMgr.h:53
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool arena_commandscript::HandleArenaInfoCommand ( ChatHandler handler,
char const args 
)
inlinestatic
296  {
297  if (!*args)
298  return false;
299 
300  uint32 teamId = atoi((char*)args);
301  if (!teamId)
302  return false;
303 
304  ArenaTeam* arena = sArenaTeamMgr->GetArenaTeamById(teamId);
305 
306  if (!arena)
307  {
309  handler->SetSentErrorMessage(true);
310  return false;
311  }
312 
313  handler->PSendSysMessage(LANG_ARENA_INFO_HEADER, arena->GetName().c_str(), arena->GetId(), arena->GetRating(), arena->GetType(), arena->GetType());
314  for (ArenaTeam::MemberList::iterator itr = arena->m_membersBegin(); itr != arena->m_membersEnd(); ++itr)
315  handler->PSendSysMessage(LANG_ARENA_INFO_MEMBERS, itr->Name.c_str(), itr->Guid.ToString().c_str(), itr->PersonalRating, (arena->GetCaptain() == itr->Guid ? " - Captain" : ""));
316 
317  return true;
318  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
Definition: Language.h:853
MemberList::iterator m_membersBegin()
Definition: ArenaTeam.h:143
uint32 GetType() const
Definition: ArenaTeam.h:125
std::string const & GetName() const
Definition: ArenaTeam.h:130
uint32 GetRating() const
Definition: ArenaTeam.h:133
uint32 GetId() const
Definition: ArenaTeam.h:124
uint32_t uint32
Definition: Define.h:150
Definition: ArenaTeam.h:112
Definition: Language.h:841
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
#define sArenaTeamMgr
Definition: ArenaTeamMgr.h:53
Definition: Language.h:852
ObjectGuid GetCaptain() const
Definition: ArenaTeam.h:129
MemberList::iterator m_membersEnd()
Definition: ArenaTeam.h:144

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool arena_commandscript::HandleArenaLookupCommand ( ChatHandler handler,
char const args 
)
inlinestatic
321  {
322  if (!*args)
323  return false;
324 
325  std::string namepart = args;
326  std::wstring wnamepart;
327 
328  if (!Utf8toWStr(namepart, wnamepart))
329  return false;
330 
331  wstrToLower(wnamepart);
332 
333  bool found = false;
334  ArenaTeamMgr::ArenaTeamContainer::const_iterator i = sArenaTeamMgr->GetArenaTeamMapBegin();
335  for (; i != sArenaTeamMgr->GetArenaTeamMapEnd(); ++i)
336  {
337  ArenaTeam* arena = i->second;
338 
339  if (Utf8FitTo(arena->GetName(), wnamepart))
340  {
341  if (handler->GetSession())
342  {
343  handler->PSendSysMessage(LANG_ARENA_LOOKUP, arena->GetName().c_str(), arena->GetId(), arena->GetType(), arena->GetType());
344  found = true;
345  continue;
346  }
347  }
348  }
349 
350  if (!found)
351  handler->PSendSysMessage(LANG_AREAN_ERROR_NAME_NOT_FOUND, namepart.c_str());
352 
353  return true;
354  }
Definition: Language.h:854
uint32 GetType() const
Definition: ArenaTeam.h:125
std::string const & GetName() const
Definition: ArenaTeam.h:130
bool Utf8toWStr(char const *utf8str, size_t csize, wchar_t *wstr, size_t &wsize)
Definition: Util.cpp:281
void wstrToLower(std::wstring &str)
Definition: Util.h:306
Definition: Language.h:845
uint32 GetId() const
Definition: ArenaTeam.h:124
bool Utf8FitTo(const std::string &str, std::wstring const &search)
Definition: Util.cpp:453
Definition: ArenaTeam.h:112
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
#define sArenaTeamMgr
Definition: ArenaTeamMgr.h:53

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool arena_commandscript::HandleArenaRenameCommand ( ChatHandler handler,
char const _args 
)
inlinestatic
156  {
157  if (!*_args)
158  return false;
159 
160  char* args = (char *)_args;
161 
162  char const* oldArenaStr = handler->extractQuotedArg(args);
163  if (!oldArenaStr)
164  {
165  handler->SendSysMessage(LANG_BAD_VALUE);
166  handler->SetSentErrorMessage(true);
167  return false;
168  }
169 
170  char const* newArenaStr = handler->extractQuotedArg(strtok(NULL, ""));
171  if (!newArenaStr)
172  {
173  handler->SendSysMessage(LANG_BAD_VALUE);
174  handler->SetSentErrorMessage(true);
175  return false;
176  }
177 
178  ArenaTeam* arena = sArenaTeamMgr->GetArenaTeamByName(oldArenaStr);
179  if (!arena)
180  {
181  handler->PSendSysMessage(LANG_AREAN_ERROR_NAME_NOT_FOUND, oldArenaStr);
182  handler->SetSentErrorMessage(true);
183  return false;
184  }
185 
186  if (sArenaTeamMgr->GetArenaTeamByName(newArenaStr))
187  {
188  handler->PSendSysMessage(LANG_ARENA_ERROR_NAME_EXISTS, oldArenaStr);
189  handler->SetSentErrorMessage(true);
190  return false;
191  }
192 
193  if (arena->IsFighting())
194  {
196  handler->SetSentErrorMessage(true);
197  return false;
198  }
199 
200  if (!arena->SetName(newArenaStr))
201  {
202  handler->SendSysMessage(LANG_BAD_VALUE);
203  handler->SetSentErrorMessage(true);
204  return false;
205  }
206 
207  handler->PSendSysMessage(LANG_ARENA_RENAME, arena->GetId(), oldArenaStr, newArenaStr);
208  if (handler->GetSession())
209  TC_LOG_DEBUG("bg.arena", "GameMaster: %s [%s] rename arena team \"%s\"[Id: %u] to \"%s\"",
210  handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUID().ToString().c_str(), oldArenaStr, arena->GetId(), newArenaStr);
211  else
212  TC_LOG_DEBUG("bg.arena", "Console: rename arena team \"%s\"[Id: %u] to \"%s\"", oldArenaStr, arena->GetId(), newArenaStr);
213 
214  return true;
215  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
bool SetName(std::string const &name)
Definition: ArenaTeam.cpp:265
char * extractQuotedArg(char *args)
Definition: Chat.cpp:1016
arena_t NULL
Definition: jemalloc_internal.h:624
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Player * GetPlayer() const
Definition: WorldSession.h:927
Definition: Language.h:845
uint32 GetId() const
Definition: ArenaTeam.h:124
Definition: Language.h:139
Definition: ArenaTeam.h:112
Definition: Language.h:850
Definition: Language.h:844
bool IsFighting() const
Definition: ArenaTeam.cpp:781
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
#define sArenaTeamMgr
Definition: ArenaTeamMgr.h:53
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
Definition: Language.h:842

+ 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: