Browse Source

nickname: Fix

tags/v0.1.0
Daniel Oaks 8 years ago
parent
commit
b8dc10f92d
4 changed files with 56 additions and 89 deletions
  1. 1
    0
      CHANGELOG.md
  2. 11
    4
      irc/commands.go
  3. 44
    80
      irc/nickname.go
  4. 0
    5
      irc/server.go

+ 1
- 0
CHANGELOG.md View File

@@ -24,6 +24,7 @@ Initial release of Oragono!
24 24
 * Added secret (`+s`) channel mode to replace private (`+p`) for hiding channels, since everything else uses `+s` over `+p` these days.
25 25
 * Default channel modes are now (`+nt`), matching most other IRCds.
26 26
 * CLI argument names made more consistent with typical software.
27
+* ONICK: Renamed to SANICK to be more consistent with other IRCds.
27 28
 
28 29
 ### Removed
29 30
 * Gitconfig config format completely removed and replaced with YAML.

+ 11
- 4
irc/commands.go View File

@@ -10,6 +10,7 @@ import "github.com/DanielOaks/girc-go/ircmsg"
10 10
 // Command represents a command accepted from a client.
11 11
 type Command struct {
12 12
 	handler           func(server *Server, client *Client, msg ircmsg.IrcMessage) bool
13
+	oper              bool
13 14
 	usablePreReg      bool
14 15
 	leaveClientActive bool // if true, leaves the client active time alone. reversed because we can't default a struct element to True
15 16
 	leaveClientIdle   bool
@@ -22,6 +23,10 @@ func (cmd *Command) Run(server *Server, client *Client, msg ircmsg.IrcMessage) b
22 23
 		// command silently ignored
23 24
 		return false
24 25
 	}
