Draft implementation of draft/setname

This commit is contained in:
Daniel Oaks 2019-02-13 23:22:16 +10:00
parent d804dddda5
commit 53ed368701
6 changed files with 43 additions and 2 deletions

@ -123,6 +123,12 @@ CAPDEFS = [
url="https://ircv3.net/specs/extensions/server-time-3.2.html",
standard="IRCv3",
),
CapDef(
identifier="SetName",
name="draft/setname",
url="https://github.com/ircv3/ircv3-specifications/pull/361",
standard="proposed IRCv3",
),
CapDef(
identifier="STS",
name="sts",

@ -7,7 +7,7 @@ package caps
const (
// number of recognized capabilities:
numCapabs = 20
numCapabs = 21
// length of the uint64 array that represents the bitset:
bitsetLen = 1
)
@ -85,6 +85,10 @@ const (
// https://ircv3.net/specs/extensions/server-time-3.2.html
ServerTime Capability = iota
// SetName is the proposed IRCv3 capability named "draft/setname":
// https://github.com/ircv3/ircv3-specifications/pull/361
SetName Capability = iota
// STS is the IRCv3 capability named "sts":
// https://ircv3.net/specs/extensions/sts.html
STS Capability = iota
@ -115,6 +119,7 @@ var (
"draft/resume-0.3",
"sasl",
"server-time",
"draft/setname",
"sts",
"userhost-in-names",
}

@ -252,6 +252,10 @@ func init() {
handler: sceneHandler,
minParams: 2,
},
"SETNAME": {
handler: setnameHandler,
minParams: 1,
},
"TAGMSG": {
handler: tagmsgHandler,
minParams: 1,

@ -2310,6 +2310,27 @@ func sceneHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Res
return false
}
// SETNAME <realname>
func setnameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
if !client.capabilities.Has(caps.SetName) {
client.Send(nil, server.name, "FAIL", "SETNAME", "CAP_NOT_NEGOTIATED", fmt.Sprintf("Capability '%s' is not negotiated, and is required to use this command", caps.SetName.Name()))
return false
}
realname := msg.Params[0]
client.stateMutex.Lock()
client.realname = realname
client.stateMutex.Unlock()
// alert friends
for friend := range client.Friends(caps.SetName) {
friend.SendFromClient("", client, nil, "SETNAME", realname)
}
return false
}
// TAGMSG <target>{,<target>}
func tagmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
clientOnlyTags := utils.GetClientOnlyTags(msg.Tags)

@ -434,6 +434,11 @@ opers. For more specific information on mode characters, see the help for
text: `SCENE <target> <text to be sent>
The SCENE command is used to send a scene notification to the given target.`,
},
"setname": {
text: `SETNAME <realname>
The SETNAME command updates the realname to be the newly-given one.`,
},
"tagmsg": {
text: `@+client-only-tags TAGMSG <target>{,<target>}

@ -47,7 +47,7 @@ var (
// SupportedCapabilities are the caps we advertise.
// MaxLine, SASL and STS are set during server startup.
SupportedCapabilities = caps.NewSet(caps.AccountTag, caps.AccountNotify, caps.AwayNotify, caps.Batch, caps.CapNotify, caps.ChgHost, caps.EchoMessage, caps.ExtendedJoin, caps.InviteNotify, caps.LabeledResponse, caps.Languages, caps.MessageTags, caps.MultiPrefix, caps.Rename, caps.Resume, caps.ServerTime, caps.UserhostInNames)
SupportedCapabilities = caps.NewSet(caps.AccountTag, caps.AccountNotify, caps.AwayNotify, caps.Batch, caps.CapNotify, caps.ChgHost, caps.EchoMessage, caps.ExtendedJoin, caps.InviteNotify, caps.LabeledResponse, caps.Languages, caps.MessageTags, caps.MultiPrefix, caps.Rename, caps.Resume, caps.ServerTime, caps.SetName, caps.UserhostInNames)
// CapValues are the actual values we advertise to v3.2 clients.
// actual values are set during server startup.