1913 | | // extract items |
1914 | | typedef std::pair<uint32,uint32> ItemPair; |
1915 | | typedef std::list< ItemPair > ItemPairs; |
1916 | | ItemPairs items; |
1917 | | |
1918 | | // get all tail string |
1919 | | char* tail = strtok(NULL, ""); |
1920 | | |
1921 | | // get from tail next item str |
1922 | | while(char* itemStr = strtok(tail, " ")) |
1923 | | { |
1924 | | // and get new tail |
1925 | | tail = strtok(NULL, ""); |
1926 | | |
1927 | | // parse item str |
1928 | | char* itemIdStr = strtok(itemStr, ":"); |
1929 | | char* itemCountStr = strtok(NULL, " "); |
1930 | | |
1931 | | uint32 item_id = atoi(itemIdStr); |
1932 | | if(!item_id) |
1933 | | return false; |
1934 | | |
1935 | | ItemPrototype const* item_proto = objmgr.GetItemPrototype(item_id); |
1936 | | if(!item_proto) |
1937 | | { |
1938 | | PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id); |
1939 | | SetSentErrorMessage(true); |
1940 | | return false; |
1941 | | } |
1942 | | |
1943 | | uint32 item_count = itemCountStr ? atoi(itemCountStr) : 1; |
1944 | | if(item_count < 1 || item_proto->MaxCount && item_count > item_proto->MaxCount) |
1945 | | { |
1946 | | PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, item_count,item_id); |
1947 | | SetSentErrorMessage(true); |
1948 | | return false; |
1949 | | } |
1950 | | |
1951 | | while(item_count > item_proto->Stackable) |
1952 | | { |
1953 | | items.push_back(ItemPair(item_id,item_proto->Stackable)); |
1954 | | item_count -= item_proto->Stackable; |
1955 | | } |
1956 | | |
1957 | | items.push_back(ItemPair(item_id,item_count)); |
1958 | | |
1959 | | if(items.size() > MAX_MAIL_ITEMS) |
1960 | | { |
1961 | | PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS); |
1962 | | SetSentErrorMessage(true); |
1963 | | return false; |
1964 | | } |
1965 | | } |
1966 | | |
1994 | | // fill mail |
1995 | | MailItemsInfo mi; // item list preparing |
1996 | | |
1997 | | for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr) |
1998 | | { |
1999 | | if(Item* item = Item::CreateItem(itr->first,itr->second,m_session->GetPlayer())) |
2000 | | { |
2001 | | item->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted |
2002 | | mi.AddItem(item->GetGUIDLow(), item->GetEntry(), item); |
2003 | | } |
2004 | | } |
2005 | | |
2006 | | WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, &mi, 0, 0, MAIL_CHECK_MASK_NONE); |
| 1938 | WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_NONE); |