From 969f7d397496c2d7f68d96e6f5e106d559e89a74 Mon Sep 17 00:00:00 2001 From: Bradlee Barnes <69256931+StupidRepo@users.noreply.github.com> Date: Sat, 13 Sep 2025 11:22:06 +0000 Subject: [PATCH] send server brand during login * send server brand to client * send brand regardless of `0x02` being recieved by server or not * send brand regardless of `0x02` being recieved by server or not + if statement to match previous lines * ifdef check for brand sending * commit main.c for ifdef check (i forgot) * commit main.c for ifdef check (i forgot) * change sc_pluginMessage to sc_sendPluginMessage - added params to it for use in other cases - other changes to fit PR reviews * revert .gitignore * revert unrelated changes * send byte instead of varint for constant packet id * gate declaration of brand string behind ifdef * make logging consistent with codebase --------- Co-authored-by: p2r3 --- include/globals.h | 10 ++++++++++ include/packets.h | 1 + src/globals.c | 5 +++++ src/main.c | 4 ++++ src/packets.c | 17 +++++++++++++++++ 5 files changed, 37 insertions(+) diff --git a/include/globals.h b/include/globals.h index eafcf20..0024603 100644 --- a/include/globals.h +++ b/include/globals.h @@ -102,6 +102,11 @@ // clients from Keep Alive packets. #define NETWORK_TIMEOUT_TIME 15000000 +// If defined, sends the server brand to clients. Doesn't do much, but will +// show up in the top-left of the F3/debug menu, in the Minecraft client. +// You can change the brand string in the "brand" variable in src/globals.c +#define SEND_BRAND + // If defined, rebroadcasts ALL incoming movement updates, disconnecting // movement from the server's tickrate. This makes movement much smoother // on very low tickrates, at the cost of potential network instability when @@ -170,6 +175,11 @@ extern uint32_t server_ticks; extern char motd[]; extern uint8_t motd_len; +#ifdef SEND_BRAND + extern char brand[]; + extern uint8_t brand_len; +#endif + extern uint16_t client_count; typedef struct { diff --git a/include/packets.h b/include/packets.h index 4065ddf..63d0366 100644 --- a/include/packets.h +++ b/include/packets.h @@ -26,6 +26,7 @@ int cs_playerCommand (int client_fd); int sc_statusResponse (int client_fd); int sc_loginSuccess (int client_fd, uint8_t *uuid, char *name); int sc_knownPacks (int client_fd); +int sc_sendPluginMessage (int client_fd, const char *channel, const uint8_t *data, size_t data_len); int sc_finishConfiguration (int client_fd); int sc_loginPlay (int client_fd); int sc_synchronizePlayerPosition (int client_fd, double x, double y, double z, float yaw, float pitch); diff --git a/src/globals.c b/src/globals.c index 762955e..ef0638f 100644 --- a/src/globals.c +++ b/src/globals.c @@ -35,6 +35,11 @@ uint32_t server_ticks = 0; char motd[] = { "A bareiron server" }; uint8_t motd_len = sizeof(motd) - 1; +#ifdef SEND_BRAND + char brand[] = { "bareiron" }; + uint8_t brand_len = sizeof(brand) - 1; +#endif + uint16_t client_count; BlockChange block_changes[MAX_BLOCK_CHANGES]; diff --git a/src/main.c b/src/main.c index 04d5171..72db6b1 100644 --- a/src/main.c +++ b/src/main.c @@ -85,6 +85,10 @@ void handlePacket (int client_fd, int length, int packet_id, int state) { if (cs_clientInformation(client_fd)) break; if (sc_knownPacks(client_fd)) break; if (sc_registries(client_fd)) break; + + #ifdef SEND_BRAND + if (sc_sendPluginMessage(client_fd, "minecraft:brand", brand, brand_len)) break; + #endif } break; diff --git a/src/packets.c b/src/packets.c index b3cbb3d..eb0d448 100644 --- a/src/packets.c +++ b/src/packets.c @@ -157,6 +157,23 @@ int cs_pluginMessage (int client_fd) { return 0; } +// S->C Clientbound Plugin Message +int sc_sendPluginMessage (int client_fd, const char *channel, const uint8_t *data, size_t data_len) { + printf("Sending Plugin Message\n\n"); + int channel_len = (int)strlen(channel); + + writeVarInt(client_fd, 1 + sizeVarInt(channel_len) + channel_len + sizeVarInt(data_len) + data_len); + writeByte(client_fd, 0x01); + + writeVarInt(client_fd, channel_len); + send_all(client_fd, channel, channel_len); + + writeVarInt(client_fd, data_len); + send_all(client_fd, data, data_len); + + return 0; +} + // S->C Finish Configuration int sc_finishConfiguration (int client_fd) { writeVarInt(client_fd, 1);