瀏覽代碼

Misc refactoring

tags/v0.11.0-beta
Daniel Oaks 6 年之前
父節點
當前提交
2ecec25d28
共有 9 個檔案被更改,包括 55 行新增59 行删除
  1. 0
    31
      irc/capability.go
  2. 12
    0
      irc/caps/constants.go
  3. 5
    2
      irc/channelreg.go
  4. 7
    5
      irc/chanserv.go
  5. 2
    2
      irc/client.go
  6. 12
    12
      irc/handlers.go
  7. 7
    5
      irc/nickserv.go
  8. 9
    1
      irc/server.go
  9. 1
    1
      irc/utils/message_tags.go

+ 0
- 31
irc/capability.go 查看文件

1
-// Copyright (c) 2012-2014 Jeremy Latt
2
-// Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
3
-// released under the MIT license
4
-
5
-package irc
6
-
7
-import (
8
-	"github.com/oragono/oragono/irc/caps"
9
-)
10
-
11
-var (
12
-	// SupportedCapabilities are the caps we advertise.
13
-	// MaxLine, SASL and STS are set during server startup.
14
-	SupportedCapabilities = caps.NewSet(caps.AccountTag, caps.AccountNotify, caps.AwayNotify, caps.CapNotify, caps.ChgHost, caps.EchoMessage, caps.ExtendedJoin, caps.InviteNotify, caps.Languages, caps.MessageTags, caps.MultiPrefix, caps.Rename, caps.Resume, caps.ServerTime, caps.UserhostInNames)
15
-
16
-	// CapValues are the actual values we advertise to v3.2 clients.
17
-	// actual values are set during server startup.
18
-	CapValues = caps.NewValues()
19
-)
20
-
21
-// CapState shows whether we're negotiating caps, finished, etc for connection registration.
22
-type CapState uint
23
-
24
-const (
25
-	// CapNone means CAP hasn't been negotiated at all.
26
-	CapNone CapState = iota
27
-	// CapNegotiating means CAP is being negotiated and registration should be paused.
28
-	CapNegotiating CapState = iota
29
-	// CapNegotiated means CAP negotiation has been successfully ended and reg should complete.
30
-	CapNegotiated CapState = iota
31
-)

+ 12
- 0
irc/caps/constants.go 查看文件

63
 	// Cap302 refers to the IRCv3.2 CAP spec.
63
 	// Cap302 refers to the IRCv3.2 CAP spec.
64
 	Cap302 Version = 302
64
 	Cap302 Version = 302
65
 )
65
 )
66
+
67
+// State shows whether we're negotiating caps, finished, etc for connection registration.
68
+type State uint
69
+
70
+const (
71
+	// NoneState means CAP hasn't been negotiated at all.
72
+	NoneState State = iota
73
+	// NegotiatingState means CAP is being negotiated and registration should be paused.
74
+	NegotiatingState State = iota
75
+	// NegotiatedState means CAP negotiation has been successfully ended and reg should complete.
76
+	NegotiatedState State = iota
77
+)

+ 5
- 2
irc/channelreg.go 查看文件

67
 	Invitelist []string
67
 	Invitelist []string
68
 }
68
 }
69
 
69
 
70
+// ChannelRegistry manages registered channels.
70
 type ChannelRegistry struct {
71
 type ChannelRegistry struct {
71
-	// this serializes operations of the form (read channel state, synchronously persist it);
72
+	// This serializes operations of the form (read channel state, synchronously persist it);
72
 	// this is enough to guarantee eventual consistency of the database with the
73
 	// this is enough to guarantee eventual consistency of the database with the
73
 	// ChannelManager and Channel objects, which are the source of truth.
74
 	// ChannelManager and Channel objects, which are the source of truth.
74
-	// Wwe could use the buntdb RW transaction lock for this purpose but we share
75
+	//
76
+	// We could use the buntdb RW transaction lock for this purpose but we share
75
 	// that with all the other modules, so let's not.
77
 	// that with all the other modules, so let's not.
76
 	sync.Mutex // tier 2
78
 	sync.Mutex // tier 2
77
 	server     *Server
79
 	server     *Server
78
 }
80
 }
