Jump to content

[PATCH] External Mail from SQL


Recommended Posts

  • 39 years later...
  • Replies 104
  • Created
  • Last Reply

Top Posters In This Topic

My simple patch, allow send mail to characters from sql table. You may configure mod from mangos config file.

Patch version 0.6:

- allow send items and money.

- allow send items count only for stacked items.

- configure in mangos.conf (enable/disable, interval).

Table for characters database

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',
 `item` bigint(20) unsigned NOT NULL default '0',
 `item_count` bigint(20) unsigned NOT NULL default '0',
 PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Patch for GIT (8794)

diff --git a/src/game/Mail.cpp b/src/game/Mail.cpp
index 5bac29d..fb720c0 100644
--- a/src/game/Mail.cpp
+++ b/src/game/Mail.cpp
@@ -995,3 +995,59 @@ void MailDraft::SendMailTo(MailReceiver const& receiver, MailSender const& sende
    else if (!m_items.empty())
        deleteIncludedItems();
}
+
+void WorldSession::SendExternalMails()
+{
+    sLog.outString("EXTERNAL MAIL> Send Mails from Queue...");
+    QueryResult *result = CharacterDatabase.Query("SELECT id,receiver,subject,message,money,item,item_count FROM mail_external");
+        if(!result)
+        {
+            sLog.outString("EXTERNAL MAIL> No Mails in Queue...");
+            delete result;
+            return;
+        }else{
+            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( receiver != 0 )
+                {
+                    sLog.outString("EXTERNAL MAIL> Sending mail to %u, Item:%u", receiver_guid, ItemID);
+                    
+                    uint32 itemTextId = !message.empty() ? sObjectMgr.CreateItemText( message ) : 0;
+                    
+                    if ( ItemID != 0 )
+                    {
+                        Item* ToMailItem = Item::CreateItem( ItemID, ItemCount, receiver );
+                        ToMailItem -> SaveToDB();
+                    
+                        MailDraft( subject, itemTextId )
+                            .AddItem( ToMailItem )
+                            .AddMoney( money )
+                            .SendMailTo( MailReceiver(receiver), MailSender(MAIL_NORMAL, 0, MAIL_STATIONERY_GM), MAIL_CHECK_MASK_RETURNED);
+                    }
+                    else 
+                    {
+                        MailDraft( subject, itemTextId )
+                            .AddMoney( money )
+                            .SendMailTo( MailReceiver(receiver), MailSender(MAIL_NORMAL, 0, MAIL_STATIONERY_GM), MAIL_CHECK_MASK_RETURNED);
+
+                    }
+                    CharacterDatabase.PExecute("DELETE FROM mail_external WHERE id=%u", id);
+                }
+                else
+                    sLog.outString("EXTERNAL MAIL> Player %u not in game, skip mail!", receiver_guid);
+            
+            }while( result -> NextRow() );
+        }
+    delete result;
+    sLog.outString("EXTERNAL MAIL> All Mails Sent...");    
+}
\\ No newline at end of file
diff --git a/src/game/World.cpp b/src/game/World.cpp
index bf0b69b..f562adc 100644
--- a/src/game/World.cpp
+++ b/src/game/World.cpp
@@ -844,6 +844,9 @@ void World::LoadConfigSettings(bool reload)
    m_configs[CONFIG_GROUP_VISIBILITY] = sConfig.GetIntDefault("Visibility.GroupMode",0);

    m_configs[CONFIG_MAIL_DELIVERY_DELAY] = sConfig.GetIntDefault("MailDeliveryDelay",HOUR);
+    
+    m_configs[CONFIG_EXTERNAL_MAIL] = sConfig.GetIntDefault("ExternalMail", 0);
+    m_configs[CONFIG_EXTERNAL_MAIL_INTERVAL] = sConfig.GetIntDefault("ExternalMailInterval", 1);    

    m_configs[CONFIG_UPTIME_UPDATE] = sConfig.GetIntDefault("UpdateUptimeInterval", 10);
    if(int32(m_configs[CONFIG_UPTIME_UPDATE])<=0)
