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

Public Member Functions

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

Static Public Member Functions

static bool HandleSendMailCommand (ChatHandler *handler, char const *args)
 
static bool HandleSendItemsCommand (ChatHandler *handler, char const *args)
 
static bool HandleSendMoneyCommand (ChatHandler *handler, char const *args)
 Send money by mail. More...
 
static bool HandleSendMessageCommand (ChatHandler *handler, char const *args)
 Send a message to a player in game. More...
 

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

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

Member Function Documentation

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

Implements CommandScript.

31  {
32  static std::vector<ChatCommand> sendCommandTable =
33  {
38  };
39 
40  static std::vector<ChatCommand> commandTable =
41  {
42  { "send", rbac::RBAC_PERM_COMMAND_SEND, false, NULL, "", sendCommandTable },
43  };
44  return commandTable;
45  }
Definition: RBAC.h:392
static bool HandleSendMailCommand(ChatHandler *handler, char const *args)
Definition: cs_send.cpp:48
Definition: RBAC.h:390
arena_t NULL
Definition: jemalloc_internal.h:624
static bool HandleSendItemsCommand(ChatHandler *handler, char const *args)
Definition: cs_send.cpp:93
static bool HandleSendMessageCommand(ChatHandler *handler, char const *args)
Send a message to a player in game.
Definition: cs_send.cpp:252
static bool HandleSendMoneyCommand(ChatHandler *handler, char const *args)
Send money by mail.
Definition: cs_send.cpp:201

+ Here is the call graph for this function:

