Index: trunk/src/game/PetHandler.cpp
===================================================================
--- trunk/src/game/PetHandler.cpp (revision 135)
+++ trunk/src/game/PetHandler.cpp (revision 152)
@@ -11,10 +11,10 @@
  * 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
+ * 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
@@ -379,5 +379,5 @@
 void WorldSession::HandlePetRename( WorldPacket & recv_data )
 {
-    CHECK_PACKET_SIZE(recv_data,8+1+1+1+1+1+1+1);
+    CHECK_PACKET_SIZE(recv_data, 8+1);
 
     sLog.outDetail( "HandlePetRename. CMSG_PET_RENAME\n" );
@@ -391,4 +391,5 @@
     recv_data >> petguid;
     recv_data >> name;
+    CHECK_PACKET_SIZE(recv_data, recv_data.rpos() + 1);
     recv_data >> isdeclined;
 
@@ -400,9 +401,16 @@
         return;
 
-    if((!ObjectMgr::IsValidPetName(name)) || (objmgr.IsReservedName(name)))
-    {
-        SendNotification(LANG_PET_INVALID_NAME);
-        return;
-    }
+    if(!ObjectMgr::IsValidPetName(name))
+    {
+        SendPetNameInvalid(PET_NAME_INVALID, name, NULL);
+        return;
+    }
+
+    if(objmgr.IsReservedName(name))
+    {
+        SendPetNameInvalid(PET_NAME_RESERVED, name, NULL);
+        return;
+    }
+
     pet->SetName(name);
 
@@ -416,11 +424,14 @@
     {
         for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
+        {
+            CHECK_PACKET_SIZE(recv_data, recv_data.rpos() + 1);
             recv_data >> declinedname.name[i];
+        }
 
         std::wstring wname;
-        Utf8toWStr(name,wname);
+        Utf8toWStr(name, wname);
         if(!ObjectMgr::CheckDeclinedNames(GetMainPartOfName(wname,0),declinedname))
         {
-            SendNotification(LANG_PET_INVALID_NAME);
+            SendPetNameInvalid(PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME, name, &declinedname);
             return;
         }
@@ -434,9 +445,9 @@
         CharacterDatabase.PExecute("DELETE FROM character_pet_declinedname WHERE owner = '%u' AND id = '%u'", _player->GetGUIDLow(), pet->GetCharmInfo()->GetPetNumber());
         CharacterDatabase.PExecute("INSERT INTO character_pet_declinedname (id, owner, genitive, dative, accusative, instrumental, prepositional) VALUES ('%u','%u','%s','%s','%s','%s','%s')",
-            pet->GetCharmInfo()->GetPetNumber(), _player->GetGUIDLow(), declinedname.name[0].c_str(),declinedname.name[1].c_str(),declinedname.name[2].c_str(),declinedname.name[3].c_str(),declinedname.name[4].c_str());
+            pet->GetCharmInfo()->GetPetNumber(), _player->GetGUIDLow(), declinedname.name[0].c_str(), declinedname.name[1].c_str(), declinedname.name[2].c_str(), declinedname.name[3].c_str(), declinedname.name[4].c_str());
     }
 
     CharacterDatabase.escape_string(name);
-    CharacterDatabase.PExecute("UPDATE character_pet SET name = '%s', renamed = '1' WHERE owner = '%u' AND id = '%u'", name.c_str(),_player->GetGUIDLow(),pet->GetCharmInfo()->GetPetNumber() );
+    CharacterDatabase.PExecute("UPDATE character_pet SET name = '%s', renamed = '1' WHERE owner = '%u' AND id = '%u'", name.c_str(), _player->GetGUIDLow(), pet->GetCharmInfo()->GetPetNumber());
     CharacterDatabase.CommitTransaction();
 
@@ -446,5 +457,5 @@
 void WorldSession::HandlePetAbandon( WorldPacket & recv_data )
 {
-    CHECK_PACKET_SIZE(recv_data,8);
+    CHECK_PACKET_SIZE(recv_data, 8);
 
     uint64 guid;
@@ -453,5 +464,5 @@
 
     // pet/charmed
-    Creature* pet=ObjectAccessor::GetCreatureOrPet(*_player, guid);
+    Creature* pet = ObjectAccessor::GetCreatureOrPet(*_player, guid);
     if(pet)
     {
@@ -581,5 +592,5 @@
 }
 
-void WorldSession::HandleAddDynamicTargetObsoleteOpcode( WorldPacket& recvPacket )
+void WorldSession::HandlePetCastSpellOpcode( WorldPacket& recvPacket )
 {
     sLog.outDetail("WORLD: CMSG_PET_CAST_SPELL");
@@ -601,5 +612,5 @@
     if(!pet || (pet != _player->GetPet() && pet!= _player->GetCharm()))
     {
-        sLog.outError( "HandleAddDynamicTargetObsoleteOpcode.Pet %u isn't pet of player %s .\n", uint32(GUID_LOPART(guid)),GetPlayer()->GetName() );
+        sLog.outError( "HandlePetCastSpellOpcode: Pet %u isn't pet of player %s .\n", uint32(GUID_LOPART(guid)),GetPlayer()->GetName() );
         return;
     }
@@ -656,2 +667,18 @@
     }
 }
