summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorRogier Polak <rogier.l.a.polak@gmail.com>2007-03-10 11:52:51 +0000
committerRogier Polak <rogier.l.a.polak@gmail.com>2007-03-10 11:52:51 +0000
commit8b56248ef58323c6e28264b5317d39c22c59db04 (patch)
tree40505a0413f414b654d2d541fe4839803736036a /src/utils
parent5eaec8f7b99feb05b605dd0c43e838b2200389b3 (diff)
downloadmanaserv-8b56248ef58323c6e28264b5317d39c22c59db04.tar.gz
manaserv-8b56248ef58323c6e28264b5317d39c22c59db04.tar.bz2
manaserv-8b56248ef58323c6e28264b5317d39c22c59db04.tar.xz
manaserv-8b56248ef58323c6e28264b5317d39c22c59db04.zip
Added a utility function for creating magic_tokens
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/logger.h4
-rw-r--r--src/utils/tokendispenser.cpp38
-rw-r--r--src/utils/tokendispenser.hpp47
3 files changed, 87 insertions, 2 deletions
diff --git a/src/utils/logger.h b/src/utils/logger.h
index a7f7c8f6..29147b46 100644
--- a/src/utils/logger.h
+++ b/src/utils/logger.h
@@ -158,8 +158,8 @@ class Logger
#define LOG(level, msg) \
do if (::utils::Logger::mVerbosity >= ::utils::Logger::level) { \
- std::ostringstream os; \
- os << msg; \
+ std::ostringstream os; \
+ os << msg; \
::utils::Logger::output(os.str(), ::utils::Logger::level); \
} while (0)
diff --git a/src/utils/tokendispenser.cpp b/src/utils/tokendispenser.cpp
new file mode 100644
index 00000000..50148144
--- /dev/null
+++ b/src/utils/tokendispenser.cpp
@@ -0,0 +1,38 @@
+/*
+ * The Mana World Server
+ * Copyright 2007 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with The Mana World; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "utils/tokendispenser.hpp"
+
+#include <cstdlib>
+
+std::string utils::getMagicToken()
+{
+ std::string magic_token(MAGIC_TOKEN_LENGTH, ' ');
+
+ for (int i = 0; i < MAGIC_TOKEN_LENGTH; ++i)
+ {
+ // A random integer with uniform distribution in the interval [1, 127]
+ magic_token[i] = 1 + std::rand() % 127;
+ }
+
+ return magic_token;
+}
diff --git a/src/utils/tokendispenser.hpp b/src/utils/tokendispenser.hpp
new file mode 100644
index 00000000..a6f0b3ee
--- /dev/null
+++ b/src/utils/tokendispenser.hpp
@@ -0,0 +1,47 @@
+/*
+ * The Mana World Server
+ * Copyright 2007 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with The Mana World; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMWSERV_TOKENDISPENSER_HPP
+#define _TMWSERV_TOKENDISPENSER_HPP
+
+#define MAGIC_TOKEN_LENGTH 32
+
+#include <string>
+
+namespace utils
+{
+ /**
+ * \brief Returns a magic_token.
+ *
+ * The tokens are used for spanning a user's session across multiple
+ * servers.
+ * NOTE: Uniqueness is not guaranteed, store the account- or characterId
+ * with the token if that is an issue.
+ * NOTE: Not passed-by-reference by design.
+ * NOTE: Store the token in a variable in this namespace if you want to
+ * avoid 1 copy operation per use.
+ */
+ std::string getMagicToken();
+
+} // namespace utils
+
+#endif // _TMWSERV_TOKENDISPENSER_HPP