Improved Privacy and handled better the clients.
This commit is contained in:
parent
b39c012a37
commit
d7b8f14bbc
26
src/server.c
26
src/server.c
@ -66,11 +66,22 @@ int main(void)
|
|||||||
u_int8_t isConnected = 0;
|
u_int8_t isConnected = 0;
|
||||||
int connfd;
|
int connfd;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WE NEED TO IMPLEMENT A WAY TO HANDLE MULTIPLE CLIENTS
|
||||||
|
* AND MAKE IT SABLE (RIGHT NOW IT CRASHES EVERY TIME A CLIENT DISCONNECTS)
|
||||||
|
*
|
||||||
|
* ALSO MAKE A BETTER WAY OF STOPPING THE SERVER
|
||||||
|
*
|
||||||
|
* TODO:
|
||||||
|
* -1 Fix the chashing issues
|
||||||
|
* -2 Implement a way to stop the server
|
||||||
|
* -3 Implement a way to handle multiple clients
|
||||||
|
*/
|
||||||
|
|
||||||
// Listen to the client requests
|
// Listen to the client requests
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
// Receive the request
|
// Receive the request
|
||||||
|
|
||||||
if (!isConnected)
|
if (!isConnected)
|
||||||
{
|
{
|
||||||
connfd = accept(sockfd, (struct sockaddr *)&cli, &len);
|
connfd = accept(sockfd, (struct sockaddr *)&cli, &len);
|
||||||
@ -79,9 +90,9 @@ int main(void)
|
|||||||
fprintf(stderr, "Server accept failed\n");
|
fprintf(stderr, "Server accept failed\n");
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
isConnected = 1;
|
isConnected = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
printf("Client connected\n");
|
printf("Client connected\n");
|
||||||
|
|
||||||
@ -161,7 +172,7 @@ int main(void)
|
|||||||
|
|
||||||
char filepath[256];
|
char filepath[256];
|
||||||
|
|
||||||
printf("Received key: %s\n", req.key);
|
printf("Received key: [%x]\n", req.key[0]);
|
||||||
printf("Received level: %d\n", req.level);
|
printf("Received level: %d\n", req.level);
|
||||||
sprintf(filepath, "%s%d.bin", PASSWORDS, req.level);
|
sprintf(filepath, "%s%d.bin", PASSWORDS, req.level);
|
||||||
|
|
||||||
@ -179,7 +190,7 @@ int main(void)
|
|||||||
|
|
||||||
char filepath[256];
|
char filepath[256];
|
||||||
|
|
||||||
printf("Received key: %s\n", req.key);
|
printf("Received key: [%x]\n", req.key[0]);
|
||||||
printf("Received level: %d\n", req.level);
|
printf("Received level: %d\n", req.level);
|
||||||
sprintf(filepath, "%s%d.bin", PASSWORDS, req.level);
|
sprintf(filepath, "%s%d.bin", PASSWORDS, req.level);
|
||||||
|
|
||||||
@ -226,9 +237,8 @@ int main(void)
|
|||||||
memcpy(aux.key, levels, 256);
|
memcpy(aux.key, levels, 256);
|
||||||
|
|
||||||
// debug
|
// debug
|
||||||
|
|
||||||
printf("Sending response\n");
|
printf("Sending response\n");
|
||||||
printf("Level: %d\tKey: %s\n", aux.level, aux.key);
|
printf("Level: %d\tKey: [%x]\n", aux.level, aux.key[0]);
|
||||||
|
|
||||||
send(connfd, &aux, sizeof(aux), 0);
|
send(connfd, &aux, sizeof(aux), 0);
|
||||||
break;
|
break;
|
||||||
@ -237,6 +247,8 @@ int main(void)
|
|||||||
fprintf(stderr, "Invalid request type\n");
|
fprintf(stderr, "Invalid request type\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop the server as the server
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the socket
|
// Close the socket
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user