summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-02-05 00:40:58 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-02-05 00:40:58 +0100
commit94c343fe079346caf24be265234cce194bc3b450 (patch)
tree276bb4da0238ff7290ad69853f81f88b419aff47
parentFixed annoying creative on fire bug (diff)
downloadcuberite-94c343fe079346caf24be265234cce194bc3b450.tar
cuberite-94c343fe079346caf24be265234cce194bc3b450.tar.gz
cuberite-94c343fe079346caf24be265234cce194bc3b450.tar.bz2
cuberite-94c343fe079346caf24be265234cce194bc3b450.tar.lz
cuberite-94c343fe079346caf24be265234cce194bc3b450.tar.xz
cuberite-94c343fe079346caf24be265234cce194bc3b450.tar.zst
cuberite-94c343fe079346caf24be265234cce194bc3b450.zip
-rw-r--r--src/ChunkMap.cpp2
-rw-r--r--src/ClientHandle.cpp30
-rw-r--r--src/ClientHandle.h13
3 files changed, 13 insertions, 32 deletions
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index cb10e275d..db2a1b1d9 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -1839,7 +1839,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
bbTNT.Expand(ExplosionSizeInt * 2, ExplosionSizeInt * 2, ExplosionSizeInt * 2);
- cTNTDamageCallback TNTDamageCallback(bbTNT, Vector3d(a_BlockX, a_BlockY, a_BlockZ), a_ExplosionSizeInt, ExplosionSizeSq);
+ cTNTDamageCallback TNTDamageCallback(bbTNT, Vector3d(a_BlockX, a_BlockY, a_BlockZ), ExplosionSizeInt, ExplosionSizeSq);
ForEachEntity(TNTDamageCallback);
// Wake up all simulators for the area, so that water and lava flows and sand falls into the blasted holes (FS #391):
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 3e9e03815..3059ae7b1 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -44,16 +44,13 @@
-/// If the number of queued outgoing packets reaches this, the client will be kicked
+/** If the number of queued outgoing packets reaches this, the client will be kicked */
#define MAX_OUTGOING_PACKETS 2000
-/// How many explosions per single game tick are allowed
-static const int MAX_EXPLOSIONS_PER_TICK = 100;
+/** Maximum number of explosions to send this tick, server will start dropping if exceeded */
+#define MAX_EXPLOSIONS_PER_TICK 100
-/// How many explosions in the recent history are allowed
-static const int MAX_RUNNING_SUM_EXPLOSIONS = cClientHandle::NUM_CHECK_EXPLOSIONS_TICKS * MAX_EXPLOSIONS_PER_TICK / 8;
-
-/// How many ticks before the socket is closed after the client is destroyed (#31)
+/** How many ticks before the socket is closed after the client is destroyed (#31) */
static const int TICKS_BEFORE_CLOSE = 20;
@@ -95,8 +92,7 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) :
m_TicksSinceDestruction(0),
m_State(csConnected),
m_ShouldCheckDownloaded(false),
- m_CurrentExplosionTick(0),
- m_RunningSumExplosions(0),
+ m_NumExplosionsThisTick(0),
m_UniqueID(0),
m_HasSentPlayerChunk(false)
{
@@ -1637,10 +1633,8 @@ void cClientHandle::Tick(float a_Dt)
}
}
- // Update the explosion statistics:
- m_CurrentExplosionTick = (m_CurrentExplosionTick + 1) % ARRAYCOUNT(m_NumExplosionsPerTick);
- m_RunningSumExplosions -= m_NumExplosionsPerTick[m_CurrentExplosionTick];
- m_NumExplosionsPerTick[m_CurrentExplosionTick] = 0;
+ // Reset explosion counter:
+ m_NumExplosionsThisTick = 0;
}
@@ -1920,18 +1914,14 @@ void cClientHandle::SendEntityVelocity(const cEntity & a_Entity)
void cClientHandle::SendExplosion(double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion)
{
- if (
- (m_NumExplosionsPerTick[m_CurrentExplosionTick] > MAX_EXPLOSIONS_PER_TICK) || // Too many explosions in this tick
- (m_RunningSumExplosions > MAX_RUNNING_SUM_EXPLOSIONS) // Too many explosions in the recent history
- )
+ if (m_NumExplosionsThisTick > MAX_EXPLOSIONS_PER_TICK)
{
- LOGD("Dropped %u explosions", a_BlocksAffected.size());
+ LOGD("Dropped an explosion!");
return;
}
// Update the statistics:
- m_NumExplosionsPerTick[m_CurrentExplosionTick] += a_BlocksAffected.size();
- m_RunningSumExplosions += a_BlocksAffected.size();
+ m_NumExplosionsThisTick += 1;
m_Protocol->SendExplosion(a_BlockX, a_BlockY, a_BlockZ, a_Radius, a_BlocksAffected, a_PlayerMotion);
}
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index e1f326543..29a56f5a7 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -53,9 +53,6 @@ public:
static const int MAX_VIEW_DISTANCE = 15;
static const int MIN_VIEW_DISTANCE = 3;
- /// How many ticks should be checked for a running average of explosions, for limiting purposes
- static const int NUM_CHECK_EXPLOSIONS_TICKS = 20;
-
cClientHandle(const cSocket * a_Socket, int a_ViewDistance);
virtual ~cClientHandle();
@@ -301,14 +298,8 @@ private:
/// If set to true during csDownloadingWorld, the tick thread calls CheckIfWorldDownloaded()
bool m_ShouldCheckDownloaded;
- /// Stores the recent history of the number of explosions per tick
- int m_NumExplosionsPerTick[NUM_CHECK_EXPLOSIONS_TICKS];
-
- /// Points to the current tick in the m_NumExplosionsPerTick[] array
- int m_CurrentExplosionTick;
-
- /// Running sum of m_NumExplosionsPerTick[]
- int m_RunningSumExplosions;
+ /** Number of explosions sent this tick */
+ int m_NumExplosionsThisTick;
static int s_ClientCount;
int m_UniqueID;