forked from EXTERNAL/bareiron
support common miscellaneous packets
This commit is contained in:
@@ -10,6 +10,7 @@ int cs_useItemOn (int client_fd);
|
||||
int cs_setPlayerPositionAndRotation (int client_fd, double *x, double *y, double *z, float *yaw, float *pitch, uint8_t *on_ground);
|
||||
int cs_setPlayerPosition (int client_fd, double *x, double *y, double *z, uint8_t *on_ground);
|
||||
int cs_setPlayerRotation (int client_fd, float *yaw, float *pitch, uint8_t *on_ground);
|
||||
int cs_setPlayerMovementFlags (int client_fd, uint8_t *on_ground);
|
||||
int cs_setHeldItem (int client_fd);
|
||||
int cs_clickContainer (int client_fd);
|
||||
int cs_closeContainer (int client_fd);
|
||||
|
26
src/main.c
26
src/main.c
@@ -157,9 +157,19 @@ void handlePacket (int client_fd, int length, int packet_id) {
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x1B: {
|
||||
if (state == STATE_PLAY) {
|
||||
// Serverbound keep-alive (ignored)
|
||||
recv_all(client_fd, recv_buffer, 8, false);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x1D:
|
||||
case 0x1E:
|
||||
case 0x1F:
|
||||
case 0x20:
|
||||
if (state == STATE_PLAY) {
|
||||
|
||||
double x, y, z;
|
||||
@@ -169,17 +179,12 @@ void handlePacket (int client_fd, int length, int packet_id) {
|
||||
// Read player position (and rotation)
|
||||
if (packet_id == 0x1D) cs_setPlayerPosition(client_fd, &x, &y, &z, &on_ground);
|
||||
else if (packet_id == 0x1F) cs_setPlayerRotation (client_fd, &yaw, &pitch, &on_ground);
|
||||
else if (packet_id == 0x20) cs_setPlayerMovementFlags (client_fd, &on_ground);
|
||||
else cs_setPlayerPositionAndRotation(client_fd, &x, &y, &z, &yaw, &pitch, &on_ground);
|
||||
|
||||
PlayerData *player;
|
||||
if (getPlayerData(client_fd, &player)) break;
|
||||
|
||||
// Update rotation in player data (if applicable)
|
||||
if (packet_id != 0x1D) {
|
||||
player->yaw = ((short)(yaw + 540) % 360 - 180) * 127 / 180;
|
||||
player->pitch = pitch / 90.0f * 127.0f;
|
||||
}
|
||||
|
||||
// Handle fall damage
|
||||
if (on_ground) {
|
||||
int8_t damage = player->grounded_y - player->y - 3;
|
||||
@@ -192,6 +197,15 @@ void handlePacket (int client_fd, int length, int packet_id) {
|
||||
player->grounded_y = player->y;
|
||||
}
|
||||
|
||||
// Don't continue if all we got were flags
|
||||
if (packet_id == 0x20) return;
|
||||
|
||||
// Update rotation in player data (if applicable)
|
||||
if (packet_id != 0x1D) {
|
||||
player->yaw = ((short)(yaw + 540) % 360 - 180) * 127 / 180;
|
||||
player->pitch = pitch / 90.0f * 127.0f;
|
||||
}
|
||||
|
||||
// Broadcast player position to other players
|
||||
#ifdef SCALE_MOVEMENT_UPDATES_TO_PLAYER_COUNT
|
||||
// If applicable, broadcast only every client_count-th movement update
|
||||
|
@@ -651,6 +651,13 @@ int cs_setPlayerRotation (int client_fd, float *yaw, float *pitch, uint8_t *on_g
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cs_setPlayerMovementFlags (int client_fd, uint8_t *on_ground) {
|
||||
|
||||
*on_ground = readByte(client_fd) & 0x01;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// C->S Set Held Item (serverbound)
|
||||
int cs_setHeldItem (int client_fd) {
|
||||
|
||||
|
Reference in New Issue
Block a user