@@ -1496,6 +1499,10 @@ void World::SetInitialWorldSettings()
    //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)
+    
+    // handle timer for external mail
+    extmail_timer.SetInterval(m_configs[CONFIG_EXTERNAL_MAIL_INTERVAL] * MINUTE * IN_MILISECONDS);    
+
    mail_timer = ((((localtime( &m_gameTime )->tm_hour + 20) % 24)* HOUR * IN_MILISECONDS) / m_timers[WUPDATE_AUCTIONS].GetInterval() );
                                                            //1440
    mail_timer_expires = ( (DAY * IN_MILISECONDS) / (m_timers[WUPDATE_AUCTIONS].GetInterval()));
@@ -1601,6 +1608,17 @@ void World::Update(uint32 diff)
        m_NextDailyQuestReset += DAY;
    }

+    /// Handle external mail
+    if (m_configs[CONFIG_EXTERNAL_MAIL] != 0)
+    {
+        extmail_timer.Update(diff);
+        if (extmail_timer.Passed())
+        {
+            WorldSession::SendExternalMails();
+            extmail_timer.Reset();
+        }
+    }    
+
    /// <ul>[*] Handle auctions when the timer has passed
    if (m_timers[WUPDATE_AUCTIONS].Passed())
    {
diff --git a/src/game/World.h b/src/game/World.h
index a86885f..1f1b478 100644
--- a/src/game/World.h
+++ b/src/game/World.h
@@ -146,6 +146,8 @@ enum WorldConfigs
    CONFIG_GM_ALLOW_ACHIEVEMENT_GAINS,
    CONFIG_GROUP_VISIBILITY,
    CONFIG_MAIL_DELIVERY_DELAY,
+    CONFIG_EXTERNAL_MAIL,
+    CONFIG_EXTERNAL_MAIL_INTERVAL,    
    CONFIG_UPTIME_UPDATE,
    CONFIG_SKILL_CHANCE_ORANGE,
    CONFIG_SKILL_CHANCE_YELLOW,
@@ -562,6 +564,7 @@ class World
        time_t m_startTime;
        time_t m_gameTime;
        IntervalTimer m_timers[WUPDATE_COUNT];
+        IntervalTimer extmail_timer;
        uint32 mail_timer;
        uint32 mail_timer_expires;

diff --git a/src/game/WorldSession.h b/src/game/WorldSession.h
index 782dcc9..eb49937 100644
--- a/src/game/WorldSession.h
+++ b/src/game/WorldSession.h
@@ -224,6 +224,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 );
diff --git a/src/mangosd/mangosd.conf.dist.in b/src/mangosd/mangosd.conf.dist.in
index 92f308f..721cfc1 100644
--- a/src/mangosd/mangosd.conf.dist.in
+++ b/src/mangosd/mangosd.conf.dist.in
@@ -661,6 +661,15 @@ LexicsCutterNoActionOnGM = 1
#        Mail delivery delay time for item sending
#        Default: 3600 sec (1 hour)
#
+#    ExternalMail
+#        Enable external mail delivery from mail_external table.
+#        Default: 0 (disabled)
+#                 1 (enabled)
+#
+#    ExternalMailInterval
+#        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
@@ -743,6 +752,8 @@ MaxPrimaryTradeSkill = 2
MinPetitionSigns = 9
MaxGroupXPDistance = 74
MailDeliveryDelay = 3600
+ExternalMail = 0
+ExternalMailInterval = 1
SkillChance.Prospecting = 0
SkillChance.Milling = 0
OffhandCheckAtTalentsReset = 0

Link to comment
Share on other sites

  • 3 weeks later...

Small code style fix.

+                uint32 ItemID = fields[5].GetUInt32();
+                uint32 ItemCount = fields[6].GetUInt32();
+
+                if(Player *receiver = sObjectMgr.GetPlayer( receiver_guid ))
+                {
+                    sLog.outString("EXTERNAL MAIL> Sending mail to %u, Item:%u", receiver_guid, ItemID);
+

Link to comment
Share on other sites

  • 3 weeks later...
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use