26
+	if (!cmd.oper) && (!client.flags[Operator]) {
27
+		client.Send(nil, server.nameString, ERR_NOPRIVILEGES, client.nickString, "Permission Denied - You're not an IRC operator")
28
+		return false
29
+	}
25 30
 	if len(msg.Params) < cmd.minParams {
26 31
 		client.Send(nil, server.nameString, ERR_NEEDMOREPARAMS, client.nickString, msg.Command, "Not enough parameters")
27 32
 		return false
@@ -76,6 +81,7 @@ var Commands = map[string]Command{
76 81
 	"KILL": Command{
77 82
 		handler:   killHandler,
78 83
 		minParams: 2,
84
+		oper:      true,
79 85
 	},
80 86
 	"LIST": Command{
81 87
 		handler:   listHandler,
@@ -103,10 +109,6 @@ var Commands = map[string]Command{
103 109
 		handler:   noticeHandler,
104 110
 		minParams: 2,
105 111
 	},
106
-	"ONICK": Command{
107
-		handler:   onickHandler,
108
-		minParams: 2,
109
-	},
110 112
 	"OPER": Command{
111 113
 		handler:   operHandler,
112 114
 		minParams: 2,
@@ -141,6 +143,11 @@ var Commands = map[string]Command{
141 143
 		usablePreReg: true,
142 144
 		minParams:    5,
143 145
 	},
146
+	"SANICK": Command{
147
+		handler:   sanickHandler,
148
+		minParams: 2,
149
+		oper:      true,
150
+	},
144 151
 	"QUIT": Command{
145 152
 		handler:      quitHandler,
146 153
 		usablePreReg: true,

+ 44
- 80
irc/nickname.go View File

@@ -8,111 +8,75 @@ import "github.com/DanielOaks/girc-go/ircmsg"
8 8
 
9 9
 // NICK <nickname>
10 10
 func nickHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
11
-	// check NICK validity
12
-	// send NICK change to primary server thread for processing
13
-	//   |-> ensure no other client exists with that nickname
14
-
15
-	// do this after replacing nickname
16
-	client.updateNickMask()
17
-	return true
18
-}
19
-
20
-/*
21
-type NickCommand struct {
22
-	BaseCommand
23
-	nickname Name
24
-}
25
-
26
-func (m *NickCommand) HandleRegServer(s *Server) {
27
-	client := m.Client()
28 11
 	if !client.authorized {
29
-		client.ErrPasswdMismatch()
30
-		client.Quit("bad password")
31
-		return
32
-	}
33
-	//TODO(dan): SET client.nickString APPROPRIATELY
34
-
35
-	if m.nickname == "" {
36
-		client.ErrNoNicknameGiven()
37
-		return
38
-	}
39
-
40
-	if s.clients.Get(m.nickname) != nil {
41
-		client.ErrNickNameInUse(m.nickname)
42
-		return
43
-	}
44
-
45
-	if !m.nickname.IsNickname() {
46
-		client.ErrErroneusNickname(m.nickname)
47
-		return
12
+		client.Quit("Bad password")
13
+		return true
48 14
 	}
49 15
 
50
-	client.SetNickname(m.nickname)
51
-	s.tryRegister(client)
52
-}
53
-
54
-func (msg *NickCommand) HandleServer(server *Server) {
55
-	client := msg.Client()
56
-	//TODO(dan): SET client.nickString APPROPRIATELY
16
+	nickname := NewName(msg.Params[0])
57 17
 
58
-	if msg.nickname == "" {
59
-		client.ErrNoNicknameGiven()
60
-		return
18
+	if len(nickname) < 1 {
19
+		client.Send(nil, server.nameString, ERR_NONICKNAMEGIVEN, client.nickString, "No nickname given")
20
+		return false
61 21
 	}
62 22
 
63
-	if !msg.nickname.IsNickname() {
64
-		client.ErrErroneusNickname(msg.nickname)
65
-		return
23
+	if !nickname.IsNickname() {
24
+		client.Send(nil, server.nameString, ERR_ERRONEUSNICKNAME, client.nickString, msg.Params[0], "Erroneous nickname")
25
+		return false
66 26
 	}
67 27
 
68
-	if msg.nickname == client.nick {
69
-		return
28
+	if client.nick == nickname {
29
+		return false
70 30
 	}
71 31
 
72
-	target := server.clients.Get(msg.nickname)
73
-	if (target != nil) && (target != client) {
74
-		client.ErrNickNameInUse(msg.nickname)
75
-		return
32
+	//TODO(dan): There's probably some races here, we should be changing this in the primary server thread
33
+	target := server.clients.Get(nickname)
34
+	if target != nil && target != client {
35
+		client.Send(nil, server.nameString, ERR_NICKNAMEINUSE, client.nickString, msg.Params[0], "Nickname is already in use")
36
+		return false
76 37
 	}
77 38
 
78
-	client.ChangeNickname(msg.nickname)
39
+	client.SetNickname(nickname)
40
+	server.tryRegister(client)
41
+	return false
79 42
 }
80 43
 
81
-type OperNickCommand struct {
82
-	BaseCommand
83
-	target Name
84
-	nick   Name
85
-}
44
+// SANICK <oldnick> <nickname>
45
+func sanickHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
46
+	if !client.authorized {
47
+		client.Quit("Bad password")
48
+		return true
49
+	}
86 50
 
87
-func (msg *OperNickCommand) HandleServer(server *Server) {
88
-	client := msg.Client()
89
-	//TODO(dan): SET client.nickString APPROPRIATELY
51
+	oldnick := NewName(msg.Params[0])
52
+	nickname := NewName(msg.Params[1])
90 53
 
91
-	if !client.flags[Operator] {
92
-		client.ErrNoPrivileges()
93
-		return
54
+	if len(nickname) < 1 {
55
+		client.Send(nil, server.nameString, ERR_NONICKNAMEGIVEN, client.nickString, "No nickname given")
56
+		return false
94 57
 	}
95 58
 
96
-	if !msg.nick.IsNickname() {
97
-		client.ErrErroneusNickname(msg.nick)
98
-		return
59
+	if !nickname.IsNickname() {
60
+		client.Send(nil, server.nameString, ERR_ERRONEUSNICKNAME, client.nickString, msg.Params[0], "Erroneous nickname")
61
+		return false
99 62
 	}
100 63
 
101
-	if msg.nick == client.nick {
102
-		return
64
+	if client.nick == nickname {
65
+		return false
103 66
 	}
104 67
 
105
-	target := server.clients.Get(msg.target)
68
+	target := server.clients.Get(oldnick)
106 69
 	if target == nil {
107
-		client.ErrNoSuchNick(msg.target)
108
-		return
70
+		client.Send(nil, server.nameString, ERR_NOSUCHNICK, msg.Params[0], "No such nick")
71
+		return false
109 72
 	}
110 73
 
111
-	if server.clients.Get(msg.nick) != nil {
112
-		client.ErrNickNameInUse(msg.nick)
113
-		return
74
+	//TODO(dan): There's probably some races here, we should be changing this in the primary server thread
75
+	if server.clients.Get(nickname) != nil {
76
+		client.Send(nil, server.nameString, ERR_NICKNAMEINUSE, client.nickString, msg.Params[0], "Nickname is already in use")
77
+		return false
114 78
 	}
115 79
 
116
-	target.ChangeNickname(msg.nick)
80
+	target.SetNickname(nickname)
81
+	return false
117 82
 }
118
-*/

+ 0
- 5
irc/server.go View File

@@ -982,11 +982,6 @@ func killHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
982 982
 	nickname := msg.Params[0]
983 983
 	comment := msg.Params[1]
984 984
 
985
-	if !client.flags[Operator] {
986
-		client.Send(nil, server.nameString, ERR_NOPRIVILEGES, client.nickString, "Permission Denied - You're not an IRC operator")
987
-		return false
988
-	}
989
-
990 985
 	target := server.clients.Get(Name(nickname))
991 986
 	if target == nil {
992 987
 		client.Send(nil, client.server.nameString, ERR_NOSUCHNICK, nickname, "No such nick")

Loading…
Cancel
Save