Răsfoiți Sursa

add player registry and dont use player name as filename for bedder security

Kolja Strohm 1 an în urmă
părinte
comite
7a99dc4a26

+ 2 - 4
FactoryCraft/ChatCommand.cpp

@@ -40,8 +40,7 @@ Framework::Text ChatCommand::getHelp() const
     }
     if (description.getLength() > 0)
     {
-        result += "\n    ";
-        result += description;
+        result.append() << "\n    " << description;
     }
     for (ChatCommandParameter* param : params)
     {
@@ -51,8 +50,7 @@ Framework::Text ChatCommand::getHelp() const
             if (param->isOptional()) result += "[";
             result += param->getName();
             if (param->isOptional()) result += "]";
-            result += " - ";
-            result += param->getDescription();
+            result.append() << " - " << param->getDescription();
         }
     }
     return result;

+ 12 - 14
FactoryCraft/ChatCommandExecutor.cpp

@@ -1,15 +1,15 @@
 #include "ChatCommandExecutor.h"
 
 #include "Game.h"
-#include "SaveCommand.h"
 #include "GrantCommand.h"
+#include "SaveCommand.h"
 
 ChatCommandExecutor::ChatCommandExecutor()
     : ReferenceCounter()
 {
     knownCommands.add(new SaveCommand());
     knownCommands.add(new CrantCommand());
-} 
+}
 
 bool ChatCommandExecutor::execute(Framework::Text line, Entity* zActor)
 {
@@ -98,8 +98,7 @@ bool ChatCommandExecutor::execute(Framework::Text line, Entity* zActor)
                         {
                             Framework::Text error
                                 = "Illegal parameter at position ";
-                            error += (index + 1);
-                            error += ": ";
+                            error.append() << (index + 1) << ": ";
                             if (params.getEintragAnzahl() > index)
                             {
                                 error += *params.z(index);
@@ -108,8 +107,7 @@ bool ChatCommandExecutor::execute(Framework::Text line, Entity* zActor)
                             {
                                 error += "(no parameter was given)";
                             }
-                            error += "\n";
-                            error += command->getHelp();
+                            error.append() << "\n" << command->getHelp();
                             Game::INSTANCE->zChat()->sendMessageTo(
                                 error, zActor, Chat::CHANNEL_ERROR);
                             return true;
@@ -120,9 +118,8 @@ bool ChatCommandExecutor::execute(Framework::Text line, Entity* zActor)
                 {
                     Framework::Text error = "Illegal number of parameters. "
                                             "First unknown parameter: ";
-                    error += *params.z(index);
-                    error += "\n";
-                    error += command->getHelp();
+                    error.append() << *params.z(index) << "\n"
+                                   << command->getHelp();
                     Game::INSTANCE->zChat()->sendMessageTo(
                         error, zActor, Chat::CHANNEL_ERROR);
                     return true;
@@ -133,11 +130,12 @@ bool ChatCommandExecutor::execute(Framework::Text line, Entity* zActor)
                 {
                     Framework::Text error
                         = "This command requires a security level of at least ";
-                    error += command->getSecurityLevel(params);
-                    error += ". You have currently a security level of ";
-                    error += zActor->getChatSecurityLevel();
-                    error += ". Ask someone with the required security lavel "
-                             "to grant you the same level.";
+                    error.append()
+                        << command->getSecurityLevel(params)
+                        << ". You have currently a security level of "
+                        << zActor->getChatSecurityLevel()
+                        << ". Ask someone with the required security lavel to "
+                           "grant you the same level.";
                     Game::INSTANCE->zChat()->sendMessageTo(
                         error, zActor, Chat::CHANNEL_ERROR);
                     return true;

+ 1 - 1
FactoryCraft/Dimension.cpp

@@ -518,7 +518,7 @@ void Dimension::save(Text worldDir) const
             {
                 Datei pFile;
                 pFile.setDatei(
-                    worldDir + "/player/" + ((Player*)entity)->getName());
+                    worldDir + "/player/" + Game::INSTANCE->getPlayerId(((Player*)entity)->getName()));
                 if (pFile.open(Datei::Style::schreiben))
                     StaticRegistry<EntityType>::INSTANCE
                         .zElement(EntityTypeEnum::PLAYER)

+ 2 - 0
FactoryCraft/FactoryCraft.vcxproj

@@ -151,6 +151,7 @@
     <ClInclude Include="NoiseInterpolator.h" />
     <ClInclude Include="Player.h" />
     <ClInclude Include="PlayerHand.h" />
+    <ClInclude Include="PlayerRegister.h" />
     <ClInclude Include="RandNoise.h" />
     <ClInclude Include="Recipie.h" />
     <ClInclude Include="RecipieList.h" />
@@ -225,6 +226,7 @@
     <ClCompile Include="NoiseInterpolator.cpp" />
     <ClCompile Include="Player.cpp" />
     <ClCompile Include="PlayerHand.cpp" />
+    <ClCompile Include="PlayerRegister.cpp" />
     <ClCompile Include="RecipieList.cpp" />
     <ClCompile Include="RandNoise.cpp" />
     <ClCompile Include="Recipie.cpp" />

+ 6 - 0
FactoryCraft/FactoryCraft.vcxproj.filters

@@ -309,6 +309,9 @@
     <ClInclude Include="GrantCommand.h">
       <Filter>chat\commands</Filter>
     </ClInclude>
+    <ClInclude Include="PlayerRegister.h">
+      <Filter>game</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Server.cpp">
@@ -524,5 +527,8 @@
     <ClCompile Include="GrantCommand.cpp">
       <Filter>chat\commands</Filter>
     </ClCompile>
+    <ClCompile Include="PlayerRegister.cpp">
+      <Filter>game</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 20 - 60
FactoryCraft/Game.cpp

@@ -12,15 +12,6 @@
 
 using namespace Framework;
 
-char* randomKey(int& len)
-{
-    len = 1024 + (int)(((double)rand() / RAND_MAX - 0.5) * 512);
-    char* key = new char[len];
-    for (int i = 0; i < len; i++)
-        key[i] = (char)((((double)rand() / RAND_MAX) * 254) + 1);
-    return key;
-}
-
 GameClient::GameClient(Player* zPlayer, FCKlient* client)
     : Thread(),
       zPlayer(zPlayer),
@@ -299,6 +290,7 @@ Game::Game(Framework::Text name, Framework::Text worldsDir)
       generator(0),
       loader(0),
       chat(0),
+      playerRegister(new PlayerRegister(path)),
       totalTickTime(0),
       tickCounter(0)
 {
@@ -323,6 +315,7 @@ Game::~Game()
     generator->release();
     loader->release();
     chat->release();
+    playerRegister->release();
 }
 
 void Game::initialize()
@@ -376,7 +369,7 @@ void Game::thread()
                     Chat::CHANNEL_INFO);
                 Datei pFile;
                 pFile.setDatei(
-                    path + "/player/" + player->zEntity()->getName());
+                    path + "/player/" + getPlayerId(player->zEntity()->getName()));
                 pFile.erstellen();
                 if (pFile.open(Datei::Style::schreiben))
                     StaticRegistry<EntityType>::INSTANCE
@@ -558,8 +551,8 @@ void Game::api(Framework::InMemoryBuffer* zRequest, GameClient* zOrigin)
         }
     case 6:
         { // chat message
-            short mLen = 0;
-            chat->chatApi(zRequest, zOrigin->zEntity() , response);
+            chat->chatApi(zRequest, zOrigin->zEntity(), response);
+            break;
         }
     default:
         std::cout << "received unknown api request in game with type "
@@ -635,71 +628,32 @@ bool Game::requestWorldUpdate(WorldUpdate* update)
 
 bool Game::checkPlayer(Framework::Text name, Framework::Text secret)
 {
-    Datei pFile;
-    pFile.setDatei(path + "/player/" + name + ".key");
-    if (!pFile.existiert())
-    {
-        if (!secret.getLength())
-            return 1;
-        else
-        {
-            std::cout << "player " << name.getText()
-                      << " tryed to connect with an invalid secret.\n";
-            return 0;
-        }
-    }
-    pFile.open(Datei::Style::lesen);
-    char* buffer = new char[(int)pFile.getSize()];
-    pFile.lese(buffer, (int)pFile.getSize());
-    bool eq = 1;
-    int sLen = secret.getLength();
-    for (int i = 0; i < pFile.getSize();
-         i++) // !!SECURITY!! runtime should not be dependent on the position of
-              // the first unequal character in the secret
-        eq &= buffer[i] == (sLen > i ? secret[i] : ~buffer[i]);
-    delete[] buffer;
-    pFile.close();
-    if (!eq)
+    if (playerRegister->checkSecret(name, secret))
+        return 1;
+    else
     {
         std::cout << "player " << name.getText()
-                  << " tryed to connect with an invalid secret.\n";
+                    << " tryed to connect with an invalid secret.\n";
+        return 0;
     }
-    return eq;
 }
 
 bool Game::existsPlayer(Framework::Text name)
 {
-    Datei pFile;
-    pFile.setDatei(path + "/player/" + name + ".key");
-    return pFile.existiert();
+    return playerRegister->hasPlayer(name);
 }
 
 Framework::Text Game::createPlayer(Framework::Text name)
 {
-    Datei pFile;
-    pFile.setDatei(path + "/player/" + name + ".key");
-    if (!pFile.existiert())
-    {
-        pFile.erstellen();
-        int keyLen;
-        char* key = randomKey(keyLen);
-        pFile.open(Datei::Style::schreiben);
-        pFile.schreibe(key, keyLen);
-        pFile.close();
-        Text res = "";
-        for (int i = 0; i < keyLen; i++)
-            res.append(key[i]);
-        delete[] key;
-        return res;
-    }
-    return "";
+    return playerRegister->addPlayer(name);
 }
 
 GameClient* Game::addPlayer(FCKlient* client, Framework::Text name)
 {
     cs.lock();
+    int id = playerRegister->getPlayerId(name);
     Datei pFile;
-    pFile.setDatei(path + "/player/" + name);
+    pFile.setDatei(path + "/player/" + id);
     Player* player;
     bool isNew = 0;
     if (!pFile.existiert() || !pFile.open(Datei::Style::lesen))
@@ -872,6 +826,7 @@ void Game::save() const
     d.open(Datei::Style::schreiben);
     d.schreibe((char*)&nextEntityId, 4);
     d.close();
+    playerRegister->save();
     for (auto dim : *dimensions)
         dim->save(path);
     chat->save();
@@ -979,4 +934,9 @@ Player* Game::zPlayerByName(const char* name) const
         }
     }
     return 0;
+}
+
+int Game::getPlayerId(const char* name) const
+{
+    return playerRegister->getPlayerId(name);
 }

