Browse Source

modes: Add TLS umode (+Z)

tags/v0.1.0
Daniel Oaks 8 years ago
parent
commit
b820559050
4 changed files with 30 additions and 8 deletions
  1. 1
    0
      CHANGELOG.md
  2. 4
    1
      irc/client.go
  3. 5
    2
      irc/modes.go
  4. 20
    5
      irc/server.go

+ 1
- 0
CHANGELOG.md View File

@@ -18,6 +18,7 @@ Initial release of Oragono!
18 18
 * Added ability to generate certificates from the command line.
19 19
 * We now advertise the [`RPL_ISUPPORT`](http://modern.ircdocs.horse/#rplisupport-005) numeric.
20 20
 * Parse new mode change syntax commonly used these days (i.e. `+h-ov dan dan dan`).
21
+* User mode for clients connected via TLS (`+Z`).
21 22
 
22 23
 ### Changed
23 24
 * Added channel Founder/Admin/Halfops (`qah`) privileges, and removed channel creator (`O`) privilege (from RFC2812, not used in the real world).

+ 4
- 1
irc/client.go View File

@@ -44,7 +44,7 @@ type Client struct {
44 44
 	isDestroyed    bool
45 45
 }
46 46
 
47
-func NewClient(server *Server, conn net.Conn) *Client {
47
+func NewClient(server *Server, conn net.Conn, isTLS bool) *Client {
48 48
 	now := time.Now()
49 49
 	socket := NewSocket(conn)
50 50
 	client := &Client{
@@ -59,6 +59,9 @@ func NewClient(server *Server, conn net.Conn) *Client {
59 59
 		socket:       &socket,
60 60
 		nickString:   "*", // * is used until actual nick is given
61 61
 	}
62
+	if isTLS {
63
+		client.flags[TLS] = true
64
+	}
62 65
 	client.Touch()
63 66
 	go client.run()
64 67
 

+ 5
- 2
irc/modes.go View File

@@ -143,6 +143,7 @@ const (
143 143
 	Operator      UserMode = 'o'
144 144
 	Restricted    UserMode = 'r'
145 145
 	ServerNotice  UserMode = 's' // deprecated
146
+	TLS           UserMode = 'Z'
146 147
 	WallOps       UserMode = 'w'
147 148
 )
148 149
 
@@ -292,11 +293,13 @@ func umodeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
292 293
 					applied = append(applied, change)
293 294
 				}
294 295
 			}
296
+
297
+			// can't do anything to TLS mode
295 298
 		}
296 299
 	}
297 300
 
298
-	if len(changes) > 0 {
299
-		client.Send(nil, client.nickMaskString, "MODE", target.nickString, changes.String())
301
+	if len(applied) > 0 {
302
+		client.Send(nil, client.nickMaskString, "MODE", target.nickString, applied.String())
300 303
 	} else if client == target {
301 304
 		client.Send(nil, target.nickMaskString, RPL_UMODEIS, target.nickString, target.ModeString())
302 305
 	}

+ 20
- 5
irc/server.go View File

@@ -33,7 +33,7 @@ type Server struct {
33 33
 	motdLines        []string
34 34
 	name             Name
35 35
 	nameString       string // cache for server name string since it's used with almost every reply
36
-	newConns         chan net.Conn
36
+	newConns         chan clientConn
37 37
 	operators        map[Name][]byte
38 38
 	password         []byte
39 39
 	signals          chan os.Signal
@@ -48,6 +48,11 @@ var (
48 48
 		syscall.SIGTERM, syscall.SIGQUIT}
49 49
 )
50 50
 
51
+type clientConn struct {
52
+	Conn  net.Conn
53
+	IsTLS bool
54
+}
55
+
51 56
 func NewServer(config *Config) *Server {
52 57
 	server := &Server{
53 58
 		channels:         make(ChannelNameMap),
@@ -58,7 +63,7 @@ func NewServer(config *Config) *Server {
58 63
 		idle:             make(chan *Client),
59 64
 		name:             NewName(config.Server.Name),
60 65
 		nameString:       NewName(config.Server.Name).String(),
61
-		newConns:         make(chan net.Conn),
66
+		newConns:         make(chan clientConn),
62 67
 		operators:        config.Operators(),
63 68
 		signals:          make(chan os.Signal, len(SERVER_SIGNALS)),
64 69
 		proxyAllowedFrom: config.Server.ProxyAllowedFrom,
@@ -180,7 +185,7 @@ func (server *Server) Run() {
180 185
 			done = true
181 186
 
182 187
 		case conn := <-server.newConns:
183
-			NewClient(server, conn)
188
+			NewClient(server, conn.Conn, conn.IsTLS)
184 189
 
185 190
 		/*TODO(dan): LOOK AT THIS MORE CLOSELY
186 191
 		case cmd := <-server.commands:
@@ -221,7 +226,12 @@ func (s *Server) listen(addr string, tlsMap map[Name]*tls.Config) {
221 226
 			}
222 227
 			Log.debug.Printf("%s accept: %s", s, conn.RemoteAddr())
223 228
 
224
-			s.newConns <- conn
229
+			newConn := clientConn{
230
+				Conn:  conn,
231
+				IsTLS: listenTLS,
232
+			}
233
+
234
+			s.newConns <- newConn
225 235
 		}
226 236
 	}()
227 237
 }
@@ -250,7 +260,11 @@ func (s *Server) wslisten(addr string, tlsMap map[string]*TLSListenConfig) {
250 260
 			return
251 261
 		}
252 262
 
253
-		s.newConns <- WSContainer{ws}
263
+		newConn := clientConn{
264
+			Conn:  WSContainer{ws},
265
+			IsTLS: false, //TODO(dan): track TLS or not here properly
266
+		}
267
+		s.newConns <- newConn
254 268
 	})
255 269
 	go func() {
256 270
 		config, listenTLS := tlsMap[addr]
@@ -294,6 +308,7 @@ func (s *Server) tryRegister(c *Client) {
294 308
 	c.Send(nil, s.nameString, RPL_MYINFO, c.nickString, s.nameString, SEM_VER, supportedUserModesString, supportedChannelModesString)
295 309
 	c.RplISupport()
296 310
 	s.MOTD(c)
311
+	c.Send(nil, c.nickMaskString, RPL_UMODEIS, c.nickString, c.ModeString())
297 312
 }
298 313
 
299 314
 func (server *Server) MOTD(client *Client) {

Loading…
Cancel
Save