diff --git a/include/basin/accept.h b/include/basin/accept.h new file mode 100644 index 0000000..48ddfe9 --- /dev/null +++ b/include/basin/accept.h @@ -0,0 +1,13 @@ +#ifndef BASIN_ACCEPT_H_ +#define BASIN_ACCEPT_H_ + +#include + +void run_accept(struct server* param); + +struct timeval { + int32_t tv_sec; + int32_t tv_usec; +}; + +#endif /* BASIN_ACCEPT_H_ */ diff --git a/include/basin/game.h b/include/basin/game.h index d96e1c0..b5fffab 100644 --- a/include/basin/game.h +++ b/include/basin/game.h @@ -51,6 +51,6 @@ void broadcastf(char* color, char* fmt, ...); #define BEGIN_BROADCAST_EXCEPT(players, except) if(players->mc) pthread_rwlock_rdlock(&players->data_mutex); for (size_t i = 0; i < players->size; i++) {struct player* bc_player = (struct player*) players->data[i];if (bc_player != NULL && bc_player != except) { #define END_BROADCAST_MT(players) }} if(players->mc) pthread_rwlock_unlock(&players->data_mutex); #define END_BROADCAST }} - */ +*/ #endif /* BASIN_GAME_H_ */ diff --git a/src/light.h b/include/basin/light.h similarity index 100% rename from src/light.h rename to include/basin/light.h diff --git a/src/login_stage_handler.h b/include/basin/login_stage_handler.h similarity index 100% rename from src/login_stage_handler.h rename to include/basin/login_stage_handler.h diff --git a/src/wake_thread.h b/include/basin/wake_thread.h similarity index 100% rename from src/wake_thread.h rename to include/basin/wake_thread.h diff --git a/src/work.h b/include/basin/work.h similarity index 100% rename from src/work.h rename to include/basin/work.h diff --git a/src/accept.c b/src/accept.c index f390e06..98e82ea 100644 --- a/src/accept.c +++ b/src/accept.c @@ -1,5 +1,5 @@ -#include "accept.h" -#include "work.h" +#include +#include #include #include #include @@ -46,7 +46,6 @@ void run_accept(struct server* server) { if ((spfd.revents ^ POLLIN) != 0) { printf("Error after polling server: %i (poll revents)!\n", spfd.revents); pfree(pool); - break; } spfd.revents = 0; int fd = accept(server->fd, (struct sockaddr*) &conn->addr, &conn->addrlen); diff --git a/src/accept.h b/src/accept.h deleted file mode 100644 index a67630d..0000000 --- a/src/accept.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef ACCEPT_H_ -#define ACCEPT_H_ - -#include - -void run_accept(struct server* param); - -#endif /* ACCEPT_H_ */ diff --git a/src/ai.c b/src/ai.c index a82a64e..ee7f1c8 100644 --- a/src/ai.c +++ b/src/ai.c @@ -601,11 +601,15 @@ int ai_shouldnearestattackabletarget(struct world* world, struct entity* entity, struct entity* ce = NULL; BEGIN_HASHMAP_ITERATION(world->entities); struct entity* ie = value; - if (!entity_has_flag(entity_get_info(ie->type), "livingbase") || ie == entity) continue; + if (!entity_has_flag(entity_get_info(ie->type), "livingbase") || ie == entity) { + + } double dsq = entity_distsq(entity, value); if (ie->type == ENT_PLAYER) { struct player* pl = ie->data.player.player; - if (pl->gamemode == 1 || pl->gamemode == 3 || pl->invulnerable) continue; + if (pl->gamemode == 1 || pl->gamemode == 3 || pl->invulnerable) { + + } int sk = entity_has_flag(entity_get_info(entity->type), "skeleton"); int zo = entity_has_flag(entity_get_info(entity->type), "zombie"); int cr = entity_has_flag(entity_get_info(entity->type), "creeper"); diff --git a/src/block.c b/src/block.c index 1821645..ef35ee7 100644 --- a/src/block.c +++ b/src/block.c @@ -448,10 +448,12 @@ void onBlockInteract_workbench(struct world* world, block blk, int32_t x, int32_ block onBlockPlaced_chest(struct world* world, block blk, int32_t x, int32_t y, int32_t z, block replaced) { int16_t meta = blk & 0x0f; if (meta < 2 || meta > 5) meta = 2; + struct mempool* pool = mempool_new(); struct tile_entity* te = tile_new("minecraft:chest", x, y, z); te->data.chest.lock = NULL; te->data.chest.inv = xmalloc(sizeof(struct inventory)); - inventory_new(te->data.chest.inv, INVTYPE_CHEST, 2, 27); + struct mempool* pool = mempool_new(); + inventory_new(pool, te->data.chest.inv, INVTYPE_CHEST, 2, 27); te->data.chest.inv->tile = te; te->data.chest.inv->title = xstrdup("{\"text\": \"Chest\"}", 0); world_set_tile(world, x, y, z, te); diff --git a/src/command.c b/src/command.c index 4d7e4eb..b43d1cd 100644 --- a/src/command.c +++ b/src/command.c @@ -234,7 +234,9 @@ void callCommand(struct player* player, struct mempool* pool, char* command) { } for (size_t i3 = 0; i3 < registered_commands->size; i3++) { struct command* com = (struct command*) registered_commands->data[i3]; - if (com == NULL) continue; + if (com == NULL) { + + } if (streq_nocase(com->command, rc)) { (*com->callback)(player, args, arg_count); return; diff --git a/src/crafting.c b/src/crafting.c index b9e75f1..5996433 100644 --- a/src/crafting.c +++ b/src/crafting.c @@ -82,8 +82,7 @@ void crafting_init() { ITER_LLIST_END(); } list_append(crafting_recipies, recipe); - continue; - crafting_format_error:; + crafting_format_error: ; printf("[WARNING] Error Loading Crafting Recipe \"%s\"! Skipped.\n", child_json->name); ITER_LLIST_END(); } @@ -94,7 +93,9 @@ void crafting_once(struct player* player, struct inventory* inv) { int cap = inv->type == INVTYPE_PLAYERINVENTORY ? 4 : 9; for (int i = 1; i <= cap; i++) { struct slot* slot = inventory_get(player, inv, i); - if (slot == NULL) continue; + if (slot == NULL) { + + } if (--slot->count <= 0) { if (slot->nbt != NULL) { pfree(slot->nbt->pool); @@ -111,12 +112,16 @@ int crafting_all(struct player* player, struct inventory* inv) { uint8_t count = 64; for (int i = 1; i <= cap; i++) { struct slot* slot = inventory_get(player, inv, i); - if (slot == NULL) continue; + if (slot == NULL) { + + } if (slot->count < count) count = slot->count; } for (int i = 1; i <= cap; i++) { struct slot* slot = inventory_get(player, inv, i); - if (slot == NULL) continue; + if (slot == NULL) { + + } slot->count -= count; if (slot->count <= 0) { if (slot->nbt != NULL) { @@ -177,12 +182,16 @@ struct slot* crafting_result(struct mempool* pool, struct slot** slots, size_t s for (size_t i = 0; i < crafting_recipies->size; i++) { struct crafting_recipe* recipe = (struct crafting_recipe*) crafting_recipies->data[i]; - if (recipe == NULL || (recipe->width > 2 && slot_count <= 4) || (slot_count == 4 && (recipe->slot[6] != NULL || recipe->slot[7] != NULL || recipe->slot[8] != NULL))) continue; + if (recipe == NULL || (recipe->width > 2 && slot_count <= 4) || (slot_count == 4 && (recipe->slot[6] != NULL || recipe->slot[7] != NULL || recipe->slot[8] != NULL))) { + + } if (recipe->shapeless) { // TODO: optimize int matching = 1; for (int slot_index = 0; slot_index <= slot_count; slot_index++) { struct slot* slot = slots[slot_index]; - if (slot == NULL) continue; + if (slot == NULL) { + + } int local_matched = 0; for (int ri = 0; ri < 9; ri++) { struct slot* local_slot = recipe->slot[ri]; @@ -199,7 +208,9 @@ struct slot* crafting_result(struct mempool* pool, struct slot** slots, size_t s if (matching) { for (int slot_index_2 = 0; slot_index_2 < 9; slot_index_2++) { struct slot* slot = recipe->slot[slot_index_2]; - if (slot == NULL) continue; + if (slot == NULL) { + + } int local_matched = 0; for (int ls = 1; ls <= 4; ls++) { struct slot* local_slot = slots[ls]; diff --git a/src/entity.c b/src/entity.c index ae57d3a..9c0048f 100644 --- a/src/entity.c +++ b/src/entity.c @@ -133,7 +133,6 @@ void init_entities() { info->dataname = str_dup(tmp->data.string, 0, entities_pool); list_set(entity_infos, id, info); hashmap_put(entity_infos_by_name, str_tolower(str_dup(info->dataname, 0, entities_pool)), info); - continue; entity_error: ; printf("[WARNING] Error Loading Entity \"%s\"! Skipped.\n", child_json->name); ITER_LLIST_END(); @@ -539,10 +538,14 @@ int entity_move(struct entity* entity, double* motionX, double* motionY, double* for (int32_t z = (int32_t) floor(obb.minZ); z < floor(obb.maxZ + 1.); z++) { for (int32_t y = (int32_t) floor(obb.minY); y < floor(obb.maxY + 1.); y++) { block b = world_get_block_guess(entity->world, ch, x, y, z); - if (b == 0) continue; + if (b == 0) { + + } b = entity_adjustCollision(entity->world, entity, ch, b, x, y, z); struct block_info* bi = getBlockInfo(b); - if (bi == NULL) continue; + if (bi == NULL) { + + } for (size_t i = 0; i < bi->boundingBox_count; i++) { struct boundingbox* bbx = &bi->boundingBoxes[i]; struct boundingbox bbd; @@ -578,10 +581,14 @@ int entity_move(struct entity* entity, double* motionX, double* motionY, double* for (int32_t z = (int32_t) floor(obb.minZ); z < floor(obb.maxZ + 1.); z++) { for (int32_t y = (int32_t) floor(obb.minY); y < floor(obb.maxY + 1.); y++) { block b = world_get_block_guess(entity->world, ch, x, y, z); - if (b == 0) continue; + if (b == 0) { + + } b = entity_adjustCollision(entity->world, entity, ch, b, x, y, z); struct block_info* bi = getBlockInfo(b); - if (bi == NULL) continue; + if (bi == NULL) { + + } for (size_t i = 0; i < bi->boundingBox_count; i++) { struct boundingbox* bbx = &bi->boundingBoxes[i]; struct boundingbox bbd; @@ -617,10 +624,14 @@ int entity_move(struct entity* entity, double* motionX, double* motionY, double* for (int32_t z = (int32_t) floor(obb.minZ); z < floor(obb.maxZ + 1.); z++) { for (int32_t y = (int32_t) floor(obb.minY); y < floor(obb.maxY + 1.); y++) { block b = world_get_block_guess(entity->world, ch, x, y, z); - if (b == 0) continue; + if (b == 0) { + + } b = entity_adjustCollision(entity->world, entity, ch, b, x, y, z); struct block_info* bi = getBlockInfo(b); - if (bi == NULL) continue; + if (bi == NULL) { + + } for (size_t i = 0; i < bi->boundingBox_count; i++) { struct boundingbox* bbx = &bi->boundingBoxes[i]; struct boundingbox bbd; @@ -835,7 +846,9 @@ int damageEntity(struct entity* attacked, float damage, int armorable) { for (size_t i = 0; i < info->loot_count; i++) { struct entity_loot* el = &info->loots[i]; int amt = el->amountMax == el->amountMin ? el->amountMax : (rand() % (el->amountMax - el->amountMin) + el->amountMin); - if (amt <= 0) continue; + if (amt <= 0) { + + } struct slot it; it.item = el->id; it.count = (unsigned char) amt; @@ -888,9 +901,13 @@ int entity_inFluid(struct entity* entity, uint16_t blk, float ydown, int meta_ch for (int32_t z = (int32_t) floor(pbb.minZ); z < floor(pbb.maxZ + 1.); z++) { for (int32_t y = (int32_t) floor(pbb.minY); y < floor(pbb.maxY + 1.); y++) { block b = world_get_block(entity->world, x, y, z); - if (meta_check ? (b != blk) : ((b >> 4) != (blk >> 4))) continue; + if (meta_check ? (b != blk) : ((b >> 4) != (blk >> 4))) { + + } struct block_info* bi = getBlockInfo(b); - if (bi == NULL) continue; + if (bi == NULL) { + + } struct boundingbox bb2; bb2.minX = 0. + (double) x; bb2.maxX = 1. + (double) x; @@ -921,9 +938,13 @@ int entity_inBlock(struct entity* ent, block blk) { // blk = 0 for any block for (int32_t z = floor(obb.minZ); z < floor(obb.maxZ + 1.); z++) { for (int32_t y = floor(obb.minY); y < floor(obb.maxY + 1.); y++) { block b = world_get_block(ent->world, x, y, z); - if (b == 0 || (blk != 0 && blk != b)) continue; + if (b == 0 || (blk != 0 && blk != b)) { + + } struct block_info* bi = getBlockInfo(b); - if (bi == NULL) continue; + if (bi == NULL) { + + } for (size_t i = 0; i < bi->boundingBox_count; i++) { struct boundingbox* bb = &bi->boundingBoxes[i]; struct boundingbox nbb; diff --git a/src/entity_impl.c b/src/entity_impl.c index 0fda1e2..b42f2e2 100644 --- a/src/entity_impl.c +++ b/src/entity_impl.c @@ -1,7 +1,8 @@ - +#include #include #include #include +#include #include #include #include @@ -21,7 +22,7 @@ void onSpawned_minecart(struct world* world, struct entity* entity) { void onTick_tnt(struct world* world, struct entity* entity) { if (entity->data.tnt.fuse-- <= 0) { world_despawn_entity(world, entity); - world_explode(world, NULL, entity->x, entity->y + .5, entity->z, 4f); + world_explode(world, NULL, entity->x, entity->y + .5, entity->z, .4f); } } @@ -108,11 +109,12 @@ void tick_arrow(struct world* world, struct entity* entity) { struct entity* ehit = NULL; struct entity* shooter = world_get_entity(world, entity->objectData - 1); double bd = 999.; - BEGIN_HASHMAP_ITERATION(world->entities) + BEGIN_HASHMAP_ITERATION(world->entities); struct entity* e2 = value; double rd = entity_distsq_block(e2, entity->x + entity->motX, entity->y + entity->motY, entity->z + entity->motZ); - if (rd > 4) continue; - //printf("4d %f\n", rd); + if (rd > 4) { + //printf("4d %f\n", rd); + } if (e2 != entity && e2 != shooter && hasFlag(getEntityInfo(e2->type), "livingbase")) { //todo: ticksInAir >= 5? struct boundingbox eb; getEntityCollision(e2, &eb); @@ -135,7 +137,7 @@ void tick_arrow(struct world* world, struct entity* entity) { } } } - END_HASHMAP_ITERATION(world->entities) + END_HASHMAP_ITERATION(world->entities); if (ehit != NULL) { float speed = sqrtf(entity->motX * entity->motX + entity->motY * entity->motY + entity->motZ * entity->motZ); int damage = ceil(speed * entity->data.arrow.damage); @@ -152,7 +154,7 @@ void tick_arrow(struct world* world, struct entity* entity) { if (ehit->type != ENT_ENDERMAN) { world_despawn_entity(world, entity); freeEntity(entity); - return 1; + return; } } else if (hf >= 0) { entity->x = hx; @@ -185,7 +187,7 @@ void tick_arrow(struct world* world, struct entity* entity) { if (entity->data.arrow.ticksInGround == 1200) { world_despawn_entity(world, entity); freeEntity(entity); - return 1; + return; } } @@ -209,20 +211,24 @@ void tick_arrow(struct world* world, struct entity* entity) { entity->yaw = entity->last_yaw + (entity->yaw - entity->last_yaw) * .2; } } - return 0; + return; } void tick_itemstack(struct world* world, struct entity* entity) { if (entity->data.itemstack.delayBeforeCanPickup > 0) { entity->data.itemstack.delayBeforeCanPickup--; - return 0; } if (entity->age >= 6000) { - world_despawn_entity(world, entity); + world_despawn_entity(world, entity); + /* + TODO: Make this a configurable option and improve the mechanics of despawning. + All nametagged entities (as well as wolves) must be excluded. + */ freeEntity(entity); - return 1; } - if (tick_counter % 10 != 0) return 0; + if (world->tick_counter % 10 != 0) { + + } struct boundingbox cebb; getEntityCollision(entity, &cebb); cebb.minX -= .625; @@ -231,46 +237,48 @@ void tick_itemstack(struct world* world, struct entity* entity) { cebb.minZ -= .625; cebb.maxZ += .625; struct boundingbox oebb; -//int32_t chunk_x = ((int32_t) entity->x) >> 4; -//int32_t chunk_z = ((int32_t) entity->z) >> 4; -//for (int32_t icx = chunk_x - 1; icx <= chunk_x + 1; icx++) -//for (int32_t icz = chunk_z - 1; icz <= chunk_z + 1; icz++) { -//struct chunk* ch = world_get_chunk(entity->world, icx, icz); -//if (ch != NULL) { - BEGIN_HASHMAP_ITERATION(entity->world->entities) - struct entity* oe = (struct entity*) value; - if (oe == entity || entity_distsq(entity, oe) > 16. * 16.) continue; - if (oe->type == ENT_PLAYER && oe->health > 0.) { - getEntityCollision(oe, &oebb); - //printf("%f, %f, %f vs %f, %f, %f\n", entity->x, entity->y, entity->z, oe->x, oe->y, oe->z); - if (boundingbox_intersects(&oebb, &cebb)) { - int os = entity->data.itemstack.slot->count; - pthread_mutex_lock(&oe->data.player.player->inventory->mut); - int r = inventory_add_player(oe->data.player.player, oe->data.player.player->inventory, entity->data.itemstack.slot, 1); - pthread_mutex_unlock(&oe->data.player.player->inventory->mut); - if (r <= 0) { - BEGIN_BROADCAST_DIST(entity, 32.) - struct packet* pkt = xmalloc(sizeof(struct packet)); - pkt->id = PKT_PLAY_CLIENT_COLLECTITEM; - pkt->data.play_client.collectitem.collected_entity_id = entity->id; - pkt->data.play_client.collectitem.collector_entity_id = oe->id; - pkt->data.play_client.collectitem.pickup_item_count = os - r; - add_queue(bc_player->outgoing_packets, pkt); - END_BROADCAST(entity->world->players) - world_despawn_entity(world, entity); - freeEntity(entity); - return 1; + /* + int32_t chunk_x = ((int32_t) entity->x) >> 4; + int32_t chunk_z = ((int32_t) entity->z) >> 4; + for (int32_t icx = chunk_x - 1; icx <= chunk_x + 1; icx++) + for (int32_t icz = chunk_z - 1; icz <= chunk_z + 1; icz++) { + struct chunk* ch = world_get_chunk(entity->world, icx, icz); + */ + if (ch != NULL) { + BEGIN_HASHMAP_ITERATION(entity->world->entities); + struct entity* oe = (struct entity*) value; + if (oe == entity || entity_distsq(entity, oe) > 16. * 16.) { + + } + if (oe->type == ENT_PLAYER && oe->health > 0.) { + getEntityCollision(oe, &oebb); + //printf("%f, %f, %f vs %f, %f, %f\n", entity->x, entity->y, entity->z, oe->x, oe->y, oe->z); + if (boundingbox_intersects(&oebb, &cebb)) { + int os = entity->data.itemstack.slot->count; + pthread_mutex_lock(&oe->data.player.player->inventory->mut); + int r = inventory_add_player(oe->data.player.player, oe->data.player.player->inventory, entity->data.itemstack.slot, 1); + pthread_mutex_unlock(&oe->data.player.player->inventory->mut); + if (r <= 0) { + BEGIN_BROADCAST_DIST(entity, 32.); + struct packet* pkt = xmalloc(sizeof(struct packet)); + pkt->id = PKT_PLAY_CLIENT_COLLECTITEM; + pkt->data.play_client.collectitem.collected_entity_id = entity->id; + pkt->data.play_client.collectitem.collector_entity_id = oe->id; + pkt->data.play_client.collectitem.pickup_item_count = os - r; + add_queue(bc_player->outgoing_packets, pkt); + END_BROADCAST(entity->world->players); + world_despawn_entity(world, entity); + freeEntity(entity); } else { - BEGIN_BROADCAST_DIST(entity, 128.) - struct packet* pkt = xmalloc(sizeof(struct packet)); - pkt->id = PKT_PLAY_CLIENT_ENTITYMETADATA; - pkt->data.play_client.entitymetadata.entity_id = entity->id; - writeMetadata(entity, &pkt->data.play_client.entitymetadata.metadata.metadata, &pkt->data.play_client.entitymetadata.metadata.metadata_size); - add_queue(bc_player->outgoing_packets, pkt); - END_BROADCAST(entity->world->players) - BREAK_HASHMAP_ITERATION(entity->world->entities) + BEGIN_BROADCAST_DIST(entity, 128.); + struct packet* pkt = xmalloc(sizeof(struct packet)); + pkt->id = PKT_PLAY_CLIENT_ENTITYMETADATA; + pkt->data.play_client.entitymetadata.entity_id = entity->id; + writeMetadata(entity, &pkt->data.play_client.entitymetadata.metadata.metadata, &pkt->data.play_client.entitymetadata.metadata.metadata_size); + add_queue(bc_player->outgoing_packets, pkt); + END_BROADCAST(entity->world->players); + BREAK_HASHMAP_ITERATION(entity->world->entities); } - break; } } else if (oe->type == ENT_ITEM) { if (oe->data.itemstack.slot->item == entity->data.itemstack.slot->item && oe->data.itemstack.slot->damage == entity->data.itemstack.slot->damage && oe->data.itemstack.slot->count + entity->data.itemstack.slot->count <= slot_max_size(entity->data.itemstack.slot)) { @@ -284,17 +292,16 @@ void tick_itemstack(struct world* world, struct entity* entity) { world_despawn_entity(world, entity); oe->data.itemstack.slot->count += entity->data.itemstack.slot->count; freeEntity(entity); - BEGIN_BROADCAST_DIST(oe, 128.) + BEGIN_BROADCAST_DIST(oe, 128.); struct packet* pkt = xmalloc(sizeof(struct packet)); pkt->id = PKT_PLAY_CLIENT_ENTITYMETADATA; pkt->data.play_client.entitymetadata.entity_id = oe->id; writeMetadata(oe, &pkt->data.play_client.entitymetadata.metadata.metadata, &pkt->data.play_client.entitymetadata.metadata.metadata_size); add_queue(bc_player->outgoing_packets, pkt); END_BROADCAST(oe->world->players) - return 1; } } } - END_HASHMAP_ITERATION(entity->world->entities) - return 0; + END_HASHMAP_ITERATION(entity->world->entities); + return; } diff --git a/src/game.c b/src/game.c index 63caffb..4b849cd 100644 --- a/src/game.c +++ b/src/game.c @@ -37,7 +37,8 @@ void game_load_player(struct player* to, struct player* from) { packet->data.play_client.spawnplayer.z = from->entity->z; packet->data.play_client.spawnplayer.yaw = (uint8_t) ((from->entity->yaw / 360.) * 256.); packet->data.play_client.spawnplayer.pitch = (uint8_t) ((from->entity->pitch / 360.) * 256.); - entitymeta_write(from->entity, &packet->data.play_client.spawnplayer.metadata.metadata, &packet->data.play_client.spawnplayer.metadata.metadata_size); + struct mempool* pool = mempool_new(); + entitymeta_write(from->entity, &packet->data.play_client.spawnplayer.metadata.metadata, &packet->data.play_client.spawnplayer.metadata.metadata_size, pool); queue_push(to->outgoing_packets, packet); game_entity_equipment(to, from->entity, 0, from->inventory->slots[from->currentItem + 36]); game_entity_equipment(to, from->entity, 5, from->inventory->slots[5]); @@ -74,7 +75,8 @@ void game_load_entity(struct player* to, struct entity* from) { queue_push(to->outgoing_packets, packet); packet = packet_new(mempool_new(), PKT_PLAY_CLIENT_ENTITYMETADATA); packet->data.play_client.entitymetadata.entity_id = from->id; - entitymeta_write(from, &packet->data.play_client.entitymetadata.metadata.metadata, &packet->data.play_client.entitymetadata.metadata.metadata_size); + struct mempool* pool = mempool_new(); + entitymeta_write(from, &packet->data.play_client.entitymetadata.metadata.metadata, &packet->data.play_client.entitymetadata.metadata.metadata_size, pool); queue_push(to->outgoing_packets, packet); } else if (from->type == ENT_PLAYER) { return; @@ -116,7 +118,8 @@ void game_load_entity(struct player* to, struct entity* from) { packet->data.play_client.spawnmob.velocity_x = (int16_t)(from->motX * 8000.); packet->data.play_client.spawnmob.velocity_y = (int16_t)(from->motY * 8000.); packet->data.play_client.spawnmob.velocity_z = (int16_t)(from->motZ * 8000.); - entitymeta_write(from, &packet->data.play_client.spawnmob.metadata.metadata, &packet->data.play_client.spawnmob.metadata.metadata_size); + struct mempool* pool = mempool_new(); + entitymeta_write(from, &packet->data.play_client.spawnmob.metadata.metadata, &packet->data.play_client.spawnmob.metadata.metadata_size, pool); queue_push(to->outgoing_packets, packet); } hashmap_putint(to->loaded_entities, (uint64_t) from->id, from); @@ -177,10 +180,11 @@ void game_drop_block(struct world* world, struct slot* slot, int32_t x, int32_t item->motY = .2; item->motZ = game_rand_float() * .2 - .1; item->data.itemstack.delayBeforeCanPickup = 0; - slot_duplicate(slot, item->data.itemstack.slot); + struct mempool* pool = mempool_new(); + slot_duplicate(pool, slot, item->data.itemstack.slot); world_spawn_entity(world, item); - BEGIN_BROADCAST_DIST(item, 128.) - game_load_entity(bc_player, item); + BEGIN_BROADCAST_DIST(item, 128.); + game_load_entity(bc_player, item); END_BROADCAST(item->world->players) } @@ -197,10 +201,11 @@ void dropPlayerItem(struct player* player, struct slot* drop) { item->motY += (game_rand_float() - game_rand_float()) * .1; item->motZ += sin(nos) * mag; item->data.itemstack.delayBeforeCanPickup = 20; - slot_duplicate(drop, item->data.itemstack.slot); + struct mempool* pool = mempool_new(); + slot_duplicate(pool, drop, item->data.itemstack.slot); world_spawn_entity(player->world, item); - BEGIN_BROADCAST_DIST(player->entity, 128.) - game_load_entity(bc_player, item); + BEGIN_BROADCAST_DIST(player->entity, 128.); + game_load_entity(bc_player, item); END_BROADCAST(player->world->players) } @@ -229,10 +234,11 @@ void dropEntityItem_explode(struct entity* entity, struct slot* drop) { item->motZ = cos(f2) * f1; item->motY = .2; item->data.itemstack.delayBeforeCanPickup = 20; - slot_duplicate(drop, item->data.itemstack.slot); + struct mempool* pool = mempool_new(); + slot_duplicate(pool, drop, item->data.itemstack.slot); world_spawn_entity(entity->world, item); - BEGIN_BROADCAST_DIST(entity, 128.) - game_load_entity(bc_player, item); + BEGIN_BROADCAST_DIST(entity, 128.); + game_load_entity(bc_player, item); END_BROADCAST(entity->world->players) } @@ -284,7 +290,7 @@ void player_openInventory(struct player* player, struct inventory* inv) { pkt->data.play_client.windowitems.count = inv->slot_count; pkt->data.play_client.windowitems.slot_data = xmalloc(sizeof(struct slot) * inv->slot_count); for (size_t i = 0; i < inv->slot_count; i++) { - slot_duplicate(inv->slots[i], &pkt->data.play_client.windowitems.slot_data[i]); + slot_duplicate(pkt->pool, inv->slots[i], &pkt->data.play_client.windowitems.slot_data[i]); } add_queue(player->outgoing_packets, pkt); } @@ -325,7 +331,7 @@ void broadcast(char* text, char* color) { char* rs = xmalloc(s); snprintf(rs, s, "{\"text\": \"%s\", \"color\": \"%s\"}", replace(replace(rsx, "\\", "\\\\"), "\"", "\\\""), color); printf(" %s\n", text); - BEGIN_BROADCAST (players) + BEGIN_BROADCAST (players); struct packet* pkt = xmalloc(sizeof(struct packet)); pkt->id = PKT_PLAY_CLIENT_CHATMESSAGE; pkt->data.play_client.chatmessage.position = 0; diff --git a/src/item.c b/src/item.c index 40deff5..3a2961a 100644 --- a/src/item.c +++ b/src/item.c @@ -166,7 +166,7 @@ int onItemInteract_painting(struct world* world, struct player* player, uint8_t else if (p == 24) ent->data.painting.title = "Skeleton"; else if (p == 25) ent->data.painting.title = "DonkeyKong"; world_spawn_entity(world, ent); - if (player->gamemode != 1) inventory_set_slot(player, player->inventory, 36 + player->currentItem, NULL, 1, 1); + if (player->gamemode != 1) inventory_set_slot(player, player->inventory, 36 + player->currentItem, NULL, 1); } return 0; @@ -185,7 +185,7 @@ int onItemInteract_minecart(struct world* world, struct player* player, uint8_t else if (slot->item == ITM_MINECARTCOMMANDBLOCK) et = ENT_MINECARTCOMMANDBLOCK; struct entity* ent = entity_new(nextEntityID++, (double) x + .5, (double) y + dy, (double) z + .5, et, 0., 0.); world_spawn_entity(world, ent); - if (player->gamemode != 1) inventory_set_slot(player, player->inventory, 36 + player->currentItem, NULL, 1, 1); + if (player->gamemode != 1) inventory_set_slot(player, player->inventory, 36 + player->currentItem, NULL, 1); return 0; } @@ -629,7 +629,7 @@ void onItemUse_bow(struct world* world, struct player* player, uint8_t slot_inde if (--ammo->count <= 0) { ammo = NULL; } - inventory_set_slot(player, player->inventory, bs, ammo, 1, 1); + inventory_set_slot(player, player->inventory, bs, ammo, 1); } world_spawn_entity(player->world, arrow); } diff --git a/src/light.c b/src/light.c index 3198a5e..ebc636f 100644 --- a/src/light.c +++ b/src/light.c @@ -1,5 +1,5 @@ #include -#include "light.h" +#include /* void light_proc(struct world* world, struct chunk* chunk, int32_t x, int32_t y, int32_t z, uint8_t light) { diff --git a/src/login_stage_handler.c b/src/login_stage_handler.c index 348b77c..b1bf125 100644 --- a/src/login_stage_handler.c +++ b/src/login_stage_handler.c @@ -1,4 +1,4 @@ -#include "login_stage_handler.h" +#include #include #include #include @@ -293,7 +293,12 @@ int handle_encryption_response(struct connection* conn, struct packet* packet) { SSL_set_fd(ssl, session_tls_fd); if (SSL_connect(ssl) != 1) goto ssl_error; char write_buf[4096]; - int write_length = snprintf(write_buf, 1024, "GET /session/minecraft/hasJoined?username=%s&serverId=%s HTTP/1.1\r\nHost: sessionserver.mojang.com\r\nUser-Agent: Basin " VERSION "\r\nConnection: close\r\n\r\n", conn->online_username, hex_hash_signed); + int write_length = snprintf(write_buf, 1024, "\ + GET /session/minecraft/hasJoined?username=%s&serverId=%s \ + HTTP/1.1\r\nHost: sessionserver.mojang.com\r\n\ + User-Agent: Basin " VERSION "\r\n\ + Connection: close\r\n\r\n\ + ", conn->online_username, hex_hash_signed); int written = 0; while (written < write_length) { int r = SSL_write(ssl, write_buf, write_length); diff --git a/src/main.c b/src/main.c index 5f6fd50..35ffe9b 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,5 @@ #include "accept.h" -#include "work.h" +#include #include #include #include diff --git a/src/player.c b/src/player.c index 899612c..245d311 100644 --- a/src/player.c +++ b/src/player.c @@ -537,7 +537,7 @@ void player_closeWindow(struct player* player, uint16_t windowID) { inventory = NULL; } else if (inventory->type == INVTYPE_CHEST) { if (inventory->tile != NULL) { - BEGIN_BROADCAST_DIST(player->entity, 128.){ + BEGIN_BROADCAST_DIST(player->entity, 128.) { struct packet* pkt = packet_new(mempool_new(), PKT_PLAY_CLIENT_BLOCKACTION); pkt->data.play_client.blockaction.location.x = inventory->tile->x; pkt->data.play_client.blockaction.location.y = inventory->tile->y; diff --git a/src/wake_thread.c b/src/wake_thread.c index 3bf7391..01d0dc7 100644 --- a/src/wake_thread.c +++ b/src/wake_thread.c @@ -1,4 +1,4 @@ -#include "wake_thread.h" +#include #include #include #include diff --git a/src/work.c b/src/work.c index b9f3032..0cdaf4e 100644 --- a/src/work.c +++ b/src/work.c @@ -1,7 +1,7 @@ -#include "work.h" -#include "accept.h" -#include "basin/packet.h" -#include "login_stage_handler.h" +#include +#include +#include +#include #include #include #include