Process Ball Transfer Packet

This commit is contained in:
2026-04-26 16:34:41 -04:00
parent 21324f72e6
commit 97021d0d4b

29
src/network/packet.c Normal file
View File

@@ -0,0 +1,29 @@
#include "../../include/network/packet.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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;
}