static bool send_commandscript::HandleSendItemsCommand ( ChatHandler handler,
char const args 
)
inlinestatic
94  {
95  // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
96  Player* receiver;
97  ObjectGuid receiverGuid;
98  std::string receiverName;
99  if (!handler->extractPlayerTarget((char*)args, &receiver, &receiverGuid, &receiverName))
100  return false;
101 
102  char* tail1 = strtok(NULL, "");
103  if (!tail1)
104  return false;
105 
106  char const* msgSubject = handler->extractQuotedArg(tail1);
107  if (!msgSubject)
108  return false;
109 
110  char* tail2 = strtok(NULL, "");
111  if (!tail2)
112  return false;
113 
114  char const* msgText = handler->extractQuotedArg(tail2);
115  if (!msgText)
116  return false;
117 
118  // msgSubject, msgText isn't NUL after prev. check
119  std::string subject = msgSubject;
120  std::string text = msgText;
121 
122  // extract items
123  typedef std::pair<uint32, uint32> ItemPair;
124  typedef std::list< ItemPair > ItemPairs;
125  ItemPairs items;
126 
127  // get all tail string
128  char* tail = strtok(NULL, "");
129 
130  // get from tail next item str
131  while (char* itemStr = strtok(tail, " "))
132  {
133  // and get new tail
134  tail = strtok(NULL, "");
135 
136  // parse item str
137  char const* itemIdStr = strtok(itemStr, ":");
138  char const* itemCountStr = strtok(NULL, " ");
139 
140  uint32 itemId = atoi(itemIdStr);
141  if (!itemId)
142  return false;
143 
144  ItemTemplate const* item_proto = sObjectMgr->GetItemTemplate(itemId);
145  if (!item_proto)
146  {
148  handler->SetSentErrorMessage(true);
149  return false;
150  }
151 
152  uint32 itemCount = itemCountStr ? atoi(itemCountStr) : 1;
153  if (itemCount < 1 || (item_proto->GetMaxCount() > 0 && itemCount > uint32(item_proto->GetMaxCount())))
154  {
155  handler->PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, itemCount, itemId);
156  handler->SetSentErrorMessage(true);
157  return false;
158  }
159 
160  while (itemCount > item_proto->GetMaxStackSize())
161  {
162  items.push_back(ItemPair(itemId, item_proto->GetMaxStackSize()));
163  itemCount -= item_proto->GetMaxStackSize();
164  }
165 
166  items.push_back(ItemPair(itemId, itemCount));
167 
168  if (items.size() > MAX_MAIL_ITEMS)
169  {
171  handler->SetSentErrorMessage(true);
172  return false;
173  }
174  }
175 
176  // from console show not existed sender
177  MailSender sender(MAIL_NORMAL, handler->GetSession() ? handler->GetSession()->GetPlayer()->GetGUID().GetCounter() : UI64LIT(0), MAIL_STATIONERY_GM);
178 
179  // fill mail
180  MailDraft draft(subject, text);
181 
183 
184  for (ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
185  {
186  if (Item* item = Item::CreateItem(itr->first, itr->second, handler->GetSession() ? handler->GetSession()->GetPlayer() : 0))
187  {
188  item->SaveToDB(trans); // save for prevent lost at next mail load, if send fail then item will deleted
189  draft.AddItem(item);
190  }
191  }
192 
193  draft.SendMailTo(trans, MailReceiver(receiver, receiverGuid.GetCounter()), sender);
195 
196  std::string nameLink = handler->playerLink(receiverName);
197  handler->PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
198  return true;
199  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
Definition: Language.h:86
SQLTransaction BeginTransaction()
Begins an automanaged transaction pointer that will automatically rollback if not commited...
Definition: DatabaseWorkerPool.h:221
Definition: Mail.h:60
#define UI64LIT(N)
Definition: Define.h:138
char * extractQuotedArg(char *args)
Definition: Chat.cpp:1016
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Mail.h:38
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
#define sObjectMgr
Definition: ObjectMgr.h:1567
void CommitTransaction(SQLTransaction transaction)
Definition: DatabaseWorkerPool.cpp:179
Definition: Mail.h:118
Definition: Item.h:259
uint32_t uint32
Definition: Define.h:150
static Item * CreateItem(uint32 itemEntry, uint32 count, Player const *player=NULL)
Definition: Item.cpp:1068
uint32 GetMaxStackSize() const
Definition: ItemTemplate.h:745
Definition: ItemTemplate.h:647
Definition: Language.h:437
WorldSession * GetSession()
Definition: Chat.h:59
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
uint32 GetMaxCount() const
Definition: ItemTemplate.h:674
Definition: ObjectGuid.h:189
uint32_t uint32
Definition: g3dmath.h:168
Definition: Language.h:201
Definition: Language.h:85
#define MAX_MAIL_ITEMS
Definition: Mail.h:34
Definition: Mail.h:104
std::string playerLink(std::string const &name) const
Definition: Chat.h:132
Definition: Mail.h:83
LowType GetCounter() const
Definition: ObjectGuid.h:221
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool send_commandscript::HandleSendMailCommand ( ChatHandler handler,
char const args 
)
inlinestatic
Todo:
Fix poor design
49  {
50  // format: name "subject text" "mail text"
51  Player* target;
52  ObjectGuid targetGuid;
53  std::string targetName;
54  if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
55  return false;
56 
57  char* tail1 = strtok(NULL, "");
58  if (!tail1)
59  return false;
60 
61  char const* msgSubject = handler->extractQuotedArg(tail1);
62  if (!msgSubject)
63  return false;
64 
65  char* tail2 = strtok(NULL, "");
66  if (!tail2)
67  return false;
68 
69  char const* msgText = handler->extractQuotedArg(tail2);
70  if (!msgText)
71  return false;
72 
73  // msgSubject, msgText isn't NUL after prev. check
74  std::string subject = msgSubject;
75  std::string text = msgText;
76 
77  // from console show not existed sender
78  MailSender sender(MAIL_NORMAL, handler->GetSession() ? handler->GetSession()->GetPlayer()->GetGUID().GetCounter() : UI64LIT(0), MAIL_STATIONERY_GM);
79 
82  MailDraft(subject, text)
83  .SendMailTo(trans, MailReceiver(target, targetGuid.GetCounter()), sender);
84 
86 
87  std::string nameLink = handler->playerLink(targetName);
88  handler->PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
89  return true;
90  }
SQLTransaction BeginTransaction()
Begins an automanaged transaction pointer that will automatically rollback if not commited...
Definition: DatabaseWorkerPool.h:221
Definition: Mail.h:60
#define UI64LIT(N)
Definition: Define.h:138
char * extractQuotedArg(char *args)
Definition: Chat.cpp:1016
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Mail.h:38
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
void SendMailTo(SQLTransaction &trans, MailReceiver const &receiver, MailSender const &sender, MailCheckMask checked=MAIL_CHECK_MASK_NONE, uint32 deliver_delay=0)
Definition: Mail.cpp:173
void CommitTransaction(SQLTransaction transaction)
Definition: DatabaseWorkerPool.cpp:179
Definition: Mail.h:118
WorldSession * GetSession()
Definition: Chat.h:59
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: ObjectGuid.h:189
Definition: Language.h:201
Definition: Mail.h:104
std::string playerLink(std::string const &name) const
Definition: Chat.h:132
Definition: Mail.h:83
LowType GetCounter() const
Definition: ObjectGuid.h:221
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool send_commandscript::HandleSendMessageCommand ( ChatHandler handler,
char const args 
)
inlinestatic

Send a message to a player in game.

  • Find the player
  • Check that he is not logging out.
  • Send the message
253  {
255  Player* player;
256  if (!handler->extractPlayerTarget((char*)args, &player))
257  return false;
258 
259  char* msgStr = strtok(NULL, "");
260  if (!msgStr)
261  return false;
262 
264  if (player->GetSession()->isLogingOut())
265  {
267  handler->SetSentErrorMessage(true);
268  return false;
269  }
270 
272  player->GetSession()->SendNotification("%s", msgStr);
273  player->GetSession()->SendNotification("|cffff0000[Message from administrator]:|r");
274 
275  // Confirmation message
276  std::string nameLink = handler->GetNameLink(player);
277  handler->PSendSysMessage(LANG_SENDMESSAGE, nameLink.c_str(), msgStr);
278 
279  return true;
280  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
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
virtual std::string GetNameLink() const
Definition: Chat.h:101
Definition: Language.h:905
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
Definition: Language.h:509

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool send_commandscript::HandleSendMoneyCommand ( ChatHandler handler,
char const args 
)
inlinestatic

Send money by mail.

format: name "subject text" "mail text" money

202  {
204 
205  Player* receiver;
206  ObjectGuid receiverGuid;
207  std::string receiverName;
208  if (!handler->extractPlayerTarget((char*)args, &receiver, &receiverGuid, &receiverName))
209  return false;
210 
211  char* tail1 = strtok(NULL, "");
212  if (!tail1)
213  return false;
214 
215  char* msgSubject = handler->extractQuotedArg(tail1);
216  if (!msgSubject)
217  return false;
218 
219  char* tail2 = strtok(NULL, "");
220  if (!tail2)
221  return false;
222 
223  char* msgText = handler->extractQuotedArg(tail2);
224  if (!msgText)
225  return false;
226 
227  char* moneyStr = strtok(NULL, "");
228  int32 money = moneyStr ? atoi(moneyStr) : 0;
229  if (money <= 0)
230  return false;
231 
232  // msgSubject, msgText isn't NUL after prev. check
233  std::string subject = msgSubject;
234  std::string text = msgText;
235 
236  // from console show not existed sender
237  MailSender sender(MAIL_NORMAL, handler->GetSession() ? handler->GetSession()->GetPlayer()->GetGUID().GetCounter() : UI64LIT(0), MAIL_STATIONERY_GM);
238 
240 
241  MailDraft(subject, text)
242  .AddMoney(money)
243  .SendMailTo(trans, MailReceiver(receiver, receiverGuid.GetCounter()), sender);
244 
246 
247  std::string nameLink = handler->playerLink(receiverName);
248  handler->PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
249  return true;
250  }
SQLTransaction BeginTransaction()
Begins an automanaged transaction pointer that will automatically rollback if not commited...
Definition: DatabaseWorkerPool.h:221
Definition: Mail.h:60
#define UI64LIT(N)
Definition: Define.h:138
char * extractQuotedArg(char *args)
Definition: Chat.cpp:1016
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Mail.h:38
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
void SendMailTo(SQLTransaction &trans, MailReceiver const &receiver, MailSender const &sender, MailCheckMask checked=MAIL_CHECK_MASK_NONE, uint32 deliver_delay=0)
Definition: Mail.cpp:173
void CommitTransaction(SQLTransaction transaction)
Definition: DatabaseWorkerPool.cpp:179
Definition: Mail.h:118
int32_t int32
Definition: Define.h:146
WorldSession * GetSession()
Definition: Chat.h:59
MailDraft & AddMoney(uint64 money)
Definition: Mail.h:137
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: ObjectGuid.h:189
Definition: Language.h:201
Definition: Mail.h:104
std::string playerLink(std::string const &name) const
Definition: Chat.h:132
Definition: Mail.h:83
LowType GetCounter() const
Definition: ObjectGuid.h:221
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58

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