forked from EXTERNAL/bareiron
add player join messages
This commit is contained in:
@@ -41,6 +41,7 @@ int sc_updateEntityRotation (int client_fd, int id, uint8_t yaw, uint8_t pitch);
|
||||
int sc_damageEvent (int client_fd, int id, int type);
|
||||
int sc_setHealth (int client_fd, uint8_t health, uint8_t food);
|
||||
int sc_respawn (int client_fd);
|
||||
int sc_systemChat (int client_fd, char* message, uint16_t len);
|
||||
int sc_registries (int client_fd);
|
||||
|
||||
#endif
|
||||
|
@@ -81,11 +81,18 @@ void handlePacket (int client_fd, int length, int packet_id) {
|
||||
// Send full client spawn sequence
|
||||
spawnPlayer(player);
|
||||
|
||||
// Prepare join message for broadcast
|
||||
uint8_t player_name_len = strlen(player->name);
|
||||
char join_message[16 + player_name_len];
|
||||
strcpy(join_message, player->name);
|
||||
strcpy(join_message + player_name_len, " joined the game");
|
||||
|
||||
// Register all existing players and spawn their entities, and broadcast
|
||||
// information about the joining player to all existing players.
|
||||
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
||||
if (player_data[i].client_fd == -1) continue;
|
||||
sc_playerInfoUpdateAddPlayer(client_fd, player_data[i]);
|
||||
sc_systemChat(player_data[i].client_fd, join_message, 16 + player_name_len);
|
||||
if (player_data[i].client_fd == client_fd) continue;
|
||||
sc_playerInfoUpdateAddPlayer(player_data[i].client_fd, *player);
|
||||
sc_spawnEntityPlayer(client_fd, player_data[i]);
|
||||
|
@@ -901,6 +901,21 @@ int cs_clientStatus (int client_fd) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sc_systemChat (int client_fd, char* message, uint16_t len) {
|
||||
|
||||
writeVarInt(client_fd, 5 + len);
|
||||
writeByte(client_fd, 0x72);
|
||||
|
||||
// String NBT tag
|
||||
writeByte(client_fd, 8);
|
||||
writeUint16(client_fd, len);
|
||||
send_all(client_fd, message, len);
|
||||
|
||||
// Is action bar message?
|
||||
writeByte(client_fd, false);
|
||||
|
||||
}
|
||||
|
||||
// S->C Registry Data (multiple packets) and Update Tags (configuration, multiple packets)
|
||||
int sc_registries (int client_fd) {
|
||||
|
||||
|
Reference in New Issue
Block a user