migrating servers

This commit is contained in:
mallocnull 2017-10-27 20:58:29 +00:00
parent 3944d713a7
commit a3ca956036
3 changed files with 49 additions and 9 deletions

View file

@ -6,13 +6,13 @@
int main(int argc, char **argv) { int main(int argc, char **argv) {
packet_context_init(2); packet_context_init(2);
packet_context_register(PCK_CTX_C2S, PCK_ID_REGISTER, 2, 8, 2); packet_context_register(PCK_CTX_C2S, PCK_ID_REGISTER, 0, 2, 8, 2);
packet_context_register(PCK_CTX_C2S, PCK_ID_LOGIN, 2, 8, 2); packet_context_register(PCK_CTX_C2S, PCK_ID_LOGIN, 0, 2, 8, 2);
packet_context_register(PCK_CTX_C2S, PCK_ID_CHANGE_CTX, 2, 8, 2); packet_context_register(PCK_CTX_C2S, PCK_ID_CHANGE_CTX, 0, 2, 1, 2);
packet_context_register(PCK_CTX_S2C, PCK_ID_REGISTER, 2, 1, 16); packet_context_register(PCK_CTX_S2C, PCK_ID_REGISTER, 0, 2, 1, 16);
packet_context_register(PCK_CTX_S2C, PCK_ID_LOGIN, 3, 1, 2, 16); packet_context_register(PCK_CTX_S2C, PCK_ID_LOGIN, 0, 3, 1, 2, 16);
packet_context_register(PCK_CTX_S2C, PCK_ID_CHANGE_CTX, 1, 2); packet_context_register(PCK_CTX_S2C, PCK_ID_CHANGE_CTX, 0, 1, 2);
if(argc == 2 && strcmp(argv[1], "server") == 0) { if(argc == 2 && strcmp(argv[1], "server") == 0) {
register_spawn_type(SPAWN_SERVER); register_spawn_type(SPAWN_SERVER);

View file

@ -8,6 +8,45 @@ struct packet_ctx_t {
uint32_t length; uint32_t length;
}; };
static packet_ctx_t *c2s_ctx; struct {
static packet_ctx_t *s2c_ctx; uint8_t count;
packet_ctx_t *c2s;
packet_ctx_t *s2c;
} static ctx;
void packet_context_init(uint8_t count) {
ctx.count = count;
ctx.c2s = (packet_ctx_t*)malloc(count * sizeof(packet_ctx_t));
ctx.s2c = (packet_ctx_t*)malloc(count * sizeof(packet_ctx_t));
}
void packet_context_register(uint8_t direction, uint8_t id, uint8_t iter_pt, uint8_t count, ...) {
if(id > ctx.count)
return;
int i;
va_list args;
packet_ctx_t *ptr =
direction == PCK_CTX_C2S ? ctx.c2s : ctx.s2c;
ptr[id].length = 0;
ptr[id].iter_start = iter_pt;
ptr[id].region_count = count;
ptr[id].region_lengths = (uint16_t*)malloc(count * sizeof(uint16_t));
va_start(args, count);
for(i = 0; i < count; ++i) {
uint16_t length = va_arg(args, uint16_t);
ptr[id].region_lengths[i] = length;
ptr[id].length += length;
}
va_end(args);
}
void packet_context_free() {
free(ctx.c2s.region_lengths);
free(ctx.c2s);
free(ctx.s2c.region_lengths);
free(ctx.s2c);
}

View file

@ -3,6 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <stdarg.h>
#include "list.h" #include "list.h"
#include "common.h" #include "common.h"
@ -28,6 +29,6 @@ void packet_context_init(uint8_t);
void packet_context_register(uint8_t, uint8_t, uint8_t, ...); void packet_context_register(uint8_t, uint8_t, uint8_t, ...);
void packet_context_register_iter(uint8_t, uint8_t, uint8_t, uint8_t, ...); void packet_context_register_iter(uint8_t, uint8_t, uint8_t, uint8_t, ...);
void packet_context_free();
#endif #endif