IBC is ready for testing

This commit is contained in:
Michiel Broek 2005-04-27 19:52:51 +00:00
parent be9f2513d1
commit 545318e14f
4 changed files with 57 additions and 12 deletions

View File

@ -134,11 +134,6 @@ extern int chnchg;
/* /*
* Prototypes * Prototypes
*/ */
#ifdef USE_EXPERIMENT
void chat_msg(char *, char *, char *);
#else
void chat_msg(int, char *, char *);
#endif
void chat_dump(void); void chat_dump(void);
void system_msg(pid_t, char *); void system_msg(pid_t, char *);
void chat_help(pid_t); 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); 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 { } else {
chat_msg(chat_users[i].channel, chat_users[i].nick, msg); chat_msg(chat_users[i].channel, chat_users[i].nick, msg);
chat_dump(); 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; goto ack;
} }

View File

@ -3,6 +3,11 @@
/* $Id$ */ /* $Id$ */
#ifdef USE_EXPERIMENT
void chat_msg(char *, char *, char *);
#else
void chat_msg(int, char *, char *);
#endif
void system_shout(const char *, ...); void system_shout(const char *, ...);
void chat_init(void); void chat_init(void);
void chat_cleanuser(pid_t); void chat_cleanuser(pid_t);

View File

@ -92,6 +92,7 @@ int command_nick(char *, char *);
int command_join(char *, char *); int command_join(char *, char *);
int command_part(char *, char *); int command_part(char *, char *);
int command_topic(char *, char *); int command_topic(char *, char *);
int command_privmsg(char *, char *);
void receiver(struct servent *); void receiver(struct servent *);
@ -1063,10 +1064,10 @@ int command_quit(char *hostname, char *parameters)
} }
if (message) { 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); system_shout("* User %s is leaving: %s", name, message);
} else { } 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); system_shout("* User %s is leaving", name);
} }
del_user(&users, server, name); del_user(&users, server, name);
@ -1279,8 +1280,8 @@ int command_topic(char *hostname, char *parameters)
chnchg = TRUE; chnchg = TRUE;
strncpy(tmp->topic, topic, 54); strncpy(tmp->topic, topic, 54);
Syslog('+', "IBC: channel %s topic: %s", channel, topic); Syslog('+', "IBC: channel %s topic: %s", channel, topic);
break;
} }
break;
} }
broadcast(hostname, "TOPIC %s %s\r\n", channel, topic); 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) int do_command(char *hostname, char *command, char *parameters)
{ {
ncs_list *tnsl; ncs_list *tnsl;
@ -1344,6 +1386,9 @@ int do_command(char *hostname, char *command, char *parameters)
if (! strcmp(command, (char *)"TOPIC")) { if (! strcmp(command, (char *)"TOPIC")) {
return command_topic(hostname, parameters); 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); send_msg(tnsl, "421 %s: Unknown command\r\n", command);
return 421; return 421;

View File

@ -72,6 +72,7 @@ typedef struct _chn_list {
char topic[55]; /* Channel topic */ char topic[55]; /* Channel topic */
char owner[10]; /* Channel owner */ char owner[10]; /* Channel owner */
time_t created; /* Channel created */ time_t created; /* Channel created */
time_t lastmsg; /* Last message in channel */
int users; /* Users in channel */ int users; /* Users in channel */
} chn_list; } chn_list;