From d55b1110ee447573eacda1fbbd7dfa8c37339756 Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Sat, 15 Jan 2011 19:20:41 +0100 Subject: use packet indizes for better readability --- src/net_client.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/net_client.c') diff --git a/src/net_client.c b/src/net_client.c index 531bbd1..d0149b4 100644 --- a/src/net_client.c +++ b/src/net_client.c @@ -26,9 +26,9 @@ void client_hello(int sock, const char* username) exit(EXIT_FAILURE); } - buf[0] = msg_type_hello; - buf[1] = namelen+2; - memcpy(buf+2, username, namelen); + buf[INDEX_TYPE] = msg_type_hello; + buf[INDEX_LEN] = namelen+2; + memcpy(buf+INDEX_PAYLOAD, username, namelen); send(sock, buf, namelen+2, 0); @@ -91,7 +91,7 @@ static struct player_list* client_recv_player_list(int sock, uint8_t data_len) recv(sock, buf, data_len, 0); - assert(buf[0] == msg_type_start_game); + assert(buf[INDEX_TYPE] == msg_type_start_game); players = malloc(sizeof(struct player_list)); if(players == NULL) @@ -99,9 +99,10 @@ static struct player_list* client_recv_player_list(int sock, uint8_t data_len) printf("client_recv_player_list: Out of memory\n"); exit(EXIT_FAILURE); } - players->count = buf[2]; - pos = 3; + pos = INDEX_PAYLOAD; + players->count = buf[pos++]; + // read usernames from buffer for(int i=0; icount; i++) { @@ -124,7 +125,7 @@ static hand* client_recv_deal_cards(int sock, uint8_t data_len) recv(sock, buf, data_len, 0); - assert(buf[0] == msg_type_deal_cards); + assert(buf[INDEX_TYPE] == msg_type_deal_cards); for(int i=0; i