diff --git a/src/chat/misc.c b/src/chat/misc.c index 778aafc..284487b 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -736,15 +736,20 @@ void *why2_communicate_thread(void *arg) if (valid_param) //IGNORE INVALID ARGS { + connection_node_t pm_connection_node = *(connection_node_t*) pm_connection -> value; + //ALLOCATE MESSAGE TO SEND TO RECEIVER - char *private_msg = why2_malloc(strlen(WHY2_CHAT_CODE_PM_SERVER) + strlen(node.username) + strlen((*(connection_node_t*) pm_connection -> value).username) + strlen(msg) + 5); + char *private_msg = why2_malloc(strlen(WHY2_CHAT_CODE_PM_SERVER) + strlen(node.username) + strlen(pm_connection_node.username) + strlen(msg) + 5); //CONSTRUCT DA MESSAGE - sprintf(private_msg, WHY2_CHAT_CODE_PM_SERVER ";%s;%s;%s;%c", node.username, (*(connection_node_t*) pm_connection -> value).username, msg, '\0'); + sprintf(private_msg, WHY2_CHAT_CODE_PM_SERVER ";%s;%s;%s;%c", node.username, pm_connection_node.username, msg, '\0'); + + //USER IS SENDING THE MESSAGE TO HIMSELF + why2_bool self_pm = pm_connection_node.connection == connection; //SEND YOU DUMB FUCK - send_socket_deallocate(private_msg, why2_chat_server_config("server_username"), (*(connection_node_t*) pm_connection -> value).connection); //RECIPIENT - send_socket_deallocate(private_msg, why2_chat_server_config("server_username"), connection); //AUTHOR + send_socket_deallocate(private_msg, why2_chat_server_config("server_username"), pm_connection_node.connection); //RECIPIENT + if (!self_pm) send_socket_deallocate(private_msg, why2_chat_server_config("server_username"), connection); //AUTHOR why2_deallocate(private_msg); }