equal
deleted
inserted
replaced
4 #include "Config.hh" |
4 #include "Config.hh" |
5 #include "../Engine.hh" |
5 #include "../Engine.hh" |
6 #include "../Logger.hh" |
6 #include "../Logger.hh" |
7 |
7 |
8 #include <cassert> |
8 #include <cassert> |
9 #include <zlib.h> |
|
10 |
9 |
11 NetworkClient::NetworkClient (Engine &engine, GameState &state, const NetworkEndpoint &connect_to) : |
10 NetworkClient::NetworkClient (Engine &engine, GameState &state, const NetworkEndpoint &connect_to) : |
12 engine(engine), state(state), netsession(NETWORK_MAGIC_ID), server(netsession.connect(connect_to)), |
11 engine(engine), state(state), netsession(NETWORK_MAGIC_ID), server(netsession.connect(connect_to)), |
13 controller(*this) |
12 controller(*this) |
14 { |
13 { |
34 PixelDimension map_h = pkt.read_uint32(); |
33 PixelDimension map_h = pkt.read_uint32(); |
35 |
34 |
36 // the terrain byte array |
35 // the terrain byte array |
37 size_t terrain_size = map_w * map_h; |
36 size_t terrain_size = map_w * map_h; |
38 uint8_t terrain_buf[map_w][map_h]; |
37 uint8_t terrain_buf[map_w][map_h]; |
39 |
38 |
40 // compressed packet data |
39 // read uncompressed terrain data |
41 unsigned long inflate_size = terrain_size; |
40 size_t inflate_size = pkt.read_uncompressed(terrain_buf, terrain_size); |
42 unsigned long deflate_size = pkt.tell_remaining(); |
41 |
43 const uint8_t *deflate_ptr = (const uint8_t *) pkt.read_ptr(deflate_size); |
|
44 |
|
45 // uncompress the rest of the packet data |
|
46 if (uncompress((uint8_t *) terrain_buf, &inflate_size, deflate_ptr, deflate_size) != Z_OK) |
|
47 throw Error("uncompress"); |
|
48 |
|
49 // invalid data? |
42 // invalid data? |
50 if (inflate_size != terrain_size) |
43 if (inflate_size != terrain_size) |
51 throw Error("Corrupt terrain data"); |
44 throw Error("Corrupt terrain data"); |
52 |
45 |
53 // translate map data to terrain vector |
46 // translate map data to terrain vector |