summaryrefslogtreecommitdiff
path: root/src/tool
diff options
context:
space:
mode:
authorChuck Miller <shadowmil@gmail.com>2009-05-25 14:04:22 -0400
committerDennis Friis <peavey@inspircd.org>2009-05-25 20:12:59 +0200
commit618e60353e1cfc3d1c0d7bc14476f5e86ee7175b (patch)
treebbe79aed30a4eeab5e49594615f3480d98a81592 /src/tool
parent3f0e5c66f9bce7581b7fa56d12accd13e0725c88 (diff)
downloadtmwa-618e60353e1cfc3d1c0d7bc14476f5e86ee7175b.tar.gz
tmwa-618e60353e1cfc3d1c0d7bc14476f5e86ee7175b.tar.bz2
tmwa-618e60353e1cfc3d1c0d7bc14476f5e86ee7175b.tar.xz
tmwa-618e60353e1cfc3d1c0d7bc14476f5e86ee7175b.zip
Added tool for finding players who have a certain item, and how many of those items they posses
Diffstat (limited to 'src/tool')
-rw-r--r--src/tool/itemsearch.cpp108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/tool/itemsearch.cpp b/src/tool/itemsearch.cpp
new file mode 100644
index 0000000..cf399e5
--- /dev/null
+++ b/src/tool/itemsearch.cpp
@@ -0,0 +1,108 @@
+// This code is GPL, blah blah
+//
+// Writen for TheManaWorld by Chuck Miller, A.K.A. Kage
+
+#include <iostream>
+#include <string>
+
+using namespace std;
+
+int itemID;
+
+int itemCount(string itemData)
+{
+ int counter = 0;
+ int pointer = 0;
+
+ do
+ {
+ int ending = itemData.find(',', pointer + 1);
+ if (ending == string::npos)
+ ending = itemData.size();
+ if (counter == 1 && atoi(itemData.substr(pointer, ending - pointer).c_str()) != itemID)
+ return 0;
+ if (counter == 2)
+ return atoi(itemData.substr(pointer, ending - pointer).c_str());
+ counter++;
+ } while ((pointer = itemData.find(',',pointer) + 1) != string::npos + 1);
+
+ return 0;
+}
+
+int parseItemData(string &items)
+{
+ int counter = 0;
+ int pointer = 0;
+
+ int total = 0;
+
+ do
+ {
+ int ending = items.find(' ', pointer + 1);
+ if (ending == string::npos)
+ ending = items.size();
+ total += itemCount(items.substr(pointer, ending - pointer));
+ counter++;
+ } while ((pointer = items.find(' ',pointer) + 1) != string::npos + 1);
+
+ return total;
+}
+
+void parseLine(string &line)
+{
+ int counter = 0;
+ int pointer = 0;
+
+ string AccountId, Name, Items;
+
+ do
+ {
+ if (counter == 1 || counter == 2 || counter == 15)
+ {
+
+ int ending = line.find('\t', pointer + 1);
+ if (ending == string::npos)
+ ending = line.size();
+ switch (counter)
+ {
+ case 1:
+ AccountId = line.substr(pointer,ending - pointer);
+ break;
+ case 2:
+ Name = line.substr(pointer, ending - pointer);
+ break;
+ case 15:
+ Items = line.substr(pointer, ending - pointer);
+ }
+ }
+ counter++;
+ } while ((pointer = line.find('\t',pointer) + 1) != string::npos + 1 && counter < 16);
+
+ if ((counter = parseItemData(Items)) > 0)
+ cout << "Account = " << AccountId << "; Name = \"" << Name << "\"; Count = " << counter << "\n";
+}
+
+void parseInput()
+{
+ string input;
+ while (getline(cin, input))
+ {
+ parseLine(input);
+ }
+}
+
+int main(int argc,char *argv[])
+{
+ if(argc < 2)
+ {
+ printf("Usage: %s <item ID>\n", argv[0]);
+ printf("e.g., %s 701\n", argv[0]);
+ printf("Will return all users who own that item\n");
+ exit(0);
+ }
+ itemID = atoi(argv[1]);
+ parseInput();
+
+ return 0;
+}
+