+
+void WorldSession::SendPetNameInvalid(uint32 error, std::string name, DeclinedName *declinedName)
+{
+    WorldPacket data(SMSG_PET_NAME_INVALID, 4 + name.size() + 1 + 1);
+    data << uint32(error);
+    data << name;
+    if(declinedName)
+    {
+        data << uint8(1);
+        for(uint32 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
+            data << declinedName->name[i];
+    }
+    else
+        data << uint8(0);
+    SendPacket(&data);
+}
Index: trunk/src/game/Pet.h
===================================================================
--- trunk/src/game/Pet.h (revision 126)
+++ trunk/src/game/Pet.h (revision 152)
@@ -97,4 +97,21 @@
     PET_TALK_SPECIAL_SPELL  = 0,
     PET_TALK_ATTACK         = 1
+};
+
+enum PetNameInvalidReason
+{
+    PET_NAME_INVALID                                        = 1,
+    PET_NAME_NO_NAME                                        = 2,
+    PET_NAME_TOO_SHORT                                      = 3,
+    PET_NAME_TOO_LONG                                       = 4,
+    PET_NAME_MIXED_LANGUAGES                                = 6,
+    PET_NAME_PROFANE                                        = 7,
+    PET_NAME_RESERVED                                       = 8,
+    PET_NAME_THREE_CONSECUTIVE                              = 11,
+    PET_NAME_INVALID_SPACE                                  = 12,
+    PET_NAME_CONSECUTIVE_SPACES                             = 13,
+    PET_NAME_RUSSIAN_CONSECUTIVE_SILENT_CHARACTERS          = 14,
+    PET_NAME_RUSSIAN_SILENT_CHARACTER_AT_BEGINNING_OR_END   = 15,
+    PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME              = 16
 };
 
Index: trunk/src/game/WorldSession.h
===================================================================
--- trunk/src/game/WorldSession.h (revision 112)
+++ trunk/src/game/WorldSession.h (revision 152)
@@ -31,4 +31,5 @@
 struct ItemPrototype;
 struct AuctionEntry;
+struct DeclinedName;
 
 class Creature;
@@ -83,4 +84,5 @@
         void SendNotification(const char *format,...) ATTR_PRINTF(2,3);
         void SendNotification(int32 string_id,...);
+        void SendPetNameInvalid(uint32 error, std::string name, DeclinedName *declinedName);
         void SendLfgResult(uint32 type, uint32 entry, uint8 lfg_type);
         void SendPartyResult(PartyOperation operation, std::string member, PartyResult res);
@@ -89,5 +91,4 @@
         uint32 GetSecurity() const { return _security; }
         uint32 GetAccountId() const { return _accountId; }
-        //std::string const& GetRemoteAddress() const { return m_remoteaddress; }
         Player* GetPlayer() const { return _player; }
         char const* GetPlayerName() const;
@@ -117,5 +118,5 @@
         void QueuePacket(WorldPacket* new_packet);
         bool Update(uint32 diff);
-        
+
         /// Handle the authentication waiting queue (to be completed)
         void SendAuthWaitQue(uint32 position);
@@ -534,5 +535,5 @@
         void HandlePetUnlearnOpcode( WorldPacket& recvPacket );
         void HandlePetSpellAutocastOpcode( WorldPacket& recvPacket );
-        void HandleAddDynamicTargetObsoleteOpcode( WorldPacket& recvPacket );
+        void HandlePetCastSpellOpcode( WorldPacket& recvPacket );
 
         void HandleSetActionBar(WorldPacket& recv_data);
Index: trunk/src/game/Pet.cpp
===================================================================
--- trunk/src/game/Pet.cpp (revision 149)
+++ trunk/src/game/Pet.cpp (revision 152)
@@ -11,10 +11,10 @@
  * 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
+ * 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
@@ -189,5 +189,6 @@
     if(!IsPositionValid())
     {
-        sLog.outError("ERROR: Pet (guidlow %d, entry %d) not loaded. Suggested coordinates isn't valid (X: %d Y: ^%d)", GetGUIDLow(), GetEntry(), GetPositionX(), GetPositionY());
+        sLog.outError("ERROR: Pet (guidlow %d, entry %d) not loaded. Suggested coordinates isn't valid (X: %f Y: %f)",
+            GetGUIDLow(), GetEntry(), GetPositionX(), GetPositionY());
         delete result;
         return false;
@@ -206,5 +207,5 @@
         return true;
     }
-    if(getPetType()==HUNTER_PET || getPetType()==SUMMON_PET && cinfo->type == CREATURE_TYPE_DEMON && owner->getClass() == CLASS_WARLOCK)
+    if(getPetType()==HUNTER_PET || (getPetType()==SUMMON_PET && cinfo->type == CREATURE_TYPE_DEMON && owner->getClass() == CLASS_WARLOCK))
         m_charmInfo->SetPetNumber(pet_number, true);
     else
@@ -1219,5 +1220,5 @@
         WorldPacket data(SMSG_SPELL_COOLDOWN, (8+1+result->GetRowCount()*8));
         data << GetGUID();
