From c6646a4fbf19011b2c1aaea49e1fa2becfe8cc7b Mon Sep 17 00:00:00 2001
From: George Hazan <ghazan@miranda.im>
Date: Fri, 6 Jan 2017 20:37:38 +0300
Subject: adding zlib

---
 protocols/Discord/discord.vcxproj | 6 ++++++
 protocols/Discord/src/gateway.cpp | 7 ++++++-
 protocols/Discord/src/stdafx.h    | 2 ++
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/protocols/Discord/discord.vcxproj b/protocols/Discord/discord.vcxproj
index a360422c31..1a76deed6c 100644
--- a/protocols/Discord/discord.vcxproj
+++ b/protocols/Discord/discord.vcxproj
@@ -30,4 +30,10 @@
       <ExceptionHandling>Sync</ExceptionHandling>
     </ClCompile>
   </ItemDefinitionGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\libs\zlib\zlib.vcxproj">
+      <Project>{e2a369cd-eda3-414f-8ad0-e732cd7ee68c}</Project>
+      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
+    </ProjectReference>
+  </ItemGroup>
 </Project>
\ No newline at end of file
diff --git a/protocols/Discord/src/gateway.cpp b/protocols/Discord/src/gateway.cpp
index a7352d4120..adf07eff4a 100644
--- a/protocols/Discord/src/gateway.cpp
+++ b/protocols/Discord/src/gateway.cpp
@@ -146,7 +146,7 @@ void CDiscordProto::GatewayThread(void*)
 		sel.dwTimeout = 1000;
 		sel.hReadConns[0] = m_hGatewayConnection;
 		if (CallService(MS_NETLIB_SELECT, 0, (LPARAM)&sel) == 0) // timeout, send a hartbeat packet
-			GatewaySend(3, "{ \"op\":1, \"d\":(null) }");
+			GatewaySend(0, "{ \"op\":1, \"d\":(null) }");
 
 		unsigned char buf[2048];
 		int bufSize = Netlib_Recv(m_hGatewayConnection, (char*)buf+offset, _countof(buf) - offset, 0);
@@ -218,6 +218,11 @@ void CDiscordProto::GatewayThread(void*)
 		case 2: // continuation
 			if (bIsFinal) {
 				// process a packet here
+				z_stream stream = {};
+				stream.next_in = dataBuf + headerSize;
+				stream.avail_in = bufSize - headerSize;
+				deflate(&stream, true);
+
 				mir_free(dataBuf); dataBuf = NULL;
 				dataBufSize = 0;
 			}
diff --git a/protocols/Discord/src/stdafx.h b/protocols/Discord/src/stdafx.h
index 43d0077d7c..b91bf0008d 100644
--- a/protocols/Discord/src/stdafx.h
+++ b/protocols/Discord/src/stdafx.h
@@ -39,6 +39,8 @@
 #include <m_json.h>
 #include <win2k.h>
 
+#include "../../libs/zlib/src/zlib.h"
+
 extern HINSTANCE g_hInstance;
 
 #include "version.h"
-- 
cgit v1.2.3