summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-25 23:46:18 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-25 23:46:18 +0200
commit7157ebc061b496d84c685070107045e8440a6ef0 (patch)
tree46ae305d432f61b0fef5363b49ea534bcafdab10 /source
parentRemoved cPackets from cChunk. (diff)
downloadcuberite-7157ebc061b496d84c685070107045e8440a6ef0.tar
cuberite-7157ebc061b496d84c685070107045e8440a6ef0.tar.gz
cuberite-7157ebc061b496d84c685070107045e8440a6ef0.tar.bz2
cuberite-7157ebc061b496d84c685070107045e8440a6ef0.tar.lz
cuberite-7157ebc061b496d84c685070107045e8440a6ef0.tar.xz
cuberite-7157ebc061b496d84c685070107045e8440a6ef0.tar.zst
cuberite-7157ebc061b496d84c685070107045e8440a6ef0.zip
Diffstat (limited to '')
-rw-r--r--source/cBlockingTCPLink.cpp1
-rw-r--r--source/cChunk.cpp16
-rw-r--r--source/cChunk.h1
-rw-r--r--source/cChunkMap.cpp18
-rw-r--r--source/cChunkMap.h2
-rw-r--r--source/cClientHandle.cpp58
-rw-r--r--source/cClientHandle.h4
-rw-r--r--source/cWorld.cpp110
-rw-r--r--source/cWorld.h7
9 files changed, 174 insertions, 43 deletions
diff --git a/source/cBlockingTCPLink.cpp b/source/cBlockingTCPLink.cpp
index 741eb328c..d297304cf 100644
--- a/source/cBlockingTCPLink.cpp
+++ b/source/cBlockingTCPLink.cpp
@@ -2,7 +2,6 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cBlockingTCPLink.h"
-#include "packets/cPacket.h"
diff --git a/source/cChunk.cpp b/source/cChunk.cpp
index 53c310a2e..8fb4570ae 100644
--- a/source/cChunk.cpp
+++ b/source/cChunk.cpp
@@ -1905,6 +1905,22 @@ void cChunk::BroadcastCollectPickup(const cPickup & a_Pickup, const cPlayer & a_
+void cChunk::BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude)
+{
+ for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr )
+ {
+ if (*itr == a_Exclude)
+ {
+ continue;
+ }
+ (*itr)->SendThunderbolt(a_BlockX, a_BlockY, a_BlockZ);
+ } // for itr - LoadedByClient[]
+}
+
+
+
+
+
void cChunk::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude)
{
// We can operate on entity pointers, we're inside the ChunkMap's CS lock which guards the list
diff --git a/source/cChunk.h b/source/cChunk.h
index 1b08f4d6b..714a14455 100644
--- a/source/cChunk.h
+++ b/source/cChunk.h
@@ -190,6 +190,7 @@ public:
void BroadcastSpawn (cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL);
void BroadcastCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL);
+ void BroadcastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL);
void SendBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, cClientHandle & a_Client);
diff --git a/source/cChunkMap.cpp b/source/cChunkMap.cpp
index c5a770871..16e250869 100644
--- a/source/cChunkMap.cpp
+++ b/source/cChunkMap.cpp
@@ -467,6 +467,24 @@ void cChunkMap::BroadcastCollectPickup(const cPickup & a_Pickup, const cPlayer &
+void cChunkMap::BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude)
+{
+ cCSLock Lock(m_CSLayers);
+ int ChunkX, ChunkZ;
+ cChunkDef::BlockToChunk(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ);
+ if (Chunk == NULL)
+ {
+ return;
+ }
+ // It's perfectly legal to broadcast packets even to invalid chunks!
+ Chunk->BroadcastThunderbolt(a_BlockX, a_BlockY, a_BlockZ, a_Exclude);
+}
+
+
+
+
+
void cChunkMap::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSLayers);
diff --git a/source/cChunkMap.h b/source/cChunkMap.h
index 54b65a019..95591c5b6 100644
--- a/source/cChunkMap.h
+++ b/source/cChunkMap.h
@@ -80,6 +80,8 @@ public:
void BroadcastCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL);
+ void BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL);
+
/// Broadcasts the block entity, if it is at the coords specified, to all clients except a_Exclude
void BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude);
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp
index a0ec88f80..206ad9acd 100644
--- a/source/cClientHandle.cpp
+++ b/source/cClientHandle.cpp
@@ -74,6 +74,7 @@
#include "packets/cPacket_Respawn.h"
#include "packets/cPacket_SpawnMob.h"
#include "packets/cPacket_TeleportEntity.h"
+#include "packets/cPacket_Thunderbolt.h"
#include "packets/cPacket_TimeUpdate.h"
#include "packets/cPacket_UpdateHealth.h"
#include "packets/cPacket_UpdateSign.h"
@@ -1969,6 +1970,63 @@ void cClientHandle::SendUnloadChunk(int a_ChunkX, int a_ChunkZ)
+void cClientHandle::SendWeather(eWeather a_Weather)
+{
+ switch( a_Weather )
+ {
+ case eWeather_Sunny:
+ {
+ cPacket_NewInvalidState WeatherPacket;
+ WeatherPacket.m_Reason = 2; // stop rain
+ Send(WeatherPacket);
+ break;
+ }
+
+ case eWeather_Rain:
+ {
+ cPacket_NewInvalidState WeatherPacket;
+ WeatherPacket.m_Reason = 1; // begin rain
+ Send(WeatherPacket);
+ break;
+ }
+
+ case eWeather_ThunderStorm:
+ {
+ cPacket_NewInvalidState WeatherPacket;
+ WeatherPacket.m_Reason = 1; // begin rain
+ Send(WeatherPacket);
+ break;
+ }
+ }
+}
+
+
+
+
+
+void cClientHandle::SendTimeUpdate(Int64 a_WorldTime)
+{
+ cPacket_TimeUpdate tu;
+ tu.m_Time = a_WorldTime;
+ Send(tu);
+}
+
+
+
+
+
+void cClientHandle::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ)
+{
+ cPacket_Thunderbolt ThunderboltPacket;
+ ThunderboltPacket.m_xLBPos = a_BlockX;
+ ThunderboltPacket.m_yLBPos = a_BlockY;
+ ThunderboltPacket.m_zLBPos = a_BlockZ;
+}
+
+
+
+
+
void cClientHandle::CheckIfWorldDownloaded(void)
{
if (m_State != csDownloadingWorld)
diff --git a/source/cClientHandle.h b/source/cClientHandle.h
index 9c8586ae5..f270c9aa3 100644
--- a/source/cClientHandle.h
+++ b/source/cClientHandle.h
@@ -11,6 +11,7 @@
#ifndef CCLIENTHANDLE_H_INCLUDED
#define CCLIENTHANDLE_H_INCLUDED
+#include "defines.h"
#include "packets/cPacket.h"
#include "Vector3d.h"
#include "cSocketThreads.h"
@@ -117,6 +118,9 @@ public:
void SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
void SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes);
void SendUnloadChunk(int a_ChunkX, int a_ChunkZ);
+ void SendWeather(eWeather a_Weather);
+ void SendTimeUpdate(Int64 a_WorldTime);
+ void SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ);
const AString & GetUsername(void) const; //tolua_export
diff --git a/source/cWorld.cpp b/source/cWorld.cpp
index 232e3a44f..e5462fd93 100644
--- a/source/cWorld.cpp
+++ b/source/cWorld.cpp
@@ -43,12 +43,6 @@
#include "Trees.h"
#include "cPluginManager.h"
#include "blocks/Block.h"
-
-
-#include "packets/cPacket_TimeUpdate.h"
-#include "packets/cPacket_NewInvalidState.h"
-#include "packets/cPacket_Thunderbolt.h"
-
#include "Vector3d.h"
#include "tolua++.h"
@@ -312,38 +306,24 @@ cWorld::cWorld( const AString & a_WorldName )
-void cWorld::SetWeather( eWeather a_Weather )
+void cWorld::SetWeather(eWeather a_Weather)
{
- switch( a_Weather )
+ switch (a_Weather)
{
- case eWeather_Sunny:
- {
- m_Weather = a_Weather;
- cPacket_NewInvalidState WeatherPacket;
- WeatherPacket.m_Reason = 2; //stop rain
- Broadcast ( WeatherPacket );
- }
- break;
- case eWeather_Rain:
+ case eWeather_Sunny:
+ case eWeather_Rain:
+ case eWeather_ThunderStorm:
{
m_Weather = a_Weather;
- cPacket_NewInvalidState WeatherPacket;
- WeatherPacket.m_Reason = 1; //begin rain
- Broadcast ( WeatherPacket );
+ BroadcastWeather(a_Weather);
+ break;
}
- break;
- case eWeather_ThunderStorm:
+
+ default:
{
- m_Weather = a_Weather;
- cPacket_NewInvalidState WeatherPacket;
- WeatherPacket.m_Reason = 1; //begin rain
- Broadcast ( WeatherPacket );
- CastThunderbolt ( 0, 0, 0 ); //start thunderstorm with a lightning strike at 0, 0, 0. >:D
+ LOGWARN("Trying to set unknown weather %d", a_Weather);
+ break;
}
- break;
- default:
- LOGWARN("Trying to set unknown weather %d", a_Weather );
- break;
}
}
@@ -351,20 +331,24 @@ void cWorld::SetWeather( eWeather a_Weather )
-void cWorld::CastThunderbolt ( int a_X, int a_Y, int a_Z )
+void cWorld::CastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ)
{
- cPacket_Thunderbolt ThunderboltPacket;
- ThunderboltPacket.m_xLBPos = a_X;
- ThunderboltPacket.m_yLBPos = a_Y;
- ThunderboltPacket.m_zLBPos = a_Z;
- BroadcastToChunkOfBlock(a_X, a_Y, a_Z, &ThunderboltPacket);
+ BroadcastThunderbolt(a_BlockX, a_BlockY, a_BlockZ);
}
+
+
+
+
void cWorld::SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ)
{
return m_ChunkMap->SetNextBlockTick(a_BlockX, a_BlockY, a_BlockZ);
}
+
+
+
+
void cWorld::InitializeSpawn(void)
{
int ChunkX = 0, ChunkY = 0, ChunkZ = 0;
@@ -447,16 +431,17 @@ void cWorld::Tick(float a_Dt)
bool bSendTime = false;
m_WorldTimeFraction += a_Dt / 1000.f;
- while ( m_WorldTimeFraction > 1.f )
+ while (m_WorldTimeFraction > 1.f)
{
m_WorldTimeFraction -= 1.f;
m_WorldTime += 20;
bSendTime = true;
}
m_WorldTime %= 24000; // 24000 units in a day
- if ( bSendTime )
+
+ if (bSendTime)
{
- Broadcast( cPacket_TimeUpdate( (m_WorldTime) ) );
+ BroadcastTimeUpdate();
}
{
@@ -1408,6 +1393,51 @@ void cWorld::BroadcastCollectPickup(const cPickup & a_Pickup, const cPlayer & a_
+void cWorld::BroadcastWeather(eWeather a_Weather, const cClientHandle * a_Exclude)
+{
+ cCSLock Lock(m_CSPlayers);
+ for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
+ {
+ cClientHandle * ch = (*itr)->GetClientHandle();
+ if ((ch == a_Exclude) || (ch == NULL) || !ch->IsLoggedIn() || ch->IsDestroyed())
+ {
+ continue;
+ }
+ ch->SendWeather(a_Weather);
+ }
+}
+
+
+
+
+
+void cWorld::BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude)
+{
+ m_ChunkMap->BroadcastThunderbolt(a_BlockX, a_BlockY, a_BlockZ, a_Exclude);
+}
+
+
+
+
+
+void cWorld::BroadcastTimeUpdate(const cClientHandle * a_Exclude)
+{
+ cCSLock Lock(m_CSPlayers);
+ for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
+ {
+ cClientHandle * ch = (*itr)->GetClientHandle();
+ if ((ch == a_Exclude) || (ch == NULL) || !ch->IsLoggedIn() || ch->IsDestroyed())
+ {
+ continue;
+ }
+ ch->SendTimeUpdate(m_WorldTime);
+ }
+}
+
+
+
+
+
void cWorld::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude)
{
m_ChunkMap->BroadcastBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_Exclude);
diff --git a/source/cWorld.h b/source/cWorld.h
index 4d474df2c..5b4cf9564 100644
--- a/source/cWorld.h
+++ b/source/cWorld.h
@@ -92,6 +92,9 @@ public:
void BroadcastMetadata (const cPawn & a_Pawn, const cClientHandle * a_Exclude = NULL);
void BroadcastSpawn (cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
void BroadcastCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL);
+ void BroadcastWeather (eWeather a_Weather, const cClientHandle * a_Exclude = NULL);
+ void BroadcastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL);
+ void BroadcastTimeUpdate (const cClientHandle * a_Exclude = NULL);
/// If there is a block entity at the specified coods, sends it to all clients except a_Exclude
void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL);
@@ -365,9 +368,9 @@ public:
float ToWait;
};
- void QueueBlockForTick(int a_X, int a_Y, int a_Z, float a_Time);
+ void QueueBlockForTick(int a_BlockX, int a_BlockY, int a_BlockZ, float a_Time);
- void CastThunderbolt (int a_X, int a_Y, int a_Z); //tolua_export
+ void CastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ); //tolua_export
void SetWeather ( eWeather a_Weather ); //tolua_export
void ChangeWeather(); //tolua_export
eWeather GetWeather() { return m_Weather; }; //tolua_export