]> git.stg.codes - stg.git/blobdiff - stglibs/ia.lib/ia.cpp
Fix auth library for BE-platforms
[stg.git] / stglibs / ia.lib / ia.cpp
index 9883dbbb8d276dbc2cb30db284b1a2c257f6564f..148750d2bbe333d3f0f1ee2f1486113ba8acad94 100644 (file)
 
 //---------------------------------------------------------------------------
 
+#ifdef WIN32
+#include <winsock2.h>
+#include <windows.h>
+#include <winbase.h>
+#include <winnt.h>
+#else
+#include <fcntl.h>
+#include <netdb.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <csignal>
+#endif
+
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
 #include <cassert>
 
-#ifdef WIN32
-    #include <winsock2.h>
-    #include <windows.h>
-    #include <winbase.h>
-    #include <winnt.h>
-#else
-    #include <fcntl.h>
-    #include <netdb.h>
-    #include <arpa/inet.h>
-    #include <unistd.h>
-#endif
-
 #include "stg/common.h"
-#include "ia.h"
+#include "stg/ia.h"
 
 #define IA_NONE            (0)
 #define IA_CONNECT         (1)
 //---------------------------------------------------------------------------
 #ifndef WIN32
 #include <sys/time.h>
+void Sleep(int ms)
+{
+long long res = ms * 1000000;
+struct timespec ts = {res / 1000000000, res % 1000000000};
+nanosleep(&ts, NULL);
+}
+//---------------------------------------------------------------------------
 void * RunL(void * data)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
 
 IA_CLIENT_PROT * c = (IA_CLIENT_PROT *)data;
 static int a = 0;
 
 if (a == 0)
     {
-    usleep(50000);
+    Sleep(50);
     a = 1;
     }
 
@@ -80,11 +91,6 @@ while (c->GetNonstop())
 return NULL;
 }
 //---------------------------------------------------------------------------
-void Sleep(int ms)
-{
-usleep(ms * 1000);
-}
-//---------------------------------------------------------------------------
 long GetTickCount()
 {
 struct timeval tv;
@@ -293,14 +299,14 @@ if (!isNetPrepared)
 int db = sizeof(HDR_8);
 for (int i = 0; i < IA_LOGIN_LEN/8; i++)
     {
-    Blowfish_Encrypt(&ctxHdr, (uint32_t*)(buffer + db + i*8), (uint32_t*)(buffer + db + i*8 + 4));
+    EncodeString(buffer + db + i * 8, buffer + db + i * 8, &ctxHdr);
     }
 
 db += IA_LOGIN_LEN;
 int encLen = (len - sizeof(HDR_8) - IA_LOGIN_LEN)/8;
 for (int i = 0; i < encLen; i++)
     {
-    Blowfish_Encrypt(&ctxPass, (uint32_t*)(buffer + db), (uint32_t*)(buffer + db + 4));
+    EncodeString(buffer + db, buffer + db, &ctxPass);
     db += 8;
     }
 
@@ -325,7 +331,7 @@ if (res == -1)
 if (strcmp(buffer + 4 + sizeof(HDR_8), "ERR"))
     {
     for (int i = 0; i < len/8; i++)
-        Blowfish_Decrypt(&ctxPass, (uint32_t*)(buffer + i*8), (uint32_t*)(buffer + i*8 + 4));
+        DecodeString(buffer + i * 8, buffer + i * 8, &ctxPass);
     }
 
 return 0;