struct trie_node *channel_map = NULL;
const char *hostname = "irc.patchysicp.xyz";
+#define is_registered(cl) ((cl)->nick != 0)
+static void err_notregistered(struct client_data *client) {
+ copy_strf(&databuf, ":%s 451 * :You have not registered\n", hostname);
+ send_log(client->FD, databuf.buf, databuf.len, 0);
+}
int processPacket(struct client_data *client) {
char *source = NULL;
(void)source;
// Send welcome
sendMOTD(client);
} else if(strcmp(command, "JOIN") == 0) {
- if (!client->nick) // FIXME: error message
- return 0;
+ if (!is_registered(client))
+ return err_notregistered(client), 0;
if (!args[0]) // FIXME: error message
return 0;
if (!strcmp(args[0], "0")) {
*p = '\0';
channel_join(client, args[0], NULL);
} else if(strcmp(command, "PART") == 0) {
- if (!client->nick) // FIXME: error message
- return 0;
+ if (!is_registered(client))
+ return err_notregistered(client), 0;
if (!args[0]) // FIXME: error message
return 0;
char *p = strchr(args[0], ','); // TODO: multiple channels
return 0;
channel_part(client, chan, args[1] ? args[1] : "");
} else if(strcmp(command, "TOPIC") == 0) {
- if (!client->nick) // FIXME: error message
- return 0;
+ if (!is_registered(client))
+ return err_notregistered(client), 0;
if (!args[0]) // FIXME: error message
return 0;
struct channel *chan = findChannel(args[0]);
} while (trie_findnext(&f) == 1);
}
} else if(strcmp(command, "PRIVMSG") == 0) {
- if (!client->nick) // FIXME: error message
- return 0;
+ if (!is_registered(client))
+ return err_notregistered(client), 0;
if (argc < 2) // FIXME: error message
return 0;
copy_strf(&databuf, ":%s!%s@%s PRIVMSG %s :%s\n", client->nick, client->username, client->hostname, args[0], args[1]);
} else if(strcmp(command, "PONG") == 0) {
// Do nothing
} else if(strcmp(command, "MODE") == 0) {
- if (!client->nick) // FIXME: error message
- return 0;
+ if (!is_registered(client))
+ return err_notregistered(client), 0;
if (argc == 0) // FIXME: error message
return 0;
char *nick = args[0];
}
}
} else if(strcmp(command, "LIST") == 0) {
+ if (!is_registered(client))
+ return err_notregistered(client), 0;
copy_strf(&databuf, ":%s 321 %s Channel :Users Name\n", hostname, client->nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
struct trie_find *f = NULL;
send_log(client->FD, databuf.buf, databuf.len, 0);
} else if(strcmp(command, "NAMES") == 0) {
// TODO: actual channel support
- if (!client->nick) // FIXME: error message
- return 0;
+ if (!is_registered(client))
+ return err_notregistered(client), 0;
if (argc == 0) // FIXME: error message
return 0;
struct trie_find *f = NULL;
copy_strf(&databuf, ":%s 366 %s :End of /NAMES list\n", hostname, client->nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
} else if(strcmp(command, "USERHOST") == 0) {
- if (!client->nick) // FIXME: error message
- return 0;
+ if (!is_registered(client))
+ return err_notregistered(client), 0;
if (argc == 0) // FIXME: error message
return 0;
copy_strf(&databuf, ":%s 302 %s", hostname, client->nick);
}
send_log(client->FD, databuf.buf, databuf.len, 0);
} else if(strcmp(command, "WHO") == 0) {
- if (!client->nick) // FIXME: error message
- return 0;
+ if (!is_registered(client))
+ return err_notregistered(client), 0;
if (argc == 0) // FIXME: error message
return 0;
struct client_data *cl = findClient(args[0]);
copy_strf(&databuf, ":%s 315 %s %s :End of WHO list\n", hostname, client->nick, args[0]);
send_log(client->FD, databuf.buf, databuf.len, 0);
} else if(strcmp(command, "WHOIS") == 0) {
- if (!client->nick) // FIXME: error message
- return 0;
+ if (!is_registered(client))
+ return err_notregistered(client), 0;
if (argc == 0) // FIXME: error message
return 0;
char *nick = args[1] ? args[1] : args[0];
send_log(client->FD, databuf.buf, databuf.len, 0);
}
} else if(strcmp(command, "AWAY") == 0) {
- if (!client->nick) // FIXME: error message
- return 0;
+ if (!is_registered(client))
+ return err_notregistered(client), 0;
if (args[0]) {
free(client->away);
client->away = mystrdup(args[0]);