diff options
| author | Reiner Herrmann <reiner@reiner-h.de> | 2011-01-15 19:20:41 +0100 |
|---|---|---|
| committer | Reiner Herrmann <reiner@reiner-h.de> | 2011-01-15 19:20:41 +0100 |
| commit | d55b1110ee447573eacda1fbbd7dfa8c37339756 (patch) | |
| tree | 5ddd155d4c5036a24e66729db7f5b16e0a52ca21 /src/net_server.c | |
| parent | f85db5843635d9e6479220f7dfd34bf719f15994 (diff) | |
use packet indizes for better readability
Diffstat (limited to 'src/net_server.c')
| -rw-r--r-- | src/net_server.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/net_server.c b/src/net_server.c index edd572b..bc64024 100644 --- a/src/net_server.c +++ b/src/net_server.c @@ -121,7 +121,7 @@ void server_start_game(int* clients, const uint8_t clientcount, const struct pla { uint8_t* buf; uint8_t usercount = players->count; - uint32_t pos = 0; + uint32_t pos; uint32_t buflen = 3 + usercount; // type + packetlen + usercount + (usercount * len) for(int i=0; i<usercount; i++) @@ -133,8 +133,9 @@ void server_start_game(int* clients, const uint8_t clientcount, const struct pla printf("server_start_game: Out of memory\n"); exit(EXIT_FAILURE); } - buf[pos++] = msg_type_start_game; - buf[pos++] = buflen; + buf[INDEX_TYPE] = msg_type_start_game; + buf[INDEX_LEN] = buflen; + pos = INDEX_PAYLOAD; buf[pos++] = players->count; // copy usernames with length to buffer for(int i=0; i<usercount; i++) @@ -164,9 +165,9 @@ static char* server_recv_hello(int sock, uint8_t data_len) recv(sock, buf, data_len, 0); - assert(buf[0] == msg_type_hello); + assert(buf[INDEX_TYPE] == msg_type_hello); - namelen = buf[1] - 2; + namelen = buf[INDEX_LEN] - 2; name = malloc(namelen+1); if(name == NULL) { @@ -194,8 +195,8 @@ void* server_recv(int sock, uint8_t wanted) assert(len != -1); - type = buf[0]; - data_len = buf[1]; + type = buf[INDEX_TYPE]; + data_len = buf[INDEX_LEN]; if(type != wanted) return NULL; @@ -218,10 +219,10 @@ void server_deal_cards(int sock, const hand h) { uint8_t buf[2+MAX_HAND_CARDS]; - buf[0] = msg_type_deal_cards; - buf[1] = 2+MAX_HAND_CARDS; + buf[INDEX_TYPE] = msg_type_deal_cards; + buf[INDEX_LEN] = 2+MAX_HAND_CARDS; for(int i=0; i<MAX_HAND_CARDS; i++) - buf[2+i] = h[i]; + buf[INDEX_PAYLOAD+i] = h[i]; send(sock, buf, 2+MAX_HAND_CARDS, 0); |
