1
0

Merge branch 'master' into HTTPSizeT

This commit is contained in:
madmaxoft 2014-04-04 13:29:48 +02:00
commit d77ca77086
39 changed files with 368 additions and 590 deletions

View File

@ -777,14 +777,14 @@ end</pre>
GetMass = { Params = "", Return = "number", Notes = "Returns the mass of the entity. Currently unused." }, GetMass = { Params = "", Return = "number", Notes = "Returns the mass of the entity. Currently unused." },
GetMaxHealth = { Params = "", Return = "number", Notes = "Returns the maximum number of hitpoints this entity is allowed to have." }, GetMaxHealth = { Params = "", Return = "number", Notes = "Returns the maximum number of hitpoints this entity is allowed to have." },
GetParentClass = { Params = "", Return = "string", Notes = "Returns the name of the direct parent class for this entity" }, GetParentClass = { Params = "", Return = "string", Notes = "Returns the name of the direct parent class for this entity" },
GetPitch = { Params = "", Return = "number", Notes = "Returns the pitch (nose-down rotation) of the entity" }, GetPitch = { Params = "", Return = "number", Notes = "Returns the pitch (nose-down rotation) of the entity. Measured in degrees, normal values range from -90 to +90. +90 means looking down, 0 means looking straight ahead, -90 means looking up." },
GetPosition = { Params = "", Return = "{{Vector3d}}", Notes = "Returns the entity's pivot position as a 3D vector" }, GetPosition = { Params = "", Return = "{{Vector3d}}", Notes = "Returns the entity's pivot position as a 3D vector" },
GetPosX = { Params = "", Return = "number", Notes = "Returns the X-coord of the entity's pivot" }, GetPosX = { Params = "", Return = "number", Notes = "Returns the X-coord of the entity's pivot" },
GetPosY = { Params = "", Return = "number", Notes = "Returns the Y-coord of the entity's pivot" }, GetPosY = { Params = "", Return = "number", Notes = "Returns the Y-coord of the entity's pivot" },
GetPosZ = { Params = "", Return = "number", Notes = "Returns the Z-coord of the entity's pivot" }, GetPosZ = { Params = "", Return = "number", Notes = "Returns the Z-coord of the entity's pivot" },
GetRawDamageAgainst = { Params = "ReceiverEntity", Return = "number", Notes = "Returns the raw damage that this entity's equipment would cause when attacking the ReceiverEntity. This includes this entity's weapon {{cEnchantments|enchantments}}, but excludes the receiver's armor or potion effects. See {{TakeDamageInfo}} for more information on attack damage." }, GetRawDamageAgainst = { Params = "ReceiverEntity", Return = "number", Notes = "Returns the raw damage that this entity's equipment would cause when attacking the ReceiverEntity. This includes this entity's weapon {{cEnchantments|enchantments}}, but excludes the receiver's armor or potion effects. See {{TakeDamageInfo}} for more information on attack damage." },
GetRoll = { Params = "", Return = "number", Notes = "Returns the roll (sideways rotation) of the entity. Currently unused." }, GetRoll = { Params = "", Return = "number", Notes = "Returns the roll (sideways rotation) of the entity. Currently unused." },
GetRot = { Params = "", Return = "{{Vector3f}}", Notes = "Returns the entire rotation vector (Yaw, Pitch, Roll)" }, GetRot = { Params = "", Return = "{{Vector3f}}", Notes = "(OBSOLETE) Returns the entire rotation vector (Yaw, Pitch, Roll)" },
GetSpeed = { Params = "", Return = "{{Vector3d}}", Notes = "Returns the complete speed vector of the entity" }, GetSpeed = { Params = "", Return = "{{Vector3d}}", Notes = "Returns the complete speed vector of the entity" },
GetSpeedX = { Params = "", Return = "number", Notes = "Returns the X-part of the speed vector" }, GetSpeedX = { Params = "", Return = "number", Notes = "Returns the X-part of the speed vector" },
GetSpeedY = { Params = "", Return = "number", Notes = "Returns the Y-part of the speed vector" }, GetSpeedY = { Params = "", Return = "number", Notes = "Returns the Y-part of the speed vector" },
@ -792,7 +792,7 @@ end</pre>
GetUniqueID = { Params = "", Return = "number", Notes = "Returns the ID that uniquely identifies the entity within the running server. Note that this ID is not persisted to the data files." }, GetUniqueID = { Params = "", Return = "number", Notes = "Returns the ID that uniquely identifies the entity within the running server. Note that this ID is not persisted to the data files." },
GetWidth = { Params = "", Return = "number", Notes = "Returns the width (X and Z size) of the entity." }, GetWidth = { Params = "", Return = "number", Notes = "Returns the width (X and Z size) of the entity." },
GetWorld = { Params = "", Return = "{{cWorld}}", Notes = "Returns the world where the entity resides" }, GetWorld = { Params = "", Return = "{{cWorld}}", Notes = "Returns the world where the entity resides" },
GetYaw = { Params = "", Return = "number", Notes = "Returns the yaw (direction) of the entity." }, GetYaw = { Params = "", Return = "number", Notes = "Returns the yaw (direction) of the entity. Measured in degrees, values range from -180 to +180. 0 means ZP, 90 means XM, -180 means ZM, -90 means XP." },
Heal = { Params = "Hitpoints", Return = "", Notes = "Heals the specified number of hitpoints. Hitpoints is expected to be a positive number." }, Heal = { Params = "Hitpoints", Return = "", Notes = "Heals the specified number of hitpoints. Hitpoints is expected to be a positive number." },
IsA = { Params = "ClassName", Return = "bool", Notes = "Returns true if the entity class is a descendant of the specified class name, or the specified class itself" }, IsA = { Params = "ClassName", Return = "bool", Notes = "Returns true if the entity class is a descendant of the specified class name, or the specified class itself" },
IsBoat = { Params = "", Return = "bool", Notes = "Returns true if the entity is a {{cBoat|boat}}." }, IsBoat = { Params = "", Return = "bool", Notes = "Returns true if the entity is a {{cBoat|boat}}." },

View File

