Index: /trunk/src/game/WorldSocket.h
===================================================================
--- /trunk/src/game/WorldSocket.h (revision 181)
+++ /trunk/src/game/WorldSocket.h (revision 232)
@@ -56,34 +56,34 @@
  * WorldSocket.
  *
- * This class is responsible for the comunication with
+ * This class is responsible for the communication with
  * remote clients.
  * Most methods return -1 on failure.
- * The class uses refferece counting.
+ * The class uses reference counting.
  *
  * For output the class uses one buffer (64K usually) and
  * a queue where it stores packet if there is no place on
  * the queue. The reason this is done, is because the server
- * does realy a lot of small-size writes to it, and it doesn't
+ * does really a lot of small-size writes to it, and it doesn't
  * scale well to allocate memory for every. When something is
- * writen to the output buffer the socket is not immideately
+ * written to the output buffer the socket is not immediately
  * activated for output (again for the same reason), there
  * is 10ms celling (thats why there is Update() method).
- * This concept is simmilar to TCP_CORK, but TCP_CORK
- * usses 200ms celling. As result overhead generated by
+ * This concept is similar to TCP_CORK, but TCP_CORK
+ * uses 200ms celling. As result overhead generated by
  * sending packets from "producer" threads is minimal,
- * and doing a lot of writes with small size is tollerated.
- *
- * The calls to Upate () method are managed by WorldSocketMgr
+ * and doing a lot of writes with small size is tolerated.
+ *
+ * The calls to Update () method are managed by WorldSocketMgr
  * and ReactorRunnable.
  *
  * For input ,the class uses one 1024 bytes buffer on stack
- * to which it does recv() calls. And then recieved data is
- * distributed where its needed. 1024 matches pritey well the
+ * to which it does recv() calls. And then received data is
+ * distributed where its needed. 1024 matches pretty well the
  * traffic generated by client for now.
  *
  * The input/output do speculative reads/writes (AKA it tryes
- * to read all data avaible in the kernel buffer or tryes to
- * write everything avaible in userspace buffer),
- * which is ok for using with Level and Edge Trigered IO
+ * to read all data available in the kernel buffer or tryes to
+ * write everything available in userspace buffer),
+ * which is ok for using with Level and Edge Triggered IO
  * notification.
  *
@@ -100,5 +100,5 @@
         typedef ACE_Acceptor< WorldSocket, ACE_SOCK_ACCEPTOR > Acceptor;
 
-        /// Mutex type used for various syncronizations.
+        /// Mutex type used for various synchronizations.
         typedef ACE_Thread_Mutex LockType;
         typedef ACE_Guard<LockType> GuardType;
@@ -121,8 +121,8 @@
         int SendPacket (const WorldPacket& pct);
 
-        /// Add refference to this object.
+        /// Add reference to this object.
         long AddReference (void);
 
-        /// Remove refference to this object.
+        /// Remove reference to this object.
         long RemoveReference (void);
 
@@ -186,5 +186,5 @@
         ACE_Time_Value m_LastPingTime;
 
-        /// Keep track of overspeed pings ,to prevent ping flood.
+        /// Keep track of over-speed pings ,to prevent ping flood.
         uint32 m_OverSpeedPings;
 
@@ -198,19 +198,19 @@
         LockType m_SessionLock;
 
-        /// Session to which recieved packets are routed
+        /// Session to which received packets are routed
         WorldSession* m_Session;
 
-        /// here are stored the fragmens of the recieved data
+        /// here are stored the fragments of the received data
         WorldPacket* m_RecvWPct;
 
         /// This block actually refers to m_RecvWPct contents,
-        /// which alows easy and safe writing to it.
+        /// which allows easy and safe writing to it.
         /// It wont free memory when its deleted. m_RecvWPct takes care of freeing.
         ACE_Message_Block m_RecvPct;
 
-        /// Fragment of the recieved header.
+        /// Fragment of the received header.
         ACE_Message_Block m_Header;
 
-        /// Mutex for protecting otuput related data.
+        /// Mutex for protecting output related data.
         LockType m_OutBufferLock;
 
@@ -222,5 +222,5 @@
 
         /// Here are stored packets for which there was no space on m_OutBuffer,
-        /// this alows not-to kick player if its buffer is overflowed.
+        /// this allows not-to kick player if its buffer is overflowed.
         PacketQueueT m_PacketQueue;
 
