Browse Source

fixed a problem connection to an empty server

Kolja Strohm 2 years ago
parent
commit
2df497b041

+ 9 - 12
FactoryCraft/GrowingPlant.cpp

@@ -94,7 +94,7 @@ GrowingPlantBlock* GrowingPlantBlock::addGrowthState(GrowthState state)
     return this;
 }
 
-GrowingPlantlockType::GrowingPlantlockType(int typeId,
+GrowingPlantBlockType::GrowingPlantBlockType(int typeId,
     ModelInfo model,
     const char* name,
     int blockTypeAfterGrowth,
@@ -113,25 +113,22 @@ GrowingPlantlockType::GrowingPlantlockType(int typeId,
       ticksNeeded(ticksNeeded)
 {}
 
-GrowingPlantlockType* GrowingPlantlockType::setHardness(float hardness)
+GrowingPlantBlockType* GrowingPlantBlockType::setHardness(float hardness)
 {
     this->hardness = hardness;
     return this;
 }
 
-GrowingPlantlockType* GrowingPlantlockType::addGrowthState(
+GrowingPlantBlockType* GrowingPlantBlockType::addGrowthState(
     float growthPercentage, ModelInfo model)
 {
     states.add(GrowthState(growthPercentage, model));
     return this;
 }
 
-void GrowingPlantlockType::createSuperBlock(Block* zBlock, Item* zItem) const
+void GrowingPlantBlockType::createSuperBlock(Block* zBlock, Item* zItem) const
 {
-    GrowingPlantlockType* block = dynamic_cast<GrowingPlantlockType*>(zBlock);
-    if (!block)
-        throw "TreeSeblingBlockType::createSuperBlock was called with a block "
-              "witch is not an instance of TreeSeblingBlock";
+    GrowingPlantBlock* block = dynamic_cast<GrowingPlantBlock*>(zBlock);
     block->transparent = transparent;
     block->passable = passable;
     block->hardness = hardness;
@@ -141,7 +138,7 @@ void GrowingPlantlockType::createSuperBlock(Block* zBlock, Item* zItem) const
     BlockType::createSuperBlock(zBlock, zItem);
 }
 
-void GrowingPlantlockType::loadSuperBlock(
+void GrowingPlantBlockType::loadSuperBlock(
     Block* zBlock, Framework::StreamReader* zReader, int dimensionId) const
 {
     BlockType::loadSuperBlock(zBlock, zReader, dimensionId);
@@ -149,7 +146,7 @@ void GrowingPlantlockType::loadSuperBlock(
     zReader->lese((char*)&block->seblingTicks, 4);
 }
 
-void GrowingPlantlockType::saveSuperBlock(
+void GrowingPlantBlockType::saveSuperBlock(
     Block* zBlock, Framework::StreamWriter* zWriter) const
 {
     BlockType::saveSuperBlock(zBlock, zWriter);
@@ -157,12 +154,12 @@ void GrowingPlantlockType::saveSuperBlock(
     zWriter->schreibe((char*)&block->seblingTicks, 4);
 }
 
-Item* GrowingPlantlockType::createItem() const
+Item* GrowingPlantBlockType::createItem() const
 {
     return 0;
 }
 
-Block* GrowingPlantlockType::createBlock(Framework::Vec3<int> position) const
+Block* GrowingPlantBlockType::createBlock(Framework::Vec3<int> position) const
 {
     GrowingPlantBlock* block = new GrowingPlantBlock(getId(),
         zTool,

+ 6 - 6
FactoryCraft/GrowingPlant.h

@@ -3,7 +3,7 @@
 #include "Block.h"
 
 
-class GrowingPlantlockType;
+class GrowingPlantBlockType;
 
 struct GrowthState
 {
@@ -41,10 +41,10 @@ public:
     virtual Framework::Text getTargetUIML();
     GrowingPlantBlock* addGrowthState(GrowthState state);
 
-    friend GrowingPlantlockType;
+    friend GrowingPlantBlockType;
 };
 
-class GrowingPlantlockType : public BlockType
+class GrowingPlantBlockType : public BlockType
 {
 private:
     bool transparent;
@@ -70,13 +70,13 @@ protected:
     virtual Block* createBlock(Framework::Vec3<int> position) const override;
 
 public:
-    GrowingPlantlockType(int typeId,
+    GrowingPlantBlockType(int typeId,
         ModelInfo model,
         const char* name,
         int blockTypeAfterGrowth,
         const char* readableName,
         int ticksNeeded);
-    GrowingPlantlockType* setHardness(float hardness);
-    GrowingPlantlockType* addGrowthState(
+    GrowingPlantBlockType* setHardness(float hardness);
+    GrowingPlantBlockType* addGrowthState(
         float growthPercentage, ModelInfo model);
 };

+ 16 - 2
FactoryCraft/Server.cpp

@@ -65,15 +65,26 @@ FactoryCraftServer::FactoryCraftServer(InitDatei* zIni)
                 if (client->matchAuthKey(key, len))
                 {
                     if (bg)
+                    {
+                        klient->sende("\1", 1);
                         client->setBackgroundClient(klient);
+                    }
                     else
+                    {
+                        klient->sende("\1", 1);
                         client->setForegroundClient(klient);
+                    }
                     found = 1;
                     break;
                 }
             }
             LeaveCriticalSection(&cs);
-            if (!found) klient->release();
+            if (!found)
+            {
+                klient->sende("\0", 1);
+                std::cout << "client failed to pass through authorisation\n";
+                klient->release();
+            }
         }
         runningThreads--;
     });
@@ -210,6 +221,7 @@ FCKlient::~FCKlient()
 // nicht constant
 void FCKlient::setForegroundClient(SKlient* foreground)
 {
+    std::cout << "foreground client connected\n";
     this->foreground = foreground;
     foregroundReader = new NetworkReader(foreground);
     foregroundWriter = new NetworkWriter(foreground);
@@ -245,6 +257,7 @@ void FCKlient::setForegroundClient(SKlient* foreground)
 
 void FCKlient::setBackgroundClient(SKlient* background)
 {
+    std::cout << "background client connected\n";
     this->background = background;
     backgroundReader = new NetworkReader(background);
     backgroundWriter = new NetworkWriter(background);
@@ -332,7 +345,8 @@ void FCKlient::thread()
                         klient->sende("\1", 1);
                         identified = 1;
                     }
-                    klient->sende((char*)&authKeyLen, 4);
+                    short keyLen = (short)authKeyLen;
+                    klient->sende((char*)&keyLen, 2);
                     klient->sende(authKey, authKeyLen);
                     delete[] name;
                     delete[] secret;

+ 1 - 1
FactoryCraft/StaticInitializerOrder.cpp

@@ -218,7 +218,7 @@ void initializeBlockTypes()
                  "blocks.ltdb/dirt.png"}),
          "Farmland"))
         ->initializeDefault();
-    (new GrowingPlantlockType(BlockTypeEnum::WHEAT_SEED,
+    (new GrowingPlantBlockType(BlockTypeEnum::WHEAT_SEED,
          ModelInfo("grass", "plants.ltdb/wheatseeds.png", 16).setTransparent(),
          "WheatSeeds",
          BlockTypeEnum::WHEAT,