From 97021d0d4b0d6f6491b6939224fb3f9efe1a9fac Mon Sep 17 00:00:00 2001 From: Colton Staiduhar Date: Sun, 26 Apr 2026 16:34:41 -0400 Subject: [PATCH] Process Ball Transfer Packet --- src/network/packet.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/network/packet.c diff --git a/src/network/packet.c b/src/network/packet.c new file mode 100644 index 0000000..0419efd --- /dev/null +++ b/src/network/packet.c @@ -0,0 +1,29 @@ +#include "../../include/network/packet.h" +#include +#include +#include + +int ProcessBallPacket(char* msg, Ball* ball, GameData* gd) +{ + // 1. Verify prefix + if (strncmp(msg, "BTRANS", 6) != 0) { + printf("Invalid prefix\n"); + printf("\nMSG: %s\n\n\n", msg); + return 1; + } + + int matched = sscanf(msg, "BTRANS %f %f %f", + &ball->y, &ball->vx, &ball->vy); + if (matched != 3) { + printf("Parsing failed\n"); + return 1; + } + + if (gd->host) + ball->x = RIGHT_COL - 1; + else + ball->x = LEFT_COL + 1; + ball->visible = 1; + + return 0; +} \ No newline at end of file