Browse Source

Misc refactoring

tags/v0.11.0-beta
Daniel Oaks 6 years ago
parent
commit
2ecec25d28
9 changed files with 55 additions and 59 deletions
  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 View File

@@ -1,31 +0,0 @@
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 View File

@@ -63,3 +63,15 @@ const (
63 63
 	// Cap302 refers to the IRCv3.2 CAP spec.
64 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 View File

@@ -67,16 +67,19 @@ type RegisteredChannel struct {
67 67
 	Invitelist []string
68 68
 }
69 69
 
70
+// ChannelRegistry manages registered channels.
70 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 73
 	// this is enough to guarantee eventual consistency of the database with the
73 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 77
 	// that with all the other modules, so let's not.
76 78
 	sync.Mutex // tier 2
77 79
 	server     *Server
78 80
 }
79 81
 
82
+// NewChannelRegistry returns a new ChannelRegistry.
80 83
 func NewChannelRegistry(server *Server) *ChannelRegistry {
81 84
 	return &ChannelRegistry{
82 85
 		server: server,

+ 7
- 5
irc/chanserv.go View File

@@ -12,16 +12,18 @@ import (
12 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 15
 // ChanServNotice sends the client a notice from ChanServ.
20 16
 func (client *Client) ChanServNotice(text string) {
21 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 27
 	var params []string
26 28
 	for _, p := range strings.Split(message, " ") {
27 29
 		if len(p) > 0 {

+ 2
- 2
irc/client.go View File

@@ -44,7 +44,7 @@ type Client struct {
44 44
 	authorized         bool
45 45
 	awayMessage        string
46 46
 	capabilities       *caps.Set
47
-	capState           CapState
47
+	capState           caps.State
48 48
 	capVersion         caps.Version
49 49
 	certfp             string
50 50
 	channels           ChannelSet
@@ -92,7 +92,7 @@ func NewClient(server *Server, conn net.Conn, isTLS bool) *Client {
92 92
 		atime:          now,
93 93
 		authorized:     server.Password() == nil,
94 94
 		capabilities:   caps.NewSet(),
95
-		capState:       CapNone,
95
+		capState:       caps.NoneState,
96 96
 		capVersion:     caps.Cap301,
97 97
 		channels:       make(ChannelSet),
98 98
 		ctime:          now,

+ 12
- 12
irc/handlers.go View File

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

+ 7
- 5
irc/nickserv.go View File

@@ -27,10 +27,6 @@ To login to an account:
27 27
 Leave out [username password] to use your client certificate fingerprint. Otherwise,
28 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 30
 // extractParam extracts a parameter from the given string, returning the param and the rest of the string.
35 31
 func extractParam(line string) (string, string) {
36 32
 	rawParams := strings.SplitN(strings.TrimSpace(line), " ", 2)
@@ -42,7 +38,13 @@ func extractParam(line string) (string, string) {
42 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 48
 	command, params := extractParam(message)
47 49
 	command = strings.ToLower(command)
48 50
 

+ 9
- 1
irc/server.go View File

@@ -49,6 +49,14 @@ var (
49 49
 	supportedUserModesString = modes.SupportedUserModes.String()
50 50
 	// supportedChannelModesString acts as a cache for when we introduce users
51 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 62
 // Limits holds the maximum limits for various things such as topic lengths.
@@ -422,7 +430,7 @@ func (server *Server) generateMessageID() string {
422 430
 
423 431
 func (server *Server) tryRegister(c *Client) {
424 432
 	if c.registered || !c.HasNick() || !c.HasUsername() ||
425
-		(c.capState == CapNegotiating) {
433
+		(c.capState == caps.NegotiatingState) {
426 434
 		return
427 435
 	}
428 436
 

irc/message_tags.go → irc/utils/message_tags.go View File

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

Loading…
Cancel
Save