Index: trunk/src/game/Bag.cpp
===================================================================
--- trunk/src/game/Bag.cpp (revision 102)
+++ trunk/src/game/Bag.cpp (revision 177)
@@ -40,8 +40,7 @@
 Bag::~Bag()
 {
-    for(int i = 0; i<MAX_BAG_SIZE; i++)
-    {
-        if(m_bagslot[i])    delete m_bagslot[i];
-    }
+    for(int i = 0; i < MAX_BAG_SIZE; ++i)
+        if (m_bagslot[i])
+             delete m_bagslot[i];
 }
 
@@ -50,18 +49,14 @@
     Item::AddToWorld();
 
-    for(int i = 0; i<MAX_BAG_SIZE; i++)
-    {
+    for(uint32 i = 0;  i < GetBagSize(); ++i)
         if(m_bagslot[i])
             m_bagslot[i]->AddToWorld();
-    }
 }
 
 void Bag::RemoveFromWorld()
 {
-    for(int i = 0; i<MAX_BAG_SIZE; i++)
-    {
+    for(uint32 i = 0; i < GetBagSize(); ++i)
         if(m_bagslot[i])
             m_bagslot[i]->RemoveFromWorld();
-    }
 
     Item::RemoveFromWorld();
@@ -112,5 +107,5 @@
 
     // cleanup bag content related item value fields (its will be filled correctly from `character_inventory`)
-    for (uint32 i = 0; i < GetProto()->ContainerSlots; i++)
+    for (int i = 0; i < MAX_BAG_SIZE; ++i)
     {
         SetUInt64Value(CONTAINER_FIELD_SLOT_1 + (i*2), 0);
@@ -128,10 +123,6 @@
 {
     for (int i = 0; i < MAX_BAG_SIZE; i++)
-    {
-        if (m_bagslot[i])
-        {
+        if (m_bagslot[i])
             m_bagslot[i]->DeleteFromDB();
-        }
-    }
 
     Item::DeleteFromDB();
@@ -140,7 +131,6 @@
 uint32 Bag::GetFreeSlots() const
 {
-    uint32 ContainerSlots=GetProto()->ContainerSlots;
     uint32 slots = 0;
-    for (uint8 i=0; i <ContainerSlots; i++)
+    for (uint32 i=0; i < GetBagSize(); i++)
         if (!m_bagslot[i])
             ++slots;
@@ -179,9 +169,7 @@
     Item::BuildCreateUpdateBlockForPlayer( data, target );
 
-    for (int i = 0; i < MAX_BAG_SIZE; i++)
-    {
+    for (uint32 i = 0; i < GetBagSize(); ++i)
         if(m_bagslot[i])
             m_bagslot[i]->BuildCreateUpdateBlockForPlayer( data, target );
-    }
 }
 
@@ -189,7 +177,7 @@
 bool Bag::IsEmpty() const
 {
-    uint32 ContainerSlots=GetProto()->ContainerSlots;
-    for(uint32 i=0; i < ContainerSlots; i++)
-        if (m_bagslot[i]) return false;
+    for(uint32 i = 0; i < GetBagSize(); ++i)
+        if (m_bagslot[i])
+            return false;
 
     return true;
@@ -198,9 +186,7 @@
 uint32 Bag::GetItemCount( uint32 item, Item* eItem ) const
 {
-    uint32 ContainerSlots=GetProto()->ContainerSlots;
-
     Item *pItem;
     uint32 count = 0;
-    for(uint32 i=0; i < ContainerSlots; i++)
+    for(uint32 i=0; i < GetBagSize(); ++i)
     {
         pItem = m_bagslot[i];
@@ -211,5 +197,5 @@
     if(eItem && eItem->GetProto()->GemProperties)
     {
-        for(uint32 i=0; i < ContainerSlots; i++)
+        for(uint32 i=0; i < GetBagSize(); ++i)
         {
             pItem = m_bagslot[i];
@@ -224,28 +210,16 @@
 uint8 Bag::GetSlotByItemGUID(uint64 guid) const
 {
-    uint32 ContainerSlots=GetProto()->ContainerSlots;
-
-    for(uint32 i=0;i<ContainerSlots;i++)
-    {
+    for(uint32 i = 0; i < GetBagSize(); ++i)
         if(m_bagslot[i] != 0)
             if(m_bagslot[i]->GetGUID() == guid)
                 return i;
-    }
     return NULL_SLOT;
 }
 
-// Adds an item to a bag slot
-// - slot can be NULL_SLOT, in that case function searchs for a free slot
-// - Return values: 0 - item not added
-//                  1 - item added to a free slot (and perhaps to a stack)
-//                  2 - item added to a stack (item should be deleted)
 Item* Bag::GetItemByPos( uint8 slot ) const
 {
-    ItemPrototype const *pBagProto = GetProto();
-    if( pBagProto )
-    {
-        if( slot < pBagProto->ContainerSlots )
-            return m_bagslot[slot];
-    }
+    if( slot < GetBagSize() )
+        return m_bagslot[slot];
+        
     return NULL;
 }
Index: trunk/src/game/Level3.cpp
===================================================================
--- trunk/src/game/Level3.cpp (revision 174)
+++ trunk/src/game/Level3.cpp (revision 177)
@@ -3657,5 +3657,5 @@
 
 //play npc emote
-bool ChatHandler::HandlePlayEmoteCommand(const char* args)
+bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args)
 {
     uint32 emote = atoi((char*)args);
@@ -5565,5 +5565,5 @@
 }
 
-bool ChatHandler::HandleChangeEntryCommand(const char *args)
+bool ChatHandler::HandleNpcChangeEntryCommand(const char *args)
 {
     if(!args)
Index: trunk/src/game/Chat.cpp
===================================================================
--- trunk/src/game/Chat.cpp (revision 174)
+++ trunk/src/game/Chat.cpp (revision 177)
@@ -379,26 +379,26 @@
     static ChatCommand npcCommandTable[] =
     {
-        { "say",            SEC_MODERATOR,      false, &ChatHandler::HandleSayCommand,                 "", NULL },
-		{ "whisper",        SEC_MODERATOR,      false, &ChatHandler::HandleNpcWhisperCommand,          "", NULL },
-		{ "yell",           SEC_MODERATOR,      false, &ChatHandler::HandleYellCommand,                "", NULL },
-		{ "textemote",      SEC_MODERATOR,      false, &ChatHandler::HandleTextEmoteCommand,           "", NULL },
-		{ "add",            SEC_GAMEMASTER,     false, &ChatHandler::HandleAddSpwCommand,              "", NULL },
-		{ "delete",         SEC_GAMEMASTER,     false, &ChatHandler::HandleDelCreatureCommand,         "", NULL },
-		{ "spawndist",      SEC_GAMEMASTER,     false, &ChatHandler::HandleSpawnDistCommand,           "", NULL },
-		{ "spawntime",      SEC_GAMEMASTER,     false, &ChatHandler::HandleSpawnTimeCommand,           "", NULL },
-		{ "factionid",      SEC_GAMEMASTER,     false, &ChatHandler::HandleFactionIdCommand,           "", NULL },
-		{ "addmove",        SEC_GAMEMASTER,     false, &ChatHandler::HandleAddMoveCommand,             "", NULL },
-		{ "setmovetype",    SEC_GAMEMASTER,     false, &ChatHandler::HandleSetMoveTypeCommand,         "", NULL },
-		{ "move",           SEC_GAMEMASTER,     false, &ChatHandler::HandleMoveCreatureCommand,        "", NULL },
-		{ "changelevel",    SEC_GAMEMASTER,     false, &ChatHandler::HandleChangeLevelCommand,         "", NULL },
-		{ "setmodel",       SEC_GAMEMASTER,     false, &ChatHandler::HandleSetModelCommand,            "", NULL },
-		{ "additem",        SEC_GAMEMASTER,     false, &ChatHandler::HandleAddVendorItemCommand,       "", NULL },
-		{ "delitem",        SEC_GAMEMASTER,     false, &ChatHandler::HandleDelVendorItemCommand,       "", NULL },
-		{ "flag",           SEC_GAMEMASTER,     false, &ChatHandler::HandleNPCFlagCommand,             "", NULL },
-		{ "changeentry",    SEC_ADMINISTRATOR,  false, &ChatHandler::HandleChangeEntryCommand,         "", NULL },
-		{ "info",           SEC_ADMINISTRATOR,  false, &ChatHandler::HandleNpcInfoCommand,             "", NULL },
-		{ "playemote",      SEC_ADMINISTRATOR,  false, &ChatHandler::HandlePlayEmoteCommand,           "", NULL },
+        { "say",            SEC_MODERATOR,      false, &ChatHandler::HandleNpcSayCommand,              "", NULL },
+        { "textemote",      SEC_MODERATOR,      false, &ChatHandler::HandleNpcTextEmoteCommand,        "", NULL },
+        { "add",            SEC_GAMEMASTER,     false, &ChatHandler::HandleNpcAddCommand,              "", NULL },
+        { "delete",         SEC_GAMEMASTER,     false, &ChatHandler::HandleNpcDeleteCommand,           "", NULL },
+        { "spawndist",      SEC_GAMEMASTER,     false, &ChatHandler::HandleNpcSpawnDistCommand,        "", NULL },
+        { "spawntime",      SEC_GAMEMASTER,     false, &ChatHandler::HandleNpcSpawnTimeCommand,        "", NULL },
+        { "factionid",      SEC_GAMEMASTER,     false, &ChatHandler::HandleNpcFactionIdCommand,        "", NULL },
+        { "addmove",        SEC_GAMEMASTER,     false, &ChatHandler::HandleNpcAddMoveCommand,          "", NULL },
+        { "setmovetype",    SEC_GAMEMASTER,     false, &ChatHandler::HandleNpcSetMoveTypeCommand,      "", NULL },
+        { "move",           SEC_GAMEMASTER,     false, &ChatHandler::HandleNpcMoveCommand,             "", NULL },
+        { "changelevel",    SEC_GAMEMASTER,     false, &ChatHandler::HandleChangeLevelCommand,         "", NULL },
+        { "setmodel",       SEC_GAMEMASTER,     false, &ChatHandler::HandleNpcSetModelCommand,         "", NULL },
+        { "additem",        SEC_GAMEMASTER,     false, &ChatHandler::HandleAddVendorItemCommand,       "", NULL },
+        { "delitem",        SEC_GAMEMASTER,     false, &ChatHandler::HandleDelVendorItemCommand,       "", NULL },
+        { "flag",           SEC_GAMEMASTER,     false, &ChatHandler::HandleNpcFlagCommand,             "", NULL },
+        { "changeentry",    SEC_ADMINISTRATOR,  false, &ChatHandler::HandleNpcChangeEntryCommand,      "", NULL },
+        { "info",           SEC_ADMINISTRATOR,  false, &ChatHandler::HandleNpcInfoCommand,             "", NULL },
+        { "playemote",      SEC_ADMINISTRATOR,  false, &ChatHandler::HandleNpcPlayEmoteCommand,        "", NULL },
         { "follow",         SEC_GAMEMASTER,     false, &ChatHandler::HandleNpcFollowCommand,           "", NULL },
         { "unfollow",       SEC_GAMEMASTER,     false, &ChatHandler::HandleNpcUnFollowCommand,         "", NULL },
+        { "whisper",        SEC_MODERATOR,      false, &ChatHandler::HandleNpcWhisperCommand,          "", NULL },
+        { "yell",           SEC_MODERATOR,      false, &ChatHandler::HandleNpcYellCommand,             "", NULL },
 
         //{ TODO: fix or remove this commands
Index: trunk/src/game/Bag.h
===================================================================
--- trunk/src/game/Bag.h (revision 102)
+++ trunk/src/game/Bag.h (revision 177)
@@ -53,4 +53,5 @@
         bool IsEmpty() const;
         uint32 GetFreeSlots() const;
+        uint32 GetBagSize() const { return GetUInt32Value(CONTAINER_FIELD_NUM_SLOTS); }
 
         // DB operations
Index: trunk/src/game/Guild.h
===================================================================
--- trunk/src/game/Guild.h (revision 173)
+++ trunk/src/game/Guild.h (revision 177)
@@ -328,4 +328,8 @@
         }
         int32 GetRank(uint32 LowGuid);
+        bool IsMember(uint32 LowGuid)
+        {
+            return (members.find(LowGuid) != members.end());
+        }
 
         void Roster(WorldSession *session);
Index: trunk/src/game/Language.h
===================================================================
--- trunk/src/game/Language.h (revision 163)
+++ trunk/src/game/Language.h (revision 177)
@@ -698,6 +698,6 @@
 
 	// Level 3 (continue)
-    LANG_MOTD_NEW                       = 1100,
-    LANG_ACCOUNT_SETADDON               = 1101,
+    LANG_ACCOUNT_SETADDON               = 1100,
+    LANG_MOTD_NEW                       = 1101,
     LANG_SENDMESSAGE                    = 1102,
     LANG_EVENT_ENTRY_LIST_CONSOLE       = 1103,
Index: trunk/src/game/Chat.h
===================================================================
--- trunk/src/game/Chat.h (revision 174)
+++ trunk/src/game/Chat.h (revision 177)
@@ -118,8 +118,4 @@
         bool HandleTaxiCheatCommand(const char* args);
         bool HandleWhispersCommand(const char* args);
-        bool HandleSayCommand(const char* args);
-        bool HandleNpcWhisperCommand(const char* args);
-        bool HandleYellCommand(const char* args);
-        bool HandlePlayEmoteCommand(const char* args);
         bool HandleSendMailCommand(const char* args);
         bool HandleNameTeleCommand(const char* args);
@@ -131,4 +127,30 @@
         bool HandleEventStopCommand(const char* args);
         bool HandleEventInfoCommand(const char* args);
+
+        bool HandleLearnCommand(const char* args);
+        bool HandleLearnAllCommand(const char* args);
+        bool HandleLearnAllGMCommand(const char* args);
+        bool HandleLearnAllCraftsCommand(const char* args);
+        bool HandleLearnAllRecipesCommand(const char* args);
+        bool HandleLearnAllDefaultCommand(const char* args);
+        bool HandleLearnAllLangCommand(const char* args);
+        bool HandleLearnAllMyClassCommand(const char* args);
+        bool HandleLearnAllMySpellsCommand(const char* args);
+        bool HandleLearnAllMyTalentsCommand(const char* args);
+
+        bool HandleLookupAreaCommand(const char* args);
+        bool HandleLookupCreatureCommand(const char* args);
+        bool HandleLookupEventCommand(const char* args);
+        bool HandleLookupFactionCommand(const char * args);
+        bool HandleLookupItemCommand(const char * args);
+        bool HandleLookupItemSetCommand(const char * args);
+        bool HandleLookupObjectCommand(const char* args);
+        bool HandleLookupPlayerIpCommand(const char* args);
+        bool HandleLookupPlayerAccountCommand(const char* args);
+        bool HandleLookupPlayerEmailCommand(const char* args);
+        bool HandleLookupQuestCommand(const char* args);
+        bool HandleLookupSkillCommand(const char* args);
+        bool HandleLookupSpellCommand(const char* args);
+        bool HandleLookupTeleCommand(const char * args);
 
         bool HandleModifyKnownTitlesCommand(const char* args);
@@ -152,7 +174,24 @@
         bool HandleModifyRepCommand(const char* args);
         bool HandleModifyArenaCommand(const char* args);
-        
+
+        bool HandleNpcAddCommand(const char* args);
+        bool HandleNpcAddMoveCommand(const char* args);
+        bool HandleNpcChangeEntryCommand(const char *args);
+        bool HandleNpcDeleteCommand(const char* args);
+        bool HandleNpcFactionIdCommand(const char* args);
+        bool HandleNpcFlagCommand(const char* args);
         bool HandleNpcFollowCommand(const char* args);
+        bool HandleNpcInfoCommand(const char* args);
+        bool HandleNpcMoveCommand(const char* args);
+        bool HandleNpcPlayEmoteCommand(const char* args);
+        bool HandleNpcSayCommand(const char* args);
+        bool HandleNpcSetModelCommand(const char* args);
+        bool HandleNpcSetMoveTypeCommand(const char* args);
+        bool HandleNpcSpawnDistCommand(const char* args);
+        bool HandleNpcSpawnTimeCommand(const char* args);
+        bool HandleNpcTextEmoteCommand(const char* args);
         bool HandleNpcUnFollowCommand(const char* args);
+        bool HandleNpcWhisperCommand(const char* args);
+        bool HandleNpcYellCommand(const char* args);
 
         bool HandleReloadCommand(const char* args);
@@ -250,19 +289,10 @@
         bool HandleSubNameCommand(const char* args);
         bool HandleItemMoveCommand(const char* args);
-        bool HandleDelCreatureCommand(const char* args);
         bool HandleDeMorphCommand(const char* args);
         bool HandleAddVendorItemCommand(const char* args);
         bool HandleDelVendorItemCommand(const char* args);
-        bool HandleAddMoveCommand(const char* args);
-        bool HandleSetMoveTypeCommand(const char* args);
         bool HandleChangeLevelCommand(const char* args);
         bool HandleSetPoiCommand(const char* args);
         bool HandleEquipErrorCommand(const char* args);
-        bool HandleNPCFlagCommand(const char* args);
-        bool HandleSetModelCommand(const char* args);
-        bool HandleFactionIdCommand(const char* args);
-        bool HandleAddSpwCommand(const char* args);
-        bool HandleSpawnDistCommand(const char* args);
-        bool HandleSpawnTimeCommand(const char* args);
         bool HandleGoCreatureCommand(const char* args);
         bool HandleGoObjectCommand(const char* args);
@@ -271,5 +301,4 @@
         bool HandleTargetObjectCommand(const char* args);
         bool HandleDelObjectCommand(const char* args);
-        bool HandleMoveCreatureCommand(const char* args);
         bool HandleMoveObjectCommand(const char* args);
         bool HandleTurnObjectCommand(const char* args);
@@ -310,30 +339,4 @@
         bool HandleGoCommand(const char* args);
 
-        bool HandleLearnCommand(const char* args);
-        bool HandleLearnAllCommand(const char* args);
-        bool HandleLearnAllGMCommand(const char* args);
-        bool HandleLearnAllCraftsCommand(const char* args);
-        bool HandleLearnAllRecipesCommand(const char* args);
-        bool HandleLearnAllDefaultCommand(const char* args);
-        bool HandleLearnAllLangCommand(const char* args);
-        bool HandleLearnAllMyClassCommand(const char* args);
-        bool HandleLearnAllMySpellsCommand(const char* args);
-        bool HandleLearnAllMyTalentsCommand(const char* args);
-
-        bool HandleLookupAreaCommand(const char* args);
-        bool HandleLookupCreatureCommand(const char* args);
-        bool HandleLookupEventCommand(const char* args);
-        bool HandleLookupFactionCommand(const char * args);
-        bool HandleLookupItemCommand(const char * args);
-        bool HandleLookupItemSetCommand(const char * args);
-        bool HandleLookupObjectCommand(const char* args);
-        bool HandleLookupPlayerIpCommand(const char* args);
-        bool HandleLookupPlayerAccountCommand(const char* args);
-        bool HandleLookupPlayerEmailCommand(const char* args);
-        bool HandleLookupQuestCommand(const char* args);
-        bool HandleLookupSkillCommand(const char* args);
-        bool HandleLookupSpellCommand(const char* args);
-        bool HandleLookupTeleCommand(const char * args);
-
         bool HandleCooldownCommand(const char* args);
         bool HandleUnLearnCommand(const char* args);
@@ -354,6 +357,4 @@
         bool HandleSpawnTransportCommand(const char* args);
         bool HandleExploreCheatCommand(const char* args);
-        bool HandleTextEmoteCommand(const char* args);
-        bool HandleNpcInfoCommand(const char* args);
         bool HandleHoverCommand(const char* args);
         bool HandleWaterwalkCommand(const char* args);
@@ -422,5 +423,4 @@
         bool HandleLoadPDumpCommand(const char *args);
         bool HandleWritePDumpCommand(const char *args);
-        bool HandleChangeEntryCommand(const char *args);
         bool HandleCastCommand(const char *args);
         bool HandleCastBackCommand(const char *args);
Index: trunk/src/game/Level1.cpp
===================================================================
--- trunk/src/game/Level1.cpp (revision 132)
+++ trunk/src/game/Level1.cpp (revision 177)
@@ -39,5 +39,5 @@
 #endif
 
-bool ChatHandler::HandleSayCommand(const char* args)
+bool ChatHandler::HandleNpcSayCommand(const char* args)
 {
     if(!*args)
@@ -57,5 +57,5 @@
 }
 
-bool ChatHandler::HandleYellCommand(const char* args)
+bool ChatHandler::HandleNpcYellCommand(const char* args)
 {
     if(!*args)
@@ -76,5 +76,5 @@
 
 //show text emote by creature in chat
-bool ChatHandler::HandleTextEmoteCommand(const char* args)
+bool ChatHandler::HandleNpcTextEmoteCommand(const char* args)
 {
     if(!*args)
Index: trunk/src/game/Player.h
===================================================================
--- trunk/src/game/Player.h (revision 174)
+++ trunk/src/game/Player.h (revision 177)
@@ -1606,4 +1606,6 @@
         void SendLogXPGain(uint32 GivenXP,Unit* victim,uint32 RestXP);
 
+		//Low Level Packets
+        void PlaySound(uint32 Sound, bool OnlySelf);
         //notifiers
         void SendAttackSwingCantAttack();
Index: trunk/src/game/debugcmds.cpp
===================================================================
--- trunk/src/game/debugcmds.cpp (revision 102)
+++ trunk/src/game/debugcmds.cpp (revision 177)
@@ -320,6 +320,5 @@
             {
                 Bag *bag = (Bag*)item;
-                const ItemPrototype *proto = bag->GetProto();
-                for (uint8 j = 0; j < proto->ContainerSlots; ++j)
+                for (uint8 j = 0; j < bag->GetBagSize(); ++j)
                 {
                     Item* item = bag->GetItemByPos(j);
@@ -417,6 +416,5 @@
             {
                 Bag *bag = (Bag*)item;
-                const ItemPrototype *proto = bag->GetProto();
-                for (uint8 j = 0; j < proto->ContainerSlots; ++j)
+                for (uint8 j = 0; j < bag->GetBagSize(); ++j)
                 {
                     Item* item = bag->GetItemByPos(j);
Index: trunk/src/game/Level2.cpp
===================================================================
--- trunk/src/game/Level2.cpp (revision 173)
+++ trunk/src/game/Level2.cpp (revision 177)
@@ -861,10 +861,10 @@
     dstslot = (uint8)atoi(pParam2);
 
+    if(srcslot==dstslot)
+        return true;
+        
     uint16 src = ((INVENTORY_SLOT_BAG_0 << 8) | srcslot);
     uint16 dst = ((INVENTORY_SLOT_BAG_0 << 8) | dstslot);
 
-    if(srcslot==dstslot)
-        return true;
-
     m_session->GetPlayer()->SwapItem( src, dst );
 
@@ -873,5 +873,5 @@
 
 //add spawn of creature
-bool ChatHandler::HandleAddSpwCommand(const char* args)
+bool ChatHandler::HandleNpcAddCommand(const char* args)
 {
     if(!*args)
@@ -923,5 +923,5 @@
 }
 
-bool ChatHandler::HandleDelCreatureCommand(const char* args)
+bool ChatHandler::HandleNpcDeleteCommand(const char* args)
 {
     Creature* unit = NULL;
@@ -1071,5 +1071,5 @@
 
 //move selected creature
-bool ChatHandler::HandleMoveCreatureCommand(const char* args)
+bool ChatHandler::HandleNpcMoveCommand(const char* args)
 {
     uint32 lowguid = 0;
@@ -1324,5 +1324,5 @@
 
 //add move for creature
-bool ChatHandler::HandleAddMoveCommand(const char* args)
+bool ChatHandler::HandleNpcAddMoveCommand(const char* args)
 {
     if(!*args)
@@ -1398,5 +1398,5 @@
  *                       change the movement type
  */
-bool ChatHandler::HandleSetMoveTypeCommand(const char* args)
+bool ChatHandler::HandleNpcSetMoveTypeCommand(const char* args)
 {
     if(!*args)
@@ -1526,5 +1526,5 @@
 
     return true;
-}                                                           // HandleSetMoveTypeCommand
+}                                                           // HandleNpcSetMoveTypeCommand
 
 //change level of creature or pet
@@ -1566,5 +1566,5 @@
 
 //set npcflag of creature
-bool ChatHandler::HandleNPCFlagCommand(const char* args)
+bool ChatHandler::HandleNpcFlagCommand(const char* args)
 {
     if (!*args)
@@ -1592,5 +1592,5 @@
 
 //set model of creature
-bool ChatHandler::HandleSetModelCommand(const char* args)
+bool ChatHandler::HandleNpcSetModelCommand(const char* args)
 {
     if (!*args)
@@ -1633,6 +1633,6 @@
 }
 
-//set faction of creature  or go
-bool ChatHandler::HandleFactionIdCommand(const char* args)
+//set faction of creature
+bool ChatHandler::HandleNpcFactionIdCommand(const char* args)
 {
     if (!*args)
@@ -2139,5 +2139,5 @@
 
 //set spawn dist of creature
-bool ChatHandler::HandleSpawnDistCommand(const char* args)
+bool ChatHandler::HandleNpcSpawnDistCommand(const char* args)
 {
     if(!*args)
@@ -2177,5 +2177,5 @@
 }
 
-bool ChatHandler::HandleSpawnTimeCommand(const char* args)
+bool ChatHandler::HandleNpcSpawnTimeCommand(const char* args)
 {
     if(!*args)
Index: trunk/src/game/Player.cpp
===================================================================
--- trunk/src/game/Player.cpp (revision 174)
+++ trunk/src/game/Player.cpp (revision 177)
@@ -3926,8 +3926,7 @@
         for(int i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; i++)
             if(Bag* pBag = (Bag*)GetItemByPos( INVENTORY_SLOT_BAG_0, i ))
-                if(ItemPrototype const *pBagProto = pBag->GetProto())
-                    for(uint32 j = 0; j < pBagProto->ContainerSlots; j++)
-                        if(Item* pItem = GetItemByPos( i, j ))
-                            DurabilityLoss(pItem,percent);
+                for(uint32 j = 0; j < pBag->GetBagSize(); j++)
+                    if(Item* pItem = GetItemByPos( i, j ))
+                        DurabilityLoss(pItem,percent);
     }
 }
@@ -3971,8 +3970,7 @@
         for(int i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; i++)
             if(Bag* pBag = (Bag*)GetItemByPos( INVENTORY_SLOT_BAG_0, i ))
-                if(ItemPrototype const *pBagProto = pBag->GetProto())
-                    for(uint32 j = 0; j < pBagProto->ContainerSlots; j++)
-                        if(Item* pItem = GetItemByPos( i, j ))
-                            DurabilityPointsLoss(pItem,points);
+                for(uint32 j = 0; j < pBag->GetBagSize(); j++)
+                    if(Item* pItem = GetItemByPos( i, j ))
+                        DurabilityPointsLoss(pItem,points);
     }
 }
@@ -8327,5 +8325,4 @@
     }
     Bag *pBag;
-    ItemPrototype const *pBagProto;
     for(int i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; i++)
     {
@@ -8333,16 +8330,12 @@
         if( pBag )
         {
-            pBagProto = pBag->GetProto();
-            if( pBagProto )
-            {
-                for(uint32 j = 0; j < pBagProto->ContainerSlots; j++)
+            for(uint32 j = 0; j < pBag->GetBagSize(); j++)
+            {
+                pItem = GetItemByPos( i, j );
+                if( pItem && pItem->GetEntry() == item )
                 {
-                    pItem = GetItemByPos( i, j );
-                    if( pItem && pItem->GetEntry() == item )
-                    {
-                        tempcount += pItem->GetCount();
-                        if( tempcount >= count )
-                            return EQUIP_ERR_OK;
-                    }
+                    tempcount += pItem->GetCount();
+                    if( tempcount >= count )
+                        return EQUIP_ERR_OK;
                 }
             }
@@ -8435,13 +8428,9 @@
         if( pBag )
         {
-            ItemPrototype const *pBagProto = pBag->GetProto();
-            if( pBagProto )
-            {
-                for(uint32 j = 0; j < pBagProto->ContainerSlots; j++)
-                {
-                    Item* pItem = pBag->GetItemByPos( j );
-                    if( pItem && pItem->GetGUID() == guid )
-                        return pItem;
-                }
+            for(uint32 j = 0; j < pBag->GetBagSize(); j++)
+            {
+                Item* pItem = pBag->GetItemByPos( j );
+                if( pItem && pItem->GetGUID() == guid )
+                    return pItem;
             }
         }
@@ -8452,13 +8441,9 @@
         if( pBag )
         {
-            ItemPrototype const *pBagProto = pBag->GetProto();
-            if( pBagProto )
-            {
-                for(uint32 j = 0; j < pBagProto->ContainerSlots; j++)
-                {
-                    Item* pItem = pBag->GetItemByPos( j );
-                    if( pItem && pItem->GetGUID() == guid )
-                        return pItem;
-                }
+            for(uint32 j = 0; j < pBag->GetBagSize(); j++)
+            {
+                Item* pItem = pBag->GetItemByPos( j );
+                if( pItem && pItem->GetGUID() == guid )
+                    return pItem;
             }
         }
@@ -8618,7 +8603,34 @@
         if(Bag* pBag = (Bag*)GetItemByPos( INVENTORY_SLOT_BAG_0, i ))
         {
-            if(ItemPrototype const *pBagProto = pBag->GetProto())
-            {
-                for(uint32 j = 0; j < pBagProto->ContainerSlots; j++)
+            for(uint32 j = 0; j < pBag->GetBagSize(); j++)
+            {
+                Item* pItem = GetItemByPos( i, j );
+                if( pItem && pItem->GetEntry() == item )
+                {
+                    tempcount += pItem->GetCount();
+                    if( tempcount >= count )
+                        return true;
+                }
+            }
+        }
+    }
+
+    if(inBankAlso)
+    {
+        for(int i = BANK_SLOT_ITEM_START; i < BANK_SLOT_ITEM_END; i++)
+        {
+            Item *pItem = GetItemByPos( INVENTORY_SLOT_BAG_0, i );
+            if( pItem && pItem->GetEntry() == item )
+            {
+                tempcount += pItem->GetCount();
+                if( tempcount >= count )
+                    return true;
+            }
+        }
+        for(int i = BANK_SLOT_BAG_START; i < BANK_SLOT_BAG_END; i++)
+        {
+            if(Bag* pBag = (Bag*)GetItemByPos( INVENTORY_SLOT_BAG_0, i ))
+            {
+                for(uint32 j = 0; j < pBag->GetBagSize(); j++)
                 {
                     Item* pItem = GetItemByPos( i, j );
@@ -8634,37 +8646,4 @@
     }
 
-    if(inBankAlso)
-    {
-        for(int i = BANK_SLOT_ITEM_START; i < BANK_SLOT_ITEM_END; i++)
-        {
-            Item *pItem = GetItemByPos( INVENTORY_SLOT_BAG_0, i );
-            if( pItem && pItem->GetEntry() == item )
-            {
-                tempcount += pItem->GetCount();
-                if( tempcount >= count )
-                    return true;
-            }
-        }
-        for(int i = BANK_SLOT_BAG_START; i < BANK_SLOT_BAG_END; i++)
-        {
-            if(Bag* pBag = (Bag*)GetItemByPos( INVENTORY_SLOT_BAG_0, i ))
-            {
-                if(ItemPrototype const *pBagProto = pBag->GetProto())
-                {
-                    for(uint32 j = 0; j < pBagProto->ContainerSlots; j++)
-                    {
-                        Item* pItem = GetItemByPos( i, j );
-                        if( pItem && pItem->GetEntry() == item )
-                        {
-                            tempcount += pItem->GetCount();
-                            if( tempcount >= count )
-                                return true;
-                        }
-                    }
-                }
-            }
-        }
-    }
-
     return false;
 }
@@ -8738,20 +8717,13 @@
             return true;
     }
-    Bag *pBag;
-    ItemPrototype const *pBagProto;
     for(uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; ++i)
     {
-        pBag = (Bag*)GetItemByPos( INVENTORY_SLOT_BAG_0, i );
-        if( pBag )
-        {
-            pBagProto = pBag->GetProto();
-            if( pBagProto )
-            {
-                for(uint32 j = 0; j < pBagProto->ContainerSlots; ++j)
-                {
-                    pItem = GetItemByPos( i, j );
-                    if( pItem && IsTotemCategoryCompatiableWith(pItem->GetProto()->TotemCategory,TotemCategory ))
-                        return true;
-                }
+        if(Bag *pBag = (Bag*)GetItemByPos( INVENTORY_SLOT_BAG_0, i ))
+        {
+            for(uint32 j = 0; j < pBag->GetBagSize(); ++j)
+            {
+                pItem = GetItemByPos( i, j );
+                if( pItem && IsTotemCategoryCompatiableWith(pItem->GetProto()->TotemCategory,TotemCategory ))
+                    return true;
             }
         }
@@ -8847,5 +8819,5 @@
         return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG;
 
-    for(uint32 j = 0; j < pBagProto->ContainerSlots; j++)
+    for(uint32 j = 0; j < pBag->GetBagSize(); j++)
     {
         // skip specific slot already processed in first called _CanStoreItem_InSpecificSlot
@@ -9354,21 +9326,12 @@
     for(int i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; i++)
     {
-        Bag     *pBag;
-        ItemPrototype const *pBagProto;
-
-        pBag = (Bag*)GetItemByPos( INVENTORY_SLOT_BAG_0, i );
-        if( pBag )
-        {
-            pBagProto = pBag->GetProto();
-
-            if( pBagProto )
-            {
-                for(uint32 j = 0; j < pBagProto->ContainerSlots; j++)
+        if(Bag* pBag = (Bag*)GetItemByPos( INVENTORY_SLOT_BAG_0, i ))
+        {
+            for(uint32 j = 0; j < pBag->GetBagSize(); j++)
+            {
+                pItem2 = GetItemByPos( i, j );
+                if (pItem2 && !pItem2->IsInTrade())
                 {
-                    pItem2 = GetItemByPos( i, j );
-                    if (pItem2 && !pItem2->IsInTrade())
-                    {
-                        inv_bags[i-INVENTORY_SLOT_BAG_START][j] = pItem2->GetCount();
-                    }
+                    inv_bags[i-INVENTORY_SLOT_BAG_START][j] = pItem2->GetCount();
                 }
             }
@@ -9437,16 +9400,12 @@
                 if( pBag )
                 {
-                    pBagProto = pBag->GetProto();
-                    if( pBagProto )
+                    for(uint32 j = 0; j < pBag->GetBagSize(); j++)
                     {
-                        for(uint32 j = 0; j < pBagProto->ContainerSlots; j++)
+                        pItem2 = GetItemByPos( t, j );
+                        if( pItem2 && pItem2->GetEntry() == pItem->GetEntry() && inv_bags[t-INVENTORY_SLOT_BAG_START][j] + pItem->GetCount() <= pProto->Stackable )
                         {
-                            pItem2 = GetItemByPos( t, j );
-                            if( pItem2 && pItem2->GetEntry() == pItem->GetEntry() && inv_bags[t-INVENTORY_SLOT_BAG_START][j] + pItem->GetCount() <= pProto->Stackable )
-                            {
-                                inv_bags[t-INVENTORY_SLOT_BAG_START][j] += pItem->GetCount();
-                                b_found = true;
-                                break;
-                            }
+                            inv_bags[t-INVENTORY_SLOT_BAG_START][j] += pItem->GetCount();
+                            b_found = true;
+                            break;
                         }
                     }
@@ -9487,5 +9446,5 @@
                         ItemCanGoIntoBag(pProto,pBagProto) )
                     {
-                        for(uint32 j = 0; j < pBagProto->ContainerSlots; j++)
+                        for(uint32 j = 0; j < pBag->GetBagSize(); j++)
                         {
                             if( inv_bags[t-INVENTORY_SLOT_BAG_START][j] == 0 )
@@ -9521,15 +9480,11 @@
             if( pBag )
             {
-                pBagProto = pBag->GetProto();
-                if( pBagProto && ItemCanGoIntoBag(pProto,pBagProto))
+                for(uint32 j = 0; j < pBag->GetBagSize(); j++)
                 {
-                    for(uint32 j = 0; j < pBagProto->ContainerSlots; j++)
+                    if( inv_bags[t-INVENTORY_SLOT_BAG_START][j] == 0 )
                     {
-                        if( inv_bags[t-INVENTORY_SLOT_BAG_START][j] == 0 )
-                        {
-                            inv_bags[t-INVENTORY_SLOT_BAG_START][j] = 1;
-                            b_found = true;
-                            break;
-                        }
+                        inv_bags[t-INVENTORY_SLOT_BAG_START][j] = 1;
+                        b_found = true;
+                        break;
                     }
                 }
@@ -10625,38 +10580,31 @@
 
     // in inventory bags
-    Bag *pBag;
-    ItemPrototype const *pBagProto;
     for(int i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; i++)
     {
-        pBag = (Bag*)GetItemByPos( INVENTORY_SLOT_BAG_0, i );
-        if( pBag )
-        {
-            pBagProto = pBag->GetProto();
-            if( pBagProto )
-            {
-                for(uint32 j = 0; j < pBagProto->ContainerSlots; j++)
+        if(Bag *pBag = (Bag*)GetItemByPos( INVENTORY_SLOT_BAG_0, i ))
+        {
+            for(uint32 j = 0; j < pBag->GetBagSize(); j++)
+            {
+                pItem = pBag->GetItemByPos(j);
+                if( pItem && pItem->GetEntry() == item )
                 {
-                    pItem = pBag->GetItemByPos(j);
-                    if( pItem && pItem->GetEntry() == item )
+                    // all items in bags can be unequipped
+                    if( pItem->GetCount() + remcount <= count )
                     {
-                        // all items in bags can be unequipped
-                        if( pItem->GetCount() + remcount <= count )
-                        {
-                            remcount += pItem->GetCount();
-                            DestroyItem( i, j, update );
-
-                            if(remcount >=count)
-                                return;
-                        }
-                        else
-                        {
-                            pProto = pItem->GetProto();
-                            ItemRemovedQuestCheck( pItem->GetEntry(), count - remcount );
-                            pItem->SetCount( pItem->GetCount() - count + remcount );
-                            if( IsInWorld() && update )
-                                pItem->SendUpdateToPlayer( this );
-                            pItem->SetState(ITEM_CHANGED, this);
+                        remcount += pItem->GetCount();
+                        DestroyItem( i, j, update );
+
+                        if(remcount >=count)
                             return;
-                        }
+                    }
+                    else
+                    {
+                        pProto = pItem->GetProto();
+                        ItemRemovedQuestCheck( pItem->GetEntry(), count - remcount );
+                        pItem->SetCount( pItem->GetCount() - count + remcount );
+                        if( IsInWorld() && update )
+                            pItem->SendUpdateToPlayer( this );
+                        pItem->SetState(ITEM_CHANGED, this);
+                        return;
                     }
                 }
@@ -10720,13 +10668,9 @@
         if( pBag )
         {
-            ItemPrototype const *pBagProto = pBag->GetProto();
-            if( pBagProto )
-            {
-                for(uint32 j = 0; j < pBagProto->ContainerSlots; j++)
-                {
-                    Item* pItem = pBag->GetItemByPos(j);
-                    if( pItem && pItem->IsLimitedToAnotherMapOrZone(GetMapId(),new_zone) )
-                        DestroyItem( i, j, update);
-                }
+            for(uint32 j = 0; j < pBag->GetBagSize(); j++)
+            {
+                Item* pItem = pBag->GetItemByPos(j);
+                if( pItem && pItem->IsLimitedToAnotherMapOrZone(GetMapId(),new_zone) )
+                    DestroyItem( i, j, update);
             }
         }
@@ -10764,15 +10708,11 @@
         if( pBag )
         {
-            ItemPrototype const *pBagProto = pBag->GetProto();
-            if( pBagProto )
-            {
-                for(uint32 j = 0; j < pBagProto->ContainerSlots; j++)
-                {
-                    Item* pItem = pBag->GetItemByPos(j);
-                    if( pItem && pItem->GetProto() &&
-                        (pItem->GetProto()->Class == ITEM_CLASS_CONSUMABLE) &&
-                        (pItem->GetProto()->Flags & ITEM_FLAGS_CONJURED) )
-                        DestroyItem( i, j, update);
-                }
+            for(uint32 j = 0; j < pBag->GetBagSize(); j++)
+            {
+                Item* pItem = pBag->GetItemByPos(j);
+                if( pItem && pItem->GetProto() &&
+                    (pItem->GetProto()->Class == ITEM_CLASS_CONSUMABLE) &&
+                    (pItem->GetProto()->Flags & ITEM_FLAGS_CONJURED) )
+                    DestroyItem( i, j, update);
             }
         }
@@ -11423,13 +11363,9 @@
         if( pBag )
         {
-            ItemPrototype const *pBagProto = pBag->GetProto();
-            if( pBagProto )
-            {
-                for(uint32 j = 0; j < pBagProto->ContainerSlots; j++)
-                {
-                    Item* pItem = pBag->GetItemByPos(j);
-                    if( pItem && pItem->GetEnchantmentId(slot) )
-                        pItem->ClearEnchantment(slot);
-                }
+            for(uint32 j = 0; j < pBag->GetBagSize(); j++)
+            {
+                Item* pItem = pBag->GetItemByPos(j);
+                if( pItem && pItem->GetEnchantmentId(slot) )
+                    pItem->ClearEnchantment(slot);
             }
         }
@@ -15717,4 +15653,14 @@
 }
 
+void Player::PlaySound(uint32 Sound, bool OnlySelf)
+{
+    WorldPacket data(SMSG_PLAY_SOUND, 4);
+    data << Sound;
+    if (OnlySelf)
+        GetSession()->SendPacket( &data );
+    else
+        SendMessageToSet( &data, true );
+}
+
 void Player::SendExplorationExperience(uint32 Area, uint32 Experience)
 {
Index: trunk/src/game/GuildHandler.cpp
===================================================================
--- trunk/src/game/GuildHandler.cpp (revision 173)
+++ trunk/src/game/GuildHandler.cpp (revision 177)
@@ -153,8 +153,4 @@
 
     std::string plName;
-    uint64 plGuid;
-    uint32 plGuildId;
-    Guild *guild;
-    Player *player;
 
     //sLog.outDebug("WORLD: Received CMSG_GUILD_REMOVE");
@@ -165,5 +161,5 @@
         return;
 
-    guild = objmgr.GetGuildById(GetPlayer()->GetGuildId());
+    Guild* guild = objmgr.GetGuildById(GetPlayer()->GetGuildId());
     if(!guild)
     {
@@ -178,15 +174,5 @@
     }
     
-    player = ObjectAccessor::Instance().FindPlayerByName(plName.c_str());
-    if(player)
-    {
-        plGuid = player->GetGUID();
-        plGuildId = player->GetGuildId();
-    }
-    else
-    {
-        plGuid = objmgr.GetPlayerGUIDByName(plName);
-        plGuildId = Player::GetGuildIdFromDB(plGuid);
-    }
+    uint64 plGuid = objmgr.GetPlayerGUIDByName(plName);
 
     if(!plGuid)
@@ -202,5 +188,5 @@
     }
 
-    if(GetPlayer()->GetGuildId() != plGuildId)
+    if(!guild->IsMember(GUID_LOPART(plGuid)))
     {
         SendGuildCommandResult(GUILD_INVITE_S, plName, GUILD_PLAYER_NOT_IN_GUILD_S);
@@ -488,7 +474,4 @@
 
     std::string name;
-    Player *newLeader;
-    uint64 newLeaderGUID;
-    uint32 newLeaderGuild;
     Player *oldLeader = GetPlayer();
     Guild *guild;
@@ -503,5 +486,5 @@
     guild = objmgr.GetGuildById(oldLeader->GetGuildId());
     
-    if(!guild)
+    if (!guild)
     {
         SendGuildCommandResult(GUILD_CREATE_S, "", GUILD_PLAYER_NOT_IN_GUILD);
@@ -509,5 +492,5 @@
     }
     
-    if(oldLeader->GetGUID() != guild->GetLeader())
+    if( oldLeader->GetGUID() != guild->GetLeader())
     {
         SendGuildCommandResult(GUILD_INVITE_S, "", GUILD_PERMISSIONS);
@@ -515,21 +498,11 @@
     }
 
-    newLeader = ObjectAccessor::Instance().FindPlayerByName(name.c_str());
-    if(newLeader)
-    {
-        newLeaderGUID = newLeader->GetGUID();
-        newLeaderGuild = newLeader->GetGuildId();
-    }
-    else
-    {
-        newLeaderGUID = objmgr.GetPlayerGUIDByName(name);
-        newLeaderGuild = Player::GetGuildIdFromDB(newLeaderGUID);
-    }
-    if(!newLeaderGUID)
+    uint64 newLeaderGUID = objmgr.GetPlayerGUIDByName(name);
+    if (!newLeaderGUID)
     {
         SendGuildCommandResult(GUILD_INVITE_S, name, GUILD_PLAYER_NOT_FOUND);
         return;
     }
-    if(oldLeader->GetGuildId() != newLeaderGuild)
+    if(!guild->IsMember(GUID_LOPART(newLeaderGUID)))
     {
         SendGuildCommandResult(GUILD_INVITE_S, name, GUILD_PLAYER_NOT_IN_GUILD_S);
@@ -589,8 +562,4 @@
     CHECK_PACKET_SIZE(recvPacket, 1);
 
-    Guild *guild;
-    Player *player;
-    uint64 plGuid;
-    uint32 plGuildId;
     std::string name,PNOTE;
 
@@ -602,6 +571,6 @@
         return;
 
-    guild = objmgr.GetGuildById(GetPlayer()->GetGuildId());
-    if(!guild)
+    Guild* guild = objmgr.GetGuildById(GetPlayer()->GetGuildId());
+    if (!guild)
     {
         SendGuildCommandResult(GUILD_CREATE_S, "", GUILD_PLAYER_NOT_IN_GUILD);
@@ -609,5 +578,5 @@
     }
     
-    if(!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_EPNOTE))
+    if (!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_EPNOTE))
     {
         SendGuildCommandResult(GUILD_INVITE_S, "", GUILD_PERMISSIONS);
@@ -615,22 +584,13 @@
     }
     
-    player = ObjectAccessor::Instance().FindPlayerByName(name.c_str());
-    if(player)
-    {
-        plGuid = player->GetGUID();
-        plGuildId = player->GetGuildId();
-    }
-    else
-    {
-        plGuid = objmgr.GetPlayerGUIDByName(name);
-        plGuildId = Player::GetGuildIdFromDB(plGuid);
-    }
-
-    if(!plGuid)
+    uint64 plGuid = objmgr.GetPlayerGUIDByName(name);
+
+    if (!plGuid)
     {
         SendGuildCommandResult(GUILD_INVITE_S, name, GUILD_PLAYER_NOT_FOUND);
         return;
     }
-    else if(GetPlayer()->GetGuildId() != plGuildId)
+    
+    if (!guild->IsMember(GUID_LOPART(plGuid)))
     {
         SendGuildCommandResult(GUILD_INVITE_S, name, GUILD_PLAYER_NOT_IN_GUILD_S);
@@ -648,8 +608,4 @@
     CHECK_PACKET_SIZE(recvPacket, 1);
 
-    Guild *guild;
-    Player *player;
-    uint64 plGuid;
-    uint32 plGuildId;
     std::string plName, OFFNOTE;
 
@@ -661,11 +617,11 @@
         return;
 
-    guild = objmgr.GetGuildById(GetPlayer()->GetGuildId());
-    if(!guild)
+    Guild* guild = objmgr.GetGuildById(GetPlayer()->GetGuildId());
+    if (!guild)
     {
         SendGuildCommandResult(GUILD_CREATE_S, "", GUILD_PLAYER_NOT_IN_GUILD);
         return;
     }
-    if(!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_EOFFNOTE))
+    if (!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_EOFFNOTE))
     {
         SendGuildCommandResult(GUILD_INVITE_S, "", GUILD_PERMISSIONS);
@@ -673,22 +629,13 @@
     }
     
-    player = ObjectAccessor::Instance().FindPlayerByName(plName.c_str());
-    if(player)
-    {
-        plGuid = player->GetGUID();
-        plGuildId = player->GetGuildId();
-    }
-    else
-    {
-        plGuid = objmgr.GetPlayerGUIDByName(plName);
-        plGuildId = Player::GetGuildIdFromDB(plGuid);
-    }
-
-    if( !plGuid )
+    uint64 plGuid = objmgr.GetPlayerGUIDByName(plName);
+
+    if (!plGuid)
     {
         SendGuildCommandResult(GUILD_INVITE_S, plName, GUILD_PLAYER_NOT_FOUND);
         return;
     }
-    else if(GetPlayer()->GetGuildId() != plGuildId)
+    
+    if (!guild->IsMember(GUID_LOPART(plGuid)))
     {
         SendGuildCommandResult(GUILD_INVITE_S, plName, GUILD_PLAYER_NOT_IN_GUILD_S);
Index: trunk/contrib/extractor/mpq_libmpq.cpp
===================================================================
--- trunk/contrib/extractor/mpq_libmpq.cpp (revision 2)
+++ trunk/contrib/extractor/mpq_libmpq.cpp (revision 177)
@@ -72,5 +72,5 @@
         }
 
-        int fileno = blockindex;
+        uint32 fileno = blockindex;
 
         //int fileno = libmpq_file_number(&mpq_a, filename);
Index: trunk/contrib/extractor/libmpq/mpq.h
===================================================================
--- trunk/contrib/extractor/libmpq/mpq.h (revision 2)
+++ trunk/contrib/extractor/libmpq/mpq.h (revision 177)
@@ -199,5 +199,5 @@
 extern int libmpq_archive_info(mpq_archive *mpq_a, unsigned int infotype);
 //extern int libmpq_file_extract(mpq_archive *mpq_a, const int number);
-extern int libmpq_file_info(mpq_archive *mpq_a, unsigned int infotype, const int number);
+extern int libmpq_file_info(mpq_archive *mpq_a, unsigned int infotype, const unsigned int number);
 extern char *libmpq_file_name(mpq_archive *mpq_a, const int number);
 extern int libmpq_file_number(mpq_archive *mpq_a, const char *name);
Index: trunk/contrib/extractor/libmpq/parser.cpp
===================================================================
--- trunk/contrib/extractor/libmpq/parser.cpp (revision 2)
+++ trunk/contrib/extractor/libmpq/parser.cpp (revision 177)
@@ -80,5 +80,5 @@
 
 	/* now search for comment in this line */
-	for (i = 0; i < strlen(line); i++) {
+	for (i = 0; i < int(strlen(line)); i++) {
 		if (line[i] == '#') {
 			pos = i - 1;
Index: trunk/contrib/extractor/libmpq/mpq.cpp
===================================================================
--- trunk/contrib/extractor/libmpq/mpq.cpp (revision 168)
+++ trunk/contrib/extractor/libmpq/mpq.cpp (revision 177)
@@ -200,5 +200,5 @@
  * This function returns some useful file information.
  */
-int libmpq_file_info(mpq_archive *mpq_a, unsigned int infotype, const int number) {
+int libmpq_file_info(mpq_archive *mpq_a, unsigned int infotype, const int unsigned number) {
 	int blockindex = number; //-1;
 	int i = 0;
Index: trunk/contrib/extractor/mpq_libmpq.h
===================================================================
--- trunk/contrib/extractor/mpq_libmpq.h (revision 2)
+++ trunk/contrib/extractor/mpq_libmpq.h (revision 177)
@@ -52,12 +52,10 @@
     }
 
-    vector<string> GetFileList() {
-        vector<string> filelist;
-
+    void GetFileListTo(vector<string>& filelist) {
         mpq_hash hash = GetHashEntry("(listfile)");
         uint32 blockindex = hash.blockindex;
 
         if ((blockindex == 0xFFFFFFFF) || (blockindex == 0))
-            return filelist;
+            return;
 
         uint32 size = libmpq_file_info(&mpq_a, LIBMPQ_FILE_UNCOMPRESSED_SIZE, blockindex);
@@ -80,6 +78,5 @@
         }
 
-        delete buffer;
-        return filelist;
+        delete[] buffer;
     }
 };
Index: trunk/contrib/extractor/System.cpp
===================================================================
--- trunk/contrib/extractor/System.cpp (revision 2)
+++ trunk/contrib/extractor/System.cpp (revision 177)
@@ -40,5 +40,5 @@
 int extract = EXTRACT_MAP | EXTRACT_DBC;
 
-static char* const langs[]={"deDE", "enGB", "enUS", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU" };
+static char* const langs[]={"enGB", "enUS", "deDE", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU" };
 #define LANG_COUNT 12
 
@@ -168,9 +168,9 @@
     CreateDir(path);
 
-    for(int x = 0; x < ADT_RES; ++x)
-    {
-        for(int y = 0; y < ADT_RES; ++y)
-        {
-            for(int z = 0; z < map_count; ++z)
+    for(unsigned int x = 0; x < ADT_RES; ++x)
+    {
+        for(unsigned int y = 0; y < ADT_RES; ++y)
+        {
+            for(unsigned int z = 0; z < map_count; ++z)
             {
                 sprintf(mpq_filename,"World\\Maps\\%s\\%s_%u_%u.adt",map_ids[z].name,map_ids[z].name,x,y);
@@ -190,5 +190,5 @@
 //bool WMO(char* filename);
 
-void ExtractDBCFiles()
+void ExtractDBCFiles(int locale, bool basicLocale)
 {
     printf("Extracting dbc files...\n");
@@ -199,5 +199,6 @@
     for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i)
     {
-        vector<string> files = (*i)->GetFileList();
+        vector<string> files;
+        (*i)->GetFileListTo(files);
         for (vector<string>::iterator iter = files.begin(); iter != files.end(); ++iter)
             if (iter->rfind(".dbc") == iter->length() - strlen(".dbc"))
@@ -205,7 +206,13 @@
     }
 
-    std::string path = output_path;
+    string path = output_path;
     path += "/dbc/";
     CreateDir(path);
+    if(!basicLocale)
+    {
+        path += langs[locale];
+        path += "/";
+        CreateDir(path);
+    }
 
     // extract DBCs
@@ -213,9 +220,6 @@
     for (set<string>::iterator iter = dbcfiles.begin(); iter != dbcfiles.end(); ++iter)
     {
-        string filename = output_path;
-        filename += "/dbc/";
+        string filename = path;
         filename += (iter->c_str() + strlen("DBFilesClient\\"));
-
-        //cout << filename << endl;
 
         FILE *output=fopen(filename.c_str(),"wb");
@@ -232,9 +236,59 @@
         ++count;
     }
-    printf("Extracted %u DBC files\n", count);
-}
-
-int GetLocale()
-{
+    printf("Extracted %u DBC files\n\n", count);
+}
+
+void LoadLocaleMPQFiles(int const locale)
+{
+    char filename[512];
+
+    sprintf(filename,"%s/Data/%s/locale-%s.MPQ",input_path,langs[locale],langs[locale]);
+    new MPQArchive(filename);
+
+    for(int i = 1; i < 5; ++i)
+    {
+        char ext[3] = "";
+        if(i > 1)
+            sprintf(ext, "-%i", i);
+
+        sprintf(filename,"%s/Data/%s/patch-%s%s.MPQ",input_path,langs[locale],langs[locale],ext);
+        if(FileExists(filename))
+            new MPQArchive(filename);
+    }
+}
+    
+void LoadCommonMPQFiles()
+{
+    char filename[512];
+
+    sprintf(filename,"%s/Data/common.MPQ",input_path);
+    new MPQArchive(filename);
+    sprintf(filename,"%s/Data/expansion.MPQ",input_path);
+    new MPQArchive(filename);
+    for(int i = 1; i < 5; ++i)
+    {
+        char ext[3] = "";
+        if(i > 1)
+            sprintf(ext, "-%i", i);
+            if(FileExists(filename))
+                new MPQArchive(filename);
+    }
+}
+
+inline void CloseMPQFiles()
+{
+    for(ArchiveSet::iterator j = gOpenArchives.begin(); j != gOpenArchives.end();++j) (*j)->close();
+        gOpenArchives.clear();
+}
+
+int main(int argc, char * arg[])
+{
+    printf("Map & DBC Extractor\n");
+    printf("===================\n\n");
+
+    HandleArgs(argc, arg);
+
+    int FirstLocale = -1;
+    
     for (int i = 0; i < LANG_COUNT; i++)
     {
@@ -244,76 +298,48 @@
         {
             printf("Detected locale: %s\n", langs[i]);
-            return i;
-        }
-    }
-
-    printf("Could not detect locale.\n");
-    return -1;
-}
-
-void LoadMPQFiles(int const locale)
-{
-    char filename[512];
-
-    sprintf(filename,"%s/Data/%s/locale-%s.MPQ",input_path,langs[locale],langs[locale]);
-    new MPQArchive(filename);
-
-    for(int i = 1; i < 5; ++i)
-    {
-        char ext[3] = "";
-        if(i > 1)
-            sprintf(ext, "-%i", i);
-
-        sprintf(filename,"%s/Data/%s/patch-%s%s.MPQ",input_path,langs[locale],langs[locale],ext);
-        if(!FileExists(filename))
-            break;
-        new MPQArchive(filename);
-    }
-
-    //need those files only if extract maps
-    if(extract & EXTRACT_MAP)
-    {
-        sprintf(filename,"%s/Data/common.MPQ",input_path);
-        new MPQArchive(filename);
-        sprintf(filename,"%s/Data/expansion.MPQ",input_path);
-        new MPQArchive(filename);
-
-        for(int i = 1; i < 5; ++i)
-        {
-            char ext[3] = "";
-            if(i > 1)
-                sprintf(ext, "-%i", i);
-
-            sprintf(filename,"%s/Data/patch%s.MPQ",input_path,ext);
-            if(!FileExists(filename))
-                break;
-            new MPQArchive(filename);
-        }
-    }
-}
-
-int main(int argc, char * arg[])
-{
-    printf("Map & DBC Extractor\n");
-    printf("===================\n");
-
-    HandleArgs(argc, arg);
-
-    int const locale = GetLocale();
-    if(locale < 0)
-        return 1;
-
-    LoadMPQFiles(locale);
-
-    if(extract & EXTRACT_DBC)
-        ExtractDBCFiles();
-
-    if(extract & EXTRACT_MAP)
+            
+            //Open MPQs
+            LoadLocaleMPQFiles(i);
+            
+            if((extract & EXTRACT_DBC) == 0)
+            {
+                FirstLocale=i;
+                break;
+            }
+
+        //Extract DBC files
+        if(FirstLocale<0)
+        {
+            ExtractDBCFiles(i, true);
+            FirstLocale = i;
+        }
+        else 
+            ExtractDBCFiles(i, false);
+        
+            //Close MPQs
+            CloseMPQFiles();
+        }
+    }
+
+    if(FirstLocale<0)
+    {
+        printf("No locales detected\n");
+        return 0;
+    }
+    
+    if (extract & EXTRACT_MAP)
+    {
+        printf("Using locale: %s\n", langs[FirstLocale]);
+        
+        // Open MPQs
+        LoadLocaleMPQFiles(FirstLocale);
+        LoadCommonMPQFiles();
+        
+        // Extract maps
         ExtractMapsFromMpq();
 
-    //Close MPQs
-    for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i)
-        (*i)->close();
-    gOpenArchives.clear();
+        // Close MPQs
+        CloseMPQFiles();
+    }
 
     return 0;
