summaryrefslogtreecommitdiff
path: root/src/utils/stringutils.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-01-17 03:13:39 +0300
committerAndrei Karas <akaras@inbox.ru>2016-01-17 14:19:17 +0300
commit41141188d70dd7d6e0b8667bda9d0f6569c0b97b (patch)
tree4ed6186d9805fe3240fd3f574faa4455ca9e3fa9 /src/utils/stringutils.cpp
parentfcf4c08536267a7be624b057c28586f510c0af2c (diff)
downloadmv-41141188d70dd7d6e0b8667bda9d0f6569c0b97b.tar.gz
mv-41141188d70dd7d6e0b8667bda9d0f6569c0b97b.tar.bz2
mv-41141188d70dd7d6e0b8667bda9d0f6569c0b97b.tar.xz
mv-41141188d70dd7d6e0b8667bda9d0f6569c0b97b.zip
Add support for adding cards into item links in chat.
Diffstat (limited to 'src/utils/stringutils.cpp')
-rw-r--r--src/utils/stringutils.cpp41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 830b0346a..dadfd35f5 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -970,9 +970,11 @@ std::string timeDiffToString(int timeDiff)
return str;
}
+#include "logger.h"
+
+#ifndef DYECMD
void replaceItemLinks(std::string &msg)
{
-#ifndef DYECMD
// Check for item link
size_t start2 = msg.find('[');
size_t sz = msg.size();
@@ -998,11 +1000,34 @@ void replaceItemLinks(std::string &msg)
{
std::string itemStr = msg.substr(start2 + 1, end - start2 - 1);
- const ItemInfo &itemInfo = ItemDB::get(itemStr);
- if (itemInfo.getId() != 0)
+ StringVect parts;
+ splitToStringVector(parts, itemStr, ',');
+ if (parts.empty())
+ return;
+
+ const ItemInfo &itemInfo = ItemDB::get(parts[0]);
+ const int itemId = itemInfo.getId();
+ if (itemId != 0)
{
- std::string temp = strprintf("@@%d|", itemInfo.getId());
- msg.insert(end, "@@");
+ std::string temp = strprintf("@@%d", itemId);
+ std::string name = parts[0];
+ msg.erase(start2 + 1, end - start2 - 1);
+ parts.erase(parts.begin());
+ if (!parts.empty())
+ name.clear();
+
+ FOR_EACH (StringVectCIter, it, parts)
+ {
+ std:: string str = *it;
+ trim(str);
+ const ItemInfo &itemInfo2 = ItemDB::get(str);
+ const int cardId = itemInfo2.getId();
+ if (cardId != 0)
+ temp.append(strprintf(",%d", cardId));
+ }
+ temp.append("|");
+ temp.append(name);
+ temp.append("@@");
msg.insert(start2 + 1, temp);
sz = msg.size();
}
@@ -1010,5 +1035,9 @@ void replaceItemLinks(std::string &msg)
}
start2 = msg.find('[', start2 + 1);
}
-#endif
}
+#else
+void replaceItemLinks(std::string &msg A_UNUSED)
+{
+}
+#endif