ソースを参照

Draft implementation of draft/setname

tags/v1.0.0-rc1
Daniel Oaks 5年前
コミット
53ed368701
6個のファイルの変更43行の追加2行の削除
  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 ファイルの表示

123
         url="https://ircv3.net/specs/extensions/server-time-3.2.html",
123
         url="https://ircv3.net/specs/extensions/server-time-3.2.html",
124
         standard="IRCv3",
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
     CapDef(
132
     CapDef(
127
         identifier="STS",
133
         identifier="STS",
128
         name="sts",
134
         name="sts",

+ 6
- 1
irc/caps/defs.go ファイルの表示

7
 
7
 
8
 const (
8
 const (
9
 	// number of recognized capabilities:
9
 	// number of recognized capabilities:
10
-	numCapabs = 20
10
+	numCapabs = 21
11
 	// length of the uint64 array that represents the bitset:
11
 	// length of the uint64 array that represents the bitset:
12
 	bitsetLen = 1
12
 	bitsetLen = 1
13
 )
13
 )
85
 	// https://ircv3.net/specs/extensions/server-time-3.2.html
85
 	// https://ircv3.net/specs/extensions/server-time-3.2.html
86
 	ServerTime Capability = iota
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
 	// STS is the IRCv3 capability named "sts":
92
 	// STS is the IRCv3 capability named "sts":
89
 	// https://ircv3.net/specs/extensions/sts.html
93
 	// https://ircv3.net/specs/extensions/sts.html
90
 	STS Capability = iota
94
 	STS Capability = iota
115
 		"draft/resume-0.3",
119
 		"draft/resume-0.3",
116
 		"sasl",
120
 		"sasl",
117
 		"server-time",
121
 		"server-time",
122
+		"draft/setname",
118
 		"sts",
123
 		"sts",
119
 		"userhost-in-names",
124
 		"userhost-in-names",
120
 	}
125
 	}

+ 4
- 0
irc/commands.go ファイルの表示

252
 			handler:   sceneHandler,
252
 			handler:   sceneHandler,
253
 			minParams: 2,
253
 			minParams: 2,
254
 		},
254
 		},
255
+		"SETNAME": {
256
+			handler:   setnameHandler,
257
+			minParams: 1,
258
+		},
255
 		"TAGMSG": {
259
 		"TAGMSG": {
256
 			handler:   tagmsgHandler,
260
 			handler:   tagmsgHandler,
257
 			minParams: 1,
261
 			minParams: 1,

+ 21
- 0
irc/handlers.go ファイルの表示

2310
 	return false
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
 // TAGMSG <target>{,<target>}
2334
 // TAGMSG <target>{,<target>}
2314
 func tagmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
2335
 func tagmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
2315
 	clientOnlyTags := utils.GetClientOnlyTags(msg.Tags)
2336
 	clientOnlyTags := utils.GetClientOnlyTags(msg.Tags)

+ 5
- 0
irc/help.go ファイルの表示

434
 		text: `SCENE <target> <text to be sent>
434
 		text: `SCENE <target> <text to be sent>
435
 
435
 
436
 The SCENE command is used to send a scene notification to the given target.`,
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
 	"tagmsg": {
443
 	"tagmsg": {
439
 		text: `@+client-only-tags TAGMSG <target>{,<target>}
444
 		text: `@+client-only-tags TAGMSG <target>{,<target>}

+ 1
- 1
irc/server.go ファイルの表示

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

読み込み中…
キャンセル
保存