Skip to content

Commit

Permalink
Send acknowledge messages
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkaMaul committed Jan 23, 2017
1 parent 0c7ad5d commit 9e192b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions includes/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ int read_message_from_server(state *s, char *buffer);
int load_game_params(state *s, char *buffer);

int send_position(state *s, position sendedPosition);
void acknowledge(state *s, char *buffer);

int is_in_arena(state *s, position testedPosition);

Expand Down
9 changes: 9 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ int read_message_from_server(state *s, char *buffer)
nice_exit(s, EXIT_SUCCESS);
}

if (buffer[HEADER_SRC] != SERVER_ID)
acknowledge(s, buffer);

return readedBytes;
}

Expand Down Expand Up @@ -240,6 +243,12 @@ int send_position(state *s, position sendedPosition)
return send_message(s, MSG_POSITION, SERVER_ID, sendedPosition.x, sendedPosition.y);
}

void acknowledge(state *s, char *buffer)
{
unsigned int idAck = (unsigned int) ((uint16_t) *buffer);
send_message(s, MSG_ACK, buffer[HEADER_SRC], idAck);
}

/**
* Parse the START message to load the game parameters
* @param s State structure
Expand Down

0 comments on commit 9e192b6

Please sign in to comment.