From 07a4eecd4e57583125707fb92da467f70bf26721 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Fri, 19 Apr 2024 20:03:20 +0200 Subject: [PATCH] removed the stupid exit command sending using codes instead --- src/chat/flags.c | 33 --------------------------------- src/chat/main/client.c | 5 +---- src/chat/misc.c | 14 ++++---------- 3 files changed, 5 insertions(+), 47 deletions(-) delete mode 100644 src/chat/flags.c diff --git a/src/chat/flags.c b/src/chat/flags.c deleted file mode 100644 index 6285fdf..0000000 --- a/src/chat/flags.c +++ /dev/null @@ -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 . -*/ - -#include - -#include - -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; -} \ No newline at end of file diff --git a/src/chat/main/client.c b/src/chat/main/client.c index accc5e3..1211180 100644 --- a/src/chat/main/client.c +++ b/src/chat/main/client.c @@ -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) diff --git a/src/chat/misc.c b/src/chat/misc.c index a5daad2..f8db908 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -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; }