return err_notregistered(client), sendbuf(client), 0;
if (argc < 1)
return err_needmoreparams(client, command), sendbuf(client), 0;
- if (!(client->umode & UMODE_OPER)) {
- copy_strf(&databuf, ":%s 481 %s :Permission Denied- You're not an IRC operator\r\n", hostname, client->nick);
- sendbuf(client);
- return 0;
- }
+ if (!(client->umode & UMODE_OPER))
+ return err_noprivileges(client), sendbuf(client), 0;
msg_wallops(client, args[0]);
struct trie_find *f = NULL;
if (trie_findfirst(&f, &client_map) == 1)
} else if(strcmp(command, "KILL") == 0) {
if (!is_registered(client))
return err_notregistered(client), sendbuf(client), 0;
- if (!(client->umode & UMODE_OPER)) {
- copy_strf(&databuf, ":%s 481 %s :Permission Denied- You're not an IRC operator\r\n", hostname, client->nick);
- sendbuf(client);
- return 0;
- }
+ if (!(client->umode & UMODE_OPER))
+ return err_noprivileges(client), sendbuf(client), 0;
if (argc < 1)
return err_needmoreparams(client, command), sendbuf(client), 0;
struct client_data *cl = findClient(args[0]);
} else if(strcmp(command, "JEDGAR") == 0) {
if (!is_registered(client))
return err_notregistered(client), sendbuf(client), 0;
- if (!(client->umode & UMODE_OPER)) {
- copy_strf(&databuf, ":%s 481 %s :Permission Denied- You're not an IRC operator\r\n", hostname, client->nick);
- sendbuf(client);
- return 0;
- }
+ if (!(client->umode & UMODE_OPER))
+ return err_noprivileges(client), sendbuf(client), 0;
if (argc < 1)
return err_needmoreparams(client, command), sendbuf(client), 0;
struct channel *chan = findChannel(args[0]);
if (!chan)
return err_nosuchchannel(client, args[1]), sendbuf(client), 0;
if (chan->dmode & DMODE_INVITEONLY) {
- if (!trie_get(&chan->o, client->key)) {
- copy_strf(&databuf, ":%s 482 %s :You're not channel operator\r\n", hostname, client->nick, chan->name);
- return sendbuf(client), 0;
- }
+ if (!trie_get(&chan->o, client->key))
+ return err_chanoprivsneeded(client, chan), sendbuf(client), 0;
} else {
if (!trie_get(&chan->members, client->key))
return err_notonchannel(client, chan), sendbuf(client), 0;
struct channel *chan = findChannel(args[0]);
if (!chan)
return err_nosuchchannel(client, args[0]), sendbuf(client), 0;
- if (!trie_get(&chan->o, client->key)) {
- copy_strf(&databuf, ":%s 482 %s :You're not channel operator\r\n", hostname, client->nick, chan->name);
- return sendbuf(client), 0;
- }
+ if (!trie_get(&chan->o, client->key))
+ return err_chanoprivsneeded(client, chan), sendbuf(client), 0;
if (!trie_get(&chan->members, client->key))
return err_notonchannel(client, chan), sendbuf(client), 0;
char *p = args[1];
char line[512];
FILE *f = fopen("help.txt", "r");
if (f) {
- copy_strf(&databuf, ":%s 704 %s * :** /HELP **\r\n", hostname, client->nick), sendbuf(client);
+ rpl_helpstart(client), sendbuf(client);
while (fgets(line, 512, f)) {
char *c = strchr(line, '\n');
if (*c)
*c = '\0';
- copy_strf(&databuf, ":%s 705 %s * :%s\r\n", hostname, client->nick, line), sendbuf(client);
+ rpl_helptxt(client, line), sendbuf(client);
}
fclose(f);
- copy_strf(&databuf, ":%s 706 %s * :End of /HELP\r\n", hostname, client->nick), sendbuf(client);
+ rpl_endofhelp(client), sendbuf(client);
} else {
- copy_strf(&databuf, ":%s 524 %s * :No help available on this topic\r\n", hostname, client->nick), sendbuf(client);
+ err_helpnotfound(client), sendbuf(client);
}
} else if(strcmp(command, "VERSION") == 0) {
if (!is_registered(client))
struct client_data *cl = findClient(nick);
if (!cl)
return err_nosuchnick(client, nick), sendbuf(client), 0;
- if (client->FD != cl->FD) {
- copy_strf(&databuf, ":%s 502 %s :Can't view mode for other users\n", hostname, client->nick);
- sendbuf(client);
- return 0;
- }
+ if (client->FD != cl->FD)
+ return err_usersdontmatch(client, "Can't view mode for other users"), sendbuf(client), 0;
rpl_umodeis(client), sendbuf(client);
} else {
struct channel *chan = findChannel(nick);
struct client_data *cl = findClient(nick);
if (!cl)
return err_nosuchnick(client, nick), sendbuf(client), 0;
- if (client->FD != cl->FD) {
- copy_strf(&databuf, ":%s 502 %s :Can't change mode for other users\n", hostname, client->nick);
- sendbuf(client);
- return 0;
- }
+ if (client->FD != cl->FD)
+ return err_usersdontmatch(client, "Can't change mode for other users"), sendbuf(client), 0;
int is_plus;
char *p = args[1];
switch (*p++) {
sendbuf(client);
break;
default:
- copy_strf(&databuf, ":%s 501 %s :Unknown MODE flag\n", hostname, client->nick);
- sendbuf(client);
+ err_umodeunknownflag(client), sendbuf(client);
}
p++;
}
// FIXME: not enough args error
break;
} else if (strchr(*argp, ',') || strchr(*argp, ' ')) {
- copy_strf(&databuf, ":%s 525 %s %s :Key is not well-formed\r\n", hostname, client->nick, nick);
- sendbuf(client);
+ err_invalidkey(client, chan), sendbuf(client);
argp++;
break;
}
// Update nickname
if(client->nick) {
- copy_strf(&databuf, ":%s!%s@%s NICK %s\n", client->nick, client->username, client->hostname, nickname);
+ msg_nick(client, nickname);
sendbuf(client);
sendbuf_visible(client);
trie_set(&client_map, client->key, NULL, NULL);
copy_strf(&databuf, ":%s 475 %s %s :Cannot join channel (+k)\r\n", hostname, client->nick, chan->name);
}
// 476 ERR_BADCHANMASK
-// 481 ERR_NOPRIVILEGES
-// 482 ERR_CHANOPRIVSNEEDED
+void err_noprivileges(struct client_data *client) // 481
+{
+ copy_strf(&databuf, ":%s 481 %s :Permission Denied- You're not an IRC operator\r\n", hostname, client->nick);
+}
+void err_chanoprivsneeded(struct client_data *client, struct channel *chan) // 481
+{
+ copy_strf(&databuf, ":%s 482 %s %s :You're not channel operator\r\n", hostname, client->nick, chan->name);
+}
// 483 ERR_CANTKILLSERVER
// 491 ERR_NOOPERHOST
-// 501 ERR_UMODEUNKNOWNFLAG
-// 502 ERR_USERSDONTMATCH
-// 524 ERR_HELPNOTFOUND
-// 525 ERR_INVALIDKEY
+void err_umodeunknownflag(struct client_data *client) // 501
+{
+ copy_strf(&databuf, ":%s 501 %s :Unknown MODE flag\r\n", hostname, client->nick);
+}
+void err_usersdontmatch(struct client_data *client, const char *what) // 502
+{
+ copy_strf(&databuf, ":%s 502 %s :%s\r\n", hostname, client->nick, what);
+}
+void err_helpnotfound(struct client_data *client) // 524
+{
+ copy_strf(&databuf, ":%s 524 %s * :No help available on this topic\r\n", hostname, client->nick);
+}
+void err_invalidkey(struct client_data *client, struct channel *chan) // 525
+{
+ copy_strf(&databuf, ":%s 525 %s %s :Key is not well-formed\r\n", hostname, client->nick, chan->name);
+}
// 670 RPL_STARTTLS
// 671 RPL_WHOISSECURE
// 691 ERR_STARTTLS
// 696 ERR_INVALIDMODEPARAM
-// 704 RPL_HELPSTART
-// 705 RPL_HELPTXT
-// 706 RPL_ENDOFHELP
+void rpl_helpstart(struct client_data *client) // 704
+{
+ copy_strf(&databuf, ":%s 704 %s * :** /HELP **\r\n", hostname, client->nick);
+}
+void rpl_helptxt(struct client_data *client, const char *line) // 705
+{
+ copy_strf(&databuf, ":%s 705 %s * :%s\r\n", hostname, client->nick, line);
+}
+void rpl_endofhelp(struct client_data *client) // 706
+{
+ copy_strf(&databuf, ":%s 706 %s * :End of /HELP\r\n", hostname, client->nick);
+}
// 723 ERR_NOPRIVS
void rpl_quietlist(struct client_data *client, struct channel *chan, const char *mask) // 728
{