aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile5
-rw-r--r--kirc.13
-rw-r--r--kirc.c69
-rw-r--r--kirc.h1
4 files changed, 56 insertions, 22 deletions
diff --git a/Makefile b/Makefile
index 2c1d5f9..f40a58b 100644
--- a/Makefile
+++ b/Makefile
@@ -4,8 +4,9 @@ PREFIX ?= /usr/local
BINDIR = $(PREFIX)/bin
MANDIR = $(PREFIX)/share/man
-all: kirc.c kirc.h
- $(CC) $(CFLAGS) $(LDFLAGS) kirc.c -o kirc
+kirc: kirc.c kirc.h
+ $(CC) $(CFLAGS) $(LDFLAGS) ${ALL_WARNING} kirc.c -o kirc
+all: kirc
install: kirc
mkdir -p $(DESTDIR)$(BINDIR)
diff --git a/kirc.1 b/kirc.1
index 42d6f19..ece0b69 100644
--- a/kirc.1
+++ b/kirc.1
@@ -63,6 +63,9 @@ received.
.BI /<command>
Send message to IRC host (e.g. /JOIN, /PART, /WHOIS, etc.)
.TP
+.BI /setprivmsg <nick>
+Set privmsg target. Useful when sending privmsg's to a nick instead of a chan.
+.TP
.BI // " <text>"
Send text to current channel (useful when sending '@' and '/', usually to bots)
.TP
diff --git a/kirc.c b/kirc.c
index 5460cf6..c8358f9 100644
--- a/kirc.c
+++ b/kirc.c
@@ -582,7 +582,7 @@ static inline void state_reset(state l)
history_add("");
}
-static char *ctime_now(char buf[26])
+static char *ctime_now(char *buf)
{
struct tm tm_;
time_t now = time(NULL);
@@ -737,17 +737,13 @@ static short parse_dcc_send_message(const char *message, char *filename, unsigne
{
/* TODO: Fix horrible hacks */
- char ipv6 = 0;
-
if (sscanf(message, "SEND \"%" STR(FNM_MAX) "[^\"]\" %41s %hu %zu", filename, ipv6_addr, port, file_size) == 4) {
- ipv6 = !!(ipv6_addr[15]);
- if (ipv6 == 1) {
+ if (ipv6_addr[15]) {
return 1;
}
}
if (sscanf(message, "SEND %" STR(FNM_MAX) "s %41s %hu %zu", filename, ipv6_addr, port, file_size) == 4) {
- ipv6 = !!(ipv6_addr[15]);
- if (ipv6 == 1) {
+ if (ipv6_addr[15]) {
return 1;
}
}
@@ -773,7 +769,7 @@ static short parse_dcc_accept_message(const char *message, char *filename, unsig
return 1;
}
-static void open_socket(int slot, int *file_fd)
+static void open_socket(int slot, int file_fd)
{
int sock_fd;
if(!ipv6) {
@@ -781,7 +777,7 @@ static void open_socket(int slot, int *file_fd)
struct sockaddr_in sockaddr = dcc_sessions.slots[slot].sin;
if (connect(sock_fd, (const struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0) {
close(sock_fd);
- close(*file_fd);
+ close(file_fd);
perror("connect");
return;
}
@@ -791,20 +787,20 @@ static void open_socket(int slot, int *file_fd)
struct sockaddr_in6 sockaddr = dcc_sessions.slots[slot].sin6;
if (connect(sock_fd, (const struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0) {
close(sock_fd);
- close(*file_fd);
+ close(file_fd);
perror("connect");
return;
}
}
if (sock_fd < 0) {
- close(*file_fd);
+ close(file_fd);
perror("socket");
return;
}
int flags = fcntl(sock_fd, F_GETFL, 0) | O_NONBLOCK;
if (flags < 0 || fcntl(sock_fd, F_SETFL, flags) < 0) {
close(sock_fd);
- close(*file_fd);
+ close(file_fd);
perror("fcntl");
return;
}
@@ -819,7 +815,9 @@ static void handle_dcc(param p)
size_t file_size = 0;
unsigned int ip_addr = 0;
unsigned short port = 0;
- char ipv6_addr[42];
+ char ipv6_addr[INET6_ADDRSTRLEN];
+
+ memset(ipv6_addr, 0, sizeof(ipv6_addr));
int slot = -1;
int file_fd;
@@ -876,6 +874,7 @@ static void handle_dcc(param p)
.file_size = file_size,
.file_fd = file_fd,
};
+
strcpy(dcc_sessions.slots[slot].filename, filename);
if(!ipv6) {
dcc_sessions.slots[slot].sin = (struct sockaddr_in){
@@ -885,6 +884,7 @@ static void handle_dcc(param p)
};
goto check_resume;
}
+
struct in6_addr result;
if (inet_pton(AF_INET6, ipv6_addr, &result) != 1){
close(file_fd);
@@ -901,9 +901,10 @@ check_resume:
p->nickname, filename, port, bytes_read);
return;
}
- open_socket(slot, &file_fd);
+ open_socket(slot, file_fd);
return;
}
+
if (!strncmp(message, "ACCEPT", 6)) {
if(parse_dcc_accept_message(message, filename, &port, &file_size)) {
return;
@@ -916,7 +917,7 @@ check_resume:
}
file_fd = dcc_sessions.slots[slot].file_fd;
- open_socket(slot, &file_fd);
+ open_socket(slot, file_fd);
return;
}
}
@@ -931,7 +932,7 @@ static void handle_ctcp(param p)
raw("NOTICE %s :\001VERSION kirc " VERSION "\001\r\n", p->nickname);
return;
}
- if (!strncmp(message, "TIME", 7)) {
+ if (!strncmp(message, "TIME", 4)) {
char buf[26];
if (!ctime_now(buf)) {
raw("NOTICE %s :\001TIME %s\001\r\n", p->nickname, buf);
@@ -983,6 +984,7 @@ static void param_print_private(param p)
if (p->channel != NULL && (strcmp(p->channel, nick) == 0)) {
handle_ctcp(p);
printf("%*s\x1b[33;1m%-.*s [PRIVMSG]\x1b[36m ", s, "", p->nicklen, p->nickname);
+ p->offset += sizeof(" [PRIVMSG]");
} else if (p->channel != NULL && strcmp(p->channel + 1, chan)) {
printf("%*s\x1b[33;1m%-.*s\x1b[0m", s, "", p->nicklen, p->nickname);
printf(" [\x1b[33m%s\x1b[0m] ", p->channel);
@@ -1132,6 +1134,7 @@ static void join_command(state l)
raw("join #%s\r\n", chan);
printf("\x1b[35m%s\x1b[0m\r\n", l->buf);
printf("\x1b[35mJoined #%s!\x1b[0m\r\n", chan);
+ l->nick_privmsg = 0;
}
static void part_command(state l)
@@ -1178,16 +1181,29 @@ static void msg_command(state l)
static void action_command(state l)
{
- char *tok;
- strtok_r(l->buf + 7, " ", &tok);
int offset = 0;
while (*(l->buf + 7 + offset) == ' ') {
offset ++;
}
+
raw("privmsg #%s :\001ACTION %s\001\r\n", chan, l->buf + 7 + offset);
printf("\x1b[35mprivmsg #%s :ACTION %s\x1b[0m\r\n", chan, l->buf + 7 + offset);
}
+static void set_privmsg_command(state l)
+{
+ int offset = 0;
+ while (*(l->buf + 11 + offset) == ' ') {
+ offset ++;
+ }
+
+ strcpy(chan, l->buf + 11 + offset);
+
+ printf("\x1b[35mNew privmsg target: %s\x1b[0m\r\n", l->buf + 11 + offset);
+ l->nick_privmsg = 1;
+}
+
+
static void nick_command(state l)
{
char *tok;
@@ -1238,8 +1254,14 @@ static void handle_user_input(state l)
action_command(l);
return;
}
+ if (!strncmp(l->buf + 1, "SETPRIVMSG", 10) || !strncmp(l->buf + 1, "setprivmsg", 10)) {
+ set_privmsg_command(l);
+ return;
+ }
+
if (l->buf[1] == '#') {
strcpy(chan, l->buf + 2);
+ l->nick_privmsg = 0;
printf("\x1b[35mnew channel: #%s\x1b[0m\r\n", chan);
return;
}
@@ -1257,8 +1279,14 @@ static void handle_user_input(state l)
printf("\x1b[35mprivmsg %s :ACTION %s\x1b[0m\r\n", l->buf + 2, tok);
return;
default: /* send private message to default channel */
- raw("privmsg #%s :%s\r\n", chan, l->buf);
- printf("\x1b[35mprivmsg #%s :%s\x1b[0m\r\n", chan, l->buf);
+ if(l->nick_privmsg == 0) {
+ raw("privmsg #%s :%s\r\n", chan, l->buf);
+ printf("\x1b[35mprivmsg #%s :%s\x1b[0m\r\n", chan, l->buf);
+ }
+ else {
+ raw("privmsg %s :%s\r\n", chan, l->buf);
+ printf("\x1b[35mprivmsg %s :%s\x1b[0m\r\n", chan, l->buf);
+ }
return;
}
}
@@ -1434,6 +1462,7 @@ int main(int argc, char **argv)
dcc_sessions.sock_fds[CON_MAX] = (struct pollfd){.fd = ttyinfd,.events = POLLIN};
dcc_sessions.sock_fds[CON_MAX + 1] = (struct pollfd){.fd = conn,.events = POLLIN};
state_t l;
+ memset(&l, 0, sizeof(l));
l.buflen = MSG_MAX;
state_reset(&l);
int rc, editReturnFlag = 0;
diff --git a/kirc.h b/kirc.h
index 04fda43..867d431 100644
--- a/kirc.h
+++ b/kirc.h
@@ -102,6 +102,7 @@ typedef struct STATE {
size_t lenu8; /* Current edited line length. */
size_t cols; /* Number of columns in terminal. */
int history_index; /* Current line in the edit history */
+ char nick_privmsg; /* whether or not we are sending messages to a chan or nick */
} state_t, *state;
struct abuf {