79
 
81
 
82
+// NewChannelRegistry returns a new ChannelRegistry.
80
 func NewChannelRegistry(server *Server) *ChannelRegistry {
83
 func NewChannelRegistry(server *Server) *ChannelRegistry {
81
 	return &ChannelRegistry{
84
 	return &ChannelRegistry{
82
 		server: server,
85
 		server: server,

+ 7
- 5
irc/chanserv.go 查看文件

12
 	"github.com/oragono/oragono/irc/sno"
12
 	"github.com/oragono/oragono/irc/sno"
13
 )
13
 )
14
 
14
 
15
-func (server *Server) chanservReceiveNotice(client *Client, message string) {
16
-	// do nothing
17
-}
18
-
19
 // ChanServNotice sends the client a notice from ChanServ.
15
 // ChanServNotice sends the client a notice from ChanServ.
20
 func (client *Client) ChanServNotice(text string) {
16
 func (client *Client) ChanServNotice(text string) {
21
 	client.Send(nil, fmt.Sprintf("ChanServ!services@%s", client.server.name), "NOTICE", client.nick, text)
17
 	client.Send(nil, fmt.Sprintf("ChanServ!services@%s", client.server.name), "NOTICE", client.nick, text)
22
 }
18
 }
23
 
19
 
24
-func (server *Server) chanservReceivePrivmsg(client *Client, message string) {
20
+// chanservReceiveNotice handles NOTICEs that ChanServ receives.
21
+func (server *Server) chanservNoticeHandler(client *Client, message string) {
22
+	// do nothing
23
+}
24
+
25
+// chanservReceiveNotice handles NOTICEs that ChanServ receives.
26
+func (server *Server) chanservPrivmsgHandler(client *Client, message string) {
25
 	var params []string
27
 	var params []string
26
 	for _, p := range strings.Split(message, " ") {
28
 	for _, p := range strings.Split(message, " ") {
27
 		if len(p) > 0 {
29
 		if len(p) > 0 {

+ 2
- 2
irc/client.go 查看文件

44
 	authorized         bool
44
 	authorized         bool
45
 	awayMessage        string
45
 	awayMessage        string
46
 	capabilities       *caps.Set
46
 	capabilities       *caps.Set
47
-	capState           CapState
47
+	capState           caps.State
48
 	capVersion         caps.Version
48
 	capVersion         caps.Version
49
 	certfp             string
49
 	certfp             string
50
 	channels           ChannelSet
50
 	channels           ChannelSet
92
 		atime:          now,
92
 		atime:          now,
93
 		authorized:     server.Password() == nil,
93
 		authorized:     server.Password() == nil,
94
 		capabilities:   caps.NewSet(),
94
 		capabilities:   caps.NewSet(),
95
-		capState:       CapNone,
95
+		capState:       caps.NoneState,
96
 		capVersion:     caps.Cap301,
96
 		capVersion:     caps.Cap301,
97
 		channels:       make(ChannelSet),
97
 		channels:       make(ChannelSet),
98
 		ctime:          now,
98
 		ctime:          now,

+ 12
- 12
irc/handlers.go 查看文件

533
 	switch subCommand {
533
 	switch subCommand {
534
 	case "LS":
534
 	case "LS":
535
 		if !client.registered {
535
 		if !client.registered {
536
-			client.capState = CapNegotiating
536
+			client.capState = caps.NegotiatingState
537
 		}
537
 		}
538
 		if len(msg.Params) > 1 && msg.Params[1] == "302" {
538
 		if len(msg.Params) > 1 && msg.Params[1] == "302" {
539
 			client.capVersion = 302
539
 			client.capVersion = 302
549
 
549
 
550
 	case "REQ":
550
 	case "REQ":
551
 		if !client.registered {
551
 		if !client.registered {
552
-			client.capState = CapNegotiating
552
+			client.capState = caps.NegotiatingState
553
 		}
553
 		}
554
 
554
 
555
 		// make sure all capabilities actually exist
555
 		// make sure all capabilities actually exist
564
 
564
 
565
 	case "END":
565
 	case "END":
566
 		if !client.registered {
566
 		if !client.registered {
567
-			client.capState = CapNegotiated
567
+			client.capState = caps.NegotiatedState
568
 			server.tryRegister(client)
568
 			server.tryRegister(client)
569
 		}
569
 		}
570
 
570
 
576
 
576
 
577
 // csHandler handles the /CS and /CHANSERV commands
577
 // csHandler handles the /CS and /CHANSERV commands
578
 func csHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
578
 func csHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
579
-	server.chanservReceivePrivmsg(client, strings.Join(msg.Params, " "))
579
+	server.chanservPrivmsgHandler(client, strings.Join(msg.Params, " "))
580
 	return false
580
 	return false
581
 }
581
 }
582
 
582
 
1676
 
1676
 
1677
 // NOTICE <target>{,<target>} <message>
1677
 // NOTICE <target>{,<target>} <message>
1678
 func noticeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
1678
 func noticeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
1679
-	clientOnlyTags := GetClientOnlyTags(msg.Tags)
1679
+	clientOnlyTags := utils.GetClientOnlyTags(msg.Tags)
1680
 	targets := strings.Split(msg.Params[0], ",")
1680
 	targets := strings.Split(msg.Params[0], ",")
1681
 	message := msg.Params[1]
1681
 	message := msg.Params[1]
1682
 
1682
 
1710
 				continue
1710
 				continue
1711
 			}
1711
 			}
1712
 			if target == "chanserv" {
1712
 			if target == "chanserv" {
1713
-				server.chanservReceiveNotice(client, message)
1713
+				server.chanservNoticeHandler(client, message)
1714
 				continue
1714
 				continue
1715
 			} else if target == "nickserv" {
1715
 			} else if target == "nickserv" {
1716
-				server.nickservReceiveNotice(client, message)
1716
+				server.nickservNoticeHandler(client, message)
1717
 				continue
1717
 				continue
1718
 			}
1718
 			}
1719
 
1719
 
1778
 
1778
 
1779
 // nsHandler handles the /NS and /NICKSERV commands
1779
 // nsHandler handles the /NS and /NICKSERV commands
1780
 func nsHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
1780
 func nsHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
1781
-	server.nickservReceivePrivmsg(client, strings.Join(msg.Params, " "))
1781
+	server.nickservPrivmsgHandler(client, strings.Join(msg.Params, " "))
1782
 	return false
1782
 	return false
1783
 }
1783
 }
1784
 
1784
 
1901
 
1901
 
1902
 // PRIVMSG <target>{,<target>} <message>
1902
 // PRIVMSG <target>{,<target>} <message>
1903
 func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
1903
 func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
1904
-	clientOnlyTags := GetClientOnlyTags(msg.Tags)
1904
+	clientOnlyTags := utils.GetClientOnlyTags(msg.Tags)
1905
 	targets := strings.Split(msg.Params[0], ",")
1905
 	targets := strings.Split(msg.Params[0], ",")
1906
 	message := msg.Params[1]
1906
 	message := msg.Params[1]
1907
 
1907
 
1937
 		} else {
1937
 		} else {
1938
 			target, err = CasefoldName(targetString)
1938
 			target, err = CasefoldName(targetString)
1939
 			if target == "chanserv" {
1939
 			if target == "chanserv" {
1940
-				server.chanservReceivePrivmsg(client, message)
1940
+				server.chanservPrivmsgHandler(client, message)
1941
 				continue
1941
 				continue
1942
 			} else if target == "nickserv" {
1942
 			} else if target == "nickserv" {
1943
-				server.nickservReceivePrivmsg(client, message)
1943
+				server.nickservPrivmsgHandler(client, message)
1944
 				continue
1944
 				continue
1945
 			}
1945
 			}
1946
 			user := server.clients.Get(target)
1946
 			user := server.clients.Get(target)
2159
 
2159
 
2160
 // TAGMSG <target>{,<target>}
2160
 // TAGMSG <target>{,<target>}
2161
 func tagmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
2161
 func tagmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
2162
-	clientOnlyTags := GetClientOnlyTags(msg.Tags)
2162
+	clientOnlyTags := utils.GetClientOnlyTags(msg.Tags)
2163
 	// no client-only tags, so we can drop it
2163
 	// no client-only tags, so we can drop it
2164
 	if clientOnlyTags == nil {
2164
 	if clientOnlyTags == nil {
2165
 		return false
2165
 		return false

+ 7
- 5
irc/nickserv.go 查看文件

27
 Leave out [username password] to use your client certificate fingerprint. Otherwise,
27
 Leave out [username password] to use your client certificate fingerprint. Otherwise,
28
 the given username and password will be used.`
28
 the given username and password will be used.`
29
 
29
 
30
-func (server *Server) nickservReceiveNotice(client *Client, message string) {
31
-	// do nothing
32
-}
33
-
34
 // extractParam extracts a parameter from the given string, returning the param and the rest of the string.
30
 // extractParam extracts a parameter from the given string, returning the param and the rest of the string.
35
 func extractParam(line string) (string, string) {
31
 func extractParam(line string) (string, string) {
36
 	rawParams := strings.SplitN(strings.TrimSpace(line), " ", 2)
32
 	rawParams := strings.SplitN(strings.TrimSpace(line), " ", 2)
42
 	return param0, param1
38
 	return param0, param1
43
 }
39
 }
44
 
40
 
45
-func (server *Server) nickservReceivePrivmsg(client *Client, message string) {
41
+// nickservNoticeHandler handles NOTICEs that NickServ receives.
42
+func (server *Server) nickservNoticeHandler(client *Client, message string) {
43
+	// do nothing
44
+}
45
+
46
+// nickservPrivmsgHandler handles PRIVMSGs that NickServ receives.
47
+func (server *Server) nickservPrivmsgHandler(client *Client, message string) {
46
 	command, params := extractParam(message)
48
 	command, params := extractParam(message)
47
 	command = strings.ToLower(command)
49
 	command = strings.ToLower(command)
48
 
50
 

+ 9
- 1
irc/server.go 查看文件

49
 	supportedUserModesString = modes.SupportedUserModes.String()
49
 	supportedUserModesString = modes.SupportedUserModes.String()
50
 	// supportedChannelModesString acts as a cache for when we introduce users
50
 	// supportedChannelModesString acts as a cache for when we introduce users
51
 	supportedChannelModesString = modes.SupportedChannelModes.String()
51
 	supportedChannelModesString = modes.SupportedChannelModes.String()
52
+
53
+	// SupportedCapabilities are the caps we advertise.
54
+	// MaxLine, SASL and STS are set during server startup.
55
+	SupportedCapabilities = caps.NewSet(caps.AccountTag, caps.AccountNotify, caps.AwayNotify, caps.CapNotify, caps.ChgHost, caps.EchoMessage, caps.ExtendedJoin, caps.InviteNotify, caps.Languages, caps.MessageTags, caps.MultiPrefix, caps.Rename, caps.Resume, caps.ServerTime, caps.UserhostInNames)
56
+
57
+	// CapValues are the actual values we advertise to v3.2 clients.
58
+	// actual values are set during server startup.
59
+	CapValues = caps.NewValues()
52
 )
60
 )
53
 
61
 
54
 // Limits holds the maximum limits for various things such as topic lengths.
62
 // Limits holds the maximum limits for various things such as topic lengths.
422
 
430
 
423
 func (server *Server) tryRegister(c *Client) {
431
 func (server *Server) tryRegister(c *Client) {
424
 	if c.registered || !c.HasNick() || !c.HasUsername() ||
432
 	if c.registered || !c.HasNick() || !c.HasUsername() ||
425
-		(c.capState == CapNegotiating) {
433
+		(c.capState == caps.NegotiatingState) {
426
 		return
434
 		return
427
 	}
435
 	}
428
 
436
 

irc/message_tags.go → irc/utils/message_tags.go 查看文件

1
 // Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
1
 // Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
2
 // released under the MIT license
2
 // released under the MIT license
3
 
3
 
4
-package irc
4
+package utils
5
 
5
 
6
 import "github.com/goshuirc/irc-go/ircmsg"
6
 import "github.com/goshuirc/irc-go/ircmsg"
7
 
7
 

Loading…
取消
儲存