From 4cebaa99f88e25e039416354cf490fe98642af7e Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Thu, 1 Nov 2012 21:38:20 +0000 Subject: Refactored the world time. Now it is stored in two values - WorldAge (only incremented, plugins cannot change) and TimeOfDay (plugins can change). Since sub-tick precision is needed in Tick(), we store it both as number of seconds (double) and number of ticks (Int64) is calculated off of that. git-svn-id: http://mc-server.googlecode.com/svn/trunk@1022 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/ClientHandle.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'source/ClientHandle.cpp') diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index a6e025f8c..24654d303 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -81,7 +81,7 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) , m_bDestroyed(false) , m_Player(NULL) , m_bKicking(false) - , m_TimeLastPacket(cWorld::GetTime()) + , m_TimeSinceLastPacket(0) , m_bKeepThreadGoing(true) , m_Ping(1000) , m_PingID(1) @@ -244,7 +244,7 @@ void cClientHandle::Authenticate(void) } // Send time - m_Protocol->SendTimeUpdate(World->GetWorldTime()); + m_Protocol->SendTimeUpdate(World->GetWorldAge(), World->GetTimeOfDay()); // Send inventory m_Player->GetInventory().SendWholeInventory(*this); @@ -1049,6 +1049,8 @@ bool cClientHandle::CheckBlockInteractionsRate(void) { ASSERT(m_Player != NULL); ASSERT(m_Player->GetWorld() != NULL); + /* + // TODO: _X 2012_11_01: This needs a total re-thinking and rewriting int LastActionCnt = m_Player->GetLastBlockActionCnt(); if ((m_Player->GetWorld()->GetTime() - m_Player->GetLastBlockActionTime()) < 0.1) { @@ -1068,6 +1070,7 @@ bool cClientHandle::CheckBlockInteractionsRate(void) m_Player->SetLastBlockActionCnt(0); // Reset count m_Player->SetLastBlockActionTime(); // Player tried to interact with a block. Reset last block interation time. } + */ return true; } @@ -1077,8 +1080,8 @@ bool cClientHandle::CheckBlockInteractionsRate(void) void cClientHandle::Tick(float a_Dt) { - (void)a_Dt; - if (cWorld::GetTime() - m_TimeLastPacket > 30.f) // 30 seconds time-out + m_TimeSinceLastPacket += a_Dt; + if (m_TimeSinceLastPacket > 30000.f) // 30 seconds time-out { SendDisconnect("Nooooo!! You timed out! D: Come back!"); Destroy(); @@ -1459,9 +1462,9 @@ void cClientHandle::SendWeather(eWeather a_Weather) -void cClientHandle::SendTimeUpdate(Int64 a_WorldTime) +void cClientHandle::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay) { - m_Protocol->SendTimeUpdate(a_WorldTime); + m_Protocol->SendTimeUpdate(a_WorldAge, a_TimeOfDay); } @@ -1704,7 +1707,7 @@ void cClientHandle::DataReceived(const char * a_Data, int a_Size) { // Data is received from the client, hand it off to the protocol: m_Protocol->DataReceived(a_Data, a_Size); - m_TimeLastPacket = cWorld::GetTime(); + m_TimeSinceLastPacket = 0; } -- cgit v1.2.3