Fix a bug where first connection would be used and fix some weird code i wrote, add edge case handling

This commit is contained in:
Alex 2020-07-30 23:02:55 +02:00
parent 60fd437b55
commit 70439434b4
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
3 changed files with 3 additions and 3 deletions

View File

@ -26,7 +26,7 @@ int write_log(char* line, char* root, IRC_Message* mesg, Connection* conn)
return 0;
cleanup_path_names(bufs[0]);
*(ppos++) = bufs[0];
if ((mesg->cmd == NOTICE || mesg->cmd == PRIVMSG) && mesg->name.nick != NULL) {
if ((mesg->cmd == NOTICE || mesg->cmd == PRIVMSG) && mesg->name.nick != NULL && *mesg->name.nick != '\0') {
if (strchr("#!&+", *mesg->args[0]) != NULL)
*(ppos++) = "channel";
else

View File

@ -86,7 +86,7 @@ int main(int argc, char* argv[])
if (Tok_mesg(cons[t].buf.buffer, &buffer) == 1) {
LOG(LOG_DEBUG, "Tokenized message successfully.", NULL, &cons[t]);
handle_irc_message(&buffer, &cons[t]);
write_log(origmsg, root, &buffer, cons);
write_log(origmsg, root, &buffer, &cons[t]);
} else
LOG(LOG_WARN, "Received invalid IRC message (see RFC2812)", origmsg, &cons[t]);
break;

View File

@ -46,7 +46,7 @@ signed int init_conn(Connection* info)
}
for (unsigned int i = 0; i < 3; i++) {
connectres = connect(sockfd, conn->ai_addr, conn->ai_addrlen);
if (connectres == 0 || connectres == EINTR) { /* TODO: Lookup if EINTR expects async conn OR connects async, assuming connects */
if (connectres == 0 || (connectres == -1 && errno == EINTR)) {
break;
} else {
LOG_ERRNO(LOG_ERROR, "Failed to connect to host.", NULL, info);