mirror of
https://github.com/p2r3/bareiron.git
synced 2025-10-02 07:35:08 +02:00
don't send gameplay packets to clients who haven't loaded in
This commit is contained in:
@@ -103,6 +103,7 @@ void handlePacket (int client_fd, int length, int packet_id, int state) {
|
|||||||
// information about the joining player to all existing players.
|
// information about the joining player to all existing players.
|
||||||
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
||||||
if (player_data[i].client_fd == -1) continue;
|
if (player_data[i].client_fd == -1) continue;
|
||||||
|
if (player_data[i].flags & 0x20) continue;
|
||||||
sc_playerInfoUpdateAddPlayer(client_fd, player_data[i]);
|
sc_playerInfoUpdateAddPlayer(client_fd, player_data[i]);
|
||||||
sc_systemChat(player_data[i].client_fd, join_message, 16 + player_name_len);
|
sc_systemChat(player_data[i].client_fd, join_message, 16 + player_name_len);
|
||||||
if (player_data[i].client_fd == client_fd) continue;
|
if (player_data[i].client_fd == client_fd) continue;
|
||||||
@@ -221,6 +222,7 @@ void handlePacket (int client_fd, int length, int packet_id, int state) {
|
|||||||
// Send current position data to all connected players
|
// Send current position data to all connected players
|
||||||
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
||||||
if (player_data[i].client_fd == -1) continue;
|
if (player_data[i].client_fd == -1) continue;
|
||||||
|
if (player_data[i].flags & 0x20) continue;
|
||||||
if (player_data[i].client_fd == client_fd) continue;
|
if (player_data[i].client_fd == client_fd) continue;
|
||||||
if (packet_id == 0x1F) {
|
if (packet_id == 0x1F) {
|
||||||
sc_updateEntityRotation(player_data[i].client_fd, client_fd, player->yaw, player->pitch);
|
sc_updateEntityRotation(player_data[i].client_fd, client_fd, player->yaw, player->pitch);
|
||||||
|
@@ -1010,6 +1010,7 @@ int cs_chat (int client_fd) {
|
|||||||
// Forward message to all connected players
|
// Forward message to all connected players
|
||||||
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
||||||
if (player_data[i].client_fd == -1) continue;
|
if (player_data[i].client_fd == -1) continue;
|
||||||
|
if (player_data[i].flags & 0x20) continue;
|
||||||
sc_systemChat(player_data[i].client_fd, (char *)recv_buffer, message_len + name_len + 3);
|
sc_systemChat(player_data[i].client_fd, (char *)recv_buffer, message_len + name_len + 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -68,6 +68,7 @@ int reservePlayerData (int client_fd, uint8_t *uuid, char *name) {
|
|||||||
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
||||||
if (memcmp(player_data[i].uuid, uuid, 16) == 0) {
|
if (memcmp(player_data[i].uuid, uuid, 16) == 0) {
|
||||||
player_data[i].client_fd = client_fd;
|
player_data[i].client_fd = client_fd;
|
||||||
|
player_data[i].flags |= 0x20;
|
||||||
memcpy(player_data[i].name, name, 16);
|
memcpy(player_data[i].name, name, 16);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -81,6 +82,7 @@ int reservePlayerData (int client_fd, uint8_t *uuid, char *name) {
|
|||||||
if (empty) {
|
if (empty) {
|
||||||
if (player_data_count >= MAX_PLAYERS) return 1;
|
if (player_data_count >= MAX_PLAYERS) return 1;
|
||||||
player_data[i].client_fd = client_fd;
|
player_data[i].client_fd = client_fd;
|
||||||
|
player_data[i].flags |= 0x20;
|
||||||
memcpy(player_data[i].uuid, uuid, 16);
|
memcpy(player_data[i].uuid, uuid, 16);
|
||||||
memcpy(player_data[i].name, name, 16);
|
memcpy(player_data[i].name, name, 16);
|
||||||
resetPlayerData(&player_data[i]);
|
resetPlayerData(&player_data[i]);
|
||||||
@@ -253,7 +255,7 @@ void spawnPlayer (PlayerData *player) {
|
|||||||
sc_updateTime(player->client_fd, world_time);
|
sc_updateTime(player->client_fd, world_time);
|
||||||
|
|
||||||
// Give the player flight (for testing)
|
// Give the player flight (for testing)
|
||||||
sc_playerAbilities(player->client_fd, 0x04);
|
// sc_playerAbilities(player->client_fd, 0x04);
|
||||||
|
|
||||||
// Calculate player's chunk coordinates
|
// Calculate player's chunk coordinates
|
||||||
short _x = div_floor(player->x, 16), _z = div_floor(player->z, 16);
|
short _x = div_floor(player->x, 16), _z = div_floor(player->z, 16);
|
||||||
@@ -276,6 +278,9 @@ void spawnPlayer (PlayerData *player) {
|
|||||||
// Re-teleport player after all chunks have been sent
|
// Re-teleport player after all chunks have been sent
|
||||||
sc_synchronizePlayerPosition(player->client_fd, spawn_x, spawn_y, spawn_z, spawn_yaw, spawn_pitch);
|
sc_synchronizePlayerPosition(player->client_fd, spawn_x, spawn_y, spawn_z, spawn_yaw, spawn_pitch);
|
||||||
|
|
||||||
|
// Flag player as fully loaded
|
||||||
|
player->flags &= ~0x20;
|
||||||
|
|
||||||
task_yield(); // Check task timer between packets
|
task_yield(); // Check task timer between packets
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -297,6 +302,7 @@ void makeBlockChange (short x, uint8_t y, short z, uint8_t block) {
|
|||||||
// Transmit block update to all in-game clients
|
// Transmit block update to all in-game clients
|
||||||
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
||||||
if (player_data[i].client_fd == -1) continue;
|
if (player_data[i].client_fd == -1) continue;
|
||||||
|
if (player_data[i].flags & 0x20) continue;
|
||||||
if (getClientState(player_data[i].client_fd) != STATE_PLAY) continue;
|
if (getClientState(player_data[i].client_fd) != STATE_PLAY) continue;
|
||||||
sc_blockUpdate(player_data[i].client_fd, x, y, z, block);
|
sc_blockUpdate(player_data[i].client_fd, x, y, z, block);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user