Skip to content

Commit 8e9d896

Browse files
sapiersapier
sapier
authored and
sapier
committedAug 22, 2014
Fix "ghost" blocks if block update is "on wire" while player digs nodes
1 parent 247a1eb commit 8e9d896

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed
 

‎src/clientiface.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ std::string ClientInterface::state2Name(ClientState state)
5252
return statenames[state];
5353
}
5454

55+
void RemoteClient::ResendBlockIfOnWire(v3s16 p)
56+
{
57+
// if this block is on wire, mark it for sending again as soon as possible
58+
if (m_blocks_sending.find(p) != m_blocks_sending.end()) {
59+
SetBlockNotSent(p);
60+
}
61+
}
5562

5663
void RemoteClient::GetNextBlocks(
5764
ServerEnvironment *env,

‎src/clientiface.h

+8
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,14 @@ class RemoteClient
238238
void SetBlockNotSent(v3s16 p);
239239
void SetBlocksNotSent(std::map<v3s16, MapBlock*> &blocks);
240240

241+
/**
242+
* tell client about this block being modified right now.
243+
* this information is required to requeue the block in case it's "on wire"
244+
* while modification is processed by server
245+
* @param p position of modified block
246+
*/
247+
void ResendBlockIfOnWire(v3s16 p);
248+
241249
s32 SendingCount()
242250
{
243251
return m_blocks_sending.size();

‎src/server.cpp

+16-7
Original file line numberDiff line numberDiff line change
@@ -2545,14 +2545,17 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
25452545
if(is_valid_dig && n.getContent() != CONTENT_IGNORE)
25462546
m_script->node_on_dig(p_under, n, playersao);
25472547

2548+
v3s16 blockpos = getNodeBlockPos(floatToInt(pointed_pos_under, BS));
2549+
RemoteClient *client = getClient(peer_id);
25482550
// Send unusual result (that is, node not being removed)
25492551
if(m_env->getMap().getNodeNoEx(p_under).getContent() != CONTENT_AIR)
25502552
{
25512553
// Re-send block to revert change on client-side
2552-
RemoteClient *client = getClient(peer_id);
2553-
v3s16 blockpos = getNodeBlockPos(floatToInt(pointed_pos_under, BS));
25542554
client->SetBlockNotSent(blockpos);
25552555
}
2556+
else {
2557+
client->ResendBlockIfOnWire(blockpos);
2558+
}
25562559
}
25572560
} // action == 2
25582561

@@ -2594,15 +2597,21 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
25942597

25952598
// If item has node placement prediction, always send the
25962599
// blocks to make sure the client knows what exactly happened
2597-
if(item.getDefinition(m_itemdef).node_placement_prediction != ""){
2598-
RemoteClient *client = getClient(peer_id);
2599-
v3s16 blockpos = getNodeBlockPos(floatToInt(pointed_pos_above, BS));
2600+
RemoteClient *client = getClient(peer_id);
2601+
v3s16 blockpos = getNodeBlockPos(floatToInt(pointed_pos_above, BS));
2602+
v3s16 blockpos2 = getNodeBlockPos(floatToInt(pointed_pos_under, BS));
2603+
if(item.getDefinition(m_itemdef).node_placement_prediction != "") {
26002604
client->SetBlockNotSent(blockpos);
2601-
v3s16 blockpos2 = getNodeBlockPos(floatToInt(pointed_pos_under, BS));
2602-
if(blockpos2 != blockpos){
2605+
if(blockpos2 != blockpos) {
26032606
client->SetBlockNotSent(blockpos2);
26042607
}
26052608
}
2609+
else {
2610+
client->ResendBlockIfOnWire(blockpos);
2611+
if(blockpos2 != blockpos) {
2612+
client->ResendBlockIfOnWire(blockpos2);
2613+
}
2614+
}
26062615
} // action == 3
26072616

26082617
/*

0 commit comments

Comments
 (0)
Please sign in to comment.