mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +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.
|
* 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.
|
||||||
|
@ -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,
|
||||||
|
140
irc/nickname.go
140
irc/nickname.go
@ -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
|
if !client.authorized {
|
||||||
// send NICK change to primary server thread for processing
|
client.Quit("Bad password")
|
||||||
// |-> ensure no other client exists with that nickname
|
|
||||||
|
|
||||||
// do this after replacing nickname
|
|
||||||
client.updateNickMask()
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
nickname := NewName(msg.Params[0])
|
||||||
type NickCommand struct {
|
|
||||||
BaseCommand
|
if len(nickname) < 1 {
|
||||||
nickname Name
|
client.Send(nil, server.nameString, ERR_NONICKNAMEGIVEN, client.nickString, "No nickname given")
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *NickCommand) HandleRegServer(s *Server) {
|
if !nickname.IsNickname() {
|
||||||
client := m.Client()
|
client.Send(nil, server.nameString, ERR_ERRONEUSNICKNAME, client.nickString, msg.Params[0], "Erroneous nickname")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// SANICK <oldnick> <nickname>
|
||||||
|
func sanickHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
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 {
|
oldnick := NewName(msg.Params[0])
|
||||||
client.ErrNickNameInUse(m.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 !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
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *NickCommand) HandleServer(server *Server) {
|
target := server.clients.Get(oldnick)
|
||||||
client := msg.Client()
|
|
||||||
//TODO(dan): SET client.nickString APPROPRIATELY
|
|
||||||
|
|
||||||
if msg.nickname == "" {
|
|
||||||
client.ErrNoNicknameGiven()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !msg.nickname.IsNickname() {
|
|
||||||
client.ErrErroneusNickname(msg.nickname)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if msg.nickname == client.nick {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
target := server.clients.Get(msg.nickname)
|
|
||||||
if (target != nil) && (target != client) {
|
|
||||||
client.ErrNickNameInUse(msg.nickname)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
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
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
@ -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")
|
||||||
|
Loading…
Reference in New Issue
Block a user