AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
send_commandscript Class Reference
Inheritance diagram for send_commandscript:
CommandScript ScriptObject

Public Member Functions

 send_commandscript ()
 
ChatCommandTable GetCommands () const override
 
virtual std::vector< Acore::ChatCommands::ChatCommandBuilderGetCommands () const =0
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
const std::string & GetName () const
 
uint16 GetTotalAvailableHooks ()
 

Static Public Member Functions

static bool HandleSendItemsCommand (ChatHandler *handler, Optional< PlayerIdentifier > target, QuotedString subject, QuotedString text, Tail items)
 
static bool HandleSendMailCommand (ChatHandler *handler, Optional< PlayerIdentifier > target, QuotedString subject, QuotedString text)
 
static bool HandleSendMessageCommand (ChatHandler *handler, Optional< PlayerIdentifier > target, Tail message)
 
static bool HandleSendMoneyCommand (ChatHandler *handler, Optional< PlayerIdentifier > target, QuotedString subject, QuotedString text, uint32 money)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name, uint16 totalAvailableHooks=0)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ send_commandscript()

send_commandscript::send_commandscript ( )
inline
33: CommandScript("send_commandscript") { }
Definition: CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable send_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

36 {
37 static ChatCommandTable sendCommandTable =
38 {
39 { "items", HandleSendItemsCommand, SEC_GAMEMASTER, Console::Yes },
40 { "mail", HandleSendMailCommand, SEC_GAMEMASTER, Console::Yes },
41 { "message", HandleSendMessageCommand, SEC_ADMINISTRATOR, Console::Yes },
42 { "money", HandleSendMoneyCommand, SEC_GAMEMASTER, Console::Yes }
43 };
44
45 static ChatCommandTable commandTable =
46 {
47 { "send", sendCommandTable }
48 };
49
50 return commandTable;
51 }
@ SEC_ADMINISTRATOR
Definition: Common.h:60
@ SEC_GAMEMASTER
Definition: Common.h:59
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:46
static bool HandleSendMoneyCommand(ChatHandler *handler, Optional< PlayerIdentifier > target, QuotedString subject, QuotedString text, uint32 money)
Definition: cs_send.cpp:191
static bool HandleSendMailCommand(ChatHandler *handler, Optional< PlayerIdentifier > target, QuotedString subject, QuotedString text)
Definition: cs_send.cpp:140
static bool HandleSendItemsCommand(ChatHandler *handler, Optional< PlayerIdentifier > target, QuotedString subject, QuotedString text, Tail items)
Definition: cs_send.cpp:53
static bool HandleSendMessageCommand(ChatHandler *handler, Optional< PlayerIdentifier > target, Tail message)
Definition: cs_send.cpp:165

References HandleSendItemsCommand(), HandleSendMailCommand(), HandleSendMessageCommand(), HandleSendMoneyCommand(), SEC_ADMINISTRATOR, and SEC_GAMEMASTER.

◆ HandleSendItemsCommand()

