From 545318e14fe1d0c115b1c0c922e3f2beecfa1384 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Wed, 27 Apr 2005 19:52:51 +0000 Subject: [PATCH] IBC is ready for testing --- mbtask/taskchat.c | 12 +++-------- mbtask/taskchat.h | 5 +++++ mbtask/taskibc.c | 51 ++++++++++++++++++++++++++++++++++++++++++++--- mbtask/taskibc.h | 1 + 4 files changed, 57 insertions(+), 12 deletions(-) diff --git a/mbtask/taskchat.c b/mbtask/taskchat.c index abbfcd66..058d0cdb 100644 --- a/mbtask/taskchat.c +++ b/mbtask/taskchat.c @@ -134,11 +134,6 @@ extern int chnchg; /* * Prototypes */ -#ifdef USE_EXPERIMENT -void chat_msg(char *, char *, char *); -#else -void chat_msg(int, char *, char *); -#endif void chat_dump(void); void system_msg(pid_t, char *); void chat_help(pid_t); @@ -541,10 +536,6 @@ void chat_msg(int channel, char *nick, char *msg) system_msg(chat_users[i].pid, buf); } } - -#ifdef USE_EXPERIMENT - send_all("MSG %s\r\n", buf); -#endif } @@ -934,6 +925,9 @@ char *chat_put(char *data) } else { chat_msg(chat_users[i].channel, chat_users[i].nick, msg); chat_dump(); +#ifdef USE_EXPERIMENT + send_all("PRIVMSG %s <%s> %s\r\n", chat_users[i].channel, chat_users[i].nick, msg); +#endif } goto ack; } diff --git a/mbtask/taskchat.h b/mbtask/taskchat.h index 77afe129..f1134a27 100644 --- a/mbtask/taskchat.h +++ b/mbtask/taskchat.h @@ -3,6 +3,11 @@ /* $Id$ */ +#ifdef USE_EXPERIMENT +void chat_msg(char *, char *, char *); +#else +void chat_msg(int, char *, char *); +#endif void system_shout(const char *, ...); void chat_init(void); void chat_cleanuser(pid_t); diff --git a/mbtask/taskibc.c b/mbtask/taskibc.c index 008ab9ad..8706e66a 100644 --- a/mbtask/taskibc.c +++ b/mbtask/taskibc.c @@ -92,6 +92,7 @@ int command_nick(char *, char *); int command_join(char *, char *); int command_part(char *, char *); int command_topic(char *, char *); +int command_privmsg(char *, char *); void receiver(struct servent *); @@ -1063,10 +1064,10 @@ int command_quit(char *hostname, char *parameters) } if (message) { - send_all("MSG ** %s is leaving: %s\r\n", name, message); + send_all("NOTICE * ** %s is leaving: %s\r\n", name, message); system_shout("* User %s is leaving: %s", name, message); } else { - send_all("MSG ** %s is leaving: Quit\r\n", name); + send_all("NOTICE * ** %s is leaving: Quit\r\n", name); system_shout("* User %s is leaving", name); } del_user(&users, server, name); @@ -1279,8 +1280,8 @@ int command_topic(char *hostname, char *parameters) chnchg = TRUE; strncpy(tmp->topic, topic, 54); Syslog('+', "IBC: channel %s topic: %s", channel, topic); + break; } - break; } broadcast(hostname, "TOPIC %s %s\r\n", channel, topic); @@ -1288,6 +1289,47 @@ int command_topic(char *hostname, char *parameters) } + +int command_privmsg(char *hostname, char *parameters) +{ + ncs_list *tnsl; + chn_list *tmp; + char *channel, *msg; + + for (tnsl = ncsl; tnsl; tnsl = tnsl->next) { + if (strcmp(tnsl->server, hostname) == 0) { + break; + } + } + + channel = strtok(parameters, " \0"); + msg = strtok(NULL, "\0"); + + if (msg == NULL) { + send_msg(tnsl, "412 PRIVMSG: No text to send\r\n"); + return 412; + } + + if (channel[0] != '#') { + send_msg(tnsl, "401 PRIVMSG: Not for a channel\r\n"); // FIXME: also check users + return 401; + } + + for (tmp = channels; tmp; tmp = tmp->next) { + if (strcmp(tmp->name, channel) == 0) { + tmp->lastmsg = now; + chat_msg(channel, NULL, msg); + broadcast(hostname, "PRIVMSG %s %s\r\n", channel, msg); + return 0; + } + } + + send_msg(tnsl, "403 %s: no such channel\r\n", channel); + return 403; +} + + + int do_command(char *hostname, char *command, char *parameters) { ncs_list *tnsl; @@ -1344,6 +1386,9 @@ int do_command(char *hostname, char *command, char *parameters) if (! strcmp(command, (char *)"TOPIC")) { return command_topic(hostname, parameters); } + if (! strcmp(command, (char *)"PRIVMSG")) { + return command_privmsg(hostname, parameters); + } send_msg(tnsl, "421 %s: Unknown command\r\n", command); return 421; diff --git a/mbtask/taskibc.h b/mbtask/taskibc.h index 87d025ef..7cac723d 100644 --- a/mbtask/taskibc.h +++ b/mbtask/taskibc.h @@ -72,6 +72,7 @@ typedef struct _chn_list { char topic[55]; /* Channel topic */ char owner[10]; /* Channel owner */ time_t created; /* Channel created */ + time_t lastmsg; /* Last message in channel */ int users; /* Users in channel */ } chn_list;