+ 3 - 2
FactoryCraft/Game.h

@@ -17,11 +17,10 @@
 #include "WorldGenerator.h"
 #include "WorldLoader.h"
 #include "WorldUpdate.h"
+#include "PlayerRegister.h"
 
 class FCKlient;
 
-char* randomKey(int& len);
-
 class GameClient : public Framework::Thread
 {
 private:
@@ -90,6 +89,7 @@ private:
     WorldLoader* loader;
     RecipieLoader recipies;
     Chat* chat;
+    PlayerRegister* playerRegister;
     double totalTickTime;
     int tickCounter;
 
@@ -137,6 +137,7 @@ public:
     TickOrganizer* zTickOrganizer() const;
     Chat* zChat() const;
     Player* zPlayerByName(const char* name) const;
+    int getPlayerId(const char* name) const;
 
     static Game* INSTANCE;
     static Critical INSTANCE_CS;

+ 1 - 3
FactoryCraft/GrantCommand.cpp

@@ -24,9 +24,7 @@ void CrantCommand::execute(
     {
         zTarget->setChatSecurityLevel(securityLevel);
         Text message = "The security level of player ";
-        message += *params.z(0);
-        message += " is now set to ";
-        message += securityLevel;
+        message.append() << *params.z(0) << " is now set to " << securityLevel;
         Game::INSTANCE->zChat()->sendMessageTo(
             message, zActor, Chat::CHANNEL_INFO);
     }

+ 5 - 14
FactoryCraft/ItemFilter.cpp

@@ -56,21 +56,13 @@ bool CombinedItemFilter::matchTargetSlot(ItemSlot* zSlot) const
 Framework::Text CombinedItemFilter::getLogicUIML() const
 {
     Framework::Text result = "<operator result_0_0=\"";
-    result += (int)op(0, 0);
-    result += "\" result_0_1=\"";
-    result += (int)op(0, 1);
-    result += "\" result_1_0=\"";
-    result += (int)op(1, 0);
-    result += "\" result_1_1=\"";
-    result += (int)op(1, 1);
-    result += "\">";
-    result += filterA->getLogicUIML();
-    result += filterB->getLogicUIML();
-    result += "</operator>";
+    result.append() << (int)op(0, 0) << "\" result_0_1=\"" << (int)op(0, 1)
+                    << "\" result_1_0=\"" << (int)op(1, 0) << "\" result_1_1=\""
+                    << (int)op(1, 1) << "\">" << filterA->getLogicUIML()
+                    << filterB->getLogicUIML() << "</operator>";
     return result;
 }
 
-
 AnyItemFilter::AnyItemFilter()
     : ItemFilter()
 {}
@@ -98,8 +90,7 @@ bool TypeItemFilter::matchItem(const Item* zItem) const
 Framework::Text TypeItemFilter::getLogicUIML() const
 {
     Framework::Text result = "<attribute name=\"Type\" operator=\"=\" value=\"";
-    result += zType->getId();
-    result += "\"/>";
+    result.append() << zType->getId() << "\"/>";
     return result;
 }
 

+ 26 - 37
FactoryCraft/Player.cpp

@@ -48,49 +48,38 @@ Framework::Text Player::getInventoryUIML()
     Framework::Text result
         = "<dialog id=\"player_inventory\" title=\"Inventory\" width=\"610\" "
           "height=\"450\">";
-
-    result += "<craftingGrid id=\"crafting\" margin-top=\"9\" "
-              "align-top=\"start\" align-left=\"start\" margin-left=\"9\" "
-              "width=\"282\" height=\"172\" rowSize=\"3\" colSize=\"3\" "
-              "numOutputSlots=\"1\" target=\"";
-    result += getId();
-    result += "\"/>";
-
-    result += "<inventory id=\"inventory\" margin-bottom=\"18\" "
-              "align-bottom=\"item_bar\" align-left=\"start\" "
-              "margin-left=\"9\" width=\"592\" height=\"172\" rowSize=\"10\" "
-              "numSlots=\"30\" slotNameFilter=\"Inventory\" target=\"";
-    result += getId();
-    result += "\"/>";
-
-    result += "<inventory id=\"item_bar\" margin-bottom=\"9\" "
-              "align-bottom=\"end\" align-left=\"start\" margin-left=\"9\" "
-              "width=\"592\" height=\"52\" rowSize=\"10\" numSlots=\"10\" "
-              "slotNameFilter=\"ItemBar\" target=\"";
-    result += getId();
-    result += "\"/>";
-
-    result += "</dialog>";
+    result.append()
+        << "<craftingGrid id=\"crafting\" margin-top=\"9\" "
+           "align-top=\"start\" align-left=\"start\" margin-left=\"9\" "
+           "width=\"282\" height=\"172\" rowSize=\"3\" colSize=\"3\" "
+           "numOutputSlots=\"1\" target=\""
+        << getId() << "\"/>"
+        << "<inventory id=\"inventory\" margin-bottom=\"18\" "
+           "align-bottom=\"item_bar\" align-left=\"start\" "
+           "margin-left=\"9\" width=\"592\" height=\"172\" rowSize=\"10\" "
+           "numSlots=\"30\" slotNameFilter=\"Inventory\" target=\""
+        << getId() << "\"/>"
+        << "<inventory id=\"item_bar\" margin-bottom=\"9\" "
+           "align-bottom=\"end\" align-left=\"start\" margin-left=\"9\" "
+           "width=\"592\" height=\"52\" rowSize=\"10\" numSlots=\"10\" "
+           "slotNameFilter=\"ItemBar\" target=\""
+        << getId() << "\"/>"
+        << "</dialog>";
     return result;
 }
 
 Framework::Text Player::getPlayerGUI()
 {
     Framework::Text result = "<gui id=\"player_gui\">";
-
-    result
-        += "<itemBar id=\"gui_item_bar\" margin-bottom=\"9\" "
+    result.append()
+        << "<itemBar id=\"gui_item_bar\" margin-bottom=\"9\" "
            "align-bottom=\"end\" align-left=\"center\" width=\"592\" "
-           "height=\"52\" rowSize=\"10\" slotNameFilter=\"ItemBar\" target=\"";
-    result += getId();
-    result += "\"/>";
-    result
-        += "<statusBars id=\"gui_status_bars\" margin-bottom=\"9\" "
-           "align-bottom=\"gui_item_bar\" align-left=\"center\" target=\"";
-    result += getId();
-    result += "\"/>";
-
-    result += "</gui>";
+           "height=\"52\" rowSize=\"10\" slotNameFilter=\"ItemBar\" target=\""
+        << getId() << "\"/>"
+        << "<statusBars id=\"gui_status_bars\" margin-bottom=\"9\" "
+           "align-bottom=\"gui_item_bar\" align-left=\"center\" target=\""
+        << getId() << "\"/>"
+        << "</gui>";
     return result;
 }
 
@@ -352,7 +341,7 @@ void Player::playerApi(
             if (target) target->applyCurrentRecipie();
             break;
         }
-        case 8: // request left hand position
+    case 8: // request left hand position
         {
             NetworkMessage* msg = new NetworkMessage();
             msg->addressGui("gui_item_bar");

+ 164 - 0
FactoryCraft/PlayerRegister.cpp

@@ -0,0 +1,164 @@
+#include "PlayerRegister.h"
+
+#include <Datei.h>
+
+Framework::Text randomSecret()
+{
+    int len = 1024 + (int)(((double)rand() / RAND_MAX - 0.5) * 512);
+    char* key = new char[len + 1];
+    for (int i = 0; i < len; i++)
+        key[i] = (char)((((double)rand() / RAND_MAX) * 254) + 1);
+    key[len] = 0;
+    Framework::Text secret = key;
+    delete[] key;
+    return secret;
+}
+
+RegisteredPlayer::RegisteredPlayer(int id, Framework::Text name)
+    : Framework::ReferenceCounter(),
+      id(id),
+      name(name),
+      secret(randomSecret())
+{}
+
+RegisteredPlayer::RegisteredPlayer(Framework::StreamReader* zReader)
+    : Framework::ReferenceCounter()
+{
+    zReader->lese((char*)&id, 4);
+    char len;
+    zReader->lese(&len, 1);
+    char* buffer = new char[len + 1];
+    zReader->lese(buffer, len);
+    buffer[(int)len] = 0;
+    name = buffer;
+    delete[] buffer;
+    short sLen;
+    zReader->lese((char*)&sLen, 2);
+    buffer = new char[sLen + 1];
+    zReader->lese(buffer, sLen);
+    buffer[sLen] = 0;
+    secret = buffer;
+    delete[] buffer;
+}
+
+int RegisteredPlayer::getId() const {
+    return id;
+}
+
+Framework::Text RegisteredPlayer::getName() const {
+    return name;
+}
+
+Framework::Text RegisteredPlayer::getSecret() const {
+    return secret;
+}
+
+void RegisteredPlayer::save(Framework::StreamWriter* zWriter) const
+{
+    zWriter->schreibe((char*)&id, 4);
+    char len = (char)name.getLength();
+    zWriter->schreibe(&len, 1);
+    zWriter->schreibe(name.getText(), len);
+    short sLen = (short)secret.getLength();
+    zWriter->schreibe((char*)&sLen, 2);
+    zWriter->schreibe(secret.getText(), sLen);
+}
+
+PlayerRegister::PlayerRegister(Framework::Text worldPath)
+    : Framework::ReferenceCounter(),
+      path(worldPath + "/player/players.reg")
+{
+    Framework::Datei regDat;
+    regDat.setDatei(path);
+    if (!regDat.existiert())
+    {
+        regDat.erstellen();
+    }
+    regDat.open(Framework::Datei::Style::lesen);
+    while (!regDat.istEnde())
+    {
+        RegisteredPlayer* p = new RegisteredPlayer(&regDat);
+        players.add(p);
+    }
+    regDat.close();
+}
+
+Framework::Text PlayerRegister::addPlayer(Framework::Text name) {
+    cs.lock();
+    int nextId = 0;
+    for (RegisteredPlayer* player : players)
+    {
+        nextId = MAX(nextId, player->getId() + 1);
+        if (player->getName().istGleich(name))
+        {
+            cs.unlock();
+            return "";
+        }
+    }
+    RegisteredPlayer* p = new RegisteredPlayer(nextId, name);
+    players.add(p);
+    cs.unlock();
+    return p->getSecret();
+}
+
+bool PlayerRegister::hasPlayer(Framework::Text name)
+{
+    cs.lock();
+    for (RegisteredPlayer* player : players)
+    {
+        if (player->getName().istGleich(name))
+        {
+            cs.unlock();
+            return 1;
+        }
+    }
+    cs.unlock();
+    return 0;
+}
+
+int PlayerRegister::getPlayerId(Framework::Text name) {
+    cs.lock();
+    for (RegisteredPlayer* player : players)
+    {
+        if (player->getName().istGleich(name))
+        {
+            cs.unlock();
+            return player->getId();
+        }
+    }
+    cs.unlock();
+    return -1;
+}
+
+bool PlayerRegister::checkSecret(Framework::Text name, Framework::Text secret)
+{
+    cs.lock();
+    for (RegisteredPlayer* player : players)
+    {
+        if (player->getName().istGleich(name))
+        {
+            cs.unlock();
+            return player->getSecret().istGleich(secret);
+        }
+    }
+    cs.unlock();
+    return secret.getLength() == 0; // new player
+}
+
+void PlayerRegister::save()
+{
+    cs.lock();
+    Framework::Datei regDat;
+    regDat.setDatei(path);
+    if (!regDat.existiert())
+    {
+        regDat.erstellen();
+    }
+    regDat.open(Framework::Datei::Style::schreiben);
+    for (RegisteredPlayer* player : players)
+    {
+        player->save(&regDat);
+    }
+    regDat.close();
+    cs.unlock();
+}

+ 42 - 0
FactoryCraft/PlayerRegister.h

@@ -0,0 +1,42 @@
+#pragma once
+
+#include <Text.h>
+#include <Array.h>
+#include <Writer.h>
+#include <Critical.h>
+
+Framework::Text randomSecret();
+
+class RegisteredPlayer : public Framework::ReferenceCounter
+{
+private:
+    int id;
+    Framework::Text name;
+    Framework::Text secret;
+
+public:
+    RegisteredPlayer(int id, Framework::Text name);
+    RegisteredPlayer(Framework::StreamReader* zReader);
+    
+    int getId() const;
+    Framework::Text getName() const;
+    Framework::Text getSecret() const;
+    void save(Framework::StreamWriter* zWriter) const;
+};
+
+class PlayerRegister : public Framework::ReferenceCounter
+{
+private:
+    Framework::RCArray<RegisteredPlayer> players;
+    Framework::Critical cs;
+    Framework::Text path;
+    
+public:
+    PlayerRegister(Framework::Text worldPath);
+   
+    Framework::Text addPlayer(Framework::Text name);
+    bool hasPlayer(Framework::Text name);
+    int getPlayerId(Framework::Text name);
+    bool checkSecret(Framework::Text name, Framework::Text secret);
+    void save();
+};

+ 25 - 46
FactoryCraft/Recipie.cpp

@@ -84,14 +84,12 @@ Framework::Text UnshapedRecipie::getRecipieUIML()
     Framework::Text result = "<recipie type=\"unshaped\"><ingredients>";
     for (int i = 0; i < filters.getEintragAnzahl(); i++)
     {
-        result += "<ingredient amount=\"";
-        result += inputAmount.get(i);
-        result += "\">";
+        result.append() << "<ingredient amount=\"" << inputAmount.get(i)
+                        << "\">";
         if (filters.z(i))
         {
-            result += "<logic>";
-            result += filters.z(i)->getLogicUIML();
-            result += "</logic>";
+            result.append()
+                << "<logic>" << filters.z(i)->getLogicUIML() << "</logic>";
         }
         result += "</ingredient>";
         // TODO: add modifiers
@@ -99,21 +97,14 @@ Framework::Text UnshapedRecipie::getRecipieUIML()
     result += "</ingredients><outputs>";
     for (int i = 0; i < outputs.getEintragAnzahl(); i++)
     {
-        result += "<output amount=\"";
-        result += outputAmount.get(i);
-        result += "\" itemType=\"";
-        result += outputs.z(i)->zItemType()->getId();
-        result += "\" hp=\"";
-        result += outputs.z(i)->getHp();
-        result += "\" durability=\"";
-        result += outputs.z(i)->getDurability();
-        result += "\" maxHp=\"";
-        result += outputs.z(i)->getMaxHp();
-        result += "\" maxDurability=\"";
-        result += outputs.z(i)->getMaxDurability();
-        result += "\">";
-        result += outputs.z(i)->getTooltipUIML();
-        result += "</output>";
+        result.append() << "<output amount=\"" << outputAmount.get(i)
+                        << "\" itemType=\""
+                        << outputs.z(i)->zItemType()->getId() << "\" hp=\""
+                        << outputs.z(i)->getHp() << "\" durability=\""
+                        << outputs.z(i)->getDurability() << "\" maxHp=\""
+                        << outputs.z(i)->getMaxHp() << "\" maxDurability=\""
+                        << outputs.z(i)->getMaxDurability() << "\">"
+                        << outputs.z(i)->getTooltipUIML() << "</output>";
     }
     result += "</outputs></recipie>";
     return result;
@@ -171,20 +162,15 @@ void ShapedRecipie::apply(CraftingStorage* zStorage)
 Framework::Text ShapedRecipie::getRecipieUIML()
 {
     Framework::Text result = "<recipie type=\"shaped\" width=\"";
-    result += width;
-    result += "\" height=\"";
-    result += height;
-    result += "\"><ingredients>";
+    result.append() << width << "\" height=\"" << height << "\"><ingredients>";
     for (int i = 0; i < filters.getEintragAnzahl(); i++)
     {
-        result += "<ingredient amount=\"";
-        result += inputAmount.get(i);
-        result += "\">";
+        result.append() << "<ingredient amount=\"" << inputAmount.get(i)
+                        << "\">";
         if (filters.z(i))
         {
-            result += "<logic>";
-            result += filters.z(i)->getLogicUIML();
-            result += "</logic>";
+            result.append()
+                << "<logic>" << filters.z(i)->getLogicUIML() << "</logic>";
         }
         result += "</ingredient>";
         // TODO: add modifiers
@@ -192,21 +178,14 @@ Framework::Text ShapedRecipie::getRecipieUIML()
     result += "</ingredients><outputs>";
     for (int i = 0; i < outputs.getEintragAnzahl(); i++)
     {
-        result += "<output amount=\"";
-        result += outputAmount.get(i);
-        result += "\" itemType=\"";
-        result += outputs.z(i)->zItemType()->getId();
-        result += "\" hp=\"";
-        result += outputs.z(i)->getHp();
-        result += "\" durability=\"";
-        result += outputs.z(i)->getDurability();
-        result += "\" maxHp=\"";
-        result += outputs.z(i)->getMaxHp();
-        result += "\" maxDurability=\"";
-        result += outputs.z(i)->getMaxDurability();
-        result += "\">";
-        result += outputs.z(i)->getTooltipUIML();
-        result += "</output>";
+        result.append() << "<output amount=\"" << outputAmount.get(i)
+                        << "\" itemType=\""
+                        << outputs.z(i)->zItemType()->getId() << "\" hp=\""
+                        << outputs.z(i)->getHp() << "\" durability=\""
+                        << outputs.z(i)->getDurability() << "\" maxHp=\""
+                        << outputs.z(i)->getMaxHp() << "\" maxDurability=\""
+                        << outputs.z(i)->getMaxDurability() << "\">"
+                        << outputs.z(i)->getTooltipUIML() << "</output>";
     }
     result += "</outputs></recipie>";
     return result;

+ 5 - 6
FactoryCraft/RecipieLoader.cpp

@@ -221,20 +221,19 @@ void RecipieLoader::registerRecipieList(const char* name)
 Framework::Text RecipieLoader::getCrafingUIML(ItemType* zTargetType)
 {
     Framework::Text result = "<dialog id=\"crafting_";
-    result += zTargetType->getId();
-    result += "\"><craftingRecipies>";
+    result.append() << zTargetType->getId() << "\"><craftingRecipies>";
     for (RecipieList* list : lists)
     {
         Framework::RCArray<Recipie> recipies;
         list->findRecipies(zTargetType, recipies);
         if (recipies.getEintragAnzahl() > 0)
         {
-            result += "<craftingRecipieGroup name=\"";
-            result += list->getName();
+            result.append()
+                << "<craftingRecipieGroup name=\"" << list->getName();
             if (list->getName().istGleich("inventory"))
             {
-                result += "\" itemIcon=\"";
-                result += ItemTypeEnum::CRAFTING_TABLE;
+                result.append()
+                    << "\" itemIcon=\"" << ItemTypeEnum::CRAFTING_TABLE;
             }
             result += "\">";
             for (Recipie* recipie : recipies)

+ 9 - 33
FactoryCraft/Server.cpp

@@ -136,24 +136,6 @@ void FactoryCraftServer::close()
     LeaveCriticalSection(&cs);
 }
 
-bool FactoryCraftServer::absturzKlient(int accountId)
-{
-    bool gefunden = 0;
-    EnterCriticalSection(&cs);
-    for (int i = 0; i < klients->getEintragAnzahl(); i++)
-    {
-        if (klients->z(i) && klients->z(i)->getAccountId() == accountId)
-        {
-            klients->z(i)->absturz();
-            klients->remove(i);
-            gefunden = 1;
-            break;
-        }
-    }
-    LeaveCriticalSection(&cs);
-    return gefunden;
-}
-
 bool FactoryCraftServer::removeKlient(FCKlient* zKlient)
 {
     bool gefunden = 0;
@@ -189,14 +171,13 @@ FCKlient::FCKlient(SSLSKlient* klient, FactoryCraftServer* ls)
     this->klient = klient;
     background = 0;
     foreground = 0;
-    accountId = 0;
     this->ls = ls;
     zGameClient = 0;
     backgroundReader = 0;
     foregroundReader = 0;
     backgroundWriter = 0;
     foregroundWriter = 0;
-    authKey = randomKey(authKeyLen);
+    authKey = randomSecret();
 }
 
 // Destruktor
@@ -215,7 +196,6 @@ FCKlient::~FCKlient()
     delete foregroundWriter;
     klient->release();
     ls->release();
-    delete[] authKey;
 }
 
 // nicht constant
@@ -227,8 +207,7 @@ void FCKlient::setForegroundClient(SKlient* foreground)
     foregroundWriter = new NetworkWriter(foreground);
     if (foreground && background)
         zGameClient
-            = Game::INSTANCE->addPlayer(dynamic_cast<FCKlient*>(getThis()),
-                Framework::Text((int)accountId));
+            = Game::INSTANCE->addPlayer(dynamic_cast<FCKlient*>(getThis()), name);
     foregroundRunning = 1;
     new AsynchronCall([this]() {
         while (this->foreground->waitForNextMessage())
@@ -264,7 +243,7 @@ void FCKlient::setBackgroundClient(SKlient* background)
     if (foreground && background)
         zGameClient
             = Game::INSTANCE->addPlayer(dynamic_cast<FCKlient*>(getThis()),
-                Framework::Text((int)accountId));
+                name);
     backgroundRunning = 1;
     new AsynchronCall([this]() {
         while (this->background->waitForNextMessage())
@@ -339,15 +318,17 @@ void FCKlient::thread()
                         short len = (short)secret.getLength();
                         klient->sende((char*)&len, 2);
                         klient->sende(secret.getText(), len);
+                        identified = 1;
                     }
                     else
                     {
                         klient->sende("\1", 1);
                         identified = 1;
                     }
-                    short keyLen = (short)authKeyLen;
+                    short keyLen = (short)authKey.getLength();
                     klient->sende((char*)&keyLen, 2);
-                    klient->sende(authKey, authKeyLen);
+                    klient->sende(authKey, keyLen);
+                    this->name = name;
                     delete[] name;
                     delete[] secret;
                     break;
@@ -397,11 +378,6 @@ void FCKlient::thread()
     }
 }
 
-int FCKlient::getAccountId() const // gibt die KlientId zurück
-{
-    return accountId;
-}
-
 NetworkWriter* FCKlient::zBackgroundWriter() const
 {
     return backgroundWriter;
@@ -415,10 +391,10 @@ NetworkWriter* FCKlient::zForegroundWriter() const
 bool FCKlient::matchAuthKey(char* key, int len) const
 {
     if (foreground && background) return 0;
-    if (len != authKeyLen) return 0;
+    if (len != authKey.getLength()) return 0;
     for (int i = 0; i < len; i++)
     {
-        if (key[i] != authKey[i]) return 0;
+        if (key[i] != authKey.getText()[i]) return 0;
     }
     return 1;
 }

+ 2 - 5
FactoryCraft/Server.h

@@ -33,7 +33,6 @@ public:
     // nicht constant
     void run();
     void close();
-    bool absturzKlient(int accountId);
     bool removeKlient(FCKlient* zKlient);
     bool hatClients() const;
     int getUnencryptedPort() const;
@@ -45,7 +44,6 @@ private:
     SSLSKlient* klient;
     SKlient* background;
     SKlient* foreground;
-    unsigned int accountId;
     FactoryCraftServer* ls;
     GameClient* zGameClient;
     NetworkReader* backgroundReader;
@@ -55,8 +53,8 @@ private:
     Critical cs;
     bool backgroundRunning;
     bool foregroundRunning;
-    char* authKey;
-    int authKeyLen;
+    Framework::Text authKey;
+    Framework::Text name;
 
 public:
     // Konstruktor
@@ -69,7 +67,6 @@ public:
     void absturz();
     void thread();
     // constant
-    int getAccountId() const;
     NetworkWriter* zBackgroundWriter() const;
     NetworkWriter* zForegroundWriter() const;
     bool matchAuthKey(char* key, int len) const;