summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-04-15 23:40:06 +0200
committermadmaxoft <github@xoft.cz>2014-04-15 23:40:06 +0200
commit99e4225269776d4e79b7d0d14dc8bbe11a2ad32d (patch)
tree4809a71978fb716e950c36c02cf9000deda8cbe9 /src
parentAdded support for per-piece per-placement weights in cPieceGenerator. (diff)
downloadcuberite-99e4225269776d4e79b7d0d14dc8bbe11a2ad32d.tar
cuberite-99e4225269776d4e79b7d0d14dc8bbe11a2ad32d.tar.gz
cuberite-99e4225269776d4e79b7d0d14dc8bbe11a2ad32d.tar.bz2
cuberite-99e4225269776d4e79b7d0d14dc8bbe11a2ad32d.tar.lz
cuberite-99e4225269776d4e79b7d0d14dc8bbe11a2ad32d.tar.xz
cuberite-99e4225269776d4e79b7d0d14dc8bbe11a2ad32d.tar.zst
cuberite-99e4225269776d4e79b7d0d14dc8bbe11a2ad32d.zip
Diffstat (limited to '')
-rw-r--r--src/ClientHandle.cpp15
-rw-r--r--src/Protocol/Protocol17x.cpp7
2 files changed, 16 insertions, 6 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 79738ff0b..9ab32d6ec 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -1718,13 +1718,16 @@ void cClientHandle::Tick(float a_Dt)
}
// Send a ping packet:
- cTimer t1;
- if ((m_LastPingTime + cClientHandle::PING_TIME_MS <= t1.GetNowTime()))
+ if (m_State == csPlaying)
{
- m_PingID++;
- m_PingStartTime = t1.GetNowTime();
- m_Protocol->SendKeepAlive(m_PingID);
- m_LastPingTime = m_PingStartTime;
+ cTimer t1;
+ if ((m_LastPingTime + cClientHandle::PING_TIME_MS <= t1.GetNowTime()))
+ {
+ m_PingID++;
+ m_PingStartTime = t1.GetNowTime();
+ m_Protocol->SendKeepAlive(m_PingID);
+ m_LastPingTime = m_PingStartTime;
+ }
}
// Handle block break animation:
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index c8105c03a..aae87f994 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -538,6 +538,13 @@ void cProtocol172::SendInventorySlot(char a_WindowID, short a_SlotNum, const cIt
void cProtocol172::SendKeepAlive(int a_PingID)
{
+ // Drop the packet if the protocol is not in the Game state yet (caused a client crash):
+ if (m_State != 3)
+ {
+ LOGWARNING("Trying to send a KeepAlive packet to a player who's not yet fully logged in (%d). The protocol class prevented the packet.", m_State);
+ return;
+ }
+
cPacketizer Pkt(*this, 0x00); // Keep Alive packet
Pkt.WriteInt(a_PingID);
}