Merge branch 'master' of github.com:zpl-c/eco2d

isolation_bkp/dynres
Dominik Madarász 2022-07-30 19:54:20 +02:00
commit e9dbbf279a
3 changed files with 19099 additions and 17933 deletions

View File

@ -21,59 +21,59 @@ static world_snapshot streamer_snapshot;
entity_view world_build_entity_view(int64_t e) { entity_view world_build_entity_view(int64_t e) {
entity_view *cached_ev = world_snapshot_get(&streamer_snapshot, e); entity_view *cached_ev = world_snapshot_get(&streamer_snapshot, e);
if (cached_ev) return *cached_ev; if (cached_ev) return *cached_ev;
entity_view view = {0}; entity_view view = {0};
const Classify *classify = ecs_get(world_ecs(), e, Classify); const Classify *classify = ecs_get(world_ecs(), e, Classify);
ZPL_ASSERT(classify); ZPL_ASSERT(classify);
view.kind = classify->id; view.kind = classify->id;
const Position *pos = ecs_get(world_ecs(), e, Position); const Position *pos = ecs_get(world_ecs(), e, Position);
if (pos) { if (pos) {
view.x = pos->x; view.x = pos->x;
view.y = pos->y; view.y = pos->y;
} }
const Velocity *vel = ecs_get(world_ecs(), e, Velocity); const Velocity *vel = ecs_get(world_ecs(), e, Velocity);
if (vel) { if (vel) {
view.flag |= EFLAG_INTERP; view.flag |= EFLAG_INTERP;
view.vx = vel->x; view.vx = vel->x;
view.vy = vel->y; view.vy = vel->y;
} }
const Health *health = ecs_get(world_ecs(), e, Health); const Health *health = ecs_get(world_ecs(), e, Health);
if (health) { if (health) {
view.hp = health->hp; view.hp = health->hp;
view.max_hp = health->max_hp; view.max_hp = health->max_hp;
} }
if (ecs_get(world_ecs(), e, Vehicle)) { if (ecs_get(world_ecs(), e, Vehicle)) {
Vehicle const* veh = ecs_get(world_ecs(), e, Vehicle); Vehicle const* veh = ecs_get(world_ecs(), e, Vehicle);
view.heading = veh->heading; view.heading = veh->heading;
} }
if (ecs_get(world_ecs(), e, ItemDrop)) { if (ecs_get(world_ecs(), e, ItemDrop)) {
ItemDrop const* dr = ecs_get(world_ecs(), e, ItemDrop); ItemDrop const* dr = ecs_get(world_ecs(), e, ItemDrop);
view.asset = dr->kind; view.asset = dr->kind;
view.quantity = dr->quantity; view.quantity = dr->quantity;
} }
view.inside_vehicle = ecs_get(world_ecs(), e, IsInVehicle) != 0 ? true : false; view.inside_vehicle = ecs_get(world_ecs(), e, IsInVehicle) != 0 ? true : false;
Inventory *inv = 0; Inventory *inv = 0;
if ((inv = ecs_get_mut_if(world_ecs(), e, Inventory))) { if ((inv = ecs_get_mut_if(world_ecs(), e, Inventory))) {
view.has_items = true; view.has_items = true;
for (int i = 0; i < ITEMS_INVENTORY_SIZE; i += 1) { for (int i = 0; i < ITEMS_INVENTORY_SIZE; i += 1) {
view.items[i] = inv->items[i]; view.items[i] = inv->items[i];
} }
const Input *in = ecs_get(world_ecs(), e, Input); const Input *in = ecs_get(world_ecs(), e, Input);
if (in) if (in)
view.selected_item = in->selected_item; view.selected_item = in->selected_item;
} }
Chunk *chunk = 0; Chunk *chunk = 0;
if ((chunk = ecs_get_mut_if(world_ecs(), e, Chunk))) { if ((chunk = ecs_get_mut_if(world_ecs(), e, Chunk))) {
view.x = chunk->x; view.x = chunk->x;
@ -81,16 +81,16 @@ entity_view world_build_entity_view(int64_t e) {
view.blocks_used = 1; view.blocks_used = 1;
view.is_dirty = chunk->is_dirty; view.is_dirty = chunk->is_dirty;
chunk->is_dirty = false; chunk->is_dirty = false;
for (int i = 0; i < world.chunk_size*world.chunk_size; i += 1) { for (int i = 0; i < world.chunk_size*world.chunk_size; i += 1) {
view.blocks[i] = world.block_mapping[chunk->id][i]; view.blocks[i] = world.block_mapping[chunk->id][i];
} }
for (int i = 0; i < world.chunk_size*world.chunk_size; i += 1) { for (int i = 0; i < world.chunk_size*world.chunk_size; i += 1) {
view.outer_blocks[i] = world.outer_block_mapping[chunk->id][i]; view.outer_blocks[i] = world.outer_block_mapping[chunk->id][i];
} }
} }
world_snapshot_set(&streamer_snapshot, e, view); world_snapshot_set(&streamer_snapshot, e, view);
return view; return view;
} }
@ -105,7 +105,7 @@ int32_t tracker_write_create(librg_world *w, librg_event *e) {
#endif #endif
size_t actual_length = librg_event_size_get(w, e); size_t actual_length = librg_event_size_get(w, e);
char *buffer = librg_event_buffer_get(w, e); char *buffer = librg_event_buffer_get(w, e);
return (int32_t)entity_view_pack_struct(buffer, actual_length, world_build_entity_view(entity_id)); return (int32_t)entity_view_pack_struct(buffer, actual_length, world_build_entity_view(entity_id));
} }
@ -126,14 +126,14 @@ int32_t tracker_write_update(librg_world *w, librg_event *e) {
size_t actual_length = librg_event_size_get(w, e); size_t actual_length = librg_event_size_get(w, e);
char *buffer = librg_event_buffer_get(w, e); char *buffer = librg_event_buffer_get(w, e);
entity_view view = world_build_entity_view(entity_id); entity_view view = world_build_entity_view(entity_id);
// NOTE(zaklaus): exclude chunks from updates as they never move // NOTE(zaklaus): exclude chunks from updates as they never move
{ {
if (view.kind == EKIND_CHUNK && !view.is_dirty) { if (view.kind == EKIND_CHUNK && !view.is_dirty) {
return LIBRG_WRITE_REJECT; return LIBRG_WRITE_REJECT;
} }
} }
return (int32_t)entity_view_pack_struct(buffer, actual_length, view); return (int32_t)entity_view_pack_struct(buffer, actual_length, view);
} }
@ -156,15 +156,15 @@ world_chunk_setup_grid(void) {
world.outer_block_mapping[i] = zpl_malloc(sizeof(block_id)*zpl_square(world.chunk_size)); world.outer_block_mapping[i] = zpl_malloc(sizeof(block_id)*zpl_square(world.chunk_size));
chunk->id = i; chunk->id = i;
chunk->is_dirty = false; chunk->is_dirty = false;
for (int y = 0; y < world.chunk_size; y += 1) { for (int y = 0; y < world.chunk_size; y += 1) {
for (int x = 0; x < world.chunk_size; x += 1) { for (int x = 0; x < world.chunk_size; x += 1) {
int chk_x = chunk->x * world.chunk_size; int chk_x = chunk->x * world.chunk_size;
int chk_y = chunk->y * world.chunk_size; int chk_y = chunk->y * world.chunk_size;
block_id *c = &world.block_mapping[i][(y*world.chunk_size)+x]; block_id *c = &world.block_mapping[i][(y*world.chunk_size)+x];
*c = world.data[(chk_y+y)*world.dim + (chk_x+x)]; *c = world.data[(chk_y+y)*world.dim + (chk_x+x)];
c = &world.outer_block_mapping[i][(y*world.chunk_size)+x]; c = &world.outer_block_mapping[i][(y*world.chunk_size)+x];
*c = world.outer_data[(chk_y+y)*world.dim + (chk_x+x)]; *c = world.outer_data[(chk_y+y)*world.dim + (chk_x+x)];
} }
@ -172,17 +172,17 @@ world_chunk_setup_grid(void) {
} }
} }
static inline static inline
void world_configure_tracker(void) { void world_configure_tracker(void) {
world.tracker = librg_world_create(); world.tracker = librg_world_create();
ZPL_ASSERT_MSG(world.tracker, "[ERROR] An error occurred while trying to create a server world."); ZPL_ASSERT_MSG(world.tracker, "[ERROR] An error occurred while trying to create a server world.");
/* config our world grid */ /* config our world grid */
librg_config_chunksize_set(world.tracker, WORLD_BLOCK_SIZE * world.chunk_size, WORLD_BLOCK_SIZE * world.chunk_size, 0); librg_config_chunksize_set(world.tracker, WORLD_BLOCK_SIZE * world.chunk_size, WORLD_BLOCK_SIZE * world.chunk_size, 0);
librg_config_chunkamount_set(world.tracker, world.chunk_amount, world.chunk_amount, 0); librg_config_chunkamount_set(world.tracker, world.chunk_amount, world.chunk_amount, 0);
librg_config_chunkoffset_set(world.tracker, LIBRG_OFFSET_BEG, LIBRG_OFFSET_BEG, LIBRG_OFFSET_BEG); librg_config_chunkoffset_set(world.tracker, LIBRG_OFFSET_BEG, LIBRG_OFFSET_BEG, LIBRG_OFFSET_BEG);
librg_event_set(world.tracker, LIBRG_WRITE_CREATE, tracker_write_create); librg_event_set(world.tracker, LIBRG_WRITE_CREATE, tracker_write_create);
librg_event_set(world.tracker, LIBRG_WRITE_REMOVE, tracker_write_remove); librg_event_set(world.tracker, LIBRG_WRITE_REMOVE, tracker_write_remove);
librg_event_set(world.tracker, LIBRG_WRITE_UPDATE, tracker_write_update); librg_event_set(world.tracker, LIBRG_WRITE_UPDATE, tracker_write_update);
@ -192,14 +192,14 @@ static inline
void world_init_worldgen_data(void) { void world_init_worldgen_data(void) {
world.data = zpl_malloc(sizeof(block_id)*world.size); world.data = zpl_malloc(sizeof(block_id)*world.size);
world.outer_data = zpl_malloc(sizeof(block_id)*world.size); world.outer_data = zpl_malloc(sizeof(block_id)*world.size);
ZPL_ASSERT(world.data && world.outer_data); ZPL_ASSERT(world.data && world.outer_data);
} }
static inline static inline
void world_setup_ecs(void) { void world_setup_ecs(void) {
world.ecs = ecs_init(); world.ecs = ecs_init();
ECS_IMPORT(world.ecs, Components); ECS_IMPORT(world.ecs, Components);
ECS_IMPORT(world.ecs, Systems); ECS_IMPORT(world.ecs, Systems);
world.ecs_update = ecs_query_new(world.ecs, "components.ClientInfo, components.Position"); world.ecs_update = ecs_query_new(world.ecs, "components.ClientInfo, components.Position");
@ -217,7 +217,7 @@ static inline
void world_generate_instance(void) { void world_generate_instance(void) {
int32_t world_build_status = worldgen_test(&world); int32_t world_build_status = worldgen_test(&world);
ZPL_ASSERT(world_build_status >= 0); ZPL_ASSERT(world_build_status >= 0);
for (int i = 0; i < zpl_square(world.dim); ++i) { for (int i = 0; i < zpl_square(world.dim); ++i) {
if (world.data[i] == 0) { if (world.data[i] == 0) {
ZPL_PANIC("Worldgen failure! Block %d is unset!\n", i); ZPL_PANIC("Worldgen failure! Block %d is unset!\n", i);
@ -239,10 +239,10 @@ int32_t world_init(int32_t seed, uint16_t chunk_size, uint16_t chunk_amount) {
world.seed = seed; world.seed = seed;
world.chunk_size = chunk_size; world.chunk_size = chunk_size;
world.chunk_amount = chunk_amount; world.chunk_amount = chunk_amount;
world.dim = (world.chunk_size * world.chunk_amount); world.dim = (world.chunk_size * world.chunk_amount);
world.size = world.dim * world.dim; world.size = world.dim * world.dim;
world_configure_tracker(); world_configure_tracker();
world_setup_ecs(); world_setup_ecs();
world_init_worldgen_data(); world_init_worldgen_data();
@ -250,9 +250,9 @@ int32_t world_init(int32_t seed, uint16_t chunk_size, uint16_t chunk_amount) {
world_init_mapping(); world_init_mapping();
world_chunk_setup_grid(); world_chunk_setup_grid();
world_free_worldgen_data(); world_free_worldgen_data();
zpl_printf("[INFO] Created a new server world\n"); zpl_printf("[INFO] Created a new server world\n");
return WORLD_ERROR_NONE; return WORLD_ERROR_NONE;
} }
@ -277,35 +277,35 @@ int32_t world_destroy(void) {
static void world_tracker_update(uint8_t ticker, float freq, uint8_t radius) { static void world_tracker_update(uint8_t ticker, float freq, uint8_t radius) {
if (world.tracker_update[ticker] > (float)zpl_time_rel()) return; if (world.tracker_update[ticker] > (float)zpl_time_rel()) return;
world.tracker_update[ticker] = (float)zpl_time_rel() + freq; world.tracker_update[ticker] = (float)zpl_time_rel() + freq;
profile(PROF_WORLD_WRITE) { profile(PROF_WORLD_WRITE) {
ecs_iter_t it = ecs_query_iter(world.ecs_update); ecs_iter_t it = ecs_query_iter(world.ecs_update);
static char buffer[WORLD_LIBRG_BUFSIZ] = {0}; static char buffer[WORLD_LIBRG_BUFSIZ] = {0};
world.active_layer_id = ticker; world.active_layer_id = ticker;
while (ecs_query_next(&it)) { while (ecs_query_next(&it)) {
ClientInfo *p = ecs_column(&it, ClientInfo, 1); ClientInfo *p = ecs_column(&it, ClientInfo, 1);
for (int i = 0; i < it.count; i++) { for (int i = 0; i < it.count; i++) {
size_t datalen = WORLD_LIBRG_BUFSIZ; size_t datalen = WORLD_LIBRG_BUFSIZ;
// TODO(zaklaus): SUPER TEMPORARY HOT !!! simulate variable radius queries // TODO(zaklaus): SUPER TEMPORARY HOT !!! simulate variable radius queries
{ {
librg_entity_radius_set(world_tracker(), it.entities[i], radius); librg_entity_radius_set(world_tracker(), it.entities[i], radius);
} }
// TODO(zaklaus): push radius once librg patch comes in // TODO(zaklaus): push radius once librg patch comes in
int32_t result = librg_world_write(world_tracker(), it.entities[i], buffer, &datalen, NULL); int32_t result = librg_world_write(world_tracker(), it.entities[i], radius, buffer, &datalen, NULL);
if (result > 0) { if (result > 0) {
zpl_printf("[info] buffer size was not enough, please increase it by at least: %d\n", result); zpl_printf("[info] buffer size was not enough, please increase it by at least: %d\n", result);
} else if (result < 0) { } else if (result < 0) {
zpl_printf("[error] an error happened writing the world %d\n", result); zpl_printf("[error] an error happened writing the world %d\n", result);
} }
pkt_send_librg_update((uint64_t)p[i].peer, p[i].view_id, ticker, buffer, datalen); pkt_send_librg_update((uint64_t)p[i].peer, p[i].view_id, ticker, buffer, datalen);
} }
} }
// NOTE(zaklaus): clear out our streaming snapshot // NOTE(zaklaus): clear out our streaming snapshot
// TODO(zaklaus): move this to zpl // TODO(zaklaus): move this to zpl
{ {
@ -319,21 +319,21 @@ int32_t world_update() {
profile (PROF_UPDATE_SYSTEMS) { profile (PROF_UPDATE_SYSTEMS) {
ecs_progress(world.ecs, 0.0f); ecs_progress(world.ecs, 0.0f);
} }
float fast_ms = WORLD_TRACKER_UPDATE_FAST_MS; float fast_ms = WORLD_TRACKER_UPDATE_FAST_MS;
float normal_ms = WORLD_TRACKER_UPDATE_NORMAL_MS; float normal_ms = WORLD_TRACKER_UPDATE_NORMAL_MS;
float slow_ms = WORLD_TRACKER_UPDATE_SLOW_MS; float slow_ms = WORLD_TRACKER_UPDATE_SLOW_MS;
if (game_get_kind() != GAMEKIND_SINGLE) { if (game_get_kind() != GAMEKIND_SINGLE) {
fast_ms = WORLD_TRACKER_UPDATE_MP_FAST_MS; fast_ms = WORLD_TRACKER_UPDATE_MP_FAST_MS;
normal_ms = WORLD_TRACKER_UPDATE_MP_NORMAL_MS; normal_ms = WORLD_TRACKER_UPDATE_MP_NORMAL_MS;
slow_ms = WORLD_TRACKER_UPDATE_MP_SLOW_MS; slow_ms = WORLD_TRACKER_UPDATE_MP_SLOW_MS;
} }
world_tracker_update(0, fast_ms, 1); world_tracker_update(0, fast_ms, 1);
world_tracker_update(1, normal_ms, 2); world_tracker_update(1, normal_ms, 2);
world_tracker_update(2, slow_ms, 3); world_tracker_update(2, slow_ms, 3);
debug_replay_update(); debug_replay_update();
return 0; return 0;
} }
@ -424,11 +424,11 @@ world_block_lookup world_block_from_realpos(float x, float y) {
int32_t size = world.chunk_size * WORLD_BLOCK_SIZE; int32_t size = world.chunk_size * WORLD_BLOCK_SIZE;
int16_t chunk_x, chunk_y; int16_t chunk_x, chunk_y;
librg_chunk_to_chunkpos(world.tracker, chunk_id, &chunk_x, &chunk_y, NULL); librg_chunk_to_chunkpos(world.tracker, chunk_id, &chunk_x, &chunk_y, NULL);
// NOTE(zaklaus): pos relative to chunk // NOTE(zaklaus): pos relative to chunk
float chx = x - chunk_x * size; float chx = x - chunk_x * size;
float chy = y - chunk_y * size; float chy = y - chunk_y * size;
uint16_t bx = (uint16_t)chx / WORLD_BLOCK_SIZE; uint16_t bx = (uint16_t)chx / WORLD_BLOCK_SIZE;
uint16_t by = (uint16_t)chy / WORLD_BLOCK_SIZE; uint16_t by = (uint16_t)chy / WORLD_BLOCK_SIZE;
uint16_t block_idx = (by*world.chunk_size)+bx; uint16_t block_idx = (by*world.chunk_size)+bx;
@ -438,11 +438,11 @@ world_block_lookup world_block_from_realpos(float x, float y) {
bid = world.block_mapping[chunk_id][block_idx]; bid = world.block_mapping[chunk_id][block_idx];
is_outer = false; is_outer = false;
} }
// NOTE(zaklaus): pos relative to block's center // NOTE(zaklaus): pos relative to block's center
float box = chx - bx * WORLD_BLOCK_SIZE - WORLD_BLOCK_SIZE/2.0f; float box = chx - bx * WORLD_BLOCK_SIZE - WORLD_BLOCK_SIZE/2.0f;
float boy = chy - by * WORLD_BLOCK_SIZE - WORLD_BLOCK_SIZE/2.0f; float boy = chy - by * WORLD_BLOCK_SIZE - WORLD_BLOCK_SIZE/2.0f;
world_block_lookup lookup = { world_block_lookup lookup = {
.id = block_idx, .id = block_idx,
.bid = bid, .bid = bid,
@ -452,19 +452,19 @@ world_block_lookup world_block_from_realpos(float x, float y) {
.oy = boy, .oy = boy,
.is_outer = is_outer, .is_outer = is_outer,
}; };
return lookup; return lookup;
} }
void world_chunk_destroy_block(float x, float y, bool drop_item) { void world_chunk_destroy_block(float x, float y, bool drop_item) {
world_block_lookup l = world_block_from_realpos(x, y); world_block_lookup l = world_block_from_realpos(x, y);
world_chunk_replace_block(l.chunk_id, l.id, 0); world_chunk_replace_block(l.chunk_id, l.id, 0);
if (l.is_outer && l.bid > 0 && drop_item) { if (l.is_outer && l.bid > 0 && drop_item) {
asset_id item_asset = blocks_get_asset(l.bid); asset_id item_asset = blocks_get_asset(l.bid);
if (item_find(item_asset) == ASSET_INVALID) return; if (item_find(item_asset) == ASSET_INVALID) return;
uint64_t e = item_spawn(item_asset, 1); uint64_t e = item_spawn(item_asset, 1);
Position *dest = ecs_get_mut(world_ecs(), e, Position, NULL); Position *dest = ecs_get_mut(world_ecs(), e, Position, NULL);
dest->x = x; dest->x = x;
dest->y = y; dest->y = y;
@ -476,14 +476,14 @@ world_block_lookup world_block_from_index(int64_t id, uint16_t block_idx) {
if (bid == 0) { if (bid == 0) {
bid = world.block_mapping[id][block_idx]; bid = world.block_mapping[id][block_idx];
} }
world_block_lookup lookup = { world_block_lookup lookup = {
.id = block_idx, .id = block_idx,
.bid = bid, .bid = bid,
.chunk_id = id, .chunk_id = id,
.chunk_e = world.chunk_mapping[id], .chunk_e = world.chunk_mapping[id],
}; };
return lookup; return lookup;
} }
@ -552,7 +552,7 @@ int64_t *world_chunk_query_entities(int64_t e, size_t *ents_len, int8_t radius)
static int64_t ents[UINT16_MAX]; static int64_t ents[UINT16_MAX];
*ents_len = UINT16_MAX; *ents_len = UINT16_MAX;
librg_entity_radius_set(world.tracker, e, radius); librg_entity_radius_set(world.tracker, e, radius);
librg_world_query(world.tracker, e, ents, ents_len); librg_world_query(world.tracker, e, radius, ents, ents_len);
return ents; return ents;
} }

261
code/vendors/enet.h vendored
View File

@ -35,14 +35,15 @@
#ifndef ENET_INCLUDE_H #ifndef ENET_INCLUDE_H
#define ENET_INCLUDE_H #define ENET_INCLUDE_H
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <time.h> #include <time.h>
#define ENET_VERSION_MAJOR 2 #define ENET_VERSION_MAJOR 2
#define ENET_VERSION_MINOR 2 #define ENET_VERSION_MINOR 3
#define ENET_VERSION_PATCH 1 #define ENET_VERSION_PATCH 4
#define ENET_VERSION_CREATE(major, minor, patch) (((major)<<16) | ((minor)<<8) | (patch)) #define ENET_VERSION_CREATE(major, minor, patch) (((major)<<16) | ((minor)<<8) | (patch))
#define ENET_VERSION_GET_MAJOR(version) (((version)>>16)&0xFF) #define ENET_VERSION_GET_MAJOR(version) (((version)>>16)&0xFF)
#define ENET_VERSION_GET_MINOR(version) (((version)>>8)&0xFF) #define ENET_VERSION_GET_MINOR(version) (((version)>>8)&0xFF)
@ -83,9 +84,9 @@
#endif #endif
#ifdef __GNUC__ #ifdef __GNUC__
#if (_WIN32_WINNT < 0x0501) #if (_WIN32_WINNT < 0x0600)
#undef _WIN32_WINNT #undef _WIN32_WINNT
#define _WIN32_WINNT 0x0501 #define _WIN32_WINNT 0x0600
#endif #endif
#endif #endif
@ -192,6 +193,15 @@
#define ENET_SOCKETSET_CHECK(sockset, socket) FD_ISSET(socket, &(sockset)) #define ENET_SOCKETSET_CHECK(sockset, socket) FD_ISSET(socket, &(sockset))
#endif #endif
#ifdef __GNUC__
#define ENET_DEPRECATED(func) func __attribute__ ((deprecated))
#elif defined(_MSC_VER)
#define ENET_DEPRECATED(func) __declspec(deprecated) func
#else
#pragma message("WARNING: Please ENET_DEPRECATED for this compiler")
#define ENET_DEPRECATED(func) func
#endif
#ifndef ENET_BUFFER_MAXIMUM #ifndef ENET_BUFFER_MAXIMUM
#define ENET_BUFFER_MAXIMUM (1 + 2 * ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS) #define ENET_BUFFER_MAXIMUM (1 + 2 * ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS)
#endif #endif
@ -202,6 +212,12 @@
#define ENET_MIN(x, y) ((x) < (y) ? (x) : (y)) #define ENET_MIN(x, y) ((x) < (y) ? (x) : (y))
#define ENET_IPV6 1 #define ENET_IPV6 1
static const struct in6_addr enet_v4_anyaddr = {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}};
static const struct in6_addr enet_v4_noaddr = {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}};
static const struct in6_addr enet_v4_localhost = {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x01 }}};
static const struct in6_addr enet_v6_anyaddr = {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}};
static const struct in6_addr enet_v6_noaddr = {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}};
static const struct in6_addr enet_v6_localhost = {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}};
#define ENET_HOST_ANY in6addr_any #define ENET_HOST_ANY in6addr_any
#define ENET_HOST_BROADCAST 0xFFFFFFFFU #define ENET_HOST_BROADCAST 0xFFFFFFFFU
#define ENET_PORT_ANY 0 #define ENET_PORT_ANY 0
@ -236,6 +252,7 @@ extern "C" {
extern void *enet_malloc(size_t); extern void *enet_malloc(size_t);
extern void enet_free(void *); extern void enet_free(void *);
extern ENetPacket* enet_packet_create(const void*,size_t,enet_uint32); extern ENetPacket* enet_packet_create(const void*,size_t,enet_uint32);
extern ENetPacket* enet_packet_copy(ENetPacket*);
extern void enet_packet_destroy(ENetPacket*); extern void enet_packet_destroy(ENetPacket*);
// =======================================================================// // =======================================================================//
@ -885,7 +902,7 @@ extern "C" {
@retval < 0 on failure @retval < 0 on failure
@returns the address of the given hostName in address on success @returns the address of the given hostName in address on success
*/ */
ENET_API int enet_address_set_host_ip(ENetAddress * address, const char * hostName); ENET_API int enet_address_set_host_ip_old(ENetAddress * address, const char * hostName);
/** Attempts to resolve the host named by the parameter hostName and sets /** Attempts to resolve the host named by the parameter hostName and sets
the host field in the address parameter if successful. the host field in the address parameter if successful.
@ -895,7 +912,7 @@ extern "C" {
@retval < 0 on failure @retval < 0 on failure
@returns the address of the given hostName in address on success @returns the address of the given hostName in address on success
*/ */
ENET_API int enet_address_set_host(ENetAddress * address, const char * hostName); ENET_API int enet_address_set_host_old(ENetAddress * address, const char * hostName);
/** Gives the printable form of the IP address specified in the address parameter. /** Gives the printable form of the IP address specified in the address parameter.
@param address address printed @param address address printed
@ -905,7 +922,7 @@ extern "C" {
@retval 0 on success @retval 0 on success
@retval < 0 on failure @retval < 0 on failure
*/ */
ENET_API int enet_address_get_host_ip(const ENetAddress * address, char * hostName, size_t nameLength); ENET_API int enet_address_get_host_ip_old(const ENetAddress * address, char * hostName, size_t nameLength);
/** Attempts to do a reverse lookup of the host field in the address parameter. /** Attempts to do a reverse lookup of the host field in the address parameter.
@param address address used for reverse lookup @param address address used for reverse lookup
@ -915,7 +932,24 @@ extern "C" {
@retval 0 on success @retval 0 on success
@retval < 0 on failure @retval < 0 on failure
*/ */
ENET_API int enet_address_get_host(const ENetAddress * address, char * hostName, size_t nameLength); ENET_API int enet_address_get_host_old(const ENetAddress * address, char * hostName, size_t nameLength);
ENET_API int enet_address_set_host_ip_new(ENetAddress * address, const char * hostName);
ENET_API int enet_address_set_host_new(ENetAddress * address, const char * hostName);
ENET_API int enet_address_get_host_ip_new(const ENetAddress * address, char * hostName, size_t nameLength);
ENET_API int enet_address_get_host_new(const ENetAddress * address, char * hostName, size_t nameLength);
#ifdef ENET_FEATURE_ADDRESS_MAPPING
#define enet_address_set_host_ip enet_address_set_host_ip_new
#define enet_address_set_host enet_address_set_host_new
#define enet_address_get_host_ip enet_address_get_host_ip_new
#define enet_address_get_host enet_address_get_host_new
#else
#define enet_address_set_host_ip enet_address_set_host_ip_old
#define enet_address_set_host enet_address_set_host_old
#define enet_address_get_host_ip enet_address_get_host_ip_old
#define enet_address_get_host enet_address_get_host_old
#endif
ENET_API enet_uint32 enet_host_get_peers_count(ENetHost *); ENET_API enet_uint32 enet_host_get_peers_count(ENetHost *);
ENET_API enet_uint32 enet_host_get_packets_sent(ENetHost *); ENET_API enet_uint32 enet_host_get_packets_sent(ENetHost *);
@ -1197,14 +1231,13 @@ extern "C" {
#endif /* defined(_MSC_VER) */ #endif /* defined(_MSC_VER) */
// =======================================================================// // =======================================================================//
// ! // !
// ! Callbacks // ! Callbacks
// ! // !
// =======================================================================// // =======================================================================//
static ENetCallbacks callbacks = { malloc, free, abort, enet_packet_create, enet_packet_destroy }; ENetCallbacks callbacks = { malloc, free, abort, enet_packet_create, enet_packet_destroy };
int enet_initialize_with_callbacks(ENetVersion version, const ENetCallbacks *inits) { int enet_initialize_with_callbacks(ENetVersion version, const ENetCallbacks *inits) {
if (version < ENET_VERSION_CREATE(1, 3, 0)) { if (version < ENET_VERSION_CREATE(1, 3, 0)) {
@ -1388,6 +1421,10 @@ extern "C" {
return packet; return packet;
} }
ENetPacket *enet_packet_copy(ENetPacket *packet) {
return enet_packet_create(packet->data, packet->dataLength, packet->flags);
}
/** /**
* Destroys the packet and deallocates its data. * Destroys the packet and deallocates its data.
* @param packet packet to be destroyed * @param packet packet to be destroyed
@ -2181,18 +2218,17 @@ extern "C" {
if (peer->state != ENET_PEER_STATE_CONNECTED && peer->state != ENET_PEER_STATE_DISCONNECT_LATER) { if (peer->state != ENET_PEER_STATE_CONNECTED && peer->state != ENET_PEER_STATE_DISCONNECT_LATER) {
return -1; return -1;
} }
if (peer->incomingBandwidth != 0) { if (peer->incomingBandwidth != 0) {
--host->bandwidthLimitedPeers; --host->bandwidthLimitedPeers;
} }
peer->incomingBandwidth = ENET_NET_TO_HOST_32(command->bandwidthLimit.incomingBandwidth); peer->incomingBandwidth = ENET_NET_TO_HOST_32(command->bandwidthLimit.incomingBandwidth);
peer->outgoingBandwidth = ENET_NET_TO_HOST_32(command->bandwidthLimit.outgoingBandwidth);
if (peer->incomingBandwidth != 0) { if (peer->incomingBandwidth != 0) {
++host->bandwidthLimitedPeers; ++host->bandwidthLimitedPeers;
} }
peer->outgoingBandwidth = ENET_NET_TO_HOST_32(command->bandwidthLimit.outgoingBandwidth);
if (peer->incomingBandwidth == 0 && host->outgoingBandwidth == 0) { if (peer->incomingBandwidth == 0 && host->outgoingBandwidth == 0) {
peer->windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE; peer->windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE;
} else if (peer->incomingBandwidth == 0 || host->outgoingBandwidth == 0) { } else if (peer->incomingBandwidth == 0 || host->outgoingBandwidth == 0) {
@ -2605,7 +2641,8 @@ extern "C" {
goto commandError; goto commandError;
} }
if (peer != NULL && (command->header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE) != 0) { assert(peer);
if ((command->header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE) != 0) {
enet_uint16 sentTime; enet_uint16 sentTime;
if (!(flags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME)) { if (!(flags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME)) {
@ -3097,12 +3134,12 @@ extern "C" {
currentPeer->packetsLost = 0; currentPeer->packetsLost = 0;
} }
host->buffers->data = headerData; host->buffers[0].data = headerData;
if (host->headerFlags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME) { if (host->headerFlags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME) {
header->sentTime = ENET_HOST_TO_NET_16(host->serviceTime & 0xFFFF); header->sentTime = ENET_HOST_TO_NET_16(host->serviceTime & 0xFFFF);
host->buffers->dataLength = sizeof(ENetProtocolHeader); host->buffers[0].dataLength = sizeof(ENetProtocolHeader);
} else { } else {
host->buffers->dataLength = (size_t) &((ENetProtocolHeader *) 0)->sentTime; host->buffers[0].dataLength = (size_t) &((ENetProtocolHeader *) 0)->sentTime;
} }
shouldCompress = 0; shouldCompress = 0;
@ -3123,9 +3160,9 @@ extern "C" {
} }
header->peerID = ENET_HOST_TO_NET_16(currentPeer->outgoingPeerID | host->headerFlags); header->peerID = ENET_HOST_TO_NET_16(currentPeer->outgoingPeerID | host->headerFlags);
if (host->checksum != NULL) { if (host->checksum != NULL) {
enet_uint32 *checksum = (enet_uint32 *) &headerData[host->buffers->dataLength]; enet_uint32 *checksum = (enet_uint32 *) &headerData[host->buffers[0].dataLength];
*checksum = currentPeer->outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID ? currentPeer->connectID : 0; *checksum = currentPeer->outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID ? currentPeer->connectID : 0;
host->buffers->dataLength += sizeof(enet_uint32); host->buffers[0].dataLength += sizeof(enet_uint32);
*checksum = host->checksum(host->buffers, host->bufferCount); *checksum = host->checksum(host->buffers, host->bufferCount);
} }
@ -3140,6 +3177,9 @@ extern "C" {
enet_protocol_remove_sent_unreliable_commands(currentPeer); enet_protocol_remove_sent_unreliable_commands(currentPeer);
if (sentLength < 0) { if (sentLength < 0) {
// The local 'headerData' array (to which 'data' is assigned) goes out
// of scope on return from this function, so ensure we no longer point to it.
host->buffers[0].data = NULL;
return -1; return -1;
} }
@ -3148,6 +3188,10 @@ extern "C" {
host->totalSentPackets++; host->totalSentPackets++;
} }
// The local 'headerData' array (to which 'data' is assigned) goes out
// of scope on return from this function, so ensure we no longer point to it.
host->buffers[0].data = NULL;
return 0; return 0;
} /* enet_protocol_send_outgoing_commands */ } /* enet_protocol_send_outgoing_commands */
@ -3815,7 +3859,7 @@ extern "C" {
* @param pingInterval the interval at which to send pings; defaults to ENET_PEER_PING_INTERVAL if 0 * @param pingInterval the interval at which to send pings; defaults to ENET_PEER_PING_INTERVAL if 0
*/ */
void enet_peer_ping_interval(ENetPeer *peer, enet_uint32 pingInterval) { void enet_peer_ping_interval(ENetPeer *peer, enet_uint32 pingInterval) {
peer->pingInterval = pingInterval ? pingInterval : ENET_PEER_PING_INTERVAL; peer->pingInterval = pingInterval ? pingInterval : (enet_uint32)ENET_PEER_PING_INTERVAL;
} }
/** Sets the timeout parameters for a peer. /** Sets the timeout parameters for a peer.
@ -3836,9 +3880,9 @@ extern "C" {
*/ */
void enet_peer_timeout(ENetPeer *peer, enet_uint32 timeoutLimit, enet_uint32 timeoutMinimum, enet_uint32 timeoutMaximum) { void enet_peer_timeout(ENetPeer *peer, enet_uint32 timeoutLimit, enet_uint32 timeoutMinimum, enet_uint32 timeoutMaximum) {
peer->timeoutLimit = timeoutLimit ? timeoutLimit : ENET_PEER_TIMEOUT_LIMIT; peer->timeoutLimit = timeoutLimit ? timeoutLimit : (enet_uint32)ENET_PEER_TIMEOUT_LIMIT;
peer->timeoutMinimum = timeoutMinimum ? timeoutMinimum : ENET_PEER_TIMEOUT_MINIMUM; peer->timeoutMinimum = timeoutMinimum ? timeoutMinimum : (enet_uint32)ENET_PEER_TIMEOUT_MINIMUM;
peer->timeoutMaximum = timeoutMaximum ? timeoutMaximum : ENET_PEER_TIMEOUT_MAXIMUM; peer->timeoutMaximum = timeoutMaximum ? timeoutMaximum : (enet_uint32)ENET_PEER_TIMEOUT_MAXIMUM;
} }
/** Force an immediate disconnection from a peer. /** Force an immediate disconnection from a peer.
@ -4293,10 +4337,9 @@ extern "C" {
memset(incomingCommand->fragments, 0, (fragmentCount + 31) / 32 * sizeof(enet_uint32)); memset(incomingCommand->fragments, 0, (fragmentCount + 31) / 32 * sizeof(enet_uint32));
} }
if (packet != NULL) { assert(packet != NULL);
++packet->referenceCount; ++packet->referenceCount;
peer->totalWaitingData += packet->dataLength; peer->totalWaitingData += packet->dataLength;
}
enet_list_insert(enet_list_next(currentCommand), incomingCommand); enet_list_insert(enet_list_next(currentCommand), incomingCommand);
@ -4318,7 +4361,8 @@ extern "C" {
goto notifyError; goto notifyError;
} }
if (packet != NULL && packet->referenceCount == 0) { assert(packet != NULL);
if (packet->referenceCount == 0) {
callbacks.packet_destroy(packet); callbacks.packet_destroy(packet);
} }
@ -4401,11 +4445,9 @@ extern "C" {
if (!channelLimit || channelLimit > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT) { if (!channelLimit || channelLimit > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT) {
channelLimit = ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT; channelLimit = ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT;
} else if (channelLimit < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT) {
channelLimit = ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT;
} }
host->randomSeed = (enet_uint32) (size_t) host; host->randomSeed = (enet_uint32) ((uintptr_t) host % UINT32_MAX);
host->randomSeed += enet_host_random_seed(); host->randomSeed += enet_host_random_seed();
host->randomSeed = (host->randomSeed << 16) | (host->randomSeed >> 16); host->randomSeed = (host->randomSeed << 16) | (host->randomSeed >> 16);
host->channelLimit = channelLimit; host->channelLimit = channelLimit;
@ -4654,10 +4696,7 @@ extern "C" {
void enet_host_channel_limit(ENetHost *host, size_t channelLimit) { void enet_host_channel_limit(ENetHost *host, size_t channelLimit) {
if (!channelLimit || channelLimit > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT) { if (!channelLimit || channelLimit > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT) {
channelLimit = ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT; channelLimit = ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT;
} else if (channelLimit < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT) {
channelLimit = ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT;
} }
host->channelLimit = channelLimit; host->channelLimit = channelLimit;
} }
@ -4865,8 +4904,8 @@ extern "C" {
t.QuadPart |= f.dwLowDateTime; t.QuadPart |= f.dwLowDateTime;
return (t); return (t);
} }
int clock_gettime(int X, struct timespec *tv) { int clock_gettime(int X, struct timespec *tv) {
(void)X;
LARGE_INTEGER t; LARGE_INTEGER t;
FILETIME f; FILETIME f;
double microseconds; double microseconds;
@ -4970,6 +5009,119 @@ extern "C" {
return (enet_uint32)(result_in_ns / ns_in_ms); return (enet_uint32)(result_in_ns / ns_in_ms);
} }
void enet_inaddr_map4to6(struct in_addr in, struct in6_addr *out)
{
if (in.s_addr == 0x00000000) { /* 0.0.0.0 */
*out = enet_v6_anyaddr;
} else if (in.s_addr == 0xFFFFFFFF) { /* 255.255.255.255 */
*out = enet_v6_noaddr;
} else {
*out = enet_v4_anyaddr;
out->s6_addr[10] = 0xFF;
out->s6_addr[11] = 0xFF;
out->s6_addr[12] = ((uint8_t *)&in.s_addr)[0];
out->s6_addr[13] = ((uint8_t *)&in.s_addr)[1];
out->s6_addr[14] = ((uint8_t *)&in.s_addr)[2];
out->s6_addr[15] = ((uint8_t *)&in.s_addr)[3];
}
}
void enet_inaddr_map6to4(const struct in6_addr *in, struct in_addr *out)
{
memset(out, 0, sizeof(struct in_addr));
((uint8_t *)&out->s_addr)[0] = in->s6_addr[12];
((uint8_t *)&out->s_addr)[1] = in->s6_addr[13];
((uint8_t *)&out->s_addr)[2] = in->s6_addr[14];
((uint8_t *)&out->s_addr)[3] = in->s6_addr[15];
}
int enet_in6addr_lookup_host(const char *name, bool nodns, ENetAddress *out) {
struct addrinfo hints, *resultList = NULL, *result = NULL;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
if (nodns)
{
hints.ai_flags = AI_NUMERICHOST; /* prevent actual DNS lookups! */
}
if (getaddrinfo(name, NULL, &hints, &resultList) != 0) {
freeaddrinfo(resultList);
return -1;
}
for (result = resultList; result != NULL; result = result->ai_next) {
if (result->ai_addr != NULL) {
if (result->ai_family == AF_INET || (result->ai_family == AF_UNSPEC && result->ai_addrlen == sizeof(struct sockaddr_in))) {
enet_inaddr_map4to6(((struct sockaddr_in*)result->ai_addr)->sin_addr, &out->host);
out->sin6_scope_id = 0;
freeaddrinfo(resultList);
return 0;
} else if (result->ai_family == AF_INET6 || (result->ai_family == AF_UNSPEC && result->ai_addrlen == sizeof(struct sockaddr_in6))) {
memcpy(&out->host, &((struct sockaddr_in6*)result->ai_addr)->sin6_addr, sizeof(struct in6_addr));
out->sin6_scope_id = (enet_uint16) ((struct sockaddr_in6*)result->ai_addr)->sin6_scope_id;
freeaddrinfo(resultList);
return 0;
}
}
}
freeaddrinfo(resultList);
return -1;
}
int enet_address_set_host_ip_new(ENetAddress *address, const char *name) {
return enet_in6addr_lookup_host(name, true, address);
}
int enet_address_set_host_new(ENetAddress *address, const char *name) {
return enet_in6addr_lookup_host(name, false, address);
}
int enet_address_get_host_ip_new(const ENetAddress *address, char *name, size_t nameLength) {
if (IN6_IS_ADDR_V4MAPPED(&address->host)) {
struct in_addr buf;
enet_inaddr_map6to4(&address->host, &buf);
if (inet_ntop(AF_INET, &buf, name, nameLength) == NULL) {
return -1;
}
}
else {
if (inet_ntop(AF_INET6, (void*)&address->host, name, nameLength) == NULL) {
return -1;
}
}
return 0;
} /* enet_address_get_host_ip_new */
int enet_address_get_host_new(const ENetAddress *address, char *name, size_t nameLength) {
struct sockaddr_in6 sin;
memset(&sin, 0, sizeof(struct sockaddr_in6));
int err;
sin.sin6_family = AF_INET6;
sin.sin6_port = ENET_HOST_TO_NET_16 (address->port);
sin.sin6_addr = address->host;
sin.sin6_scope_id = address->sin6_scope_id;
err = getnameinfo((struct sockaddr *) &sin, sizeof(sin), name, nameLength, NULL, 0, NI_NAMEREQD);
if (!err) {
if (name != NULL && nameLength > 0 && !memchr(name, '\0', nameLength)) {
return -1;
}
return 0;
}
if (err != EAI_NONAME) {
return -1;
}
return enet_address_get_host_ip_new(address, name, nameLength);
} /* enet_address_get_host_new */
// =======================================================================// // =======================================================================//
// ! // !
// ! Platform Specific (Unix) // ! Platform Specific (Unix)
@ -5159,7 +5311,7 @@ extern "C" {
} }
} }
#endif // __MINGW__ #endif // __MINGW__
int enet_initialize(void) { int enet_initialize(void) {
return 0; return 0;
} }
@ -5170,7 +5322,7 @@ extern "C" {
return (enet_uint64) time(NULL); return (enet_uint64) time(NULL);
} }
int enet_address_set_host_ip(ENetAddress *address, const char *name) { int enet_address_set_host_ip_old(ENetAddress *address, const char *name) {
if (!inet_pton(AF_INET6, name, &address->host)) { if (!inet_pton(AF_INET6, name, &address->host)) {
return -1; return -1;
} }
@ -5178,7 +5330,7 @@ extern "C" {
return 0; return 0;
} }
int enet_address_set_host(ENetAddress *address, const char *name) { int enet_address_set_host_old(ENetAddress *address, const char *name) {
struct addrinfo hints, *resultList = NULL, *result = NULL; struct addrinfo hints, *resultList = NULL, *result = NULL;
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
@ -5199,7 +5351,6 @@ extern "C" {
((uint32_t *)&address->host.s6_addr)[3] = sin->sin_addr.s_addr; ((uint32_t *)&address->host.s6_addr)[3] = sin->sin_addr.s_addr;
freeaddrinfo(resultList); freeaddrinfo(resultList);
return 0; return 0;
} }
else if(result->ai_family == AF_INET6) { else if(result->ai_family == AF_INET6) {
@ -5209,21 +5360,16 @@ extern "C" {
address->sin6_scope_id = sin->sin6_scope_id; address->sin6_scope_id = sin->sin6_scope_id;
freeaddrinfo(resultList); freeaddrinfo(resultList);
return 0; return 0;
} }
} }
} }
freeaddrinfo(resultList);
if (resultList != NULL) {
freeaddrinfo(resultList);
}
return enet_address_set_host_ip(address, name); return enet_address_set_host_ip(address, name);
} /* enet_address_set_host */ } /* enet_address_set_host_old */
int enet_address_get_host_ip(const ENetAddress *address, char *name, size_t nameLength) { int enet_address_get_host_ip_old(const ENetAddress *address, char *name, size_t nameLength) {
if (inet_ntop(AF_INET6, &address->host, name, nameLength) == NULL) { if (inet_ntop(AF_INET6, &address->host, name, nameLength) == NULL) {
return -1; return -1;
} }
@ -5231,17 +5377,14 @@ extern "C" {
return 0; return 0;
} }
int enet_address_get_host(const ENetAddress *address, char *name, size_t nameLength) { int enet_address_get_host_old(const ENetAddress *address, char *name, size_t nameLength) {
struct sockaddr_in6 sin; struct sockaddr_in6 sin;
int err; int err;
memset(&sin, 0, sizeof(struct sockaddr_in6)); memset(&sin, 0, sizeof(struct sockaddr_in6));
sin.sin6_family = AF_INET6; sin.sin6_family = AF_INET6;
sin.sin6_port = ENET_HOST_TO_NET_16 (address->port); sin.sin6_port = ENET_HOST_TO_NET_16 (address->port);
sin.sin6_addr = address->host; sin.sin6_addr = address->host;
sin.sin6_scope_id = address->sin6_scope_id; sin.sin6_scope_id = address->sin6_scope_id;
err = getnameinfo((struct sockaddr *) &sin, sizeof(sin), name, nameLength, NULL, 0, NI_NAMEREQD); err = getnameinfo((struct sockaddr *) &sin, sizeof(sin), name, nameLength, NULL, 0, NI_NAMEREQD);
if (!err) { if (!err) {
if (name != NULL && nameLength > 0 && !memchr(name, '\0', nameLength)) { if (name != NULL && nameLength > 0 && !memchr(name, '\0', nameLength)) {
@ -5252,9 +5395,8 @@ extern "C" {
if (err != EAI_NONAME) { if (err != EAI_NONAME) {
return -1; return -1;
} }
return enet_address_get_host_ip(address, name, nameLength); return enet_address_get_host_ip(address, name, nameLength);
} /* enet_address_get_host */ } /* enet_address_get_host_old */
int enet_socket_bind(ENetSocket socket, const ENetAddress *address) { int enet_socket_bind(ENetSocket socket, const ENetAddress *address) {
struct sockaddr_in6 sin; struct sockaddr_in6 sin;
@ -5294,7 +5436,7 @@ extern "C" {
} }
ENetSocket enet_socket_create(ENetSocketType type) { ENetSocket enet_socket_create(ENetSocketType type) {
return socket(PF_INET6, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0); return socket(PF_INET6, (int)type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
} }
int enet_socket_set_option(ENetSocket socket, ENetSocketOption option, int value) { int enet_socket_set_option(ENetSocket socket, ENetSocketOption option, int value) {
@ -5579,7 +5721,7 @@ extern "C" {
return (enet_uint64) timeGetTime(); return (enet_uint64) timeGetTime();
} }
int enet_address_set_host_ip(ENetAddress *address, const char *name) { int enet_address_set_host_ip_old(ENetAddress *address, const char *name) {
enet_uint8 vals[4] = { 0, 0, 0, 0 }; enet_uint8 vals[4] = { 0, 0, 0, 0 };
int i; int i;
@ -5603,7 +5745,7 @@ extern "C" {
return 0; return 0;
} }
int enet_address_set_host(ENetAddress *address, const char *name) { int enet_address_set_host_old(ENetAddress *address, const char *name) {
struct hostent *hostEntry = NULL; struct hostent *hostEntry = NULL;
hostEntry = gethostbyname(name); hostEntry = gethostbyname(name);
@ -5623,7 +5765,7 @@ extern "C" {
return 0; return 0;
} }
int enet_address_get_host_ip(const ENetAddress *address, char *name, size_t nameLength) { int enet_address_get_host_ip_old(const ENetAddress *address, char *name, size_t nameLength) {
if (inet_ntop(AF_INET6, (PVOID)&address->host, name, nameLength) == NULL) { if (inet_ntop(AF_INET6, (PVOID)&address->host, name, nameLength) == NULL) {
return -1; return -1;
} }
@ -5631,13 +5773,11 @@ extern "C" {
return 0; return 0;
} }
int enet_address_get_host(const ENetAddress *address, char *name, size_t nameLength) { int enet_address_get_host_old(const ENetAddress *address, char *name, size_t nameLength) {
struct in6_addr in; struct in6_addr in;
struct hostent *hostEntry = NULL; struct hostent *hostEntry = NULL;
in = address->host; in = address->host;
hostEntry = gethostbyaddr((char *)&in, sizeof(struct in6_addr), AF_INET6); hostEntry = gethostbyaddr((char *)&in, sizeof(struct in6_addr), AF_INET6);
if (hostEntry == NULL) { if (hostEntry == NULL) {
return enet_address_get_host_ip(address, name, nameLength); return enet_address_get_host_ip(address, name, nameLength);
} else { } else {
@ -5647,7 +5787,6 @@ extern "C" {
} }
memcpy(name, hostEntry->h_name, hostLen + 1); memcpy(name, hostEntry->h_name, hostLen + 1);
} }
return 0; return 0;
} }

36661
code/vendors/librg.h vendored

File diff suppressed because it is too large Load Diff