From: Egor Date: Fri, 3 Feb 2023 19:13:25 +0000 (+0200) Subject: add KICK X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;h=447f044f3c9e5e6a0e71637ffb55b84fb63bdbec;p=patchyircd.git add KICK --- diff --git a/irc.c b/irc.c index 7d30c82..6c465fe 100644 --- a/irc.c +++ b/irc.c @@ -408,7 +408,7 @@ int processPacket(struct client_data *client, char *source, char *command, int a if (trie_findfirst(&f, &client->channels) == 1) do { struct channel *chan = f->n->value; - channel_part(client, chan, "I fell for a classic prank"); + channel_part(client, chan, "I fell for a classic prank", NULL); } while(trie_findfirst(&f, &client->channels) == 1); free(f); return 0; @@ -437,7 +437,7 @@ int processPacket(struct client_data *client, char *source, char *command, int a struct channel *chan = findChannel(channel); if (!chan) return err_nosuchchannel(client, args[0]), sendbuf(client), 0; - channel_part(client, chan, args[1] ? args[1] : ""); + channel_part(client, chan, args[1] ? args[1] : "", NULL); } while (p); } else if(strcmp(command, "TOPIC") == 0) { if (!is_registered(client)) @@ -453,7 +453,7 @@ int processPacket(struct client_data *client, char *source, char *command, int a } else { // TODO: membership check, maybe? if (chan->dmode & DMODE_TOPICPROT && !trie_get(&chan->o, client->key)) - return 0; // error 482 + return 0; // FIXME: error 482 free(chan->topic); free(chan->topic_who); if (!*args[1]) { @@ -510,6 +510,31 @@ int processPacket(struct client_data *client, char *source, char *command, int a msg_invite(client, cl, chan); sendbuf(cl); sendbuf_chan_caps(chan, CAP_INVITENOTIFY, 0); + } else if(strcmp(command, "KICK") == 0) { + if (!is_registered(client)) + return err_notregistered(client), sendbuf(client), 0; + if (argc < 2) + return err_needmoreparams(client, command), 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->members, client->key)) + return err_notonchannel(client, chan), sendbuf(client), 0; + char *p = args[1]; + do { + char *nick = p; + if ((p = strchr(nick, ','))) + *p++ = '\0'; + struct client_data *cl = findClient(nick); + if (!cl) + err_nosuchnick(client, nick), sendbuf(client); + else + channel_part(cl, chan, args[2], client); + } while (p); } else if(strcmp(command, "PRIVMSG") == 0 || strcmp(command, "NOTICE") == 0) { if (!is_registered(client)) return err_notregistered(client), sendbuf(client), 0; @@ -1307,11 +1332,14 @@ void channel_join(struct client_data *client, const char *channel, const char *c // send names channel_sendnames(client, chan); } -void channel_part(struct client_data *client, struct channel *chan, const char *reason) +void channel_part(struct client_data *client, struct channel *chan, const char *reason, struct client_data *kicker) { if (!trie_get(&chan->members, client->key)) return; - if (reason) { + if (kicker) { + msg_kick(kicker, client, chan, reason); + sendbuf_chan(chan); + } else if (reason) { msg_part(client, chan, *reason ? reason : NULL); sendbuf_chan(chan); } diff --git a/irc.h b/irc.h index d75225f..2d1a04c 100644 --- a/irc.h +++ b/irc.h @@ -16,7 +16,7 @@ struct channel *findChannel(const char *channel); void channel_sendtopic(struct client_data *client, struct channel *chan, int joining); void channel_sendnames(struct client_data *client, struct channel *chan); void channel_join(struct client_data *client, const char *channel, const char *chankey); -void channel_part(struct client_data *client, struct channel *chan, const char *reason); +void channel_part(struct client_data *client, struct channel *chan, const char *reason, struct client_data *kicker); extern struct dynarr databuf; // glob.c diff --git a/ircfmt.c b/ircfmt.c index d064d07..4e03793 100644 --- a/ircfmt.c +++ b/ircfmt.c @@ -81,7 +81,6 @@ void msg_invite(struct client_data *src, struct client_data *dst, struct channel copy_strf(&databuf, ":%s!%s@%s INVITE %s %s\r\n", src->nick, src->username, src->hostname, dst->nick, chan->name); } -#if 0 void msg_kick(struct client_data *src, struct client_data *who, struct channel *chan, const char *reason) { if (reason) @@ -91,7 +90,6 @@ void msg_kick(struct client_data *src, struct client_data *who, struct channel * copy_strf(&databuf, ":%s!%s@%s KICK %s %s\r\n", src->nick, src->username, src->hostname, chan->name, who->nick); } -#endif void msg_privmsg(struct client_data *src, const char *dst, const char *msg) { copy_strf(&databuf, ":%s!%s@%s PRIVMSG %s :%s\r\n", diff --git a/net.c b/net.c index 0101443..12f06d2 100644 --- a/net.c +++ b/net.c @@ -48,7 +48,7 @@ void killConnection(struct client_data *cl, bool byChoice) { if (trie_findfirst(&f, &cl->channels) == 1) do { struct channel *chan = f->n->value; - channel_part(cl, chan, NULL); + channel_part(cl, chan, NULL, NULL); } while(trie_findfirst(&f, &cl->channels) == 1); free(f); if (cl->key) {