2012-06-14 09:06:06 -04:00
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "ClientHandle.h"
|
|
|
|
#include "Server.h"
|
|
|
|
#include "World.h"
|
2013-08-19 05:39:13 -04:00
|
|
|
#include "Entities/Pickup.h"
|
2013-12-08 06:17:54 -05:00
|
|
|
#include "Bindings/PluginManager.h"
|
2013-08-19 05:39:13 -04:00
|
|
|
#include "Entities/Player.h"
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "Inventory.h"
|
2014-07-31 06:13:11 -04:00
|
|
|
#include "BlockEntities/BeaconEntity.h"
|
2013-05-28 15:12:47 -04:00
|
|
|
#include "BlockEntities/ChestEntity.h"
|
2014-01-18 12:58:46 -05:00
|
|
|
#include "BlockEntities/CommandBlockEntity.h"
|
2013-05-28 15:12:47 -04:00
|
|
|
#include "BlockEntities/SignEntity.h"
|
2012-09-23 13:19:34 -04:00
|
|
|
#include "UI/Window.h"
|
2014-12-13 09:06:55 -05:00
|
|
|
#include "UI/AnvilWindow.h"
|
|
|
|
#include "UI/BeaconWindow.h"
|
|
|
|
#include "UI/EnchantingWindow.h"
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "Item.h"
|
2012-09-23 16:53:08 -04:00
|
|
|
#include "Mobs/Monster.h"
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "ChatColor.h"
|
2012-09-29 09:59:32 -04:00
|
|
|
#include "Items/ItemHandler.h"
|
|
|
|
#include "Blocks/BlockHandler.h"
|
2013-08-25 10:11:19 -04:00
|
|
|
#include "Blocks/BlockSlab.h"
|
2015-02-08 16:21:48 -05:00
|
|
|
#include "Blocks/BlockBed.h"
|
2014-01-26 09:20:39 -05:00
|
|
|
#include "Blocks/ChunkInterface.h"
|
2015-04-14 04:49:01 -04:00
|
|
|
#include "BlockInServerPluginInterface.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "Root.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-04-13 07:04:56 -04:00
|
|
|
#include "Protocol/Authenticator.h"
|
2012-09-23 16:03:26 -04:00
|
|
|
#include "Protocol/ProtocolRecognizer.h"
|
2014-02-15 17:16:44 -05:00
|
|
|
#include "CompositeChat.h"
|
2014-02-23 14:02:44 -05:00
|
|
|
#include "Items/ItemSword.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-06-27 13:34:53 -04:00
|
|
|
#include "polarssl/md5.h"
|
2014-04-14 14:21:00 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
2014-02-04 18:40:58 -05:00
|
|
|
/** Maximum number of explosions to send this tick, server will start dropping if exceeded */
|
2014-02-04 19:45:08 -05:00
|
|
|
#define MAX_EXPLOSIONS_PER_TICK 20
|
2013-06-18 15:32:31 -04:00
|
|
|
|
2014-03-01 16:24:36 -05:00
|
|
|
/** Maximum number of block change interactions a player can perform per tick - exceeding this causes a kick */
|
|
|
|
#define MAX_BLOCK_CHANGE_INTERACTIONS 20
|
|
|
|
|
2014-12-07 09:46:27 -05:00
|
|
|
/** The interval for sending pings to clients.
|
|
|
|
Vanilla sends one ping every 1 second. */
|
|
|
|
static const std::chrono::milliseconds PING_TIME_MS = std::chrono::milliseconds(1000);
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int cClientHandle::s_ClientCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-14 09:06:06 -04:00
|
|
|
// cClientHandle:
|
|
|
|
|
2015-01-24 14:17:00 -05:00
|
|
|
cClientHandle::cClientHandle(const AString & a_IPString, int a_ViewDistance) :
|
2014-11-15 16:26:54 -05:00
|
|
|
m_CurrentViewDistance(a_ViewDistance),
|
2014-11-15 09:33:42 -05:00
|
|
|
m_RequestedViewDistance(a_ViewDistance),
|
2015-01-24 14:17:00 -05:00
|
|
|
m_IPString(a_IPString),
|
2014-10-20 16:55:07 -04:00
|
|
|
m_Player(nullptr),
|
2013-12-20 13:10:07 -05:00
|
|
|
m_HasSentDC(false),
|
|
|
|
m_LastStreamedChunkX(0x7fffffff), // bogus chunk coords to force streaming upon login
|
|
|
|
m_LastStreamedChunkZ(0x7fffffff),
|
2015-01-24 14:17:00 -05:00
|
|
|
m_TicksSinceLastPacket(0),
|
2013-12-20 13:10:07 -05:00
|
|
|
m_Ping(1000),
|
|
|
|
m_PingID(1),
|
|
|
|
m_BlockDigAnimStage(-1),
|
2014-08-21 16:39:53 -04:00
|
|
|
m_BlockDigAnimSpeed(0),
|
|
|
|
m_BlockDigAnimX(0),
|
|
|
|
m_BlockDigAnimY(256), // Invalid Y, so that the coords don't get picked up
|
|
|
|
m_BlockDigAnimZ(0),
|
2013-12-20 13:10:07 -05:00
|
|
|
m_HasStartedDigging(false),
|
2014-08-21 16:39:53 -04:00
|
|
|
m_LastDigBlockX(0),
|
|
|
|
m_LastDigBlockY(256), // Invalid Y, so that the coords don't get picked up
|
|
|
|
m_LastDigBlockZ(0),
|
2013-12-20 13:10:07 -05:00
|
|
|
m_State(csConnected),
|
|
|
|
m_ShouldCheckDownloaded(false),
|
2014-02-04 18:40:58 -05:00
|
|
|
m_NumExplosionsThisTick(0),
|
2014-08-21 16:39:53 -04:00
|
|
|
m_NumBlockChangeInteractionsThisTick(0),
|
2013-12-20 13:10:07 -05:00
|
|
|
m_UniqueID(0),
|
2014-03-08 11:33:38 -05:00
|
|
|
m_HasSentPlayerChunk(false),
|
2014-10-05 14:19:21 -04:00
|
|
|
m_Locale("en_GB"),
|
2014-11-15 16:36:31 -05:00
|
|
|
m_LastPlacedSign(0, -1, 0),
|
2014-10-05 14:19:21 -04:00
|
|
|
m_ProtocolVersion(0)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-30 05:56:59 -04:00
|
|
|
m_Protocol = new cProtocolRecognizer(this);
|
2012-08-27 13:31:16 -04:00
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
s_ClientCount++; // Not protected by CS because clients are always constructed from the same thread
|
2012-06-14 09:06:06 -04:00
|
|
|
m_UniqueID = s_ClientCount;
|
2014-12-07 09:46:27 -05:00
|
|
|
m_PingStartTime = std::chrono::steady_clock::now();
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-08-27 13:31:16 -04:00
|
|
|
LOGD("New ClientHandle created at %p", this);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cClientHandle::~cClientHandle()
|
|
|
|
{
|
2014-07-12 19:12:32 -04:00
|
|
|
ASSERT(m_State == csDestroyed); // Has Destroy() been called?
|
2012-11-11 09:00:58 -05:00
|
|
|
|
2012-08-27 13:31:16 -04:00
|
|
|
LOGD("Deleting client \"%s\" at %p", GetUsername().c_str(), this);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSChunkLists);
|
|
|
|
m_LoadedChunks.clear();
|
|
|
|
m_ChunksToSend.clear();
|
|
|
|
}
|
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_Player != nullptr)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
cWorld * World = m_Player->GetWorld();
|
2014-10-20 16:55:07 -04:00
|
|
|
if (World != nullptr)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-09-23 08:39:49 -04:00
|
|
|
if (!m_Username.empty())
|
|
|
|
{
|
|
|
|
// Send the Offline PlayerList packet:
|
|
|
|
World->BroadcastPlayerListRemovePlayer(*m_Player, this);
|
|
|
|
}
|
|
|
|
|
2014-07-29 15:50:30 -04:00
|
|
|
World->RemovePlayer(m_Player, true); // Must be called before cPlayer::Destroy() as otherwise cChunk tries to delete the player, and then we do it again
|
2013-04-13 17:02:10 -04:00
|
|
|
m_Player->Destroy();
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2013-04-13 17:02:10 -04:00
|
|
|
delete m_Player;
|
2014-10-20 16:55:07 -04:00
|
|
|
m_Player = nullptr;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2013-01-05 14:05:15 -05:00
|
|
|
if (!m_HasSentDC)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-09-25 04:23:19 -04:00
|
|
|
SendDisconnect("Server shut down? Kthnxbai");
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-08-27 13:31:16 -04:00
|
|
|
delete m_Protocol;
|
2014-10-20 16:55:07 -04:00
|
|
|
m_Protocol = nullptr;
|
2012-08-27 13:31:16 -04:00
|
|
|
|
|
|
|
LOGD("ClientHandle at %p deleted", this);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-13 16:45:29 -04:00
|
|
|
void cClientHandle::Destroy(void)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2015-01-24 14:17:00 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSOutgoingData);
|
|
|
|
m_Link.reset();
|
|
|
|
}
|
2013-08-13 16:45:29 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSDestroyingState);
|
|
|
|
if (m_State >= csDestroying)
|
|
|
|
{
|
|
|
|
// Already called
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_State = csDestroying;
|
|
|
|
}
|
|
|
|
|
|
|
|
// DEBUG:
|
|
|
|
LOGD("%s: client %p, \"%s\"", __FUNCTION__, this, m_Username.c_str());
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
if ((m_Player != nullptr) && (m_Player->GetWorld() != nullptr))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
RemoveFromAllChunks();
|
|
|
|
m_Player->GetWorld()->RemoveClientFromChunkSender(this);
|
|
|
|
}
|
2015-01-24 14:17:00 -05:00
|
|
|
if (m_Player != nullptr)
|
|
|
|
{
|
|
|
|
m_Player->RemoveClientHandle();
|
|
|
|
}
|
2014-07-12 19:12:32 -04:00
|
|
|
m_State = csDestroyed;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-14 14:21:00 -04:00
|
|
|
void cClientHandle::GenerateOfflineUUID(void)
|
2014-04-14 16:52:59 -04:00
|
|
|
{
|
|
|
|
m_UUID = GenerateOfflineUUID(m_Username);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-26 12:21:49 -04:00
|
|
|
AString cClientHandle::FormatChatPrefix(bool ShouldAppendChatPrefixes, AString a_ChatPrefixS, AString m_Color1, AString m_Color2)
|
|
|
|
{
|
|
|
|
if (ShouldAppendChatPrefixes)
|
2014-12-05 10:59:11 -05:00
|
|
|
{
|
2014-04-26 17:01:48 -04:00
|
|
|
return Printf("%s[%s] %s", m_Color1.c_str(), a_ChatPrefixS.c_str(), m_Color2.c_str());
|
2014-12-05 10:59:11 -05:00
|
|
|
}
|
2014-04-26 12:21:49 -04:00
|
|
|
else
|
2014-12-05 10:59:11 -05:00
|
|
|
{
|
2014-04-26 12:21:49 -04:00
|
|
|
return Printf("%s", m_Color1.c_str());
|
2014-12-05 10:59:11 -05:00
|
|
|
}
|
2014-04-26 12:21:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-24 20:24:39 -04:00
|
|
|
AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString &a_AdditionalData)
|
|
|
|
{
|
|
|
|
switch (a_ChatPrefix)
|
|
|
|
{
|
2014-04-27 12:35:41 -04:00
|
|
|
case mtCustom: return "";
|
2014-04-26 17:01:48 -04:00
|
|
|
case mtFailure: return FormatChatPrefix(ShouldAppendChatPrefixes, "INFO", cChatColor::Rose, cChatColor::White);
|
|
|
|
case mtInformation: return FormatChatPrefix(ShouldAppendChatPrefixes, "INFO", cChatColor::Yellow, cChatColor::White);
|
|
|
|
case mtSuccess: return FormatChatPrefix(ShouldAppendChatPrefixes, "INFO", cChatColor::Green, cChatColor::White);
|
|
|
|
case mtWarning: return FormatChatPrefix(ShouldAppendChatPrefixes, "WARN", cChatColor::Rose, cChatColor::White);
|
|
|
|
case mtFatal: return FormatChatPrefix(ShouldAppendChatPrefixes, "FATAL", cChatColor::Red, cChatColor::White);
|
|
|
|
case mtDeath: return FormatChatPrefix(ShouldAppendChatPrefixes, "DEATH", cChatColor::Gray, cChatColor::White);
|
|
|
|
case mtJoin: return FormatChatPrefix(ShouldAppendChatPrefixes, "JOIN", cChatColor::Yellow, cChatColor::White);
|
|
|
|
case mtLeave: return FormatChatPrefix(ShouldAppendChatPrefixes, "LEAVE", cChatColor::Yellow, cChatColor::White);
|
2014-04-24 20:24:39 -04:00
|
|
|
case mtPrivateMessage:
|
|
|
|
{
|
|
|
|
if (ShouldAppendChatPrefixes)
|
2014-04-28 14:37:22 -04:00
|
|
|
{
|
2014-07-19 14:15:21 -04:00
|
|
|
return Printf("%s[MSG: %s] %s%s", cChatColor::LightBlue, a_AdditionalData.c_str(), cChatColor::White, cChatColor::Italic);
|
2014-04-28 14:37:22 -04:00
|
|
|
}
|
2014-04-24 20:24:39 -04:00
|
|
|
else
|
2014-04-28 14:37:22 -04:00
|
|
|
{
|
2014-07-19 14:15:21 -04:00
|
|
|
return Printf("%s: %s", a_AdditionalData.c_str(), cChatColor::LightBlue);
|
2014-04-28 14:37:22 -04:00
|
|
|
}
|
2014-04-24 20:24:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ASSERT(!"Unhandled chat prefix type!");
|
2014-04-27 12:35:41 -04:00
|
|
|
return "";
|
2014-04-24 20:24:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-14 16:52:59 -04:00
|
|
|
AString cClientHandle::GenerateOfflineUUID(const AString & a_Username)
|
2014-04-14 14:21:00 -04:00
|
|
|
{
|
2014-06-21 16:13:35 -04:00
|
|
|
// Online UUIDs are always version 4 (random)
|
|
|
|
// We use Version 3 (MD5 hash) UUIDs for the offline UUIDs
|
|
|
|
// This guarantees that they will never collide with an online UUID and can be distinguished.
|
2014-04-14 14:21:00 -04:00
|
|
|
// Proper format for a version 3 UUID is:
|
|
|
|
// xxxxxxxx-xxxx-3xxx-yxxx-xxxxxxxxxxxx where x is any hexadecimal digit and y is one of 8, 9, A, or B
|
2014-07-30 07:52:51 -04:00
|
|
|
// Note that we generate a short UUID (without the dashes)
|
2014-04-14 14:21:00 -04:00
|
|
|
|
2014-10-15 07:41:23 -04:00
|
|
|
// First make the username lowercase:
|
|
|
|
AString lcUsername = StrToLower(a_Username);
|
|
|
|
|
2014-04-14 14:21:00 -04:00
|
|
|
// Generate an md5 checksum, and use it as base for the ID:
|
2014-06-27 13:34:53 -04:00
|
|
|
unsigned char MD5[16];
|
2014-10-15 07:41:23 -04:00
|
|
|
md5((const unsigned char *)lcUsername.c_str(), lcUsername.length(), MD5);
|
2014-06-29 12:27:41 -04:00
|
|
|
MD5[6] &= 0x0f; // Need to trim to 4 bits only...
|
|
|
|
MD5[8] &= 0x0f; // ... otherwise %01x overflows into two chars
|
2014-07-30 07:52:51 -04:00
|
|
|
return Printf("%02x%02x%02x%02x%02x%02x3%01x%02x8%01x%02x%02x%02x%02x%02x%02x%02x",
|
2014-06-29 12:27:41 -04:00
|
|
|
MD5[0], MD5[1], MD5[2], MD5[3],
|
|
|
|
MD5[4], MD5[5], MD5[6], MD5[7],
|
2014-06-27 13:34:53 -04:00
|
|
|
MD5[8], MD5[9], MD5[10], MD5[11],
|
|
|
|
MD5[12], MD5[13], MD5[14], MD5[15]
|
|
|
|
);
|
2014-04-14 14:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-21 16:13:35 -04:00
|
|
|
bool cClientHandle::IsUUIDOnline(const AString & a_UUID)
|
|
|
|
{
|
|
|
|
// Online UUIDs are always version 4 (random)
|
|
|
|
// We use Version 3 (MD5 hash) UUIDs for the offline UUIDs
|
|
|
|
// This guarantees that they will never collide with an online UUID and can be distinguished.
|
|
|
|
// The version-specifying char is at pos #12 of raw UUID, pos #14 in dashed-UUID.
|
|
|
|
switch (a_UUID.size())
|
|
|
|
{
|
|
|
|
case 32:
|
|
|
|
{
|
|
|
|
// This is the UUID format without dashes, the version char is at pos #12:
|
|
|
|
return (a_UUID[12] == '4');
|
|
|
|
}
|
|
|
|
case 36:
|
|
|
|
{
|
|
|
|
// This is the UUID format with dashes, the version char is at pos #14:
|
|
|
|
return (a_UUID[14] == '4');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
void cClientHandle::Kick(const AString & a_Reason)
|
|
|
|
{
|
|
|
|
if (m_State >= csAuthenticating) // Don't log pings
|
|
|
|
{
|
2013-12-07 09:41:58 -05:00
|
|
|
LOGINFO("Kicking player %s for \"%s\"", m_Username.c_str(), StripColorCodes(a_Reason).c_str());
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-08-25 17:59:13 -04:00
|
|
|
SendDisconnect(a_Reason);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-15 19:03:47 -04:00
|
|
|
void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
if (m_State != csAuthenticating)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
ASSERT(m_Player == nullptr);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-04-13 07:04:56 -04:00
|
|
|
m_Username = a_Name;
|
2014-09-17 10:01:14 -04:00
|
|
|
|
|
|
|
// Only assign UUID and properties if not already pre-assigned (BungeeCord sends those in the Handshake packet):
|
|
|
|
if (m_UUID.empty())
|
|
|
|
{
|
|
|
|
m_UUID = a_UUID;
|
|
|
|
}
|
|
|
|
if (m_Properties.empty())
|
|
|
|
{
|
|
|
|
m_Properties = a_Properties;
|
|
|
|
}
|
2014-04-14 16:52:59 -04:00
|
|
|
|
|
|
|
// Send login success (if the protocol supports it):
|
|
|
|
m_Protocol->SendLoginSuccess();
|
2014-04-13 07:04:56 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
// Spawn player (only serversided, so data is loaded)
|
2015-01-24 14:17:00 -05:00
|
|
|
m_Player = new cPlayer(m_Self, GetUsername());
|
|
|
|
m_Self.reset();
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
cWorld * World = cRoot::Get()->GetWorld(m_Player->GetLoadedWorldName());
|
2014-10-20 16:55:07 -04:00
|
|
|
if (World == nullptr)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
World = cRoot::Get()->GetDefaultWorld();
|
|
|
|
}
|
|
|
|
|
2012-08-27 13:31:16 -04:00
|
|
|
if (m_Player->GetGameMode() == eGameMode_NotSet)
|
|
|
|
{
|
2012-07-13 11:26:27 -04:00
|
|
|
m_Player->LoginSetGameMode(World->GetGameMode());
|
2012-08-27 13:31:16 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-09-25 04:23:19 -04:00
|
|
|
m_Player->SetIP (m_IPString);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-02-03 16:12:44 -05:00
|
|
|
if (!cRoot::Get()->GetPluginManager()->CallHookPlayerJoined(*m_Player))
|
|
|
|
{
|
2014-02-05 18:24:16 -05:00
|
|
|
cRoot::Get()->BroadcastChatJoin(Printf("%s has joined the game", GetUsername().c_str()));
|
2014-07-14 14:49:31 -04:00
|
|
|
LOGINFO("Player %s has joined the game", m_Username.c_str());
|
2014-02-03 16:12:44 -05:00
|
|
|
}
|
2012-09-23 12:54:03 -04:00
|
|
|
|
|
|
|
m_ConfirmPosition = m_Player->GetPosition();
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
// Return a server login packet
|
2012-09-02 08:09:58 -04:00
|
|
|
m_Protocol->SendLogin(*m_Player, *World);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
// Send Weather if raining:
|
|
|
|
if ((World->GetWeather() == 1) || (World->GetWeather() == 2))
|
|
|
|
{
|
2012-08-27 13:31:16 -04:00
|
|
|
m_Protocol->SendWeather(World->GetWeather());
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2014-08-10 14:06:03 -04:00
|
|
|
// Send time:
|
2014-08-10 18:20:28 -04:00
|
|
|
m_Protocol->SendTimeUpdate(World->GetWorldAge(), World->GetTimeOfDay(), World->IsDaylightCycleEnabled());
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-11-05 12:36:58 -05:00
|
|
|
// Send contents of the inventory window
|
|
|
|
m_Protocol->SendWholeInventory(*m_Player->GetWindow());
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
// Send health
|
2012-07-17 08:02:03 -04:00
|
|
|
m_Player->SendHealth();
|
2013-11-15 10:23:50 -05:00
|
|
|
|
|
|
|
// Send experience
|
|
|
|
m_Player->SendExperience();
|
2013-08-13 16:45:29 -04:00
|
|
|
|
2014-09-08 21:02:25 -04:00
|
|
|
// Send player list items
|
2014-09-18 12:50:17 -04:00
|
|
|
SendPlayerListAddPlayer(*m_Player);
|
|
|
|
World->BroadcastPlayerListAddPlayer(*m_Player);
|
2014-09-08 21:02:25 -04:00
|
|
|
World->SendPlayerList(m_Player);
|
2014-09-18 12:50:17 -04:00
|
|
|
|
2014-06-08 15:58:08 -04:00
|
|
|
m_Player->Initialize(*World);
|
2013-08-13 16:45:29 -04:00
|
|
|
m_State = csAuthenticated;
|
|
|
|
|
2014-01-21 08:58:17 -05:00
|
|
|
// Query player team
|
|
|
|
m_Player->UpdateTeam();
|
|
|
|
|
2014-01-21 12:43:13 -05:00
|
|
|
// Send scoreboard data
|
|
|
|
World->GetScoreBoard().SendTo(*this);
|
2014-05-11 07:57:06 -04:00
|
|
|
|
2014-06-28 19:40:15 -04:00
|
|
|
// Send statistics
|
|
|
|
SendStatistics(m_Player->GetStatManager());
|
|
|
|
|
2014-04-29 17:10:50 -04:00
|
|
|
// Delay the first ping until the client "settles down"
|
|
|
|
// This should fix #889, "BadCast exception, cannot convert bit to fm" error in client
|
2014-12-07 09:46:27 -05:00
|
|
|
m_PingStartTime = std::chrono::steady_clock::now() + std::chrono::seconds(3); // Send the first KeepAlive packet in 3 seconds
|
2014-01-21 12:43:13 -05:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
cRoot::Get()->GetPluginManager()->CallHookPlayerSpawned(*m_Player);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-06 15:27:53 -04:00
|
|
|
bool cClientHandle::StreamNextChunk(void)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-08-14 04:24:34 -04:00
|
|
|
if ((m_State < csAuthenticated) || (m_State >= csDestroying))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-10-06 15:27:53 -04:00
|
|
|
return true;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2014-10-20 16:55:07 -04:00
|
|
|
ASSERT(m_Player != nullptr);
|
2014-06-08 15:58:08 -04:00
|
|
|
|
2014-10-06 11:38:17 -04:00
|
|
|
int ChunkPosX = m_Player->GetChunkX();
|
|
|
|
int ChunkPosZ = m_Player->GetChunkZ();
|
|
|
|
if ((m_LastStreamedChunkX == ChunkPosX) && (m_LastStreamedChunkZ == ChunkPosZ))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-10-06 11:38:17 -04:00
|
|
|
// All chunks are already loaded. Abort loading.
|
2014-10-06 15:27:53 -04:00
|
|
|
return true;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2014-10-06 11:38:17 -04:00
|
|
|
|
|
|
|
// Get the look vector and normalize it.
|
|
|
|
Vector3d Position = m_Player->GetEyePosition();
|
2014-10-02 17:50:41 -04:00
|
|
|
Vector3d LookVector = m_Player->GetLookVector();
|
|
|
|
LookVector.Normalize();
|
2014-06-08 15:58:08 -04:00
|
|
|
|
2014-10-06 11:38:17 -04:00
|
|
|
// Lock the list
|
|
|
|
cCSLock Lock(m_CSChunkLists);
|
|
|
|
|
|
|
|
// High priority: Load the chunks that are in the view-direction of the player (with a radius of 3)
|
2014-11-15 16:26:54 -05:00
|
|
|
for (int Range = 0; Range < m_CurrentViewDistance; Range++)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-10-02 17:50:41 -04:00
|
|
|
Vector3d Vector = Position + LookVector * cChunkDef::Width * Range;
|
|
|
|
|
2014-10-06 11:38:17 -04:00
|
|
|
// Get the chunk from the x/z coords.
|
2014-10-02 17:50:41 -04:00
|
|
|
int RangeX, RangeZ = 0;
|
2014-10-21 11:00:41 -04:00
|
|
|
cChunkDef::BlockToChunk(FloorC(Vector.x), FloorC(Vector.z), RangeX, RangeZ);
|
2014-10-02 17:50:41 -04:00
|
|
|
|
2014-10-06 11:38:17 -04:00
|
|
|
for (size_t X = 0; X < 7; X++)
|
2014-10-02 17:50:41 -04:00
|
|
|
{
|
2014-10-06 11:38:17 -04:00
|
|
|
for (size_t Z = 0; Z < 7; Z++)
|
2014-10-02 17:50:41 -04:00
|
|
|
{
|
2014-10-06 11:38:17 -04:00
|
|
|
int ChunkX = RangeX + ((X >= 4) ? (3 - X) : X);
|
|
|
|
int ChunkZ = RangeZ + ((Z >= 4) ? (3 - Z) : Z);
|
2014-10-02 17:50:41 -04:00
|
|
|
cChunkCoords Coords(ChunkX, ChunkZ);
|
|
|
|
|
2014-10-07 15:36:01 -04:00
|
|
|
// Checks if the chunk is in distance
|
2014-11-15 16:26:54 -05:00
|
|
|
if ((Diff(ChunkX, ChunkPosX) > m_CurrentViewDistance) || (Diff(ChunkZ, ChunkPosZ) > m_CurrentViewDistance))
|
2014-10-07 15:36:01 -04:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-10-02 17:50:41 -04:00
|
|
|
// If the chunk already loading/loaded -> skip
|
2014-10-06 11:38:17 -04:00
|
|
|
if (
|
|
|
|
(std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), Coords) != m_ChunksToSend.end()) ||
|
|
|
|
(std::find(m_LoadedChunks.begin(), m_LoadedChunks.end(), Coords) != m_LoadedChunks.end())
|
|
|
|
)
|
2014-10-02 17:50:41 -04:00
|
|
|
{
|
2014-10-06 11:38:17 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unloaded chunk found -> Send it to the client.
|
|
|
|
Lock.Unlock();
|
2014-10-23 15:19:43 -04:00
|
|
|
StreamChunk(ChunkX, ChunkZ, ((Range <= 2) ? cChunkSender::E_CHUNK_PRIORITY_HIGH : cChunkSender::E_CHUNK_PRIORITY_MEDIUM));
|
2014-10-06 15:27:53 -04:00
|
|
|
return false;
|
2014-10-06 11:38:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Low priority: Add all chunks that are in range. (From the center out to the edge)
|
2014-11-15 16:26:54 -05:00
|
|
|
for (int d = 0; d <= m_CurrentViewDistance; ++d) // cycle through (square) distance, from nearest to furthest
|
2014-10-06 11:38:17 -04:00
|
|
|
{
|
|
|
|
// For each distance add chunks in a hollow square centered around current position:
|
|
|
|
cChunkCoordsList CurcleChunks;
|
|
|
|
for (int i = -d; i <= d; ++i)
|
|
|
|
{
|
|
|
|
CurcleChunks.push_back(cChunkCoords(ChunkPosX + d, ChunkPosZ + i));
|
|
|
|
CurcleChunks.push_back(cChunkCoords(ChunkPosX - d, ChunkPosZ + i));
|
|
|
|
}
|
|
|
|
for (int i = -d + 1; i < d; ++i)
|
|
|
|
{
|
|
|
|
CurcleChunks.push_back(cChunkCoords(ChunkPosX + i, ChunkPosZ + d));
|
|
|
|
CurcleChunks.push_back(cChunkCoords(ChunkPosX + i, ChunkPosZ - d));
|
|
|
|
}
|
|
|
|
|
|
|
|
// For each the CurcleChunks list and send the first unloaded chunk:
|
|
|
|
for (cChunkCoordsList::iterator itr = CurcleChunks.begin(), end = CurcleChunks.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
cChunkCoords Coords = *itr;
|
|
|
|
|
|
|
|
// If the chunk already loading/loaded -> skip
|
|
|
|
if (
|
|
|
|
(std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), Coords) != m_ChunksToSend.end()) ||
|
|
|
|
(std::find(m_LoadedChunks.begin(), m_LoadedChunks.end(), Coords) != m_LoadedChunks.end())
|
|
|
|
)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unloaded chunk found -> Send it to the client.
|
|
|
|
Lock.Unlock();
|
2014-10-06 15:27:53 -04:00
|
|
|
StreamChunk(Coords.m_ChunkX, Coords.m_ChunkZ, cChunkSender::E_CHUNK_PRIORITY_LOW);
|
|
|
|
return false;
|
2014-10-06 11:38:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// All chunks are loaded -> Sets the last loaded chunk coordinates to current coordinates
|
2012-06-14 09:06:06 -04:00
|
|
|
m_LastStreamedChunkX = ChunkPosX;
|
|
|
|
m_LastStreamedChunkZ = ChunkPosZ;
|
2014-10-06 15:27:53 -04:00
|
|
|
return true;
|
2014-10-02 17:50:41 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-10-02 17:50:41 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-10-02 17:50:41 -04:00
|
|
|
|
|
|
|
|
|
|
|
void cClientHandle::UnloadOutOfRangeChunks(void)
|
|
|
|
{
|
|
|
|
int ChunkPosX = FAST_FLOOR_DIV((int)m_Player->GetPosX(), cChunkDef::Width);
|
|
|
|
int ChunkPosZ = FAST_FLOOR_DIV((int)m_Player->GetPosZ(), cChunkDef::Width);
|
|
|
|
|
|
|
|
cChunkCoordsList ChunksToRemove;
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSChunkLists);
|
|
|
|
for (cChunkCoordsList::iterator itr = m_LoadedChunks.begin(); itr != m_LoadedChunks.end();)
|
|
|
|
{
|
2014-10-02 17:50:41 -04:00
|
|
|
int DiffX = Diff((*itr).m_ChunkX, ChunkPosX);
|
|
|
|
int DiffZ = Diff((*itr).m_ChunkZ, ChunkPosZ);
|
2014-11-15 16:26:54 -05:00
|
|
|
if ((DiffX > m_CurrentViewDistance) || (DiffZ > m_CurrentViewDistance))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-10-02 17:50:41 -04:00
|
|
|
ChunksToRemove.push_back(*itr);
|
2012-06-14 09:06:06 -04:00
|
|
|
itr = m_LoadedChunks.erase(itr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++itr;
|
|
|
|
}
|
2014-10-02 17:50:41 -04:00
|
|
|
}
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
for (cChunkCoordsList::iterator itr = m_ChunksToSend.begin(); itr != m_ChunksToSend.end();)
|
|
|
|
{
|
2014-10-02 17:50:41 -04:00
|
|
|
int DiffX = Diff((*itr).m_ChunkX, ChunkPosX);
|
|
|
|
int DiffZ = Diff((*itr).m_ChunkZ, ChunkPosZ);
|
2014-11-15 16:26:54 -05:00
|
|
|
if ((DiffX > m_CurrentViewDistance) || (DiffZ > m_CurrentViewDistance))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
itr = m_ChunksToSend.erase(itr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++itr;
|
|
|
|
}
|
2014-10-02 17:50:41 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2014-10-02 17:50:41 -04:00
|
|
|
|
|
|
|
for (cChunkCoordsList::iterator itr = ChunksToRemove.begin(); itr != ChunksToRemove.end(); ++itr)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-10-02 17:50:41 -04:00
|
|
|
m_Player->GetWorld()->RemoveChunkClient(itr->m_ChunkX, itr->m_ChunkZ, this);
|
2014-10-30 17:04:04 -04:00
|
|
|
SendUnloadChunk(itr->m_ChunkX, itr->m_ChunkZ);
|
2014-10-02 17:50:41 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-02 17:50:41 -04:00
|
|
|
|
2014-10-06 15:27:53 -04:00
|
|
|
void cClientHandle::StreamChunk(int a_ChunkX, int a_ChunkZ, cChunkSender::eChunkPriority a_Priority)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-11-11 09:00:58 -05:00
|
|
|
if (m_State >= csDestroying)
|
|
|
|
{
|
|
|
|
// Don't stream chunks to clients that are being destroyed
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
cWorld * World = m_Player->GetWorld();
|
2014-10-20 16:55:07 -04:00
|
|
|
ASSERT(World != nullptr);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
if (World->AddChunkClient(a_ChunkX, a_ChunkZ, this))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSChunkLists);
|
2014-08-28 05:36:35 -04:00
|
|
|
m_LoadedChunks.push_back(cChunkCoords(a_ChunkX, a_ChunkZ));
|
|
|
|
m_ChunksToSend.push_back(cChunkCoords(a_ChunkX, a_ChunkZ));
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2014-10-06 15:27:53 -04:00
|
|
|
World->SendChunkTo(a_ChunkX, a_ChunkZ, a_Priority, this);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Removes the client from all chunks. Used when switching worlds or destroying the player
|
|
|
|
void cClientHandle::RemoveFromAllChunks()
|
|
|
|
{
|
|
|
|
cWorld * World = m_Player->GetWorld();
|
2014-10-20 16:55:07 -04:00
|
|
|
if (World != nullptr)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
World->RemoveClientFromChunks(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2014-10-16 15:12:26 -04:00
|
|
|
// Reset all chunk lists:
|
2012-06-14 09:06:06 -04:00
|
|
|
cCSLock Lock(m_CSChunkLists);
|
|
|
|
m_LoadedChunks.clear();
|
|
|
|
m_ChunksToSend.clear();
|
2014-10-16 15:12:26 -04:00
|
|
|
m_SentChunks.clear();
|
2014-10-06 11:38:17 -04:00
|
|
|
|
2013-07-03 03:47:35 -04:00
|
|
|
// Also reset the LastStreamedChunk coords to bogus coords,
|
|
|
|
// so that all chunks are streamed in subsequent StreamChunks() call (FS #407)
|
|
|
|
m_LastStreamedChunkX = 0x7fffffff;
|
|
|
|
m_LastStreamedChunkZ = 0x7fffffff;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-30 07:33:57 -04:00
|
|
|
void cClientHandle::HandleNPCTrade(int a_SlotNum)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
LOGWARNING("%s: Not implemented yet", __FUNCTION__);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
void cClientHandle::HandlePing(void)
|
|
|
|
{
|
|
|
|
// Somebody tries to retrieve information about the server
|
|
|
|
AString Reply;
|
2014-04-19 11:53:02 -04:00
|
|
|
const cServer & Server = *cRoot::Get()->GetServer();
|
2014-04-18 15:09:44 -04:00
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
Printf(Reply, "%s%s%i%s%i",
|
2014-04-19 11:53:02 -04:00
|
|
|
Server.GetDescription().c_str(),
|
2014-07-19 14:15:21 -04:00
|
|
|
cChatColor::Delimiter,
|
2014-04-19 11:53:02 -04:00
|
|
|
Server.GetNumPlayers(),
|
2014-07-19 14:15:21 -04:00
|
|
|
cChatColor::Delimiter,
|
2014-04-19 11:53:02 -04:00
|
|
|
Server.GetMaxPlayers()
|
2012-06-14 09:06:06 -04:00
|
|
|
);
|
2014-04-18 15:09:44 -04:00
|
|
|
Kick(Reply);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-30 04:19:19 -04:00
|
|
|
bool cClientHandle::HandleLogin(int a_ProtocolVersion, const AString & a_Username)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-10-05 14:19:21 -04:00
|
|
|
// If the protocol version hasn't been set yet, set it now:
|
|
|
|
if (m_ProtocolVersion == 0)
|
|
|
|
{
|
|
|
|
m_ProtocolVersion = a_ProtocolVersion;
|
|
|
|
}
|
|
|
|
|
2012-08-30 04:19:19 -04:00
|
|
|
m_Username = a_Username;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-10-05 14:19:21 -04:00
|
|
|
// Let the plugins know about this event, they may refuse the player:
|
2014-10-15 13:01:55 -04:00
|
|
|
if (cRoot::Get()->GetPluginManager()->CallHookLogin(*this, a_ProtocolVersion, a_Username))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
Destroy();
|
2012-08-30 04:19:19 -04:00
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2014-10-05 14:19:21 -04:00
|
|
|
// Schedule for authentication; until then, let the player wait (but do not block)
|
2012-06-14 09:06:06 -04:00
|
|
|
m_State = csAuthenticating;
|
2012-09-06 13:36:59 -04:00
|
|
|
cRoot::Get()->GetAuthenticator().Authenticate(GetUniqueID(), GetUsername(), m_Protocol->GetAuthServerID());
|
2012-08-30 04:19:19 -04:00
|
|
|
return true;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-21 08:00:20 -04:00
|
|
|
void cClientHandle::HandleCreativeInventory(Int16 a_SlotNum, const cItem & a_HeldItem, eClickAction a_ClickAction)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
// This is for creative Inventory changes
|
2013-10-29 16:19:06 -04:00
|
|
|
if (!m_Player->IsGameModeCreative())
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-09-20 09:25:54 -04:00
|
|
|
LOGWARNING("Got a CreativeInventoryAction packet from user \"%s\" while not in creative mode. Ignoring.", m_Username.c_str());
|
|
|
|
return;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2013-10-28 08:30:24 -04:00
|
|
|
if (m_Player->GetWindow()->GetWindowType() != cWindow::wtInventory)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-09-20 09:25:54 -04:00
|
|
|
LOGWARNING("Got a CreativeInventoryAction packet from user \"%s\" while not in the inventory window. Ignoring.", m_Username.c_str());
|
|
|
|
return;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-09-20 09:25:54 -04:00
|
|
|
|
2015-03-21 08:00:20 -04:00
|
|
|
m_Player->GetWindow()->Clicked(*m_Player, 0, a_SlotNum, a_ClickAction, a_HeldItem);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-21 08:00:20 -04:00
|
|
|
void cClientHandle::HandleEnchantItem(UInt8 a_WindowID, UInt8 a_Enchantment)
|
2015-01-24 14:17:00 -05:00
|
|
|
{
|
|
|
|
if (a_Enchantment > 2)
|
|
|
|
{
|
2015-03-21 08:00:20 -04:00
|
|
|
LOGWARNING("%s attempt to crash the server with invalid enchanting selection (%u)!", GetUsername().c_str(), a_Enchantment);
|
2015-01-24 14:17:00 -05:00
|
|
|
Kick("Invalid enchanting!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
(m_Player->GetWindow() == nullptr) ||
|
|
|
|
(m_Player->GetWindow()->GetWindowID() != a_WindowID) ||
|
|
|
|
(m_Player->GetWindow()->GetWindowType() != cWindow::wtEnchantment)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-25 11:04:53 -05:00
|
|
|
cEnchantingWindow * Window = reinterpret_cast<cEnchantingWindow *>(m_Player->GetWindow());
|
|
|
|
cItem Item = *Window->m_SlotArea->GetSlot(0, *m_Player); // Make a copy of the item
|
|
|
|
short BaseEnchantmentLevel = Window->GetPropertyValue(a_Enchantment);
|
2015-01-24 14:17:00 -05:00
|
|
|
|
|
|
|
if (Item.EnchantByXPLevels(BaseEnchantmentLevel))
|
|
|
|
{
|
|
|
|
if (m_Player->IsGameModeCreative() || m_Player->DeltaExperience(-m_Player->XpForLevel(BaseEnchantmentLevel)) >= 0)
|
|
|
|
{
|
|
|
|
Window->m_SlotArea->SetSlot(0, *m_Player, Item);
|
|
|
|
Window->SendSlot(*m_Player, Window->m_SlotArea, 0);
|
|
|
|
Window->BroadcastWholeWindow();
|
|
|
|
|
|
|
|
Window->SetProperty(0, 0, *m_Player);
|
|
|
|
Window->SetProperty(1, 0, *m_Player);
|
|
|
|
Window->SetProperty(2, 0, *m_Player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-15 09:11:59 -05:00
|
|
|
void cClientHandle::HandlePlayerAbilities(bool a_CanFly, bool a_IsFlying, float FlyingSpeed, float WalkingSpeed)
|
2013-12-15 08:48:17 -05:00
|
|
|
{
|
2014-07-17 13:13:23 -04:00
|
|
|
UNUSED(FlyingSpeed); // Ignore the client values for these
|
2013-12-19 15:53:47 -05:00
|
|
|
UNUSED(WalkingSpeed);
|
|
|
|
|
2013-12-15 09:11:59 -05:00
|
|
|
m_Player->SetCanFly(a_CanFly);
|
|
|
|
m_Player->SetFlying(a_IsFlying);
|
2013-12-15 08:48:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-18 05:56:28 -04:00
|
|
|
void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ, double a_Stance, bool a_IsOnGround)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
if ((m_Player == nullptr) || (m_State != csPlaying))
|
2013-09-08 12:36:06 -04:00
|
|
|
{
|
|
|
|
// The client hasn't been spawned yet and sends nonsense, we know better
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-26 10:38:14 -04:00
|
|
|
/*
|
|
|
|
// TODO: Invalid stance check
|
|
|
|
if ((a_PosY >= a_Stance) || (a_Stance > a_PosY + 1.65))
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2014-05-26 10:38:14 -04:00
|
|
|
LOGD("Invalid stance");
|
|
|
|
SendPlayerMoveLook();
|
2014-05-16 16:04:19 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-05-26 10:38:14 -04:00
|
|
|
*/
|
|
|
|
|
2013-09-08 12:36:06 -04:00
|
|
|
// If the player has moved too far, "repair" them:
|
2012-08-19 15:42:32 -04:00
|
|
|
Vector3d Pos(a_PosX, a_PosY, a_PosZ);
|
|
|
|
if ((m_Player->GetPosition() - Pos).SqrLength() > 100 * 100)
|
|
|
|
{
|
|
|
|
LOGD("Too far away (%0.2f), \"repairing\" the client", (m_Player->GetPosition() - Pos).Length());
|
|
|
|
SendPlayerMoveLook();
|
|
|
|
return;
|
|
|
|
}
|
2013-07-12 16:01:25 -04:00
|
|
|
|
|
|
|
// If a jump just started, process food exhaustion:
|
|
|
|
if ((a_PosY > m_Player->GetPosY()) && !a_IsOnGround && m_Player->IsOnGround())
|
|
|
|
{
|
2013-08-08 11:57:34 -04:00
|
|
|
// we only add this exhaustion if the player is not swimming - otherwise we end up with both jump + swim exhaustion
|
2013-08-09 03:37:39 -04:00
|
|
|
|
2013-09-08 12:36:06 -04:00
|
|
|
if (!m_Player->IsSwimming())
|
2013-08-08 11:57:34 -04:00
|
|
|
{
|
2014-08-01 11:29:17 -04:00
|
|
|
m_Player->GetStatManager().AddValue(statJumps, 1);
|
2013-08-08 11:57:34 -04:00
|
|
|
m_Player->AddFoodExhaustion(m_Player->IsSprinting() ? 0.8 : 0.2);
|
|
|
|
}
|
2013-07-12 16:01:25 -04:00
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
m_Player->MoveTo(Pos);
|
2012-08-18 05:56:28 -04:00
|
|
|
m_Player->SetStance(a_Stance);
|
|
|
|
m_Player->SetTouchGround(a_IsOnGround);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-07 11:47:05 -05:00
|
|
|
void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString & a_Message)
|
|
|
|
{
|
2014-09-30 07:33:57 -04:00
|
|
|
if (a_Channel == "REGISTER")
|
2014-02-20 17:24:39 -05:00
|
|
|
{
|
2014-03-06 15:06:53 -05:00
|
|
|
if (HasPluginChannel(a_Channel))
|
|
|
|
{
|
|
|
|
SendPluginMessage("UNREGISTER", a_Channel);
|
2014-07-17 13:13:23 -04:00
|
|
|
return; // Can't register again if already taken - kinda defeats the point of plugin messaging!
|
2014-03-06 15:06:53 -05:00
|
|
|
}
|
|
|
|
|
2014-02-20 17:24:39 -05:00
|
|
|
RegisterPluginChannels(BreakApartPluginChannels(a_Message));
|
|
|
|
}
|
|
|
|
else if (a_Channel == "UNREGISTER")
|
|
|
|
{
|
|
|
|
UnregisterPluginChannels(BreakApartPluginChannels(a_Message));
|
2014-01-18 12:58:46 -05:00
|
|
|
}
|
2014-03-06 15:06:53 -05:00
|
|
|
else if (!HasPluginChannel(a_Channel))
|
|
|
|
{
|
|
|
|
// Ignore if client sent something but didn't register the channel first
|
|
|
|
LOGD("Player %s sent a plugin message on channel \"%s\", but didn't REGISTER it first", GetUsername().c_str(), a_Channel.c_str());
|
|
|
|
SendPluginMessage("UNREGISTER", a_Channel);
|
|
|
|
return;
|
|
|
|
}
|
2014-01-18 12:58:46 -05:00
|
|
|
|
2014-01-07 11:47:05 -05:00
|
|
|
cPluginManager::Get()->CallHookPluginMessage(*this, a_Channel, a_Message);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-20 17:24:39 -05:00
|
|
|
AStringVector cClientHandle::BreakApartPluginChannels(const AString & a_PluginChannels)
|
|
|
|
{
|
|
|
|
// Break the string on each NUL character.
|
|
|
|
// Note that StringSplit() doesn't work on this because NUL is a special char - string terminator
|
|
|
|
size_t len = a_PluginChannels.size();
|
|
|
|
size_t first = 0;
|
|
|
|
AStringVector res;
|
|
|
|
for (size_t i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (a_PluginChannels[i] != 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (i > first)
|
|
|
|
{
|
|
|
|
res.push_back(a_PluginChannels.substr(first, i - first));
|
|
|
|
}
|
|
|
|
first = i + 1;
|
|
|
|
} // for i - a_PluginChannels[]
|
|
|
|
if (first < len)
|
|
|
|
{
|
|
|
|
res.push_back(a_PluginChannels.substr(first, len - first));
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cClientHandle::RegisterPluginChannels(const AStringVector & a_ChannelList)
|
|
|
|
{
|
|
|
|
for (AStringVector::const_iterator itr = a_ChannelList.begin(), end = a_ChannelList.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_PluginChannels.insert(*itr);
|
|
|
|
} // for itr - a_ChannelList[]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cClientHandle::UnregisterPluginChannels(const AStringVector & a_ChannelList)
|
|
|
|
{
|
|
|
|
for (AStringVector::const_iterator itr = a_ChannelList.begin(), end = a_ChannelList.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_PluginChannels.erase(*itr);
|
|
|
|
} // for itr - a_ChannelList[]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-30 07:33:57 -04:00
|
|
|
void cClientHandle::HandleBeaconSelection(int a_PrimaryEffect, int a_SecondaryEffect)
|
2014-07-30 15:59:35 -04:00
|
|
|
{
|
|
|
|
cWindow * Window = m_Player->GetWindow();
|
2014-10-20 16:55:07 -04:00
|
|
|
if ((Window == nullptr) || (Window->GetWindowType() != cWindow::wtBeacon))
|
2014-07-30 15:59:35 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cBeaconWindow * BeaconWindow = (cBeaconWindow *) Window;
|
|
|
|
|
|
|
|
if (Window->GetSlot(*m_Player, 0)->IsEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-31 06:13:11 -04:00
|
|
|
cEntityEffect::eType PrimaryEffect = cEntityEffect::effNoEffect;
|
2014-09-30 07:33:57 -04:00
|
|
|
if ((a_PrimaryEffect >= 0) && (a_PrimaryEffect <= (int)cEntityEffect::effSaturation))
|
2014-07-30 15:59:35 -04:00
|
|
|
{
|
2014-09-30 07:33:57 -04:00
|
|
|
PrimaryEffect = (cEntityEffect::eType)a_PrimaryEffect;
|
2014-07-30 15:59:35 -04:00
|
|
|
}
|
2014-07-31 06:13:11 -04:00
|
|
|
cEntityEffect::eType SecondaryEffect = cEntityEffect::effNoEffect;
|
2014-09-30 07:33:57 -04:00
|
|
|
if ((a_SecondaryEffect >= 0) && (a_SecondaryEffect <= (int)cEntityEffect::effSaturation))
|
2014-07-30 15:59:35 -04:00
|
|
|
{
|
2014-09-30 07:33:57 -04:00
|
|
|
SecondaryEffect = (cEntityEffect::eType)a_SecondaryEffect;
|
2014-07-30 15:59:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Window->SetSlot(*m_Player, 0, cItem());
|
2014-07-31 12:15:39 -04:00
|
|
|
BeaconWindow->GetBeaconEntity()->SetPrimaryEffect(PrimaryEffect);
|
2014-08-01 18:14:05 -04:00
|
|
|
|
|
|
|
// Valid effect check. Vanilla don't check this, but we do it :)
|
|
|
|
if (
|
|
|
|
(SecondaryEffect == cEntityEffect::effNoEffect) ||
|
|
|
|
(SecondaryEffect == cEntityEffect::effRegeneration) ||
|
|
|
|
(SecondaryEffect == BeaconWindow->GetBeaconEntity()->GetPrimaryEffect())
|
|
|
|
)
|
|
|
|
{
|
|
|
|
BeaconWindow->GetBeaconEntity()->SetSecondaryEffect(SecondaryEffect);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BeaconWindow->GetBeaconEntity()->SetSecondaryEffect(cEntityEffect::effNoEffect);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Player->CloseWindow(true);
|
2014-07-30 15:59:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-30 07:33:57 -04:00
|
|
|
void cClientHandle::HandleCommandBlockBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_NewCommand)
|
2014-01-18 12:58:46 -05:00
|
|
|
{
|
|
|
|
cWorld * World = m_Player->GetWorld();
|
2014-01-23 07:57:04 -05:00
|
|
|
if (World->AreCommandBlocksEnabled())
|
|
|
|
{
|
2014-09-30 07:33:57 -04:00
|
|
|
World->SetCommandBlockCommand(a_BlockX, a_BlockY, a_BlockZ, a_NewCommand);
|
2014-02-07 13:58:52 -05:00
|
|
|
SendChat("Successfully set command block command", mtSuccess);
|
2014-01-23 07:57:04 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-07 13:58:52 -05:00
|
|
|
SendChat("Command blocks are not enabled on this server", mtFailure);
|
2014-01-23 07:57:04 -05:00
|
|
|
}
|
2014-01-18 12:58:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-21 08:00:20 -04:00
|
|
|
void cClientHandle::HandleCommandBlockEntityChange(UInt32 a_EntityID, const AString & a_NewCommand)
|
2014-04-30 19:25:04 -04:00
|
|
|
{
|
2014-09-30 07:33:57 -04:00
|
|
|
// TODO
|
|
|
|
LOGWARNING("%s: Not implemented yet", __FUNCTION__);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-30 19:25:04 -04:00
|
|
|
|
2014-09-30 07:33:57 -04:00
|
|
|
|
|
|
|
|
|
|
|
void cClientHandle::HandleAnvilItemName(const AString & a_ItemName)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
if ((m_Player->GetWindow() == nullptr) || (m_Player->GetWindow()->GetWindowType() != cWindow::wtAnvil))
|
2014-04-30 19:25:04 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-30 07:33:57 -04:00
|
|
|
if (a_ItemName.length() <= 30)
|
2014-04-30 19:25:04 -04:00
|
|
|
{
|
2014-09-30 07:33:57 -04:00
|
|
|
((cAnvilWindow *)m_Player->GetWindow())->SetRepairedItemName(a_ItemName, m_Player);
|
2014-04-30 19:25:04 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-21 10:40:56 -04:00
|
|
|
void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, UInt8 a_Status)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
LOGD("HandleLeftClick: {%i, %i, %i}; Face: %i; Stat: %i",
|
|
|
|
a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status
|
|
|
|
);
|
|
|
|
|
2014-03-01 16:24:36 -05:00
|
|
|
m_NumBlockChangeInteractionsThisTick++;
|
|
|
|
|
|
|
|
if (!CheckBlockInteractionsRate())
|
|
|
|
{
|
|
|
|
Kick("Too many blocks were destroyed per unit time - hacked client?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-22 09:32:27 -04:00
|
|
|
if ((a_Status == DIG_STATUS_STARTED) || (a_Status == DIG_STATUS_FINISHED))
|
2014-08-11 16:34:33 -04:00
|
|
|
{
|
2014-08-22 09:32:27 -04:00
|
|
|
if (a_BlockFace == BLOCK_FACE_NONE)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for clickthrough-blocks:
|
|
|
|
When the user breaks a fire block, the client send the wrong block location.
|
|
|
|
We must find the right block with the face direction. */
|
2014-08-11 16:34:33 -04:00
|
|
|
int BlockX = a_BlockX;
|
|
|
|
int BlockY = a_BlockY;
|
|
|
|
int BlockZ = a_BlockZ;
|
|
|
|
AddFaceDirection(BlockX, BlockY, BlockZ, a_BlockFace);
|
2015-02-14 17:11:38 -05:00
|
|
|
|
|
|
|
if ((BlockY < 0) || (BlockY >= cChunkDef::Height))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-11 16:34:33 -04:00
|
|
|
if (cBlockInfo::GetHandler(m_Player->GetWorld()->GetBlock(BlockX, BlockY, BlockZ))->IsClickedThrough())
|
|
|
|
{
|
|
|
|
a_BlockX = BlockX;
|
|
|
|
a_BlockY = BlockY;
|
|
|
|
a_BlockZ = BlockZ;
|
|
|
|
}
|
|
|
|
|
2014-08-22 09:32:27 -04:00
|
|
|
if (
|
|
|
|
((Diff(m_Player->GetPosX(), (double)a_BlockX) > 6) ||
|
|
|
|
(Diff(m_Player->GetPosY(), (double)a_BlockY) > 6) ||
|
|
|
|
(Diff(m_Player->GetPosZ(), (double)a_BlockZ) > 6))
|
|
|
|
)
|
|
|
|
{
|
|
|
|
m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
|
|
|
|
return;
|
|
|
|
}
|
2014-05-15 13:58:48 -04:00
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager();
|
|
|
|
if (PlgMgr->CallHookPlayerLeftClick(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status))
|
|
|
|
{
|
|
|
|
// A plugin doesn't agree with the action, replace the block on the client and quit:
|
|
|
|
m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
|
|
|
|
return;
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
switch (a_Status)
|
|
|
|
{
|
|
|
|
case DIG_STATUS_DROP_HELD: // Drop held item
|
|
|
|
{
|
|
|
|
if (PlgMgr->CallHookPlayerTossingItem(*m_Player))
|
|
|
|
{
|
|
|
|
// A plugin doesn't agree with the tossing. The plugin itself is responsible for handling the consequences (possible inventory mismatch)
|
|
|
|
return;
|
|
|
|
}
|
2014-01-23 02:27:39 -05:00
|
|
|
|
|
|
|
m_Player->TossEquippedItem();
|
2013-01-11 23:46:01 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DIG_STATUS_SHOOT_EAT:
|
|
|
|
{
|
|
|
|
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem());
|
2014-06-08 20:06:15 -04:00
|
|
|
if (ItemHandler->IsFood() || ItemHandler->IsDrinkable(m_Player->GetEquippedItem().m_ItemDamage))
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
2013-07-28 13:15:03 -04:00
|
|
|
m_Player->AbortEating();
|
|
|
|
return;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (PlgMgr->CallHookPlayerShooting(*m_Player))
|
|
|
|
{
|
|
|
|
// A plugin doesn't agree with the action. The plugin itself is responsible for handling the consequences (possible inventory mismatch)
|
|
|
|
return;
|
|
|
|
}
|
2013-08-30 08:24:03 -04:00
|
|
|
ItemHandler->OnItemShoot(m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DIG_STATUS_STARTED:
|
|
|
|
{
|
|
|
|
BLOCKTYPE OldBlock;
|
|
|
|
NIBBLETYPE OldMeta;
|
|
|
|
m_Player->GetWorld()->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, OldBlock, OldMeta);
|
|
|
|
HandleBlockDigStarted(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, OldBlock, OldMeta);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DIG_STATUS_FINISHED:
|
|
|
|
{
|
|
|
|
BLOCKTYPE OldBlock;
|
|
|
|
NIBBLETYPE OldMeta;
|
|
|
|
m_Player->GetWorld()->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, OldBlock, OldMeta);
|
|
|
|
HandleBlockDigFinished(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, OldBlock, OldMeta);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-13 07:59:48 -05:00
|
|
|
case DIG_STATUS_CANCELLED:
|
|
|
|
{
|
|
|
|
// Block breaking cancelled by player
|
2014-05-11 05:56:15 -04:00
|
|
|
FinishDigAnimation();
|
2013-01-13 07:59:48 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-15 17:36:19 -05:00
|
|
|
case DIG_STATUS_DROP_STACK:
|
|
|
|
{
|
|
|
|
if (PlgMgr->CallHookPlayerTossingItem(*m_Player))
|
|
|
|
{
|
|
|
|
// A plugin doesn't agree with the tossing. The plugin itself is responsible for handling the consequences (possible inventory mismatch)
|
|
|
|
return;
|
|
|
|
}
|
2014-07-17 13:13:23 -04:00
|
|
|
m_Player->TossEquippedItem(64); // Toss entire slot - if there aren't enough items, the maximum will be ejected
|
2014-01-15 17:36:19 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Unhandled DIG_STATUS");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} // switch (a_Status)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
|
2014-02-04 13:59:05 -05:00
|
|
|
void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
if (
|
|
|
|
m_HasStartedDigging &&
|
|
|
|
(a_BlockX == m_LastDigBlockX) &&
|
|
|
|
(a_BlockY == m_LastDigBlockY) &&
|
|
|
|
(a_BlockZ == m_LastDigBlockZ)
|
|
|
|
)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
// It is a duplicate packet, drop it right away
|
2012-06-14 09:06:06 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-05-09 17:10:02 -04:00
|
|
|
|
2014-02-23 14:02:44 -05:00
|
|
|
if (
|
|
|
|
m_Player->IsGameModeCreative() &&
|
2014-08-28 14:49:34 -04:00
|
|
|
ItemCategory::IsSword(m_Player->GetInventory().GetEquippedItem().m_ItemType) &&
|
|
|
|
(m_Player->GetWorld()->GetBlock(a_BlockX, a_BlockY, a_BlockZ) != E_BLOCK_FIRE)
|
2014-02-23 14:02:44 -05:00
|
|
|
)
|
|
|
|
{
|
2014-08-28 17:02:20 -04:00
|
|
|
// Players can't destroy blocks with a sword in the hand.
|
2014-02-23 14:02:44 -05:00
|
|
|
return;
|
|
|
|
}
|
2014-05-09 17:10:02 -04:00
|
|
|
|
2014-05-15 13:58:48 -04:00
|
|
|
if (
|
|
|
|
(Diff(m_Player->GetPosX(), (double)a_BlockX) > 6) ||
|
|
|
|
(Diff(m_Player->GetPosY(), (double)a_BlockY) > 6) ||
|
|
|
|
(Diff(m_Player->GetPosZ(), (double)a_BlockZ) > 6)
|
|
|
|
)
|
2012-07-15 16:36:34 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
|
2012-08-18 05:56:28 -04:00
|
|
|
return;
|
2012-07-15 16:36:34 -04:00
|
|
|
}
|
2014-05-15 13:58:48 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
// Set the last digging coords to the block being dug, so that they can be checked in DIG_FINISHED to avoid dig/aim bug in the client:
|
|
|
|
m_HasStartedDigging = true;
|
|
|
|
m_LastDigBlockX = a_BlockX;
|
|
|
|
m_LastDigBlockY = a_BlockY;
|
|
|
|
m_LastDigBlockZ = a_BlockZ;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-02-14 16:47:57 -05:00
|
|
|
if (
|
2013-10-29 16:45:31 -04:00
|
|
|
(m_Player->IsGameModeCreative()) || // In creative mode, digging is done immediately
|
2014-03-01 14:34:19 -05:00
|
|
|
cBlockInfo::IsOneHitDig(a_OldBlock) // One-hit blocks get destroyed immediately, too
|
2013-02-14 16:47:57 -05:00
|
|
|
)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
HandleBlockDigFinished(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_OldBlock, a_OldMeta);
|
2012-06-14 09:06:06 -04:00
|
|
|
return;
|
|
|
|
}
|
2012-11-12 06:10:01 -05:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
// Start dig animation
|
|
|
|
// TODO: calculate real animation speed
|
|
|
|
// TODO: Send animation packets even without receiving any other packets
|
|
|
|
m_BlockDigAnimSpeed = 10;
|
|
|
|
m_BlockDigAnimX = a_BlockX;
|
|
|
|
m_BlockDigAnimY = a_BlockY;
|
|
|
|
m_BlockDigAnimZ = a_BlockZ;
|
|
|
|
m_BlockDigAnimStage = 0;
|
|
|
|
m_Player->GetWorld()->BroadcastBlockBreakAnimation(m_UniqueID, m_BlockDigAnimX, m_BlockDigAnimY, m_BlockDigAnimZ, 0, this);
|
|
|
|
|
|
|
|
cWorld * World = m_Player->GetWorld();
|
2014-02-01 11:35:48 -05:00
|
|
|
cChunkInterface ChunkInterface(World->GetChunkMap());
|
2014-03-02 14:25:05 -05:00
|
|
|
cBlockHandler * Handler = cBlockInfo::GetHandler(a_OldBlock);
|
2014-02-01 11:35:48 -05:00
|
|
|
Handler->OnDigging(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ);
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem());
|
2013-05-19 14:22:37 -04:00
|
|
|
ItemHandler->OnDiggingBlock(World, m_Player, m_Player->GetEquippedItem(), a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-11-12 06:10:01 -05:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-04 13:59:05 -05:00
|
|
|
void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
if (
|
|
|
|
!m_HasStartedDigging || // Hasn't received the DIG_STARTED packet
|
|
|
|
(m_LastDigBlockX != a_BlockX) || // DIG_STARTED has had different pos
|
|
|
|
(m_LastDigBlockY != a_BlockY) ||
|
|
|
|
(m_LastDigBlockZ != a_BlockZ)
|
|
|
|
)
|
2012-09-25 05:54:36 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
LOGD("Prevented a dig/aim bug in the client (finish {%d, %d, %d} vs start {%d, %d, %d}, HSD: %s)",
|
|
|
|
a_BlockX, a_BlockY, a_BlockZ,
|
|
|
|
m_LastDigBlockX, m_LastDigBlockY, m_LastDigBlockZ,
|
2014-03-11 17:16:08 -04:00
|
|
|
(m_HasStartedDigging ? "True" : "False")
|
2013-01-11 23:46:01 -05:00
|
|
|
);
|
|
|
|
return;
|
2012-09-25 05:54:36 -04:00
|
|
|
}
|
2013-01-11 23:46:01 -05:00
|
|
|
|
2014-05-11 05:56:15 -04:00
|
|
|
FinishDigAnimation();
|
2012-09-25 05:54:36 -04:00
|
|
|
|
2014-09-27 15:49:03 -04:00
|
|
|
if (!m_Player->IsGameModeCreative())
|
2014-09-27 15:07:52 -04:00
|
|
|
{
|
2014-09-27 15:49:03 -04:00
|
|
|
if (a_OldBlock == E_BLOCK_BEDROCK)
|
|
|
|
{
|
|
|
|
Kick("You can't break a bedrock!");
|
2014-09-28 16:17:29 -04:00
|
|
|
return;
|
2014-09-27 15:49:03 -04:00
|
|
|
}
|
|
|
|
if (a_OldBlock == E_BLOCK_BARRIER)
|
|
|
|
{
|
|
|
|
Kick("You can't break a barrier!");
|
|
|
|
return;
|
|
|
|
}
|
2014-09-27 15:07:52 -04:00
|
|
|
}
|
2014-09-12 09:57:37 -04:00
|
|
|
|
2014-05-15 13:58:48 -04:00
|
|
|
cWorld * World = m_Player->GetWorld();
|
2013-01-11 23:46:01 -05:00
|
|
|
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem());
|
2014-05-09 17:10:02 -04:00
|
|
|
|
|
|
|
if (cRoot::Get()->GetPluginManager()->CallHookPlayerBreakingBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_OldBlock, a_OldMeta))
|
2012-09-25 05:54:36 -04:00
|
|
|
{
|
2014-05-09 17:10:02 -04:00
|
|
|
// A plugin doesn't agree with the breaking. Bail out. Send the block back to the client, so that it knows:
|
|
|
|
m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
|
|
|
|
return;
|
2012-09-25 05:54:36 -04:00
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (a_OldBlock == E_BLOCK_AIR)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-11-10 17:20:25 -05:00
|
|
|
LOGD("Dug air - what the function?");
|
2013-01-11 23:46:01 -05:00
|
|
|
return;
|
2012-08-18 05:56:28 -04:00
|
|
|
}
|
2014-05-09 17:43:00 -04:00
|
|
|
|
2014-07-31 17:04:00 -04:00
|
|
|
m_Player->AddFoodExhaustion(0.025);
|
2013-05-19 14:22:37 -04:00
|
|
|
ItemHandler->OnBlockDestroyed(World, m_Player, m_Player->GetEquippedItem(), a_BlockX, a_BlockY, a_BlockZ);
|
2013-09-21 12:08:05 -04:00
|
|
|
// The ItemHandler is also responsible for spawning the pickups
|
2014-02-01 09:01:13 -05:00
|
|
|
cChunkInterface ChunkInterface(World->GetChunkMap());
|
2014-07-19 08:53:41 -04:00
|
|
|
BlockHandler(a_OldBlock)->OnDestroyedByPlayer(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ);
|
2013-11-10 17:20:25 -05:00
|
|
|
World->BroadcastSoundParticleEffect(2001, a_BlockX, a_BlockY, a_BlockZ, a_OldBlock, this);
|
2013-01-11 23:46:01 -05:00
|
|
|
World->DigBlock(a_BlockX, a_BlockY, a_BlockZ);
|
2012-10-06 16:53:08 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
cRoot::Get()->GetPluginManager()->CallHookPlayerBrokenBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_OldBlock, a_OldMeta);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-11 05:56:15 -04:00
|
|
|
void cClientHandle::FinishDigAnimation()
|
2014-05-09 17:10:02 -04:00
|
|
|
{
|
2014-07-17 13:13:23 -04:00
|
|
|
if (!m_HasStartedDigging) // Hasn't received the DIG_STARTED packet
|
2014-05-09 17:10:02 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_HasStartedDigging = false;
|
|
|
|
if (m_BlockDigAnimStage != -1)
|
|
|
|
{
|
|
|
|
// End dig animation
|
|
|
|
m_BlockDigAnimStage = -1;
|
|
|
|
// It seems that 10 ends block animation
|
|
|
|
m_Player->GetWorld()->BroadcastBlockBreakAnimation(m_UniqueID, m_LastDigBlockX, m_LastDigBlockY, m_LastDigBlockZ, 10, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_BlockDigAnimX = -1;
|
|
|
|
m_BlockDigAnimY = -1;
|
|
|
|
m_BlockDigAnimZ = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-04 13:59:05 -05:00
|
|
|
void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, const cItem & a_HeldItem)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-09-08 19:52:51 -04:00
|
|
|
// TODO: Rewrite this function
|
|
|
|
|
2014-11-25 15:24:25 -05:00
|
|
|
// Distance from the block's center to the player's eye height
|
|
|
|
double dist = (Vector3d(a_BlockX, a_BlockY, a_BlockZ) + Vector3d(0.5, 0.5, 0.5) - m_Player->GetEyePosition()).Length();
|
|
|
|
LOGD("HandleRightClick: {%d, %d, %d}, face %d, HeldItem: %s; dist: %.02f",
|
|
|
|
a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, ItemToFullString(a_HeldItem).c_str(), dist
|
2012-09-07 16:53:37 -04:00
|
|
|
);
|
2014-11-25 15:24:25 -05:00
|
|
|
|
|
|
|
// Check the reach distance:
|
|
|
|
// _X 2014-11-25: I've maxed at 5.26 with a Survival client and 5.78 with a Creative client in my tests
|
|
|
|
double maxDist = m_Player->IsGameModeCreative() ? 5.78 : 5.26;
|
|
|
|
bool AreRealCoords = (dist <= maxDist);
|
|
|
|
|
2014-03-05 09:10:20 -05:00
|
|
|
cWorld * World = m_Player->GetWorld();
|
2014-05-15 13:58:48 -04:00
|
|
|
|
|
|
|
if (
|
2014-06-08 05:32:52 -04:00
|
|
|
(a_BlockFace != BLOCK_FACE_NONE) && // The client is interacting with a specific block
|
2014-09-11 19:37:19 -04:00
|
|
|
IsValidBlock(a_HeldItem.m_ItemType) &&
|
2014-09-12 07:19:33 -04:00
|
|
|
!AreRealCoords
|
2014-05-15 13:58:48 -04:00
|
|
|
)
|
|
|
|
{
|
2014-06-08 05:32:52 -04:00
|
|
|
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
|
2014-09-12 07:19:33 -04:00
|
|
|
if ((a_BlockX != -1) && (a_BlockY >= 0) && (a_BlockZ != -1))
|
2014-05-15 13:58:48 -04:00
|
|
|
{
|
2014-09-08 19:52:51 -04:00
|
|
|
World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
|
|
|
|
if (a_BlockY < cChunkDef::Height - 1)
|
|
|
|
{
|
|
|
|
World->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, m_Player); // 2 block high things
|
|
|
|
}
|
|
|
|
if (a_BlockY > 0)
|
|
|
|
{
|
|
|
|
World->SendBlockTo(a_BlockX, a_BlockY - 1, a_BlockZ, m_Player); // 2 block high things
|
|
|
|
}
|
2014-06-08 05:32:52 -04:00
|
|
|
}
|
|
|
|
m_Player->GetInventory().SendEquippedSlot();
|
2014-05-15 13:58:48 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-12 07:19:33 -04:00
|
|
|
if (!AreRealCoords)
|
|
|
|
{
|
|
|
|
a_BlockFace = BLOCK_FACE_NONE;
|
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager();
|
|
|
|
if (PlgMgr->CallHookPlayerRightClick(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ))
|
|
|
|
{
|
|
|
|
// A plugin doesn't agree with the action, replace the block on the client and quit:
|
2014-09-12 07:19:33 -04:00
|
|
|
if (AreRealCoords)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
2014-09-08 19:52:51 -04:00
|
|
|
cChunkInterface ChunkInterface(World->GetChunkMap());
|
|
|
|
BLOCKTYPE BlockType = World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
|
|
|
|
cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType);
|
|
|
|
BlockHandler->OnCancelRightClick(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
|
|
|
|
|
|
|
|
if (a_BlockFace != BLOCK_FACE_NONE)
|
|
|
|
{
|
|
|
|
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
|
|
|
|
World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
|
2015-04-19 11:33:58 -04:00
|
|
|
if (a_BlockY < cChunkDef::Height - 1)
|
|
|
|
{
|
|
|
|
World->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, m_Player); // 2 block high things
|
|
|
|
}
|
|
|
|
if (a_BlockY > 1)
|
|
|
|
{
|
|
|
|
World->SendBlockTo(a_BlockX, a_BlockY - 1, a_BlockZ, m_Player); // 2 block high things
|
|
|
|
}
|
2014-09-08 19:52:51 -04:00
|
|
|
m_Player->GetInventory().SendEquippedSlot();
|
|
|
|
}
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2014-03-28 18:52:04 -04:00
|
|
|
|
|
|
|
m_NumBlockChangeInteractionsThisTick++;
|
2013-01-11 23:46:01 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
if (!CheckBlockInteractionsRate())
|
|
|
|
{
|
2014-03-02 11:28:51 -05:00
|
|
|
Kick("Too many blocks were placed/interacted with per unit time - hacked client?");
|
2012-06-14 09:06:06 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-19 14:22:37 -04:00
|
|
|
const cItem & Equipped = m_Player->GetInventory().GetEquippedItem();
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-09-07 16:53:37 -04:00
|
|
|
if ((Equipped.m_ItemType != a_HeldItem.m_ItemType) && (a_HeldItem.m_ItemType != -1))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-09-07 16:53:37 -04:00
|
|
|
// Only compare ItemType, not meta (torches have different metas)
|
2014-07-17 10:33:09 -04:00
|
|
|
// The -1 check is there because sometimes the client sends -1 instead of the held item
|
2014-07-21 09:19:48 -04:00
|
|
|
// Ref.: http://forum.mc-server.org/showthread.php?tid=549&pid=4502#pid4502
|
2012-06-14 09:06:06 -04:00
|
|
|
LOGWARN("Player %s tried to place a block that was not equipped (exp %d, got %d)",
|
2012-08-18 05:56:28 -04:00
|
|
|
m_Username.c_str(), Equipped.m_ItemType, a_HeldItem.m_ItemType
|
2012-06-14 09:06:06 -04:00
|
|
|
);
|
2012-08-18 05:56:28 -04:00
|
|
|
|
|
|
|
// Let's send the current world block to the client, so that it can immediately "let the user know" that they haven't placed the block
|
2014-03-29 09:18:26 -04:00
|
|
|
if (a_BlockFace != BLOCK_FACE_NONE)
|
2012-08-18 05:56:28 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
|
2014-03-05 09:10:20 -05:00
|
|
|
World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
|
2012-08-18 05:56:28 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-12 07:19:33 -04:00
|
|
|
if (AreRealCoords)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-09-08 11:02:54 -04:00
|
|
|
BLOCKTYPE BlockType;
|
|
|
|
NIBBLETYPE BlockMeta;
|
|
|
|
World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta);
|
|
|
|
cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType);
|
|
|
|
|
|
|
|
if (BlockHandler->IsUseable() && !m_Player->IsCrouched())
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
2014-09-08 11:02:54 -04:00
|
|
|
if (PlgMgr->CallHookPlayerUsingBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta))
|
|
|
|
{
|
|
|
|
// A plugin doesn't agree with using the block, abort
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cChunkInterface ChunkInterface(World->GetChunkMap());
|
|
|
|
BlockHandler->OnUse(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ);
|
|
|
|
PlgMgr->CallHookPlayerUsedBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta);
|
2013-01-11 23:46:01 -05:00
|
|
|
return;
|
|
|
|
}
|
2012-08-06 16:10:16 -04:00
|
|
|
}
|
2013-01-11 23:46:01 -05:00
|
|
|
|
2014-06-08 20:06:15 -04:00
|
|
|
short EquippedDamage = Equipped.m_ItemDamage;
|
2013-01-11 23:46:01 -05:00
|
|
|
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(Equipped.m_ItemType);
|
|
|
|
|
2014-03-29 09:18:26 -04:00
|
|
|
if (ItemHandler->IsPlaceable() && (a_BlockFace != BLOCK_FACE_NONE))
|
2012-08-06 16:10:16 -04:00
|
|
|
{
|
2014-12-24 01:20:17 -05:00
|
|
|
if (!ItemHandler->OnPlayerPlace(*World, *m_Player, Equipped, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ))
|
|
|
|
{
|
|
|
|
// Placement failed, bail out
|
|
|
|
return;
|
|
|
|
}
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
2014-07-18 04:56:26 -04:00
|
|
|
else if ((ItemHandler->IsFood() || ItemHandler->IsDrinkable(EquippedDamage)))
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
2014-12-24 01:20:17 -05:00
|
|
|
if (
|
|
|
|
(m_Player->IsSatiated() || m_Player->IsGameModeCreative()) && // Only creative or hungry players can eat
|
|
|
|
ItemHandler->IsFood() &&
|
|
|
|
(Equipped.m_ItemType != E_ITEM_GOLDEN_APPLE) // Golden apple is a special case, it is used instead of eaten
|
|
|
|
)
|
2013-07-28 16:55:09 -04:00
|
|
|
{
|
2014-07-18 04:56:26 -04:00
|
|
|
// The player is satiated or in creative, and trying to eat
|
2013-07-28 16:55:09 -04:00
|
|
|
return;
|
|
|
|
}
|
2013-07-28 13:15:03 -04:00
|
|
|
m_Player->StartEating();
|
|
|
|
if (PlgMgr->CallHookPlayerEating(*m_Player))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-07-28 13:15:03 -04:00
|
|
|
// A plugin won't let us eat, abort (send the proper packets to the client, too):
|
|
|
|
m_Player->AbortEating();
|
2012-08-18 05:56:28 -04:00
|
|
|
}
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (PlgMgr->CallHookPlayerUsingItem(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
// A plugin doesn't agree with using the item, abort
|
|
|
|
return;
|
|
|
|
}
|
2015-04-14 04:49:01 -04:00
|
|
|
cBlockInServerPluginInterface PluginInterface(*World);
|
|
|
|
ItemHandler->OnItemUse(World, m_Player, PluginInterface, Equipped, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
|
2013-01-11 23:46:01 -05:00
|
|
|
PlgMgr->CallHookPlayerUsedItem(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ);
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
2012-07-15 16:36:34 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
2012-08-18 06:38:15 -04:00
|
|
|
void cClientHandle::HandleChat(const AString & a_Message)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-08-14 14:08:05 -04:00
|
|
|
// We no longer need to postpone message processing, because the messages already arrive in the Tick thread
|
2013-07-03 03:47:35 -04:00
|
|
|
|
2013-08-14 14:08:05 -04:00
|
|
|
// If a command, perform it:
|
|
|
|
AString Message(a_Message);
|
|
|
|
if (cRoot::Get()->GetServer()->Command(*this, Message))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-16 17:51:32 -05:00
|
|
|
// Not a command, broadcast as a message:
|
|
|
|
cCompositeChat Msg;
|
|
|
|
AString Color = m_Player->GetColor();
|
|
|
|
if (Color.length() == 3)
|
|
|
|
{
|
|
|
|
Color = AString("@") + Color[2];
|
|
|
|
}
|
|
|
|
else
|
2014-07-17 10:33:09 -04:00
|
|
|
{
|
2014-04-18 15:09:44 -04:00
|
|
|
Color.clear();
|
2014-02-16 17:51:32 -05:00
|
|
|
}
|
|
|
|
Msg.AddTextPart(AString("<") + m_Player->GetName() + "> ", Color);
|
|
|
|
Msg.ParseText(a_Message);
|
|
|
|
Msg.UnderlineUrls();
|
2013-08-14 14:08:05 -04:00
|
|
|
m_Player->GetWorld()->BroadcastChat(Msg);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 07:51:17 -04:00
|
|
|
void cClientHandle::HandlePlayerLook(float a_Rotation, float a_Pitch, bool a_IsOnGround)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
if ((m_Player == nullptr) || (m_State != csPlaying))
|
2013-09-08 12:36:06 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-16 14:00:49 -05:00
|
|
|
m_Player->SetYaw (a_Rotation);
|
2013-04-02 02:48:31 -04:00
|
|
|
m_Player->SetHeadYaw (a_Rotation);
|
2012-08-19 07:51:17 -04:00
|
|
|
m_Player->SetPitch (a_Pitch);
|
|
|
|
m_Player->SetTouchGround(a_IsOnGround);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-26 10:38:14 -04:00
|
|
|
void cClientHandle::HandlePlayerMoveLook(double a_PosX, double a_PosY, double a_PosZ, double a_Stance, float a_Rotation, float a_Pitch, bool a_IsOnGround)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-05-26 17:13:40 -04:00
|
|
|
HandlePlayerLook(a_Rotation, a_Pitch, a_IsOnGround);
|
2014-05-27 03:28:46 -04:00
|
|
|
HandlePlayerPos(a_PosX, a_PosY, a_PosZ, a_Stance, a_IsOnGround);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-18 16:43:35 -05:00
|
|
|
void cClientHandle::HandleAnimation(int a_Animation)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-12-18 11:11:15 -05:00
|
|
|
if (cPluginManager::Get()->CallHookPlayerAnimation(*m_Player, a_Animation))
|
2013-08-11 06:12:20 -04:00
|
|
|
{
|
|
|
|
// Plugin disagrees, bail out
|
|
|
|
return;
|
|
|
|
}
|
2013-12-19 11:03:43 -05:00
|
|
|
|
2013-12-06 18:47:07 -05:00
|
|
|
m_Player->GetWorld()->BroadcastEntityAnimation(*m_Player, a_Animation, this);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-21 08:00:20 -04:00
|
|
|
void cClientHandle::HandleSlotSelected(Int16 a_SlotNum)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-05-19 14:22:37 -04:00
|
|
|
m_Player->GetInventory().SetEquippedSlotNum(a_SlotNum);
|
2012-08-19 07:51:17 -04:00
|
|
|
m_Player->GetWorld()->BroadcastEntityEquipment(*m_Player, 0, m_Player->GetInventory().GetEquippedItem(), this);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-09-05 18:04:49 -04:00
|
|
|
void cClientHandle::HandleSteerVehicle(float a_Forward, float a_Sideways)
|
|
|
|
{
|
|
|
|
m_Player->SteerVehicle(a_Forward, a_Sideways);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-21 08:00:20 -04:00
|
|
|
void cClientHandle::HandleWindowClose(UInt8 a_WindowID)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-05-30 15:34:09 -04:00
|
|
|
m_Player->CloseWindowIfID(a_WindowID);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-21 08:00:20 -04:00
|
|
|
void cClientHandle::HandleWindowClick(UInt8 a_WindowID, Int16 a_SlotNum, eClickAction a_ClickAction, const cItem & a_HeldItem)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-05-08 05:45:07 -04:00
|
|
|
LOGD("WindowClick: WinID %d, SlotNum %d, action: %s, Item %s x %d",
|
|
|
|
a_WindowID, a_SlotNum, ClickActionToString(a_ClickAction),
|
2012-09-20 09:25:54 -04:00
|
|
|
ItemToString(a_HeldItem).c_str(), a_HeldItem.m_ItemCount
|
|
|
|
);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
cWindow * Window = m_Player->GetWindow();
|
2014-10-20 16:55:07 -04:00
|
|
|
if (Window == nullptr)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
LOGWARNING("Player \"%s\" clicked in a non-existent window. Ignoring", m_Username.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-08 05:45:07 -04:00
|
|
|
Window->Clicked(*m_Player, a_WindowID, a_SlotNum, a_ClickAction, a_HeldItem);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
void cClientHandle::HandleUpdateSign(
|
2014-07-17 10:33:09 -04:00
|
|
|
int a_BlockX, int a_BlockY, int a_BlockZ,
|
|
|
|
const AString & a_Line1, const AString & a_Line2,
|
2012-08-19 15:42:32 -04:00
|
|
|
const AString & a_Line3, const AString & a_Line4
|
|
|
|
)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-11-15 16:36:31 -05:00
|
|
|
if (m_LastPlacedSign.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ)))
|
2014-11-15 09:16:52 -05:00
|
|
|
{
|
2014-11-15 16:36:31 -05:00
|
|
|
m_LastPlacedSign.Set(0, -1, 0);
|
2014-11-15 09:16:52 -05:00
|
|
|
m_Player->GetWorld()->SetSignLines(a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4, m_Player);
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-21 08:00:20 -04:00
|
|
|
void cClientHandle::HandleUseEntity(UInt32 a_TargetEntityID, bool a_IsLeftClick)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-03-03 14:05:11 -05:00
|
|
|
// TODO: Let plugins interfere via a hook
|
|
|
|
|
2013-07-12 16:01:25 -04:00
|
|
|
// If it is a right click, call the entity's OnRightClicked() handler:
|
2012-08-19 15:42:32 -04:00
|
|
|
if (!a_IsLeftClick)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-03-03 14:05:11 -05:00
|
|
|
class cRclkEntity : public cEntityCallback
|
|
|
|
{
|
|
|
|
cPlayer & m_Player;
|
|
|
|
virtual bool Item(cEntity * a_Entity) override
|
|
|
|
{
|
2013-08-02 02:44:06 -04:00
|
|
|
if (cPluginManager::Get()->CallHookPlayerRightClickingEntity(m_Player, *a_Entity))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-03 14:05:11 -05:00
|
|
|
a_Entity->OnRightClicked(m_Player);
|
2013-07-12 16:01:25 -04:00
|
|
|
return false;
|
2013-03-03 14:05:11 -05:00
|
|
|
}
|
|
|
|
public:
|
|
|
|
cRclkEntity(cPlayer & a_Player) : m_Player(a_Player) {}
|
|
|
|
} Callback (*m_Player);
|
|
|
|
|
|
|
|
cWorld * World = m_Player->GetWorld();
|
|
|
|
World->DoWithEntityByID(a_TargetEntityID, Callback);
|
2012-06-14 09:06:06 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-12 16:01:25 -04:00
|
|
|
// If it is a left click, attack the entity:
|
2012-06-14 09:06:06 -04:00
|
|
|
class cDamageEntity : public cEntityCallback
|
|
|
|
{
|
|
|
|
virtual bool Item(cEntity * a_Entity) override
|
|
|
|
{
|
2012-11-16 11:03:56 -05:00
|
|
|
if (!a_Entity->GetWorld()->IsPVPEnabled())
|
2012-10-10 15:46:12 -04:00
|
|
|
{
|
2013-07-12 16:01:25 -04:00
|
|
|
// PVP is disabled, disallow players hurting other players:
|
|
|
|
if (a_Entity->IsPlayer())
|
2012-10-10 15:46:12 -04:00
|
|
|
{
|
|
|
|
// Player is hurting another player which is not allowed when PVP is disabled so ignore it
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2013-07-12 16:01:25 -04:00
|
|
|
a_Entity->TakeDamage(*m_Attacker);
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
public:
|
2012-12-21 06:04:08 -05:00
|
|
|
cPawn * m_Attacker;
|
2012-06-14 09:06:06 -04:00
|
|
|
} Callback;
|
|
|
|
|
2012-12-21 06:04:08 -05:00
|
|
|
Callback.m_Attacker = m_Player;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
cWorld * World = m_Player->GetWorld();
|
2013-07-12 16:01:25 -04:00
|
|
|
if (World->DoWithEntityByID(a_TargetEntityID, Callback))
|
|
|
|
{
|
|
|
|
// Any kind of an attack implies food exhaustion
|
|
|
|
m_Player->AddFoodExhaustion(0.3);
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cClientHandle::HandleRespawn(void)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_Player == nullptr)
|
2012-10-17 08:19:20 -04:00
|
|
|
{
|
|
|
|
Destroy();
|
|
|
|
return;
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
m_Player->Respawn();
|
2013-01-11 23:46:01 -05:00
|
|
|
cRoot::Get()->GetPluginManager()->CallHookPlayerSpawned(*m_Player);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
void cClientHandle::HandleKeepAlive(int a_KeepAliveID)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-19 15:42:32 -04:00
|
|
|
if (a_KeepAliveID == m_PingID)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-10-20 13:59:40 -04:00
|
|
|
m_Ping = std::chrono::steady_clock::now() - m_PingStartTime;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-12-08 03:45:29 -05:00
|
|
|
bool cClientHandle::CheckMultiLogin(const AString & a_Username)
|
2014-12-08 03:12:48 -05:00
|
|
|
{
|
2014-12-08 17:33:59 -05:00
|
|
|
// If the multilogin is allowed, skip this check entirely:
|
2014-12-10 03:45:24 -05:00
|
|
|
if ((cRoot::Get()->GetServer()->DoesAllowMultiLogin()))
|
2014-12-08 03:12:48 -05:00
|
|
|
{
|
2014-12-08 17:33:59 -05:00
|
|
|
return true;
|
|
|
|
}
|
2014-12-08 03:12:48 -05:00
|
|
|
|
2014-12-08 17:33:59 -05:00
|
|
|
// Check if the player is waiting to be transferred to the World.
|
|
|
|
if (cRoot::Get()->GetServer()->IsPlayerInQueue(a_Username))
|
|
|
|
{
|
2014-12-09 06:06:25 -05:00
|
|
|
Kick("A player of the username is already logged in");
|
|
|
|
return false;
|
2014-12-08 17:33:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
class cCallback :
|
|
|
|
public cPlayerListCallback
|
|
|
|
{
|
|
|
|
virtual bool Item(cPlayer * a_Player) override
|
|
|
|
{
|
|
|
|
return true;
|
2014-12-08 03:16:09 -05:00
|
|
|
}
|
2014-12-11 08:34:09 -05:00
|
|
|
} Callback;
|
2014-12-08 17:33:59 -05:00
|
|
|
|
|
|
|
// Check if the player is in any World.
|
|
|
|
if (cRoot::Get()->DoWithPlayer(a_Username, Callback))
|
|
|
|
{
|
|
|
|
Kick("A player of the username is already logged in");
|
2014-12-09 17:23:44 -05:00
|
|
|
return false;
|
2014-12-08 03:12:48 -05:00
|
|
|
}
|
2014-12-09 17:23:44 -05:00
|
|
|
return true;
|
2014-12-08 03:12:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-09-05 16:30:27 -04:00
|
|
|
bool cClientHandle::HandleHandshake(const AString & a_Username)
|
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
if (!cRoot::Get()->GetPluginManager()->CallHookHandshake(*this, a_Username))
|
2012-09-05 16:30:27 -04:00
|
|
|
{
|
2013-08-11 13:18:06 -04:00
|
|
|
if (cRoot::Get()->GetServer()->GetNumPlayers() >= cRoot::Get()->GetServer()->GetMaxPlayers())
|
2012-09-05 16:30:27 -04:00
|
|
|
{
|
|
|
|
Kick("The server is currently full :(-- Try again later");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-12-08 03:16:09 -05:00
|
|
|
|
2014-12-08 03:45:29 -05:00
|
|
|
return CheckMultiLogin(a_Username);
|
2012-09-05 16:30:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-21 08:00:20 -04:00
|
|
|
void cClientHandle::HandleEntityCrouch(UInt32 a_EntityID, bool a_IsCrouching)
|
2012-09-29 16:43:42 -04:00
|
|
|
{
|
2013-08-11 13:18:06 -04:00
|
|
|
if (a_EntityID != m_Player->GetUniqueID())
|
2012-09-29 16:43:42 -04:00
|
|
|
{
|
|
|
|
// We should only receive entity actions from the entity that is performing the action
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-08 11:55:53 -05:00
|
|
|
m_Player->SetCrouch(a_IsCrouching);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-21 08:00:20 -04:00
|
|
|
void cClientHandle::HandleEntityLeaveBed(UInt32 a_EntityID)
|
2014-03-08 11:55:53 -05:00
|
|
|
{
|
|
|
|
if (a_EntityID != m_Player->GetUniqueID())
|
2012-09-29 16:43:42 -04:00
|
|
|
{
|
2014-03-08 11:55:53 -05:00
|
|
|
// We should only receive entity actions from the entity that is performing the action
|
|
|
|
return;
|
2012-09-29 16:43:42 -04:00
|
|
|
}
|
2014-03-08 11:55:53 -05:00
|
|
|
|
2015-03-05 16:21:39 -05:00
|
|
|
cChunkInterface Interface(GetPlayer()->GetWorld()->GetChunkMap());
|
|
|
|
cBlockBedHandler::SetBedOccupationState(Interface, GetPlayer()->GetLastBedPos(), false);
|
2015-02-08 16:21:48 -05:00
|
|
|
GetPlayer()->SetIsInBed(false);
|
2014-03-08 11:55:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-21 08:00:20 -04:00
|
|
|
void cClientHandle::HandleEntitySprinting(UInt32 a_EntityID, bool a_IsSprinting)
|
2014-03-08 11:55:53 -05:00
|
|
|
{
|
|
|
|
if (a_EntityID != m_Player->GetUniqueID())
|
|
|
|
{
|
|
|
|
// We should only receive entity actions from the entity that is performing the action
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Player->SetSprint(a_IsSprinting);
|
2012-09-29 16:43:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-05 17:11:06 -04:00
|
|
|
void cClientHandle::HandleUnmount(void)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_Player == nullptr)
|
2013-07-05 17:11:06 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_Player->Detach();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-30 16:48:59 -04:00
|
|
|
void cClientHandle::HandleTabCompletion(const AString & a_Text)
|
|
|
|
{
|
|
|
|
AStringVector Results;
|
|
|
|
m_Player->GetWorld()->TabCompleteUserName(a_Text, Results);
|
2013-07-31 05:16:11 -04:00
|
|
|
cRoot::Get()->GetPluginManager()->TabCompleteCommand(a_Text, Results, m_Player);
|
2013-07-30 16:48:59 -04:00
|
|
|
if (Results.empty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
std::sort(Results.begin(), Results.end());
|
|
|
|
SendTabCompletionResults(Results);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-04 04:13:25 -04:00
|
|
|
void cClientHandle::SendData(const char * a_Data, size_t a_Size)
|
2012-08-27 13:31:16 -04:00
|
|
|
{
|
2013-08-22 02:17:26 -04:00
|
|
|
if (m_HasSentDC)
|
|
|
|
{
|
|
|
|
// This could crash the client, because they've already unloaded the world etc., and suddenly a wild packet appears (#31)
|
|
|
|
return;
|
|
|
|
}
|
2015-01-24 14:17:00 -05:00
|
|
|
|
|
|
|
cCSLock Lock(m_CSOutgoingData);
|
2015-01-26 08:49:51 -05:00
|
|
|
m_OutgoingData.append(a_Data, a_Size);
|
2012-08-27 13:31:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-08 15:58:08 -04:00
|
|
|
void cClientHandle::RemoveFromWorld(void)
|
2013-08-14 04:24:34 -04:00
|
|
|
{
|
|
|
|
// Remove all associated chunks:
|
|
|
|
cChunkCoordsList Chunks;
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSChunkLists);
|
|
|
|
std::swap(Chunks, m_LoadedChunks);
|
|
|
|
m_ChunksToSend.clear();
|
|
|
|
}
|
|
|
|
for (cChunkCoordsList::iterator itr = Chunks.begin(), end = Chunks.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_Protocol->SendUnloadChunk(itr->m_ChunkX, itr->m_ChunkZ);
|
|
|
|
} // for itr - Chunks[]
|
2014-10-02 17:50:41 -04:00
|
|
|
|
2014-06-12 10:21:07 -04:00
|
|
|
// Here, we set last streamed values to bogus ones so everything is resent
|
2013-08-14 04:24:34 -04:00
|
|
|
m_LastStreamedChunkX = 0x7fffffff;
|
|
|
|
m_LastStreamedChunkZ = 0x7fffffff;
|
2014-10-06 11:38:17 -04:00
|
|
|
|
2013-09-08 12:36:06 -04:00
|
|
|
m_HasSentPlayerChunk = false;
|
2013-08-14 04:24:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
bool cClientHandle::CheckBlockInteractionsRate(void)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
ASSERT(m_Player != nullptr);
|
|
|
|
ASSERT(m_Player->GetWorld() != nullptr);
|
2014-03-01 16:24:36 -05:00
|
|
|
|
|
|
|
if (m_NumBlockChangeInteractionsThisTick > MAX_BLOCK_CHANGE_INTERACTIONS)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-03-01 16:24:36 -05:00
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2014-03-01 16:24:36 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cClientHandle::Tick(float a_Dt)
|
|
|
|
{
|
2013-08-13 16:45:29 -04:00
|
|
|
// Process received network data:
|
|
|
|
AString IncomingData;
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSIncomingData);
|
|
|
|
std::swap(IncomingData, m_IncomingData);
|
|
|
|
}
|
2015-01-25 16:52:40 -05:00
|
|
|
if (!IncomingData.empty())
|
|
|
|
{
|
|
|
|
m_Protocol->DataReceived(IncomingData.data(), IncomingData.size());
|
|
|
|
}
|
2015-01-26 08:49:51 -05:00
|
|
|
|
|
|
|
// Send any queued outgoing data:
|
|
|
|
AString OutgoingData;
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSOutgoingData);
|
|
|
|
std::swap(OutgoingData, m_OutgoingData);
|
|
|
|
}
|
2015-02-22 13:05:43 -05:00
|
|
|
if (!OutgoingData.empty())
|
2015-01-26 08:49:51 -05:00
|
|
|
{
|
2015-02-22 13:05:43 -05:00
|
|
|
cTCPLinkPtr Link(m_Link); // Grab a copy of the link in a multithread-safe way
|
|
|
|
if ((Link != nullptr))
|
|
|
|
{
|
|
|
|
Link->Send(OutgoingData.data(), OutgoingData.size());
|
|
|
|
}
|
2015-01-26 08:49:51 -05:00
|
|
|
}
|
2013-08-13 16:45:29 -04:00
|
|
|
|
2015-01-24 14:17:00 -05:00
|
|
|
m_TicksSinceLastPacket += 1;
|
|
|
|
if (m_TicksSinceLastPacket > 600) // 30 seconds time-out
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-25 17:59:13 -04:00
|
|
|
SendDisconnect("Nooooo!! You timed out! D: Come back!");
|
2012-06-14 09:06:06 -04:00
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_Player == nullptr)
|
2013-08-12 02:35:13 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-10-02 17:50:41 -04:00
|
|
|
|
2013-09-08 12:36:06 -04:00
|
|
|
// If the chunk the player's in was just sent, spawn the player:
|
2013-12-15 14:12:40 -05:00
|
|
|
if (m_HasSentPlayerChunk && (m_State == csDownloadingWorld))
|
2013-09-08 12:36:06 -04:00
|
|
|
{
|
|
|
|
m_Protocol->SendPlayerMoveLook();
|
|
|
|
m_State = csPlaying;
|
|
|
|
}
|
|
|
|
|
2013-07-03 03:47:35 -04:00
|
|
|
// Send a ping packet:
|
2014-04-15 17:40:06 -04:00
|
|
|
if (m_State == csPlaying)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-12-07 09:46:27 -05:00
|
|
|
if ((m_PingStartTime + PING_TIME_MS <= std::chrono::steady_clock::now()))
|
2014-04-15 17:40:06 -04:00
|
|
|
{
|
|
|
|
m_PingID++;
|
2014-10-20 13:59:40 -04:00
|
|
|
m_PingStartTime = std::chrono::steady_clock::now();
|
2014-04-15 17:40:06 -04:00
|
|
|
m_Protocol->SendKeepAlive(m_PingID);
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-09-25 05:54:36 -04:00
|
|
|
|
2014-10-02 17:50:41 -04:00
|
|
|
if ((m_State >= csAuthenticated) && (m_State < csDestroying))
|
|
|
|
{
|
2014-10-06 15:27:53 -04:00
|
|
|
// Stream 4 chunks per tick
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
// Stream the next chunk
|
|
|
|
if (StreamNextChunk())
|
|
|
|
{
|
|
|
|
// Streaming finished. All chunks are loaded.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-10-02 17:50:41 -04:00
|
|
|
|
2014-10-06 11:38:17 -04:00
|
|
|
// Unload all chunks that are out of the view distance (all 5 seconds)
|
|
|
|
if ((m_Player->GetWorld()->GetWorldAge() % 100) == 0)
|
2014-10-02 17:50:41 -04:00
|
|
|
{
|
|
|
|
UnloadOutOfRangeChunks();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-25 05:54:36 -04:00
|
|
|
// Handle block break animation:
|
2013-08-12 02:35:13 -04:00
|
|
|
if (m_BlockDigAnimStage > -1)
|
2012-09-25 05:54:36 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
int lastAnimVal = m_BlockDigAnimStage;
|
|
|
|
m_BlockDigAnimStage += (int)(m_BlockDigAnimSpeed * a_Dt);
|
|
|
|
if (m_BlockDigAnimStage > 9000)
|
2012-09-25 05:54:36 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
m_BlockDigAnimStage = 9000;
|
2012-09-25 05:54:36 -04:00
|
|
|
}
|
2013-01-11 23:46:01 -05:00
|
|
|
if (m_BlockDigAnimStage / 1000 != lastAnimVal / 1000)
|
2012-09-25 05:54:36 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
m_Player->GetWorld()->BroadcastBlockBreakAnimation(m_UniqueID, m_BlockDigAnimX, m_BlockDigAnimY, m_BlockDigAnimZ, (char)(m_BlockDigAnimStage / 1000), this);
|
2012-09-25 05:54:36 -04:00
|
|
|
}
|
|
|
|
}
|
2013-06-18 15:32:31 -04:00
|
|
|
|
2014-03-01 16:24:36 -05:00
|
|
|
// Reset explosion & block change counters:
|
2014-02-04 18:40:58 -05:00
|
|
|
m_NumExplosionsThisTick = 0;
|
2014-03-01 16:24:36 -05:00
|
|
|
m_NumBlockChangeInteractionsThisTick = 0;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-16 04:41:35 -05:00
|
|
|
void cClientHandle::ServerTick(float a_Dt)
|
|
|
|
{
|
|
|
|
// Process received network data:
|
|
|
|
AString IncomingData;
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSIncomingData);
|
|
|
|
std::swap(IncomingData, m_IncomingData);
|
|
|
|
}
|
2015-01-25 16:52:40 -05:00
|
|
|
if (!IncomingData.empty())
|
|
|
|
{
|
|
|
|
m_Protocol->DataReceived(IncomingData.data(), IncomingData.size());
|
|
|
|
}
|
2013-12-16 04:41:35 -05:00
|
|
|
|
2015-01-26 08:49:51 -05:00
|
|
|
// Send any queued outgoing data:
|
|
|
|
AString OutgoingData;
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSOutgoingData);
|
|
|
|
std::swap(OutgoingData, m_OutgoingData);
|
|
|
|
}
|
|
|
|
if ((m_Link != nullptr) && !OutgoingData.empty())
|
|
|
|
{
|
|
|
|
m_Link->Send(OutgoingData.data(), OutgoingData.size());
|
|
|
|
}
|
2013-12-16 04:41:35 -05:00
|
|
|
|
|
|
|
if (m_State == csAuthenticated)
|
|
|
|
{
|
2014-10-02 17:50:41 -04:00
|
|
|
StreamNextChunk();
|
2013-12-16 04:41:35 -05:00
|
|
|
|
|
|
|
// Remove the client handle from the server, it will be ticked from its cPlayer object from now on
|
|
|
|
cRoot::Get()->GetServer()->ClientMovedToWorld(this);
|
|
|
|
|
|
|
|
// Add the player to the world (start ticking from there):
|
|
|
|
m_State = csDownloadingWorld;
|
|
|
|
m_Player->GetWorld()->AddPlayer(m_Player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-24 14:17:00 -05:00
|
|
|
m_TicksSinceLastPacket += 1;
|
|
|
|
if (m_TicksSinceLastPacket > 600) // 30 seconds
|
2013-12-16 04:41:35 -05:00
|
|
|
{
|
|
|
|
SendDisconnect("Nooooo!! You timed out! D: Come back!");
|
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendAttachEntity(const cEntity & a_Entity, const cEntity * a_Vehicle)
|
2012-08-17 06:18:07 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendAttachEntity(a_Entity, a_Vehicle);
|
2012-08-18 05:56:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType)
|
2012-08-18 05:56:28 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendBlockAction(a_BlockX, a_BlockY, a_BlockZ, a_Byte1, a_Byte2, a_BlockType);
|
2012-08-18 06:38:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-21 11:11:57 -04:00
|
|
|
void cClientHandle::SendBlockBreakAnim(UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage)
|
2012-08-18 06:38:15 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendBlockBreakAnim(a_EntityID, a_BlockX, a_BlockY, a_BlockZ, a_Stage);
|
2012-08-17 06:18:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
2012-08-19 07:51:17 -04:00
|
|
|
{
|
2014-10-16 15:12:26 -04:00
|
|
|
int ChunkX, ChunkZ = 0;
|
|
|
|
cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
|
|
|
|
cChunkCoords ChunkCoords = cChunkCoords(ChunkX, ChunkZ);
|
|
|
|
|
|
|
|
// Do not send block changes in chunks that weren't sent to the client yet:
|
|
|
|
cCSLock Lock(m_CSChunkLists);
|
|
|
|
if (std::find(m_SentChunks.begin(), m_SentChunks.end(), ChunkCoords) != m_SentChunks.end())
|
|
|
|
{
|
|
|
|
Lock.Unlock();
|
|
|
|
m_Protocol->SendBlockChange(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta);
|
|
|
|
}
|
2012-08-19 07:51:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes)
|
2012-08-19 07:51:17 -04:00
|
|
|
{
|
2013-08-19 15:55:03 -04:00
|
|
|
ASSERT(!a_Changes.empty()); // We don't want to be sending empty change packets!
|
2014-10-16 15:12:26 -04:00
|
|
|
|
|
|
|
// Do not send block changes in chunks that weren't sent to the client yet:
|
|
|
|
cChunkCoords ChunkCoords = cChunkCoords(a_ChunkX, a_ChunkZ);
|
|
|
|
cCSLock Lock(m_CSChunkLists);
|
|
|
|
if (std::find(m_SentChunks.begin(), m_SentChunks.end(), ChunkCoords) != m_SentChunks.end())
|
|
|
|
{
|
|
|
|
Lock.Unlock();
|
|
|
|
m_Protocol->SendBlockChanges(a_ChunkX, a_ChunkZ, a_Changes);
|
|
|
|
}
|
2012-08-19 07:51:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-15 17:16:44 -05:00
|
|
|
void cClientHandle::SendChat(const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData)
|
2012-08-19 07:51:17 -04:00
|
|
|
{
|
2014-07-27 07:47:21 -04:00
|
|
|
cWorld * World = GetPlayer()->GetWorld();
|
2014-10-20 16:55:07 -04:00
|
|
|
if (World == nullptr)
|
2014-02-07 13:58:52 -05:00
|
|
|
{
|
2014-07-27 07:47:21 -04:00
|
|
|
World = cRoot::Get()->GetWorld(GetPlayer()->GetLoadedWorldName());
|
2014-10-20 16:55:07 -04:00
|
|
|
if (World == nullptr)
|
2014-02-07 13:58:52 -05:00
|
|
|
{
|
|
|
|
World = cRoot::Get()->GetDefaultWorld();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-27 07:47:21 -04:00
|
|
|
AString Message = FormatMessageType(World->ShouldUseChatPrefixes(), a_ChatPrefix, a_AdditionalData);
|
2014-04-24 20:24:39 -04:00
|
|
|
m_Protocol->SendChat(Message.append(a_Message));
|
2012-08-19 07:51:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-15 17:16:44 -05:00
|
|
|
void cClientHandle::SendChat(const cCompositeChat & a_Message)
|
|
|
|
{
|
|
|
|
m_Protocol->SendChat(a_Message);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer)
|
2012-08-19 07:51:17 -04:00
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
ASSERT(m_Player != nullptr);
|
2013-08-20 15:13:28 -04:00
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
// Check chunks being sent, erase them from m_ChunksToSend:
|
|
|
|
bool Found = false;
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSChunkLists);
|
|
|
|
for (cChunkCoordsList::iterator itr = m_ChunksToSend.begin(); itr != m_ChunksToSend.end(); ++itr)
|
|
|
|
{
|
|
|
|
if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ))
|
|
|
|
{
|
|
|
|
m_ChunksToSend.erase(itr);
|
|
|
|
Found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} // for itr - m_ChunksToSend[]
|
|
|
|
}
|
|
|
|
if (!Found)
|
|
|
|
{
|
|
|
|
// This just sometimes happens. If you have a reliably replicatable situation for this, go ahead and fix it
|
|
|
|
// It's not a big issue anyway, just means that some chunks may be compressed several times
|
|
|
|
// LOGD("Refusing to send chunk [%d, %d] to client \"%s\" at [%d, %d].", ChunkX, ChunkZ, m_Username.c_str(), m_Player->GetChunkX(), m_Player->GetChunkZ());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Protocol->SendChunkData(a_ChunkX, a_ChunkZ, a_Serializer);
|
2013-09-08 12:36:06 -04:00
|
|
|
|
2014-10-16 15:12:26 -04:00
|
|
|
// Add the chunk to the list of chunks sent to the player:
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSChunkLists);
|
|
|
|
m_SentChunks.push_back(cChunkCoords(a_ChunkX, a_ChunkZ));
|
|
|
|
}
|
|
|
|
|
2013-09-08 12:36:06 -04:00
|
|
|
// If it is the chunk the player's in, make them spawn (in the tick thread):
|
|
|
|
if ((m_State == csAuthenticated) || (m_State == csDownloadingWorld))
|
|
|
|
{
|
|
|
|
if ((a_ChunkX == m_Player->GetChunkX()) && (a_ChunkZ == m_Player->GetChunkZ()))
|
|
|
|
{
|
|
|
|
m_HasSentPlayerChunk = true;
|
|
|
|
}
|
|
|
|
}
|
2012-08-19 07:51:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-27 14:56:29 -04:00
|
|
|
void cClientHandle::SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player)
|
2012-08-19 07:51:17 -04:00
|
|
|
{
|
2014-06-27 14:56:29 -04:00
|
|
|
m_Protocol->SendCollectEntity(a_Entity, a_Player);
|
2012-08-19 07:51:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendDestroyEntity(const cEntity & a_Entity)
|
2012-08-19 07:51:17 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendDestroyEntity(a_Entity);
|
2012-08-19 07:51:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendDisconnect(const AString & a_Reason)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
if (!m_HasSentDC)
|
|
|
|
{
|
2013-07-08 09:00:09 -04:00
|
|
|
LOGD("Sending a DC: \"%s\"", StripColorCodes(a_Reason).c_str());
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendDisconnect(a_Reason);
|
|
|
|
m_HasSentDC = true;
|
|
|
|
}
|
2012-08-19 15:42:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-29 15:42:05 -04:00
|
|
|
void cClientHandle::SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ)
|
|
|
|
{
|
2014-11-15 16:36:31 -05:00
|
|
|
m_LastPlacedSign.Set(a_BlockX, a_BlockY, a_BlockZ);
|
2013-07-29 15:42:05 -04:00
|
|
|
m_Protocol->SendEditSign(a_BlockX, a_BlockY, a_BlockZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-14 12:19:56 -05:00
|
|
|
void cClientHandle::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration)
|
|
|
|
{
|
|
|
|
m_Protocol->SendEntityEffect(a_Entity, a_EffectID, a_Amplifier, a_Duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendEntityEquipment(a_Entity, a_SlotNum, a_Item);
|
2012-08-19 15:42:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendEntityHeadLook(const cEntity & a_Entity)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
ASSERT(a_Entity.GetUniqueID() != m_Player->GetUniqueID()); // Must not send for self
|
|
|
|
|
|
|
|
m_Protocol->SendEntityHeadLook(a_Entity);
|
2012-08-19 15:42:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendEntityLook(const cEntity & a_Entity)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
|
|
|
ASSERT(a_Entity.GetUniqueID() != m_Player->GetUniqueID()); // Must not send for self
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendEntityLook(a_Entity);
|
2012-08-19 15:42:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendEntityMetadata(const cEntity & a_Entity)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendEntityMetadata(a_Entity);
|
2012-08-19 15:42:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
|
|
|
ASSERT(a_Entity.GetUniqueID() != m_Player->GetUniqueID()); // Must not send for self
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendEntityRelMove(a_Entity, a_RelX, a_RelY, a_RelZ);
|
2012-08-19 15:42:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ)
|
2013-03-17 22:51:55 -04:00
|
|
|
{
|
|
|
|
ASSERT(a_Entity.GetUniqueID() != m_Player->GetUniqueID()); // Must not send for self
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendEntityRelMoveLook(a_Entity, a_RelX, a_RelY, a_RelZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cClientHandle::SendEntityStatus(const cEntity & a_Entity, char a_Status)
|
|
|
|
{
|
|
|
|
m_Protocol->SendEntityStatus(a_Entity, a_Status);
|
2013-03-17 22:51:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendEntityVelocity(const cEntity & a_Entity)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendEntityVelocity(a_Entity);
|
2012-08-19 15:42:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendExplosion(double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion)
|
2013-03-03 14:05:11 -05:00
|
|
|
{
|
2014-02-04 18:40:58 -05:00
|
|
|
if (m_NumExplosionsThisTick > MAX_EXPLOSIONS_PER_TICK)
|
2013-07-07 09:06:06 -04:00
|
|
|
{
|
2014-02-04 18:40:58 -05:00
|
|
|
LOGD("Dropped an explosion!");
|
2013-07-07 09:06:06 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the statistics:
|
2014-04-12 08:16:48 -04:00
|
|
|
m_NumExplosionsThisTick++;
|
2013-07-07 09:06:06 -04:00
|
|
|
|
|
|
|
m_Protocol->SendExplosion(a_BlockX, a_BlockY, a_BlockZ, a_Radius, a_BlocksAffected, a_PlayerMotion);
|
2013-03-03 14:05:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendGameMode(eGameMode a_GameMode)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendGameMode(a_GameMode);
|
2012-08-19 15:42:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cClientHandle::SendHealth(void)
|
|
|
|
{
|
2012-08-27 13:31:16 -04:00
|
|
|
m_Protocol->SendHealth();
|
2012-08-19 15:42:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem & a_Item)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendInventorySlot(a_WindowID, a_SlotNum, a_Item);
|
2012-08-19 15:42:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-12 20:20:04 -04:00
|
|
|
void cClientHandle::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale)
|
2014-02-13 10:13:09 -05:00
|
|
|
{
|
2014-09-12 20:20:04 -04:00
|
|
|
m_Protocol->SendMapColumn(a_ID, a_X, a_Y, a_Colors, a_Length, m_Scale);
|
2014-02-13 10:13:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-12 20:20:04 -04:00
|
|
|
void cClientHandle::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale)
|
2014-02-18 13:50:08 -05:00
|
|
|
{
|
2014-09-12 20:20:04 -04:00
|
|
|
m_Protocol->SendMapDecorators(a_ID, a_Decorators, m_Scale);
|
2014-02-18 13:50:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-13 10:13:09 -05:00
|
|
|
void cClientHandle::SendMapInfo(int a_ID, unsigned int a_Scale)
|
|
|
|
{
|
|
|
|
m_Protocol->SendMapInfo(a_ID, a_Scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-11 11:03:09 -04:00
|
|
|
void cClientHandle::SendParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount)
|
2013-12-22 08:45:25 -05:00
|
|
|
{
|
2014-09-11 11:03:09 -04:00
|
|
|
m_Protocol->SendParticleEffect(a_ParticleName, a_SrcX, a_SrcY, a_SrcZ, a_OffsetX, a_OffsetY, a_OffsetZ, a_ParticleData, a_ParticleAmount);
|
2013-12-22 08:45:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-21 13:17:26 -04:00
|
|
|
void cClientHandle::SendParticleEffect(const AString & a_ParticleName, const Vector3f a_Src, const Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array<int, 2> a_Data)
|
|
|
|
{
|
|
|
|
m_Protocol->SendParticleEffect(a_ParticleName, a_Src, a_Offset, a_ParticleData, a_ParticleAmount, a_Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendPickupSpawn(const cPickup & a_Pickup)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendPickupSpawn(a_Pickup);
|
2012-08-19 15:42:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-17 19:16:03 -05:00
|
|
|
void cClientHandle::SendPaintingSpawn(const cPainting & a_Painting)
|
|
|
|
{
|
|
|
|
m_Protocol->SendPaintingSpawn(a_Painting);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
2013-12-06 18:47:07 -05:00
|
|
|
void cClientHandle::SendEntityAnimation(const cEntity & a_Entity, char a_Animation)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2013-12-06 18:47:07 -05:00
|
|
|
m_Protocol->SendEntityAnimation(a_Entity, a_Animation);
|
2012-08-19 15:42:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-15 08:48:17 -05:00
|
|
|
void cClientHandle::SendPlayerAbilities()
|
|
|
|
{
|
|
|
|
m_Protocol->SendPlayerAbilities();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-18 12:50:17 -04:00
|
|
|
void cClientHandle::SendPlayerListAddPlayer(const cPlayer & a_Player)
|
|
|
|
{
|
|
|
|
m_Protocol->SendPlayerListAddPlayer(a_Player);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cClientHandle::SendPlayerListRemovePlayer(const cPlayer & a_Player)
|
|
|
|
{
|
|
|
|
m_Protocol->SendPlayerListRemovePlayer(a_Player);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cClientHandle::SendPlayerListUpdateGameMode(const cPlayer & a_Player)
|
2012-08-19 17:14:45 -04:00
|
|
|
{
|
2014-09-18 12:50:17 -04:00
|
|
|
m_Protocol->SendPlayerListUpdateGameMode(a_Player);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cClientHandle::SendPlayerListUpdatePing(const cPlayer & a_Player)
|
|
|
|
{
|
|
|
|
m_Protocol->SendPlayerListUpdatePing(a_Player);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-26 11:37:19 -04:00
|
|
|
void cClientHandle::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName)
|
2012-08-19 17:14:45 -04:00
|
|
|
{
|
2014-09-26 11:37:19 -04:00
|
|
|
m_Protocol->SendPlayerListUpdateDisplayName(a_Player, a_CustomName);
|
2012-08-19 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendPlayerMaxSpeed(void)
|
2013-04-17 22:42:45 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendPlayerMaxSpeed();
|
2013-04-17 22:42:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendPlayerMoveLook(void)
|
2012-08-19 17:14:45 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
/*
|
|
|
|
LOGD("Sending PlayerMoveLook: {%0.2f, %0.2f, %0.2f}, stance %0.2f, OnGround: %d",
|
|
|
|
m_Player->GetPosX(), m_Player->GetPosY(), m_Player->GetPosZ(), m_Player->GetStance(), m_Player->IsOnGround() ? 1 : 0
|
|
|
|
);
|
|
|
|
*/
|
|
|
|
m_Protocol->SendPlayerMoveLook();
|
2012-08-19 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendPlayerPosition(void)
|
2012-08-19 17:14:45 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendPlayerPosition();
|
2012-08-19 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-24 03:58:26 -04:00
|
|
|
void cClientHandle::SendPlayerSpawn(const cPlayer & a_Player)
|
|
|
|
{
|
2012-08-27 13:31:16 -04:00
|
|
|
if (a_Player.GetUniqueID() == m_Player->GetUniqueID())
|
|
|
|
{
|
|
|
|
// Do NOT send this packet to myself
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
LOGD("Spawning player \"%s\" on client \"%s\" @ %s",
|
2012-09-23 12:25:32 -04:00
|
|
|
a_Player.GetName().c_str(), GetPlayer()->GetName().c_str(), GetIPString().c_str()
|
|
|
|
);
|
|
|
|
|
2012-08-27 13:31:16 -04:00
|
|
|
m_Protocol->SendPlayerSpawn(a_Player);
|
2012-08-24 03:58:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-09 05:39:42 -05:00
|
|
|
void cClientHandle::SendPluginMessage(const AString & a_Channel, const AString & a_Message)
|
|
|
|
{
|
|
|
|
m_Protocol->SendPluginMessage(a_Channel, a_Message);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-14 12:19:56 -05:00
|
|
|
void cClientHandle::SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID)
|
|
|
|
{
|
|
|
|
m_Protocol->SendRemoveEntityEffect(a_Entity, a_EffectID);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-18 15:12:27 -04:00
|
|
|
void cClientHandle::SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks)
|
2012-08-24 03:58:26 -04:00
|
|
|
{
|
2014-07-18 15:12:27 -04:00
|
|
|
m_Protocol->SendRespawn(a_Dimension, a_ShouldIgnoreDimensionChecks);
|
2012-08-24 03:58:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-15 10:23:50 -05:00
|
|
|
void cClientHandle::SendExperience(void)
|
2013-11-15 06:42:09 -05:00
|
|
|
{
|
2013-11-15 10:23:50 -05:00
|
|
|
m_Protocol->SendExperience();
|
2013-11-15 06:42:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-25 15:43:43 -05:00
|
|
|
void cClientHandle::SendExperienceOrb(const cExpOrb & a_ExpOrb)
|
2013-11-25 14:04:39 -05:00
|
|
|
{
|
2013-11-25 15:43:43 -05:00
|
|
|
m_Protocol->SendExperienceOrb(a_ExpOrb);
|
2013-11-25 14:04:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-21 08:58:17 -05:00
|
|
|
void cClientHandle::SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode)
|
|
|
|
{
|
|
|
|
m_Protocol->SendScoreboardObjective(a_Name, a_DisplayName, a_Mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cClientHandle::SendScoreUpdate(const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode)
|
|
|
|
{
|
|
|
|
m_Protocol->SendScoreUpdate(a_Objective, a_Player, a_Score, a_Mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cClientHandle::SendDisplayObjective(const AString & a_Objective, cScoreboard::eDisplaySlot a_Display)
|
|
|
|
{
|
|
|
|
m_Protocol->SendDisplayObjective(a_Objective, a_Display);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-12 20:08:02 -04:00
|
|
|
void cClientHandle::SendSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch)
|
2012-12-26 04:12:00 -05:00
|
|
|
{
|
2014-07-12 20:08:02 -04:00
|
|
|
m_Protocol->SendSoundEffect(a_SoundName, a_X, a_Y, a_Z, a_Volume, a_Pitch);
|
2012-12-26 04:12:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data)
|
2012-08-24 03:58:26 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendSoundParticleEffect(a_EffectID, a_SrcX, a_SrcY, a_SrcZ, a_Data);
|
2012-08-24 03:58:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock)
|
2012-08-24 03:58:26 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendSpawnFallingBlock(a_FallingBlock);
|
2012-08-24 03:58:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendSpawnMob(const cMonster & a_Mob)
|
2012-08-24 05:49:00 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendSpawnMob(a_Mob);
|
2012-08-24 05:49:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch)
|
2012-08-25 13:52:08 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendSpawnObject(a_Entity, a_ObjectType, a_ObjectData, a_Yaw, a_Pitch);
|
2012-08-25 13:52:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 13:13:23 -04:00
|
|
|
void cClientHandle::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) // VehicleSubType is specific to Minecarts
|
2012-08-25 13:52:08 -04:00
|
|
|
{
|
2013-08-29 08:47:22 -04:00
|
|
|
m_Protocol->SendSpawnVehicle(a_Vehicle, a_VehicleType, a_VehicleSubType);
|
2012-08-25 13:52:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-11 07:57:06 -04:00
|
|
|
void cClientHandle::SendStatistics(const cStatManager & a_Manager)
|
|
|
|
{
|
|
|
|
m_Protocol->SendStatistics(a_Manager);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-30 16:48:59 -04:00
|
|
|
void cClientHandle::SendTabCompletionResults(const AStringVector & a_Results)
|
|
|
|
{
|
|
|
|
m_Protocol->SendTabCompletionResults(a_Results);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendTeleportEntity(const cEntity & a_Entity)
|
2012-08-25 13:52:08 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendTeleportEntity(a_Entity);
|
2012-08-25 13:52:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ)
|
2012-08-25 17:46:18 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendThunderbolt(a_BlockX, a_BlockY, a_BlockZ);
|
2012-08-25 17:46:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-10 18:20:28 -04:00
|
|
|
void cClientHandle::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle)
|
2012-08-25 17:46:18 -04:00
|
|
|
{
|
2014-08-10 18:20:28 -04:00
|
|
|
m_Protocol->SendTimeUpdate(a_WorldAge, a_TimeOfDay, a_DoDaylightCycle);
|
2012-08-25 17:46:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendUnloadChunk(int a_ChunkX, int a_ChunkZ)
|
2012-08-25 17:46:18 -04:00
|
|
|
{
|
2014-10-16 15:12:26 -04:00
|
|
|
// Remove the chunk from the list of chunks sent to the client:
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSChunkLists);
|
|
|
|
m_SentChunks.remove(cChunkCoords(a_ChunkX, a_ChunkZ));
|
|
|
|
}
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendUnloadChunk(a_ChunkX, a_ChunkZ);
|
2012-08-25 17:46:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-19 14:42:25 -05:00
|
|
|
void cClientHandle::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity)
|
2014-01-18 19:54:38 -05:00
|
|
|
{
|
2014-01-19 14:42:25 -05:00
|
|
|
m_Protocol->SendUpdateBlockEntity(a_BlockEntity);
|
2014-01-18 19:54:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-25 17:46:18 -04:00
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendUpdateSign(
|
|
|
|
int a_BlockX, int a_BlockY, int a_BlockZ,
|
|
|
|
const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4
|
|
|
|
)
|
2012-09-11 08:01:34 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendUpdateSign(
|
|
|
|
a_BlockX, a_BlockY, a_BlockZ,
|
|
|
|
a_Line1, a_Line2, a_Line3, a_Line4
|
|
|
|
);
|
2012-09-11 08:01:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-21 09:19:48 -04:00
|
|
|
void cClientHandle::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ)
|
2012-10-21 03:46:28 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendUseBed(a_Entity, a_BlockX, a_BlockY, a_BlockZ);
|
2012-10-21 03:46:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-07 09:06:06 -04:00
|
|
|
void cClientHandle::SendWeather(eWeather a_Weather)
|
2012-09-25 05:54:36 -04:00
|
|
|
{
|
2013-07-07 09:06:06 -04:00
|
|
|
m_Protocol->SendWeather(a_Weather);
|
2012-09-25 05:54:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-18 07:26:37 -04:00
|
|
|
void cClientHandle::SendWholeInventory(const cWindow & a_Window)
|
2012-09-30 12:37:44 -04:00
|
|
|
{
|
2013-08-18 07:26:37 -04:00
|
|
|
m_Protocol->SendWholeInventory(a_Window);
|
2012-09-30 12:37:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-09-29 16:43:42 -04:00
|
|
|
|
2013-08-18 07:26:37 -04:00
|
|
|
void cClientHandle::SendWindowClose(const cWindow & a_Window)
|
2013-02-18 11:48:50 -05:00
|
|
|
{
|
2013-08-18 07:26:37 -04:00
|
|
|
m_Protocol->SendWindowClose(a_Window);
|
2013-02-18 11:48:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-08 15:32:14 -05:00
|
|
|
void cClientHandle::SendWindowOpen(const cWindow & a_Window)
|
2012-08-26 17:01:07 -04:00
|
|
|
{
|
2013-11-08 15:32:14 -05:00
|
|
|
m_Protocol->SendWindowOpen(a_Window);
|
2013-08-18 07:26:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-03 16:32:41 -04:00
|
|
|
void cClientHandle::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value)
|
2013-08-18 07:26:37 -04:00
|
|
|
{
|
|
|
|
m_Protocol->SendWindowProperty(a_Window, a_Property, a_Value);
|
2012-08-26 17:01:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
const AString & cClientHandle::GetUsername(void) const
|
|
|
|
{
|
|
|
|
return m_Username;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-21 09:19:48 -04:00
|
|
|
void cClientHandle::SetUsername( const AString & a_Username)
|
2012-10-18 17:54:56 -04:00
|
|
|
{
|
|
|
|
m_Username = a_Username;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
void cClientHandle::SetViewDistance(int a_ViewDistance)
|
|
|
|
{
|
2014-11-15 09:33:42 -05:00
|
|
|
m_RequestedViewDistance = a_ViewDistance;
|
2014-11-17 06:34:14 -05:00
|
|
|
LOGD("%s is requesting ViewDistance of %d!", GetUsername().c_str(), m_RequestedViewDistance);
|
|
|
|
|
|
|
|
// Set the current view distance based on the requested VD and world max VD:
|
|
|
|
cWorld * world = m_Player->GetWorld();
|
|
|
|
if (world != nullptr)
|
|
|
|
{
|
|
|
|
m_CurrentViewDistance = Clamp(a_ViewDistance, cClientHandle::MIN_VIEW_DISTANCE, world->GetMaxViewDistance());
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-20 17:24:39 -05:00
|
|
|
bool cClientHandle::HasPluginChannel(const AString & a_PluginChannel)
|
|
|
|
{
|
|
|
|
return (m_PluginChannels.find(a_PluginChannel) != m_PluginChannels.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-28 05:36:35 -04:00
|
|
|
bool cClientHandle::WantsSendChunk(int a_ChunkX, int a_ChunkZ)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-11-11 09:00:58 -05:00
|
|
|
if (m_State >= csDestroying)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
cCSLock Lock(m_CSChunkLists);
|
2014-08-28 05:36:35 -04:00
|
|
|
return (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), cChunkCoords(a_ChunkX, a_ChunkZ)) != m_ChunksToSend.end());
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cClientHandle::AddWantedChunk(int a_ChunkX, int a_ChunkZ)
|
|
|
|
{
|
2012-11-11 09:00:58 -05:00
|
|
|
if (m_State >= csDestroying)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
LOGD("Adding chunk [%d, %d] to wanted chunks for client %p", a_ChunkX, a_ChunkZ, this);
|
|
|
|
cCSLock Lock(m_CSChunkLists);
|
2014-08-28 05:36:35 -04:00
|
|
|
if (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), cChunkCoords(a_ChunkX, a_ChunkZ)) == m_ChunksToSend.end())
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-08-28 05:36:35 -04:00
|
|
|
m_ChunksToSend.push_back(cChunkCoords(a_ChunkX, a_ChunkZ));
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-27 13:31:16 -04:00
|
|
|
void cClientHandle::PacketBufferFull(void)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-27 13:31:16 -04:00
|
|
|
// Too much data in the incoming queue, the server is probably too busy, kick the client:
|
2012-09-25 04:23:19 -04:00
|
|
|
LOGERROR("Too much data in queue for client \"%s\" @ %s, kicking them.", m_Username.c_str(), m_IPString.c_str());
|
2012-08-27 13:31:16 -04:00
|
|
|
SendDisconnect("Server busy");
|
|
|
|
Destroy();
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
2012-08-27 13:31:16 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-12 17:05:23 -05:00
|
|
|
void cClientHandle::PacketUnknown(UInt32 a_PacketType)
|
2012-08-27 13:31:16 -04:00
|
|
|
{
|
2013-12-12 17:05:23 -05:00
|
|
|
LOGERROR("Unknown packet type 0x%x from client \"%s\" @ %s", a_PacketType, m_Username.c_str(), m_IPString.c_str());
|
2012-08-27 13:31:16 -04:00
|
|
|
|
|
|
|
AString Reason;
|
2013-12-12 17:05:23 -05:00
|
|
|
Printf(Reason, "Unknown [C->S] PacketType: 0x%x", a_PacketType);
|
2012-08-27 13:31:16 -04:00
|
|
|
SendDisconnect(Reason);
|
|
|
|
Destroy();
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-18 16:43:35 -05:00
|
|
|
void cClientHandle::PacketError(UInt32 a_PacketType)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-27 13:31:16 -04:00
|
|
|
LOGERROR("Protocol error while parsing packet type 0x%02x; disconnecting client \"%s\"", a_PacketType, m_Username.c_str());
|
|
|
|
SendDisconnect("Protocol error");
|
|
|
|
Destroy();
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
2012-08-27 13:31:16 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-24 14:17:00 -05:00
|
|
|
void cClientHandle::SocketClosed(void)
|
2012-08-27 13:31:16 -04:00
|
|
|
{
|
2015-01-24 14:17:00 -05:00
|
|
|
// The socket has been closed for any reason
|
|
|
|
|
|
|
|
if (!m_Username.empty()) // Ignore client pings
|
|
|
|
{
|
|
|
|
LOGD("Client %s @ %s disconnected", m_Username.c_str(), m_IPString.c_str());
|
|
|
|
cRoot::Get()->GetPluginManager()->CallHookDisconnect(*this, "Player disconnected");
|
|
|
|
}
|
|
|
|
|
|
|
|
Destroy();
|
2012-08-27 13:31:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-24 14:17:00 -05:00
|
|
|
void cClientHandle::SetSelf(cClientHandlePtr a_Self)
|
2012-08-27 13:31:16 -04:00
|
|
|
{
|
2015-01-24 14:17:00 -05:00
|
|
|
ASSERT(m_Self == nullptr);
|
|
|
|
m_Self = a_Self;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-24 14:17:00 -05:00
|
|
|
void cClientHandle::OnLinkCreated(cTCPLinkPtr a_Link)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2015-01-24 14:17:00 -05:00
|
|
|
m_Link = a_Link;
|
|
|
|
}
|
2013-12-18 13:17:17 -05:00
|
|
|
|
|
|
|
|
2015-01-24 14:17:00 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cClientHandle::OnReceivedData(const char * a_Data, size_t a_Length)
|
|
|
|
{
|
|
|
|
// Reset the timeout:
|
|
|
|
m_TicksSinceLastPacket = 0;
|
|
|
|
|
|
|
|
// Queue the incoming data to be processed in the tick thread:
|
|
|
|
cCSLock Lock(m_CSIncomingData);
|
|
|
|
m_IncomingData.append(a_Data, a_Length);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 16:06:25 -04:00
|
|
|
|
2015-01-24 14:17:00 -05:00
|
|
|
void cClientHandle::OnRemoteClosed(void)
|
2014-04-16 08:33:03 -04:00
|
|
|
{
|
2014-08-28 08:58:03 -04:00
|
|
|
{
|
2015-01-24 14:17:00 -05:00
|
|
|
cCSLock Lock(m_CSOutgoingData);
|
|
|
|
m_Link.reset();
|
2014-08-28 08:58:03 -04:00
|
|
|
}
|
2015-01-24 14:17:00 -05:00
|
|
|
SocketClosed();
|
|
|
|
}
|
2014-08-28 08:58:03 -04:00
|
|
|
|
2014-04-16 08:33:03 -04:00
|
|
|
|
|
|
|
|
2015-01-24 14:17:00 -05:00
|
|
|
|
|
|
|
|
|
|
|
void cClientHandle::OnError(int a_ErrorCode, const AString & a_ErrorMsg)
|
|
|
|
{
|
|
|
|
LOGD("An error has occurred on client link for %s @ %s: %d (%s). Client disconnected.",
|
|
|
|
m_Username.c_str(), m_IPString.c_str(), a_ErrorCode, a_ErrorMsg.c_str()
|
|
|
|
);
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CSOutgoingData);
|
|
|
|
m_Link.reset();
|
2014-04-16 08:33:03 -04:00
|
|
|
}
|
2015-01-24 14:17:00 -05:00
|
|
|
SocketClosed();
|
2014-04-16 08:33:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|