From 63611932ebae93620386b26cfa82f7c4552b22ff Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 29 May 2011 21:11:16 +0300 Subject: player passwords and privileges in world/auth.txt --HG-- extra : rebase_source : 7260636295d9068fbeeddf4143c89f2b8a91446c --- src/utility.h | 55 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'src/utility.h') 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 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) { -- cgit v1.2.3 From 223b3793485a76f87599d39364b1003c2ca7c49c Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 31 May 2011 00:15:43 +0300 Subject: Reduced the CPU usage of the sent block selector algorithm --- src/utility.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/utility.h') diff --git a/src/utility.h b/src/utility.h index f18d31278..534aea483 100644 --- a/src/utility.h +++ b/src/utility.h @@ -244,6 +244,9 @@ inline f32 readF1000(std::istream &is) { char buf[2]; is.read(buf, 2); + // TODO: verify if this gets rid of the valgrind warning + //if(is.gcount() != 2) + // return 0; return readF1000((u8*)buf); } -- cgit v1.2.3 From aed9e809a19bffdf911f75dd9d718efb8decd2c1 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 25 Jun 2011 16:32:09 +0300 Subject: mapgen stuff --- src/utility.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/utility.h') diff --git a/src/utility.h b/src/utility.h index 534aea483..497f79fa0 100644 --- a/src/utility.h +++ b/src/utility.h @@ -1741,6 +1741,11 @@ void mysrand(unsigned seed); inline int myrand_range(int min, int max) { + if(max-min > MYRAND_MAX) + { + dstream<<"WARNING: myrand_range: max-min > MYRAND_MAX"< max) { assert(0); -- cgit v1.2.3