eco2d/code/common/packets/pkt_01_welcome.c

38 lines
1.1 KiB
C
Raw Normal View History

2021-05-03 22:44:39 +00:00
#include "packet.h"
#include "cwpack/cwpack.h"
#include "packet_utils.h"
#define PKT_01_WELCOME_ARGS 2
2021-05-03 23:57:19 +00:00
#ifdef SERVER
2021-05-03 22:44:39 +00:00
size_t pkt_01_welcome_encode(pkt_01_welcome *table) {
cw_pack_context pc = {0};
pkt_pack_msg(&pc, PKT_01_WELCOME_ARGS);
cw_pack_unsigned(&pc, world_chunk_size());
cw_pack_unsigned(&pc, world_chunk_amount());
return pc.current - pc.start; /* length */
}
2021-05-03 23:57:19 +00:00
#else
pkt_desc pkt_01_welcome_desc[3] = {
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, chunk_size) },
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, chunk_amount) },
{ PKT_END },
};
2021-05-03 22:44:39 +00:00
int32_t pkt_01_welcome_decode(pkt_01_welcome *table, pkt_header *header) {
cw_unpack_context uc = {0};
pkt_unpack_msg(&uc, header, PKT_01_WELCOME_ARGS);
2021-05-03 23:38:47 +00:00
pkt_unpack_struct(&uc, header, PKT_STRUCT_PTR(table));
2021-05-03 22:44:39 +00:00
2021-05-03 23:38:47 +00:00
return pkt_validate_eof_msg(&uc);
2021-05-03 22:44:39 +00:00
}
int32_t pkt_01_welcome_handler(pkt_header *header) {
pkt_01_welcome table;
2021-05-03 23:57:19 +00:00
PKT_IF(pkt_01_welcome_decode(&table, header));
2021-05-03 22:44:39 +00:00
zpl_printf("we received: chunk_size: %d and chunk_amount: %d\n", table.chunk_size, table.chunk_amount);
return 0;
}
2021-05-03 23:57:19 +00:00
#endif