Bläddra i källkod

fixed a problem connection to an empty server

Kolja Strohm 2 år sedan
förälder
incheckning
6fb9c01ab9
2 ändrade filer med 10 tillägg och 2 borttagningar
  1. 8 2
      FactoryCraft/FactoryClient.cpp
  2. 2 0
      FactoryCraft/World.cpp

+ 8 - 2
FactoryCraft/FactoryClient.cpp

@@ -26,6 +26,7 @@ FactoryClient::~FactoryClient()
 
 void FactoryClient::loadServerInfo()
 {
+    std::cout << "downloading server type information\n";
     // receive type information
     for (int i = 0; i < blockTypeCount; i++)
         blockTypes[i]->release();
@@ -176,8 +177,8 @@ int FactoryClient::join(
             secret = buffer;
             delete[] buffer;
         }
-        int keyLen;
-        client->getNachricht((char*)&keyLen, 4);
+        short keyLen;
+        client->getNachricht((char*)&keyLen, 2);
         char* key = new char[keyLen];
         client->getNachricht(key, keyLen);
         foreground = new Klient();
@@ -235,6 +236,11 @@ int FactoryClient::join(
         bg = 1;
         if (!background->sende((char*)&bg, 1)) return 201;
         backgroundReader = new NetworkReader(background);
+        char res;
+        foregroundReader->lese(&res, 1);
+        if (res != 1) return 403;
+        backgroundReader->lese(&res, 1);
+        if (res != 1) return 403;
         client->trenne();
         loadServerInfo();
         return 200;

+ 2 - 0
FactoryCraft/World.cpp

@@ -202,6 +202,7 @@ void World::thread()
             update(0);
             Sleep(10);
         }
+        std::cout << "foreground connection lost\n";
     });
     while (client->isConnected())
     {
@@ -214,6 +215,7 @@ void World::thread()
         zScreenPtr->unlock();
         update(1);
         Sleep(10);
+        std::cout << "background connection lost\n";
     }
 }