@ -387,6 +387,8 @@ bool cConnection::RelayFromServer(void)
return CLIENTSEND(Buffer, res); return CLIENTSEND(Buffer, res);
} }
} }
ASSERT(!"Unhandled server state while relaying from server");
return false;
} }
@ -423,6 +425,8 @@ bool cConnection::RelayFromClient(void)
return SERVERSEND(Buffer, res); return SERVERSEND(Buffer, res);
} }
} }
ASSERT(!"Unhandled server state while relaying from client");
return false;
} }
@ -438,11 +442,11 @@ double cConnection::GetRelativeTime(void)
bool cConnection::SendData(SOCKET a_Socket, const char * a_Data, int a_Size, const char * a_Peer) bool cConnection::SendData(SOCKET a_Socket, const char * a_Data, size_t a_Size, const char * a_Peer)
{ {
DataLog(a_Data, a_Size, "Sending data to %s, %d bytes", a_Peer, a_Size); DataLog(a_Data, a_Size, "Sending data to %s, %u bytes", a_Peer, (unsigned)a_Size);
int res = send(a_Socket, a_Data, a_Size, 0); int res = send(a_Socket, a_Data, (int)a_Size, 0);
if (res <= 0) if (res <= 0)
{ {
Log("%s closed the socket: %d, %d; aborting connection", a_Peer, res, SocketError); Log("%s closed the socket: %d, %d; aborting connection", a_Peer, res, SocketError);

View File

@ -103,7 +103,7 @@ protected:
double GetRelativeTime(void); double GetRelativeTime(void);
/// Sends data to the specified socket. If sending fails, prints a fail message using a_Peer and returns false. /// Sends data to the specified socket. If sending fails, prints a fail message using a_Peer and returns false.
bool SendData(SOCKET a_Socket, const char * a_Data, int a_Size, const char * a_Peer); bool SendData(SOCKET a_Socket, const char * a_Data, size_t a_Size, const char * a_Peer);
/// Sends data to the specified socket. If sending fails, prints a fail message using a_Peer and returns false. /// Sends data to the specified socket. If sending fails, prints a fail message using a_Peer and returns false.
bool SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a_Peer); bool SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a_Peer);

View File

@ -21,20 +21,22 @@
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockLightValue #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockLightValue
static int tolua_get_AllToLua_g_BlockLightValue(lua_State* tolua_S) static int tolua_get_AllToLua_g_BlockLightValue(lua_State* tolua_S)
{ {
int tolua_index; int BlockType;
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
{ {
tolua_Error tolua_err; tolua_Error tolua_err;
if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
{
tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
}
} }
#endif #endif
tolua_index = (int)tolua_tonumber(tolua_S,2,0); BlockType = (int)tolua_tonumber(tolua_S, 2, 0);
#ifndef TOLUA_RELEASE if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID))
if (tolua_index<0) {
tolua_error(tolua_S,"array indexing out of range.",NULL); tolua_error(tolua_S, "array indexing out of range.", NULL);
#endif }
tolua_pushnumber(tolua_S,(lua_Number)cBlockInfo::GetLightValue(tolua_index)); tolua_pushnumber(tolua_S,(lua_Number)cBlockInfo::GetLightValue((BLOCKTYPE)BlockType));
return 1; return 1;
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
@ -43,37 +45,11 @@ static int tolua_get_AllToLua_g_BlockLightValue(lua_State* tolua_S)
/* set function: g_BlockLightValue */
#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockLightValue
static int tolua_set_AllToLua_g_BlockLightValue(lua_State* tolua_S)
{
int tolua_index;
#ifndef TOLUA_RELEASE
{
tolua_Error tolua_err;
if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
}
#endif
tolua_index = (int)tolua_tonumber(tolua_S,2,0);
#ifndef TOLUA_RELEASE
if (tolua_index<0)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
cBlockInfo::Get(tolua_index).m_LightValue = ((unsigned char) tolua_tonumber(tolua_S,3,0));
return 0;
}
#endif //#ifndef TOLUA_DISABLE
/* get function: g_BlockSpreadLightFalloff */ /* get function: g_BlockSpreadLightFalloff */
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockSpreadLightFalloff #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockSpreadLightFalloff
static int tolua_get_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S) static int tolua_get_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S)
{ {
int tolua_index; int BlockType;
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
{ {
tolua_Error tolua_err; tolua_Error tolua_err;
@ -81,12 +57,12 @@ static int tolua_get_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S)
tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
} }
#endif #endif
tolua_index = (int)tolua_tonumber(tolua_S,2,0); BlockType = (int)tolua_tonumber(tolua_S, 2, 0);
#ifndef TOLUA_RELEASE if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID))
if (tolua_index<0) {
tolua_error(tolua_S,"array indexing out of range.",NULL); tolua_error(tolua_S, "array indexing out of range.", NULL);
#endif }
tolua_pushnumber(tolua_S,(lua_Number)cBlockInfo::GetSpreadLightFalloff(tolua_index)); tolua_pushnumber(tolua_S, (lua_Number)cBlockInfo::GetSpreadLightFalloff((BLOCKTYPE)BlockType));
return 1; return 1;
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
@ -95,37 +71,11 @@ static int tolua_get_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S)
/* set function: g_BlockSpreadLightFalloff */
#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockSpreadLightFalloff
static int tolua_set_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S)
{
int tolua_index;
#ifndef TOLUA_RELEASE
{
tolua_Error tolua_err;
if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
}
#endif
tolua_index = (int)tolua_tonumber(tolua_S,2,0);
#ifndef TOLUA_RELEASE
if (tolua_index<0)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
cBlockInfo::Get(tolua_index).m_SpreadLightFalloff = ((unsigned char) tolua_tonumber(tolua_S,3,0));
return 0;
}
#endif //#ifndef TOLUA_DISABLE
/* get function: g_BlockTransparent */ /* get function: g_BlockTransparent */
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockTransparent #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockTransparent
static int tolua_get_AllToLua_g_BlockTransparent(lua_State* tolua_S) static int tolua_get_AllToLua_g_BlockTransparent(lua_State* tolua_S)
{ {
int tolua_index; int BlockType;
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
{ {
tolua_Error tolua_err; tolua_Error tolua_err;
@ -133,12 +83,12 @@ static int tolua_get_AllToLua_g_BlockTransparent(lua_State* tolua_S)
tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
} }
#endif #endif
tolua_index = (int)tolua_tonumber(tolua_S,2,0); BlockType = (int)tolua_tonumber(tolua_S, 2, 0);
#ifndef TOLUA_RELEASE if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID))
if (tolua_index<0) {
tolua_error(tolua_S,"array indexing out of range.",NULL); tolua_error(tolua_S, "array indexing out of range.", NULL);
#endif }
tolua_pushboolean(tolua_S, cBlockInfo::IsTransparent(tolua_index)); tolua_pushboolean(tolua_S, cBlockInfo::IsTransparent((BLOCKTYPE)BlockType));
return 1; return 1;
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
@ -147,37 +97,11 @@ static int tolua_get_AllToLua_g_BlockTransparent(lua_State* tolua_S)
/* set function: g_BlockTransparent */
#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockTransparent
static int tolua_set_AllToLua_g_BlockTransparent(lua_State* tolua_S)
{
int tolua_index;
#ifndef TOLUA_RELEASE
{
tolua_Error tolua_err;
if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
}
#endif
tolua_index = (int)tolua_tonumber(tolua_S,2,0);
#ifndef TOLUA_RELEASE
if (tolua_index<0)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
cBlockInfo::Get(tolua_index).m_Transparent = (tolua_toboolean(tolua_S,3,0) != 0);
return 0;
}
#endif //#ifndef TOLUA_DISABLE
/* get function: g_BlockOneHitDig */ /* get function: g_BlockOneHitDig */
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockOneHitDig #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockOneHitDig
static int tolua_get_AllToLua_g_BlockOneHitDig(lua_State* tolua_S) static int tolua_get_AllToLua_g_BlockOneHitDig(lua_State* tolua_S)
{ {
int tolua_index; int BlockType;
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
{ {
tolua_Error tolua_err; tolua_Error tolua_err;
@ -185,12 +109,12 @@ static int tolua_get_AllToLua_g_BlockOneHitDig(lua_State* tolua_S)
tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
} }
#endif #endif
tolua_index = (int)tolua_tonumber(tolua_S,2,0); BlockType = (int)tolua_tonumber(tolua_S, 2, 0);
#ifndef TOLUA_RELEASE if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID))
if (tolua_index<0) {
tolua_error(tolua_S,"array indexing out of range.",NULL); tolua_error(tolua_S, "array indexing out of range.", NULL);
#endif }
tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsOneHitDig(tolua_index)); tolua_pushboolean(tolua_S, cBlockInfo::IsOneHitDig((BLOCKTYPE)BlockType));
return 1; return 1;
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
@ -199,37 +123,11 @@ static int tolua_get_AllToLua_g_BlockOneHitDig(lua_State* tolua_S)
/* set function: g_BlockOneHitDig */
#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockOneHitDig
static int tolua_set_AllToLua_g_BlockOneHitDig(lua_State* tolua_S)
{
int tolua_index;
#ifndef TOLUA_RELEASE
{
tolua_Error tolua_err;
if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
}
#endif
tolua_index = (int)tolua_tonumber(tolua_S,2,0);
#ifndef TOLUA_RELEASE
if (tolua_index<0)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
cBlockInfo::Get(tolua_index).m_OneHitDig = (tolua_toboolean(tolua_S,3,0) != 0);
return 0;
}
#endif //#ifndef TOLUA_DISABLE
/* get function: g_BlockPistonBreakable */ /* get function: g_BlockPistonBreakable */
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockPistonBreakable #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockPistonBreakable
static int tolua_get_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S) static int tolua_get_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S)
{ {
int tolua_index; int BlockType;
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
{ {
tolua_Error tolua_err; tolua_Error tolua_err;
@ -237,12 +135,12 @@ static int tolua_get_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S)
tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
} }
#endif #endif
tolua_index = (int)tolua_tonumber(tolua_S,2,0); BlockType = (int)tolua_tonumber(tolua_S, 2, 0);
#ifndef TOLUA_RELEASE if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID))
if (tolua_index<0 || tolua_index>=256) {
tolua_error(tolua_S,"array indexing out of range.",NULL); tolua_error(tolua_S, "array indexing out of range.", NULL);
#endif }
tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsPistonBreakable(tolua_index)); tolua_pushboolean(tolua_S, cBlockInfo::IsPistonBreakable((BLOCKTYPE)BlockType));
return 1; return 1;
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
@ -251,37 +149,11 @@ static int tolua_get_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S)
/* set function: g_BlockPistonBreakable */
#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockPistonBreakable
static int tolua_set_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S)
{
int tolua_index;
#ifndef TOLUA_RELEASE
{
tolua_Error tolua_err;
if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
}
#endif
tolua_index = (int)tolua_tonumber(tolua_S,2,0);
#ifndef TOLUA_RELEASE
if (tolua_index<0 || tolua_index>=256)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
cBlockInfo::Get(tolua_index).m_PistonBreakable = (tolua_toboolean(tolua_S,3,0) != 0);
return 0;
}
#endif //#ifndef TOLUA_DISABLE
/* get function: g_BlockIsSnowable */ /* get function: g_BlockIsSnowable */
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockIsSnowable #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockIsSnowable
static int tolua_get_AllToLua_g_BlockIsSnowable(lua_State* tolua_S) static int tolua_get_AllToLua_g_BlockIsSnowable(lua_State* tolua_S)
{ {
int tolua_index; int BlockType;
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
{ {
tolua_Error tolua_err; tolua_Error tolua_err;
@ -289,12 +161,12 @@ static int tolua_get_AllToLua_g_BlockIsSnowable(lua_State* tolua_S)
tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
} }
#endif #endif
tolua_index = (int)tolua_tonumber(tolua_S,2,0); BlockType = (int)tolua_tonumber(tolua_S, 2, 0);
#ifndef TOLUA_RELEASE if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID))
if (tolua_index<0 || tolua_index>=256) {
tolua_error(tolua_S,"array indexing out of range.",NULL); tolua_error(tolua_S, "array indexing out of range.", NULL);
#endif }
tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsSnowable(tolua_index)); tolua_pushboolean(tolua_S, cBlockInfo::IsSnowable((BLOCKTYPE)BlockType));
return 1; return 1;
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
@ -303,37 +175,11 @@ static int tolua_get_AllToLua_g_BlockIsSnowable(lua_State* tolua_S)
/* set function: g_BlockIsSnowable */
#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockIsSnowable
static int tolua_set_AllToLua_g_BlockIsSnowable(lua_State* tolua_S)
{
int tolua_index;
#ifndef TOLUA_RELEASE
{
tolua_Error tolua_err;
if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
}
#endif
tolua_index = (int)tolua_tonumber(tolua_S,2,0);
#ifndef TOLUA_RELEASE
if (tolua_index<0 || tolua_index>=256)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
cBlockInfo::Get(tolua_index).m_IsSnowable = (tolua_toboolean(tolua_S,3,0) != 0);
return 0;
}
#endif //#ifndef TOLUA_DISABLE
/* get function: g_BlockRequiresSpecialTool */ /* get function: g_BlockRequiresSpecialTool */
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockRequiresSpecialTool #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockRequiresSpecialTool
static int tolua_get_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S) static int tolua_get_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S)
{ {
int tolua_index; int BlockType;
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
{ {
tolua_Error tolua_err; tolua_Error tolua_err;
@ -341,12 +187,12 @@ static int tolua_get_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S)
tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
} }
#endif #endif
tolua_index = (int)tolua_tonumber(tolua_S,2,0); BlockType = (int)tolua_tonumber(tolua_S, 2, 0);
#ifndef TOLUA_RELEASE if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID))
if (tolua_index<0 || tolua_index>=256) {
tolua_error(tolua_S,"array indexing out of range.",NULL); tolua_error(tolua_S, "array indexing out of range.", NULL);
#endif }
tolua_pushboolean(tolua_S,(bool)cBlockInfo::RequiresSpecialTool(tolua_index)); tolua_pushboolean(tolua_S, cBlockInfo::RequiresSpecialTool((BLOCKTYPE)BlockType));
return 1; return 1;
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
@ -355,37 +201,11 @@ static int tolua_get_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S)
/* set function: g_BlockRequiresSpecialTool */
#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockRequiresSpecialTool
static int tolua_set_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S)
{
int tolua_index;
#ifndef TOLUA_RELEASE
{
tolua_Error tolua_err;
if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
}
#endif
tolua_index = (int)tolua_tonumber(tolua_S,2,0);
#ifndef TOLUA_RELEASE
if (tolua_index<0 || tolua_index>=256)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
cBlockInfo::Get(tolua_index).m_RequiresSpecialTool = (tolua_toboolean(tolua_S,3,0) != 0);
return 0;
}
#endif //#ifndef TOLUA_DISABLE
/* get function: g_BlockIsSolid */ /* get function: g_BlockIsSolid */
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockIsSolid #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockIsSolid
static int tolua_get_AllToLua_g_BlockIsSolid(lua_State* tolua_S) static int tolua_get_AllToLua_g_BlockIsSolid(lua_State* tolua_S)
{ {
int tolua_index; int BlockType;
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
{ {
tolua_Error tolua_err; tolua_Error tolua_err;
@ -393,12 +213,12 @@ static int tolua_get_AllToLua_g_BlockIsSolid(lua_State* tolua_S)
tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
} }
#endif #endif
tolua_index = (int)tolua_tonumber(tolua_S,2,0); BlockType = (int)tolua_tonumber(tolua_S, 2, 0);
#ifndef TOLUA_RELEASE if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID))
if (tolua_index<0 || tolua_index>=256) {
tolua_error(tolua_S,"array indexing out of range.",NULL); tolua_error(tolua_S, "array indexing out of range.", NULL);
#endif }
tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsSolid(tolua_index)); tolua_pushboolean(tolua_S, (bool)cBlockInfo::IsSolid((BLOCKTYPE)BlockType));
return 1; return 1;
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
@ -407,37 +227,11 @@ static int tolua_get_AllToLua_g_BlockIsSolid(lua_State* tolua_S)
/* set function: g_BlockIsSolid */
#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockIsSolid
static int tolua_set_AllToLua_g_BlockIsSolid(lua_State* tolua_S)
{
int tolua_index;
#ifndef TOLUA_RELEASE
{
tolua_Error tolua_err;
if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
}
#endif
tolua_index = (int)tolua_tonumber(tolua_S,2,0);
#ifndef TOLUA_RELEASE
if (tolua_index<0 || tolua_index>=256)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
cBlockInfo::Get(tolua_index).m_IsSolid = (tolua_toboolean(tolua_S,3,0) != 0);
return 0;
}
#endif //#ifndef TOLUA_DISABLE
/* get function: g_BlockFullyOccupiesVoxel */ /* get function: g_BlockFullyOccupiesVoxel */
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockFullyOccupiesVoxel #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockFullyOccupiesVoxel
static int tolua_get_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S) static int tolua_get_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S)
{ {
int tolua_index; int BlockType;
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
{ {
tolua_Error tolua_err; tolua_Error tolua_err;
@ -445,12 +239,12 @@ static int tolua_get_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S)
tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
} }
#endif #endif
tolua_index = (int)tolua_tonumber(tolua_S,2,0); BlockType = (int)tolua_tonumber(tolua_S, 2, 0);
#ifndef TOLUA_RELEASE if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID))
if (tolua_index<0 || tolua_index>=256) {
tolua_error(tolua_S,"array indexing out of range.",NULL); tolua_error(tolua_S, "array indexing out of range.", NULL);
#endif }
tolua_pushboolean(tolua_S,(bool)cBlockInfo::FullyOccupiesVoxel(tolua_index)); tolua_pushboolean(tolua_S, (bool)cBlockInfo::FullyOccupiesVoxel((BLOCKTYPE)BlockType));
return 1; return 1;
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
@ -459,45 +253,19 @@ static int tolua_get_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S)
/* set function: g_BlockFullyOccupiesVoxel */
#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockFullyOccupiesVoxel
static int tolua_set_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S)
{
int tolua_index;
#ifndef TOLUA_RELEASE
{
tolua_Error tolua_err;
if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
}
#endif
tolua_index = (int)tolua_tonumber(tolua_S,2,0);
#ifndef TOLUA_RELEASE
if (tolua_index<0 || tolua_index>=256)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
cBlockInfo::Get(tolua_index).m_FullyOccupiesVoxel = (tolua_toboolean(tolua_S,3,0) != 0);
return 0;
}
#endif //#ifndef TOLUA_DISABLE
void DeprecatedBindings::Bind(lua_State * tolua_S) void DeprecatedBindings::Bind(lua_State * tolua_S)
{ {
tolua_beginmodule(tolua_S, NULL); tolua_beginmodule(tolua_S, NULL);
tolua_array(tolua_S, "g_BlockLightValue", tolua_get_AllToLua_g_BlockLightValue, tolua_set_AllToLua_g_BlockLightValue); tolua_array(tolua_S, "g_BlockLightValue", tolua_get_AllToLua_g_BlockLightValue, NULL);
tolua_array(tolua_S, "g_BlockSpreadLightFalloff", tolua_get_AllToLua_g_BlockSpreadLightFalloff, tolua_set_AllToLua_g_BlockSpreadLightFalloff); tolua_array(tolua_S, "g_BlockSpreadLightFalloff", tolua_get_AllToLua_g_BlockSpreadLightFalloff, NULL);
tolua_array(tolua_S, "g_BlockTransparent", tolua_get_AllToLua_g_BlockTransparent, tolua_set_AllToLua_g_BlockTransparent); tolua_array(tolua_S, "g_BlockTransparent", tolua_get_AllToLua_g_BlockTransparent, NULL);
tolua_array(tolua_S, "g_BlockOneHitDig", tolua_get_AllToLua_g_BlockOneHitDig, tolua_set_AllToLua_g_BlockOneHitDig); tolua_array(tolua_S, "g_BlockOneHitDig", tolua_get_AllToLua_g_BlockOneHitDig, NULL);
tolua_array(tolua_S, "g_BlockPistonBreakable", tolua_get_AllToLua_g_BlockPistonBreakable, tolua_set_AllToLua_g_BlockPistonBreakable); tolua_array(tolua_S, "g_BlockPistonBreakable", tolua_get_AllToLua_g_BlockPistonBreakable, NULL);
tolua_array(tolua_S, "g_BlockIsSnowable", tolua_get_AllToLua_g_BlockIsSnowable, tolua_set_AllToLua_g_BlockIsSnowable); tolua_array(tolua_S, "g_BlockIsSnowable", tolua_get_AllToLua_g_BlockIsSnowable, NULL);
tolua_array(tolua_S, "g_BlockRequiresSpecialTool", tolua_get_AllToLua_g_BlockRequiresSpecialTool, tolua_set_AllToLua_g_BlockRequiresSpecialTool); tolua_array(tolua_S, "g_BlockRequiresSpecialTool", tolua_get_AllToLua_g_BlockRequiresSpecialTool, NULL);
tolua_array(tolua_S, "g_BlockIsSolid", tolua_get_AllToLua_g_BlockIsSolid, tolua_set_AllToLua_g_BlockIsSolid); tolua_array(tolua_S, "g_BlockIsSolid", tolua_get_AllToLua_g_BlockIsSolid, NULL);
tolua_array(tolua_S, "g_BlockFullyOccupiesVoxel", tolua_get_AllToLua_g_BlockFullyOccupiesVoxel, tolua_set_AllToLua_g_BlockFullyOccupiesVoxel); tolua_array(tolua_S, "g_BlockFullyOccupiesVoxel", tolua_get_AllToLua_g_BlockFullyOccupiesVoxel, NULL);
tolua_endmodule(tolua_S); tolua_endmodule(tolua_S);
} }

View File

@ -530,7 +530,7 @@ void cBlockArea::DumpToRawFile(const AString & a_FileName)
f.Write(&SizeX, 4); f.Write(&SizeX, 4);
f.Write(&SizeY, 4); f.Write(&SizeY, 4);
f.Write(&SizeZ, 4); f.Write(&SizeZ, 4);
unsigned char DataTypes = GetDataTypes(); unsigned char DataTypes = (unsigned char)GetDataTypes();
f.Write(&DataTypes, 1); f.Write(&DataTypes, 1);
int NumBlocks = GetBlockCount(); int NumBlocks = GetBlockCount();
if (HasBlockTypes()) if (HasBlockTypes())

View File

@ -160,7 +160,7 @@ bool cCommandBlockEntity::LoadFromJson(const Json::Value & a_Value)
m_Command = a_Value.get("Command", "").asString(); m_Command = a_Value.get("Command", "").asString();
m_LastOutput = a_Value.get("LastOutput", "").asString(); m_LastOutput = a_Value.get("LastOutput", "").asString();
m_Result = a_Value.get("SuccessCount", 0).asInt(); m_Result = (NIBBLETYPE)a_Value.get("SuccessCount", 0).asInt();
return true; return true;
} }

View File

@ -93,6 +93,7 @@ public:
// Check if it's fuel: // Check if it's fuel:
BLOCKTYPE BlockType; BLOCKTYPE BlockType;
if ( if (
((a_RelY + y < 0) || (a_RelY + y > cChunkDef::Height)) ||
!a_Chunk.UnboundedRelGetBlockType(a_RelX + x, a_RelY + y, a_RelZ + z, BlockType) || !a_Chunk.UnboundedRelGetBlockType(a_RelX + x, a_RelY + y, a_RelZ + z, BlockType) ||
!cFireSimulator::IsFuel(BlockType) !cFireSimulator::IsFuel(BlockType)
) )
@ -119,6 +120,7 @@ public:
for (size_t i = 0; i < ARRAYCOUNT(CrossCoords); i++) for (size_t i = 0; i < ARRAYCOUNT(CrossCoords); i++)
{ {
if ( if (
((RelY + CrossCoords[i].y >= 0) && (RelY + CrossCoords[i].y <= cChunkDef::Height)) &&
a_Chunk.UnboundedRelGetBlockType(RelX + CrossCoords[i].x, RelY + CrossCoords[i].y, RelZ + CrossCoords[i].z, BlockType) && a_Chunk.UnboundedRelGetBlockType(RelX + CrossCoords[i].x, RelY + CrossCoords[i].y, RelZ + CrossCoords[i].z, BlockType) &&
(BlockType == E_BLOCK_AIR) (BlockType == E_BLOCK_AIR)
) )

View File

@ -31,7 +31,7 @@ public:
} }
static char RotationToMetaData(double a_Rotation) static NIBBLETYPE RotationToMetaData(double a_Rotation)
{ {
a_Rotation += 180 + (180 / 16); // So it's not aligned with axis a_Rotation += 180 + (180 / 16); // So it's not aligned with axis
if (a_Rotation > 360) if (a_Rotation > 360)
@ -45,7 +45,7 @@ public:
} }
static char DirectionToMetaData(eBlockFace a_Direction) static NIBBLETYPE DirectionToMetaData(eBlockFace a_Direction)
{ {
switch (a_Direction) switch (a_Direction)
{ {

View File

@ -11,6 +11,7 @@
#include "BlockHandler.h" #include "BlockHandler.h"
#include "../Items/ItemHandler.h" #include "../Items/ItemHandler.h"
#include "Root.h"
@ -38,41 +39,9 @@ public:
) override ) override
{ {
a_BlockType = m_BlockType; a_BlockType = m_BlockType;
BLOCKTYPE Type = (BLOCKTYPE) (a_Player->GetEquippedItem().m_ItemType);
NIBBLETYPE Meta = (NIBBLETYPE) a_Player->GetEquippedItem().m_ItemDamage; NIBBLETYPE Meta = (NIBBLETYPE) a_Player->GetEquippedItem().m_ItemDamage;
// HandlePlaceBlock wants a cItemHandler pointer thing, so let's give it one // Set the correct metadata based on player equipped item (i.e. a_BlockMeta not initialised yet)
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(GetDoubleSlabType(Type));
// Check if the block at the coordinates is a slab. Eligibility for combining has already been processed in ClientHandle
if (IsAnySlabType(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ)))
{
// Call the function in ClientHandle that places a block when the client sends the packet,
// so that plugins may interfere with the placement.
if ((a_BlockFace == BLOCK_FACE_TOP) || (a_BlockFace == BLOCK_FACE_BOTTOM))
{
// Top and bottom faces need no parameter modification
a_Player->GetClientHandle()->HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler);
}
else
{
// The other faces need to distinguish between top and bottom cursor positions
if (a_CursorY > 7)
{
// Edit the call to use BLOCK_FACE_BOTTOM, otherwise it places incorrectly
a_Player->GetClientHandle()->HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_TOP, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler);
}
else
{
// Edit the call to use BLOCK_FACE_TOP, otherwise it places incorrectly
a_Player->GetClientHandle()->HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_BOTTOM, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler);
}
}
return false; // Cancel the event, because dblslabs were already placed, nothing else needed
}
// Place the single-slab with correct metas:
switch (a_BlockFace) switch (a_BlockFace)
{ {
case BLOCK_FACE_TOP: case BLOCK_FACE_TOP:
@ -105,6 +74,14 @@ public:
} }
case BLOCK_FACE_NONE: return false; case BLOCK_FACE_NONE: return false;
} // switch (a_BlockFace) } // switch (a_BlockFace)
// Check if the block at the coordinates is a single slab. Eligibility for combining has already been processed in ClientHandle
// Changed to-be-placed to a double slab if we are clicking on a single slab, as opposed to placing one for the first time
if (IsAnySlabType(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ)))
{
a_BlockType = GetDoubleSlabType(m_BlockType);
}
return true; return true;
} }