-        data << uint8(0x0);
+        data << uint8(0x0);                                 // flags (0x1, 0x2)
 
         do
@@ -1367,7 +1368,7 @@
                 remaincharges = -1;
 
-			/// do not load single target auras (unless they were cast by the player)
-			if (caster_guid != GetGUID() && IsSingleTargetSpell(spellproto))
-				continue;
+            /// do not load single target auras (unless they were cast by the player)
+            if (caster_guid != GetGUID() && IsSingleTargetSpell(spellproto))
+                continue;
 
             Aura* aura = CreateAura(spellproto, effindex, NULL, this, NULL);
@@ -1401,16 +1402,16 @@
 
         if (i != 3)
-			continue;
-
-		if(itr->second->IsPassive())
-			continue;
-
-		/// do not save single target auras (unless they were cast by the player)
-		if (itr->second->GetCasterGUID() != GetGUID() && IsSingleTargetSpell(spellInfo))
-			continue;
-
-		CharacterDatabase.PExecute("INSERT INTO pet_aura (guid,caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges) "
-			"VALUES ('%u', '" I64FMTD "', '%u', '%u', '%d', '%d', '%d', '%d')",
-			m_charmInfo->GetPetNumber(), itr->second->GetCasterGUID(),(uint32)(*itr).second->GetId(), (uint32)(*itr).second->GetEffIndex(),(*itr).second->GetModifier()->m_amount,int((*itr).second->GetAuraMaxDuration()),int((*itr).second->GetAuraDuration()),int((*itr).second->m_procCharges));
+            continue;
+        
+        if(itr->second->IsPassive())
+            continue;
+
+        /// do not save single target auras (unless they were cast by the player)
+        if (itr->second->GetCasterGUID() != GetGUID() && IsSingleTargetSpell(spellInfo))
+            continue;
+
+        CharacterDatabase.PExecute("INSERT INTO pet_aura (guid,caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges) "
+            "VALUES ('%u', '" I64FMTD "', '%u', '%u', '%d', '%d', '%d', '%d')",
+            m_charmInfo->GetPetNumber(), itr->second->GetCasterGUID(),(uint32)(*itr).second->GetId(), (uint32)(*itr).second->GetEffIndex(),(*itr).second->GetModifier()->m_amount,int((*itr).second->GetAuraMaxDuration()),int((*itr).second->GetAuraDuration()),int((*itr).second->m_procCharges));
     }
 }
Index: trunk/src/game/Opcodes.cpp
===================================================================
--- trunk/src/game/Opcodes.cpp (revision 102)
+++ trunk/src/game/Opcodes.cpp (revision 152)
@@ -11,10 +11,10 @@
  * 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
+ * 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
@@ -314,5 +314,4 @@
     /*0x11B*/ { "CMSG_UNACCEPT_TRADE",              STATUS_LOGGEDIN, &WorldSession::HandleUnacceptTradeOpcode       },
     /*0x11C*/ { "CMSG_CANCEL_TRADE",                STATUS_AUTHED,   &WorldSession::HandleCancelTradeOpcode         },
-                                                            // also send after logout complete
     /*0x11D*/ { "CMSG_SET_TRADE_ITEM",              STATUS_LOGGEDIN, &WorldSession::HandleSetTradeItemOpcode        },
     /*0x11E*/ { "CMSG_CLEAR_TRADE_ITEM",            STATUS_LOGGEDIN, &WorldSession::HandleClearTradeItemOpcode      },
@@ -526,5 +525,5 @@
     /*0x1EE*/ { "SMSG_AUTH_RESPONSE",               STATUS_NEVER,    &WorldSession::Handle_ServerSide               },
     /*0x1EF*/ { "MSG_GM_SHOWLABEL",                 STATUS_NEVER,    &WorldSession::Handle_NULL                     },
-    /*0x1F0*/ { "CMSG_PET_CAST_SPELL",              STATUS_LOGGEDIN, &WorldSession::HandleAddDynamicTargetObsoleteOpcode},
+    /*0x1F0*/ { "CMSG_PET_CAST_SPELL",              STATUS_LOGGEDIN, &WorldSession::HandlePetCastSpellOpcode        },
     /*0x1F1*/ { "MSG_SAVE_GUILD_EMBLEM",            STATUS_LOGGEDIN, &WorldSession::HandleGuildSaveEmblemOpcode     },
     /*0x1F2*/ { "MSG_TABARDVENDOR_ACTIVATE",        STATUS_LOGGEDIN, &WorldSession::HandleTabardVendorActivateOpcode},
Index: trunk/src/bindings/scripts/ScriptMgr.cpp
===================================================================
--- trunk/src/bindings/scripts/ScriptMgr.cpp (revision 150)
+++ trunk/src/bindings/scripts/ScriptMgr.cpp (revision 152)
@@ -1839,6 +1839,6 @@
 //*** Functions used internally ***
 
-Trinity_DLL_EXPORT
-const char* ScriptsVersion()
+TRINITY_DLL_EXPORT
+char const* ScriptsVersion()
 {
 	return "Default Trinity scripting library";
