Merge branch 'master' into Slabs
This commit is contained in:
commit
7da308a7e1
@ -551,7 +551,22 @@ end
|
|||||||
{{cPlayer}}:SendMessage(), {{cWorld}}:BroadcastChat() and {{cRoot}}:BroadcastChat().</p>
|
{{cPlayer}}:SendMessage(), {{cWorld}}:BroadcastChat() and {{cRoot}}:BroadcastChat().</p>
|
||||||
<p>
|
<p>
|
||||||
Note that most of the functions in this class are so-called modifiers - they modify the object and
|
Note that most of the functions in this class are so-called modifiers - they modify the object and
|
||||||
then return the object itself, so that they can be chained one after another.
|
then return the object itself, so that they can be chained one after another. See the Chaining
|
||||||
|
example below for details.</p>
|
||||||
|
<p>
|
||||||
|
Each part of the composite chat message takes a "Style" parameter, this is a string that describes
|
||||||
|
the formatting. It uses the following strings, concatenated together:
|
||||||
|
<table>
|
||||||
|
<tr><th>String</th><th>Style</th></tr>
|
||||||
|
<tr><td>b</td><td>Bold text</td></tr>
|
||||||
|
<tr><td>i</td><td>Italic text</td></tr>
|
||||||
|
<tr><td>u</td><td>Underlined text</td></tr>
|
||||||
|
<tr><td>s</td><td>Strikethrough text</td></tr>
|
||||||
|
<tr><td>o</td><td>Obfuscated text</td></tr>
|
||||||
|
<tr><td>@X</td><td>color X (X is 0 - 9 or a - f, same as dye meta</td></tr>
|
||||||
|
</table>
|
||||||
|
The following picture, taken from MineCraft Wiki, illustrates the color codes:</p>
|
||||||
|
<img src="http://hydra-media.cursecdn.com/minecraft.gamepedia.com/4/4c/Colors.png?version=34a0f56789a95326e1f7d82047b12232" />
|
||||||
]],
|
]],
|
||||||
Functions =
|
Functions =
|
||||||
{
|
{
|
||||||
@ -565,6 +580,7 @@ end
|
|||||||
AddTextPart = { Params = "Text, [Style]", Return = "self", Notes = "Adds a regular text. Chaining." },
|
AddTextPart = { Params = "Text, [Style]", Return = "self", Notes = "Adds a regular text. Chaining." },
|
||||||
AddUrlPart = { Params = "Text, Url, [Style]", Return = "self", Notes = "Adds a text which, when clicked, opens up a browser at the specified URL. Chaining." },
|
AddUrlPart = { Params = "Text, Url, [Style]", Return = "self", Notes = "Adds a text which, when clicked, opens up a browser at the specified URL. Chaining." },
|
||||||
Clear = { Params = "", Return = "", Notes = "Removes all parts from this object" },
|
Clear = { Params = "", Return = "", Notes = "Removes all parts from this object" },
|
||||||
|
ExtractText = { Params = "", Return = "string", Notes = "Returns the text from the parts that comprises the human-readable data. Used for older protocols that don't support composite chat and for console-logging." },
|
||||||
GetMessageType = { Params = "", Return = "MessageType", Notes = "Returns the MessageType (mtXXX constant) that is associated with this message. When sent to a player, the message will be formatted according to this message type and the player's settings (adding \"[INFO]\" prefix etc.)" },
|
GetMessageType = { Params = "", Return = "MessageType", Notes = "Returns the MessageType (mtXXX constant) that is associated with this message. When sent to a player, the message will be formatted according to this message type and the player's settings (adding \"[INFO]\" prefix etc.)" },
|
||||||
ParseText = { Params = "Text", Return = "self", Notes = "Adds text, while recognizing http and https URLs and old-style formatting codes (\"@2\"). Chaining." },
|
ParseText = { Params = "Text", Return = "self", Notes = "Adds text, while recognizing http and https URLs and old-style formatting codes (\"@2\"). Chaining." },
|
||||||
SetMessageType = { Params = "MessageType", Return = "self", Notes = "Sets the MessageType (mtXXX constant) that is associated with this message. When sent to a player, the message will be formatted according to this message type and the player's settings (adding \"[INFO]\" prefix etc.) Chaining." },
|
SetMessageType = { Params = "MessageType", Return = "self", Notes = "Sets the MessageType (mtXXX constant) that is associated with this message. When sent to a player, the message will be formatted according to this message type and the player's settings (adding \"[INFO]\" prefix etc.) Chaining." },
|
||||||
@ -2200,7 +2216,7 @@ end
|
|||||||
CastThunderbolt = { Params = "X, Y, Z", Return = "", Notes = "Creates a thunderbolt at the specified coords" },
|
CastThunderbolt = { Params = "X, Y, Z", Return = "", Notes = "Creates a thunderbolt at the specified coords" },
|
||||||
ChangeWeather = { Params = "", Return = "", Notes = "Forces the weather to change in the next game tick. Weather is changed according to the normal rules: wSunny <-> wRain <-> wStorm" },
|
ChangeWeather = { Params = "", Return = "", Notes = "Forces the weather to change in the next game tick. Weather is changed according to the normal rules: wSunny <-> wRain <-> wStorm" },
|
||||||
ChunkStay = { Params = "ChunkCoordTable, OnChunkAvailable, OnAllChunksAvailable", Return = "", Notes = "Queues the specified chunks to be loaded or generated and calls the specified callbacks once they are loaded. ChunkCoordTable is an arra-table of chunk coords, each coord being a table of 2 numbers: { {Chunk1x, Chunk1z}, {Chunk2x, Chunk2z}, ...}. When any of those chunks are made available (including being available at the start of this call), the OnChunkAvailable() callback is called. When all the chunks are available, the OnAllChunksAvailable() callback is called. The function signatures are: <pre class=\"prettyprint lang-lua\">function OnChunkAvailable(ChunkX, ChunkZ)\nfunction OnAllChunksAvailable()</pre> All return values from the callbacks are ignored." },
|
ChunkStay = { Params = "ChunkCoordTable, OnChunkAvailable, OnAllChunksAvailable", Return = "", Notes = "Queues the specified chunks to be loaded or generated and calls the specified callbacks once they are loaded. ChunkCoordTable is an arra-table of chunk coords, each coord being a table of 2 numbers: { {Chunk1x, Chunk1z}, {Chunk2x, Chunk2z}, ...}. When any of those chunks are made available (including being available at the start of this call), the OnChunkAvailable() callback is called. When all the chunks are available, the OnAllChunksAvailable() callback is called. The function signatures are: <pre class=\"prettyprint lang-lua\">function OnChunkAvailable(ChunkX, ChunkZ)\nfunction OnAllChunksAvailable()</pre> All return values from the callbacks are ignored." },
|
||||||
CreateProjectile = { Params = "X, Y, Z, {{cProjectileEntity|ProjectileKind}}, {{cEntity|Creator}}, [{{Vector3d|Speed}}]", Return = "", Notes = "Creates a new projectile of the specified kind at the specified coords. The projectile's creator is set to Creator (may be nil). Optional speed indicates the initial speed for the projectile." },
|
CreateProjectile = { Params = "X, Y, Z, {{cProjectileEntity|ProjectileKind}}, {{cEntity|Creator}}, {{cItem|Originating Item}}, [{{Vector3d|Speed}}]", Return = "", Notes = "Creates a new projectile of the specified kind at the specified coords. The projectile's creator is set to Creator (may be nil). The item that created the projectile entity, commonly the {{cPlayer|player}}'s currently equipped item, is used at present for fireworks to correctly set their entity metadata. It is not used for any other projectile. Optional speed indicates the initial speed for the projectile." },
|
||||||
DigBlock = { Params = "X, Y, Z", Return = "", Notes = "Replaces the specified block with air, without dropping the usual pickups for the block. Wakes up the simulators for the block and its neighbors." },
|
DigBlock = { Params = "X, Y, Z", Return = "", Notes = "Replaces the specified block with air, without dropping the usual pickups for the block. Wakes up the simulators for the block and its neighbors." },
|
||||||
DoExplosionAt = { Params = "Force, X, Y, Z, CanCauseFire, Source, SourceData", Return = "", Notes = "Creates an explosion of the specified relative force in the specified position. If CanCauseFire is set, the explosion will set blocks on fire, too. The Source parameter specifies the source of the explosion, one of the esXXX constants. The SourceData parameter is specific to each source type, usually it provides more info about the source." },
|
DoExplosionAt = { Params = "Force, X, Y, Z, CanCauseFire, Source, SourceData", Return = "", Notes = "Creates an explosion of the specified relative force in the specified position. If CanCauseFire is set, the explosion will set blocks on fire, too. The Source parameter specifies the source of the explosion, one of the esXXX constants. The SourceData parameter is specific to each source type, usually it provides more info about the source." },
|
||||||
DoWithBlockEntityAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a block entity at the specified coords, calls the CallbackFunction with the {{cBlockEntity}} parameter representing the block entity. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cBlockEntity|BlockEntity}}, [CallbackData])</pre> The function returns false if there is no block entity, or if there is, it returns the bool value that the callback has returned. Use {{tolua}}.cast() to cast the Callback's BlockEntity parameter to the correct {{cBlockEntity}} descendant." },
|
DoWithBlockEntityAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a block entity at the specified coords, calls the CallbackFunction with the {{cBlockEntity}} parameter representing the block entity. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cBlockEntity|BlockEntity}}, [CallbackData])</pre> The function returns false if there is no block entity, or if there is, it returns the bool value that the callback has returned. Use {{tolua}}.cast() to cast the Callback's BlockEntity parameter to the correct {{cBlockEntity}} descendant." },
|
||||||
|
@ -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);
|
||||||
|
@ -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);
|
||||||
|
131
src/Blocks/BlockBigFlower.h
Normal file
131
src/Blocks/BlockBigFlower.h
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "BlockHandler.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class cBlockBigFlowerHandler :
|
||||||
|
public cBlockHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef cBlockHandler super;
|
||||||
|
|
||||||
|
cBlockBigFlowerHandler(BLOCKTYPE a_BlockType)
|
||||||
|
: cBlockHandler(a_BlockType)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual void DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ) override
|
||||||
|
{
|
||||||
|
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
|
||||||
|
if (Meta & 0x8)
|
||||||
|
{
|
||||||
|
super::DropBlock(a_ChunkInterface, a_WorldInterface, a_BlockPluginInterface, a_Digger, a_BlockX, a_BlockY - 1, a_BlockZ);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
super::DropBlock(a_ChunkInterface, a_WorldInterface, a_BlockPluginInterface, a_Digger, a_BlockX, a_BlockY, a_BlockZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
||||||
|
{
|
||||||
|
NIBBLETYPE Meta = a_BlockMeta & 0x7;
|
||||||
|
|
||||||
|
if ((Meta == 2) || (Meta == 3))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
a_Pickups.push_back(cItem(E_BLOCK_BIG_FLOWER, 1, Meta));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override
|
||||||
|
{
|
||||||
|
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
|
||||||
|
if (Meta & 0x8)
|
||||||
|
{
|
||||||
|
Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY - 1, a_BlockZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
NIBBLETYPE FlowerMeta = Meta & 0x7;
|
||||||
|
if (!a_Player->IsGameModeCreative())
|
||||||
|
{
|
||||||
|
if (((FlowerMeta == 2) || (FlowerMeta == 3)) && (a_Player->GetEquippedItem().m_ItemType == E_ITEM_SHEARS))
|
||||||
|
{
|
||||||
|
MTRand r1;
|
||||||
|
if (r1.randInt(10) == 5)
|
||||||
|
{
|
||||||
|
cItems Pickups;
|
||||||
|
if (FlowerMeta == 2)
|
||||||
|
{
|
||||||
|
Pickups.Add(E_BLOCK_TALL_GRASS, 2, 1);
|
||||||
|
}
|
||||||
|
else if (FlowerMeta == 3)
|
||||||
|
{
|
||||||
|
Pickups.Add(E_BLOCK_TALL_GRASS, 2, 2);
|
||||||
|
}
|
||||||
|
a_WorldInterface.SpawnItemPickups(Pickups, a_BlockX, a_BlockY, a_BlockZ);
|
||||||
|
}
|
||||||
|
a_Player->UseEquippedItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
|
||||||
|
{
|
||||||
|
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR) && (a_RelY < cChunkDef::Height) && ((a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ) == E_BLOCK_AIR) || (a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ) == E_BLOCK_BIG_FLOWER)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual void OnPlacedByPlayer(
|
||||||
|
cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player,
|
||||||
|
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
|
||||||
|
int a_CursorX, int a_CursorY, int a_CursorZ,
|
||||||
|
BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta
|
||||||
|
) override
|
||||||
|
{
|
||||||
|
int Meta = (((int)floor(a_Player->GetYaw() * 4.0 / 360.0 + 0.5) & 0x3) + 2) % 4;
|
||||||
|
a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY + 1, a_BlockZ, m_BlockType, 0x8 | Meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override
|
||||||
|
{
|
||||||
|
NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
|
||||||
|
|
||||||
|
if (OldMeta & 0x8)
|
||||||
|
{
|
||||||
|
// Was upper part of flower
|
||||||
|
if (a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ) == m_BlockType)
|
||||||
|
{
|
||||||
|
a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Was lower part
|
||||||
|
if (a_ChunkInterface.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ) == m_BlockType)
|
||||||
|
{
|
||||||
|
a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY + 1, a_BlockZ, E_BLOCK_AIR, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual const char * GetStepSound(void) override
|
||||||
|
{
|
||||||
|
return "step.grass";
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
|||||||
#include "../Chunk.h"
|
#include "../Chunk.h"
|
||||||
#include "BlockAnvil.h"
|
#include "BlockAnvil.h"
|
||||||
#include "BlockBed.h"
|
#include "BlockBed.h"
|
||||||
|
#include "BlockBigFlower.h"
|
||||||
#include "BlockBrewingStand.h"
|
#include "BlockBrewingStand.h"
|
||||||
#include "BlockButton.h"
|
#include "BlockButton.h"
|
||||||
#include "BlockCactus.h"
|
#include "BlockCactus.h"
|
||||||
@ -90,6 +91,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
|
|||||||
case E_BLOCK_ACTIVATOR_RAIL: return new cBlockRailHandler (a_BlockType);
|
case E_BLOCK_ACTIVATOR_RAIL: return new cBlockRailHandler (a_BlockType);
|
||||||
case E_BLOCK_ANVIL: return new cBlockAnvilHandler (a_BlockType);
|
case E_BLOCK_ANVIL: return new cBlockAnvilHandler (a_BlockType);
|
||||||
case E_BLOCK_BED: return new cBlockBedHandler (a_BlockType);
|
case E_BLOCK_BED: return new cBlockBedHandler (a_BlockType);
|
||||||
|
case E_BLOCK_BIG_FLOWER: return new cBlockBigFlowerHandler (a_BlockType);
|
||||||
case E_BLOCK_BIRCH_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType);
|
case E_BLOCK_BIRCH_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType);
|
||||||
case E_BLOCK_BREWING_STAND: return new cBlockBrewingStandHandler (a_BlockType);
|
case E_BLOCK_BREWING_STAND: return new cBlockBrewingStandHandler (a_BlockType);
|
||||||
case E_BLOCK_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType);
|
case E_BLOCK_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType);
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -15,14 +15,14 @@ public:
|
|||||||
: cBlockHandler(a_BlockType)
|
: cBlockHandler(a_BlockType)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual bool DoesIgnoreBuildCollision(void) override
|
virtual bool DoesIgnoreBuildCollision(void) override
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
||||||
{
|
{
|
||||||
// Drop seeds, sometimes
|
// Drop seeds, sometimes
|
||||||
@ -34,11 +34,25 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override
|
||||||
|
{
|
||||||
|
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
|
||||||
|
|
||||||
|
if ((!a_Player->IsGameModeCreative()) && (a_Player->GetEquippedItem().m_ItemType == E_ITEM_SHEARS))
|
||||||
|
{
|
||||||
|
cItems Pickups;
|
||||||
|
Pickups.Add(E_BLOCK_TALL_GRASS, 1, Meta);
|
||||||
|
a_WorldInterface.SpawnItemPickups(Pickups, a_BlockX, a_BlockY, a_BlockZ);
|
||||||
|
}
|
||||||
|
a_Player->UseEquippedItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
|
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
|
||||||
{
|
{
|
||||||
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR));
|
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual const char * GetStepSound(void) override
|
virtual const char * GetStepSound(void) override
|
||||||
{
|
{
|
||||||
|
@ -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;
|
||||||
@ -2633,7 +2633,7 @@ void cClientHandle::PacketError(unsigned char a_PacketType)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cClientHandle::DataReceived(const char * a_Data, int a_Size)
|
void cClientHandle::DataReceived(const char * a_Data, size_t a_Size)
|
||||||
{
|
{
|
||||||
// Data is received from the client, store it in the buffer to be processed by the Tick thread:
|
// Data is received from the client, store it in the buffer to be processed by the Tick thread:
|
||||||
m_TimeSinceLastPacket = 0;
|
m_TimeSinceLastPacket = 0;
|
||||||
|
@ -225,7 +225,7 @@ 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);
|
||||||
@ -362,7 +362,7 @@ private:
|
|||||||
void HandleCommandBlockMessage(const char * a_Data, unsigned int a_Length);
|
void HandleCommandBlockMessage(const char * a_Data, unsigned int a_Length);
|
||||||
|
|
||||||
// cSocketThreads::cCallback overrides:
|
// cSocketThreads::cCallback overrides:
|
||||||
virtual void DataReceived (const char * a_Data, int a_Size) override; // Data is received from the client
|
virtual void DataReceived (const char * a_Data, size_t a_Size) override; // Data is received from the client
|
||||||
virtual void GetOutgoingData(AString & a_Data) override; // Data can be sent to client
|
virtual void GetOutgoingData(AString & a_Data) override; // Data can be sent to client
|
||||||
virtual void SocketClosed (void) override; // The socket has been closed for any reason
|
virtual void SocketClosed (void) override; // The socket has been closed for any reason
|
||||||
}; // tolua_export
|
}; // tolua_export
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1469,7 +1469,7 @@ void cEntity::SteerVehicle(float a_Forward, float a_Sideways)
|
|||||||
Vector3d cEntity::GetLookVector(void) const
|
Vector3d cEntity::GetLookVector(void) const
|
||||||
{
|
{
|
||||||
Matrix4d m;
|
Matrix4d m;
|
||||||
m.Init(Vector3f(), 0, m_Rot.x, -m_Rot.y);
|
m.Init(Vector3d(), 0, m_Rot.x, -m_Rot.y);
|
||||||
Vector3d Look = m.Transform(Vector3d(0, 0, 1));
|
Vector3d Look = m.Transform(Vector3d(0, 0, 1));
|
||||||
return Look;
|
return Look;
|
||||||
}
|
}
|
||||||
|
@ -1124,6 +1124,17 @@ void cPlayer::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cPlayer::SendRotation(double a_YawDegrees, double a_PitchDegrees)
|
||||||
|
{
|
||||||
|
SetYaw(a_YawDegrees);
|
||||||
|
SetPitch(a_PitchDegrees);
|
||||||
|
m_ClientHandle->SendPlayerMoveLook();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Vector3d cPlayer::GetThrowStartPos(void) const
|
Vector3d cPlayer::GetThrowStartPos(void) const
|
||||||
{
|
{
|
||||||
Vector3d res = GetEyePosition();
|
Vector3d res = GetEyePosition();
|
||||||
|
@ -129,6 +129,12 @@ public:
|
|||||||
|
|
||||||
// tolua_begin
|
// tolua_begin
|
||||||
|
|
||||||
|
/** Sends the "look" packet to the player, forcing them to set their rotation to the specified values.
|
||||||
|
a_YawDegrees is clipped to range [-180, +180),
|
||||||
|
a_PitchDegrees is clipped to range [-180, +180) but the client only uses [-90, +90]
|
||||||
|
*/
|
||||||
|
void SendRotation(double a_YawDegrees, double a_PitchDegrees);
|
||||||
|
|
||||||
/** Returns the position where projectiles thrown by this player should start, player eye position + adjustment */
|
/** Returns the position where projectiles thrown by this player should start, player eye position + adjustment */
|
||||||
Vector3d GetThrowStartPos(void) const;
|
Vector3d GetThrowStartPos(void) const;
|
||||||
|
|
||||||
|
@ -371,13 +371,14 @@ void cProjectileEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
|
|||||||
SetYawFromSpeed();
|
SetYawFromSpeed();
|
||||||
SetPitchFromSpeed();
|
SetPitchFromSpeed();
|
||||||
|
|
||||||
// DEBUG:
|
/*
|
||||||
LOGD("Projectile %d: pos {%.02f, %.02f, %.02f}, speed {%.02f, %.02f, %.02f}, rot {%.02f, %.02f}",
|
LOGD("Projectile %d: pos {%.02f, %.02f, %.02f}, speed {%.02f, %.02f, %.02f}, rot {%.02f, %.02f}",
|
||||||
m_UniqueID,
|
m_UniqueID,
|
||||||
GetPosX(), GetPosY(), GetPosZ(),
|
GetPosX(), GetPosY(), GetPosZ(),
|
||||||
GetSpeedX(), GetSpeedY(), GetSpeedZ(),
|
GetSpeedX(), GetSpeedY(), GetSpeedZ(),
|
||||||
GetYaw(), GetPitch()
|
GetYaw(), GetPitch()
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ cEnvelopeParser::cEnvelopeParser(cCallbacks & a_Callbacks) :
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int cEnvelopeParser::Parse(const char * a_Data, int a_Size)
|
size_t cEnvelopeParser::Parse(const char * a_Data, size_t a_Size)
|
||||||
{
|
{
|
||||||
if (!m_IsInHeaders)
|
if (!m_IsInHeaders)
|
||||||
{
|
{
|
||||||
@ -55,7 +55,7 @@ int cEnvelopeParser::Parse(const char * a_Data, int a_Size)
|
|||||||
{
|
{
|
||||||
// An error has occurred
|
// An error has occurred
|
||||||
m_IsInHeaders = false;
|
m_IsInHeaders = false;
|
||||||
return -1;
|
return AString::npos;
|
||||||
}
|
}
|
||||||
Last = idxCRLF + 2;
|
Last = idxCRLF + 2;
|
||||||
idxCRLF = m_IncomingData.find("\r\n", idxCRLF + 2);
|
idxCRLF = m_IncomingData.find("\r\n", idxCRLF + 2);
|
||||||
|
@ -22,7 +22,7 @@ public:
|
|||||||
// Force a virtual destructor in descendants:
|
// Force a virtual destructor in descendants:
|
||||||
virtual ~cCallbacks() {}
|
virtual ~cCallbacks() {}
|
||||||
|
|
||||||
/// Called when a full header line is parsed
|
/** Called when a full header line is parsed */
|
||||||
virtual void OnHeaderLine(const AString & a_Key, const AString & a_Value) = 0;
|
virtual void OnHeaderLine(const AString & a_Key, const AString & a_Value) = 0;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
@ -30,40 +30,41 @@ public:
|
|||||||
cEnvelopeParser(cCallbacks & a_Callbacks);
|
cEnvelopeParser(cCallbacks & a_Callbacks);
|
||||||
|
|
||||||
/** Parses the incoming data.
|
/** Parses the incoming data.
|
||||||
Returns the number of bytes consumed from the input. The bytes not consumed are not part of the envelope header
|
Returns the number of bytes consumed from the input. The bytes not consumed are not part of the envelope header.
|
||||||
|
Returns AString::npos on error
|
||||||
*/
|
*/
|
||||||
int Parse(const char * a_Data, int a_Size);
|
size_t Parse(const char * a_Data, size_t a_Size);
|
||||||
|
|
||||||
/// Makes the parser forget everything parsed so far, so that it can be reused for parsing another datastream
|
/** Makes the parser forget everything parsed so far, so that it can be reused for parsing another datastream */
|
||||||
void Reset(void);
|
void Reset(void);
|
||||||
|
|
||||||
/// Returns true if more input is expected for the envelope header
|
/** Returns true if more input is expected for the envelope header */
|
||||||
bool IsInHeaders(void) const { return m_IsInHeaders; }
|
bool IsInHeaders(void) const { return m_IsInHeaders; }
|
||||||
|
|
||||||
/// Sets the IsInHeaders flag; used by cMultipartParser to simplify the parser initial conditions
|
/** Sets the IsInHeaders flag; used by cMultipartParser to simplify the parser initial conditions */
|
||||||
void SetIsInHeaders(bool a_IsInHeaders) { m_IsInHeaders = a_IsInHeaders; }
|
void SetIsInHeaders(bool a_IsInHeaders) { m_IsInHeaders = a_IsInHeaders; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Callbacks to call for the various events
|
/** Callbacks to call for the various events */
|
||||||
cCallbacks & m_Callbacks;
|
cCallbacks & m_Callbacks;
|
||||||
|
|
||||||
/// Set to true while the parser is still parsing the envelope headers. Once set to true, the parser will not consume any more data.
|
/** Set to true while the parser is still parsing the envelope headers. Once set to true, the parser will not consume any more data. */
|
||||||
bool m_IsInHeaders;
|
bool m_IsInHeaders;
|
||||||
|
|
||||||
/// Buffer for the incoming data until it is parsed
|
/** Buffer for the incoming data until it is parsed */
|
||||||
AString m_IncomingData;
|
AString m_IncomingData;
|
||||||
|
|
||||||
/// Holds the last parsed key; used for line-wrapped values
|
/** Holds the last parsed key; used for line-wrapped values */
|
||||||
AString m_LastKey;
|
AString m_LastKey;
|
||||||
|
|
||||||
/// Holds the last parsed value; used for line-wrapped values
|
/** Holds the last parsed value; used for line-wrapped values */
|
||||||
AString m_LastValue;
|
AString m_LastValue;
|
||||||
|
|
||||||
|
|
||||||
/// Notifies the callback of the key/value stored in m_LastKey/m_LastValue, then erases them
|
/** Notifies the callback of the key/value stored in m_LastKey/m_LastValue, then erases them */
|
||||||
void NotifyLast(void);
|
void NotifyLast(void);
|
||||||
|
|
||||||
/// Parses one line of header data. Returns true if successful
|
/** Parses one line of header data. Returns true if successful */
|
||||||
bool ParseLine(const char * a_Data, size_t a_Size);
|
bool ParseLine(const char * a_Data, size_t a_Size);
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -67,10 +67,10 @@ void cHTTPConnection::Send(const cHTTPResponse & a_Response)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cHTTPConnection::Send(const void * a_Data, int a_Size)
|
void cHTTPConnection::Send(const void * a_Data, size_t a_Size)
|
||||||
{
|
{
|
||||||
ASSERT(m_State == wcsSendingResp);
|
ASSERT(m_State == wcsSendingResp);
|
||||||
AppendPrintf(m_OutgoingData, "%x\r\n", a_Size);
|
AppendPrintf(m_OutgoingData, SIZE_T_FMT "\r\n", a_Size);
|
||||||
m_OutgoingData.append((const char *)a_Data, a_Size);
|
m_OutgoingData.append((const char *)a_Data, a_Size);
|
||||||
m_OutgoingData.append("\r\n");
|
m_OutgoingData.append("\r\n");
|
||||||
m_HTTPServer.NotifyConnectionWrite(*this);
|
m_HTTPServer.NotifyConnectionWrite(*this);
|
||||||
@ -144,7 +144,7 @@ void cHTTPConnection::Terminate(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cHTTPConnection::DataReceived(const char * a_Data, int a_Size)
|
void cHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
|
||||||
{
|
{
|
||||||
switch (m_State)
|
switch (m_State)
|
||||||
{
|
{
|
||||||
@ -155,8 +155,8 @@ void cHTTPConnection::DataReceived(const char * a_Data, int a_Size)
|
|||||||
m_CurrentRequest = new cHTTPRequest;
|
m_CurrentRequest = new cHTTPRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BytesConsumed = m_CurrentRequest->ParseHeaders(a_Data, a_Size);
|
size_t BytesConsumed = m_CurrentRequest->ParseHeaders(a_Data, a_Size);
|
||||||
if (BytesConsumed < 0)
|
if (BytesConsumed == AString::npos)
|
||||||
{
|
{
|
||||||
delete m_CurrentRequest;
|
delete m_CurrentRequest;
|
||||||
m_CurrentRequest = NULL;
|
m_CurrentRequest = NULL;
|
||||||
@ -174,7 +174,7 @@ void cHTTPConnection::DataReceived(const char * a_Data, int a_Size)
|
|||||||
m_State = wcsRecvBody;
|
m_State = wcsRecvBody;
|
||||||
m_HTTPServer.NewRequest(*this, *m_CurrentRequest);
|
m_HTTPServer.NewRequest(*this, *m_CurrentRequest);
|
||||||
m_CurrentRequestBodyRemaining = m_CurrentRequest->GetContentLength();
|
m_CurrentRequestBodyRemaining = m_CurrentRequest->GetContentLength();
|
||||||
if (m_CurrentRequestBodyRemaining < 0)
|
if (m_CurrentRequestBodyRemaining == AString::npos)
|
||||||
{
|
{
|
||||||
// The body length was not specified in the request, assume zero
|
// The body length was not specified in the request, assume zero
|
||||||
m_CurrentRequestBodyRemaining = 0;
|
m_CurrentRequestBodyRemaining = 0;
|
||||||
@ -197,7 +197,7 @@ void cHTTPConnection::DataReceived(const char * a_Data, int a_Size)
|
|||||||
ASSERT(m_CurrentRequest != NULL);
|
ASSERT(m_CurrentRequest != NULL);
|
||||||
if (m_CurrentRequestBodyRemaining > 0)
|
if (m_CurrentRequestBodyRemaining > 0)
|
||||||
{
|
{
|
||||||
int BytesToConsume = std::min(m_CurrentRequestBodyRemaining, a_Size);
|
size_t BytesToConsume = std::min(m_CurrentRequestBodyRemaining, (size_t)a_Size);
|
||||||
m_HTTPServer.RequestBody(*this, *m_CurrentRequest, a_Data, BytesToConsume);
|
m_HTTPServer.RequestBody(*this, *m_CurrentRequest, a_Data, BytesToConsume);
|
||||||
m_CurrentRequestBodyRemaining -= BytesToConsume;
|
m_CurrentRequestBodyRemaining -= BytesToConsume;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ public:
|
|||||||
void Send(const cHTTPResponse & a_Response);
|
void Send(const cHTTPResponse & a_Response);
|
||||||
|
|
||||||
/** Sends the data as the response (may be called multiple times) */
|
/** Sends the data as the response (may be called multiple times) */
|
||||||
void Send(const void * a_Data, int a_Size);
|
void Send(const void * a_Data, size_t a_Size);
|
||||||
|
|
||||||
/** Sends the data as the response (may be called multiple times) */
|
/** Sends the data as the response (may be called multiple times) */
|
||||||
void Send(const AString & a_Data) { Send(a_Data.data(), a_Data.size()); }
|
void Send(const AString & a_Data) { Send(a_Data.data(), a_Data.size()); }
|
||||||
@ -87,11 +87,11 @@ protected:
|
|||||||
|
|
||||||
/** Number of bytes that remain to read for the complete body of the message to be received.
|
/** Number of bytes that remain to read for the complete body of the message to be received.
|
||||||
Valid only in wcsRecvBody */
|
Valid only in wcsRecvBody */
|
||||||
int m_CurrentRequestBodyRemaining;
|
size_t m_CurrentRequestBodyRemaining;
|
||||||
|
|
||||||
|
|
||||||
// cSocketThreads::cCallback overrides:
|
// cSocketThreads::cCallback overrides:
|
||||||
virtual void DataReceived (const char * a_Data, int a_Size) override; // Data is received from the client
|
virtual void DataReceived (const char * a_Data, size_t a_Size) override; // Data is received from the client
|
||||||
virtual void GetOutgoingData(AString & a_Data) override; // Data can be sent to client
|
virtual void GetOutgoingData(AString & a_Data) override; // Data can be sent to client
|
||||||
virtual void SocketClosed (void) override; // The socket has been closed for any reason
|
virtual void SocketClosed (void) override; // The socket has been closed for any reason
|
||||||
} ;
|
} ;
|
||||||
|
@ -52,7 +52,7 @@ cHTTPFormParser::cHTTPFormParser(cHTTPRequest & a_Request, cCallbacks & a_Callba
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
cHTTPFormParser::cHTTPFormParser(eKind a_Kind, const char * a_Data, int a_Size, cCallbacks & a_Callbacks) :
|
cHTTPFormParser::cHTTPFormParser(eKind a_Kind, const char * a_Data, size_t a_Size, cCallbacks & a_Callbacks) :
|
||||||
m_Callbacks(a_Callbacks),
|
m_Callbacks(a_Callbacks),
|
||||||
m_Kind(a_Kind),
|
m_Kind(a_Kind),
|
||||||
m_IsValid(true)
|
m_IsValid(true)
|
||||||
@ -64,7 +64,7 @@ cHTTPFormParser::cHTTPFormParser(eKind a_Kind, const char * a_Data, int a_Size,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cHTTPFormParser::Parse(const char * a_Data, int a_Size)
|
void cHTTPFormParser::Parse(const char * a_Data, size_t a_Size)
|
||||||
{
|
{
|
||||||
if (!m_IsValid)
|
if (!m_IsValid)
|
||||||
{
|
{
|
||||||
@ -243,7 +243,7 @@ void cHTTPFormParser::OnPartHeader(const AString & a_Key, const AString & a_Valu
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cHTTPFormParser::OnPartData(const char * a_Data, int a_Size)
|
void cHTTPFormParser::OnPartData(const char * a_Data, size_t a_Size)
|
||||||
{
|
{
|
||||||
if (m_CurrentPartName.empty())
|
if (m_CurrentPartName.empty())
|
||||||
{
|
{
|
||||||
|
@ -43,7 +43,7 @@ public:
|
|||||||
virtual void OnFileStart(cHTTPFormParser & a_Parser, const AString & a_FileName) = 0;
|
virtual void OnFileStart(cHTTPFormParser & a_Parser, const AString & a_FileName) = 0;
|
||||||
|
|
||||||
/// Called when more file data has come for the current file in the form data
|
/// Called when more file data has come for the current file in the form data
|
||||||
virtual void OnFileData(cHTTPFormParser & a_Parser, const char * a_Data, int a_Size) = 0;
|
virtual void OnFileData(cHTTPFormParser & a_Parser, const char * a_Data, size_t a_Size) = 0;
|
||||||
|
|
||||||
/// Called when the current file part has ended in the form data
|
/// Called when the current file part has ended in the form data
|
||||||
virtual void OnFileEnd(cHTTPFormParser & a_Parser) = 0;
|
virtual void OnFileEnd(cHTTPFormParser & a_Parser) = 0;
|
||||||
@ -54,10 +54,10 @@ public:
|
|||||||
cHTTPFormParser(cHTTPRequest & a_Request, cCallbacks & a_Callbacks);
|
cHTTPFormParser(cHTTPRequest & a_Request, cCallbacks & a_Callbacks);
|
||||||
|
|
||||||
/// Creates a parser with the specified content type that reads data from a string
|
/// Creates a parser with the specified content type that reads data from a string
|
||||||
cHTTPFormParser(eKind a_Kind, const char * a_Data, int a_Size, cCallbacks & a_Callbacks);
|
cHTTPFormParser(eKind a_Kind, const char * a_Data, size_t a_Size, cCallbacks & a_Callbacks);
|
||||||
|
|
||||||
/// Adds more data into the parser, as the request body is received
|
/// Adds more data into the parser, as the request body is received
|
||||||
void Parse(const char * a_Data, int a_Size);
|
void Parse(const char * a_Data, size_t a_Size);
|
||||||
|
|
||||||
/** Notifies that there's no more data incoming and the parser should finish its parsing.
|
/** Notifies that there's no more data incoming and the parser should finish its parsing.
|
||||||
Returns true if parsing successful
|
Returns true if parsing successful
|
||||||
@ -106,7 +106,7 @@ protected:
|
|||||||
// cMultipartParser::cCallbacks overrides:
|
// cMultipartParser::cCallbacks overrides:
|
||||||
virtual void OnPartStart (void) override;
|
virtual void OnPartStart (void) override;
|
||||||
virtual void OnPartHeader(const AString & a_Key, const AString & a_Value) override;
|
virtual void OnPartHeader(const AString & a_Key, const AString & a_Value) override;
|
||||||
virtual void OnPartData (const char * a_Data, int a_Size) override;
|
virtual void OnPartData (const char * a_Data, size_t a_Size) override;
|
||||||
virtual void OnPartEnd (void) override;
|
virtual void OnPartEnd (void) override;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
cHTTPMessage::cHTTPMessage(eKind a_Kind) :
|
cHTTPMessage::cHTTPMessage(eKind a_Kind) :
|
||||||
m_Kind(a_Kind),
|
m_Kind(a_Kind),
|
||||||
m_ContentLength(-1)
|
m_ContentLength(AString::npos)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,23 +81,23 @@ cHTTPRequest::cHTTPRequest(void) :
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int cHTTPRequest::ParseHeaders(const char * a_Data, int a_Size)
|
size_t cHTTPRequest::ParseHeaders(const char * a_Data, size_t a_Size)
|
||||||
{
|
{
|
||||||
if (!m_IsValid)
|
if (!m_IsValid)
|
||||||
{
|
{
|
||||||
return -1;
|
return AString::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_Method.empty())
|
if (m_Method.empty())
|
||||||
{
|
{
|
||||||
// The first line hasn't been processed yet
|
// The first line hasn't been processed yet
|
||||||
int res = ParseRequestLine(a_Data, a_Size);
|
size_t res = ParseRequestLine(a_Data, a_Size);
|
||||||
if ((res < 0) || (res == a_Size))
|
if ((res == AString::npos) || (res == a_Size))
|
||||||
{
|
{
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
int res2 = m_EnvelopeParser.Parse(a_Data + res, a_Size - res);
|
size_t res2 = m_EnvelopeParser.Parse(a_Data + res, a_Size - res);
|
||||||
if (res2 < 0)
|
if (res2 == AString::npos)
|
||||||
{
|
{
|
||||||
m_IsValid = false;
|
m_IsValid = false;
|
||||||
return res2;
|
return res2;
|
||||||
@ -107,8 +107,8 @@ int cHTTPRequest::ParseHeaders(const char * a_Data, int a_Size)
|
|||||||
|
|
||||||
if (m_EnvelopeParser.IsInHeaders())
|
if (m_EnvelopeParser.IsInHeaders())
|
||||||
{
|
{
|
||||||
int res = m_EnvelopeParser.Parse(a_Data, a_Size);
|
size_t res = m_EnvelopeParser.Parse(a_Data, a_Size);
|
||||||
if (res < 0)
|
if (res == AString::npos)
|
||||||
{
|
{
|
||||||
m_IsValid = false;
|
m_IsValid = false;
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ AString cHTTPRequest::GetBareURL(void) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int cHTTPRequest::ParseRequestLine(const char * a_Data, int a_Size)
|
size_t cHTTPRequest::ParseRequestLine(const char * a_Data, size_t a_Size)
|
||||||
{
|
{
|
||||||
m_IncomingHeaderData.append(a_Data, a_Size);
|
m_IncomingHeaderData.append(a_Data, a_Size);
|
||||||
size_t IdxEnd = m_IncomingHeaderData.size();
|
size_t IdxEnd = m_IncomingHeaderData.size();
|
||||||
@ -158,7 +158,7 @@ int cHTTPRequest::ParseRequestLine(const char * a_Data, int a_Size)
|
|||||||
if (LineStart >= IdxEnd)
|
if (LineStart >= IdxEnd)
|
||||||
{
|
{
|
||||||
m_IsValid = false;
|
m_IsValid = false;
|
||||||
return -1;
|
return AString::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
int NumSpaces = 0;
|
int NumSpaces = 0;
|
||||||
@ -186,7 +186,7 @@ int cHTTPRequest::ParseRequestLine(const char * a_Data, int a_Size)
|
|||||||
{
|
{
|
||||||
// Too many spaces in the request
|
// Too many spaces in the request
|
||||||
m_IsValid = false;
|
m_IsValid = false;
|
||||||
return -1;
|
return AString::npos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NumSpaces += 1;
|
NumSpaces += 1;
|
||||||
@ -198,13 +198,13 @@ int cHTTPRequest::ParseRequestLine(const char * a_Data, int a_Size)
|
|||||||
{
|
{
|
||||||
// LF too early, without a CR, without two preceeding spaces or too soon after the second space
|
// LF too early, without a CR, without two preceeding spaces or too soon after the second space
|
||||||
m_IsValid = false;
|
m_IsValid = false;
|
||||||
return -1;
|
return AString::npos;
|
||||||
}
|
}
|
||||||
// Check that there's HTTP/version at the end
|
// Check that there's HTTP/version at the end
|
||||||
if (strncmp(a_Data + URLEnd + 1, "HTTP/1.", 7) != 0)
|
if (strncmp(a_Data + URLEnd + 1, "HTTP/1.", 7) != 0)
|
||||||
{
|
{
|
||||||
m_IsValid = false;
|
m_IsValid = false;
|
||||||
return -1;
|
return AString::npos;
|
||||||
}
|
}
|
||||||
m_Method = m_IncomingHeaderData.substr(LineStart, MethodEnd - LineStart);
|
m_Method = m_IncomingHeaderData.substr(LineStart, MethodEnd - LineStart);
|
||||||
m_URL = m_IncomingHeaderData.substr(MethodEnd + 1, URLEnd - MethodEnd - 1);
|
m_URL = m_IncomingHeaderData.substr(MethodEnd + 1, URLEnd - MethodEnd - 1);
|
||||||
|
@ -39,10 +39,10 @@ public:
|
|||||||
void AddHeader(const AString & a_Key, const AString & a_Value);
|
void AddHeader(const AString & a_Key, const AString & a_Value);
|
||||||
|
|
||||||
void SetContentType (const AString & a_ContentType) { m_ContentType = a_ContentType; }
|
void SetContentType (const AString & a_ContentType) { m_ContentType = a_ContentType; }
|
||||||
void SetContentLength(int a_ContentLength) { m_ContentLength = a_ContentLength; }
|
void SetContentLength(size_t a_ContentLength) { m_ContentLength = a_ContentLength; }
|
||||||
|
|
||||||
const AString & GetContentType (void) const { return m_ContentType; }
|
const AString & GetContentType (void) const { return m_ContentType; }
|
||||||
int GetContentLength(void) const { return m_ContentLength; }
|
size_t GetContentLength(void) const { return m_ContentLength; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef std::map<AString, AString> cNameValueMap;
|
typedef std::map<AString, AString> cNameValueMap;
|
||||||
@ -54,8 +54,10 @@ protected:
|
|||||||
/** Type of the content; parsed by AddHeader(), set directly by SetContentLength() */
|
/** Type of the content; parsed by AddHeader(), set directly by SetContentLength() */
|
||||||
AString m_ContentType;
|
AString m_ContentType;
|
||||||
|
|
||||||
/** Length of the content that is to be received. -1 when the object is created, parsed by AddHeader() or set directly by SetContentLength() */
|
/** Length of the content that is to be received.
|
||||||
int m_ContentLength;
|
AString::npos when the object is created.
|
||||||
|
Parsed by AddHeader() or set directly by SetContentLength() */
|
||||||
|
size_t m_ContentLength;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
@ -72,12 +74,12 @@ public:
|
|||||||
cHTTPRequest(void);
|
cHTTPRequest(void);
|
||||||
|
|
||||||
/** Parses the request line and then headers from the received data.
|
/** Parses the request line and then headers from the received data.
|
||||||
Returns the number of bytes consumed or a negative number for error
|
Returns the number of bytes consumed or AString::npos number for error
|
||||||
*/
|
*/
|
||||||
int ParseHeaders(const char * a_Data, int a_Size);
|
size_t ParseHeaders(const char * a_Data, size_t a_Size);
|
||||||
|
|
||||||
/** Returns true if the request did contain a Content-Length header */
|
/** Returns true if the request did contain a Content-Length header */
|
||||||
bool HasReceivedContentLength(void) const { return (m_ContentLength >= 0); }
|
bool HasReceivedContentLength(void) const { return (m_ContentLength != AString::npos); }
|
||||||
|
|
||||||
/** Returns the method used in the request */
|
/** Returns the method used in the request */
|
||||||
const AString & GetMethod(void) const { return m_Method; }
|
const AString & GetMethod(void) const { return m_Method; }
|
||||||
@ -145,7 +147,7 @@ protected:
|
|||||||
/** Parses the incoming data for the first line (RequestLine)
|
/** Parses the incoming data for the first line (RequestLine)
|
||||||
Returns the number of bytes consumed, or -1 for an error
|
Returns the number of bytes consumed, or -1 for an error
|
||||||
*/
|
*/
|
||||||
int ParseRequestLine(const char * a_Data, int a_Size);
|
size_t ParseRequestLine(const char * a_Data, size_t a_Size);
|
||||||
|
|
||||||
// cEnvelopeParser::cCallbacks overrides:
|
// cEnvelopeParser::cCallbacks overrides:
|
||||||
virtual void OnHeaderLine(const AString & a_Key, const AString & a_Value) override;
|
virtual void OnHeaderLine(const AString & a_Key, const AString & a_Value) override;
|
||||||
|
@ -38,7 +38,7 @@ class cDebugCallbacks :
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual void OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size) override
|
virtual void OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size) override
|
||||||
{
|
{
|
||||||
UNUSED(a_Connection);
|
UNUSED(a_Connection);
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ class cDebugCallbacks :
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual void OnFileData(cHTTPFormParser & a_Parser, const char * a_Data, int a_Size) override
|
virtual void OnFileData(cHTTPFormParser & a_Parser, const char * a_Data, size_t a_Size) override
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
@ -242,7 +242,7 @@ void cHTTPServer::NewRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Re
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cHTTPServer::RequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size)
|
void cHTTPServer::RequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size)
|
||||||
{
|
{
|
||||||
m_Callbacks->OnRequestBody(a_Connection, a_Request, a_Data, a_Size);
|
m_Callbacks->OnRequestBody(a_Connection, a_Request, a_Data, a_Size);
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,9 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual void OnRequestBegun(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) = 0;
|
virtual void OnRequestBegun(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) = 0;
|
||||||
|
|
||||||
/// Called when another part of request body has arrived.
|
/** Called when another part of request body has arrived.
|
||||||
virtual void OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size) = 0;
|
May be called multiple times for a single request. */
|
||||||
|
virtual void OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size) = 0;
|
||||||
|
|
||||||
/// Called when the request body has been fully received in previous calls to OnRequestBody()
|
/// Called when the request body has been fully received in previous calls to OnRequestBody()
|
||||||
virtual void OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) = 0;
|
virtual void OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) = 0;
|
||||||
@ -90,8 +91,9 @@ protected:
|
|||||||
/// Called by cHTTPConnection when it finishes parsing the request header
|
/// Called by cHTTPConnection when it finishes parsing the request header
|
||||||
void NewRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request);
|
void NewRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request);
|
||||||
|
|
||||||
/// Called by cHTTPConenction when it receives more data for the request body
|
/** Called by cHTTPConenction when it receives more data for the request body.
|
||||||
void RequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size);
|
May be called multiple times for a single request. */
|
||||||
|
void RequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size);
|
||||||
|
|
||||||
/// Called by cHTTPConnection when it detects that the request has finished (all of its body has been received)
|
/// Called by cHTTPConnection when it detects that the request has finished (all of its body has been received)
|
||||||
void RequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request);
|
void RequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request);
|
||||||
|
@ -97,8 +97,6 @@ cMultipartParser::cMultipartParser(const AString & a_ContentType, cCallbacks & a
|
|||||||
m_EnvelopeParser(*this),
|
m_EnvelopeParser(*this),
|
||||||
m_HasHadData(false)
|
m_HasHadData(false)
|
||||||
{
|
{
|
||||||
static AString s_Multipart = "multipart/";
|
|
||||||
|
|
||||||
// Check that the content type is multipart:
|
// Check that the content type is multipart:
|
||||||
AString ContentType(a_ContentType);
|
AString ContentType(a_ContentType);
|
||||||
if (strncmp(ContentType.c_str(), "multipart/", 10) != 0)
|
if (strncmp(ContentType.c_str(), "multipart/", 10) != 0)
|
||||||
@ -146,7 +144,7 @@ cMultipartParser::cMultipartParser(const AString & a_ContentType, cCallbacks & a
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cMultipartParser::Parse(const char * a_Data, int a_Size)
|
void cMultipartParser::Parse(const char * a_Data, size_t a_Size)
|
||||||
{
|
{
|
||||||
// Skip parsing if invalid
|
// Skip parsing if invalid
|
||||||
if (!m_IsValid)
|
if (!m_IsValid)
|
||||||
@ -160,8 +158,8 @@ void cMultipartParser::Parse(const char * a_Data, int a_Size)
|
|||||||
{
|
{
|
||||||
if (m_EnvelopeParser.IsInHeaders())
|
if (m_EnvelopeParser.IsInHeaders())
|
||||||
{
|
{
|
||||||
int BytesConsumed = m_EnvelopeParser.Parse(m_IncomingData.data(), m_IncomingData.size());
|
size_t BytesConsumed = m_EnvelopeParser.Parse(m_IncomingData.data(), m_IncomingData.size());
|
||||||
if (BytesConsumed < 0)
|
if (BytesConsumed == AString::npos)
|
||||||
{
|
{
|
||||||
m_IsValid = false;
|
m_IsValid = false;
|
||||||
return;
|
return;
|
||||||
|
@ -25,50 +25,50 @@ public:
|
|||||||
// Force a virtual destructor in descendants:
|
// Force a virtual destructor in descendants:
|
||||||
virtual ~cCallbacks() {}
|
virtual ~cCallbacks() {}
|
||||||
|
|
||||||
/// Called when a new part starts
|
/** Called when a new part starts */
|
||||||
virtual void OnPartStart(void) = 0;
|
virtual void OnPartStart(void) = 0;
|
||||||
|
|
||||||
/// Called when a complete header line is received for a part
|
/** Called when a complete header line is received for a part */
|
||||||
virtual void OnPartHeader(const AString & a_Key, const AString & a_Value) = 0;
|
virtual void OnPartHeader(const AString & a_Key, const AString & a_Value) = 0;
|
||||||
|
|
||||||
/// Called when body for a part is received
|
/** Called when body for a part is received */
|
||||||
virtual void OnPartData(const char * a_Data, int a_Size) = 0;
|
virtual void OnPartData(const char * a_Data, size_t a_Size) = 0;
|
||||||
|
|
||||||
/// Called when the current part ends
|
/** Called when the current part ends */
|
||||||
virtual void OnPartEnd(void) = 0;
|
virtual void OnPartEnd(void) = 0;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
/// Creates the parser, expects to find the boundary in a_ContentType
|
/** Creates the parser, expects to find the boundary in a_ContentType */
|
||||||
cMultipartParser(const AString & a_ContentType, cCallbacks & a_Callbacks);
|
cMultipartParser(const AString & a_ContentType, cCallbacks & a_Callbacks);
|
||||||
|
|
||||||
/// Parses more incoming data
|
/** Parses more incoming data */
|
||||||
void Parse(const char * a_Data, int a_Size);
|
void Parse(const char * a_Data, size_t a_Size);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// The callbacks to call for various parsing events
|
/** The callbacks to call for various parsing events */
|
||||||
cCallbacks & m_Callbacks;
|
cCallbacks & m_Callbacks;
|
||||||
|
|
||||||
/// True if the data parsed so far is valid; if false, further parsing is skipped
|
/** True if the data parsed so far is valid; if false, further parsing is skipped */
|
||||||
bool m_IsValid;
|
bool m_IsValid;
|
||||||
|
|
||||||
/// Parser for each part's envelope
|
/** Parser for each part's envelope */
|
||||||
cEnvelopeParser m_EnvelopeParser;
|
cEnvelopeParser m_EnvelopeParser;
|
||||||
|
|
||||||
/// Buffer for the incoming data until it is parsed
|
/** Buffer for the incoming data until it is parsed */
|
||||||
AString m_IncomingData;
|
AString m_IncomingData;
|
||||||
|
|
||||||
/// The boundary, excluding both the initial "--" and the terminating CRLF
|
/** The boundary, excluding both the initial "--" and the terminating CRLF */
|
||||||
AString m_Boundary;
|
AString m_Boundary;
|
||||||
|
|
||||||
/// Set to true if some data for the current part has already been signalized to m_Callbacks. Used for proper CRLF inserting.
|
/** Set to true if some data for the current part has already been signalized to m_Callbacks. Used for proper CRLF inserting. */
|
||||||
bool m_HasHadData;
|
bool m_HasHadData;
|
||||||
|
|
||||||
|
|
||||||
/// Parse one line of incoming data. The CRLF has already been stripped from a_Data / a_Size
|
/** Parse one line of incoming data. The CRLF has already been stripped from a_Data / a_Size */
|
||||||
void ParseLine(const char * a_Data, int a_Size);
|
void ParseLine(const char * a_Data, size_t a_Size);
|
||||||
|
|
||||||
/// Parse one line of incoming data in the headers section of a part. The CRLF has already been stripped from a_Data / a_Size
|
/** Parse one line of incoming data in the headers section of a part. The CRLF has already been stripped from a_Data / a_Size */
|
||||||
void ParseHeaderLine(const char * a_Data, int a_Size);
|
void ParseHeaderLine(const char * a_Data, size_t a_Size);
|
||||||
|
|
||||||
// cEnvelopeParser overrides:
|
// cEnvelopeParser overrides:
|
||||||
virtual void OnHeaderLine(const AString & a_Key, const AString & a_Value) override;
|
virtual void OnHeaderLine(const AString & a_Key, const AString & a_Value) override;
|
||||||
|
@ -24,7 +24,7 @@ public:
|
|||||||
|
|
||||||
// Now try parsing char-by-char, to debug transitions across datachunk boundaries:
|
// Now try parsing char-by-char, to debug transitions across datachunk boundaries:
|
||||||
cNameValueParser Parser2;
|
cNameValueParser Parser2;
|
||||||
for (int i = 0; i < sizeof(Data) - 1; i++)
|
for (size_t i = 0; i < sizeof(Data) - 1; i++)
|
||||||
{
|
{
|
||||||
Parser2.Parse(Data + i, 1);
|
Parser2.Parse(Data + i, 1);
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ cNameValueParser::cNameValueParser(bool a_AllowsKeyOnly) :
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
cNameValueParser::cNameValueParser(const char * a_Data, int a_Size, bool a_AllowsKeyOnly) :
|
cNameValueParser::cNameValueParser(const char * a_Data, size_t a_Size, bool a_AllowsKeyOnly) :
|
||||||
m_State(psKeySpace),
|
m_State(psKeySpace),
|
||||||
m_AllowsKeyOnly(a_AllowsKeyOnly)
|
m_AllowsKeyOnly(a_AllowsKeyOnly)
|
||||||
{
|
{
|
||||||
@ -93,12 +93,12 @@ cNameValueParser::cNameValueParser(const char * a_Data, int a_Size, bool a_Allow
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cNameValueParser::Parse(const char * a_Data, int a_Size)
|
void cNameValueParser::Parse(const char * a_Data, size_t a_Size)
|
||||||
{
|
{
|
||||||
ASSERT(m_State != psFinished); // Calling Parse() after Finish() is wrong!
|
ASSERT(m_State != psFinished); // Calling Parse() after Finish() is wrong!
|
||||||
|
|
||||||
int Last = 0;
|
int Last = 0;
|
||||||
for (int i = 0; i < a_Size;)
|
for (size_t i = 0; i < a_Size;)
|
||||||
{
|
{
|
||||||
switch (m_State)
|
switch (m_State)
|
||||||
{
|
{
|
||||||
|
@ -21,10 +21,10 @@ public:
|
|||||||
cNameValueParser(bool a_AllowsKeyOnly = true);
|
cNameValueParser(bool a_AllowsKeyOnly = true);
|
||||||
|
|
||||||
/// Creates an empty parser, then parses the data given. Doesn't call Finish(), so more data can be parsed later
|
/// Creates an empty parser, then parses the data given. Doesn't call Finish(), so more data can be parsed later
|
||||||
cNameValueParser(const char * a_Data, int a_Size, bool a_AllowsKeyOnly = true);
|
cNameValueParser(const char * a_Data, size_t a_Size, bool a_AllowsKeyOnly = true);
|
||||||
|
|
||||||
/// Parses the data given
|
/// Parses the data given
|
||||||
void Parse(const char * a_Data, int a_Size);
|
void Parse(const char * a_Data, size_t a_Size);
|
||||||
|
|
||||||
/// Notifies the parser that no more data will be coming. Returns true if the parser state is valid
|
/// Notifies the parser that no more data will be coming. Returns true if the parser state is valid
|
||||||
bool Finish(void);
|
bool Finish(void);
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -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,
|
||||||
|
@ -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;
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ public:
|
|||||||
virtual ~cCallback() {}
|
virtual ~cCallback() {}
|
||||||
|
|
||||||
/** Called when data is received from the remote party */
|
/** Called when data is received from the remote party */
|
||||||
virtual void DataReceived(const char * a_Data, int a_Size) = 0;
|
virtual void DataReceived(const char * a_Data, size_t a_Size) = 0;
|
||||||
|
|
||||||
/** Called when data can be sent to remote party
|
/** Called when data can be sent to remote party
|
||||||
The function is supposed to *set* outgoing data to a_Data (overwrite) */
|
The function is supposed to *set* outgoing data to a_Data (overwrite) */
|
||||||
|
@ -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
|
||||||
|
@ -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());
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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));
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -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;
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -169,7 +169,7 @@ cRCONServer::cConnection::cConnection(cRCONServer & a_RCONServer, cSocket & a_So
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cRCONServer::cConnection::DataReceived(const char * a_Data, int a_Size)
|
void cRCONServer::cConnection::DataReceived(const char * a_Data, size_t a_Size)
|
||||||
{
|
{
|
||||||
// Append data to the buffer:
|
// Append data to the buffer:
|
||||||
m_Buffer.append(a_Data, a_Size);
|
m_Buffer.append(a_Data, a_Size);
|
||||||
|
@ -65,7 +65,7 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
// cSocketThreads::cCallback overrides:
|
// cSocketThreads::cCallback overrides:
|
||||||
virtual void DataReceived(const char * a_Data, int a_Size) override;
|
virtual void DataReceived(const char * a_Data, size_t a_Size) override;
|
||||||
virtual void GetOutgoingData(AString & a_Data) override;
|
virtual void GetOutgoingData(AString & a_Data) override;
|
||||||
virtual void SocketClosed(void) override;
|
virtual void SocketClosed(void) override;
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
@ -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
|
||||||
|
@ -490,7 +490,7 @@ void cWebAdmin::OnRequestBegun(cHTTPConnection & a_Connection, cHTTPRequest & a_
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cWebAdmin::OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size)
|
void cWebAdmin::OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size)
|
||||||
{
|
{
|
||||||
UNUSED(a_Connection);
|
UNUSED(a_Connection);
|
||||||
cRequestData * Data = (cRequestData *)(a_Request.GetUserData());
|
cRequestData * Data = (cRequestData *)(a_Request.GetUserData());
|
||||||
@ -537,7 +537,7 @@ void cWebAdmin::OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest &
|
|||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// cWebAdmin::cWebadminRequestData
|
// cWebAdmin::cWebadminRequestData
|
||||||
|
|
||||||
void cWebAdmin::cWebadminRequestData::OnBody(const char * a_Data, int a_Size)
|
void cWebAdmin::cWebadminRequestData::OnBody(const char * a_Data, size_t a_Size)
|
||||||
{
|
{
|
||||||
m_Form.Parse(a_Data, a_Size);
|
m_Form.Parse(a_Data, a_Size);
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ protected:
|
|||||||
virtual ~cRequestData() {} // Force a virtual destructor in all descendants
|
virtual ~cRequestData() {} // Force a virtual destructor in all descendants
|
||||||
|
|
||||||
/** Called when a new chunk of body data is received */
|
/** Called when a new chunk of body data is received */
|
||||||
virtual void OnBody(const char * a_Data, int a_Size) = 0;
|
virtual void OnBody(const char * a_Data, size_t a_Size) = 0;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
/** The body handler for requests in the "/webadmin" and "/~webadmin" paths */
|
/** The body handler for requests in the "/webadmin" and "/~webadmin" paths */
|
||||||
@ -169,14 +169,14 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cRequestData overrides:
|
// cRequestData overrides:
|
||||||
virtual void OnBody(const char * a_Data, int a_Size) override;
|
virtual void OnBody(const char * a_Data, size_t a_Size) override;
|
||||||
|
|
||||||
// cHTTPFormParser::cCallbacks overrides. Files are ignored:
|
// cHTTPFormParser::cCallbacks overrides. Files are ignored:
|
||||||
virtual void OnFileStart(cHTTPFormParser &, const AString & a_FileName) override
|
virtual void OnFileStart(cHTTPFormParser &, const AString & a_FileName) override
|
||||||
{
|
{
|
||||||
UNUSED(a_FileName);
|
UNUSED(a_FileName);
|
||||||
}
|
}
|
||||||
virtual void OnFileData(cHTTPFormParser &, const char * a_Data, int a_Size) override
|
virtual void OnFileData(cHTTPFormParser &, const char * a_Data, size_t a_Size) override
|
||||||
{
|
{
|
||||||
UNUSED(a_Data);
|
UNUSED(a_Data);
|
||||||
UNUSED(a_Size);
|
UNUSED(a_Size);
|
||||||
@ -216,7 +216,7 @@ protected:
|
|||||||
|
|
||||||
// cHTTPServer::cCallbacks overrides:
|
// cHTTPServer::cCallbacks overrides:
|
||||||
virtual void OnRequestBegun (cHTTPConnection & a_Connection, cHTTPRequest & a_Request) override;
|
virtual void OnRequestBegun (cHTTPConnection & a_Connection, cHTTPRequest & a_Request) override;
|
||||||
virtual void OnRequestBody (cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size) override;
|
virtual void OnRequestBody (cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size) override;
|
||||||
virtual void OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) override;
|
virtual void OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) override;
|
||||||
} ; // tolua_export
|
} ; // tolua_export
|
||||||
|
|
||||||
|
@ -2993,7 +2993,6 @@ int cWorld::CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProje
|
|||||||
delete Projectile;
|
delete Projectile;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
BroadcastSpawnEntity(*Projectile);
|
|
||||||
return Projectile->GetUniqueID();
|
return Projectile->GetUniqueID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user