3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

nickname: Fix

This commit is contained in:
Daniel Oaks 2016-06-20 10:04:53 +10:00
parent 9e7a590f23
commit b8dc10f92d
4 changed files with 61 additions and 94 deletions

View File

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

View File

@ -10,6 +10,7 @@ import "github.com/DanielOaks/girc-go/ircmsg"
// Command represents a command accepted from a client. // Command represents a command accepted from a client.
type Command struct { type Command struct {
handler func(server *Server, client *Client, msg ircmsg.IrcMessage) bool handler func(server *Server, client *Client, msg ircmsg.IrcMessage) bool
oper bool
usablePreReg bool usablePreReg bool
leaveClientActive bool // if true, leaves the client active time alone. reversed because we can't default a struct element to True leaveClientActive bool // if true, leaves the client active time alone. reversed because we can't default a struct element to True
leaveClientIdle bool leaveClientIdle bool
@ -22,6 +23,10 @@ func (cmd *Command) Run(server *Server, client *Client, msg ircmsg.IrcMessage) b
// command silently ignored // command silently ignored
return false return false
} }
if (!cmd.oper) && (!client.flags[Operator]) {
client.Send(nil, server.nameString, ERR_NOPRIVILEGES, client.nickString, "Permission Denied - You're not an IRC operator")
return false
}
if len(msg.Params) < cmd.minParams { if len(msg.Params) < cmd.minParams {
client.Send(nil, server.nameString, ERR_NEEDMOREPARAMS, client.nickString, msg.Command, "Not enough parameters") client.Send(nil, server.nameString, ERR_NEEDMOREPARAMS, client.nickString, msg.Command, "Not enough parameters")
return false return false
@ -76,6 +81,7 @@ var Commands = map[string]Command{
"KILL": Command{ "KILL": Command{
handler: killHandler, handler: killHandler,
minParams: 2, minParams: 2,
oper: true,
}, },
"LIST": Command{ "LIST": Command{
handler: listHandler, handler: listHandler,
@ -103,10 +109,6 @@ var Commands = map[string]Command{
handler: noticeHandler, handler: noticeHandler,
minParams: 2, minParams: 2,
}, },
"ONICK": Command{
handler: onickHandler,
minParams: 2,
},
"OPER": Command{ "OPER": Command{
handler: operHandler, handler: operHandler,
minParams: 2, minParams: 2,
@ -141,6 +143,11 @@ var Commands = map[string]Command{
usablePreReg: true, usablePreReg: true,
minParams: 5, minParams: 5,
}, },
"SANICK": Command{
handler: sanickHandler,
minParams: 2,
oper: true,
},
"QUIT": Command{ "QUIT": Command{
handler: quitHandler, handler: quitHandler,
usablePreReg: true, usablePreReg: true,

View File

@ -8,111 +8,75 @@ import "github.com/DanielOaks/girc-go/ircmsg"
// NICK <nickname> // NICK <nickname>
func nickHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { func nickHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
// check NICK validity
// send NICK change to primary server thread for processing
// |-> ensure no other client exists with that nickname
// do this after replacing nickname
client.updateNickMask()
return true
}
/*
type NickCommand struct {
BaseCommand
nickname Name
}
func (m *NickCommand) HandleRegServer(s *Server) {
client := m.Client()
if !client.authorized { if !client.authorized {
client.ErrPasswdMismatch() client.Quit("Bad password")
client.Quit("bad password") return true
return
}
//TODO(dan): SET client.nickString APPROPRIATELY
if m.nickname == "" {
client.ErrNoNicknameGiven()
return
} }
if s.clients.Get(m.nickname) != nil { nickname := NewName(msg.Params[0])
client.ErrNickNameInUse(m.nickname)
return if len(nickname) < 1 {
client.Send(nil, server.nameString, ERR_NONICKNAMEGIVEN, client.nickString, "No nickname given")
return false
} }
if !m.nickname.IsNickname() { if !nickname.IsNickname() {
client.ErrErroneusNickname(m.nickname) client.Send(nil, server.nameString, ERR_ERRONEUSNICKNAME, client.nickString, msg.Params[0], "Erroneous nickname")
return return false
} }
client.SetNickname(m.nickname) if client.nick == nickname {
s.tryRegister(client) return false
}
//TODO(dan): There's probably some races here, we should be changing this in the primary server thread
target := server.clients.Get(nickname)
if target != nil && target != client {
client.Send(nil, server.nameString, ERR_NICKNAMEINUSE, client.nickString, msg.Params[0], "Nickname is already in use")
return false
}
client.SetNickname(nickname)
server.tryRegister(client)
return false
} }
func (msg *NickCommand) HandleServer(server *Server) { // SANICK <oldnick> <nickname>
client := msg.Client() func sanickHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
//TODO(dan): SET client.nickString APPROPRIATELY if !client.authorized {
client.Quit("Bad password")
if msg.nickname == "" { return true
client.ErrNoNicknameGiven()
return
} }
if !msg.nickname.IsNickname() { oldnick := NewName(msg.Params[0])
client.ErrErroneusNickname(msg.nickname) nickname := NewName(msg.Params[1])
return
if len(nickname) < 1 {
client.Send(nil, server.nameString, ERR_NONICKNAMEGIVEN, client.nickString, "No nickname given")
return false
} }
if msg.nickname == client.nick { if !nickname.IsNickname() {
return client.Send(nil, server.nameString, ERR_ERRONEUSNICKNAME, client.nickString, msg.Params[0], "Erroneous nickname")
return false
} }
target := server.clients.Get(msg.nickname) if client.nick == nickname {
if (target != nil) && (target != client) { return false
client.ErrNickNameInUse(msg.nickname)
return
} }
client.ChangeNickname(msg.nickname) target := server.clients.Get(oldnick)
}
type OperNickCommand struct {
BaseCommand
target Name
nick Name
}
func (msg *OperNickCommand) HandleServer(server *Server) {
client := msg.Client()
//TODO(dan): SET client.nickString APPROPRIATELY
if !client.flags[Operator] {
client.ErrNoPrivileges()
return
}
if !msg.nick.IsNickname() {
client.ErrErroneusNickname(msg.nick)
return
}
if msg.nick == client.nick {
return
}
target := server.clients.Get(msg.target)
if target == nil { if target == nil {
client.ErrNoSuchNick(msg.target) client.Send(nil, server.nameString, ERR_NOSUCHNICK, msg.Params[0], "No such nick")
return return false
} }
if server.clients.Get(msg.nick) != nil { //TODO(dan): There's probably some races here, we should be changing this in the primary server thread
client.ErrNickNameInUse(msg.nick) if server.clients.Get(nickname) != nil {
return client.Send(nil, server.nameString, ERR_NICKNAMEINUSE, client.nickString, msg.Params[0], "Nickname is already in use")
return false
} }
target.ChangeNickname(msg.nick) target.SetNickname(nickname)
return false
} }
*/

View File

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