Explorar el Código

Draft implementation of draft/setname

tags/v1.0.0-rc1
Daniel Oaks hace 5 años
padre
commit
53ed368701
Se han modificado 6 ficheros con 43 adiciones y 2 borrados
  1. 6
    0
      gencapdefs.py
  2. 6
    1
      irc/caps/defs.go
  3. 4
    0
      irc/commands.go
  4. 21
    0
      irc/handlers.go
  5. 5
    0
      irc/help.go
  6. 1
    1
      irc/server.go

+ 6
- 0
gencapdefs.py Ver fichero

@@ -123,6 +123,12 @@ CAPDEFS = [
123 123
         url="https://ircv3.net/specs/extensions/server-time-3.2.html",
124 124
         standard="IRCv3",
125 125
     ),
126
+    CapDef(
127
+        identifier="SetName",
128
+        name="draft/setname",
129
+        url="https://github.com/ircv3/ircv3-specifications/pull/361",
130
+        standard="proposed IRCv3",
131
+    ),
126 132
     CapDef(
127 133
         identifier="STS",
128 134
         name="sts",

+ 6
- 1
irc/caps/defs.go Ver fichero

@@ -7,7 +7,7 @@ package caps
7 7
 
8 8
 const (
9 9
 	// number of recognized capabilities:
10
-	numCapabs = 20
10
+	numCapabs = 21
11 11
 	// length of the uint64 array that represents the bitset:
12 12
 	bitsetLen = 1
13 13
 )
@@ -85,6 +85,10 @@ const (
85 85
 	// https://ircv3.net/specs/extensions/server-time-3.2.html
86 86
 	ServerTime Capability = iota
87 87
 
88
+	// SetName is the proposed IRCv3 capability named "draft/setname":
89
+	// https://github.com/ircv3/ircv3-specifications/pull/361
90
+	SetName Capability = iota
91
+
88 92
 	// STS is the IRCv3 capability named "sts":
89 93
 	// https://ircv3.net/specs/extensions/sts.html
90 94
 	STS Capability = iota
@@ -115,6 +119,7 @@ var (
115 119
 		"draft/resume-0.3",
116 120
 		"sasl",
117 121
 		"server-time",
122
+		"draft/setname",
118 123
 		"sts",
119 124
 		"userhost-in-names",
120 125
 	}

+ 4
- 0
irc/commands.go Ver fichero

@@ -252,6 +252,10 @@ func init() {
252 252
 			handler:   sceneHandler,
253 253
 			minParams: 2,
254 254
 		},
255
+		"SETNAME": {
256
+			handler:   setnameHandler,
257
+			minParams: 1,
258
+		},
255 259
 		"TAGMSG": {
256 260
 			handler:   tagmsgHandler,
257 261
 			minParams: 1,

+ 21
- 0
irc/handlers.go Ver fichero

@@ -2310,6 +2310,27 @@ func sceneHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Res
2310 2310
 	return false
2311 2311
 }
2312 2312
 
2313
+// SETNAME <realname>
2314
+func setnameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
2315
+	if !client.capabilities.Has(caps.SetName) {
2316
+		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()))
2317
+		return false
2318
+	}
2319
+
2320
+	realname := msg.Params[0]
2321
+
2322
+	client.stateMutex.Lock()
2323
+	client.realname = realname
2324
+	client.stateMutex.Unlock()
2325
+
2326
+	// alert friends
2327
+	for friend := range client.Friends(caps.SetName) {
2328
+		friend.SendFromClient("", client, nil, "SETNAME", realname)
2329
+	}
2330
+
2331
+	return false
2332
+}
2333
+
2313 2334
 // TAGMSG <target>{,<target>}
2314 2335
 func tagmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
2315 2336
 	clientOnlyTags := utils.GetClientOnlyTags(msg.Tags)

+ 5
- 0
irc/help.go Ver fichero

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

+ 1
- 1
irc/server.go Ver fichero

@@ -47,7 +47,7 @@ var (
47 47
 
48 48
 	// SupportedCapabilities are the caps we advertise.
49 49
 	// MaxLine, SASL and STS are set during server startup.
50
-	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)
50
+	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)
51 51
 
52 52
 	// CapValues are the actual values we advertise to v3.2 clients.
53 53
 	// actual values are set during server startup.

Loading…
Cancelar
Guardar