Index: /trunk/src/game/Level3.cpp
===================================================================
--- /trunk/src/game/Level3.cpp (revision 230)
+++ /trunk/src/game/Level3.cpp (revision 232)
@@ -6202,4 +6202,243 @@
 }
 
+//Send items by mail
+bool ChatHandler::HandleSendItemsCommand(const char* args)
+{
+    if(!*args)
+        return false;
+
+    // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
+
+    char* pName = strtok((char*)args, " ");
+    if(!pName)
+        return false;
+
+    char* tail1 = strtok(NULL, "");
+    if(!tail1)
+        return false;
+
+    char* msgSubject;
+    if(*tail1=='"')
+        msgSubject = strtok(tail1+1, "\"");
+    else
+    {
+        char* space = strtok(tail1, "\"");
+        if(!space)
+            return false;
+        msgSubject = strtok(NULL, "\"");
+    }
+
+    if (!msgSubject)
+        return false;
+
+    char* tail2 = strtok(NULL, "");
+    if(!tail2)
+        return false;
+
+    char* msgText;
+    if(*tail2=='"')
+        msgText = strtok(tail2+1, "\"");
+    else
+    {
+        char* space = strtok(tail2, "\"");
+        if(!space)
+            return false;
+        msgText = strtok(NULL, "\"");
+    }
+
+    if (!msgText)
+        return false;
+
+    // pName, msgSubject, msgText isn't NUL after prev. check
+    std::string name    = pName;
+    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* itemIdStr = strtok(itemStr, ":");
+        char* itemCountStr = strtok(NULL, " ");
+
+        uint32 item_id = atoi(itemIdStr);
+        if(!item_id)
+            return false;
+
+        ItemPrototype const* item_proto = objmgr.GetItemPrototype(item_id);
+        if(!item_proto)
+        {
+            PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
+            SetSentErrorMessage(true);
+            return false;
+        }
+
+        uint32 item_count = itemCountStr ? atoi(itemCountStr) : 1;
+        if(item_count < 1 || item_proto->MaxCount && item_count > item_proto->MaxCount)
+        {
+            PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, item_count,item_id);
+            SetSentErrorMessage(true);
+            return false;
+        }
+
+        while(item_count > item_proto->Stackable)
+        {
+            items.push_back(ItemPair(item_id,item_proto->Stackable));
+            item_count -= item_proto->Stackable;
+        }
+
+        items.push_back(ItemPair(item_id,item_count));
+
+        if(items.size() > MAX_MAIL_ITEMS)
+        {
+            PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
+            SetSentErrorMessage(true);
+            return false;
+        }
+    }
+
+    if(!normalizePlayerName(name))
+    {
+        SendSysMessage(LANG_PLAYER_NOT_FOUND);
+        SetSentErrorMessage(true);
+        return false;
+    }
+
+    uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
+    if(!receiver_guid)
+    {
+        SendSysMessage(LANG_PLAYER_NOT_FOUND);
+        SetSentErrorMessage(true);
+        return false;
+    }
+
+    // from console show not existed sender
+    uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
+
+    uint32 messagetype = MAIL_NORMAL;
+    uint32 stationery = MAIL_STATIONERY_GM;
+    uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
+
+    Player *receiver = objmgr.GetPlayer(receiver_guid);
+
+    // fill mail
+    MailItemsInfo mi;                                       // item list preparing
+
+    for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
+    {
+        if(Item* item = Item::CreateItem(itr->first,itr->second,m_session ? m_session->GetPlayer() : 0))
+        {
+            item->SaveToDB();                               // save for prevent lost at next mail load, if send fail then item will deleted
+            mi.AddItem(item->GetGUIDLow(), item->GetEntry(), item);
+        }
+    }
+
+    WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
+
+    PSendSysMessage(LANG_MAIL_SENT, name.c_str());
+    return true;
+}
+
+///Send money by mail
+bool ChatHandler::HandleSendMoneyCommand(const char* args)
+{
+    if (!*args)
+        return false;
+
+    /// format: name "subject text" "mail text" money
+
+    char* pName = strtok((char*)args, " ");
+    if (!pName)
+        return false;
+
+    char* tail1 = strtok(NULL, "");
+    if (!tail1)
+        return false;
+
+    char* msgSubject;
+    if (*tail1=='"')
+        msgSubject = strtok(tail1+1, "\"");
+    else
+    {
+        char* space = strtok(tail1, "\"");
+        if (!space)
+            return false;
+        msgSubject = strtok(NULL, "\"");
+    }
+
+    if (!msgSubject)
+        return false;
+
+    char* tail2 = strtok(NULL, "");
+    if (!tail2)
+        return false;
+
+    char* msgText;
+    if (*tail2=='"')
+        msgText = strtok(tail2+1, "\"");
+    else
+    {
+        char* space = strtok(tail2, "\"");
+        if (!space)
+            return false;
+        msgText = strtok(NULL, "\"");
+    }
+
+    if (!msgText)
+        return false;
+
+    char* money_str = strtok(NULL, "");
+    int32 money = money_str ? atoi(money_str) : 0;
+    if (money <= 0)
+        return false;
+
+    // pName, msgSubject, msgText isn't NUL after prev. check
+    std::string name    = pName;
+    std::string subject = msgSubject;
+    std::string text    = msgText;
+
+    if (!normalizePlayerName(name))
+    {
+        SendSysMessage(LANG_PLAYER_NOT_FOUND);
+        SetSentErrorMessage(true);
+        return false;
+    }
+
+    uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
+    if (!receiver_guid)
+    {
+        SendSysMessage(LANG_PLAYER_NOT_FOUND);
+        SetSentErrorMessage(true);
+        return false;
+    }
+
+    uint32 mailId = objmgr.GenerateMailID();
+
+    // from console show not existed sender
+    uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
+
+    uint32 messagetype = MAIL_NORMAL;
+    uint32 stationery = MAIL_STATIONERY_GM;
+    uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
+
+    Player *receiver = objmgr.GetPlayer(receiver_guid);
+
+    WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, money, 0, MAIL_CHECK_MASK_NONE);
+
+    PSendSysMessage(LANG_MAIL_SENT, name.c_str());
+    return true;
+}
+
 /// Send a message to a player in game
 bool ChatHandler::HandleSendMessageCommand(const char* args)
