[PHP] - Trinity Mail

How exactly does the mail system on Trinity work? I am guessing you can’t just insert items into the table and they will be sent with the mail… how do you figure out the item_guid ??

I recommend using the ‘External Mail’ patch in your core. It will allow you to send mail/items from an external source such as a PHP script with ease.

Ty, I am looking into it, don’t know anything about it.

Is there a guide on using ‘External Mail’ ? I can’t find any articles on it except broken scripts and stuff…

RA or (best option) SOAP

I need a guide to 1 of these options, never heard of them and when I search it… I get no good results.

Beware of RA, I know more than one person to have hacked by RA, the best option is SOAP.

RA is secure if you dont open the port to externals conections… If RA is only avaliable por local’s connections… (127.0.0.1) and you change the port to a out of range port (50000 for example), and you close the port (50000) for incomming conections or apply for only a IP to PORT on your firewall, you have a secure RA on your server.

Thanks for the tips… but still don’t have a clue how to use any of them…

Yes, yes, i’m not saying that is not safe, i say that with a bit of mischief you can access.

O.o lol.

Is there anyone that can help me with this?

I tried this:


void WorldSession::SendExternalMails()

{

        SQLTransaction trans = CharacterDatabase.BeginTransaction();

                CharacterDatabase.BeginTransaction();

    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( trans, MailReceiver(last_receiver_guid),MailSender(MAIL_NORMAL, 0 , MAIL_STATIONERY_GM),MAIL_CHECK_MASK_RETURNED, NULL);

                    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(trans);

                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( trans, MailReceiver(last_receiver_guid),MailSender(MAIL_NORMAL, 0 , MAIL_STATIONERY_GM),MAIL_CHECK_MASK_RETURNED, NULL);

            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");

        }

    }


        CharacterDatabase.CommitTransaction(trans);

    //delete result;

    sLog.outString("EXTERNAL MAIL> All Mails Sent...");

}

And got the following errors:

Error 1 error C2039: ‘SendExternalMails’ : is not a member of ‘WorldSession’ C:\Users\Lss\Desktop\Trinity\TrinityCore\src\server\game\Mails\Mail.cpp 174

Error 2 error C2228: left of ‘.outString’ must have class/struct/union C:\Users\Lss\Desktop\Trinity\TrinityCore\src\server\game\Mails\Mail.cpp 178

Error 3 error C2228: left of ‘.outString’ must have class/struct/union C:\Users\Lss\Desktop\Trinity\TrinityCore\src\server\game\Mails\Mail.cpp 182

Error 4 error C2228: left of ‘.GetPlayer’ must have class/struct/union C:\Users\Lss\Desktop\Trinity\TrinityCore\src\server\game\Mails\Mail.cpp 203

Error 5 error C2228: left of ‘.outString’ must have class/struct/union C:\Users\Lss\Desktop\Trinity\TrinityCore\src\server\game\Mails\Mail.cpp 210

Error 6 error C2228: left of ‘.outString’ must have class/struct/union C:\Users\Lss\Desktop\Trinity\TrinityCore\src\server\game\Mails\Mail.cpp 214

Error 7 error C2228: left of ‘.outString’ must have class/struct/union C:\Users\Lss\Desktop\Trinity\TrinityCore\src\server\game\Mails\Mail.cpp 222

Error 8 error C2228: left of ‘.outString’ must have class/struct/union C:\Users\Lss\Desktop\Trinity\TrinityCore\src\server\game\Mails\Mail.cpp 229

Error 9 error C2228: left of ‘.outString’ must have class/struct/union C:\Users\Lss\Desktop\Trinity\TrinityCore\src\server\game\Mails\Mail.cpp 245

Error 10 error C2228: left of ‘.outString’ must have class/struct/union C:\Users\Lss\Desktop\Trinity\TrinityCore\src\server\game\Mails\Mail.cpp 250

Error 11 error C2228: left of ‘.outString’ must have class/struct/union C:\Users\Lss\Desktop\Trinity\TrinityCore\src\server\game\Mails\Mail.cpp 256

for the first error, you don’t have the declaration in the world.h file for the command. As for the rest, the sLog usage was changed a while back, and a simple search in the source would have shown you the change… sLog->outString

also, sObjectMgr.GetPlayer sObjectMgr->GetPlayer

seems you don’t have the entire patch… make sure you have the sql part set up properly as well.

Ty, how would I declare it in world.h?

exactly like any other function there already, don’t be lazy.

I am not sure if I did it right lol… but, I did the following:

class SendExternalMails;

at the top with all the other classes… and I am compiling now.

Error Outcome: Error 1 error C2039: ‘SendExternalMails’ : is not a member of ‘WorldSession’ C:\Users\Lss\Desktop\Trinity\TrinityCore\src\server\game\Mails\Mail.cpp 174

Compile Outcome: ========== Build: 12 succeeded, 2 failed, 0 up-to-date, 1 skipped ==========

With last error: Error 2 error LNK1181: cannot open input file ‘…\game\Release\game.lib’ C:\Users\Lss\Desktop\Trinity\Build\src\server\worldserver\LINK

Any ideas?

It’s not a class

void WorldSession::SendExternalMails()

I don’t see any functions in there… I am going to guess and say its declared like:

function name; ?

You don’t see any functions?

WTF are these, then?


        WorldSession* FindSession(uint32 id) const;

        void AddSession(WorldSession *s);

        void SendAutoBroadcast();

        bool RemoveSession(uint32 id);

        /// Get the number of current active sessions

        void UpdateMaxSessionCounters();

        const SessionMap& GetAllSessions() const { return m_sessions; }

        uint32 GetActiveAndQueuedSessionCount() const { return m_sessions.size(); }

        uint32 GetActiveSessionCount() const { return m_sessions.size() - m_QueuedPlayer.size(); }

        uint32 GetQueuedSessionCount() const { return m_QueuedPlayer.size(); }

        /// Get the maximum number of parallel sessions on the server since last reboot

        uint32 GetMaxQueuedSessionCount() const { return m_maxQueuedSessionCount; }

        uint32 GetMaxActiveSessionCount() const { return m_maxActiveSessionCount; }

        /// Get number of players

        inline uint32 GetPlayerCount() const { return m_PlayerCount; }

        inline uint32 GetMaxPlayerCount() const { return m_MaxPlayerCount; }