summaryrefslogtreecommitdiff
path: root/src/utility.h
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-05-29 21:11:16 +0300
committerPerttu Ahola <celeron55@gmail.com>2011-05-29 21:11:16 +0300
commit63611932ebae93620386b26cfa82f7c4552b22ff (patch)
tree57c065bebf3ba53857dbed80e48cf67cd7e63038 /src/utility.h
parent99c2ac0125f9bbae0a4b06e6e7145f76f4dfbbf4 (diff)
downloadminetest-63611932ebae93620386b26cfa82f7c4552b22ff.tar.gz
minetest-63611932ebae93620386b26cfa82f7c4552b22ff.tar.bz2
minetest-63611932ebae93620386b26cfa82f7c4552b22ff.zip
player passwords and privileges in world/auth.txt
--HG-- extra : rebase_source : 7260636295d9068fbeeddf4143c89f2b8a91446c
Diffstat (limited to 'src/utility.h')
-rw-r--r--src/utility.h55
1 files changed, 35 insertions, 20 deletions
diff --git a/src/utility.h b/src/utility.h
index c7513e94d..f18d31278 100644
--- a/src/utility.h
+++ b/src/utility.h
@@ -1984,17 +1984,23 @@ inline std::string serializeString(const std::string &plain)
return s;
}
-/*// Reads a string with the length as the first two bytes
-inline std::string deSerializeString(const std::string encoded)
+// Creates a string with the length as the first two bytes from wide string
+inline std::string serializeWideString(const std::wstring &plain)
{
- u16 s_size = readU16((u8*)&encoded.c_str()[0]);
- if(s_size > encoded.length() - 2)
- return "";
+ //assert(plain.size() <= 65535);
+ if(plain.size() > 65535)
+ throw SerializationError("String too long for serializeString");
+ char buf[2];
+ writeU16((u8*)buf, plain.size());
std::string s;
- s.reserve(s_size);
- s.append(&encoded.c_str()[2], s_size);
+ s.append(buf, 2);
+ for(u32 i=0; i<plain.size(); i++)
+ {
+ writeU16((u8*)buf, plain[i]);
+ s.append(buf, 2);
+ }
return s;
-}*/
+}
// Reads a string with the length as the first two bytes
inline std::string deSerializeString(std::istream &is)
@@ -2014,6 +2020,27 @@ inline std::string deSerializeString(std::istream &is)
return s;
}
+// Reads a wide string with the length as the first two bytes
+inline std::wstring deSerializeWideString(std::istream &is)
+{
+ char buf[2];
+ is.read(buf, 2);
+ if(is.gcount() != 2)
+ throw SerializationError("deSerializeString: size not read");
+ u16 s_size = readU16((u8*)buf);
+ if(s_size == 0)
+ return L"";
+ std::wstring s;
+ s.reserve(s_size);
+ for(u32 i=0; i<s_size; i++)
+ {
+ is.read(&buf[0], 2);
+ wchar_t c16 = readU16((u8*)buf);
+ s.append(&c16, 1);
+ }
+ return s;
+}
+
// Creates a string with the length as the first four bytes
inline std::string serializeLongString(const std::string &plain)
{
@@ -2025,18 +2052,6 @@ inline std::string serializeLongString(const std::string &plain)
return s;
}
-/*// Reads a string with the length as the first four bytes
-inline std::string deSerializeLongString(const std::string encoded)
-{
- u32 s_size = readU32((u8*)&encoded.c_str()[0]);
- if(s_size > encoded.length() - 4)
- return "";
- std::string s;
- s.reserve(s_size);
- s.append(&encoded.c_str()[4], s_size);
- return s;
-}*/
-
// Reads a string with the length as the first four bytes
inline std::string deSerializeLongString(std::istream &is)
{