Core/RBAC: Move send commands to RBAC (using individual permissions)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* cs_pet.cpp */
|
||||
|
||||
SET @id = 472;
|
||||
SET @id = 479;
|
||||
|
||||
-- Add new permissions
|
||||
DELETE FROM `rbac_permissions` WHERE `id` BETWEEN @id AND @id+3;
|
||||
@@ -13,7 +13,7 @@ INSERT INTO `rbac_permissions` (`id`, `name`) VALUES
|
||||
-- Add permissions to "corresponding Commands Role"
|
||||
DELETE FROM `rbac_role_permissions` WHERE `permissionId` BETWEEN @id AND @id+3;
|
||||
INSERT INTO `rbac_role_permissions` (`roleId`, `permissionId`) VALUES
|
||||
(2, @id+0),
|
||||
(2, @id+1),
|
||||
(2, @id+2),
|
||||
(2, @id+3);
|
||||
(3, @id+0),
|
||||
(3, @id+1),
|
||||
(3, @id+2),
|
||||
(3, @id+3);
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/* cs_send.cpp */
|
||||
|
||||
SET @id = 483;
|
||||
|
||||
-- Add new permissions
|
||||
DELETE FROM `rbac_permissions` WHERE `id` BETWEEN @id AND @id+4;
|
||||
INSERT INTO `rbac_permissions` (`id`, `name`) VALUES
|
||||
(@id+0 , 'send'),
|
||||
(@id+1 , 'send items'),
|
||||
(@id+2 , 'send mail'),
|
||||
(@id+3 , 'send message'),
|
||||
(@id+4 , 'send money');
|
||||
|
||||
-- Add permissions to "corresponding Commands Role"
|
||||
DELETE FROM `rbac_role_permissions` WHERE `permissionId` BETWEEN @id AND @id+4;
|
||||
INSERT INTO `rbac_role_permissions` (`roleId`, `permissionId`) VALUES
|
||||
(2, @id+0),
|
||||
(2, @id+1),
|
||||
(3, @id+2),
|
||||
(3, @id+3),
|
||||
(3, @id+4);
|
||||
@@ -0,0 +1,10 @@
|
||||
/* cs_send.cpp */
|
||||
|
||||
SET @id = 483;
|
||||
|
||||
-- Update command table with new RBAC permissions
|
||||
UPDATE `command` SET `permission` = @id+0 WHERE `name` = 'send';
|
||||
UPDATE `command` SET `permission` = @id+1 WHERE `name` = 'send items';
|
||||
UPDATE `command` SET `permission` = @id+2 WHERE `name` = 'send mail';
|
||||
UPDATE `command` SET `permission` = @id+3 WHERE `name` = 'send message';
|
||||
UPDATE `command` SET `permission` = @id+4 WHERE `name` = 'send money';
|
||||
@@ -382,6 +382,11 @@ enum RBACPermissions
|
||||
RBAC_PERM_COMMAND_PET_CREATE = 480,
|
||||
RBAC_PERM_COMMAND_PET_LEARN = 481,
|
||||
RBAC_PERM_COMMAND_PET_UNLEARN = 482,
|
||||
RBAC_PERM_COMMAND_SEND = 483,
|
||||
RBAC_PERM_COMMAND_SEND_ITEMS = 484,
|
||||
RBAC_PERM_COMMAND_SEND_MAIL = 485,
|
||||
RBAC_PERM_COMMAND_SEND_MESSAGE = 486,
|
||||
RBAC_PERM_COMMAND_SEND_MONEY = 487,
|
||||
|
||||
// custom permissions 1000+
|
||||
RBAC_PERM_MAX
|
||||
|
||||
@@ -77,6 +77,7 @@ void AddSC_quest_commandscript();
|
||||
void AddSC_rbac_commandscript();
|
||||
void AddSC_reload_commandscript();
|
||||
void AddSC_reset_commandscript();
|
||||
void AddSC_send_commandscript();
|
||||
void AddSC_server_commandscript();
|
||||
void AddSC_tele_commandscript();
|
||||
void AddSC_ticket_commandscript();
|
||||
@@ -760,6 +761,7 @@ void AddCommandScripts()
|
||||
AddSC_rbac_commandscript();
|
||||
AddSC_reload_commandscript();
|
||||
AddSC_reset_commandscript();
|
||||
AddSC_send_commandscript();
|
||||
AddSC_server_commandscript();
|
||||
AddSC_tele_commandscript();
|
||||
AddSC_ticket_commandscript();
|
||||
|
||||
@@ -44,14 +44,6 @@ public:
|
||||
|
||||
ChatCommand* GetCommands() const OVERRIDE
|
||||
{
|
||||
static ChatCommand sendCommandTable[] =
|
||||
{
|
||||
{ "items", RBAC_PERM_ADMINISTRATOR_COMMANDS, true, &HandleSendItemsCommand, "", NULL },
|
||||
{ "mail", RBAC_PERM_MODERATOR_COMMANDS, true, &HandleSendMailCommand, "", NULL },
|
||||
{ "message", RBAC_PERM_ADMINISTRATOR_COMMANDS, true, &HandleSendMessageCommand, "", NULL },
|
||||
{ "money", RBAC_PERM_ADMINISTRATOR_COMMANDS, true, &HandleSendMoneyCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
static ChatCommand commandTable[] =
|
||||
{
|
||||
{ "dev", RBAC_PERM_ADMINISTRATOR_COMMANDS, false, &HandleDevCommand, "", NULL },
|
||||
@@ -86,7 +78,6 @@ public:
|
||||
{ "setskill", RBAC_PERM_ADMINISTRATOR_COMMANDS, false, &HandleSetSkillCommand, "", NULL },
|
||||
{ "pinfo", RBAC_PERM_GAMEMASTER_COMMANDS, true, &HandlePInfoCommand, "", NULL },
|
||||
{ "respawn", RBAC_PERM_ADMINISTRATOR_COMMANDS, false, &HandleRespawnCommand, "", NULL },
|
||||
{ "send", RBAC_PERM_MODERATOR_COMMANDS, true, NULL, "", sendCommandTable },
|
||||
{ "mute", RBAC_PERM_MODERATOR_COMMANDS, true, &HandleMuteCommand, "", NULL },
|
||||
{ "unmute", RBAC_PERM_MODERATOR_COMMANDS, true, &HandleUnmuteCommand, "", NULL },
|
||||
{ "movegens", RBAC_PERM_ADMINISTRATOR_COMMANDS, false, &HandleMovegensCommand, "", NULL },
|
||||
@@ -2248,241 +2239,6 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
// Send mail by command
|
||||
static bool HandleSendMailCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
// format: name "subject text" "mail text"
|
||||
Player* target;
|
||||
uint64 targetGuid;
|
||||
std::string targetName;
|
||||
if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
|
||||
return false;
|
||||
|
||||
char* tail1 = strtok(NULL, "");
|
||||
if (!tail1)
|
||||
return false;
|
||||
|
||||
char const* msgSubject = handler->extractQuotedArg(tail1);
|
||||
if (!msgSubject)
|
||||
return false;
|
||||
|
||||
char* tail2 = strtok(NULL, "");
|
||||
if (!tail2)
|
||||
return false;
|
||||
|
||||
char const* msgText = handler->extractQuotedArg(tail2);
|
||||
if (!msgText)
|
||||
return false;
|
||||
|
||||
// msgSubject, msgText isn't NUL after prev. check
|
||||
std::string subject = msgSubject;
|
||||
std::string text = msgText;
|
||||
|
||||
// from console show not existed sender
|
||||
MailSender sender(MAIL_NORMAL, handler->GetSession() ? handler->GetSession()->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM);
|
||||
|
||||
/// @todo Fix poor design
|
||||
SQLTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
MailDraft(subject, text)
|
||||
.SendMailTo(trans, MailReceiver(target, GUID_LOPART(targetGuid)), sender);
|
||||
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
|
||||
std::string nameLink = handler->playerLink(targetName);
|
||||
handler->PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
|
||||
return true;
|
||||
}
|
||||
// Send items by mail
|
||||
static bool HandleSendItemsCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
// format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
|
||||
Player* receiver;
|
||||
uint64 receiverGuid;
|
||||
std::string receiverName;
|
||||
if (!handler->extractPlayerTarget((char*)args, &receiver, &receiverGuid, &receiverName))
|
||||
return false;
|
||||
|
||||
char* tail1 = strtok(NULL, "");
|
||||
if (!tail1)
|
||||
return false;
|
||||
|
||||
char const* msgSubject = handler->extractQuotedArg(tail1);
|
||||
if (!msgSubject)
|
||||
return false;
|
||||
|
||||
char* tail2 = strtok(NULL, "");
|
||||
if (!tail2)
|
||||
return false;
|
||||
|
||||
char const* msgText = handler->extractQuotedArg(tail2);
|
||||
if (!msgText)
|
||||
return false;
|
||||
|
||||
// msgSubject, msgText isn't NUL after prev. check
|
||||
std::string subject = msgSubject;
|
||||
std::string text = msgText;
|
||||
|
||||
// extract items
|
||||
typedef std::pair<uint32, uint32> ItemPair;
|
||||
typedef std::list< ItemPair > ItemPairs;
|
||||
ItemPairs items;
|
||||
|
||||
// get all tail string
|
||||
char* tail = strtok(NULL, "");
|
||||
|
||||
// get from tail next item str
|
||||
while (char* itemStr = strtok(tail, " "))
|
||||
{
|
||||
// and get new tail
|
||||
tail = strtok(NULL, "");
|
||||
|
||||
// parse item str
|
||||
char const* itemIdStr = strtok(itemStr, ":");
|
||||
char const* itemCountStr = strtok(NULL, " ");
|
||||
|
||||
uint32 itemId = atoi(itemIdStr);
|
||||
if (!itemId)
|
||||
return false;
|
||||
|
||||
ItemTemplate const* item_proto = sObjectMgr->GetItemTemplate(itemId);
|
||||
if (!item_proto)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 itemCount = itemCountStr ? atoi(itemCountStr) : 1;
|
||||
if (itemCount < 1 || (item_proto->MaxCount > 0 && itemCount > uint32(item_proto->MaxCount)))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, itemCount, itemId);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
while (itemCount > item_proto->GetMaxStackSize())
|
||||
{
|
||||
items.push_back(ItemPair(itemId, item_proto->GetMaxStackSize()));
|
||||
itemCount -= item_proto->GetMaxStackSize();
|
||||
}
|
||||
|
||||
items.push_back(ItemPair(itemId, itemCount));
|
||||
|
||||
if (items.size() > MAX_MAIL_ITEMS)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// from console show not existed sender
|
||||
MailSender sender(MAIL_NORMAL, handler->GetSession() ? handler->GetSession()->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM);
|
||||
|
||||
// fill mail
|
||||
MailDraft draft(subject, text);
|
||||
|
||||
SQLTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
|
||||
for (ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
|
||||
{
|
||||
if (Item* item = Item::CreateItem(itr->first, itr->second, handler->GetSession() ? handler->GetSession()->GetPlayer() : 0))
|
||||
{
|
||||
item->SaveToDB(trans); // save for prevent lost at next mail load, if send fail then item will deleted
|
||||
draft.AddItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
draft.SendMailTo(trans, MailReceiver(receiver, GUID_LOPART(receiverGuid)), sender);
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
|
||||
std::string nameLink = handler->playerLink(receiverName);
|
||||
handler->PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
|
||||
return true;
|
||||
}
|
||||
/// Send money by mail
|
||||
static bool HandleSendMoneyCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
/// format: name "subject text" "mail text" money
|
||||
|
||||
Player* receiver;
|
||||
uint64 receiverGuid;
|
||||
std::string receiverName;
|
||||
if (!handler->extractPlayerTarget((char*)args, &receiver, &receiverGuid, &receiverName))
|
||||
return false;
|
||||
|
||||
char* tail1 = strtok(NULL, "");
|
||||
if (!tail1)
|
||||
return false;
|
||||
|
||||
char* msgSubject = handler->extractQuotedArg(tail1);
|
||||
if (!msgSubject)
|
||||
return false;
|
||||
|
||||
char* tail2 = strtok(NULL, "");
|
||||
if (!tail2)
|
||||
return false;
|
||||
|
||||
char* msgText = handler->extractQuotedArg(tail2);
|
||||
if (!msgText)
|
||||
return false;
|
||||
|
||||
char* moneyStr = strtok(NULL, "");
|
||||
int32 money = moneyStr ? atoi(moneyStr) : 0;
|
||||
if (money <= 0)
|
||||
return false;
|
||||
|
||||
// msgSubject, msgText isn't NUL after prev. check
|
||||
std::string subject = msgSubject;
|
||||
std::string text = msgText;
|
||||
|
||||
// from console show not existed sender
|
||||
MailSender sender(MAIL_NORMAL, handler->GetSession() ? handler->GetSession()->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM);
|
||||
|
||||
SQLTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
|
||||
MailDraft(subject, text)
|
||||
.AddMoney(money)
|
||||
.SendMailTo(trans, MailReceiver(receiver, GUID_LOPART(receiverGuid)), sender);
|
||||
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
|
||||
std::string nameLink = handler->playerLink(receiverName);
|
||||
handler->PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
|
||||
return true;
|
||||
}
|
||||
/// Send a message to a player in game
|
||||
static bool HandleSendMessageCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
/// - Find the player
|
||||
Player* player;
|
||||
if (!handler->extractPlayerTarget((char*)args, &player))
|
||||
return false;
|
||||
|
||||
char* msgStr = strtok(NULL, "");
|
||||
if (!msgStr)
|
||||
return false;
|
||||
|
||||
///- Check that he is not logging out.
|
||||
if (player->GetSession()->isLogingOut())
|
||||
{
|
||||
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// - Send the message
|
||||
// Use SendAreaTriggerMessage for fastest delivery.
|
||||
player->GetSession()->SendAreaTriggerMessage("%s", msgStr);
|
||||
player->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
|
||||
|
||||
// Confirmation message
|
||||
std::string nameLink = handler->GetNameLink(player);
|
||||
handler->PSendSysMessage(LANG_SENDMESSAGE, nameLink.c_str(), msgStr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleFreezeCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
std::string name;
|
||||
|
||||
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2013 TrinityCore <http://www.trinitycore.org/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Chat.h"
|
||||
#include "Language.h"
|
||||
#include "Pet.h"
|
||||
#include "Player.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "ScriptMgr.h"
|
||||
|
||||
class send_commandscript : public CommandScript
|
||||
{
|
||||
public:
|
||||
send_commandscript() : CommandScript("send_commandscript") { }
|
||||
|
||||
ChatCommand* GetCommands() const OVERRIDE
|
||||
{
|
||||
static ChatCommand sendCommandTable[] =
|
||||
{
|
||||
{ "items", RBAC_PERM_COMMAND_SEND_ITEMS, true, &HandleSendItemsCommand, "", NULL },
|
||||
{ "mail", RBAC_PERM_COMMAND_SEND_MAIL, true, &HandleSendMailCommand, "", NULL },
|
||||
{ "message", RBAC_PERM_COMMAND_SEND_MESSAGE, true, &HandleSendMessageCommand, "", NULL },
|
||||
{ "money", RBAC_PERM_COMMAND_SEND_MONEY, true, &HandleSendMoneyCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
|
||||
static ChatCommand commandTable[] =
|
||||
{
|
||||
{ "send", RBAC_PERM_COMMAND_SEND, false, NULL, "", sendCommandTable },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
return commandTable;
|
||||
}
|
||||
|
||||
// Send mail by command
|
||||
static bool HandleSendMailCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
// format: name "subject text" "mail text"
|
||||
Player* target;
|
||||
uint64 targetGuid;
|
||||
std::string targetName;
|
||||
if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
|
||||
return false;
|
||||
|
||||
char* tail1 = strtok(NULL, "");
|
||||
if (!tail1)
|
||||
return false;
|
||||
|
||||
char const* msgSubject = handler->extractQuotedArg(tail1);
|
||||
if (!msgSubject)
|
||||
return false;
|
||||
|
||||
char* tail2 = strtok(NULL, "");
|
||||
if (!tail2)
|
||||
return false;
|
||||
|
||||
char const* msgText = handler->extractQuotedArg(tail2);
|
||||
if (!msgText)
|
||||
return false;
|
||||
|
||||
// msgSubject, msgText isn't NUL after prev. check
|
||||
std::string subject = msgSubject;
|
||||
std::string text = msgText;
|
||||
|
||||
// from console show not existed sender
|
||||
MailSender sender(MAIL_NORMAL, handler->GetSession() ? handler->GetSession()->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM);
|
||||
|
||||
/// @todo Fix poor design
|
||||
SQLTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
MailDraft(subject, text)
|
||||
.SendMailTo(trans, MailReceiver(target, GUID_LOPART(targetGuid)), sender);
|
||||
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
|
||||
std::string nameLink = handler->playerLink(targetName);
|
||||
handler->PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Send items by mail
|
||||
static bool HandleSendItemsCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
// format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
|
||||
Player* receiver;
|
||||
uint64 receiverGuid;
|
||||
std::string receiverName;
|
||||
if (!handler->extractPlayerTarget((char*)args, &receiver, &receiverGuid, &receiverName))
|
||||
return false;
|
||||
|
||||
char* tail1 = strtok(NULL, "");
|
||||
if (!tail1)
|
||||
return false;
|
||||
|
||||
char const* msgSubject = handler->extractQuotedArg(tail1);
|
||||
if (!msgSubject)
|
||||
return false;
|
||||
|
||||
char* tail2 = strtok(NULL, "");
|
||||
if (!tail2)
|
||||
return false;
|
||||
|
||||
char const* msgText = handler->extractQuotedArg(tail2);
|
||||
if (!msgText)
|
||||
return false;
|
||||
|
||||
// msgSubject, msgText isn't NUL after prev. check
|
||||
std::string subject = msgSubject;
|
||||
std::string text = msgText;
|
||||
|
||||
// extract items
|
||||
typedef std::pair<uint32, uint32> ItemPair;
|
||||
typedef std::list< ItemPair > ItemPairs;
|
||||
ItemPairs items;
|
||||
|
||||
// get all tail string
|
||||
char* tail = strtok(NULL, "");
|
||||
|
||||
// get from tail next item str
|
||||
while (char* itemStr = strtok(tail, " "))
|
||||
{
|
||||
// and get new tail
|
||||
tail = strtok(NULL, "");
|
||||
|
||||
// parse item str
|
||||
char const* itemIdStr = strtok(itemStr, ":");
|
||||
char const* itemCountStr = strtok(NULL, " ");
|
||||
|
||||
uint32 itemId = atoi(itemIdStr);
|
||||
if (!itemId)
|
||||
return false;
|
||||
|
||||
ItemTemplate const* item_proto = sObjectMgr->GetItemTemplate(itemId);
|
||||
if (!item_proto)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 itemCount = itemCountStr ? atoi(itemCountStr) : 1;
|
||||
if (itemCount < 1 || (item_proto->MaxCount > 0 && itemCount > uint32(item_proto->MaxCount)))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, itemCount, itemId);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
while (itemCount > item_proto->GetMaxStackSize())
|
||||
{
|
||||
items.push_back(ItemPair(itemId, item_proto->GetMaxStackSize()));
|
||||
itemCount -= item_proto->GetMaxStackSize();
|
||||
}
|
||||
|
||||
items.push_back(ItemPair(itemId, itemCount));
|
||||
|
||||
if (items.size() > MAX_MAIL_ITEMS)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// from console show not existed sender
|
||||
MailSender sender(MAIL_NORMAL, handler->GetSession() ? handler->GetSession()->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM);
|
||||
|
||||
// fill mail
|
||||
MailDraft draft(subject, text);
|
||||
|
||||
SQLTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
|
||||
for (ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
|
||||
{
|
||||
if (Item* item = Item::CreateItem(itr->first, itr->second, handler->GetSession() ? handler->GetSession()->GetPlayer() : 0))
|
||||
{
|
||||
item->SaveToDB(trans); // save for prevent lost at next mail load, if send fail then item will deleted
|
||||
draft.AddItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
draft.SendMailTo(trans, MailReceiver(receiver, GUID_LOPART(receiverGuid)), sender);
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
|
||||
std::string nameLink = handler->playerLink(receiverName);
|
||||
handler->PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
|
||||
return true;
|
||||
}
|
||||
/// Send money by mail
|
||||
static bool HandleSendMoneyCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
/// format: name "subject text" "mail text" money
|
||||
|
||||
Player* receiver;
|
||||
uint64 receiverGuid;
|
||||
std::string receiverName;
|
||||
if (!handler->extractPlayerTarget((char*)args, &receiver, &receiverGuid, &receiverName))
|
||||
return false;
|
||||
|
||||
char* tail1 = strtok(NULL, "");
|
||||
if (!tail1)
|
||||
return false;
|
||||
|
||||
char* msgSubject = handler->extractQuotedArg(tail1);
|
||||
if (!msgSubject)
|
||||
return false;
|
||||
|
||||
char* tail2 = strtok(NULL, "");
|
||||
if (!tail2)
|
||||
return false;
|
||||
|
||||
char* msgText = handler->extractQuotedArg(tail2);
|
||||
if (!msgText)
|
||||
return false;
|
||||
|
||||
char* moneyStr = strtok(NULL, "");
|
||||
int32 money = moneyStr ? atoi(moneyStr) : 0;
|
||||
if (money <= 0)
|
||||
return false;
|
||||
|
||||
// msgSubject, msgText isn't NUL after prev. check
|
||||
std::string subject = msgSubject;
|
||||
std::string text = msgText;
|
||||
|
||||
// from console show not existed sender
|
||||
MailSender sender(MAIL_NORMAL, handler->GetSession() ? handler->GetSession()->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM);
|
||||
|
||||
SQLTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
|
||||
MailDraft(subject, text)
|
||||
.AddMoney(money)
|
||||
.SendMailTo(trans, MailReceiver(receiver, GUID_LOPART(receiverGuid)), sender);
|
||||
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
|
||||
std::string nameLink = handler->playerLink(receiverName);
|
||||
handler->PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
|
||||
return true;
|
||||
}
|
||||
/// Send a message to a player in game
|
||||
static bool HandleSendMessageCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
/// - Find the player
|
||||
Player* player;
|
||||
if (!handler->extractPlayerTarget((char*)args, &player))
|
||||
return false;
|
||||
|
||||
char* msgStr = strtok(NULL, "");
|
||||
if (!msgStr)
|
||||
return false;
|
||||
|
||||
///- Check that he is not logging out.
|
||||
if (player->GetSession()->isLogingOut())
|
||||
{
|
||||
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// - Send the message
|
||||
// Use SendAreaTriggerMessage for fastest delivery.
|
||||
player->GetSession()->SendAreaTriggerMessage("%s", msgStr);
|
||||
player->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
|
||||
|
||||
// Confirmation message
|
||||
std::string nameLink = handler->GetNameLink(player);
|
||||
handler->PSendSysMessage(LANG_SENDMESSAGE, nameLink.c_str(), msgStr);
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_send_commandscript()
|
||||
{
|
||||
new send_commandscript();
|
||||
}
|
||||
Reference in New Issue
Block a user