Index: /trunk/src/game/Chat.cpp
===================================================================
--- /trunk/src/game/Chat.cpp (revision 229)
+++ /trunk/src/game/Chat.cpp (revision 232)
@@ -545,5 +545,7 @@
         { "lockaccount",    SEC_PLAYER,         false, &ChatHandler::HandleLockAccountCommand,         "", NULL },
         { "respawn",        SEC_ADMINISTRATOR,  false, &ChatHandler::HandleRespawnCommand,             "", NULL },
-        { "sendmail",       SEC_MODERATOR,      false, &ChatHandler::HandleSendMailCommand,            "", NULL },
+        { "senditems",      SEC_ADMINISTRATOR,  true,  &ChatHandler::HandleSendItemsCommand,           "", NULL },
+        { "sendmail",       SEC_MODERATOR,      true,  &ChatHandler::HandleSendMailCommand,            "", NULL },
+        { "sendmoney",      SEC_ADMINISTRATOR,  true,  &ChatHandler::HandleSendMoneyCommand,           "", NULL },
         { "rename",         SEC_GAMEMASTER,     true,  &ChatHandler::HandleRenameCommand,              "", NULL },
         { "loadscripts",    SEC_ADMINISTRATOR,  true,  &ChatHandler::HandleLoadScriptsCommand,         "", NULL },
Index: /trunk/src/game/Chat.h
===================================================================
--- /trunk/src/game/Chat.h (revision 209)
+++ /trunk/src/game/Chat.h (revision 232)
@@ -118,8 +118,10 @@
         bool HandleTaxiCheatCommand(const char* args);
         bool HandleWhispersCommand(const char* args);
-        bool HandleSendMailCommand(const char* args);
         bool HandleNameTeleCommand(const char* args);
         bool HandleGroupTeleCommand(const char* args);
         bool HandleDrunkCommand(const char* args);
+        bool HandleSendItemsCommand(const char* args);
+        bool HandleSendMailCommand(const char* args);
+        bool HandleSendMoneyCommand(const char* args);
 
         bool HandleEventActiveListCommand(const char* args);
Index: /trunk/src/game/Level1.cpp
===================================================================
--- /trunk/src/game/Level1.cpp (revision 177)
+++ /trunk/src/game/Level1.cpp (revision 232)
@@ -1864,5 +1864,5 @@
         return false;
 