static bool send_commandscript::HandleSendItemsCommand ( ChatHandler handler,
Optional< PlayerIdentifier target,
QuotedString  subject,
QuotedString  text,
Tail  items 
)
inlinestatic
54 {
55 if (!target)
56 {
57 target = PlayerIdentifier::FromTargetOrSelf(handler);
58 }
59
60 if (!target)
61 {
62 return false;
63 }
64
65 // extract items
66 std::vector<std::pair<uint32, uint32>> itemList;
67
68 for (auto const& itemString : Acore::Tokenize(items, ' ', true))
69 {
70 auto itemTokens = Acore::Tokenize(itemString, ':', false);
71
72 uint32 itemCount;
73 switch (itemTokens.size())
74 {
75 case 1:
76 itemCount = 1; // Default to sending 1 item
77 break;
78 case 2:
79 itemCount = *Acore::StringTo<uint32>(itemTokens.at(1));
80 break;
81 default:
82 handler->SendSysMessage(Acore::StringFormat("> Incorrect item list format for '{}'", itemString));
83 continue;
84 }
85
86 uint32 itemID = *Acore::StringTo<uint32>(itemTokens.at(0));
87
88 ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(itemID);
89 if (!itemTemplate)
90 {
92 return false;
93 }
94
95 if (!itemCount || (itemTemplate->MaxCount > 0 && itemCount > uint32(itemTemplate->MaxCount)))
96 {
97 handler->SendErrorMessage(LANG_COMMAND_INVALID_ITEM_COUNT, itemCount, itemID);
98 return false;
99 }
100
101 while (itemCount > itemTemplate->GetMaxStackSize())
102 {
103 itemList.emplace_back(itemID, itemTemplate->GetMaxStackSize());
104 itemCount -= itemTemplate->GetMaxStackSize();
105 }
106
107 itemList.emplace_back(itemID, itemCount);
108
109 if (itemList.size() > MAX_MAIL_ITEMS)
110 {
112 return false;
113 }
114 }
115
116 // If the message is sent from console, set it as sent by the target itself, like the other Customer Support mails.
117 ObjectGuid::LowType senderGuid = handler->GetSession() ? handler->GetSession()->GetPlayer()->GetGUID().GetCounter() : target->GetGUID().GetCounter();
118
119 // fill mail
120 MailDraft draft(subject, text);
121 MailSender sender(MAIL_NORMAL, senderGuid, MAIL_STATIONERY_GM);
122 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
123
124 for (auto const& [itemID, itemCount] : itemList)
125 {
126 if (Item* item = Item::CreateItem(itemID, itemCount, handler->GetSession() ? handler->GetSession()->GetPlayer() : 0))
127 {
128 item->SaveToDB(trans); // save for prevent lost at next mail load, if send fail then item will deleted
129 draft.AddItem(item);
130 }
131 }
132
133 draft.SendMailTo(trans, MailReceiver(target->GetConnectedPlayer(), target->GetGUID().GetCounter()), sender);
134 CharacterDatabase.CommitTransaction(trans);
135
136 handler->PSendSysMessage(LANG_MAIL_SENT, handler->playerLink(target->GetName()));
137 return true;
138 }
std::uint32_t uint32
Definition: Define.h:107
#define sObjectMgr
Definition: ObjectMgr.h:1635
@ LANG_COMMAND_INVALID_ITEM_COUNT
Definition: Language.h:84
@ LANG_COMMAND_MAIL_ITEMS_LIMIT
Definition: Language.h:85
@ LANG_MAIL_SENT
Definition: Language.h:209
@ LANG_COMMAND_ITEMIDINVALID
Definition: Language.h:467
#define MAX_MAIL_ITEMS
Definition: Mail.h:33
@ MAIL_STATIONERY_GM
Definition: Mail.h:59
@ MAIL_NORMAL
Definition: Mail.h:37
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
Definition: DatabaseEnvFwd.h:69
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
std::vector< std::string_view > Tokenize(std::string_view str, char sep, bool keepEmpty)
Definition: Tokenize.cpp:20
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default AC string format function.
Definition: StringFormat.h:34
std::string playerLink(std::string const &name) const
Definition: Chat.h:231
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:210
WorldSession * GetSession()
Definition: Chat.h:242
void SendErrorMessage(uint32 entry)
Definition: Chat.cpp:215
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:159
static Optional< PlayerIdentifier > FromTargetOrSelf(ChatHandler *handler)
Definition: ChatCommandTags.h:184
Definition: Item.h:220
static Item * CreateItem(uint32 item, uint32 count, Player const *player=nullptr, bool clone=false, uint32 randomPropertyId=0)
Definition: Item.cpp:1087
Definition: ItemTemplate.h:619
int32 MaxCount
Definition: ItemTemplate.h:644
uint32 GetMaxStackSize() const
Definition: ItemTemplate.h:729
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:112
LowType GetCounter() const
Definition: ObjectGuid.h:145
uint32 LowType
Definition: ObjectGuid.h:122
Definition: Mail.h:83
Definition: Mail.h:105
Definition: Mail.h:119
Player * GetPlayer() const
Definition: WorldSession.h:362

References MailDraft::AddItem(), CharacterDatabase, Item::CreateItem(), Acore::ChatCommands::PlayerIdentifier::FromTargetOrSelf(), ObjectGuid::GetCounter(), Object::GetGUID(), ItemTemplate::GetMaxStackSize(), WorldSession::GetPlayer(), ChatHandler::GetSession(), LANG_COMMAND_INVALID_ITEM_COUNT, LANG_COMMAND_ITEMIDINVALID, LANG_COMMAND_MAIL_ITEMS_LIMIT, LANG_MAIL_SENT, MAIL_NORMAL, MAIL_STATIONERY_GM, MAX_MAIL_ITEMS, ItemTemplate::MaxCount, ChatHandler::playerLink(), ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), MailDraft::SendMailTo(), ChatHandler::SendSysMessage(), sObjectMgr, Acore::StringFormat(), and Acore::Tokenize().

Referenced by GetCommands().

◆ HandleSendMailCommand()

