Skip to content

Commit 969f7d3

Browse files
b1braddersp2r3
andauthored
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 <p2r3@p2r3.com>
1 parent 2a9e443 commit 969f7d3

5 files changed

Lines changed: 37 additions & 0 deletions

File tree

include/globals.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@
102102
// clients from Keep Alive packets.
103103
#define NETWORK_TIMEOUT_TIME 15000000
104104

105+
// If defined, sends the server brand to clients. Doesn't do much, but will
106+
// show up in the top-left of the F3/debug menu, in the Minecraft client.
107+
// You can change the brand string in the "brand" variable in src/globals.c
108+
#define SEND_BRAND
109+
105110
// If defined, rebroadcasts ALL incoming movement updates, disconnecting
106111
// movement from the server's tickrate. This makes movement much smoother
107112
// on very low tickrates, at the cost of potential network instability when
@@ -170,6 +175,11 @@ extern uint32_t server_ticks;
170175
extern char motd[];
171176
extern uint8_t motd_len;
172177

178+
#ifdef SEND_BRAND
179+
extern char brand[];
180+
extern uint8_t brand_len;
181+
#endif
182+
173183
extern uint16_t client_count;
174184

175185
typedef struct {

include/packets.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ int cs_playerCommand (int client_fd);
2626
int sc_statusResponse (int client_fd);
2727
int sc_loginSuccess (int client_fd, uint8_t *uuid, char *name);
2828
int sc_knownPacks (int client_fd);
29+
int sc_sendPluginMessage (int client_fd, const char *channel, const uint8_t *data, size_t data_len);
2930
int sc_finishConfiguration (int client_fd);
3031
int sc_loginPlay (int client_fd);
3132
int sc_synchronizePlayerPosition (int client_fd, double x, double y, double z, float yaw, float pitch);

src/globals.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ uint32_t server_ticks = 0;
3535
char motd[] = { "A bareiron server" };
3636
uint8_t motd_len = sizeof(motd) - 1;
3737

38+
#ifdef SEND_BRAND
39+
char brand[] = { "bareiron" };
40+
uint8_t brand_len = sizeof(brand) - 1;
41+
#endif
42+
3843
uint16_t client_count;
3944

4045
BlockChange block_changes[MAX_BLOCK_CHANGES];

src/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ void handlePacket (int client_fd, int length, int packet_id, int state) {
8585
if (cs_clientInformation(client_fd)) break;
8686
if (sc_knownPacks(client_fd)) break;
8787
if (sc_registries(client_fd)) break;
88+
89+
#ifdef SEND_BRAND
90+
if (sc_sendPluginMessage(client_fd, "minecraft:brand", brand, brand_len)) break;
91+
#endif
8892
}
8993
break;
9094

src/packets.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,23 @@ int cs_pluginMessage (int client_fd) {
157157
return 0;
158158
}
159159

160+
// S->C Clientbound Plugin Message
161+
int sc_sendPluginMessage (int client_fd, const char *channel, const uint8_t *data, size_t data_len) {
162+
printf("Sending Plugin Message\n\n");
163+
int channel_len = (int)strlen(channel);
164+
165+
writeVarInt(client_fd, 1 + sizeVarInt(channel_len) + channel_len + sizeVarInt(data_len) + data_len);
166+
writeByte(client_fd, 0x01);
167+
168+
writeVarInt(client_fd, channel_len);
169+
send_all(client_fd, channel, channel_len);
170+
171+
writeVarInt(client_fd, data_len);
172+
send_all(client_fd, data, data_len);
173+
174+
return 0;
175+
}
176+
160177
// S->C Finish Configuration
161178
int sc_finishConfiguration (int client_fd) {
162179
writeVarInt(client_fd, 1);

0 commit comments

Comments
 (0)