cWorld doesn't use cPackets.
git-svn-id: http://mc-server.googlecode.com/svn/trunk@789 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
bb25ba4977
commit
7157ebc061
@ -2,7 +2,6 @@
|
|||||||
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
||||||
|
|
||||||
#include "cBlockingTCPLink.h"
|
#include "cBlockingTCPLink.h"
|
||||||
#include "packets/cPacket.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -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)
|
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
|
// We can operate on entity pointers, we're inside the ChunkMap's CS lock which guards the list
|
||||||
|
@ -190,6 +190,7 @@ public:
|
|||||||
void BroadcastSpawn (cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
|
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 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 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);
|
void SendBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, cClientHandle & a_Client);
|
||||||
|
|
||||||
|
@ -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)
|
void cChunkMap::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude)
|
||||||
{
|
{
|
||||||
cCSLock Lock(m_CSLayers);
|
cCSLock Lock(m_CSLayers);
|
||||||
|
@ -80,6 +80,8 @@ public:
|
|||||||
|
|
||||||
void BroadcastCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player, 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);
|
||||||
|
|
||||||
/// Broadcasts the block entity, if it is at the coords specified, to all clients except a_Exclude
|
/// 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);
|
void BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude);
|
||||||
|
|
||||||
|
@ -74,6 +74,7 @@
|
|||||||
#include "packets/cPacket_Respawn.h"
|
#include "packets/cPacket_Respawn.h"
|
||||||
#include "packets/cPacket_SpawnMob.h"
|
#include "packets/cPacket_SpawnMob.h"
|
||||||
#include "packets/cPacket_TeleportEntity.h"
|
#include "packets/cPacket_TeleportEntity.h"
|
||||||
|
#include "packets/cPacket_Thunderbolt.h"
|
||||||
#include "packets/cPacket_TimeUpdate.h"
|
#include "packets/cPacket_TimeUpdate.h"
|
||||||
#include "packets/cPacket_UpdateHealth.h"
|
#include "packets/cPacket_UpdateHealth.h"
|
||||||
#include "packets/cPacket_UpdateSign.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)
|
void cClientHandle::CheckIfWorldDownloaded(void)
|
||||||
{
|
{
|
||||||
if (m_State != csDownloadingWorld)
|
if (m_State != csDownloadingWorld)
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#ifndef CCLIENTHANDLE_H_INCLUDED
|
#ifndef CCLIENTHANDLE_H_INCLUDED
|
||||||
#define CCLIENTHANDLE_H_INCLUDED
|
#define CCLIENTHANDLE_H_INCLUDED
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
#include "packets/cPacket.h"
|
#include "packets/cPacket.h"
|
||||||
#include "Vector3d.h"
|
#include "Vector3d.h"
|
||||||
#include "cSocketThreads.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 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 SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes);
|
||||||
void SendUnloadChunk(int a_ChunkX, int a_ChunkZ);
|
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
|
const AString & GetUsername(void) const; //tolua_export
|
||||||
|
|
||||||
|
@ -43,12 +43,6 @@
|
|||||||
#include "Trees.h"
|
#include "Trees.h"
|
||||||
#include "cPluginManager.h"
|
#include "cPluginManager.h"
|
||||||
#include "blocks/Block.h"
|
#include "blocks/Block.h"
|
||||||
|
|
||||||
|
|
||||||
#include "packets/cPacket_TimeUpdate.h"
|
|
||||||
#include "packets/cPacket_NewInvalidState.h"
|
|
||||||
#include "packets/cPacket_Thunderbolt.h"
|
|
||||||
|
|
||||||
#include "Vector3d.h"
|
#include "Vector3d.h"
|
||||||
|
|
||||||
#include "tolua++.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:
|
case eWeather_Sunny:
|
||||||
|
case eWeather_Rain:
|
||||||
|
case eWeather_ThunderStorm:
|
||||||
{
|
{
|
||||||
m_Weather = a_Weather;
|
m_Weather = a_Weather;
|
||||||
cPacket_NewInvalidState WeatherPacket;
|
BroadcastWeather(a_Weather);
|
||||||
WeatherPacket.m_Reason = 2; //stop rain
|
break;
|
||||||
Broadcast ( WeatherPacket );
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case eWeather_Rain:
|
default:
|
||||||
{
|
{
|
||||||
m_Weather = a_Weather;
|
LOGWARN("Trying to set unknown weather %d", a_Weather);
|
||||||
cPacket_NewInvalidState WeatherPacket;
|
break;
|
||||||
WeatherPacket.m_Reason = 1; //begin rain
|
|
||||||
Broadcast ( WeatherPacket );
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case eWeather_ThunderStorm:
|
|
||||||
{
|
|
||||||
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
|
|
||||||
}
|
|
||||||
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;
|
BroadcastThunderbolt(a_BlockX, a_BlockY, a_BlockZ);
|
||||||
ThunderboltPacket.m_xLBPos = a_X;
|
|
||||||
ThunderboltPacket.m_yLBPos = a_Y;
|
|
||||||
ThunderboltPacket.m_zLBPos = a_Z;
|
|
||||||
BroadcastToChunkOfBlock(a_X, a_Y, a_Z, &ThunderboltPacket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cWorld::SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ)
|
void cWorld::SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ)
|
||||||
{
|
{
|
||||||
return m_ChunkMap->SetNextBlockTick(a_BlockX, a_BlockY, a_BlockZ);
|
return m_ChunkMap->SetNextBlockTick(a_BlockX, a_BlockY, a_BlockZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cWorld::InitializeSpawn(void)
|
void cWorld::InitializeSpawn(void)
|
||||||
{
|
{
|
||||||
int ChunkX = 0, ChunkY = 0, ChunkZ = 0;
|
int ChunkX = 0, ChunkY = 0, ChunkZ = 0;
|
||||||
@ -447,16 +431,17 @@ void cWorld::Tick(float a_Dt)
|
|||||||
|
|
||||||
bool bSendTime = false;
|
bool bSendTime = false;
|
||||||
m_WorldTimeFraction += a_Dt / 1000.f;
|
m_WorldTimeFraction += a_Dt / 1000.f;
|
||||||
while ( m_WorldTimeFraction > 1.f )
|
while (m_WorldTimeFraction > 1.f)
|
||||||
{
|
{
|
||||||
m_WorldTimeFraction -= 1.f;
|
m_WorldTimeFraction -= 1.f;
|
||||||
m_WorldTime += 20;
|
m_WorldTime += 20;
|
||||||
bSendTime = true;
|
bSendTime = true;
|
||||||
}
|
}
|
||||||
m_WorldTime %= 24000; // 24000 units in a day
|
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)
|
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);
|
m_ChunkMap->BroadcastBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_Exclude);
|
||||||
|
@ -92,6 +92,9 @@ public:
|
|||||||
void BroadcastMetadata (const cPawn & a_Pawn, const cClientHandle * a_Exclude = NULL);
|
void BroadcastMetadata (const cPawn & a_Pawn, const cClientHandle * a_Exclude = NULL);
|
||||||
void BroadcastSpawn (cEntity & a_Entity, 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 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
|
/// 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);
|
void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL);
|
||||||
@ -365,9 +368,9 @@ public:
|
|||||||
float ToWait;
|
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 SetWeather ( eWeather a_Weather ); //tolua_export
|
||||||
void ChangeWeather(); //tolua_export
|
void ChangeWeather(); //tolua_export
|
||||||
eWeather GetWeather() { return m_Weather; }; //tolua_export
|
eWeather GetWeather() { return m_Weather; }; //tolua_export
|
||||||
|
Loading…
Reference in New Issue
Block a user