|
@@ -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
|
|
-*/
|