Add /setname command

I'm not sure about that replies check in handleStandardReply. If more of
those are added the reply counter system will definitely need
refactoring.
master
C. McEnroe 2020-12-29 23:49:16 -05:00
parent b4ed58602b
commit 1662b01a5f
4 changed files with 36 additions and 0 deletions

View File

@ -328,6 +328,9 @@ command is likely needed
for command output.
.It Ic /say Ar message
Send a regular message.
.It Ic /setname Ar name
Update realname
if supported by the server.
.It Ic /topic Op Ar topic
Show or set the topic of the channel.
Press
@ -735,6 +738,13 @@ ignore = * [JPQ][OAU][IR][NT] #example
.Re
.It
.Rs
.%A Janne Mareike Koschinski
.%T IRCv3 setname Extension
.%I IRCv3 Working Group
.%U https://ircv3.net/specs/extensions/setname
.Re
.It
.Rs
.%A Mantas Mikul\[u0117]nas
.%T IRCv3.2 userhost-in-names Extension
.%I IRCv3 Working Group

2
chat.h
View File

@ -171,6 +171,7 @@ extern struct Network {
X("multi-prefix", CapMultiPrefix) \
X("sasl", CapSASL) \
X("server-time", CapServerTime) \
X("setname", CapSetname) \
X("userhost-in-names", CapUserhostInNames)
enum Cap {
@ -256,6 +257,7 @@ extern struct Replies {
uint list;
uint mode;
uint names;
uint setname;
uint topic;
uint who;
uint whois;

View File

@ -159,6 +159,13 @@ static void commandAway(uint id, char *params) {
replies.away++;
}
static void commandSetname(uint id, char *params) {
(void)id;
if (!params) return;
ircFormat("SETNAME :%s\r\n", params);
replies.setname++;
}
static void commandTopic(uint id, char *params) {
if (params) {
ircFormat("TOPIC %s :%s\r\n", idNames[id], params);
@ -486,6 +493,7 @@ static const struct Handler {
{ "/quit", commandQuit, 0 },
{ "/quote", commandQuote, Multiline | Restricted },
{ "/say", commandPrivmsg, Multiline },
{ "/setname", commandSetname, 0 },
{ "/topic", commandTopic, 0 },
{ "/unban", commandUnban, 0 },
{ "/unexcept", commandUnexcept, 0 },

View File

@ -97,6 +97,10 @@ typedef void Handler(struct Message *msg);
static void handleStandardReply(struct Message *msg) {
require(msg, false, 3);
if (!strcmp(msg->params[0], "SETNAME")) {
if (!replies.setname) return;
replies.setname--;
}
for (uint i = 2; i < ParamCap - 1; ++i) {
if (msg->params[i + 1]) continue;
uiFormat(
@ -1150,6 +1154,17 @@ static void handleReplyNowAway(struct Message *msg) {
replies.away--;
}
static void handleSetname(struct Message *msg) {
require(msg, true, 1);
if (!replies.setname) return;
if (strcmp(msg->nick, self.nick)) return;
uiFormat(
Network, Warm, tagTime(msg),
"You update your name tag: %s", msg->params[0]
);
replies.setname--;
}
static bool isAction(struct Message *msg) {
if (strncmp(msg->params[1], "\1ACTION ", 8)) return false;
msg->params[1] += 8;
@ -1343,6 +1358,7 @@ static const struct Handler {
{ "PING", handlePing },
{ "PRIVMSG", handlePrivmsg },
{ "QUIT", handleQuit },
{ "SETNAME", handleSetname },
{ "TOPIC", handleTopic },
{ "WARN", handleStandardReply },
};