Skip to content

Commit

Permalink
✨ fixing bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeFTN committed Dec 30, 2022
1 parent 73294ba commit 4d89792
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 33 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
branches: [ "v2" ]
pull_request:
branches: [ "v2" ]
schedule:
- cron: '00 12 * * 0-6'

jobs:
analyze:
Expand Down
9 changes: 9 additions & 0 deletions server/handler/handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,23 @@ int run_command(char *option, bool *mysecurity, bool *connected)
if (option[0] == '0')
{
printf("shutting down computer");
#ifdef _WIN32
system("shutdown -s");
#else
system("sudo shutdown -P");
#endif
return 0;

} else if (option[0] == '1')
{
*connected = false;
*mysecurity = false;
return 0;
} else if (option[0] == '2')
{
*connected = false;
*mysecurity = true;
return 0;
}

return -1;
Expand Down
60 changes: 29 additions & 31 deletions server/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,45 +30,43 @@ int main()
return -1;
connected = true;

// While user does not choose 'Exit'
while (connected)
{
// Receive client's handshake
error = receive_socket(client, handshake);
if (error < 0)
close_socket(client, sock);

// Receive client's handshake
error = receive_socket(client, handshake);
if (error < 0)
close_socket(client, sock);
handshaked = strstr(handshake, "Handshake");

handshaked = strstr(handshake, "Handshake");
if (!handshaked)
{
printf("[x] Could not handshake - `%s`\n", handshake);
close_socket(client, sock);
return -1;
}
printf("[+] Handshaked!\n");

if (handshaked)
{
printf("[+] Handshaked!\n");
// While user does not choose 'Exit'
while (connected)
{
// Send options to message
error = send_socket(client, get_commands());
if (error < 0)
close_socket(client, sock);

// Send options to message
error = send_socket(client, get_commands());
if (error < 0)
close_socket(client, sock);
// Get message sended from client
error = receive_socket(client, option);
if (error < 0)
close_socket(client, sock);

// Get message sended from client
error = receive_socket(client, option);
// Handle user option
error = run_command(option, &mysecurity, &connected);
if (error < 0)
{
error = send_socket(client, "[!] Invalid option");
if (error < 0)
close_socket(client, sock);

// Handle user option
error = run_command(option, &mysecurity, &connected);
if (error < 0)
{
error = send_socket(client, "[!] Invalid option");
if (error < 0)
close_socket(client, sock);
}
} else {
printf("[x] Could not handshake - `%s`\n", handshake);
close_socket(client, sock);
return -1;
}
}
}
}
return 0;
}
1 change: 1 addition & 0 deletions server/socket/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ int close_socket(int client, int sock)
WSACleanup();
#else
close(client);
shutdown(client, SHUT_RDWR);
#endif

return 0;
Expand Down

0 comments on commit 4d89792

Please sign in to comment.