if(strcmp(command, "PING") == 0) {
if (!args[0]) // FIXME: error message
return 0;
- copy_strf(&databuf, ":%s PONG %s :%s", hostname, hostname, args[0]);
+ copy_strf(&databuf, ":%s PONG %s :%s\n", hostname, hostname, args[0]);
send_log(client->FD, databuf.buf, databuf.len, 0);
+ } else if(strcmp(command, "CAP") == 0) {
+ if (!args[0]) // FIXME: error message
+ return 0;
+ stringupper(args[0]);
+ if (strcmp(args[0], "LS") == 0) {
+ // at least one client hangs if it doesn't see a known extension
+ copy_strf(&databuf, ":%s CAP * LS :multi-prefix\n", hostname);
+ send_log(client->FD, databuf.buf, databuf.len, 0);
+ if (client->regstate != REG_CAPEND || !client->nick || !client->username)
+ client->regstate = REG_CAPLS;
+ } else if (strcmp(args[0], "LIST") == 0) {
+ copy_strf(&databuf, ":%s CAP * LIST :\n", hostname);
+ send_log(client->FD, databuf.buf, databuf.len, 0);
+ } else if (strcmp(args[0], "REQ") == 0) {
+ if (!args[1]) // FIXME: error message
+ return 0;
+ copy_strf(&databuf, ":%s CAP * NAK :%s\n", hostname, args[1]);
+ send_log(client->FD, databuf.buf, databuf.len, 0);
+ } else if (strcmp(args[0], "END") == 0) {
+ if (client->regstate == REG_CAPLS && client->nick && client->username)
+ newUser(client);
+ } else {
+ goto unknown;
+ }
} else if(strcmp(command, "NICK") == 0) {
// User now registered
if (!args[0]) // FIXME: error message
if (client->nick)
printf("USER SET NICKNAME %s\n", client->nick);
fflush(stdout);
- if (client->nick && client->username)
+ if (client->regstate != REG_CAPLS && client->nick && client->username)
newUser(client);
} else if(strcmp(command, "USER") == 0) {
if (argc < 4) // FIXME: error message
if (!client->hostname)
abort();
// Send welcome
- if (client->nick && client->username)
+ if (client->regstate != REG_CAPLS && client->nick && client->username)
newUser(client);
} else if(strcmp(command, "MOTD") == 0) {
// Send welcome
}
void newUser(struct client_data *client) {
+ client->regstate = REG_CAPEND;
copy_strf(&databuf, ":%s 001 %s :Welcome to the Patchy Network, %s\n", hostname, client->nick, client->nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
copy_strf(&databuf, ":%s 002 %s :Your host is PatchyIRCD, running version 0.0.1\n", hostname, client->nick);