mirror of
https://github.com/ergochat/ergo.git
synced 2025-01-03 08:32:43 +01:00
nickname: Fix
This commit is contained in:
parent
9e7a590f23
commit
b8dc10f92d
@ -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.
|
||||
* Default channel modes are now (`+nt`), matching most other IRCds.
|
||||
* CLI argument names made more consistent with typical software.
|
||||
* ONICK: Renamed to SANICK to be more consistent with other IRCds.
|
||||
|
||||
### Removed
|
||||
* Gitconfig config format completely removed and replaced with YAML.
|
||||
|
@ -10,6 +10,7 @@ import "github.com/DanielOaks/girc-go/ircmsg"
|
||||
// Command represents a command accepted from a client.
|
||||
type Command struct {
|
||||
handler func(server *Server, client *Client, msg ircmsg.IrcMessage) bool
|
||||
oper bool
|
||||
usablePreReg bool
|
||||
leaveClientActive bool // if true, leaves the client active time alone. reversed because we can't default a struct element to True
|
||||
leaveClientIdle bool
|
||||
@ -22,6 +23,10 @@ func (cmd *Command) Run(server *Server, client *Client, msg ircmsg.IrcMessage) b
|
||||
// command silently ignored
|
||||
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 {
|
||||
client.Send(nil, server.nameString, ERR_NEEDMOREPARAMS, client.nickString, msg.Command, "Not enough parameters")
|
||||
return false
|
||||
@ -76,6 +81,7 @@ var Commands = map[string]Command{
|
||||
"KILL": Command{
|
||||
handler: killHandler,
|
||||
minParams: 2,
|
||||
oper: true,
|
||||
},
|
||||
"LIST": Command{
|
||||
handler: listHandler,
|
||||
@ -103,10 +109,6 @@ var Commands = map[string]Command{
|
||||
handler: noticeHandler,
|
||||
minParams: 2,
|
||||
},
|
||||
"ONICK": Command{
|
||||
handler: onickHandler,
|
||||
minParams: 2,
|
||||
},
|
||||
"OPER": Command{
|
||||
handler: operHandler,
|
||||
minParams: 2,
|
||||
@ -141,6 +143,11 @@ var Commands = map[string]Command{
|
||||
usablePreReg: true,
|
||||
minParams: 5,
|
||||
},
|
||||
"SANICK": Command{
|
||||
handler: sanickHandler,
|
||||
minParams: 2,
|
||||
oper: true,
|
||||
},
|
||||
"QUIT": Command{
|
||||
handler: quitHandler,
|
||||
usablePreReg: true,
|
||||
|
134
irc/nickname.go
134
irc/nickname.go
@ -8,111 +8,75 @@ import "github.com/DanielOaks/girc-go/ircmsg"
|
||||
|
||||
// NICK <nickname>
|
||||
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 {
|
||||
client.ErrPasswdMismatch()
|
||||
client.Quit("bad password")
|
||||
return
|
||||
}
|
||||
//TODO(dan): SET client.nickString APPROPRIATELY
|
||||
|
||||
if m.nickname == "" {
|
||||
client.ErrNoNicknameGiven()
|
||||
return
|
||||
client.Quit("Bad password")
|
||||
return true
|
||||
}
|
||||
|
||||
if s.clients.Get(m.nickname) != nil {
|
||||
client.ErrNickNameInUse(m.nickname)
|
||||
return
|
||||
nickname := NewName(msg.Params[0])
|
||||
|
||||
if len(nickname) < 1 {
|
||||
client.Send(nil, server.nameString, ERR_NONICKNAMEGIVEN, client.nickString, "No nickname given")
|
||||
return false
|
||||
}
|
||||
|
||||
if !m.nickname.IsNickname() {
|
||||
client.ErrErroneusNickname(m.nickname)
|
||||
return
|
||||
if !nickname.IsNickname() {
|
||||
client.Send(nil, server.nameString, ERR_ERRONEUSNICKNAME, client.nickString, msg.Params[0], "Erroneous nickname")
|
||||
return false
|
||||
}
|
||||
|
||||
client.SetNickname(m.nickname)
|
||||
s.tryRegister(client)
|
||||
if client.nick == nickname {
|
||||
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) {
|
||||
client := msg.Client()
|
||||
//TODO(dan): SET client.nickString APPROPRIATELY
|
||||
|
||||
if msg.nickname == "" {
|
||||
client.ErrNoNicknameGiven()
|
||||
return
|
||||
// SANICK <oldnick> <nickname>
|
||||
func sanickHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||
if !client.authorized {
|
||||
client.Quit("Bad password")
|
||||
return true
|
||||
}
|
||||
|
||||
if !msg.nickname.IsNickname() {
|
||||
client.ErrErroneusNickname(msg.nickname)
|
||||
return
|
||||
oldnick := NewName(msg.Params[0])
|
||||
nickname := NewName(msg.Params[1])
|
||||
|
||||
if len(nickname) < 1 {
|
||||
client.Send(nil, server.nameString, ERR_NONICKNAMEGIVEN, client.nickString, "No nickname given")
|
||||
return false
|
||||
}
|
||||
|
||||
if msg.nickname == client.nick {
|
||||
return
|
||||
if !nickname.IsNickname() {
|
||||
client.Send(nil, server.nameString, ERR_ERRONEUSNICKNAME, client.nickString, msg.Params[0], "Erroneous nickname")
|
||||
return false
|
||||
}
|
||||
|
||||
target := server.clients.Get(msg.nickname)
|
||||
if (target != nil) && (target != client) {
|
||||
client.ErrNickNameInUse(msg.nickname)
|
||||
return
|
||||
if client.nick == nickname {
|
||||
return false
|
||||
}
|
||||
|
||||
client.ChangeNickname(msg.nickname)
|
||||
}
|
||||
|
||||
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)
|
||||
target := server.clients.Get(oldnick)
|
||||
if target == nil {
|
||||
client.ErrNoSuchNick(msg.target)
|
||||
return
|
||||
client.Send(nil, server.nameString, ERR_NOSUCHNICK, msg.Params[0], "No such nick")
|
||||
return false
|
||||
}
|
||||
|
||||
if server.clients.Get(msg.nick) != nil {
|
||||
client.ErrNickNameInUse(msg.nick)
|
||||
return
|
||||
//TODO(dan): There's probably some races here, we should be changing this in the primary server thread
|
||||
if server.clients.Get(nickname) != nil {
|
||||
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
|
||||
}
|
||||
*/
|
||||
|
@ -982,11 +982,6 @@ func killHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||
nickname := msg.Params[0]
|
||||
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))
|
||||
if target == nil {
|
||||
client.Send(nil, client.server.nameString, ERR_NOSUCHNICK, nickname, "No such nick")
|
||||
|
Loading…
Reference in New Issue
Block a user