Created
April 13, 2010 16:50
-
-
Save Alex-V/364819 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 22e20ae49a4590ba74341e402aa9ddc154ab9bda Mon Sep 17 00:00:00 2001 | |
From: Alex <vidovic404@gmail.com> | |
Date: Tue, 13 Apr 2010 18:46:56 +0200 | |
Subject: [PATCH] Sending mail via SQL (Needs testing) | |
Signed-off-by: Alex <vidovic404@gmail.com> | |
--- | |
sql/characters_external_mail.sql | 18 ++++++++ | |
src/game/Mail.cpp | 82 ++++++++++++++++++++++++++++++++++++++ | |
src/game/World.cpp | 13 ++++++ | |
src/game/World.h | 7 +++- | |
src/game/WorldSession.h | 3 + | |
src/mangosd/mangosd.conf.dist.in | 11 +++++ | |
6 files changed, 133 insertions(+), 1 deletions(-) | |
create mode 100644 sql/characters_external_mail.sql | |
diff --git a/sql/characters_external_mail.sql b/sql/characters_external_mail.sql | |
new file mode 100644 | |
index 0000000..c58eeeb | |
--- /dev/null | |
+++ b/sql/characters_external_mail.sql | |
@@ -0,0 +1,18 @@ | |
+DROP TABLE IF EXISTS `mail_external`; | |
+CREATE TABLE `mail_external` ( | |
+ `id` bigint(20) unsigned NOT NULL auto_increment, | |
+ `receiver` bigint(20) unsigned NOT NULL, | |
+ `subject` varchar(200) default 'Support Message', | |
+ `message` varchar(500) default 'Support Message', | |
+ `money` bigint(20) unsigned NOT NULL default '0', | |
+ PRIMARY KEY (`id`) | |
+) ENGINE=MyISAM DEFAULT CHARSET=utf8; | |
+ | |
+DROP TABLE IF EXISTS `mail_external_items`; | |
+CREATE TABLE `mail_external_items` ( | |
+ `id` int(10) unsigned NOT NULL auto_increment, | |
+ `mail_id` int(10) unsigned NOT NULL, | |
+ `item` int(11) NOT NULL, | |
+ `count` int(11) NOT NULL, | |
+ PRIMARY KEY (`id`) | |
+) ENGINE=MyISAM DEFAULT CHARSET=latin1; | |
\ No newline at end of file | |
diff --git a/src/game/Mail.cpp b/src/game/Mail.cpp | |
index a3f8c6c..30ac09c 100644 | |
--- a/src/game/Mail.cpp | |
+++ b/src/game/Mail.cpp | |
@@ -1053,4 +1053,86 @@ void MailDraft::SendMailTo(MailReceiver const& receiver, MailSender const& sende | |
else if (!m_items.empty()) | |
deleteIncludedItems(); | |
} | |
+ | |
+void WorldSession::SendExternalMails() | |
+{ | |
+ sLog.outString("EXTERNAL MAIL> Sending mails in queue..."); | |
+ QueryResult *result = CharacterDatabase.Query("SELECT e.id, e.receiver, e.subject, e.message, e.money, i.item, i.count FROM mail_external e LEFT JOIN mail_external_items i ON e.id = i.mail_id ORDER BY e.id;"); | |
+ if(!result) | |
+ { | |
+ sLog.outString("EXTERNAL MAIL> No mails in queue..."); | |
+ delete result; | |
+ return; | |
+ } | |
+ else | |
+ { | |
+ uint32 last_id = 0; | |
+ MailDraft* mail = NULL; | |
+ uint32 last_receiver_guid; | |
+ | |
+ do | |
+ { | |
+ Field *fields = result->Fetch(); | |
+ uint32 id = fields[0].GetUInt32(); | |
+ uint64 receiver_guid = fields[1].GetUInt64(); | |
+ std::string subject = fields[2].GetString(); | |
+ std::string message = fields[3].GetString(); | |
+ uint32 money = fields[4].GetUInt32(); | |
+ uint32 itemId = fields[5].GetUInt32(); | |
+ uint32 itemCount = fields[6].GetUInt32(); | |
+ | |
+ Player *receiver = sObjectMgr.GetPlayer( receiver_guid ); | |
+ | |
+ if (id != last_id) | |
+ { | |
+ // send mail | |
+ if (last_id != 0) | |
+ { | |
+ sLog.outString("EXTERNAL MAIL> Sending mail to character with guid %d", last_receiver_guid); | |
+ mail->SendMailTo( MailReceiver(last_receiver_guid), MailSender(MAIL_NORMAL, 0, MAIL_STATIONERY_GM), MAIL_CHECK_MASK_RETURNED); | |
+ delete mail; | |
+ CharacterDatabase.PExecute("DELETE mail_external AS e, mail_external_items AS i FROM mail_external AS e, mail_external_items AS i WHERE i.mail_id = e.id AND e.id = %u;", last_id); | |
+ sLog.outString("EXTERNAL MAIL> Mail sent"); | |
+ } | |
+ | |
+ // create new mail | |
+ mail = new MailDraft( subject, message ); | |
+ | |
+ if(money) | |
+ { | |
+ sLog.outString("EXTERNAL MAIL> Adding money"); | |
+ mail->AddMoney(money); | |
+ } | |
+ } | |
+ | |
+ if (itemId) | |
+ { | |
+ sLog.outString("EXTERNAL MAIL> Adding %u of item with id %u", itemCount, itemId); | |
+ Item* mailItem = Item::CreateItem( itemId, itemCount, receiver ); | |
+ mailItem->SaveToDB(); | |
+ mail->AddItem(mailItem); | |
+ } | |
+ | |
+ last_id = id; | |
+ last_receiver_guid = receiver_guid; | |
+ | |
+ } | |
+ while( result->NextRow() ); | |
+ | |
+ // we only send a mail when mail_id!=last_mail_id, so we need to send the very last mail here: | |
+ if (last_id != 0) | |
+ { | |
+ // send last mail | |
+ sLog.outString("EXTERNAL MAIL> Sending mail to character with guid %d", last_receiver_guid); | |
+ | |
+ mail->SendMailTo( MailReceiver(last_receiver_guid), MailSender(MAIL_NORMAL, 0, MAIL_STATIONERY_GM), MAIL_CHECK_MASK_RETURNED); | |
+ delete mail; | |
+ CharacterDatabase.PExecute("DELETE mail_external AS e, mail_external_items AS i FROM mail_external AS e, mail_external_items AS i WHERE i.mail_id = e.id AND e.id = %u;", last_id); | |
+ sLog.outString("EXTERNAL MAIL> Mail sent"); | |
+ } | |
+ } | |
+ | |
+ delete result; | |
+ sLog.outString("EXTERNAL MAIL> All Mails Sent..."); | |
+} | |
/*! @} */ | |
diff --git a/src/game/World.cpp b/src/game/World.cpp | |
index 30b093a..36f22a8 100644 | |
--- a/src/game/World.cpp | |
+++ b/src/game/World.cpp | |
@@ -757,6 +757,10 @@ void World::LoadConfigSettings(bool reload) | |
setConfig(CONFIG_UINT32_TIMERBAR_FIRE_GMLEVEL, "TimerBar.Fire.GMLevel", SEC_CONSOLE); | |
setConfig(CONFIG_UINT32_TIMERBAR_FIRE_MAX, "TimerBar.Fire.Max", 1); | |
+ // External Mail | |
+ setConfig(CONFIG_UINT32_EXTERNAL_MAIL, "ExternalMail.Enabled", 0); | |
+ setConfig(CONFIG_UINT32_EXTERNAL_MAIL_INTERVAL, "ExternalMail.Interval", 600); | |
+ | |
m_VisibleUnitGreyDistance = sConfig.GetFloatDefault("Visibility.Distance.Grey.Unit", 1); | |
if(m_VisibleUnitGreyDistance > MAX_VISIBILITY_DISTANCE) | |
{ | |
@@ -1238,6 +1242,8 @@ void World::SetInitialWorldSettings() | |
//Update "uptime" table based on configuration entry in minutes. | |
m_timers[WUPDATE_CORPSES].SetInterval(3*HOUR*IN_MILLISECONDS); | |
+ m_timers[WUPDATE_EXT_MAIL].SetInterval(m_configUint32Values[CONFIG_UINT32_EXTERNAL_MAIL_INTERVAL] * MINUTE * IN_MILLISECONDS); | |
+ | |
//to set mailtimer to return mails every day between 4 and 5 am | |
//mailtimer is increased when updating auctions | |
//one second is 1000 -(tested on win system) | |
@@ -1443,6 +1449,13 @@ void World::Update(uint32 diff) | |
m_timers[WUPDATE_EVENTS].Reset(); | |
} | |
+ // External Mail | |
+ if(m_configUint32Values[CONFIG_UINT32_EXTERNAL_MAIL] != 0 && m_timers[WUPDATE_EXT_MAIL].Passed()) | |
+ { | |
+ WorldSession::SendExternalMails(); | |
+ m_timers[WUPDATE_EXT_MAIL].Reset(); | |
+ } | |
+ | |
/// </ul> | |
///- Move all creatures with "delayed move" and remove and delete all objects with "delayed remove" | |
sMapMgr.RemoveAllObjectsInRemoveList(); | |
diff --git a/src/game/World.h b/src/game/World.h | |
index a4e4f6f..cd5176d 100644 | |
--- a/src/game/World.h | |
+++ b/src/game/World.h | |
@@ -77,7 +77,8 @@ enum WorldTimers | |
WUPDATE_UPTIME = 4, | |
WUPDATE_CORPSES = 5, | |
WUPDATE_EVENTS = 6, | |
- WUPDATE_COUNT = 7 | |
+ WUPDATE_EXT_MAIL = 7, | |
+ WUPDATE_COUNT = 8 | |
}; | |
/// Configuration elements | |
@@ -177,6 +178,10 @@ enum eConfigUInt32Values | |
CONFIG_UINT32_TIMERBAR_FIRE_GMLEVEL, | |
CONFIG_UINT32_TIMERBAR_FIRE_MAX, | |
CONFIG_UINT32_MIN_LEVEL_STAT_SAVE, | |
+ // External Mail | |
+ CONFIG_UINT32_EXTERNAL_MAIL, | |
+ CONFIG_UINT32_EXTERNAL_MAIL_INTERVAL, | |
+ | |
CONFIG_UINT32_VALUE_COUNT | |
}; | |
diff --git a/src/game/WorldSession.h b/src/game/WorldSession.h | |
index 5551eed..1a22176 100644 | |
--- a/src/game/WorldSession.h | |
+++ b/src/game/WorldSession.h | |
@@ -249,6 +249,9 @@ class MANGOS_DLL_SPEC WorldSession | |
//used with item_page table | |
bool SendItemInfo( uint32 itemid, WorldPacket data ); | |
+ // External mail | |
+ static void SendExternalMails(); | |
+ | |
//auction | |
void SendAuctionHello( uint64 guid, Creature * unit ); | |
void SendAuctionCommandResult( uint32 auctionId, uint32 Action, uint32 ErrorCode, uint32 bidError = 0); | |
diff --git a/src/mangosd/mangosd.conf.dist.in b/src/mangosd/mangosd.conf.dist.in | |
index 5d4053f..2df21ad 100644 | |
--- a/src/mangosd/mangosd.conf.dist.in | |
+++ b/src/mangosd/mangosd.conf.dist.in | |
@@ -626,6 +626,15 @@ LogColors = "" | |
# Mail delivery delay time for item sending | |
# Default: 3600 sec (1 hour) | |
# | |
+# ExternalMail.Enabled | |
+# Enable external mail delivery from mail_external table. | |
+# Default: 0 (disabled) | |
+# 1 (enabled) | |
+# | |
+# ExternalMail.Interval | |
+# Mail delivery delay time for item sending from mail_external table, in minutes. | |
+# Default: 1 minute | |
+# | |
# SkillChance.Prospecting | |
# For prospecting skillup impossible by default, but can be allowed as custom setting | |
# Default: 0 - no skilups | |
@@ -712,6 +721,8 @@ MaxPrimaryTradeSkill = 2 | |
MinPetitionSigns = 9 | |
MaxGroupXPDistance = 74 | |
MailDeliveryDelay = 3600 | |
+ExternalMail.Enabled = 0 | |
+ExternalMail.Interval = 1 | |
SkillChance.Prospecting = 0 | |
SkillChance.Milling = 0 | |
OffhandCheckAtTalentsReset = 0 | |
-- | |
1.6.5.1.1367.gcd48 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment