Skip to content

Commit e81e75a

Browse files
committed
ensure mob uuid uniqueness on login
Closes #51
1 parent 61eb38a commit e81e75a

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/main.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,19 @@ void handlePacket (int client_fd, int length, int packet_id, int state) {
135135
sc_spawnEntityPlayer(client_fd, player_data[i]);
136136
}
137137

138-
// Send information about all other entities (mobs)
139-
// For more info on the arguments, see the spawnMob function
138+
// Send information about all other entities (mobs):
139+
// Use a random number for the first half of the UUID
140+
uint8_t uuid[16];
141+
uint32_t r = fast_rand();
142+
memcpy(uuid, &r, 4);
143+
// Send allocated living mobs, use ID for second half of UUID
140144
for (int i = 0; i < MAX_MOBS; i ++) {
141145
if (mob_data[i].type == 0) continue;
142146
if ((mob_data[i].data & 31) == 0) continue;
147+
memcpy(uuid + 4, &i, 4);
148+
// For more info on the arguments here, see the spawnMob function
143149
sc_spawnEntity(
144-
client_fd, -2 - i, recv_buffer,
150+
client_fd, -2 - i, uuid,
145151
mob_data[i].type, mob_data[i].x, mob_data[i].y, mob_data[i].z,
146152
0, 0
147153
);

0 commit comments

Comments
 (0)