From 53ed368701359c78a486ce23a3e0e268ccbee5a3 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Wed, 13 Feb 2019 23:22:16 +1000 Subject: [PATCH 1/2] Draft implementation of draft/setname --- gencapdefs.py | 6 ++++++ irc/caps/defs.go | 7 ++++++- irc/commands.go | 4 ++++ irc/handlers.go | 21 +++++++++++++++++++++ irc/help.go | 5 +++++ irc/server.go | 2 +- 6 files changed, 43 insertions(+), 2 deletions(-) diff --git a/gencapdefs.py b/gencapdefs.py index a0dcd0f4..9c3fe2e3 100644 --- a/gencapdefs.py +++ b/gencapdefs.py @@ -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", diff --git a/irc/caps/defs.go b/irc/caps/defs.go index 74ff1de6..adfbbb7d 100644 --- a/irc/caps/defs.go +++ b/irc/caps/defs.go @@ -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", } diff --git a/irc/commands.go b/irc/commands.go index fce1b5df..92e1bfb2 100644 --- a/irc/commands.go +++ b/irc/commands.go @@ -252,6 +252,10 @@ func init() { handler: sceneHandler, minParams: 2, }, + "SETNAME": { + handler: setnameHandler, + minParams: 1, + }, "TAGMSG": { handler: tagmsgHandler, minParams: 1, diff --git a/irc/handlers.go b/irc/handlers.go index e6210d03..3304021f 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -2310,6 +2310,27 @@ func sceneHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Res return false } +// SETNAME +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 {,} func tagmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool { clientOnlyTags := utils.GetClientOnlyTags(msg.Tags) diff --git a/irc/help.go b/irc/help.go index cef0f1d0..e2a94e0f 100644 --- a/irc/help.go +++ b/irc/help.go @@ -434,6 +434,11 @@ opers. For more specific information on mode characters, see the help for text: `SCENE The SCENE command is used to send a scene notification to the given target.`, + }, + "setname": { + text: `SETNAME + +The SETNAME command updates the realname to be the newly-given one.`, }, "tagmsg": { text: `@+client-only-tags TAGMSG {,} diff --git a/irc/server.go b/irc/server.go index c478afdb..fdf4f01e 100644 --- a/irc/server.go +++ b/irc/server.go @@ -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. From 78a0b322f7ba675a27325e49d51c2810af001973 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Wed, 13 Feb 2019 23:42:03 +1000 Subject: [PATCH 2/2] Make it act as intended --- irc/handlers.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/irc/handlers.go b/irc/handlers.go index 3304021f..64534610 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -2312,11 +2312,6 @@ func sceneHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Res // SETNAME 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()