removed the stupid exit command sending

using codes instead
This commit is contained in:
Václav Šmejkal 2024-04-19 20:03:20 +02:00
parent d451030ad0
commit 07a4eecd4e
Signed by: ENGO150
GPG Key ID: 4A57E86482968843
3 changed files with 5 additions and 47 deletions

View File

@ -1,33 +0,0 @@
/*
This is part of WHY2
Copyright (C) 2022 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <why2/chat/flags.h>
#include <stdlib.h>
char *server_exit_cmd = NULL;
char *why2_chat_client_get_server_exit_cmd()
{
return server_exit_cmd;
}
void why2_chat_client_set_server_exit_cmd(char *cmd)
{
server_exit_cmd = cmd;
}

View File

@ -43,10 +43,7 @@ void exit_client(WHY2_UNUSED int i) //guess what
if (exited) return;
exited = 1;
char *exit_cmd = why2_chat_client_get_server_exit_cmd();
why2_send_socket(exit_cmd, NULL, listen_socket);
why2_deallocate(exit_cmd);
why2_send_socket(WHY2_CHAT_CODE_EXIT, NULL, listen_socket);
}
int main(void)

View File

@ -382,8 +382,6 @@ void send_socket(char *text, char *username, int socket, why2_bool welcome)
json_object_object_add(json, "min_uname", json_object_new_string(min_uname));
json_object_object_add(json, "max_tries", json_object_new_string(max_tries));
json_object_object_add(json, "exit_cmd", json_object_new_string(WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_EXIT));
//DEALLOCATION
why2_toml_read_free(max_uname);
why2_toml_read_free(min_uname);
@ -655,18 +653,15 @@ void *why2_communicate_thread(void *arg)
if (decoded_buffer != NULL && strlen(decoded_buffer) != 0 && strlen(decoded_buffer) <= (unsigned long) server_config_int("max_message_length"))
{
if (decoded_buffer[0] == '!') //COMMANDS
if (strncmp(decoded_buffer, "code", 4) == 0) //CODES FROM CLIENT
{
if (strcmp(decoded_buffer, WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_EXIT) == 0) //USER REQUESTED EXIT
if (strcmp(decoded_buffer, WHY2_CHAT_CODE_EXIT) == 0) //USER REQUESTED EXIT
{
exiting = 1;
} else
{
send_socket_deallocate(WHY2_CHAT_CODE_INVALID_COMMAND, why2_chat_server_config("server_username"), connection); //INFORM USER THAT HE'S DUMB
}
//IGNORE MESSAGES BEGINNING WITH '!'
} else
//IGNORE INVALID CODES, THE USER JUST GOT HIS LOBOTOMY DONE
} else if (decoded_buffer[0] != '!') //IGNORE MESSAGES BEGINNING WITH '!'
{
//REBUILD MESSAGE WITH USERNAME
json_object_object_add(json, "message", json_object_new_string(decoded_buffer));
@ -804,7 +799,6 @@ void *why2_listen_server(void *socket)
max_uname = get_int_from_json_string(read, "max_uname");
min_uname = get_int_from_json_string(read, "min_uname");
max_tries = get_int_from_json_string(read, "max_tries");
why2_chat_client_set_server_exit_cmd(get_string_from_json_string(read, "exit_cmd"));
continuing = 1;
}