From 1b427181a2708984f497267d566fdcc0f9b9e3dd Mon Sep 17 00:00:00 2001 From: ninya9k <> Date: Sun, 12 Nov 2023 15:42:24 +0000 Subject: [PATCH] lazy but works --- uttt.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/uttt.c b/uttt.c index dc8ed94..26c3d68 100644 --- a/uttt.c +++ b/uttt.c @@ -186,7 +186,17 @@ bool getpos(const struct ut_state *state, int *x, int *y) { } bool getpos_net(const struct ut_state *state, int conn, int *x, int *y) { - //recv(conn, ) + char buf[4]; + int n = recv(conn, &buf, 4, 0); // lazy way but idc + printf("bytes received: %d\n", n); + printf("buf=%s\n", buf); + *x = buf[0] - 0x30; + *y = buf[2] - 0x30; + printf("x=%d y=%d\n", *x, *y); + if (buf[1] != ',' || buf[3] != '\n' || *x >= 9 || *y >= 9 || *x < 0 || *y < 0) { + printf("protocol not followed perfectly by partner - exiting\n"); + exit(1); + } } void finish(int sig) @@ -230,12 +240,12 @@ void ut_host_game(struct ut_state *state, int conn, char host_player) { if (state->player == host_player) { bool ok = getpos(state, &x, &y); if (!ok) {continue;} - int err = ut_move(state, state, x, y); - if (err) {continue;} } else { - printf("Waiting for game parter ..."); + printf("Waiting for game parter ...\n"); getpos_net(state, conn, &x, &y); } + int err = ut_move(state, state, x, y); + if (err) {continue;} char w = ut_winner((char *)state->boards, 0, 3); if(w) {