X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fclient%2Fnet.cpp;h=bd2a43abd002a20224e8019ff36f203c08989061;hb=ed3bdc028edc0ecb5835d1c0bf18dbc59b342daf;hp=d7a2661d56c3bc54d09df6140da9a003fed848db;hpb=4727825186798902f68df5b99a6a32f0ef618454;p=blank.git diff --git a/src/client/net.cpp b/src/client/net.cpp index d7a2661..bd2a43a 100644 --- a/src/client/net.cpp +++ b/src/client/net.cpp @@ -23,8 +23,9 @@ namespace blank { namespace client { -ChunkReceiver::ChunkReceiver(ChunkStore &store, const WorldSave &save) -: store(store) +ChunkReceiver::ChunkReceiver(Client &client, ChunkStore &store, const WorldSave &save) +: client(client) +, store(store) , save(save) , transmissions() , timer(5000) { @@ -40,7 +41,14 @@ void ChunkReceiver::Update(int dt) { for (ChunkTransmission &trans : transmissions) { if (trans.active && (timer.Elapsed() - trans.last_update) > timer.Interval()) { cout << "timeout for transmission of chunk " << trans.coords << endl; - trans.Clear(); + if (trans.header_received) { + client.SendChunkRequest(trans.coords); + trans.Reset(); + trans.last_update = timer.Elapsed(); + } else { + // well shit + trans.Clear(); + } } } if (transmissions.size() > 3) { @@ -152,7 +160,7 @@ void ChunkReceiver::Commit(ChunkTransmission &trans) { Chunk *chunk = store.Allocate(trans.coords); if (!chunk) { - // chunk no longer of interes, just drop the data + // chunk no longer of interest, just drop the data // it should probably be cached to disk, but not now :P trans.Clear(); return; @@ -167,10 +175,17 @@ void ChunkReceiver::Commit(ChunkTransmission &trans) { if (uncompress(dst, &dst_len, src, src_len) != Z_OK) { // omg, now what? cout << "got corruped chunk data for " << trans.coords << endl; + client.SendChunkRequest(trans.coords); + trans.Reset(); + // chunk data can, and probably will, contain invalid block IDs, so + // zero it to be safe + memset(dst, 0, dst_len); + return; } } else { memcpy(dst, src, min(src_len, dst_len)); } + chunk->ScanActive(); chunk->Invalidate(); trans.Clear(); } @@ -188,11 +203,15 @@ ChunkTransmission::ChunkTransmission() } -void ChunkTransmission::Clear() noexcept { +void ChunkTransmission::Reset() noexcept { data_size = 0; data_received = 0; last_update = 0; header_received = false; +} + +void ChunkTransmission::Clear() noexcept { + Reset(); active = false; } @@ -305,6 +324,14 @@ uint16_t Client::SendPart() { return conn.Send(client_pack, client_sock); } +uint16_t Client::SendChunkRequest( + const glm::ivec3 &coords +) { + auto pack = Packet::Make(client_pack); + pack.WriteChunkCoords(coords); + return conn.Send(client_pack, client_sock); +} + uint16_t Client::SendMessage( uint8_t type, uint32_t ref,