-    // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
+    // format: name "subject text" "mail text"
 
     char* pName = strtok((char*)args, " ");
@@ -1911,58 +1911,4 @@
     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* itemIdStr = strtok(itemStr, ":");
-        char* itemCountStr = strtok(NULL, " ");
-        
-        uint32 item_id = atoi(itemIdStr);
-        if(!item_id)
-            return false;
-
-        ItemPrototype const* item_proto = objmgr.GetItemPrototype(item_id);
-        if(!item_proto)
-        {
-            PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
-            SetSentErrorMessage(true);
-            return false;
-        }
-
-        uint32 item_count = itemCountStr ? atoi(itemCountStr) : 1;
-        if(item_count < 1 || item_proto->MaxCount && item_count > item_proto->MaxCount)
-        {
-            PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, item_count,item_id);
-            SetSentErrorMessage(true);
-            return false;
-        }
-
-        while(item_count > item_proto->Stackable)
-        {
-            items.push_back(ItemPair(item_id,item_proto->Stackable));
-            item_count -= item_proto->Stackable;
-        }
-
-        items.push_back(ItemPair(item_id,item_count));
-
-        if(items.size() > MAX_MAIL_ITEMS)
-        {
-            PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
-            SetSentErrorMessage(true);
-            return false;
-        }
-    }
-
     if(!normalizePlayerName(name))
     {
@@ -1981,28 +1927,14 @@
 
     uint32 mailId = objmgr.GenerateMailID();
-    uint32 sender_guidlo = m_session->GetPlayer()->GetGUIDLow();
+    // from console show not existed sender
+    uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
+
     uint32 messagetype = MAIL_NORMAL;
     uint32 stationery = MAIL_STATIONERY_GM;
-    uint32 itemTextId = 0;
-    if (!text.empty())
-    {
-        itemTextId = objmgr.CreateItemText( text );
-    }
+    uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
 
     Player *receiver = objmgr.GetPlayer(receiver_guid);
 
-    // fill mail
-    MailItemsInfo mi;                                       // item list preparing
-
-    for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
-    {
-        if(Item* item = Item::CreateItem(itr->first,itr->second,m_session->GetPlayer()))
-        {
-            item->SaveToDB();                               // save for prevent lost at next mail load, if send fail then item will deleted
-            mi.AddItem(item->GetGUIDLow(), item->GetEntry(), item);
-        }
-    }
-
-    WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
+    WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_NONE);
 
     PSendSysMessage(LANG_MAIL_SENT, name.c_str());