View File

@ -1064,7 +1064,7 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e
// If clicked top face and slab occupies the top voxel, we want a slab to be placed above it (therefore increment Y) // If clicked top face and slab occupies the top voxel, we want a slab to be placed above it (therefore increment Y)
// Else if clicked bottom face and slab occupies the bottom voxel, decrement Y for the same reason // Else if clicked bottom face and slab occupies the bottom voxel, decrement Y for the same reason
// Don't touch coordinates if anything else because a dblslab opportunity is present // Don't touch coordinates if anything else because a dblslab opportunity is present
if((ClickedBlockMeta & 0x08) && (a_BlockFace == BLOCK_FACE_TOP)) if ((ClickedBlockMeta & 0x08) && (a_BlockFace == BLOCK_FACE_TOP))
{ {
++a_BlockY; ++a_BlockY;
} }
@ -1532,7 +1532,7 @@ void cClientHandle::HandleTabCompletion(const AString & a_Text)
void cClientHandle::SendData(const char * a_Data, int a_Size) void cClientHandle::SendData(const char * a_Data, size_t a_Size)
{ {
if (m_HasSentDC) if (m_HasSentDC)
{ {
@ -1547,7 +1547,7 @@ void cClientHandle::SendData(const char * a_Data, int a_Size)
if (m_OutgoingDataOverflow.empty()) if (m_OutgoingDataOverflow.empty())
{ {
// No queued overflow data; if this packet fits into the ringbuffer, put it in, otherwise put it in the overflow buffer: // No queued overflow data; if this packet fits into the ringbuffer, put it in, otherwise put it in the overflow buffer:
int CanFit = m_OutgoingData.GetFreeSpace(); size_t CanFit = m_OutgoingData.GetFreeSpace();
if (CanFit > a_Size) if (CanFit > a_Size)
{ {
CanFit = a_Size; CanFit = a_Size;

View File

@ -225,15 +225,15 @@ public:
*/ */
bool HandleLogin(int a_ProtocolVersion, const AString & a_Username); bool HandleLogin(int a_ProtocolVersion, const AString & a_Username);
void SendData(const char * a_Data, int a_Size); void SendData(const char * a_Data, size_t a_Size);
/** Called when the player moves into a different world; queues sreaming the new chunks */ /** Called when the player moves into a different world; queues sreaming the new chunks */
void MoveToWorld(cWorld & a_World, bool a_SendRespawnPacket); void MoveToWorld(cWorld & a_World, bool a_SendRespawnPacket);
private:
/** Handles the block placing packet when it is a real block placement (not block-using, item-using or eating) */ /** Handles the block placing packet when it is a real block placement (not block-using, item-using or eating) */
void HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, cItemHandler & a_ItemHandler); void HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, cItemHandler & a_ItemHandler);
private:
/** The type used for storing the names of registered plugin channels. */ /** The type used for storing the names of registered plugin channels. */
typedef std::set<AString> cChannels; typedef std::set<AString> cChannels;

View File

@ -1,12 +1,14 @@
#pragma once #pragma once
#define ntohll(x) ((((UInt64)ntohl((u_long)x)) << 32) + ntohl(x >> 32))
// Changes endianness // Changes endianness
inline unsigned long long HostToNetwork8(const void* a_Value ) inline UInt64 HostToNetwork8(const void * a_Value)
{ {
unsigned long long __HostToNetwork8; unsigned long long __HostToNetwork8;
memcpy( &__HostToNetwork8, a_Value, sizeof( __HostToNetwork8 ) ); memcpy( &__HostToNetwork8, a_Value, sizeof( __HostToNetwork8 ) );
@ -18,7 +20,7 @@ inline unsigned long long HostToNetwork8(const void* a_Value )
inline unsigned int HostToNetwork4(const void* a_Value ) inline UInt32 HostToNetwork4(const void* a_Value )
{ {
unsigned int __HostToNetwork4; unsigned int __HostToNetwork4;
memcpy( &__HostToNetwork4, a_Value, sizeof( __HostToNetwork4 ) ); memcpy( &__HostToNetwork4, a_Value, sizeof( __HostToNetwork4 ) );
@ -30,11 +32,10 @@ inline unsigned int HostToNetwork4(const void* a_Value )
inline double NetworkToHostDouble8(const void* a_Value ) inline double NetworkToHostDouble8(const void * a_Value)
{ {
#define ntohll(x) ((((unsigned long long)ntohl((u_long)x)) << 32) + ntohl(x >> 32)) UInt64 buf = 0;
unsigned long long buf = 0;//(*(unsigned long long*)a_Value); memcpy(&buf, a_Value, 8);
memcpy( &buf, a_Value, 8 );
buf = ntohll(buf); buf = ntohll(buf);
double x; double x;
memcpy(&x, &buf, sizeof(double)); memcpy(&x, &buf, sizeof(double));
@ -45,23 +46,25 @@ inline double NetworkToHostDouble8(const void* a_Value )
inline long long NetworkToHostLong8(const void * a_Value ) inline Int64 NetworkToHostLong8(const void * a_Value)
{ {
unsigned long long buf = *(unsigned long long*)a_Value; UInt64 buf;
memcpy(&buf, &a_Value, 8);
buf = ntohll(buf); buf = ntohll(buf);
return *reinterpret_cast<long long *>(&buf); return *reinterpret_cast<Int64 *>(&buf);
} }
inline float NetworkToHostFloat4(const void* a_Value ) inline float NetworkToHostFloat4(const void * a_Value)
{ {
u_long buf = *(u_long*)a_Value; UInt32 buf;
buf = ntohl( buf ); float x;
float x = 0; memcpy(&buf, &a_Value, 4);
memcpy( &x, &buf, sizeof(float) ); buf = ntohl(buf);
memcpy(&x, &buf, sizeof(float));
return x; return x;
} }

View File

@ -159,7 +159,7 @@ public:
cWorld * GetWorld(void) const { return m_World; } cWorld * GetWorld(void) const { return m_World; }
double GetHeadYaw (void) const { return m_HeadYaw; } double GetHeadYaw (void) const { return m_HeadYaw; } // In degrees
double GetHeight (void) const { return m_Height; } double GetHeight (void) const { return m_Height; }
double GetMass (void) const { return m_Mass; } double GetMass (void) const { return m_Mass; }
const Vector3d & GetPosition (void) const { return m_Pos; } const Vector3d & GetPosition (void) const { return m_Pos; }
@ -167,9 +167,9 @@ public:
double GetPosY (void) const { return m_Pos.y; } double GetPosY (void) const { return m_Pos.y; }
double GetPosZ (void) const { return m_Pos.z; } double GetPosZ (void) const { return m_Pos.z; }
const Vector3d & GetRot (void) const { return m_Rot; } // OBSOLETE, use individual GetYaw(), GetPitch, GetRoll() components const Vector3d & GetRot (void) const { return m_Rot; } // OBSOLETE, use individual GetYaw(), GetPitch, GetRoll() components
double GetYaw (void) const { return m_Rot.x; } double GetYaw (void) const { return m_Rot.x; } // In degrees, [-180, +180)
double GetPitch (void) const { return m_Rot.y; } double GetPitch (void) const { return m_Rot.y; } // In degrees, [-180, +180), but normal client clips to [-90, +90]
double GetRoll (void) const { return m_Rot.z; } double GetRoll (void) const { return m_Rot.z; } // In degrees, unused in current client
Vector3d GetLookVector(void) const; Vector3d GetLookVector(void) const;
const Vector3d & GetSpeed (void) const { return m_Speed; } const Vector3d & GetSpeed (void) const { return m_Speed; }
double GetSpeedX (void) const { return m_Speed.x; } double GetSpeedX (void) const { return m_Speed.x; }
@ -189,9 +189,9 @@ public:
void SetPosition(double a_PosX, double a_PosY, double a_PosZ); void SetPosition(double a_PosX, double a_PosY, double a_PosZ);
void SetPosition(const Vector3d & a_Pos) { SetPosition(a_Pos.x, a_Pos.y, a_Pos.z); } void SetPosition(const Vector3d & a_Pos) { SetPosition(a_Pos.x, a_Pos.y, a_Pos.z); }
void SetRot (const Vector3f & a_Rot); // OBSOLETE, use individual SetYaw(), SetPitch(), SetRoll() components void SetRot (const Vector3f & a_Rot); // OBSOLETE, use individual SetYaw(), SetPitch(), SetRoll() components
void SetYaw (double a_Yaw); void SetYaw (double a_Yaw); // In degrees, normalizes to [-180, +180)
void SetPitch (double a_Pitch); void SetPitch (double a_Pitch); // In degrees, normalizes to [-180, +180)
void SetRoll (double a_Roll); void SetRoll (double a_Roll); // In degrees, normalizes to [-180, +180)
void SetSpeed (double a_SpeedX, double a_SpeedY, double a_SpeedZ); void SetSpeed (double a_SpeedX, double a_SpeedY, double a_SpeedZ);
void SetSpeed (const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); } void SetSpeed (const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); }
void SetSpeedX (double a_SpeedX); void SetSpeedX (double a_SpeedX);

View File

@ -29,6 +29,9 @@
// Disabling this warning, because we know what we're doing when we're doing this: // Disabling this warning, because we know what we're doing when we're doing this:
#pragma warning(disable: 4355) // 'this' used in initializer list #pragma warning(disable: 4355) // 'this' used in initializer list
// Disabled because it's useless:
#pragma warning(disable: 4512) // 'class': assignment operator could not be generated - reported for each class that has a reference-type member
// 2014_01_06 xoft: Disabled this warning because MSVC is stupid and reports it in obviously wrong places // 2014_01_06 xoft: Disabled this warning because MSVC is stupid and reports it in obviously wrong places
// #pragma warning(3 : 4244) // Conversion from 'type1' to 'type2', possible loss of data // #pragma warning(3 : 4244) // Conversion from 'type1' to 'type2', possible loss of data

View File

@ -55,7 +55,7 @@ public:
return true; return true;
} }
a_Player->GetInventory().AddItem(cItem(E_ITEM_MAP, 1, NewMap->GetID()), true, true); a_Player->GetInventory().AddItem(cItem(E_ITEM_MAP, 1, (short)(NewMap->GetID() & 0x7fff)), true, true);
return true; return true;
} }

View File

@ -123,7 +123,7 @@ public:
} }
case 2: case 2:
{ {
Drops.Add(cItem(E_ITEM_FISHING_ROD, 1, a_World->GetTickRandomNumber(50))); // Fishing rod with durability. TODO: Enchantments on it Drops.Add(cItem(E_ITEM_FISHING_ROD, 1, (short)a_World->GetTickRandomNumber(50))); // Fishing rod with durability. TODO: Enchantments on it
break; break;
} }
case 3: case 3:
@ -152,7 +152,7 @@ public:
} }
else if (Junk <= 4) else if (Junk <= 4)
{ {
Drops.Add(cItem(E_ITEM_BOW, 1, a_World->GetTickRandomNumber(64))); Drops.Add(cItem(E_ITEM_BOW, 1, (short)a_World->GetTickRandomNumber(64)));
} }
else if (Junk <= 9) else if (Junk <= 9)
{ {

View File

@ -506,13 +506,13 @@ bool cItemHandler::GetPlacementBlockTypeMeta(
{ {
ASSERT(m_ItemType < 256); // Items with IDs above 255 should all be handled by specific handlers ASSERT(m_ItemType < 256); // Items with IDs above 255 should all be handled by specific handlers
if (m_ItemType > 256) if (m_ItemType >= 256)
{ {
LOGERROR("%s: Item %d has no valid block!", __FUNCTION__, m_ItemType); LOGERROR("%s: Item %d is not eligible for direct block placement!", __FUNCTION__, m_ItemType);
return false; return false;
} }
cBlockHandler * BlockH = BlockHandler(m_ItemType); cBlockHandler * BlockH = BlockHandler((BLOCKTYPE)m_ItemType);
cChunkInterface ChunkInterface(a_World->GetChunkMap()); cChunkInterface ChunkInterface(a_World->GetChunkMap());
return BlockH->GetPlacementBlockTypeMeta( return BlockH->GetPlacementBlockTypeMeta(
ChunkInterface, a_Player, ChunkInterface, a_Player,

View File

@ -16,17 +16,19 @@ class cItemLilypadHandler :
typedef cItemHandler super; typedef cItemHandler super;
public: public:
cItemLilypadHandler(BLOCKTYPE a_BlockType) cItemLilypadHandler(int a_ItemType):
: cItemHandler(a_BlockType) super(a_ItemType)
{ {
} }
virtual bool IsPlaceable(void) override virtual bool IsPlaceable(void) override
{ {
return false; // Set as not placeable so OnItemUse is called return false; // Set as not placeable so OnItemUse is called
} }
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
{ {
if (a_BlockFace > BLOCK_FACE_NONE) if (a_BlockFace > BLOCK_FACE_NONE)
@ -45,23 +47,22 @@ public:
public cBlockTracer::cCallbacks public cBlockTracer::cCallbacks
{ {
public: public:
cCallbacks(cWorld * a_World) : cCallbacks(cWorld * a_CBWorld) :
m_HasHitFluid(false), m_HasHitFluid(false),
m_World(a_World) m_World(a_CBWorld)
{ {
} }
virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override virtual bool OnNextBlock(int a_CBBlockX, int a_CBBlockY, int a_CBBlockZ, BLOCKTYPE a_CBBlockType, NIBBLETYPE a_CBBlockMeta, char a_CBEntryFace) override
{ {
if (IsBlockWater(a_BlockType)) if (IsBlockWater(a_CBBlockType))
{ {
if ((a_BlockMeta != 0) || (a_EntryFace == BLOCK_FACE_NONE)) // The hit block should be a source. The FACE_NONE check is clicking whilst submerged if ((a_CBBlockMeta != 0) || (a_CBEntryFace == BLOCK_FACE_NONE)) // The hit block should be a source. The FACE_NONE check is clicking whilst submerged
{ {
return false; return false;
} }
a_EntryFace = BLOCK_FACE_YP; // Always place pad at top of water block AddFaceDirection(a_CBBlockX, a_CBBlockY, a_CBBlockZ, BLOCK_FACE_YP); // Always place pad at top of water block
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, (eBlockFace)a_EntryFace); BLOCKTYPE Block = m_World->GetBlock(a_CBBlockX, a_CBBlockY, a_CBBlockZ);
BLOCKTYPE Block = m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
if ( if (
!IsBlockWater(Block) && !IsBlockWater(Block) &&
cBlockInfo::FullyOccupiesVoxel(Block) cBlockInfo::FullyOccupiesVoxel(Block)
@ -71,7 +72,7 @@ public:
return true; return true;
} }
m_HasHitFluid = true; m_HasHitFluid = true;
m_Pos.Set(a_BlockX, a_BlockY, a_BlockZ); m_Pos.Set(a_CBBlockX, a_CBBlockY, a_CBBlockZ);
return true; return true;
} }
return false; return false;

View File

@ -29,7 +29,7 @@ public:
virtual void OnUpdate(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item) virtual void OnUpdate(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item)
{ {
cMap * Map = a_World->GetMapManager().GetMapData(a_Item.m_ItemDamage); cMap * Map = a_World->GetMapManager().GetMapData((unsigned)a_Item.m_ItemDamage);
if (Map == NULL) if (Map == NULL)
{ {

View File

@ -164,9 +164,7 @@ protected:
int & a_NumSeedsOut, unsigned char * a_IsSeedOut, unsigned int * a_SeedIdxOut int & a_NumSeedsOut, unsigned char * a_IsSeedOut, unsigned int * a_SeedIdxOut
) )
{ {
ASSERT(a_SrcIdx >= 0);
ASSERT(a_SrcIdx < ARRAYCOUNT(m_SkyLight)); ASSERT(a_SrcIdx < ARRAYCOUNT(m_SkyLight));
ASSERT(a_DstIdx >= 0);
ASSERT(a_DstIdx < ARRAYCOUNT(m_BlockTypes)); ASSERT(a_DstIdx < ARRAYCOUNT(m_BlockTypes));
if (a_Light[a_SrcIdx] <= a_Light[a_DstIdx] + cBlockInfo::GetSpreadLightFalloff(m_BlockTypes[a_DstIdx])) if (a_Light[a_SrcIdx] <= a_Light[a_DstIdx] + cBlockInfo::GetSpreadLightFalloff(m_BlockTypes[a_DstIdx]))

View File

@ -129,6 +129,11 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
BLOCKTYPE TargetBlock = E_BLOCK_AIR; BLOCKTYPE TargetBlock = E_BLOCK_AIR;
if (m_AllowedTypes.find(a_MobType) != m_AllowedTypes.end() && a_Chunk->UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, TargetBlock)) if (m_AllowedTypes.find(a_MobType) != m_AllowedTypes.end() && a_Chunk->UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, TargetBlock))
{ {
if ((a_RelY + 1 > cChunkDef::Height) || (a_RelY - 1 < 0))
{
return false;
}
NIBBLETYPE BlockLight = a_Chunk->GetBlockLight(a_RelX, a_RelY, a_RelZ); NIBBLETYPE BlockLight = a_Chunk->GetBlockLight(a_RelX, a_RelY, a_RelZ);
NIBBLETYPE SkyLight = a_Chunk->GetSkyLight(a_RelX, a_RelY, a_RelZ); NIBBLETYPE SkyLight = a_Chunk->GetSkyLight(a_RelX, a_RelY, a_RelZ);
BLOCKTYPE BlockAbove = a_Chunk->GetBlock(a_RelX, a_RelY + 1, a_RelZ); BLOCKTYPE BlockAbove = a_Chunk->GetBlock(a_RelX, a_RelY + 1, a_RelZ);
@ -200,7 +205,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
case cMonster::mtSpider: case cMonster::mtSpider:
{ {
bool CanSpawn = true; bool CanSpawn = true;
bool HaveFloor = false; bool HasFloor = false;
for (int x = 0; x < 2; ++x) for (int x = 0; x < 2; ++x)
{ {
for(int z = 0; z < 2; ++z) for(int z = 0; z < 2; ++z)
@ -211,8 +216,8 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
{ {
return false; return false;
} }
HaveFloor = ( HasFloor = (
HaveFloor || HasFloor ||
( (
a_Chunk->UnboundedRelGetBlockType(a_RelX + x, a_RelY - 1, a_RelZ + z, TargetBlock) && a_Chunk->UnboundedRelGetBlockType(a_RelX + x, a_RelY - 1, a_RelZ + z, TargetBlock) &&
!cBlockInfo::IsTransparent(TargetBlock) !cBlockInfo::IsTransparent(TargetBlock)
@ -220,7 +225,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
); );
} }
} }
return CanSpawn && HaveFloor && (SkyLight <= 7) && (BlockLight <= 7); return CanSpawn && HasFloor && (SkyLight <= 7) && (BlockLight <= 7);
} }
case cMonster::mtCreeper: case cMonster::mtCreeper:

View File

@ -111,9 +111,9 @@ void cMonster::SpawnOn(cClientHandle & a_Client)
void cMonster::TickPathFinding() void cMonster::TickPathFinding()
{ {
int PosX = (int)floor(GetPosX()); const int PosX = (int)floor(GetPosX());
int PosY = (int)floor(GetPosY()); const int PosY = (int)floor(GetPosY());
int PosZ = (int)floor(GetPosZ()); const int PosZ = (int)floor(GetPosZ());
m_FinalDestination.y = (double)FindFirstNonAirBlockPosition(m_FinalDestination.x, m_FinalDestination.z); m_FinalDestination.y = (double)FindFirstNonAirBlockPosition(m_FinalDestination.x, m_FinalDestination.z);
@ -130,14 +130,16 @@ void cMonster::TickPathFinding()
{ 0, 1}, { 0, 1},
{ 0,-1}, { 0,-1},
} ; } ;
if ((PosY - 1 < 0) || (PosY + 2 > cChunkDef::Height) /* PosY + 1 will never be true if PosY + 2 is not */)
{
// Too low/high, can't really do anything
FinishPathFinding();
return;
}
for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++)
{ {
if ((gCrossCoords[i].x + PosX == PosX) && (gCrossCoords[i].z + PosZ == PosZ))
{
continue;
}
if (IsCoordinateInTraversedList(Vector3i(gCrossCoords[i].x + PosX, PosY, gCrossCoords[i].z + PosZ))) if (IsCoordinateInTraversedList(Vector3i(gCrossCoords[i].x + PosX, PosY, gCrossCoords[i].z + PosZ)))
{ {
continue; continue;

View File

@ -425,7 +425,7 @@ void cCubicCell3D::Move(int a_NewFloorX, int a_NewFloorY, int a_NewFloorZ)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cNoise: // cNoise:
cNoise::cNoise(unsigned int a_Seed) : cNoise::cNoise(int a_Seed) :
m_Seed(a_Seed) m_Seed(a_Seed)
{ {
} }

View File

@ -25,7 +25,7 @@
class cNoise class cNoise
{ {
public: public:
cNoise(unsigned int a_Seed); cNoise(int a_Seed);
cNoise(const cNoise & a_Noise); cNoise(const cNoise & a_Noise);
// The following functions, if not marked INLINE, are about 20 % slower // The following functions, if not marked INLINE, are about 20 % slower
@ -47,14 +47,14 @@ public:
NOISE_DATATYPE CubicNoise3D (NOISE_DATATYPE a_X, NOISE_DATATYPE a_Y, NOISE_DATATYPE a_Z) const; NOISE_DATATYPE CubicNoise3D (NOISE_DATATYPE a_X, NOISE_DATATYPE a_Y, NOISE_DATATYPE a_Z) const;
void SetSeed(unsigned int a_Seed) { m_Seed = a_Seed; } void SetSeed(int a_Seed) { m_Seed = a_Seed; }
INLINE static NOISE_DATATYPE CubicInterpolate (NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_C, NOISE_DATATYPE a_D, NOISE_DATATYPE a_Pct); INLINE static NOISE_DATATYPE CubicInterpolate (NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_C, NOISE_DATATYPE a_D, NOISE_DATATYPE a_Pct);
INLINE static NOISE_DATATYPE CosineInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_Pct); INLINE static NOISE_DATATYPE CosineInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_Pct);
INLINE static NOISE_DATATYPE LinearInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_Pct); INLINE static NOISE_DATATYPE LinearInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_Pct);
private: private:
unsigned int m_Seed; int m_Seed;
} ; } ;

View File

@ -105,7 +105,7 @@ void cChunkDataSerializer::Serialize29(AString & a_Data)
a_Data.append((const char *)&BitMap1, sizeof(short)); a_Data.append((const char *)&BitMap1, sizeof(short));
a_Data.append((const char *)&BitMap2, sizeof(short)); a_Data.append((const char *)&BitMap2, sizeof(short));
Int32 CompressedSizeBE = htonl(CompressedSize); UInt32 CompressedSizeBE = htonl((UInt32)CompressedSize);
a_Data.append((const char *)&CompressedSizeBE, sizeof(CompressedSizeBE)); a_Data.append((const char *)&CompressedSizeBE, sizeof(CompressedSizeBE));
Int32 UnusedInt32 = 0; Int32 UnusedInt32 = 0;
@ -163,7 +163,7 @@ void cChunkDataSerializer::Serialize39(AString & a_Data)
a_Data.append((const char *)&BitMap1, sizeof(short)); a_Data.append((const char *)&BitMap1, sizeof(short));
a_Data.append((const char *)&BitMap2, sizeof(short)); a_Data.append((const char *)&BitMap2, sizeof(short));
Int32 CompressedSizeBE = htonl(CompressedSize); UInt32 CompressedSizeBE = htonl((UInt32)CompressedSize);
a_Data.append((const char *)&CompressedSizeBE, sizeof(CompressedSizeBE)); a_Data.append((const char *)&CompressedSizeBE, sizeof(CompressedSizeBE));
// Unlike 29, 39 doesn't have the "unused" int // Unlike 29, 39 doesn't have the "unused" int

View File

@ -132,7 +132,7 @@ protected:
cCriticalSection m_CSPacket; //< Each SendXYZ() function must acquire this CS in order to send the whole packet at once cCriticalSection m_CSPacket; //< Each SendXYZ() function must acquire this CS in order to send the whole packet at once
/// A generic data-sending routine, all outgoing packet data needs to be routed through this so that descendants may override it /// A generic data-sending routine, all outgoing packet data needs to be routed through this so that descendants may override it
virtual void SendData(const char * a_Data, int a_Size) = 0; virtual void SendData(const char * a_Data, size_t a_Size) = 0;
/// Called after writing each packet, enables descendants to flush their buffers /// Called after writing each packet, enables descendants to flush their buffers
virtual void Flush(void) {}; virtual void Flush(void) {};
@ -143,10 +143,15 @@ protected:
SendData((const char *)&a_Value, 1); SendData((const char *)&a_Value, 1);
} }
void WriteChar(char a_Value)
{
SendData(&a_Value, 1);
}
void WriteShort(short a_Value) void WriteShort(short a_Value)
{ {
a_Value = htons(a_Value); u_short Value = htons((u_short)a_Value);
SendData((const char *)&a_Value, 2); SendData((const char *)&Value, 2);
} }
/* /*
@ -159,8 +164,8 @@ protected:
void WriteInt(int a_Value) void WriteInt(int a_Value)
{ {
a_Value = htonl(a_Value); u_long Value = htonl((u_long)a_Value);
SendData((const char *)&a_Value, 4); SendData((const char *)&Value, 4);
} }
void WriteUInt(unsigned int a_Value) void WriteUInt(unsigned int a_Value)
@ -171,19 +176,19 @@ protected:
void WriteInt64 (Int64 a_Value) void WriteInt64 (Int64 a_Value)
{ {
a_Value = HostToNetwork8(&a_Value); UInt64 Value = HostToNetwork8(&a_Value);
SendData((const char *)&a_Value, 8); SendData((const char *)Value, 8);
} }
void WriteFloat (float a_Value) void WriteFloat (float a_Value)
{ {
unsigned int val = HostToNetwork4(&a_Value); UInt32 val = HostToNetwork4(&a_Value);
SendData((const char *)&val, 4); SendData((const char *)&val, 4);
} }
void WriteDouble(double a_Value) void WriteDouble(double a_Value)
{ {
unsigned long long val = HostToNetwork8(&a_Value); UInt64 val = HostToNetwork8(&a_Value);
SendData((const char *)&val, 8); SendData((const char *)&val, 8);
} }
@ -191,7 +196,7 @@ protected:
{ {
AString UTF16; AString UTF16;
UTF8ToRawBEUTF16(a_Value.c_str(), a_Value.length(), UTF16); UTF8ToRawBEUTF16(a_Value.c_str(), a_Value.length(), UTF16);
WriteShort((unsigned short)(UTF16.size() / 2)); WriteShort((short)(UTF16.size() / 2));
SendData(UTF16.data(), UTF16.size()); SendData(UTF16.data(), UTF16.size());
} }
@ -211,7 +216,7 @@ protected:
{ {
// A 32-bit integer can be encoded by at most 5 bytes: // A 32-bit integer can be encoded by at most 5 bytes:
unsigned char b[5]; unsigned char b[5];
int idx = 0; size_t idx = 0;
do do
{ {
b[idx] = (a_Value & 0x7f) | ((a_Value > 0x7f) ? 0x80 : 0x00); b[idx] = (a_Value & 0x7f) | ((a_Value > 0x7f) ? 0x80 : 0x00);
@ -224,7 +229,7 @@ protected:
void WriteVarUTF8String(const AString & a_String) void WriteVarUTF8String(const AString & a_String)
{ {
WriteVarInt(a_String.size()); WriteVarInt((UInt32)a_String.size());
SendData(a_String.data(), a_String.size()); SendData(a_String.data(), a_String.size());
} }
} ; } ;

View File

@ -161,8 +161,8 @@ void cProtocol125::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, cha
WriteInt (a_BlockX); WriteInt (a_BlockX);
WriteShort((short)a_BlockY); WriteShort((short)a_BlockY);
WriteInt (a_BlockZ); WriteInt (a_BlockZ);
WriteByte (a_Byte1); WriteChar (a_Byte1);
WriteByte (a_Byte2); WriteChar (a_Byte2);
Flush(); Flush();
} }
@ -209,12 +209,12 @@ void cProtocol125::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockV
WriteByte (PACKET_MULTI_BLOCK); WriteByte (PACKET_MULTI_BLOCK);
WriteInt (a_ChunkX); WriteInt (a_ChunkX);
WriteInt (a_ChunkZ); WriteInt (a_ChunkZ);
WriteShort((unsigned short)a_Changes.size()); WriteShort((short)a_Changes.size());
WriteUInt (sizeof(int) * a_Changes.size()); WriteUInt ((UInt32)(4 * a_Changes.size()));
for (sSetBlockVector::const_iterator itr = a_Changes.begin(), end = a_Changes.end(); itr != end; ++itr) for (sSetBlockVector::const_iterator itr = a_Changes.begin(), end = a_Changes.end(); itr != end; ++itr)
{ {
unsigned int Coords = itr->y | (itr->z << 8) | (itr->x << 12); UInt32 Coords = ((UInt32)itr->y) | ((UInt32)(itr->z << 8)) | ((UInt32)(itr->x << 12));
unsigned int Blocks = itr->BlockMeta | (itr->BlockType << 4); UInt32 Blocks = ((UInt32)itr->BlockMeta) | ((UInt32)(itr->BlockType << 4));
WriteUInt(Coords << 16 | Blocks); WriteUInt(Coords << 16 | Blocks);
} }
Flush(); Flush();
@ -325,8 +325,8 @@ void cProtocol125::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, in
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte (PACKET_ENTITY_EFFECT); WriteByte (PACKET_ENTITY_EFFECT);
WriteInt (a_Entity.GetUniqueID()); WriteInt (a_Entity.GetUniqueID());
WriteByte (a_EffectID); WriteByte ((Byte)a_EffectID);
WriteByte (a_Amplifier); WriteByte ((Byte)a_Amplifier);
WriteShort(a_Duration); WriteShort(a_Duration);
Flush(); Flush();
} }
@ -357,7 +357,7 @@ void cProtocol125::SendEntityHeadLook(const cEntity & a_Entity)
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte(PACKET_ENT_HEAD_LOOK); WriteByte(PACKET_ENT_HEAD_LOOK);
WriteInt (a_Entity.GetUniqueID()); WriteInt (a_Entity.GetUniqueID());
WriteByte((char)((a_Entity.GetHeadYaw() / 360.f) * 256)); WriteChar((char)((a_Entity.GetHeadYaw() / 360.f) * 256));
Flush(); Flush();
} }
@ -372,8 +372,8 @@ void cProtocol125::SendEntityLook(const cEntity & a_Entity)
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte(PACKET_ENT_LOOK); WriteByte(PACKET_ENT_LOOK);
WriteInt (a_Entity.GetUniqueID()); WriteInt (a_Entity.GetUniqueID());
WriteByte((char)((a_Entity.GetYaw() / 360.f) * 256)); WriteChar((char)((a_Entity.GetYaw() / 360.f) * 256));
WriteByte((char)((a_Entity.GetPitch() / 360.f) * 256)); WriteChar((char)((a_Entity.GetPitch() / 360.f) * 256));
Flush(); Flush();
} }
@ -421,9 +421,9 @@ void cProtocol125::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte(PACKET_ENT_REL_MOVE); WriteByte(PACKET_ENT_REL_MOVE);
WriteInt (a_Entity.GetUniqueID()); WriteInt (a_Entity.GetUniqueID());
WriteByte(a_RelX); WriteChar(a_RelX);
WriteByte(a_RelY); WriteChar(a_RelY);
WriteByte(a_RelZ); WriteChar(a_RelZ);
Flush(); Flush();
} }
@ -438,11 +438,11 @@ void cProtocol125::SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX,
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte(PACKET_ENT_REL_MOVE_LOOK); WriteByte(PACKET_ENT_REL_MOVE_LOOK);
WriteInt (a_Entity.GetUniqueID()); WriteInt (a_Entity.GetUniqueID());
WriteByte(a_RelX); WriteChar(a_RelX);
WriteByte(a_RelY); WriteChar(a_RelY);
WriteByte(a_RelZ); WriteChar(a_RelZ);
WriteByte((char)((a_Entity.GetYaw() / 360.f) * 256)); WriteChar((char)((a_Entity.GetYaw() / 360.f) * 256));
WriteByte((char)((a_Entity.GetPitch() / 360.f) * 256)); WriteChar((char)((a_Entity.GetPitch() / 360.f) * 256));
Flush(); Flush();
} }
@ -455,7 +455,7 @@ void cProtocol125::SendEntityStatus(const cEntity & a_Entity, char a_Status)
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte(PACKET_ENT_STATUS); WriteByte(PACKET_ENT_STATUS);
WriteInt (a_Entity.GetUniqueID()); WriteInt (a_Entity.GetUniqueID());
WriteByte(a_Status); WriteChar(a_Status);
Flush(); Flush();
} }
@ -488,7 +488,7 @@ void cProtocol125::SendExplosion(double a_BlockX, double a_BlockY, double a_Bloc
WriteDouble (a_BlockY); WriteDouble (a_BlockY);
WriteDouble (a_BlockZ); WriteDouble (a_BlockZ);
WriteFloat (a_Radius); WriteFloat (a_Radius);
WriteInt (a_BlocksAffected.size()); WriteInt ((Int32)a_BlocksAffected.size());
int BlockX = (int)a_BlockX; int BlockX = (int)a_BlockX;
int BlockY = (int)a_BlockY; int BlockY = (int)a_BlockY;
int BlockZ = (int)a_BlockZ; int BlockZ = (int)a_BlockZ;
@ -513,7 +513,7 @@ void cProtocol125::SendGameMode(eGameMode a_GameMode)
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte(PACKET_CHANGE_GAME_STATE); WriteByte(PACKET_CHANGE_GAME_STATE);
WriteByte(3); WriteByte(3);
WriteByte((char)a_GameMode); WriteChar((char)a_GameMode);
Flush(); Flush();
} }
@ -538,7 +538,7 @@ void cProtocol125::SendHealth(void)
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte (PACKET_UPDATE_HEALTH); WriteByte (PACKET_UPDATE_HEALTH);
WriteShort((short)m_Client->GetPlayer()->GetHealth()); WriteShort((short)m_Client->GetPlayer()->GetHealth());
WriteShort(m_Client->GetPlayer()->GetFoodLevel()); WriteShort((short)m_Client->GetPlayer()->GetFoodLevel());
WriteFloat((float)m_Client->GetPlayer()->GetFoodSaturationLevel()); WriteFloat((float)m_Client->GetPlayer()->GetFoodSaturationLevel());
Flush(); Flush();
} }
@ -551,7 +551,7 @@ void cProtocol125::SendInventorySlot(char a_WindowID, short a_SlotNum, const cIt
{ {
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte (PACKET_INVENTORY_SLOT); WriteByte (PACKET_INVENTORY_SLOT);
WriteByte (a_WindowID); WriteChar (a_WindowID);
WriteShort(a_SlotNum); WriteShort(a_SlotNum);
WriteItem (a_Item); WriteItem (a_Item);
Flush(); Flush();
@ -600,17 +600,14 @@ void cProtocol125::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colo
WriteByte (PACKET_ITEM_DATA); WriteByte (PACKET_ITEM_DATA);
WriteShort(E_ITEM_MAP); WriteShort(E_ITEM_MAP);
WriteShort(a_ID); WriteShort((short)a_ID);
WriteShort(3 + a_Length); WriteShort((short)(3 + a_Length));
WriteByte(0); WriteByte(0);
WriteByte(a_X); WriteChar((char)a_X);
WriteByte(a_Y); WriteChar((char)a_Y);
for (unsigned int i = 0; i < a_Length; ++i) SendData((const char *)a_Colors, a_Length);
{
WriteByte(a_Colors[i]);
}
Flush(); Flush();
} }
@ -625,16 +622,16 @@ void cProtocol125::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decor
WriteByte (PACKET_ITEM_DATA); WriteByte (PACKET_ITEM_DATA);
WriteShort(E_ITEM_MAP); WriteShort(E_ITEM_MAP);
WriteShort(a_ID); WriteShort((short)a_ID);
WriteShort(1 + (3 * a_Decorators.size())); WriteShort((short)(1 + (3 * a_Decorators.size())));
WriteByte(1); WriteByte(1);
for (cMapDecoratorList::const_iterator it = a_Decorators.begin(); it != a_Decorators.end(); ++it) for (cMapDecoratorList::const_iterator it = a_Decorators.begin(); it != a_Decorators.end(); ++it)
{ {
WriteByte((it->GetType() << 4) | (it->GetRot() & 0xf)); WriteByte((Byte)(it->GetType() << 4) | (it->GetRot() & 0xf));
WriteByte(it->GetPixelX()); WriteByte((Byte)it->GetPixelX());
WriteByte(it->GetPixelZ()); WriteByte((Byte)it->GetPixelZ());
} }
Flush(); Flush();
@ -651,7 +648,7 @@ void cProtocol125::SendPickupSpawn(const cPickup & a_Pickup)
WriteByte (PACKET_PICKUP_SPAWN); WriteByte (PACKET_PICKUP_SPAWN);
WriteInt (a_Pickup.GetUniqueID()); WriteInt (a_Pickup.GetUniqueID());
WriteShort (a_Pickup.GetItem().m_ItemType); WriteShort (a_Pickup.GetItem().m_ItemType);
WriteByte (a_Pickup.GetItem().m_ItemCount); WriteChar (a_Pickup.GetItem().m_ItemCount);
WriteShort (a_Pickup.GetItem().m_ItemDamage); WriteShort (a_Pickup.GetItem().m_ItemDamage);
WriteVectorI((Vector3i)(a_Pickup.GetPosition() * 32)); WriteVectorI((Vector3i)(a_Pickup.GetPosition() * 32));
WriteByte ((char)(a_Pickup.GetSpeed().x * 8)); WriteByte ((char)(a_Pickup.GetSpeed().x * 8));
@ -669,7 +666,7 @@ void cProtocol125::SendEntityAnimation(const cEntity & a_Entity, char a_Animatio
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte(PACKET_ANIMATION); WriteByte(PACKET_ANIMATION);
WriteInt (a_Entity.GetUniqueID()); WriteInt (a_Entity.GetUniqueID());
WriteByte(a_Animation); WriteChar(a_Animation);
Flush(); Flush();
} }
@ -763,8 +760,8 @@ void cProtocol125::SendPlayerSpawn(const cPlayer & a_Player)
WriteInt ((int)(a_Player.GetPosX() * 32)); WriteInt ((int)(a_Player.GetPosX() * 32));
WriteInt ((int)(a_Player.GetPosY() * 32)); WriteInt ((int)(a_Player.GetPosY() * 32));
WriteInt ((int)(a_Player.GetPosZ() * 32)); WriteInt ((int)(a_Player.GetPosZ() * 32));
WriteByte ((char)((a_Player.GetYaw() / 360.f) * 256)); WriteChar ((char)((a_Player.GetYaw() / 360.f) * 256));
WriteByte ((char)((a_Player.GetPitch() / 360.f) * 256)); WriteChar ((char)((a_Player.GetPitch() / 360.f) * 256));
WriteShort (HeldItem.IsEmpty() ? 0 : HeldItem.m_ItemType); WriteShort (HeldItem.IsEmpty() ? 0 : HeldItem.m_ItemType);
Flush(); Flush();
} }
@ -790,9 +787,9 @@ void cProtocol125::SendPluginMessage(const AString & a_Channel, const AString &
void cProtocol125::SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID) void cProtocol125::SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID)
{ {
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte (PACKET_REMOVE_ENTITY_EFFECT); WriteByte(PACKET_REMOVE_ENTITY_EFFECT);
WriteInt (a_Entity.GetUniqueID()); WriteInt (a_Entity.GetUniqueID());
WriteByte (a_EffectID); WriteChar((char)a_EffectID);
Flush(); Flush();
} }
@ -806,7 +803,7 @@ void cProtocol125::SendRespawn(void)
WriteByte (PACKET_RESPAWN); WriteByte (PACKET_RESPAWN);
WriteInt ((int)(m_Client->GetPlayer()->GetWorld()->GetDimension())); WriteInt ((int)(m_Client->GetPlayer()->GetWorld()->GetDimension()));
WriteByte (2); // TODO: Difficulty; 2 = Normal WriteByte (2); // TODO: Difficulty; 2 = Normal
WriteByte ((char)m_Client->GetPlayer()->GetGameMode()); WriteChar ((char)m_Client->GetPlayer()->GetGameMode());
WriteShort (256); // Current world height WriteShort (256); // Current world height
WriteString("default"); WriteString("default");
} }
@ -837,7 +834,7 @@ void cProtocol125::SendExperienceOrb(const cExpOrb & a_ExpOrb)
WriteInt((int) a_ExpOrb.GetPosX()); WriteInt((int) a_ExpOrb.GetPosX());
WriteInt((int) a_ExpOrb.GetPosY()); WriteInt((int) a_ExpOrb.GetPosY());
WriteInt((int) a_ExpOrb.GetPosZ()); WriteInt((int) a_ExpOrb.GetPosZ());
WriteShort(a_ExpOrb.GetReward()); WriteShort((short)a_ExpOrb.GetReward());
Flush(); Flush();
} }
@ -878,7 +875,7 @@ void cProtocol125::SendSpawnMob(const cMonster & a_Mob)
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte (PACKET_SPAWN_MOB); WriteByte (PACKET_SPAWN_MOB);
WriteInt (a_Mob.GetUniqueID()); WriteInt (a_Mob.GetUniqueID());
WriteByte (a_Mob.GetMobType()); WriteByte ((Byte)a_Mob.GetMobType());
WriteVectorI((Vector3i)(a_Mob.GetPosition() * 32)); WriteVectorI((Vector3i)(a_Mob.GetPosition() * 32));
WriteByte (0); WriteByte (0);
WriteByte (0); WriteByte (0);
@ -903,7 +900,7 @@ void cProtocol125::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType,
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte(PACKET_SPAWN_OBJECT); WriteByte(PACKET_SPAWN_OBJECT);
WriteInt (a_Entity.GetUniqueID()); WriteInt (a_Entity.GetUniqueID());
WriteByte(a_ObjectType); WriteChar(a_ObjectType);
WriteInt ((int)(a_Entity.GetPosX() * 32)); WriteInt ((int)(a_Entity.GetPosX() * 32));
WriteInt ((int)(a_Entity.GetPosY() * 32)); WriteInt ((int)(a_Entity.GetPosY() * 32));
WriteInt ((int)(a_Entity.GetPosZ() * 32)); WriteInt ((int)(a_Entity.GetPosZ() * 32));
@ -928,7 +925,7 @@ void cProtocol125::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleTyp
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte (PACKET_SPAWN_OBJECT); WriteByte (PACKET_SPAWN_OBJECT);
WriteInt (a_Vehicle.GetUniqueID()); WriteInt (a_Vehicle.GetUniqueID());
WriteByte (a_VehicleType); WriteChar (a_VehicleType);
WriteInt ((int)(a_Vehicle.GetPosX() * 32)); WriteInt ((int)(a_Vehicle.GetPosX() * 32));
WriteInt ((int)(a_Vehicle.GetPosY() * 32)); WriteInt ((int)(a_Vehicle.GetPosY() * 32));
WriteInt ((int)(a_Vehicle.GetPosZ() * 32)); WriteInt ((int)(a_Vehicle.GetPosZ() * 32));
@ -966,8 +963,8 @@ void cProtocol125::SendTeleportEntity(const cEntity & a_Entity)
WriteInt ((int)(floor(a_Entity.GetPosX() * 32))); WriteInt ((int)(floor(a_Entity.GetPosX() * 32)));
WriteInt ((int)(floor(a_Entity.GetPosY() * 32))); WriteInt ((int)(floor(a_Entity.GetPosY() * 32)));
WriteInt ((int)(floor(a_Entity.GetPosZ() * 32))); WriteInt ((int)(floor(a_Entity.GetPosZ() * 32)));
WriteByte ((char)((a_Entity.GetYaw() / 360.f) * 256)); WriteChar ((char)((a_Entity.GetYaw() / 360.f) * 256));
WriteByte ((char)((a_Entity.GetPitch() / 360.f) * 256)); WriteChar ((char)((a_Entity.GetPitch() / 360.f) * 256));
Flush(); Flush();
} }
@ -1042,7 +1039,7 @@ void cProtocol125::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_Bloc
WriteInt (a_Entity.GetUniqueID()); WriteInt (a_Entity.GetUniqueID());
WriteByte(0); // Unknown byte only 0 has been observed WriteByte(0); // Unknown byte only 0 has been observed
WriteInt (a_BlockX); WriteInt (a_BlockX);
WriteByte(a_BlockY); WriteByte((Byte)a_BlockY);
WriteInt (a_BlockZ); WriteInt (a_BlockZ);
Flush(); Flush();
} }
@ -1086,7 +1083,7 @@ void cProtocol125::SendWholeInventory(const cWindow & a_Window)
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
cItems Slots; cItems Slots;
a_Window.GetSlots(*(m_Client->GetPlayer()), Slots); a_Window.GetSlots(*(m_Client->GetPlayer()), Slots);
SendWindowSlots(a_Window.GetWindowID(), Slots.size(), &(Slots[0])); SendWindowSlots(a_Window.GetWindowID(), (int)Slots.size(), &(Slots[0]));
} }
@ -1103,7 +1100,7 @@ void cProtocol125::SendWindowClose(const cWindow & a_Window)
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte(PACKET_WINDOW_CLOSE); WriteByte(PACKET_WINDOW_CLOSE);
WriteByte(a_Window.GetWindowID()); WriteChar(a_Window.GetWindowID());
Flush(); Flush();
} }
@ -1120,10 +1117,10 @@ void cProtocol125::SendWindowOpen(const cWindow & a_Window)
} }
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte (PACKET_WINDOW_OPEN); WriteByte (PACKET_WINDOW_OPEN);
WriteByte (a_Window.GetWindowID()); WriteChar (a_Window.GetWindowID());
WriteByte (a_Window.GetWindowType()); WriteByte ((Byte)a_Window.GetWindowType());
WriteString(a_Window.GetWindowTitle()); WriteString(a_Window.GetWindowTitle());
WriteByte (a_Window.GetNumNonInventorySlots()); WriteByte ((Byte)a_Window.GetNumNonInventorySlots());
Flush(); Flush();
} }
@ -1135,7 +1132,7 @@ void cProtocol125::SendWindowProperty(const cWindow & a_Window, short a_Property
{ {
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte (PACKET_WINDOW_PROPERTY); WriteByte (PACKET_WINDOW_PROPERTY);
WriteByte (a_Window.GetWindowID()); WriteChar (a_Window.GetWindowID());
WriteShort(a_Property); WriteShort(a_Property);
WriteShort(a_Value); WriteShort(a_Value);
Flush(); Flush();
@ -1156,7 +1153,7 @@ AString cProtocol125::GetAuthServerID(void)
void cProtocol125::SendData(const char * a_Data, int a_Size) void cProtocol125::SendData(const char * a_Data, size_t a_Size)
{ {
m_Client->SendData(a_Data, a_Size); m_Client->SendData(a_Data, a_Size);
} }
@ -1527,7 +1524,7 @@ int cProtocol125::ParsePluginMessage(void)
HANDLE_PACKET_READ(ReadBEUTF16String16, AString, ChannelName); HANDLE_PACKET_READ(ReadBEUTF16String16, AString, ChannelName);
HANDLE_PACKET_READ(ReadBEShort, short, Length); HANDLE_PACKET_READ(ReadBEShort, short, Length);
AString Data; AString Data;
if (!m_ReceivedData.ReadString(Data, Length)) if (!m_ReceivedData.ReadString(Data, (size_t)Length))
{ {
m_ReceivedData.CheckValid(); m_ReceivedData.CheckValid();
return PARSE_INCOMPLETE; return PARSE_INCOMPLETE;
@ -1688,7 +1685,7 @@ void cProtocol125::SendPreChunk(int a_ChunkX, int a_ChunkZ, bool a_ShouldLoad)
void cProtocol125::SendWindowSlots(char a_WindowID, int a_NumItems, const cItem * a_Items) void cProtocol125::SendWindowSlots(char a_WindowID, int a_NumItems, const cItem * a_Items)
{ {
WriteByte (PACKET_INVENTORY_WHOLE); WriteByte (PACKET_INVENTORY_WHOLE);
WriteByte (a_WindowID); WriteChar (a_WindowID);
WriteShort((short)a_NumItems); WriteShort((short)a_NumItems);
for (int j = 0; j < a_NumItems; j++) for (int j = 0; j < a_NumItems; j++)
@ -1718,7 +1715,7 @@ void cProtocol125::WriteItem(const cItem & a_Item)
return; return;
} }
WriteByte (a_Item.m_ItemCount); WriteChar (a_Item.m_ItemCount);
WriteShort(a_Item.m_ItemDamage); WriteShort(a_Item.m_ItemDamage);
if (cItem::IsEnchantable(a_Item.m_ItemType)) if (cItem::IsEnchantable(a_Item.m_ItemType))
@ -1765,7 +1762,7 @@ int cProtocol125::ParseItem(cItem & a_Item)
} }
// TODO: Enchantment not implemented yet! // TODO: Enchantment not implemented yet!
if (!m_ReceivedData.SkipRead(EnchantNumBytes)) if (!m_ReceivedData.SkipRead((size_t)EnchantNumBytes))
{ {
return PARSE_INCOMPLETE; return PARSE_INCOMPLETE;
} }
@ -1850,7 +1847,7 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob)
case cMonster::mtCreeper: case cMonster::mtCreeper:
{ {
WriteByte(0x10); WriteByte(0x10);
WriteByte(((const cCreeper &)a_Mob).IsBlowing() ? 1 : -1); // Blowing up? WriteChar(((const cCreeper &)a_Mob).IsBlowing() ? 1 : -1); // Blowing up?
WriteByte(0x11); WriteByte(0x11);
WriteByte(((const cCreeper &)a_Mob).IsCharged() ? 1 : 0); // Lightning-charged? WriteByte(((const cCreeper &)a_Mob).IsCharged() ? 1 : 0); // Lightning-charged?
break; break;
@ -1920,9 +1917,9 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob)
WriteByte(0x10); WriteByte(0x10);
Byte SheepMetadata = 0; Byte SheepMetadata = 0;
SheepMetadata = ((const cSheep &)a_Mob).GetFurColor(); // Fur colour SheepMetadata = (Byte)((const cSheep &)a_Mob).GetFurColor();
if (((const cSheep &)a_Mob).IsSheared()) // Is sheared? if (((const cSheep &)a_Mob).IsSheared())
{ {
SheepMetadata |= 0x16; SheepMetadata |= 0x16;
} }
@ -1954,7 +1951,7 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob)
case cMonster::mtWither: case cMonster::mtWither:
{ {
WriteByte(0x54); // Int at index 20 WriteByte(0x54); // Int at index 20
WriteInt(((const cWither &)a_Mob).GetNumInvulnerableTicks()); WriteInt((Int32)((const cWither &)a_Mob).GetNumInvulnerableTicks());
WriteByte(0x66); // Float at index 6 WriteByte(0x66); // Float at index 6
WriteFloat((float)(a_Mob.GetHealth())); WriteFloat((float)(a_Mob.GetHealth()));
break; break;
@ -1965,11 +1962,11 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob)
WriteByte(0x10); WriteByte(0x10);
if (a_Mob.GetMobType() == cMonster::mtSlime) if (a_Mob.GetMobType() == cMonster::mtSlime)
{ {
WriteByte(((const cSlime &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME WriteByte((Byte)((const cSlime &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME
} }
else else
{ {
WriteByte(((const cMagmaCube &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME WriteByte((Byte)((const cMagmaCube &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME
} }
break; break;
} }
@ -2008,7 +2005,7 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob)
WriteInt(Flags); WriteInt(Flags);
WriteByte(0x13); WriteByte(0x13);
WriteByte(((const cHorse &)a_Mob).GetHorseType()); // Type of horse (donkey, chestnut, etc.) WriteByte((Byte)((const cHorse &)a_Mob).GetHorseType()); // Type of horse (donkey, chestnut, etc.)
WriteByte(0x54); WriteByte(0x54);
int Appearance = 0; int Appearance = 0;
@ -2020,6 +2017,10 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob)
WriteInt(((const cHorse &)a_Mob).GetHorseArmour()); // Horshey armour WriteInt(((const cHorse &)a_Mob).GetHorseArmour()); // Horshey armour
break; break;
} }
default:
{
break;
}
} }
} }

View File

@ -125,7 +125,7 @@ protected:
AString m_Username; ///< Stored in ParseHandshake(), compared to Login username AString m_Username; ///< Stored in ParseHandshake(), compared to Login username
virtual void SendData(const char * a_Data, int a_Size) override; virtual void SendData(const char * a_Data, size_t a_Size) override;
/// Sends the Handshake packet /// Sends the Handshake packet
void SendHandshake(const AString & a_ConnectionHash); void SendHandshake(const AString & a_ConnectionHash);

View File

@ -115,7 +115,7 @@ void cProtocol132::DataReceived(const char * a_Data, size_t a_Size)
Byte Decrypted[512]; Byte Decrypted[512];
while (a_Size > 0) while (a_Size > 0)
{ {
int NumBytes = (a_Size > (int)sizeof(Decrypted)) ? (int)sizeof(Decrypted) : a_Size; size_t NumBytes = (a_Size > sizeof(Decrypted)) ? sizeof(Decrypted) : a_Size;
m_Decryptor.ProcessData(Decrypted, (Byte *)a_Data, NumBytes); m_Decryptor.ProcessData(Decrypted, (Byte *)a_Data, NumBytes);
super::DataReceived((const char *)Decrypted, NumBytes); super::DataReceived((const char *)Decrypted, NumBytes);
a_Size -= NumBytes; a_Size -= NumBytes;
@ -139,8 +139,8 @@ void cProtocol132::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, cha
WriteInt (a_BlockX); WriteInt (a_BlockX);
WriteShort((short)a_BlockY); WriteShort((short)a_BlockY);
WriteInt (a_BlockZ); WriteInt (a_BlockZ);
WriteByte (a_Byte1); WriteChar (a_Byte1);
WriteByte (a_Byte2); WriteChar (a_Byte2);
WriteShort(a_BlockType); WriteShort(a_BlockType);
Flush(); Flush();
} }
@ -157,7 +157,7 @@ void cProtocol132::SendBlockBreakAnim(int a_entityID, int a_BlockX, int a_BlockY
WriteInt (a_BlockX); WriteInt (a_BlockX);
WriteInt (a_BlockY); WriteInt (a_BlockY);
WriteInt (a_BlockZ); WriteInt (a_BlockZ);
WriteByte (stage); WriteChar (stage);
Flush(); Flush();
} }
@ -259,7 +259,7 @@ void cProtocol132::SendLogin(const cPlayer & a_Player, const cWorld & a_World)
WriteByte (PACKET_LOGIN); WriteByte (PACKET_LOGIN);
WriteInt (a_Player.GetUniqueID()); // EntityID of the player WriteInt (a_Player.GetUniqueID()); // EntityID of the player
WriteString("default"); // Level type WriteString("default"); // Level type
WriteByte ((int)a_Player.GetGameMode()); WriteByte ((Byte)a_Player.GetGameMode());
WriteByte ((Byte)(a_World.GetDimension())); WriteByte ((Byte)(a_World.GetDimension()));
WriteByte (2); // TODO: Difficulty WriteByte (2); // TODO: Difficulty
WriteByte (0); // Unused, used to be world height WriteByte (0); // Unused, used to be world height
@ -283,8 +283,8 @@ void cProtocol132::SendPlayerSpawn(const cPlayer & a_Player)
WriteInt ((int)(a_Player.GetPosX() * 32)); WriteInt ((int)(a_Player.GetPosX() * 32));
WriteInt ((int)(a_Player.GetPosY() * 32)); WriteInt ((int)(a_Player.GetPosY() * 32));
WriteInt ((int)(a_Player.GetPosZ() * 32)); WriteInt ((int)(a_Player.GetPosZ() * 32));
WriteByte ((char)((a_Player.GetYaw() / 360.f) * 256)); WriteChar ((char)((a_Player.GetYaw() / 360.f) * 256));
WriteByte ((char)((a_Player.GetPitch() / 360.f) * 256)); WriteChar ((char)((a_Player.GetPitch() / 360.f) * 256));
WriteShort (HeldItem.IsEmpty() ? 0 : HeldItem.m_ItemType); WriteShort (HeldItem.IsEmpty() ? 0 : HeldItem.m_ItemType);
// Player metadata: just use a default metadata value, since the client doesn't like starting without any metadata: // Player metadata: just use a default metadata value, since the client doesn't like starting without any metadata:
WriteByte (0); // Index 0, byte (flags) WriteByte (0); // Index 0, byte (flags)
@ -306,7 +306,7 @@ void cProtocol132::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int
WriteInt (a_SrcY); WriteInt (a_SrcY);
WriteInt (a_SrcZ); WriteInt (a_SrcZ);
WriteFloat (a_Volume); WriteFloat (a_Volume);
WriteByte ((char)(a_Pitch * 63.0f)); WriteChar ((char)(a_Pitch * 63.0f));
Flush(); Flush();
} }
@ -320,7 +320,7 @@ void cProtocol132::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_Src
WriteByte(PACKET_SOUND_PARTICLE_EFFECT); WriteByte(PACKET_SOUND_PARTICLE_EFFECT);
WriteInt (a_EffectID); WriteInt (a_EffectID);
WriteInt (a_SrcX); WriteInt (a_SrcX);
WriteByte(a_SrcY); WriteByte((Byte)a_SrcY);
WriteInt (a_SrcZ); WriteInt (a_SrcZ);
WriteInt (a_Data); WriteInt (a_Data);
Flush(); Flush();
@ -335,7 +335,7 @@ void cProtocol132::SendSpawnMob(const cMonster & a_Mob)
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte (PACKET_SPAWN_MOB); WriteByte (PACKET_SPAWN_MOB);
WriteInt (a_Mob.GetUniqueID()); WriteInt (a_Mob.GetUniqueID());
WriteByte (a_Mob.GetMobType()); WriteByte ((Byte)a_Mob.GetMobType());
WriteVectorI((Vector3i)(a_Mob.GetPosition() * 32)); WriteVectorI((Vector3i)(a_Mob.GetPosition() * 32));
WriteByte ((Byte)((a_Mob.GetYaw() / 360.f) * 256)); WriteByte ((Byte)((a_Mob.GetYaw() / 360.f) * 256));
WriteByte ((Byte)((a_Mob.GetPitch() / 360.f) * 256)); WriteByte ((Byte)((a_Mob.GetPitch() / 360.f) * 256));
@ -411,12 +411,12 @@ void cProtocol132::SendWholeInventory(const cWindow & a_Window)
const cInventory & Inventory = m_Client->GetPlayer()->GetInventory(); const cInventory & Inventory = m_Client->GetPlayer()->GetInventory();
int BaseOffset = a_Window.GetNumSlots() - (cInventory::invNumSlots - cInventory::invInventoryOffset); // Number of non-inventory slots int BaseOffset = a_Window.GetNumSlots() - (cInventory::invNumSlots - cInventory::invInventoryOffset); // Number of non-inventory slots
char WindowID = a_Window.GetWindowID(); char WindowID = a_Window.GetWindowID();
for (int i = 0; i < cInventory::invInventoryCount; i++) for (short i = 0; i < cInventory::invInventoryCount; i++)
{ {
SendInventorySlot(WindowID, BaseOffset + i, Inventory.GetInventorySlot(i)); SendInventorySlot(WindowID, BaseOffset + i, Inventory.GetInventorySlot(i));
} // for i - Inventory[] } // for i - Inventory[]
BaseOffset += cInventory::invInventoryCount; BaseOffset += cInventory::invInventoryCount;
for (int i = 0; i < cInventory::invHotbarCount; i++) for (short i = 0; i < cInventory::invHotbarCount; i++)
{ {
SendInventorySlot(WindowID, BaseOffset + i, Inventory.GetHotbarSlot(i)); SendInventorySlot(WindowID, BaseOffset + i, Inventory.GetHotbarSlot(i));
} // for i - Hotbar[] } // for i - Hotbar[]
@ -527,21 +527,30 @@ int cProtocol132::ParseClientStatuses(void)
int cProtocol132::ParseEncryptionKeyResponse(void) int cProtocol132::ParseEncryptionKeyResponse(void)
{ {
// Read the encryption key:
HANDLE_PACKET_READ(ReadBEShort, short, EncKeyLength); HANDLE_PACKET_READ(ReadBEShort, short, EncKeyLength);
if (EncKeyLength > MAX_ENC_LEN)
{
LOGD("Too long encryption key");
m_Client->Kick("Hacked client");
return PARSE_OK;
}
AString EncKey; AString EncKey;
if (!m_ReceivedData.ReadString(EncKey, EncKeyLength)) if (!m_ReceivedData.ReadString(EncKey, (size_t)EncKeyLength))
{ {
return PARSE_INCOMPLETE; return PARSE_INCOMPLETE;
} }
// Read the encryption nonce:
HANDLE_PACKET_READ(ReadBEShort, short, EncNonceLength); HANDLE_PACKET_READ(ReadBEShort, short, EncNonceLength);
AString EncNonce; AString EncNonce;
if (!m_ReceivedData.ReadString(EncNonce, EncNonceLength)) if (!m_ReceivedData.ReadString(EncNonce, (size_t)EncNonceLength))
{ {
return PARSE_INCOMPLETE; return PARSE_INCOMPLETE;
} }
if ((EncKeyLength > MAX_ENC_LEN) || (EncNonceLength > MAX_ENC_LEN)) if (EncNonceLength > MAX_ENC_LEN)
{ {
LOGD("Too long encryption"); LOGD("Too long encryption nonce");
m_Client->Kick("Hacked client"); m_Client->Kick("Hacked client");
return PARSE_OK; return PARSE_OK;
} }
@ -605,7 +614,7 @@ int cProtocol132::ParseTabCompletion(void)
void cProtocol132::SendData(const char * a_Data, int a_Size) void cProtocol132::SendData(const char * a_Data, size_t a_Size)
{ {
m_DataToSend.append(a_Data, a_Size); m_DataToSend.append(a_Data, a_Size);
} }
@ -623,23 +632,23 @@ void cProtocol132::Flush(void)
LOGD("Flushing empty"); LOGD("Flushing empty");
return; return;
} }
const char * a_Data = m_DataToSend.data(); const char * Data = m_DataToSend.data();
int a_Size = m_DataToSend.size(); size_t Size = m_DataToSend.size();
if (m_IsEncrypted) if (m_IsEncrypted)
{ {
Byte Encrypted[8192]; // Larger buffer, we may be sending lots of data (chunks) Byte Encrypted[8192]; // Larger buffer, we may be sending lots of data (chunks)
while (a_Size > 0) while (Size > 0)
{ {
int NumBytes = (a_Size > (int)sizeof(Encrypted)) ? (int)sizeof(Encrypted) : a_Size; size_t NumBytes = (Size > sizeof(Encrypted)) ? sizeof(Encrypted) : Size;
m_Encryptor.ProcessData(Encrypted, (Byte *)a_Data, NumBytes); m_Encryptor.ProcessData(Encrypted, (Byte *)Data, NumBytes);
super::SendData((const char *)Encrypted, NumBytes); super::SendData((const char *)Encrypted, NumBytes);
a_Size -= NumBytes; Size -= NumBytes;
a_Data += NumBytes; Data += NumBytes;
} }
} }
else else
{ {
super::SendData(a_Data, a_Size); super::SendData(Data, Size);
} }
m_DataToSend.clear(); m_DataToSend.clear();
} }
@ -665,7 +674,7 @@ void cProtocol132::WriteItem(const cItem & a_Item)
} }
WriteShort(ItemType); WriteShort(ItemType);
WriteByte (a_Item.m_ItemCount); WriteChar (a_Item.m_ItemCount);
WriteShort(a_Item.m_ItemDamage); WriteShort(a_Item.m_ItemDamage);
if (a_Item.m_Enchantments.IsEmpty()) if (a_Item.m_Enchantments.IsEmpty())
@ -681,7 +690,7 @@ void cProtocol132::WriteItem(const cItem & a_Item)
Writer.Finish(); Writer.Finish();
AString Compressed; AString Compressed;
CompressStringGZIP(Writer.GetResult().data(), Writer.GetResult().size(), Compressed); CompressStringGZIP(Writer.GetResult().data(), Writer.GetResult().size(), Compressed);
WriteShort(Compressed.size()); WriteShort((short)Compressed.size());
SendData(Compressed.data(), Compressed.size()); SendData(Compressed.data(), Compressed.size());
} }
@ -717,8 +726,8 @@ int cProtocol132::ParseItem(cItem & a_Item)
// Read the metadata // Read the metadata
AString Metadata; AString Metadata;
Metadata.resize(MetadataLength); Metadata.resize((size_t)MetadataLength);
if (!m_ReceivedData.ReadBuf((void *)Metadata.data(), MetadataLength)) if (!m_ReceivedData.ReadBuf((void *)Metadata.data(), (size_t)MetadataLength))
{ {
return PARSE_INCOMPLETE; return PARSE_INCOMPLETE;
} }

View File

@ -87,7 +87,7 @@ protected:
/// The ServerID used for session authentication; set in StartEncryption(), used in GetAuthServerID() /// The ServerID used for session authentication; set in StartEncryption(), used in GetAuthServerID()
AString m_AuthServerID; AString m_AuthServerID;
virtual void SendData(const char * a_Data, int a_Size) override; virtual void SendData(const char * a_Data, size_t a_Size) override;
// DEBUG: // DEBUG:
virtual void Flush(void) override; virtual void Flush(void) override;

View File

@ -103,9 +103,9 @@ void cProtocol142::SendPickupSpawn(const cPickup & a_Pickup)
WriteInt (a_Pickup.GetUniqueID()); WriteInt (a_Pickup.GetUniqueID());
WriteItem (a_Pickup.GetItem()); WriteItem (a_Pickup.GetItem());
WriteVectorI((Vector3i)(a_Pickup.GetPosition() * 32)); WriteVectorI((Vector3i)(a_Pickup.GetPosition() * 32));
WriteByte ((char)(a_Pickup.GetSpeed().x * 8)); WriteChar ((char)(a_Pickup.GetSpeed().x * 8));
WriteByte ((char)(a_Pickup.GetSpeed().y * 8)); WriteChar ((char)(a_Pickup.GetSpeed().y * 8));
WriteByte ((char)(a_Pickup.GetSpeed().z * 8)); WriteChar ((char)(a_Pickup.GetSpeed().z * 8));
Flush(); Flush();
} }
@ -119,7 +119,7 @@ void cProtocol142::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_Src
WriteByte(PACKET_SOUND_PARTICLE_EFFECT); WriteByte(PACKET_SOUND_PARTICLE_EFFECT);
WriteInt (a_EffectID); WriteInt (a_EffectID);
WriteInt (a_SrcX); WriteInt (a_SrcX);
WriteByte(a_SrcY); WriteByte((Byte)a_SrcY);
WriteInt (a_SrcZ); WriteInt (a_SrcZ);
WriteInt (a_Data); WriteInt (a_Data);
WriteBool(0); WriteBool(0);
@ -218,7 +218,7 @@ void cProtocol146::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType,
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte(PACKET_SPAWN_OBJECT); WriteByte(PACKET_SPAWN_OBJECT);
WriteInt (a_Entity.GetUniqueID()); WriteInt (a_Entity.GetUniqueID());
WriteByte(a_ObjectType); WriteChar(a_ObjectType);
WriteInt ((int)(a_Entity.GetPosX() * 32)); WriteInt ((int)(a_Entity.GetPosX() * 32));
WriteInt ((int)(a_Entity.GetPosY() * 32)); WriteInt ((int)(a_Entity.GetPosY() * 32));
WriteInt ((int)(a_Entity.GetPosZ() * 32)); WriteInt ((int)(a_Entity.GetPosZ() * 32));
@ -243,7 +243,7 @@ void cProtocol146::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleTyp
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte (PACKET_SPAWN_OBJECT); WriteByte (PACKET_SPAWN_OBJECT);
WriteInt (a_Vehicle.GetUniqueID()); WriteInt (a_Vehicle.GetUniqueID());
WriteByte (a_VehicleType); WriteChar (a_VehicleType);
WriteInt ((int)(a_Vehicle.GetPosX() * 32)); WriteInt ((int)(a_Vehicle.GetPosX() * 32));
WriteInt ((int)(a_Vehicle.GetPosY() * 32)); WriteInt ((int)(a_Vehicle.GetPosY() * 32));
WriteInt ((int)(a_Vehicle.GetPosZ() * 32)); WriteInt ((int)(a_Vehicle.GetPosZ() * 32));

View File

@ -119,7 +119,7 @@ void cProtocol161::SendHealth(void)
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte (PACKET_UPDATE_HEALTH); WriteByte (PACKET_UPDATE_HEALTH);
WriteFloat((float)m_Client->GetPlayer()->GetHealth()); WriteFloat((float)m_Client->GetPlayer()->GetHealth());
WriteShort(m_Client->GetPlayer()->GetFoodLevel()); WriteShort((short)m_Client->GetPlayer()->GetFoodLevel());
WriteFloat((float)m_Client->GetPlayer()->GetFoodSaturationLevel()); WriteFloat((float)m_Client->GetPlayer()->GetFoodSaturationLevel());
Flush(); Flush();
} }
@ -163,10 +163,10 @@ void cProtocol161::SendWindowOpen(const cWindow & a_Window)
} }
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte (PACKET_WINDOW_OPEN); WriteByte (PACKET_WINDOW_OPEN);
WriteByte (a_Window.GetWindowID()); WriteChar (a_Window.GetWindowID());
WriteByte (a_Window.GetWindowType()); WriteByte ((Byte)a_Window.GetWindowType());
WriteString(a_Window.GetWindowTitle()); WriteString(a_Window.GetWindowTitle());
WriteByte (a_Window.GetNumNonInventorySlots()); WriteByte ((Byte)a_Window.GetNumNonInventorySlots());
WriteByte (1); // Use title WriteByte (1); // Use title
if (a_Window.GetWindowType() == cWindow::wtAnimalChest) if (a_Window.GetWindowType() == cWindow::wtAnimalChest)
{ {

View File

@ -1236,7 +1236,7 @@ void cProtocol172::SendWindowProperty(const cWindow & a_Window, short a_Property
void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) void cProtocol172::AddReceivedData(const char * a_Data, size_t a_Size)
{ {
// Write the incoming data into the comm log file: // Write the incoming data into the comm log file:
if (g_ShouldLogCommIn) if (g_ShouldLogCommIn)
@ -1258,7 +1258,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size)
AString Hex; AString Hex;
CreateHexDump(Hex, a_Data, a_Size, 16); CreateHexDump(Hex, a_Data, a_Size, 16);
m_CommLogFile.Printf("Incoming data: %d (0x%x) bytes: \n%s\n", m_CommLogFile.Printf("Incoming data: %d (0x%x) bytes: \n%s\n",
a_Size, a_Size, Hex.c_str() (unsigned)a_Size, (unsigned)a_Size, Hex.c_str()
); );
m_CommLogFile.Flush(); m_CommLogFile.Flush();
} }
@ -1988,14 +1988,14 @@ void cProtocol172::WritePacket(cByteBuffer & a_Packet)
void cProtocol172::SendData(const char * a_Data, int a_Size) void cProtocol172::SendData(const char * a_Data, size_t a_Size)
{ {
if (m_IsEncrypted) if (m_IsEncrypted)
{ {
Byte Encrypted[8192]; // Larger buffer, we may be sending lots of data (chunks) Byte Encrypted[8192]; // Larger buffer, we may be sending lots of data (chunks)
while (a_Size > 0) while (a_Size > 0)
{ {
size_t NumBytes = ((size_t)a_Size > sizeof(Encrypted)) ? sizeof(Encrypted) : (size_t)a_Size; size_t NumBytes = (a_Size > sizeof(Encrypted)) ? sizeof(Encrypted) : a_Size;
m_Encryptor.ProcessData(Encrypted, (Byte *)a_Data, NumBytes); m_Encryptor.ProcessData(Encrypted, (Byte *)a_Data, NumBytes);
m_Client->SendData((const char *)Encrypted, NumBytes); m_Client->SendData((const char *)Encrypted, NumBytes);
a_Size -= NumBytes; a_Size -= NumBytes;

View File

@ -196,7 +196,7 @@ protected:
m_Out.WriteVarUTF8String(a_Value); m_Out.WriteVarUTF8String(a_Value);
} }
void WriteBuf(const char * a_Data, int a_Size) void WriteBuf(const char * a_Data, size_t a_Size)
{ {
m_Out.Write(a_Data, a_Size); m_Out.Write(a_Data, a_Size);
} }
@ -243,7 +243,7 @@ protected:
/** Adds the received (unencrypted) data to m_ReceivedData, parses complete packets */ /** Adds the received (unencrypted) data to m_ReceivedData, parses complete packets */
void AddReceivedData(const char * a_Data, int a_Size); void AddReceivedData(const char * a_Data, size_t a_Size);
/** Reads and handles the packet. The packet length and type have already been read. /** Reads and handles the packet. The packet length and type have already been read.
Returns true if the packet was understood, false if it was an unknown packet Returns true if the packet was understood, false if it was an unknown packet
@ -287,7 +287,7 @@ protected:
void WritePacket(cByteBuffer & a_Packet); void WritePacket(cByteBuffer & a_Packet);
/** Sends the data to the client, encrypting them if needed. */ /** Sends the data to the client, encrypting them if needed. */
virtual void SendData(const char * a_Data, int a_Size) override; virtual void SendData(const char * a_Data, size_t a_Size) override;
void SendCompass(const cWorld & a_World); void SendCompass(const cWorld & a_World);

View File

@ -794,7 +794,7 @@ AString cProtocolRecognizer::GetAuthServerID(void)
void cProtocolRecognizer::SendData(const char * a_Data, int a_Size) void cProtocolRecognizer::SendData(const char * a_Data, size_t a_Size)
{ {
// This is used only when handling the server ping // This is used only when handling the server ping
m_Client->SendData(a_Data, a_Size); m_Client->SendData(a_Data, a_Size);
@ -854,7 +854,7 @@ bool cProtocolRecognizer::TryRecognizeProtocol(void)
// This must be a lengthed protocol, try if it has the entire initial handshake packet: // This must be a lengthed protocol, try if it has the entire initial handshake packet:
m_Buffer.ResetRead(); m_Buffer.ResetRead();
UInt32 PacketLen; UInt32 PacketLen;
UInt32 ReadSoFar = m_Buffer.GetReadableSpace(); UInt32 ReadSoFar = (UInt32)m_Buffer.GetReadableSpace();
if (!m_Buffer.ReadVarInt(PacketLen)) if (!m_Buffer.ReadVarInt(PacketLen))
{ {
// Not enough bytes for the packet length, keep waiting // Not enough bytes for the packet length, keep waiting
@ -931,7 +931,7 @@ bool cProtocolRecognizer::TryRecognizeLengthlessProtocol(void)
bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRemaining) bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRemaining)
{ {
UInt32 PacketType; UInt32 PacketType;
UInt32 NumBytesRead = m_Buffer.GetReadableSpace(); UInt32 NumBytesRead = (UInt32)m_Buffer.GetReadableSpace();
if (!m_Buffer.ReadVarInt(PacketType)) if (!m_Buffer.ReadVarInt(PacketType))
{ {
return false; return false;
@ -962,7 +962,7 @@ bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRema
m_Buffer.ReadBEShort(ServerPort); m_Buffer.ReadBEShort(ServerPort);
m_Buffer.ReadVarInt(NextState); m_Buffer.ReadVarInt(NextState);
m_Buffer.CommitRead(); m_Buffer.CommitRead();
m_Protocol = new cProtocol172(m_Client, ServerAddress, ServerPort, NextState); m_Protocol = new cProtocol172(m_Client, ServerAddress, (UInt16)ServerPort, NextState);
return true; return true;
} }
} }

View File

@ -133,7 +133,7 @@ public:
virtual AString GetAuthServerID(void) override; virtual AString GetAuthServerID(void) override;
virtual void SendData(const char * a_Data, int a_Size) override; virtual void SendData(const char * a_Data, size_t a_Size) override;
protected: protected:
cProtocol * m_Protocol; //< The recognized protocol cProtocol * m_Protocol; //< The recognized protocol

View File

@ -531,32 +531,32 @@ AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a
format binary data this way: format binary data this way:
00001234: 31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 1234567890abcdef 00001234: 31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 1234567890abcdef
*/ */
AString & CreateHexDump(AString & a_Out, const void * a_Data, int a_Size, int a_LineLength) AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, size_t a_BytesPerLine)
{ {
ASSERT(a_LineLength <= 120); // Due to using a fixed size line buffer; increase line[]'s size to lift this max ASSERT(a_BytesPerLine <= 120); // Due to using a fixed size line buffer; increase line[]'s size to lift this max
char line[512]; char line[512];
char * p; char * p;
char * q; char * q;
a_Out.reserve(a_Size / a_LineLength * (18 + 6 * a_LineLength)); a_Out.reserve(a_Size / a_BytesPerLine * (18 + 6 * a_BytesPerLine));
for (int i = 0; i < a_Size; i += a_LineLength) for (size_t i = 0; i < a_Size; i += a_BytesPerLine)
{ {
int k = a_Size - i; size_t k = a_Size - i;
if (k > a_LineLength) if (k > a_BytesPerLine)
{ {
k = a_LineLength; k = a_BytesPerLine;
} }
#ifdef _MSC_VER #ifdef _MSC_VER
// MSVC provides a "secure" version of sprintf() // MSVC provides a "secure" version of sprintf()
int Count = sprintf_s(line, sizeof(line), "%08x:", i); int Count = sprintf_s(line, sizeof(line), "%08x:", (unsigned)i);
#else #else
int Count = sprintf(line, "%08x:", i); int Count = sprintf(line, "%08x:", (unsigned)i);
#endif #endif
// Remove the terminating NULL / leftover garbage in line, after the sprintf-ed value // Remove the terminating NULL / leftover garbage in line, after the sprintf-ed value
memset(line + Count, 32, sizeof(line) - Count); memset(line + Count, 32, sizeof(line) - Count);
p = line + 10; p = line + 10;
q = p + 2 + a_LineLength * 3 + 1; q = p + 2 + a_BytesPerLine * 3 + 1;
for (int j = 0; j < k; j++) for (size_t j = 0; j < k; j++)
{ {
unsigned char c = ((unsigned char *)a_Data)[i + j]; unsigned char c = ((unsigned char *)a_Data)[i + j];
p[0] = HEX(c >> 4); p[0] = HEX(c >> 4);

View File

@ -64,7 +64,7 @@ extern AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString &
extern AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a_UTF16); extern AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a_UTF16);
/// Creates a nicely formatted HEX dump of the given memory block. Max a_BytesPerLine is 120 /// Creates a nicely formatted HEX dump of the given memory block. Max a_BytesPerLine is 120
extern AString & CreateHexDump(AString & a_Out, const void * a_Data, int a_Size, int a_BytesPerLine); extern AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, size_t a_BytesPerLine);
/// Returns a copy of a_Message with all quotes and backslashes escaped by a backslash /// Returns a copy of a_Message with all quotes and backslashes escaped by a backslash
extern AString EscapeString(const AString & a_Message); // tolua_export extern AString EscapeString(const AString & a_Message); // tolua_export

View File

@ -122,33 +122,33 @@ public:
int GetRoot(void) const {return 0; } int GetRoot(void) const {return 0; }
/** Returns the first child of the specified tag, or -1 if none / not applicable. */ /** Returns the first child of the specified tag, or -1 if none / not applicable. */
int GetFirstChild (int a_Tag) const { return m_Tags[a_Tag].m_FirstChild; } int GetFirstChild (int a_Tag) const { return m_Tags[(size_t)a_Tag].m_FirstChild; }
/** Returns the last child of the specified tag, or -1 if none / not applicable. */ /** Returns the last child of the specified tag, or -1 if none / not applicable. */
int GetLastChild (int a_Tag) const { return m_Tags[a_Tag].m_LastChild; } int GetLastChild (int a_Tag) const { return m_Tags[(size_t)a_Tag].m_LastChild; }
/** Returns the next sibling of the specified tag, or -1 if none. */ /** Returns the next sibling of the specified tag, or -1 if none. */
int GetNextSibling(int a_Tag) const { return m_Tags[a_Tag].m_NextSibling; } int GetNextSibling(int a_Tag) const { return m_Tags[(size_t)a_Tag].m_NextSibling; }
/** Returns the previous sibling of the specified tag, or -1 if none. */ /** Returns the previous sibling of the specified tag, or -1 if none. */
int GetPrevSibling(int a_Tag) const { return m_Tags[a_Tag].m_PrevSibling; } int GetPrevSibling(int a_Tag) const { return m_Tags[(size_t)a_Tag].m_PrevSibling; }
/** Returns the length of the tag's data, in bytes. /** Returns the length of the tag's data, in bytes.
Not valid for Compound or List tags! */ Not valid for Compound or List tags! */
int GetDataLength (int a_Tag) const int GetDataLength (int a_Tag) const
{ {
ASSERT(m_Tags[a_Tag].m_Type != TAG_List); ASSERT(m_Tags[(size_t)a_Tag].m_Type != TAG_List);
ASSERT(m_Tags[a_Tag].m_Type != TAG_Compound); ASSERT(m_Tags[(size_t)a_Tag].m_Type != TAG_Compound);
return m_Tags[a_Tag].m_DataLength; return m_Tags[(size_t)a_Tag].m_DataLength;
} }
/** Returns the data stored in this tag. /** Returns the data stored in this tag.
Not valid for Compound or List tags! */ Not valid for Compound or List tags! */
const char * GetData(int a_Tag) const const char * GetData(int a_Tag) const
{ {
ASSERT(m_Tags[a_Tag].m_Type != TAG_List); ASSERT(m_Tags[(size_t)a_Tag].m_Type != TAG_List);
ASSERT(m_Tags[a_Tag].m_Type != TAG_Compound); ASSERT(m_Tags[(size_t)a_Tag].m_Type != TAG_Compound);
return m_Data + m_Tags[a_Tag].m_DataStart; return m_Data + m_Tags[(size_t)a_Tag].m_DataStart;
} }
/** Returns the direct child tag of the specified name, or -1 if no such tag. */ /** Returns the direct child tag of the specified name, or -1 if no such tag. */
@ -163,47 +163,47 @@ public:
/** Returns the child tag of the specified path (Name1\Name2\Name3...), or -1 if no such tag. */ /** Returns the child tag of the specified path (Name1\Name2\Name3...), or -1 if no such tag. */
int FindTagByPath(int a_Tag, const AString & a_Path) const; int FindTagByPath(int a_Tag, const AString & a_Path) const;
eTagType GetType(int a_Tag) const { return m_Tags[a_Tag].m_Type; } eTagType GetType(int a_Tag) const { return m_Tags[(size_t)a_Tag].m_Type; }
/** Returns the children type for a List tag; undefined on other tags. If list empty, returns TAG_End. */ /** Returns the children type for a List tag; undefined on other tags. If list empty, returns TAG_End. */
eTagType GetChildrenType(int a_Tag) const eTagType GetChildrenType(int a_Tag) const
{ {
ASSERT(m_Tags[a_Tag].m_Type == TAG_List); ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_List);
return (m_Tags[a_Tag].m_FirstChild < 0) ? TAG_End : m_Tags[m_Tags[a_Tag].m_FirstChild].m_Type; return (m_Tags[(size_t)a_Tag].m_FirstChild < 0) ? TAG_End : m_Tags[(size_t)m_Tags[(size_t)a_Tag].m_FirstChild].m_Type;
} }
/** Returns the value stored in a Byte tag. Not valid for any other tag type. */ /** Returns the value stored in a Byte tag. Not valid for any other tag type. */
inline unsigned char GetByte(int a_Tag) const inline unsigned char GetByte(int a_Tag) const
{ {
ASSERT(m_Tags[a_Tag].m_Type == TAG_Byte); ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_Byte);
return (unsigned char)(m_Data[m_Tags[a_Tag].m_DataStart]); return (unsigned char)(m_Data[(size_t)m_Tags[(size_t)a_Tag].m_DataStart]);
} }
/** Returns the value stored in a Short tag. Not valid for any other tag type. */ /** Returns the value stored in a Short tag. Not valid for any other tag type. */
inline Int16 GetShort(int a_Tag) const inline Int16 GetShort(int a_Tag) const
{ {
ASSERT(m_Tags[a_Tag].m_Type == TAG_Short); ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_Short);
return GetBEShort(m_Data + m_Tags[a_Tag].m_DataStart); return GetBEShort(m_Data + m_Tags[(size_t)a_Tag].m_DataStart);
} }
/** Returns the value stored in an Int tag. Not valid for any other tag type. */ /** Returns the value stored in an Int tag. Not valid for any other tag type. */
inline Int32 GetInt(int a_Tag) const inline Int32 GetInt(int a_Tag) const
{ {
ASSERT(m_Tags[a_Tag].m_Type == TAG_Int); ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_Int);
return GetBEInt(m_Data + m_Tags[a_Tag].m_DataStart); return GetBEInt(m_Data + m_Tags[(size_t)a_Tag].m_DataStart);
} }
/** Returns the value stored in a Long tag. Not valid for any other tag type. */ /** Returns the value stored in a Long tag. Not valid for any other tag type. */
inline Int64 GetLong(int a_Tag) const inline Int64 GetLong(int a_Tag) const
{ {
ASSERT(m_Tags[a_Tag].m_Type == TAG_Long); ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_Long);
return NetworkToHostLong8(m_Data + m_Tags[a_Tag].m_DataStart); return NetworkToHostLong8(m_Data + m_Tags[(size_t)a_Tag].m_DataStart);
} }
/** Returns the value stored in a Float tag. Not valid for any other tag type. */ /** Returns the value stored in a Float tag. Not valid for any other tag type. */
inline float GetFloat(int a_Tag) const inline float GetFloat(int a_Tag) const
{ {
ASSERT(m_Tags[a_Tag].m_Type == TAG_Float); ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_Float);
// Cause a compile-time error if sizeof(float) != 4 // Cause a compile-time error if sizeof(float) != 4
// If your platform produces a compiler error here, you'll need to add code that manually decodes 32-bit floats // If your platform produces a compiler error here, you'll need to add code that manually decodes 32-bit floats
@ -212,7 +212,7 @@ public:
UNUSED(Check1); UNUSED(Check1);
UNUSED(Check2); UNUSED(Check2);
Int32 i = GetBEInt(m_Data + m_Tags[a_Tag].m_DataStart); Int32 i = GetBEInt(m_Data + m_Tags[(size_t)a_Tag].m_DataStart);
float f; float f;
memcpy(&f, &i, sizeof(f)); memcpy(&f, &i, sizeof(f));
return f; return f;
@ -228,16 +228,16 @@ public:
UNUSED(Check1); UNUSED(Check1);
UNUSED(Check2); UNUSED(Check2);
ASSERT(m_Tags[a_Tag].m_Type == TAG_Double); ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_Double);
return NetworkToHostDouble8(m_Data + m_Tags[a_Tag].m_DataStart); return NetworkToHostDouble8(m_Data + m_Tags[(size_t)a_Tag].m_DataStart);
} }
/** Returns the value stored in a String tag. Not valid for any other tag type. */ /** Returns the value stored in a String tag. Not valid for any other tag type. */
inline AString GetString(int a_Tag) const inline AString GetString(int a_Tag) const
{ {
ASSERT(m_Tags[a_Tag].m_Type == TAG_String); ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_String);
AString res; AString res;
res.assign(m_Data + m_Tags[a_Tag].m_DataStart, m_Tags[a_Tag].m_DataLength); res.assign(m_Data + m_Tags[(size_t)a_Tag].m_DataStart, m_Tags[(size_t)a_Tag].m_DataLength);
return res; return res;
} }
@ -245,7 +245,7 @@ public:
inline AString GetName(int a_Tag) const inline AString GetName(int a_Tag) const
{ {
AString res; AString res;
res.assign(m_Data + m_Tags[a_Tag].m_NameStart, m_Tags[a_Tag].m_NameLength); res.assign(m_Data + m_Tags[(size_t)a_Tag].m_NameStart, m_Tags[(size_t)a_Tag].m_NameLength);
return res; return res;
} }