]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/serialization.cpp
Add function to get server info.
[dragonfireclient.git] / src / serialization.cpp
index 1fd75c97aae219608c67e9990ff595693cd1a07a..d30e83726f307cac9d58f83c6f4f80d93d1ebac3 100644 (file)
@@ -20,7 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "serialization.h"
 
 #include "util/serialize.h"
-#ifdef _MSC_VER
+#if defined(_WIN32) && !defined(WIN32_NO_ZLIB_WINAPI)
        #define ZLIB_WINAPI
 #endif
 #include "zlib.h"
@@ -53,7 +53,7 @@ void zerr(int ret)
     }
 }
 
-void compressZlib(SharedBuffer<u8> data, std::ostream &os)
+void compressZlib(SharedBuffer<u8> data, std::ostream &os, int level)
 {
        z_stream z;
        const s32 bufsize = 16384;
@@ -65,7 +65,7 @@ void compressZlib(SharedBuffer<u8> data, std::ostream &os)
        z.zfree = Z_NULL;
        z.opaque = Z_NULL;
 
-       ret = deflateInit(&z, -1);
+       ret = deflateInit(&z, level);
        if(ret != Z_OK)
                throw SerializationError("compressZlib: deflateInit failed");
        
@@ -94,13 +94,12 @@ void compressZlib(SharedBuffer<u8> data, std::ostream &os)
        }
 
        deflateEnd(&z);
-
 }
 
-void compressZlib(const std::string &data, std::ostream &os)
+void compressZlib(const std::string &data, std::ostream &os, int level)
 {
        SharedBuffer<u8> databuf((u8*)data.c_str(), data.size());
-       compressZlib(databuf, os);
+       compressZlib(databuf, os, level);
 }
 
 void decompressZlib(std::istream &is, std::ostream &os)
@@ -134,7 +133,8 @@ void decompressZlib(std::istream &is, std::ostream &os)
                if(z.avail_in == 0)
                {
                        z.next_in = (Bytef*)input_buffer;
-                       input_buffer_len = is.readsome(input_buffer, bufsize);
+                       is.read(input_buffer, bufsize);
+                       input_buffer_len = is.gcount();
                        z.avail_in = input_buffer_len;
                        //dstream<<"read fail="<<is.fail()<<" bad="<<is.bad()<<std::endl;
                }
@@ -167,6 +167,7 @@ void decompressZlib(std::istream &is, std::ostream &os)
                        //dstream<<"z.avail_in="<<z.avail_in<<std::endl;
                        //dstream<<"fail="<<is.fail()<<" bad="<<is.bad()<<std::endl;
                        // Unget all the data that inflate didn't take
+                       is.clear(); // Just in case EOF is set
                        for(u32 i=0; i < z.avail_in; i++)
                        {
                                is.unget();