server03 passed

This commit is contained in:
2025-07-30 18:58:21 +01:00
parent e87c1f74f4
commit 7e7124ee11

View File

@@ -45,7 +45,7 @@ void *handle_connection(void *args) {
status_t status = CONNECTED; status_t status = CONNECTED;
char *message = malloc(sizeof(char)*1024); char *message = malloc(sizeof(char)*1024);
char_array_t *data = char_array_create(1024); char_array_t *data = char_array_create(1024);
send(handleArgs->client, WELCOME, sizeof(WELCOME), 0); send(handleArgs->client, WELCOME, sizeof(WELCOME)-1, 0);
char *username = malloc(sizeof(char)*1024); char *username = malloc(sizeof(char)*1024);
while ((bytesReceived = recv(handleArgs->client, buffer, sizeof(buffer), 0)) > 0) { while ((bytesReceived = recv(handleArgs->client, buffer, sizeof(buffer), 0)) > 0) {
printf("{%d} Client sent: |%d| \n", handleArgs->connection, bytesReceived); printf("{%d} Client sent: |%d| \n", handleArgs->connection, bytesReceived);
@@ -102,8 +102,10 @@ void *handle_connection(void *args) {
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
} }
sprintf(message, "* %s has left the room\n", username); if (status == IDENTIFIED) {
broadcast(handleArgs->connections, &handleArgs->client, message); sprintf(message, "* %s has left the room\n", username);
broadcast(handleArgs->connections, &handleArgs->client, message);
}
connections_remove(handleArgs->connections, handleArgs->client); connections_remove(handleArgs->connections, handleArgs->client);
printf("{%d} Client disconnected\n", handleArgs->connection); printf("{%d} Client disconnected\n", handleArgs->connection);