Procházet zdrojové kódy

send item names to clients for filtering

Kolja Strohm před 1 rokem
rodič
revize
0e3f1d58f7
3 změnil soubory, kde provedl 21 přidání a 2 odebrání
  1. 15 2
      FactoryCraft/Inventory.cpp
  2. 5 0
      FactoryCraft/Item.cpp
  3. 1 0
      FactoryCraft/Item.h

+ 15 - 2
FactoryCraft/Inventory.cpp

@@ -362,7 +362,8 @@ void Inventory::afterPushStack(
     else
     {
         NetworkMessage* msg = new NetworkMessage();
-        char* message = new char[29];
+        char* message
+            = new char[30 + zItem->getName().getLength()];
         message[0] = 2; // add new stack
         *(int*)(message + 1) = zSlot->getId();
         *(int*)(message + 5) = zSlot->getNumberOfItems();
@@ -372,7 +373,11 @@ void Inventory::afterPushStack(
         *(float*)(message + 17) = zItem->getDurability();
         *(float*)(message + 21) = zItem->getMaxDurability();
         *(int*)(message + 25) = zItem->zItemType()->getId();
-        msg->setMessage(message, 29);
+        *(message + 29) = (char)zItem->getName().getLength();
+        memcpy(message + 30,
+            zItem->getName().getText(),
+            zItem->getName().getLength());
+        msg->setMessage(message, 30 + zItem->getName().getLength());
         notifyObservers(msg);
     }
     for (auto call : afterPushStackCalls)
@@ -733,6 +738,14 @@ void Inventory::inventoryApi(Framework::StreamReader* zRequest,
                         buffer.schreibe((char*)&f, 4);
                         int id = slot->zStack()->zItem()->zItemType()->getId();
                         buffer.schreibe((char*)&id, 4);
+                        char len = (char)slot->zStack()
+                                       ->zItem()
+                                       ->getName()
+                                       .getLength();
+                        buffer.schreibe((char*)&len, 1);
+                        buffer.schreibe(
+                            slot->zStack()->zItem()->getName().getText(),
+                            slot->zStack()->zItem()->getName().getLength());
                     }
                 }
             }

+ 5 - 0
FactoryCraft/Item.cpp

@@ -105,6 +105,11 @@ float Item::getMaxHp() const
     return maxHp;
 }
 
+const Framework::Text& Item::getName() const
+{
+    return name;
+}
+
 bool Item::canBeStackedWith(const Item* zItem) const
 {
     return itemTypeId == zItem->itemTypeId && durability == maxDurability

+ 1 - 0
FactoryCraft/Item.h

@@ -46,6 +46,7 @@ public:
     float getMaxDurability() const;
     int getMaxStackSize() const;
     float getMaxHp() const;
+    const Framework::Text& getName() const;
     virtual bool canBeStackedWith(const Item* zItem) const;
     virtual bool canBePlacedAt(int dimensionId, Framework::Vec3<int> worldPos) const;
     virtual void onPlaced();