if(strcmp(command, "PING") == 0) {
if (!args[0]) // FIXME: error message
return 0;
- append_strf(&databuf, ":%s PONG %s :%s", hostname, hostname, args[0]);
+ copy_strf(&databuf, ":%s PONG %s :%s", hostname, hostname, args[0]);
send_log(client->FD, databuf.buf, databuf.len, 0);
} else if(strcmp(command, "NICK") == 0) {
// User now registered
*p = '\0';
break;
}
- append_strf(&databuf, ":%s JOIN :%s\n", client->nick, args[0]);
+ copy_strf(&databuf, ":%s JOIN :%s\n", client->nick, args[0]);
// End GitHub Copilot
send_log(client->FD, databuf.buf, databuf.len, 0);
sendall_log(client->FD, databuf.buf, databuf.len, 0);
for(int i=0; i<CLIENTS; i++)
if(clients[i] && clients[i]->nick[0]) {
- databuf.len = 0;
- append_strf(&databuf, ":%s 353 %s = %s :%s\n", hostname, client->nick, args[0], clients[i]->nick);
+ copy_strf(&databuf, ":%s 353 %s = %s :%s\n", hostname, client->nick, args[0], clients[i]->nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
}
- databuf.len = 0;
- append_strf(&databuf, ":%s 366 %s :End of /NAMES list\n", hostname, client->nick);
+ 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, "PRIVMSG") == 0) {
if (argc < 2) // FIXME: error message
return 0;
- append_strf(&databuf, ":%s PRIVMSG %s :%s\n", client->nick, args[0], args[1]);
+ copy_strf(&databuf, ":%s PRIVMSG %s :%s\n", client->nick, args[0], args[1]);
sendall_log(client->FD, databuf.buf, databuf.len, 0);
// Start GitHub Copilot - this shit actually be copy pasting my code lmao
} else if(strcmp(command, "QUIT") == 0) {
- append_strf(&databuf, ":%s QUIT :%s\n", client->nick, args[0] ? args[0] : "Client Quit");
+ copy_strf(&databuf, ":%s QUIT :%s\n", client->nick, args[0] ? args[0] : "Client Quit");
sendall_log(client->FD, databuf.buf, databuf.len, 0);
killConnection(client, true);
return 1;
if (*nick != '#') {
struct client_data *cl = findClient(nick);
if (!cl) {
- append_strf(&databuf, ":%s 401 %s %s :No such nick/channel\n", hostname, client->nick, nick);
+ copy_strf(&databuf, ":%s 401 %s %s :No such nick/channel\n", hostname, client->nick, nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
return 0;
}
- append_strf(&databuf, ":%s 221 %s +", hostname, client->nick);
+ copy_strf(&databuf, ":%s 221 %s +", hostname, client->nick);
if (cl->umode & UMODE_INVISIBLE) append_str(&databuf, "i");
if (cl->umode & UMODE_OPER) append_str(&databuf, "o");
if (cl->umode & UMODE_LOPER) append_str(&databuf, "O");
append_str(&databuf, "\n");
send_log(client->FD, databuf.buf, databuf.len, 0);
} else {
- append_strf(&databuf, ":%s 324 %s %s +nt\n", hostname, client->nick, nick);
+ copy_strf(&databuf, ":%s 324 %s %s +nt\n", hostname, client->nick, nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
}
} else { // set mode
if (*nick != '#') {
struct client_data *cl = findClient(nick);
if (!cl) {
- append_strf(&databuf, ":%s 401 %s %s :No such nick/channel\n", hostname, client->nick, nick);
+ copy_strf(&databuf, ":%s 401 %s %s :No such nick/channel\n", hostname, client->nick, nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
return 0;
}
if (client->FD != cl->FD) {
- append_strf(&databuf, ":%s 502 %s :Can't change mode for other users\n", hostname, client->nick);
+ copy_strf(&databuf, ":%s 502 %s :Can't change mode for other users\n", hostname, client->nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
return 0;
}
default: goto unknown;
}
while (*p) {
- databuf.len = 0;
switch (*p) {
case 'i':
if (off) {
- append_strf(&databuf, ":%s MODE %s -i\n", hostname, client->nick);
+ copy_strf(&databuf, ":%s MODE %s -i\n", hostname, client->nick);
cl->umode &= ~UMODE_INVISIBLE;
} else {
- append_strf(&databuf, ":%s MODE %s +i\n", hostname, client->nick);
+ copy_strf(&databuf, ":%s MODE %s +i\n", hostname, client->nick);
cl->umode |= UMODE_INVISIBLE;
}
send_log(client->FD, databuf.buf, databuf.len, 0);
break;
default:
- append_strf(&databuf, ":%s 501 %s :Unknown MODE flag\n", hostname, client->nick);
+ copy_strf(&databuf, ":%s 501 %s :Unknown MODE flag\n", hostname, client->nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
}
p++;
return 0;
for(int i=0; i<CLIENTS; i++)
if(clients[i] && clients[i]->nick[0]) {
- databuf.len = 0;
- append_strf(&databuf, ":%s 353 %s = %s :%s\n", hostname, client->nick, args[0], clients[i]->nick);
+ copy_strf(&databuf, ":%s 353 %s = %s :%s\n", hostname, client->nick, args[0], clients[i]->nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
}
- databuf.len = 0;
- append_strf(&databuf, ":%s 366 %s :End of /NAMES list\n", hostname, client->nick);
+ copy_strf(&databuf, ":%s 366 %s :End of /NAMES list\n", hostname, client->nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
} else {
unknown:
// Inform user of error
- append_strf(&databuf, ":%s 421 %s :Unknown command %s\n", hostname, client->nick, command);
+ copy_strf(&databuf, ":%s 421 %s :Unknown command %s\n", hostname, client->nick, command);
send_log(client->FD, databuf.buf, databuf.len, 0);
fflush(stdout);
}
}
void newUser(struct client_data *client) {
- // Copy in basics
- databuf.len = 0;
- append_strf(&databuf, ":%s 001 %s :Welcome to PatchyIRCD!!!\n", hostname, client->nick);
+ copy_strf(&databuf, ":%s 001 %s :Welcome to PatchyIRCD!!!\n", hostname, client->nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
- databuf.len = 0;
- append_strf(&databuf, ":%s 002 %s :Your host is PatchyIRCD V0.0.1\n", hostname, client->nick);
+ copy_strf(&databuf, ":%s 002 %s :Your host is PatchyIRCD V0.0.1\n", hostname, client->nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
- databuf.len = 0;
- append_strf(&databuf, ":%s 003 %s :This server was created when I had cybersex with your mother.\n", hostname, client->nick);
+ copy_strf(&databuf, ":%s 003 %s :This server was created when I had cybersex with your mother.\n", hostname, client->nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
- databuf.len = 0;
- append_strf(&databuf, ":%s 251 %s :This server exists\n", hostname, client->nick);
+ copy_strf(&databuf, ":%s 251 %s :This server exists\n", hostname, client->nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
- databuf.len = 0;
- append_strf(&databuf, ":%s 252 %s :Jannies don't exist\n", hostname, client->nick);
+ copy_strf(&databuf, ":%s 252 %s :Jannies don't exist\n", hostname, client->nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
sendMOTD(client);
}
void sendMOTD(struct client_data *client) {
- databuf.len = 0;
- append_strf(&databuf, ":%s 375 %s :PatchySICP /MOTD\n", hostname, client->nick);
+ copy_strf(&databuf, ":%s 375 %s :PatchySICP /MOTD\n", hostname, client->nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
- databuf.len = 0;
- append_strf(&databuf, ":%s 372 %s :Welcome to Montreal!\n", hostname, client->nick);
+ copy_strf(&databuf, ":%s 372 %s :Welcome to Montreal!\n", hostname, client->nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
- databuf.len = 0;
- append_strf(&databuf, ":%s 372 %s :You are retarded and I will have cybersex with your mom.\n", hostname, client->nick);
+ copy_strf(&databuf, ":%s 372 %s :You are retarded and I will have cybersex with your mom.\n", hostname, client->nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
- databuf.len = 0;
- append_strf(&databuf, ":%s 376 %s :/MOTD over\n", hostname, client->nick);
+ copy_strf(&databuf, ":%s 376 %s :/MOTD over\n", hostname, client->nick);
send_log(client->FD, databuf.buf, databuf.len, 0);
}
if(clients[i] == 0) continue;
if(strncmp(clients[i]->nick, nickname, size) == 0) {
// Nickname is already taken
- databuf.len = 0;
- append_strf(&databuf, ":%s 443 * %s :Nickname is already in use\n", hostname, nickname);
+ copy_strf(&databuf, ":%s 443 * %s :Nickname is already in use\n", hostname, nickname);
send_log(client->FD, databuf.buf, databuf.len, 0);
return;
}
// Update nickname
if(client->nickLen) {
- databuf.len = 0;
- append_strf(&databuf, ":%s NICK %s\n", client->nick, nickname);
+ copy_strf(&databuf, ":%s NICK %s\n", client->nick, nickname);
send_log(client->FD, databuf.buf, databuf.len, 0);
sendall_log(client->FD, databuf.buf, databuf.len, 0);
}