aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared/Utilities/Util.cpp
diff options
context:
space:
mode:
authorWarpten <vertozor@gmail.com>2012-10-12 22:13:28 +0200
committerWarpten <vertozor@gmail.com>2012-10-12 22:13:28 +0200
commitc8c4291c6f57616489f7d511595c07a63bd230bc (patch)
treea534146dfd43413fa2931de7532d70bc7421183a /src/server/shared/Utilities/Util.cpp
parentb06e9cfd41e11b8efed8c1e8abb7899b91897b8d (diff)
Core/Commands: Allow .modify money to take another parameter structure:
Example uses: * .modify money 325g 25s 12c is the same as .modify money 3252512 * .modify money -12g is the same as .modify money -120000 * .modify money -12g 45s is the same as .modify money -115500 * .modify money 25c 18g is the same as .modify money 18g 25c
Diffstat (limited to 'src/server/shared/Utilities/Util.cpp')
-rwxr-xr-xsrc/server/shared/Utilities/Util.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/server/shared/Utilities/Util.cpp b/src/server/shared/Utilities/Util.cpp
index 0897c8814ab..407d0704619 100755
--- a/src/server/shared/Utilities/Util.cpp
+++ b/src/server/shared/Utilities/Util.cpp
@@ -150,6 +150,37 @@ std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
return ss.str();
}
+int32 MoneyStringToMoney(const std::string& moneyString)
+{
+ int32 money = 0;
+
+ if (!(std::count(moneyString.begin(), moneyString.end(), 'g') == 1 ||
+ std::count(moneyString.begin(), moneyString.end(), 's') == 1 ||
+ std::count(moneyString.begin(), moneyString.end(), 'c') == 1))
+ return 0; // Bad format
+
+ Tokenizer tokens(moneyString, ' ');
+ for (Tokenizer::const_iterator itr = tokens.begin(); itr != tokens.end(); ++itr)
+ {
+ std::string tokenString(*itr);
+ uint32 gCount = std::count(tokenString.begin(), tokenString.end(), 'g');
+ uint32 sCount = std::count(tokenString.begin(), tokenString.end(), 's');
+ uint32 cCount = std::count(tokenString.begin(), tokenString.end(), 'c');
+ if (gCount + sCount + cCount != 1)
+ return 0;
+
+ uint32 amount = atoi(*itr);
+ if (gCount == 1)
+ money += amount * 100 * 100;
+ else if (sCount == 1)
+ money += amount * 100;
+ else if (cCount == 1)
+ money += amount;
+ }
+
+ return money;
+}
+
uint32 TimeStringToSecs(const std::string& timestring)
{
uint32 secs = 0;