Revision 342
identified error
hltp.c | ||
---|---|---|
17 | 17 |
return nctp_send(2, ptr, sz); |
18 | 18 |
} |
19 | 19 |
|
20 |
static host_info_t* hltp_interpret_host_info(const uint8_t *p) { |
|
20 |
static host_info_t* hltp_interpret_host_info(const uint8_t *p, const size_t sz) { |
|
21 |
if (sz != sizeof(host_info_t)) { printf("%d should equal %d\n", sz, sizeof(host_info_t)); return NULL;} |
|
21 | 22 |
host_info_t *ret = (host_info_t*)malloc(sizeof(host_info_t)); |
22 |
size_t pos = 0; |
|
23 |
//size_t pos = 0;
|
|
23 | 24 |
// players information |
24 |
memcpy(ret, p + pos, sizeof(int16_t)*10); |
|
25 |
memcpy(ret, p, sz); |
|
26 |
/* |
|
25 | 27 |
pos += sizeof(int16_t)*10; |
26 | 28 |
// size of arrays |
27 | 29 |
memcpy(&(ret->no_bullets), p + pos, sizeof(uint8_t)); |
... | ... | |
46 | 48 |
// array containing the shooter id of the bullets |
47 | 49 |
(ret->bullets_shooter) = (bool*)malloc(sizeof(bool)*(ret->no_bullets)); |
48 | 50 |
memcpy((ret->bullets_shooter), p + pos, sizeof(bool)*sz); |
49 |
|
|
51 |
*/ |
|
50 | 52 |
return ret; |
51 | 53 |
} |
52 | 54 |
int hltp_send_host_info(const host_info_t *p) { |
53 | 55 |
|
54 | 56 |
uint8_t type = hltp_type_host; |
55 |
const uint8_t* ptr[17]; size_t sz[17];
|
|
57 |
const uint8_t* ptr[11]; size_t sz[11];
|
|
56 | 58 |
ptr[0] = (uint8_t*)& type ; sz[0] = 1; |
57 | 59 |
ptr[1] = (uint8_t*)&p->host_x ; sz[1] = sizeof(int16_t); |
58 | 60 |
ptr[2] = (uint8_t*)&p->host_y ; sz[2] = sizeof(int16_t); |
... | ... | |
64 | 66 |
ptr[8] = (uint8_t*)&p->remote_angle ; sz[8] = sizeof(int16_t); |
65 | 67 |
ptr[9] = (uint8_t*)&p->remote_health ; sz[9] = sizeof(int16_t); |
66 | 68 |
ptr[10] = (uint8_t*)&p->remote_current_health ; sz[10] = sizeof(int16_t); |
69 |
/* |
|
67 | 70 |
ptr[11] = (uint8_t*)&p->no_bullets ; sz[11] = sizeof(uint8_t); |
68 | 71 |
ptr[12] = (uint8_t*) p->bullets_x ; sz[12] = sizeof(int16_t) * p->no_bullets; |
69 | 72 |
ptr[13] = (uint8_t*) p->bullets_y ; sz[13] = sizeof(int16_t) * p->no_bullets; |
70 | 73 |
ptr[14] = (uint8_t*) p->bullets_vx ; sz[14] = sizeof(int16_t) * p->no_bullets; |
71 | 74 |
ptr[15] = (uint8_t*) p->bullets_vy ; sz[15] = sizeof(int16_t) * p->no_bullets; |
72 | 75 |
ptr[16] = (uint8_t*) p->bullets_shooter ; sz[16] = sizeof(bool) * p->no_bullets; |
73 |
return nctp_send(17, ptr, sz); |
|
76 |
*/ |
|
77 |
return nctp_send(11, ptr, sz); |
|
74 | 78 |
} |
75 | 79 |
|
76 | 80 |
static remote_info_t* hltp_interpret_remote_info(const uint8_t *p) { |
... | ... | |
113 | 117 |
uint8_t ret = p[0]; |
114 | 118 |
switch(ret){ |
115 | 119 |
case hltp_type_string: *dest = hltp_interpret_string (p+1, sz-1); break; |
116 |
case hltp_type_host : *dest = hltp_interpret_host_info (p+1); break;
|
|
117 |
case hltp_type_remote: *dest = hltp_interpret_remote_info(p+1); break;
|
|
118 |
case hltp_type_bullet: *dest = hltp_interpret_bullet_info(p+1); break;
|
|
120 |
case hltp_type_host : *dest = hltp_interpret_host_info (p+1, sz-1); break;
|
|
121 |
case hltp_type_remote: *dest = hltp_interpret_remote_info(p+1); break; |
|
122 |
case hltp_type_bullet: *dest = hltp_interpret_bullet_info(p+1); break; |
|
119 | 123 |
default: *dest = NULL; break; |
120 | 124 |
} |
121 | 125 |
return ret; |
Also available in: Unified diff