WorldPackets.cpp 913 B

1234567891011121314151617181920212223242526272829
  1. #include "client/packets/WorldPackets.h"
  2. #include "client/Game.h"
  3. #include "common/network/Packets.h"
  4. #include "utils/Logger.h"
  5. void WorldPackets::receiveChunk(World& w, InPacket& in) {
  6. LOG_DEBUG("received chunk from server");
  7. int32 ox;
  8. int32 oz;
  9. if(in.readS32(ox) || in.readS32(oz)) {
  10. LOG_WARNING("missing chunk offset in packet");
  11. return;
  12. }
  13. uint16 counter = 0;
  14. Block::Id b = 0;
  15. for(int y = 0; y < w.blocks.getHeight(); y++) {
  16. for(int x = 0; x < BlockStorage::SEGMENT; x++) {
  17. for(int z = 0; z < BlockStorage::SEGMENT; z++) {
  18. if(counter == 0 && (in.readU16(b) || in.readU16(counter))) {
  19. LOG_WARNING("missing block data in packet");
  20. return;
  21. }
  22. w.blocks.set(ox + x, y, oz + z, b);
  23. counter--;
  24. }
  25. }
  26. }
  27. w.dirty = true;
  28. }