static bool send_commandscript::HandleSendMailCommand ( ChatHandler handler,
Optional< PlayerIdentifier target,
QuotedString  subject,
QuotedString  text 
)
inlinestatic
141 {
142 if (!target)
143 {
144 target = PlayerIdentifier::FromTargetOrSelf(handler);
145 }
146
147 if (!target)
148 {
149 return false;
150 }
151
152 ObjectGuid::LowType senderGuid = handler->GetSession() ? handler->GetSession()->GetPlayer()->GetGUID().GetCounter() : target->GetGUID().GetCounter();
153
154 // If the message is sent from console, set it as sent by the target itself, like the other Customer Support mails.
155 MailSender sender(MAIL_NORMAL, senderGuid, MAIL_STATIONERY_GM);
156 MailDraft draft(subject, text);
157 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
158 draft.SendMailTo(trans, MailReceiver(target->GetConnectedPlayer(), target->GetGUID().GetCounter()), sender);
159 CharacterDatabase.CommitTransaction(trans);
160
161 handler->PSendSysMessage(LANG_MAIL_SENT, handler->playerLink(target->GetName()));
162 return true;
163 }

References CharacterDatabase, Acore::ChatCommands::PlayerIdentifier::FromTargetOrSelf(), ObjectGuid::GetCounter(), Object::GetGUID(), WorldSession::GetPlayer(), ChatHandler::GetSession(), LANG_MAIL_SENT, MAIL_NORMAL, MAIL_STATIONERY_GM, ChatHandler::playerLink(), ChatHandler::PSendSysMessage(), and MailDraft::SendMailTo().

Referenced by GetCommands().

◆ HandleSendMessageCommand()

static bool send_commandscript::HandleSendMessageCommand ( ChatHandler handler,
Optional< PlayerIdentifier target,
Tail  message 
)
inlinestatic
  • Send the message
166 {
167 if (!target)
168 {
169 target = PlayerIdentifier::FromTargetOrSelf(handler);
170 }
171
172 if (!target || !target->IsConnected())
173 {
174 return false;
175 }
176
177 Player* player = target->GetConnectedPlayer();
178 std::string msg = std::string{ message };
179
181 // Use SendAreaTriggerMessage for fastest delivery.
182 player->GetSession()->SendAreaTriggerMessage("%s", msg.c_str());
183 player->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
184
185 // Confirmation message
186 handler->PSendSysMessage(LANG_SENDMESSAGE, handler->playerLink(target->GetName()), msg);
187
188 return true;
189 }
@ LANG_SENDMESSAGE
Definition: Language.h:891
Definition: Player.h:1081
WorldSession * GetSession() const
Definition: Player.h:1998
void SendAreaTriggerMessage(const char *Text,...) ATTR_PRINTF(2
Definition: MiscHandler.cpp:692

References Acore::ChatCommands::PlayerIdentifier::FromTargetOrSelf(), Player::GetSession(), LANG_SENDMESSAGE, ChatHandler::playerLink(), ChatHandler::PSendSysMessage(), and WorldSession::SendAreaTriggerMessage().

Referenced by GetCommands().

◆ HandleSendMoneyCommand()

static bool send_commandscript::HandleSendMoneyCommand ( ChatHandler handler,
Optional< PlayerIdentifier target,
QuotedString  subject,
QuotedString  text,
uint32  money 
)
inlinestatic
192 {
193 if (!target)
194 {
195 target = PlayerIdentifier::FromTargetOrSelf(handler);
196 }
197
198 if (!target)
199 {
200 return false;
201 }
202
203 // from console show not existed sender
204 MailSender sender(MAIL_NORMAL, handler->GetSession() ? handler->GetSession()->GetPlayer()->GetGUID().GetCounter() : 0, MAIL_STATIONERY_GM);
205
206 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
207
208 MailDraft(subject, text)
209 .AddMoney(money)
210 .SendMailTo(trans, MailReceiver(target->GetConnectedPlayer(), target->GetGUID().GetCounter()), sender);
211
212 CharacterDatabase.CommitTransaction(trans);
213
214 handler->PSendSysMessage(LANG_MAIL_SENT, handler->playerLink(target->GetName()));
215 return true;
216 }
MailDraft & AddMoney(uint32 money)
Definition: Mail.h:137
void SendMailTo(CharacterDatabaseTransaction trans, MailReceiver const &receiver, MailSender const &sender, MailCheckMask checked=MAIL_CHECK_MASK_NONE, uint32 deliver_delay=0, uint32 custom_expiration=0, bool deleteMailItemsFromDB=false, bool sendMail=true)
Definition: Mail.cpp:185

References MailDraft::AddMoney(), CharacterDatabase, Acore::ChatCommands::PlayerIdentifier::FromTargetOrSelf(), ObjectGuid::GetCounter(), Object::GetGUID(), WorldSession::GetPlayer(), ChatHandler::GetSession(), LANG_MAIL_SENT, MAIL_NORMAL, MAIL_STATIONERY_GM, ChatHandler::playerLink(), ChatHandler::PSendSysMessage(), and MailDraft::SendMailTo().

Referenced by GetCommands().