mirror of
https://github.com/p2r3/bareiron.git
synced 2025-10-02 07:35:08 +02:00
refactor to use struct instead of byte buffer
This commit is contained in:
39
main.c
39
main.c
@@ -56,21 +56,17 @@ void handlePacket (int client_fd, int length, int packet_id) {
|
|||||||
|
|
||||||
sc_loginPlay(client_fd);
|
sc_loginPlay(client_fd);
|
||||||
|
|
||||||
short x = 8, y = 80, z = 8;
|
PlayerData *player;
|
||||||
int8_t yaw = 0, pitch = 0;
|
if (getPlayerData(client_fd, &player)) break;
|
||||||
restorePlayerPosition(client_fd, &x, &y, &z, &yaw, &pitch);
|
|
||||||
sc_synchronizePlayerPosition(client_fd, x, y, z, yaw * 180 / 127, pitch * 90 / 127);
|
|
||||||
|
|
||||||
short _x = x / 16, _z = z / 16;
|
sc_synchronizePlayerPosition(client_fd, player->x, player->y, player->z, player->yaw * 180 / 127, player->pitch * 90 / 127);
|
||||||
|
|
||||||
uint8_t *inventory = getPlayerInventory(client_fd);
|
for (uint8_t i = 0; i < 41; i ++) {
|
||||||
uint16_t item;
|
sc_setContainerSlot(client_fd, 0, serverSlotToClientSlot(i), player->inventory_count[i], player->inventory_items[i]);
|
||||||
for (uint8_t i = 0; i < 123; i += 3) {
|
|
||||||
memcpy(&item, inventory + i, 2);
|
|
||||||
sc_setContainerSlot(client_fd, 0, serverSlotToClientSlot(i / 3), inventory[i + 2], item);
|
|
||||||
}
|
}
|
||||||
sc_setHeldItem(client_fd, *(inventory - 1));
|
sc_setHeldItem(client_fd, player->hotbar);
|
||||||
|
|
||||||
|
short _x = player->x / 16, _z = player->z / 16;
|
||||||
sc_setDefaultSpawnPosition(client_fd, 8, 80, 8);
|
sc_setDefaultSpawnPosition(client_fd, 8, 80, 8);
|
||||||
sc_startWaitingForChunks(client_fd);
|
sc_startWaitingForChunks(client_fd);
|
||||||
sc_setCenterChunk(client_fd, _x, _z);
|
sc_setCenterChunk(client_fd, _x, _z);
|
||||||
@@ -116,13 +112,13 @@ void handlePacket (int client_fd, int length, int packet_id) {
|
|||||||
|
|
||||||
if (packet_id == 0x1D) cs_setPlayerPosition(client_fd, &x, &y, &z);
|
if (packet_id == 0x1D) cs_setPlayerPosition(client_fd, &x, &y, &z);
|
||||||
else cs_setPlayerPositionAndRotation(client_fd, &x, &y, &z, &yaw, &pitch);
|
else cs_setPlayerPositionAndRotation(client_fd, &x, &y, &z, &yaw, &pitch);
|
||||||
|
|
||||||
short cx = x + 0.5, cy = y, cz = z + 0.5;
|
short cx = x + 0.5, cy = y, cz = z + 0.5;
|
||||||
short px, py, pz;
|
|
||||||
restorePlayerPosition (client_fd, &px, &py, &pz, NULL, NULL);
|
PlayerData *player;
|
||||||
|
if (getPlayerData(client_fd, &player)) break;
|
||||||
|
|
||||||
short _x = (cx < 0 ? cx - 16 : cx) / 16, _z = (cz < 0 ? cz - 16 : cz) / 16;
|
short _x = (cx < 0 ? cx - 16 : cx) / 16, _z = (cz < 0 ? cz - 16 : cz) / 16;
|
||||||
short dx = _x - (px < 0 ? px - 16 : px) / 16, dz = _z - (pz < 0 ? pz - 16 : pz) / 16;
|
short dx = _x - (player->x < 0 ? player->x - 16 : player->x) / 16, dz = _z - (player->z < 0 ? player->z - 16 : player->z) / 16;
|
||||||
|
|
||||||
if (dx != 0 || dz != 0) {
|
if (dx != 0 || dz != 0) {
|
||||||
|
|
||||||
@@ -157,8 +153,13 @@ void handlePacket (int client_fd, int length, int packet_id) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet_id == 0x1D) savePlayerPosition(client_fd, cx, cy, cz);
|
player->x = cx;
|
||||||
else savePlayerPositionAndRotation(client_fd, cx, cy, cz, yaw / 180.0f * 127.0f, pitch / 90.0f * 127.0f);
|
player->y = cy;
|
||||||
|
player->z = cz;
|
||||||
|
if (packet_id == 0x1E) {
|
||||||
|
player->yaw = yaw / 180.0f * 127.0f;
|
||||||
|
player->pitch = pitch / 90.0f * 127.0f;
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -197,7 +198,9 @@ void handlePacket (int client_fd, int length, int packet_id) {
|
|||||||
|
|
||||||
int main () {
|
int main () {
|
||||||
|
|
||||||
memset(block_changes, 0xFF, sizeof(block_changes));
|
for (int i = 0; i < sizeof(block_changes) / sizeof(BlockChange); i ++) {
|
||||||
|
block_changes[i].block = 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
int server_fd, client_fd, opt = 1;
|
int server_fd, client_fd, opt = 1;
|
||||||
struct sockaddr_in server_addr, client_addr;
|
struct sockaddr_in server_addr, client_addr;
|
||||||
|
@@ -9,17 +9,8 @@ ssize_t recv_count;
|
|||||||
uint8_t recv_buffer[256] = {0};
|
uint8_t recv_buffer[256] = {0};
|
||||||
|
|
||||||
uint32_t world_seed = 0xA103DE6C;
|
uint32_t world_seed = 0xA103DE6C;
|
||||||
uint8_t block_changes[50 * 1024];
|
|
||||||
|
BlockChange block_changes[20000];
|
||||||
int block_changes_count = 0;
|
int block_changes_count = 0;
|
||||||
|
|
||||||
uint8_t player_data[(
|
PlayerData player_data[MAX_PLAYERS];
|
||||||
16 + // UUID
|
|
||||||
4 + // File descriptor
|
|
||||||
2 + // X position (short)
|
|
||||||
2 + // Y position (short)
|
|
||||||
2 + // Z position (short)
|
|
||||||
2 + // Angles (both, i8)
|
|
||||||
1 + // Hotbar slot
|
|
||||||
123 // Inventory (u16 id, u8 count)
|
|
||||||
) * MAX_PLAYERS];
|
|
||||||
int player_data_size = 16 + 4 + 2 + 2 + 2 + 2 + 1 + 123;
|
|
||||||
|
@@ -21,19 +21,34 @@ extern ssize_t recv_count;
|
|||||||
extern uint8_t recv_buffer[256];
|
extern uint8_t recv_buffer[256];
|
||||||
|
|
||||||
extern uint32_t world_seed;
|
extern uint32_t world_seed;
|
||||||
extern uint8_t block_changes[50 * 1024];
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
short x;
|
||||||
|
short y;
|
||||||
|
short z;
|
||||||
|
uint8_t block;
|
||||||
|
} BlockChange;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t uuid[16];
|
||||||
|
int client_fd;
|
||||||
|
short x;
|
||||||
|
short y;
|
||||||
|
short z;
|
||||||
|
uint8_t yaw;
|
||||||
|
uint8_t pitch;
|
||||||
|
uint8_t hotbar;
|
||||||
|
uint16_t inventory_items[41];
|
||||||
|
uint8_t inventory_count[41];
|
||||||
|
} PlayerData;
|
||||||
|
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
extern BlockChange block_changes[20000];
|
||||||
extern int block_changes_count;
|
extern int block_changes_count;
|
||||||
|
|
||||||
extern uint8_t player_data[(
|
extern PlayerData player_data[MAX_PLAYERS];
|
||||||
16 + // UUID
|
|
||||||
4 + // File descriptor
|
|
||||||
2 + // X position (short)
|
|
||||||
2 + // Y position (short)
|
|
||||||
2 + // Z position (short)
|
|
||||||
2 + // Angles (both, i8)
|
|
||||||
1 + // Hotbar slot
|
|
||||||
123 // Inventory (u16 id, u8 count)
|
|
||||||
) * MAX_PLAYERS];
|
|
||||||
extern int player_data_size;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -370,33 +370,9 @@ int cs_playerAction (int client_fd) {
|
|||||||
else item = 0;
|
else item = 0;
|
||||||
} else item = B_to_I[block];
|
} else item = B_to_I[block];
|
||||||
|
|
||||||
uint8_t *inventory = getPlayerInventory(client_fd);
|
|
||||||
|
|
||||||
makeBlockChange(x, y, z, 0);
|
makeBlockChange(x, y, z, 0);
|
||||||
|
|
||||||
int slot_pair = -1;
|
if (item) givePlayerItem(client_fd, item);
|
||||||
for (int i = 0; i < 36 * 3; i += 3) {
|
|
||||||
memcpy(&tmp, inventory + i, 2);
|
|
||||||
if (tmp == item && inventory[i+2] < 64) {
|
|
||||||
slot_pair = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (slot_pair == -1) {
|
|
||||||
for (int i = 0; i < 36 * 3; i += 3) {
|
|
||||||
if ((inventory[i] == 0 && inventory[i + 1] == 0) || inventory[i+2] == 0) {
|
|
||||||
slot_pair = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item && slot_pair != -1) {
|
|
||||||
uint8_t slot = serverSlotToClientSlot(slot_pair / 3);
|
|
||||||
memcpy(inventory + slot_pair, &item, 2);
|
|
||||||
sc_setContainerSlot(client_fd, 0, slot, ++inventory[slot_pair + 2], item);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,24 +403,20 @@ int cs_useItemOn (int client_fd) {
|
|||||||
|
|
||||||
int sequence = readVarInt(client_fd);
|
int sequence = readVarInt(client_fd);
|
||||||
|
|
||||||
// first, get pointer to player inventory
|
PlayerData *player;
|
||||||
uint8_t *inventory = getPlayerInventory(client_fd);
|
if (getPlayerData(client_fd, &player)) return 1;
|
||||||
// then, get pointer to selected hotbar slot
|
|
||||||
// the hotbar position is in address (inventory - 1)
|
uint8_t block = I_to_B[player->inventory_items[player->hotbar]];
|
||||||
uint8_t *slot = inventory + (*(inventory - 1)) * 3;
|
|
||||||
// the inventory is split into id-amount pairs, get the amount address
|
|
||||||
uint8_t *amount = slot + 2;
|
|
||||||
// convert the item id to a block id
|
|
||||||
uint8_t block = I_to_B[*(uint16_t *)slot];
|
|
||||||
|
|
||||||
// if the selected item doesn't correspond to a block, exit
|
// if the selected item doesn't correspond to a block, exit
|
||||||
if (block == 0) return 0;
|
if (block == 0) return 0;
|
||||||
// if the selected slot doesn't hold any items, exit
|
// if the selected slot doesn't hold any items, exit
|
||||||
if (*amount == 0) return 0;
|
if (player->inventory_count[player->hotbar] == 0) return 0;
|
||||||
// decrease item amount in selected slot
|
// decrease item amount in selected slot
|
||||||
*amount = *amount - 1;
|
player->inventory_count[player->hotbar] --;
|
||||||
// clear item id in slot if amount is zero
|
// clear item id in slot if amount is zero
|
||||||
if (*amount == 0) *slot = 0;
|
if (player->inventory_count[player->hotbar] == 0)
|
||||||
|
player->inventory_items[player->hotbar] = 0;
|
||||||
|
|
||||||
switch (face) {
|
switch (face) {
|
||||||
case 0: makeBlockChange(x, y - 1, z, block); break;
|
case 0: makeBlockChange(x, y - 1, z, block); break;
|
||||||
@@ -471,7 +443,9 @@ int cs_clickContainer (int client_fd) {
|
|||||||
|
|
||||||
int changes_count = readVarInt(client_fd);
|
int changes_count = readVarInt(client_fd);
|
||||||
|
|
||||||
uint8_t *inventory = getPlayerInventory(client_fd);
|
PlayerData *player;
|
||||||
|
if (getPlayerData(client_fd, &player)) return 1;
|
||||||
|
|
||||||
uint8_t slot, count;
|
uint8_t slot, count;
|
||||||
uint16_t item;
|
uint16_t item;
|
||||||
int tmp;
|
int tmp;
|
||||||
@@ -482,9 +456,8 @@ int cs_clickContainer (int client_fd) {
|
|||||||
|
|
||||||
if (!readByte(client_fd)) { // no item?
|
if (!readByte(client_fd)) { // no item?
|
||||||
if (slot != 255) {
|
if (slot != 255) {
|
||||||
inventory[slot * 3] = 0;
|
player->inventory_items[slot] = 0;
|
||||||
inventory[slot * 3 + 1] = 0;
|
player->inventory_count[slot] = 0;
|
||||||
inventory[slot * 3 + 2] = 0;
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -499,8 +472,8 @@ int cs_clickContainer (int client_fd) {
|
|||||||
recv(client_fd, recv_buffer, tmp, MSG_WAITALL);
|
recv(client_fd, recv_buffer, tmp, MSG_WAITALL);
|
||||||
|
|
||||||
if (item <= 255 && count > 0) {
|
if (item <= 255 && count > 0) {
|
||||||
memcpy(inventory + slot * 3, &item, 2);
|
player->inventory_items[slot] = item;
|
||||||
inventory[slot * 3 + 2] = count;
|
player->inventory_count[slot] = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -543,8 +516,10 @@ int cs_setPlayerPosition (int client_fd, double *x, double *y, double *z) {
|
|||||||
// C->S Set Held Item (serverbound)
|
// C->S Set Held Item (serverbound)
|
||||||
int cs_setHeldItem (int client_fd) {
|
int cs_setHeldItem (int client_fd) {
|
||||||
|
|
||||||
uint8_t *hotbar = getPlayerInventory(client_fd) - 1;
|
PlayerData *player;
|
||||||
*hotbar = (uint8_t)readUint16(client_fd);
|
if (getPlayerData(client_fd, &player)) return 1;
|
||||||
|
|
||||||
|
player->hotbar = (uint8_t)readUint16(client_fd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
175
src/tools.c
175
src/tools.c
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "varnum.h"
|
#include "varnum.h"
|
||||||
|
#include "packets.h"
|
||||||
|
|
||||||
static uint64_t htonll (uint64_t value) {
|
static uint64_t htonll (uint64_t value) {
|
||||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||||
@@ -128,51 +129,24 @@ int getClientIndex (int client_fd) {
|
|||||||
|
|
||||||
int reservePlayerData (int client_fd, char *uuid) {
|
int reservePlayerData (int client_fd, char *uuid) {
|
||||||
|
|
||||||
uint64_t tmp;
|
|
||||||
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
||||||
memcpy(&tmp, player_data + i * player_data_size, 8);
|
if (memcmp(player_data[i].uuid, uuid, 16) == 0) {
|
||||||
if (memcmp(&tmp, uuid, 8) == 0) {
|
player_data[i].client_fd = client_fd;
|
||||||
memcpy(player_data + i * player_data_size + 16, &client_fd, 4);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (tmp == 0) {
|
uint8_t empty = true;
|
||||||
memcpy(player_data + i * player_data_size, uuid, 16);
|
for (uint8_t j = 0; j < 16; j ++) {
|
||||||
memcpy(player_data + i * player_data_size + 16, &client_fd, 4);
|
if (player_data[i].uuid[j] != 0) {
|
||||||
player_data[i * player_data_size + 20] = 8;
|
empty = false;
|
||||||
player_data[i * player_data_size + 22] = 80;
|
|
||||||
player_data[i * player_data_size + 24] = 8;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void clearPlayerFD (int client_fd) {
|
|
||||||
|
|
||||||
int tmp;
|
|
||||||
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
|
||||||
memcpy(&tmp, player_data + i * player_data_size + 16, 4);
|
|
||||||
if (tmp == client_fd) {
|
|
||||||
tmp = 0;
|
|
||||||
memcpy(player_data + i * player_data_size + 16, &tmp, 4);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (empty) {
|
||||||
}
|
player_data[i].client_fd = client_fd;
|
||||||
|
memcpy(player_data[i].uuid, uuid, 16);
|
||||||
int savePlayerPosition (int client_fd, short x, short y, short z) {
|
player_data[i].x = 8;
|
||||||
|
player_data[i].y = 80;
|
||||||
int tmp;
|
player_data[i].z = 8;
|
||||||
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
|
||||||
if (memcmp(&client_fd, player_data + i * player_data_size + 16, 4) == 0) {
|
|
||||||
|
|
||||||
memcpy(player_data + i * player_data_size + 20, &x, 2);
|
|
||||||
memcpy(player_data + i * player_data_size + 22, &y, 2);
|
|
||||||
memcpy(player_data + i * player_data_size + 24, &z, 2);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,59 +155,23 @@ int savePlayerPosition (int client_fd, short x, short y, short z) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int savePlayerPositionAndRotation (int client_fd, short x, short y, short z, int8_t yaw, int8_t pitch) {
|
int getPlayerData (int client_fd, PlayerData **output) {
|
||||||
|
|
||||||
int tmp;
|
|
||||||
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
||||||
if (memcmp(&client_fd, player_data + i * player_data_size + 16, 4) == 0) {
|
if (player_data[i].client_fd == client_fd) {
|
||||||
|
*output = &player_data[i];
|
||||||
memcpy(player_data + i * player_data_size + 20, &x, 2);
|
|
||||||
memcpy(player_data + i * player_data_size + 22, &y, 2);
|
|
||||||
memcpy(player_data + i * player_data_size + 24, &z, 2);
|
|
||||||
|
|
||||||
memcpy(player_data + i * player_data_size + 26, &yaw, 1);
|
|
||||||
memcpy(player_data + i * player_data_size + 27, &pitch, 1);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int restorePlayerPosition (int client_fd, short *x, short *y, short *z, int8_t *yaw, int8_t *pitch) {
|
void clearPlayerFD (int client_fd) {
|
||||||
|
|
||||||
int tmp;
|
|
||||||
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
||||||
if (memcmp(&client_fd, player_data + i * player_data_size + 16, 4) == 0) {
|
if (player_data[i].client_fd == client_fd) {
|
||||||
|
player_data[i].client_fd = 0;
|
||||||
memcpy(x, player_data + i * player_data_size + 20, 2);
|
return;
|
||||||
memcpy(y, player_data + i * player_data_size + 22, 2);
|
|
||||||
memcpy(z, player_data + i * player_data_size + 24, 2);
|
|
||||||
|
|
||||||
if (yaw != NULL) memcpy(yaw, player_data + i * player_data_size + 26, 1);
|
|
||||||
if (pitch != NULL) memcpy(pitch, player_data + i * player_data_size + 27, 1);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t *getPlayerInventory (int client_fd) {
|
|
||||||
|
|
||||||
int tmp;
|
|
||||||
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
|
||||||
if (memcmp(&client_fd, player_data + i * player_data_size + 16, 4) == 0) {
|
|
||||||
return player_data + i * player_data_size + 29;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t serverSlotToClientSlot (uint8_t slot) {
|
uint8_t serverSlotToClientSlot (uint8_t slot) {
|
||||||
@@ -249,17 +187,47 @@ uint8_t clientSlotToServerSlot (uint8_t slot) {
|
|||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int givePlayerItem (int client_fd, uint16_t item) {
|
||||||
|
|
||||||
|
PlayerData *player;
|
||||||
|
if (getPlayerData(client_fd, &player)) return 1;
|
||||||
|
|
||||||
|
uint8_t slot = 255;
|
||||||
|
for (int i = 0; i < 41; i ++) {
|
||||||
|
if (player->inventory_items[i] == item && player->inventory_count[i] < 64) {
|
||||||
|
slot = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slot == 255) {
|
||||||
|
for (int i = 0; i < 41; i ++) {
|
||||||
|
if (player->inventory_items[i] == 0 && player->inventory_count[i] == 0) {
|
||||||
|
slot = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slot == 255) return 1;
|
||||||
|
|
||||||
|
player->inventory_items[slot] = item;
|
||||||
|
player->inventory_count[slot] ++;
|
||||||
|
sc_setContainerSlot(client_fd, 0, serverSlotToClientSlot(slot), player->inventory_count[slot], item);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t getBlockChange (short x, short y, short z) {
|
uint8_t getBlockChange (short x, short y, short z) {
|
||||||
short tmp;
|
short tmp;
|
||||||
for (int i = 0; i < block_changes_count * 7; i += 7) {
|
for (int i = 0; i < block_changes_count; i ++) {
|
||||||
if (block_changes[i + 6] == 0xFF) continue;
|
if (block_changes[i].block == 0xFF) continue;
|
||||||
memcpy(&tmp, block_changes + i, 2);
|
if (
|
||||||
if (x != tmp) continue;
|
block_changes[i].x == x &&
|
||||||
memcpy(&tmp, block_changes + i + 2, 2);
|
block_changes[i].y == y &&
|
||||||
if (y != tmp) continue;
|
block_changes[i].z == z
|
||||||
memcpy(&tmp, block_changes + i + 4, 2);
|
) return block_changes[i].block;
|
||||||
if (z != tmp) continue;
|
|
||||||
return block_changes[i + 6];
|
|
||||||
}
|
}
|
||||||
return 0xFF;
|
return 0xFF;
|
||||||
}
|
}
|
||||||
@@ -267,22 +235,21 @@ uint8_t getBlockChange (short x, short y, short z) {
|
|||||||
void makeBlockChange (short x, short y, short z, uint8_t block) {
|
void makeBlockChange (short x, short y, short z, uint8_t block) {
|
||||||
|
|
||||||
short tmp;
|
short tmp;
|
||||||
for (int i = 0; i < block_changes_count * 7; i += 7) {
|
for (int i = 0; i < block_changes_count; i ++) {
|
||||||
memcpy(&tmp, block_changes + i, 2);
|
if (
|
||||||
if (x != tmp) continue;
|
block_changes[i].x == x &&
|
||||||
memcpy(&tmp, block_changes + i + 2, 2);
|
block_changes[i].y == y &&
|
||||||
if (y != tmp) continue;
|
block_changes[i].z == z
|
||||||
memcpy(&tmp, block_changes + i + 4, 2);
|
) {
|
||||||
if (z != tmp) continue;
|
block_changes[i].block = block;
|
||||||
block_changes[i + 6] = block;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int end = block_changes_count * 7;
|
block_changes[block_changes_count].x = x;
|
||||||
memcpy(block_changes + end, &x, 2);
|
block_changes[block_changes_count].y = y;
|
||||||
memcpy(block_changes + end + 2, &y, 2);
|
block_changes[block_changes_count].z = z;
|
||||||
memcpy(block_changes + end + 4, &z, 2);
|
block_changes[block_changes_count].block = block;
|
||||||
block_changes[end + 6] = block;
|
|
||||||
block_changes_count ++;
|
block_changes_count ++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -32,11 +32,9 @@ int getClientState (int client_fd);
|
|||||||
int getClientIndex (int client_fd);
|
int getClientIndex (int client_fd);
|
||||||
|
|
||||||
int reservePlayerData (int client_fd, char *uuid);
|
int reservePlayerData (int client_fd, char *uuid);
|
||||||
|
int getPlayerData (int client_fd, PlayerData **output);
|
||||||
void clearPlayerFD (int client_fd);
|
void clearPlayerFD (int client_fd);
|
||||||
int savePlayerPositionAndRotation (int client_fd, short x, short y, short z, int8_t yaw, int8_t pitch);
|
int givePlayerItem (int client_fd, uint16_t item);
|
||||||
int savePlayerPosition (int client_fd, short x, short y, short z);
|
|
||||||
int restorePlayerPosition (int client_fd, short *x, short *y, short *z, int8_t *yaw, int8_t *pitch);
|
|
||||||
uint8_t *getPlayerInventory (int client_fd);
|
|
||||||
|
|
||||||
uint8_t serverSlotToClientSlot (uint8_t slot);
|
uint8_t serverSlotToClientSlot (uint8_t slot);
|
||||||
uint8_t clientSlotToServerSlot (uint8_t slot);
|
uint8_t clientSlotToServerSlot (uint8_t slot);
|
||||||
|
Reference in New Issue
Block a user