summaryrefslogtreecommitdiff
path: root/src/net/eathena/chathandler.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-09-08 19:39:32 +0300
committerAndrei Karas <akaras@inbox.ru>2014-09-08 19:39:32 +0300
commit571ff6e1401876cb775b827f6af25e14b1f59c6f (patch)
tree4cf36adcda2779a40f1f1f9a46b7a787f2834782 /src/net/eathena/chathandler.cpp
parent15e87a84d62cc0b0077b25c235824879bde66a41 (diff)
downloadplus-571ff6e1401876cb775b827f6af25e14b1f59c6f.tar.gz
plus-571ff6e1401876cb775b827f6af25e14b1f59c6f.tar.bz2
plus-571ff6e1401876cb775b827f6af25e14b1f59c6f.tar.xz
plus-571ff6e1401876cb775b827f6af25e14b1f59c6f.zip
Improve string to int parsing.
Diffstat (limited to 'src/net/eathena/chathandler.cpp')
-rw-r--r--src/net/eathena/chathandler.cpp19
1 files changed, 4 insertions, 15 deletions
diff --git a/src/net/eathena/chathandler.cpp b/src/net/eathena/chathandler.cpp
index eed77a52c..d55a93dbb 100644
--- a/src/net/eathena/chathandler.cpp
+++ b/src/net/eathena/chathandler.cpp
@@ -157,13 +157,13 @@ void ChatHandler::sendRaw(const std::string &args) const
if (pos != std::string::npos)
{
str = line.substr(0, pos);
- outMsg = new MessageOut(static_cast<int16_t>(atoi(str.c_str())));
+ outMsg = new MessageOut(static_cast<int16_t>(parseNumber(str)));
line = line.substr(pos + 1);
pos = line.find(" ");
}
else
{
- outMsg = new MessageOut(static_cast<int16_t>(atoi(line.c_str())));
+ outMsg = new MessageOut(static_cast<int16_t>(parseNumber(line)));
delete outMsg;
return;
}
@@ -186,19 +186,8 @@ void ChatHandler::processRaw(MessageOut &restrict outMsg,
if (line.size() < 2)
return;
- char cmd = tolower(line[0]);
- int i = 0;
- std::string str = line.substr(1);
- int idx = 0;
- if (strStartWith(str, "0x"))
- idx = 2;
- else if (str[0] == 'h' || str[0] == 'x')
- idx = 1;
- if (idx > 0)
- sscanf(str.substr(idx).c_str(), "%10x", &i);
- else
- i = atoi(str.c_str());
- switch (cmd)
+ const int i = parseNumber(line.substr(1));
+ switch (tolower(line[0]))
{
case 'b':
{