Inventory.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. #include <InMemoryBuffer.h>
  2. #include "Inventory.h"
  3. #include "ItemFilter.h"
  4. #include "Constants.h"
  5. #include "Area.h"
  6. #include "NetworkMessage.h"
  7. #include "Entity.h"
  8. #include "Game.h"
  9. using namespace Framework;
  10. InventoryInteraction::InventoryInteraction(Inventory* current, Inventory* other, Direction dir)
  11. : current(current),
  12. other(other),
  13. dir(dir)
  14. {
  15. lock();
  16. }
  17. InventoryInteraction::InventoryInteraction(const InventoryInteraction& interaction)
  18. : InventoryInteraction(interaction.current, interaction.other, interaction.dir)
  19. {}
  20. InventoryInteraction::~InventoryInteraction()
  21. {
  22. unlock();
  23. }
  24. void InventoryInteraction::lock()
  25. {
  26. if (!current || !other) return;
  27. if (current->location.x < other->location.x)
  28. {
  29. current->cs.lock();
  30. other->cs.lock();
  31. return;
  32. }
  33. else if (current->location.x == other->location.x)
  34. {
  35. if (current->location.y < other->location.y)
  36. {
  37. current->cs.lock();
  38. other->cs.lock();
  39. return;
  40. }
  41. else if (current->location.y == other->location.y)
  42. {
  43. if (current->location.z < other->location.z)
  44. {
  45. current->cs.lock();
  46. other->cs.lock();
  47. return;
  48. }
  49. }
  50. }
  51. other->cs.lock();
  52. current->cs.lock();
  53. }
  54. void InventoryInteraction::unlock()
  55. {
  56. if (!current || !other) return;
  57. if (current->location.x < other->location.x)
  58. {
  59. current->cs.unlock();
  60. other->cs.unlock();
  61. return;
  62. }
  63. else if (current->location.x == other->location.x)
  64. {
  65. if (current->location.y < other->location.y)
  66. {
  67. current->cs.unlock();
  68. other->cs.unlock();
  69. return;
  70. }
  71. else if (current->location.y == other->location.y)
  72. {
  73. if (current->location.z < other->location.z)
  74. {
  75. current->cs.unlock();
  76. other->cs.unlock();
  77. return;
  78. }
  79. }
  80. }
  81. other->cs.unlock();
  82. current->cs.unlock();
  83. }
  84. void InventoryInteraction::transaction(Inventory* zSource, Inventory* zTarget, ItemFilter* zFilter, Direction sourceView, Direction targetView, int count)
  85. {
  86. for (auto sourceSlot = zSource->pullSlotsOrder->begin(); sourceSlot; )
  87. {
  88. while (sourceSlot && (sourceSlot->getNumberOfItems() == 0 || (zFilter && !zFilter->matchSourceSlot(sourceSlot))))
  89. sourceSlot++;
  90. if (!sourceSlot) break;
  91. // TODO: use target cache ot get list of slots that already contains the source item
  92. for (auto targetSlot = zTarget->pushSlotsOrder->begin(); targetSlot; )
  93. {
  94. while (targetSlot && (targetSlot->isFull() || (zFilter && !zFilter->matchTargetSlot(targetSlot))))
  95. targetSlot++;
  96. if (!targetSlot) break;
  97. if (targetSlot->zStack())
  98. {
  99. if (sourceSlot->zStack()->zItem()->canBeStackedWith(targetSlot->zStack()->zItem()))
  100. {
  101. int number = MIN(targetSlot->numberOfAddableItems(sourceSlot->zStack(), sourceView), count);
  102. int tmp = number;
  103. if (number > 0 && zSource->allowPullStack(sourceSlot, sourceView) && zTarget->allowPushStack(targetSlot, targetView, sourceSlot->zStack()->zItem(), tmp))
  104. {
  105. number = MIN(number, tmp);
  106. ItemStack* stack = sourceSlot->takeItemsOut(number, dir);
  107. if (stack)
  108. {
  109. targetSlot->addItems(stack, dir);
  110. zSource->updateCache(sourceSlot, targetSlot->zStack()->zItem()->zItemType()->getId());
  111. zSource->afterPullStack(sourceSlot, sourceView, targetSlot->zStack()->zItem(), number);
  112. zTarget->afterPushStack(targetSlot, targetView, targetSlot->zStack()->zItem(), number);
  113. if (stack->getSize())
  114. throw stack;
  115. stack->release();
  116. count -= number;
  117. if (count == 0)
  118. break;
  119. }
  120. else
  121. targetSlot++;
  122. }
  123. else
  124. targetSlot++;
  125. }
  126. else
  127. targetSlot++;
  128. }
  129. else
  130. {
  131. int number = MIN(targetSlot->numberOfAddableItems(sourceSlot->zStack(), sourceView), count);
  132. int tmp = number;
  133. if (number > 0 && zSource->allowPullStack(sourceSlot, sourceView) && zTarget->allowPushStack(targetSlot, targetView, sourceSlot->zStack()->zItem(), tmp))
  134. {
  135. number = MIN(number, tmp);
  136. if (number > 0)
  137. {
  138. ItemStack* stack = sourceSlot->takeItemsOut(number, dir);
  139. if (stack)
  140. {
  141. targetSlot->addItems(stack, dir);
  142. zSource->updateCache(sourceSlot, targetSlot->zStack()->zItem()->zItemType()->getId());
  143. zTarget->updateCache(targetSlot, -1);
  144. zSource->afterPullStack(sourceSlot, sourceView, targetSlot->zStack()->zItem(), number);
  145. zTarget->afterPushStack(targetSlot, targetView, targetSlot->zStack()->zItem(), number);
  146. if (stack->getSize())
  147. throw stack;
  148. stack->release();
  149. count -= number;
  150. if (count == 0)
  151. return;
  152. }
  153. else
  154. targetSlot++;
  155. }
  156. else
  157. targetSlot++;
  158. }
  159. else
  160. targetSlot++;
  161. }
  162. if (sourceSlot->getNumberOfItems() == 0)
  163. break;
  164. }
  165. }
  166. }
  167. InventoryInteraction& InventoryInteraction::operator=(const InventoryInteraction& data)
  168. {
  169. if (&data == this) return *this;
  170. unlock();
  171. current = data.current;
  172. other = data.other;
  173. dir = data.dir;
  174. lock();
  175. return *this;
  176. }
  177. void InventoryInteraction::endInteraction()
  178. {
  179. unlock();
  180. current = 0;
  181. other = 0;
  182. }
  183. void InventoryInteraction::pullItems(int count, ItemFilter* zFilter)
  184. {
  185. if (!current || !other) return;
  186. transaction(other, current, zFilter, getOppositeDirection(dir), dir, count);
  187. }
  188. void InventoryInteraction::pushItems(int count, ItemFilter* zFilter)
  189. {
  190. if (!current || !other) return;
  191. transaction(current, other, zFilter, dir, getOppositeDirection(dir), count);
  192. }
  193. Inventory::Inventory(const Framework::Vec3<float> location, bool hasInventory)
  194. : ReferenceCounter(),
  195. nextSlotId(1),
  196. location(location)
  197. {
  198. if (hasInventory)
  199. {
  200. pullSlotsOrder = new Framework::RCArray<ItemSlot>();
  201. pushSlotsOrder = new Framework::RCArray<ItemSlot>();
  202. itemCache = new Framework::HashMap<int, Framework::Array<ItemSlot*>*>(ITEM_CACHE_SIZE, std::_Identity<int>());
  203. }
  204. else
  205. {
  206. pullSlotsOrder = 0;
  207. pushSlotsOrder = 0;
  208. itemCache = 0;
  209. }
  210. }
  211. Inventory::~Inventory()
  212. {
  213. if (pullSlotsOrder)
  214. pullSlotsOrder->release();
  215. if (pushSlotsOrder)
  216. pushSlotsOrder->release();
  217. if (itemCache)
  218. itemCache->release();
  219. }
  220. void Inventory::updateCache(ItemSlot* zSlot, int beforeKey)
  221. {
  222. if (!itemCache)
  223. return;
  224. int key = zSlot->zStack() ? zSlot->zStack()->zItem()->zItemType()->getId() : -1;
  225. if (key == beforeKey)
  226. return;
  227. if (beforeKey >= 0)
  228. {
  229. auto tmp = itemCache->safeGet(key, 0);
  230. if (tmp)
  231. tmp->removeValue(zSlot);
  232. }
  233. if (zSlot->zStack())
  234. {
  235. auto tmp = itemCache->safeGet(key, 0);
  236. if (!tmp)
  237. {
  238. tmp = new Array<ItemSlot*>();
  239. itemCache->put(key, tmp);
  240. }
  241. tmp->add(zSlot, 0);
  242. }
  243. }
  244. void Inventory::addSlot(ItemSlot* slot)
  245. {
  246. cs.lock();
  247. ((ItemSlotIDSetter*)slot)->setId(nextSlotId++);
  248. int pullPrio = slot->getPullPriority();
  249. int pushPrio = slot->getPushPriority();
  250. int index = 0;
  251. for (auto stack : *pullSlotsOrder)
  252. {
  253. if (stack->getPullPriority() > pullPrio)
  254. break;
  255. index++;
  256. }
  257. pullSlotsOrder->add(dynamic_cast<ItemSlot*>(slot->getThis()), index);
  258. index = 0;
  259. for (auto stack : *pushSlotsOrder)
  260. {
  261. if (stack->getPushPriority() > pushPrio)
  262. break;
  263. index++;
  264. }
  265. pushSlotsOrder->add(slot, index);
  266. updateCache(slot, -1);
  267. cs.unlock();
  268. }
  269. bool Inventory::allowPullStack(ItemSlot* zSlot, Direction dir) const
  270. {
  271. return pullSlotsOrder;
  272. }
  273. bool Inventory::allowPushStack(ItemSlot* zSlot, Direction dir, const Item* zItem, int& count) const
  274. {
  275. return pushSlotsOrder;
  276. }
  277. void Inventory::afterPullStack(ItemSlot* zSlot, Direction dir, const Item* zItem, int count)
  278. {
  279. NetworkMessage msg;
  280. char message[9];
  281. message[0] = 1; // set count of items
  282. *(int*)(message + 1) = zSlot->getId();
  283. *(int*)(message + 5) = zSlot->getNumberOfItems();
  284. msg.setMessage(message, 9, 0);
  285. notyObservers(msg);
  286. }
  287. void Inventory::afterPushStack(ItemSlot* zSlot, Direction dir, const Item* zItem, int count)
  288. {
  289. if (zSlot->getNumberOfItems() > count)
  290. {
  291. NetworkMessage msg;
  292. char message[9];
  293. message[0] = 1; // set count of items
  294. *(int*)(message + 1) = zSlot->getId();
  295. *(int*)(message + 5) = zSlot->getNumberOfItems();
  296. msg.setMessage(message, 9, 0);
  297. notyObservers(msg);
  298. }
  299. else
  300. {
  301. NetworkMessage msg;
  302. char message[29];
  303. message[0] = 2; // add new stack
  304. *(int*)(message + 1) = zSlot->getId();
  305. *(int*)(message + 5) = zSlot->getNumberOfItems();
  306. const Item* zItem = zSlot->zStack()->zItem();
  307. *(float*)(message + 9) = zItem->getDamage();
  308. *(float*)(message + 13) = zItem->getMaxDamage();
  309. *(float*)(message + 17) = zItem->getDurability();
  310. *(float*)(message + 21) = zItem->getMaxDurability();
  311. *(int*)(message + 25) = zItem->zItemType()->getId();
  312. msg.setMessage(message, 29, 0);
  313. notyObservers(msg);
  314. }
  315. }
  316. void Inventory::loadInventory(Framework::StreamReader* zReader)
  317. {
  318. if (itemCache)
  319. {
  320. for (auto stack : *pushSlotsOrder)
  321. {
  322. int size = 0;
  323. zReader->lese((char*)&size, 4);
  324. if (size != 0)
  325. {
  326. int id = 0;
  327. zReader->lese((char*)&id, 4);
  328. Item* item = StaticRegistry<ItemType>::INSTANCE.zElement(id)->loadItem(zReader);
  329. stack->addItems(new ItemStack(item, size), NO_DIRECTION);
  330. }
  331. }
  332. }
  333. }
  334. void Inventory::saveInventory(Framework::StreamWriter* zWriter)
  335. {
  336. if (itemCache)
  337. {
  338. for (auto slot : *pushSlotsOrder)
  339. {
  340. const ItemStack* stack = slot->zStack();
  341. int value = 0;
  342. if (!stack || !stack->zItem())
  343. {
  344. zWriter->schreibe((char*)&value, 4);
  345. }
  346. else
  347. {
  348. value = stack->getSize();
  349. zWriter->schreibe((char*)&value, 4);
  350. value = stack->zItem()->zItemType()->getId();
  351. zWriter->schreibe((char*)&value, 4);
  352. stack->zItem()->zItemType()->saveItem(stack->zItem(), zWriter);
  353. }
  354. }
  355. }
  356. }
  357. void Inventory::notyObservers(NetworkMessage& msg)
  358. {
  359. cs.lock();
  360. int index = 0;
  361. Array<int> toDelete;
  362. for (auto observer : observers)
  363. {
  364. Entity* e = Game::INSTANCE->zEntity(observer.getFirst());
  365. if (e)
  366. {
  367. msg.adressGui(observer.getSecond());
  368. Game::INSTANCE->sendMessage(&msg, e);
  369. }
  370. else
  371. toDelete.add(index, 0);
  372. index++;
  373. }
  374. for (int i : toDelete)
  375. observers.remove(i);
  376. cs.unlock();
  377. }
  378. void Inventory::removeObserver(Entity* zSource, Framework::Text id)
  379. {
  380. cs.lock();
  381. int index = 0;
  382. for (auto observer : observers)
  383. {
  384. if (observer.getFirst() == zSource->getId() && observer.getSecond().istGleich(id))
  385. {
  386. observers.remove(index);
  387. break;
  388. }
  389. index++;
  390. }
  391. cs.unlock();
  392. }
  393. const ItemSlot* Inventory::zSlot(int id) const
  394. {
  395. if (itemCache)
  396. {
  397. for (auto slot : *pushSlotsOrder)
  398. {
  399. if (slot->getId() == id)
  400. return slot;
  401. }
  402. }
  403. return 0;
  404. }
  405. void Inventory::localTransaction(Array< ItemSlot* >* zSourceSlots, Array< ItemSlot* >* zTargetSlots, ItemFilter* zFilter, int count, Direction outDir, Direction inDir)
  406. {
  407. if (itemCache)
  408. {
  409. cs.lock();
  410. auto sourceSlot = zSourceSlots ? zSourceSlots->begin() : pullSlotsOrder->begin();
  411. for (auto targetSlot = zTargetSlots->begin(); targetSlot; )
  412. {
  413. int amount = count;
  414. if (!targetSlot->isFull())
  415. {
  416. if (targetSlot->zStack())
  417. {
  418. Array<ItemSlot*>* zSurceListe = itemCache->safeGet(targetSlot->zStack()->zItem()->zItemType()->getId(), 0);
  419. if (zSurceListe)
  420. {
  421. Array<int> toDelete;
  422. int index = 0;
  423. for (auto sourceSlot = zSurceListe->begin(); sourceSlot; sourceSlot++, index++)
  424. {
  425. if (zSourceSlots && zSourceSlots->getWertIndex(sourceSlot) < 0)
  426. continue;
  427. if (zFilter && !zFilter->matchItem(sourceSlot->zStack()->zItem()))
  428. continue;
  429. int number = MIN(targetSlot->numberOfAddableItems(sourceSlot->zStack(), inDir), count);
  430. if (number > 0)
  431. {
  432. ItemStack* stack = sourceSlot->takeItemsOut(number, outDir);
  433. if (stack)
  434. {
  435. if (!sourceSlot->zStack())
  436. toDelete.add(index, 0);
  437. targetSlot->addItems(stack, inDir);
  438. updateCache(sourceSlot, targetSlot->zStack()->zItem()->zItemType()->getId());
  439. if (stack->getSize())
  440. {
  441. cs.unlock();
  442. throw stack;
  443. }
  444. stack->release();
  445. count -= number;
  446. if (count == 0)
  447. break;
  448. }
  449. }
  450. }
  451. for (auto indexToDelete = toDelete.begin(); indexToDelete; indexToDelete++)
  452. zSurceListe->remove(indexToDelete);
  453. if (count == 0)
  454. {
  455. cs.unlock();
  456. return;
  457. }
  458. }
  459. }
  460. else
  461. {
  462. while (sourceSlot && (!sourceSlot->zStack() || (zFilter && !zFilter->matchItem(sourceSlot->zStack()->zItem()))))
  463. sourceSlot++;
  464. if (!sourceSlot)
  465. {
  466. cs.unlock();
  467. return;
  468. }
  469. int number = MIN(targetSlot->numberOfAddableItems(sourceSlot->zStack(), inDir), count);
  470. if (number > 0)
  471. {
  472. ItemStack* stack = sourceSlot->takeItemsOut(number, outDir);
  473. if (stack)
  474. {
  475. targetSlot->addItems(stack, inDir);
  476. updateCache(sourceSlot, targetSlot->zStack()->zItem()->zItemType()->getId());
  477. updateCache(targetSlot, -1);
  478. if (stack->getSize())
  479. {
  480. cs.unlock();
  481. throw stack;
  482. }
  483. stack->release();
  484. count -= number;
  485. if (count == 0)
  486. {
  487. cs.unlock();
  488. return;
  489. }
  490. }
  491. }
  492. }
  493. }
  494. if (amount == count || targetSlot->isFull())
  495. targetSlot++;
  496. }
  497. cs.unlock();
  498. }
  499. }
  500. void Inventory::addItems(ItemStack* items, Direction dir)
  501. {
  502. if (itemCache && items && items->getSize() > 0)
  503. {
  504. cs.lock();
  505. for (auto targetSlot = pushSlotsOrder->begin(); targetSlot; targetSlot++)
  506. {
  507. if (!targetSlot->isFull())
  508. {
  509. if (targetSlot->zStack())
  510. {
  511. int number = MIN(targetSlot->numberOfAddableItems(items, dir), items->getSize());
  512. int tmp = number;
  513. if (number > 0 && allowPushStack(targetSlot, dir, items->zItem(), tmp))
  514. {
  515. number = MIN(number, tmp);
  516. ItemStack* stack = items->split(number);
  517. if (stack)
  518. {
  519. targetSlot->addItems(stack, dir);
  520. afterPushStack(targetSlot, dir, targetSlot->zStack()->zItem(), number);
  521. if (stack->getSize())
  522. throw stack;
  523. stack->release();
  524. if (!items->getSize())
  525. break;
  526. }
  527. }
  528. }
  529. else
  530. {
  531. int number = MIN(targetSlot->numberOfAddableItems(items, dir), items->getSize());
  532. int tmp = number;
  533. if (number > 0 && allowPushStack(targetSlot, dir, items->zItem(), tmp))
  534. {
  535. number = MIN(number, tmp);
  536. ItemStack* stack = items->split(number);
  537. if (stack)
  538. {
  539. targetSlot->addItems(stack, dir);
  540. updateCache(targetSlot, -1);
  541. afterPushStack(targetSlot, dir, targetSlot->zStack()->zItem(), number);
  542. if (stack->getSize())
  543. throw stack;
  544. stack->release();
  545. if (!items->getSize())
  546. break;
  547. }
  548. }
  549. }
  550. }
  551. }
  552. cs.unlock();
  553. }
  554. }
  555. ItemStack* Inventory::takeItemsOut(ItemSlot* zSlot, int count, Direction dir)
  556. {
  557. if (allowPullStack(zSlot, dir))
  558. {
  559. ItemStack* stack = zSlot->takeItemsOut(count, dir);
  560. if (stack)
  561. {
  562. updateCache(zSlot, stack->zItem()->zItemType()->getId());
  563. if (stack->getSize() > 0)
  564. afterPullStack(zSlot, dir, stack->zItem(), stack->getSize());
  565. }
  566. return stack;
  567. }
  568. return 0;
  569. }
  570. InventoryInteraction Inventory::interactWith(Inventory* zInventory, Direction dir)
  571. {
  572. return InventoryInteraction(this, zInventory, dir);
  573. }
  574. void Inventory::unsaveAddItem(ItemStack* zStack, Direction dir)
  575. {
  576. addItems(zStack, dir);
  577. }
  578. int Inventory::numberOfAddableItems(const ItemStack* zStack, Direction dir) const
  579. {
  580. int count = 0;
  581. for (auto targetSlot = pushSlotsOrder->begin(); targetSlot; targetSlot++)
  582. {
  583. int maxCount = targetSlot->numberOfAddableItems(zStack, dir);
  584. int allowed = maxCount;
  585. if (allowPushStack(targetSlot, dir, zStack->zItem(), allowed))
  586. count += MIN(maxCount, allowed);
  587. }
  588. return count;
  589. }
  590. Framework::Iterator<ItemSlot*> Inventory::begin()
  591. {
  592. return pullSlotsOrder->begin();
  593. }
  594. Framework::Iterator<ItemSlot*> Inventory::end()
  595. {
  596. return pullSlotsOrder->end();
  597. }
  598. void Inventory::inventoryApi(Framework::StreamReader* zRequest, NetworkMessage* zResponse, Entity* zSource)
  599. {
  600. char type;
  601. zRequest->lese(&type, 1);
  602. switch (type)
  603. {
  604. case 0: // request inventory
  605. {
  606. char idLen;
  607. zRequest->lese(&idLen, 1);
  608. char* id = new char[idLen + 1];
  609. zRequest->lese(id, idLen);
  610. id[(int)idLen] = 0;
  611. zResponse->adressGui(id);
  612. observers.add(ImmutablePair<int, Text>(zSource->getId(), id));
  613. delete[] id;
  614. char filterLen;
  615. zRequest->lese(&filterLen, 1);
  616. char* filter = new char[filterLen + 1];
  617. zRequest->lese(filter, filterLen);
  618. filter[(int)filterLen] = 0;
  619. InMemoryBuffer buffer;
  620. int count = 0;
  621. for (ItemSlot* slot : *this)
  622. {
  623. if (slot->getName().istGleich(filter))
  624. {
  625. count++;
  626. int id = slot->getId();
  627. buffer.schreibe((char*)&id, 4);
  628. int itemCount = slot->getNumberOfItems();
  629. buffer.schreibe((char*)&itemCount, 4);
  630. if (itemCount > 0)
  631. {
  632. float f = slot->zStack()->zItem()->getDamage();
  633. buffer.schreibe((char*)&f, 4);
  634. f = slot->zStack()->zItem()->getMaxDamage();
  635. buffer.schreibe((char*)&f, 4);
  636. f = slot->zStack()->zItem()->getDurability();
  637. buffer.schreibe((char*)&f, 4);
  638. f = slot->zStack()->zItem()->getMaxDurability();
  639. buffer.schreibe((char*)&f, 4);
  640. int id = slot->zStack()->zItem()->zItemType()->getId();
  641. buffer.schreibe((char*)&id, 4);
  642. }
  643. }
  644. }
  645. delete[] filter;
  646. char* msg = new char[5 + buffer.getSize()];
  647. msg[0] = 0;
  648. *(int*)(msg + 1) = count;
  649. buffer.lese(msg + 5, (int)buffer.getSize());
  650. zResponse->setMessage(msg, 5 + (int)buffer.getSize(), 1);
  651. break;
  652. }
  653. case 1: // remove Observer
  654. char idLen;
  655. zRequest->lese(&idLen, 1);
  656. char* id = new char[idLen + 1];
  657. zRequest->lese(id, idLen);
  658. id[(int)idLen] = 0;
  659. removeObserver(zSource, id);
  660. delete[] id;
  661. break;
  662. }
  663. }