Index: /trunk/src/game/WorldSocket.cpp
===================================================================
--- /trunk/src/game/WorldSocket.cpp (revision 229)
+++ /trunk/src/game/WorldSocket.cpp (revision 232)
@@ -463,5 +463,5 @@
         if (m_Header.space () > 0)
         {
-            //need to recieve the header
+            //need to receive the header
             const size_t to_header = (message_block.length () > m_Header.space () ? m_Header.space () : message_block.length ());
             m_Header.copy (message_block.rd_ptr (), to_header);
@@ -470,5 +470,5 @@
             if (m_Header.space () > 0)
             {
-                //couldn't recieve the whole header this time
+                // Couldn't receive the whole header this time
                 ACE_ASSERT (message_block.length () == 0);
                 errno = EWOULDBLOCK;
@@ -476,5 +476,5 @@
             }
 
-          //we just recieved nice new header
+          // We just received nice new header
             if (handle_input_header () == -1)
             {
@@ -485,14 +485,14 @@
 
         // Its possible on some error situations that this happens
-        // for example on closing when epoll recieves more chunked data and stuff
+        // for example on closing when epoll receives more chunked data and stuff
         // hope this is not hack ,as proper m_RecvWPct is asserted around
         if (!m_RecvWPct)
         {
-            sLog.outError ("Forsing close on input m_RecvWPct = NULL");
+            sLog.outError ("Forcing close on input m_RecvWPct = NULL");
             errno = EINVAL;
             return -1;
         }
 
-        // We have full readed header, now check the data payload
+        // We have full read header, now check the data payload
         if (m_RecvPct.space () > 0)
         {
@@ -504,5 +504,5 @@
             if (m_RecvPct.space () > 0)
             {
-                //couldn't recieve the whole data this time
+                //couldn't receive the whole data this time
                 ACE_ASSERT (message_block.length () == 0);
                 errno = EWOULDBLOCK;
@@ -511,5 +511,5 @@
         }
 
-        //just recieved fresh new payload
+        //just received fresh new payload
         if (handle_input_payload () == -1)
         {
@@ -573,5 +573,5 @@
         return -1;
 
-    // dump recieved packet
+    // Dump received packet
     if (sWorldLog.LogWorld ())
     {
@@ -638,5 +638,5 @@
 int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
 {
-    // NOTE: ATM the socket is singlethreaded, have this in mind ...
+    // NOTE: ATM the socket is singlethread, have this in mind ...
     uint8 digest[20];
     uint32 clientSeed;
@@ -930,5 +930,5 @@
                 {
                     sLog.outError  ("WorldSocket::HandlePing: Player kicked for "
-                                    "overspeeded pings adress = %s",
+                                    "over-speed pings address = %s",
                                     GetRemoteAddress ().c_str ());
 
@@ -951,5 +951,5 @@
             sLog.outError ("WorldSocket::HandlePing: peer sent CMSG_PING, "
                             "but is not authenticated or got recently kicked,"
-                            " adress = %s",
+                            " address = %s",
                             GetRemoteAddress ().c_str ());
              return -1;
Index: /trunk/src/game/MiscHandler.cpp
===================================================================
--- /trunk/src/game/MiscHandler.cpp (revision 230)
+++ /trunk/src/game/MiscHandler.cpp (revision 232)
@@ -500,5 +500,5 @@
 
     WorldSession * session = sWorld.FindSession(accountId);
-    if(!session)
+    if(!session || !session->GetPlayer())
         return;
 
@@ -583,5 +583,5 @@
 
     WorldSession * session = sWorld.FindSession(accountId);
-    if(!session)
+    if(!session || !session->GetPlayer())
         return;
 
Index: /trunk/src/game/Unit.cpp
===================================================================
--- /trunk/src/game/Unit.cpp (revision 231)
+++ /trunk/src/game/Unit.cpp (revision 232)
@@ -7333,5 +7333,5 @@
     AuraList const& mModDamagePercentTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN);
     for(AuraList::const_iterator i = mModDamagePercentTaken.begin(); i != mModDamagePercentTaken.end(); ++i)
-        if( (*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spellProto) )
+        if((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spellProto))
             TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f;
 
@@ -8233,5 +8233,5 @@
     AuraList const& mDamageTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN);
     for(AuraList::const_iterator i = mDamageTaken.begin();i != mDamageTaken.end(); ++i)
-        if((*i)->GetModifier()->m_miscvalue & SPELL_SCHOOL_MASK_NORMAL)
+        if((*i)->GetModifier()->m_miscvalue & GetMeleeDamageSchoolMask())
             TakenFlatBenefit += (*i)->GetModifier()->m_amount;
 
@@ -8257,5 +8257,5 @@
     AuraList const& mModDamagePercentTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN);
     for(AuraList::const_iterator i = mModDamagePercentTaken.begin(); i != mModDamagePercentTaken.end(); ++i)
-        if((*i)->GetModifier()->m_miscvalue & SPELL_SCHOOL_MASK_NORMAL)
+        if((*i)->GetModifier()->m_miscvalue & GetMeleeDamageSchoolMask())
             TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f;
 
Index: /trunk/sql/updates/240_world.sql
===================================================================
--- /trunk/sql/updates/240_world.sql (revision 232)
+++ /trunk/sql/updates/240_world.sql (revision 232)
@@ -0,0 +1,5 @@
+delete from `command` where `name` IN ('senditems','sendmail');
+insert into `command` (`name`, `security`, `help`) values
+('senditems',3,'Syntax: .senditems #playername "#subject" "#text" itemid1[:count1] itemid2[:count2] ... itemidN[:countN]\r\n\r\nSend a mail to a player. Subject and mail text must be in "". If for itemid not provided related count values then expected 1, if count > max items in stack then items will be send in required amount stacks. All stacks amount in mail limited to 12.'),
+('sendmail',1,'Syntax: .sendmail #playername "#subject" "#text"\r\n\r\nSend a mail to a player. Subject and mail text must be in "".');
+ 
