mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 18:52:41 +01:00
ONICK command to allow operators to change users' nicks
This commit is contained in:
parent
abf00e22ec
commit
8c44bb9ff3
@ -227,6 +227,10 @@ func (client *Client) Friends() ClientSet {
|
||||
}
|
||||
|
||||
func (client *Client) SetNickname(nickname Name) {
|
||||
if client.HasNick() {
|
||||
Log.error.Printf("%s nickname already set!", client)
|
||||
return
|
||||
}
|
||||
client.nick = nickname
|
||||
client.server.clients.Add(client)
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ var (
|
||||
NAMES: NewNamesCommand,
|
||||
NICK: NewNickCommand,
|
||||
NOTICE: NewNoticeCommand,
|
||||
ONICK: NewOperNickCommand,
|
||||
OPER: NewOperCommand,
|
||||
PART: NewPartCommand,
|
||||
PASS: NewPassCommand,
|
||||
@ -228,15 +229,6 @@ func NewPassCommand(args []string) (Command, error) {
|
||||
|
||||
// NICK <nickname>
|
||||
|
||||
type NickCommand struct {
|
||||
BaseCommand
|
||||
nickname Name
|
||||
}
|
||||
|
||||
func (m *NickCommand) String() string {
|
||||
return fmt.Sprintf("NICK(nickname=%s)", m.nickname)
|
||||
}
|
||||
|
||||
func NewNickCommand(args []string) (Command, error) {
|
||||
if len(args) != 1 {
|
||||
return nil, NotEnoughArgsError
|
||||
@ -1006,3 +998,14 @@ func NewWhoWasCommand(args []string) (Command, error) {
|
||||
}
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func NewOperNickCommand(args []string) (Command, error) {
|
||||
if len(args) < 2 {
|
||||
return nil, NotEnoughArgsError
|
||||
}
|
||||
|
||||
return &OperNickCommand{
|
||||
target: NewName(args[0]),
|
||||
nick: NewName(args[1]),
|
||||
}, nil
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ const (
|
||||
NAMES StringCode = "NAMES"
|
||||
NICK StringCode = "NICK"
|
||||
NOTICE StringCode = "NOTICE"
|
||||
ONICK StringCode = "ONICK"
|
||||
OPER StringCode = "OPER"
|
||||
PART StringCode = "PART"
|
||||
PASS StringCode = "PASS"
|
||||
|
99
irc/nickname.go
Normal file
99
irc/nickname.go
Normal file
@ -0,0 +1,99 @@
|
||||
package irc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type NickCommand struct {
|
||||
BaseCommand
|
||||
nickname Name
|
||||
}
|
||||
|
||||
func (m *NickCommand) String() string {
|
||||
return fmt.Sprintf("NICK(nickname=%s)", m.nickname)
|
||||
}
|
||||
|
||||
func (m *NickCommand) HandleRegServer(s *Server) {
|
||||
client := m.Client()
|
||||
if !client.authorized {
|
||||
client.ErrPasswdMismatch()
|
||||
client.Quit("bad password")
|
||||
return
|
||||
}
|
||||
|
||||
if client.capState == CapNegotiating {
|
||||
client.capState = CapNegotiated
|
||||
}
|
||||
|
||||
if m.nickname == "" {
|
||||
client.ErrNoNicknameGiven()
|
||||
return
|
||||
}
|
||||
|
||||
if s.clients.Get(m.nickname) != nil {
|
||||
client.ErrNickNameInUse(m.nickname)
|
||||
return
|
||||
}
|
||||
|
||||
if !m.nickname.IsNickname() {
|
||||
client.ErrErroneusNickname(m.nickname)
|
||||
return
|
||||
}
|
||||
|
||||
client.SetNickname(m.nickname)
|
||||
s.tryRegister(client)
|
||||
}
|
||||
|
||||
func (msg *NickCommand) HandleServer(server *Server) {
|
||||
client := msg.Client()
|
||||
|
||||
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()
|
||||
|
||||
if !client.flags[Operator] {
|
||||
client.ErrNoPrivileges()
|
||||
return
|
||||
}
|
||||
|
||||
if !msg.nick.IsNickname() {
|
||||
client.ErrErroneusNickname(msg.nick)
|
||||
return
|
||||
}
|
||||
|
||||
target := server.clients.Get(msg.target)
|
||||
if target == nil {
|
||||
client.ErrNoSuchNick(msg.target)
|
||||
return
|
||||
}
|
||||
|
||||
target.ChangeNickname(msg.nick)
|
||||
}
|
@ -289,37 +289,6 @@ func (msg *ProxyCommand) HandleRegServer(server *Server) {
|
||||
msg.Client().hostname = msg.hostname
|
||||
}
|
||||
|
||||
func (m *NickCommand) HandleRegServer(s *Server) {
|
||||
client := m.Client()
|
||||
if !client.authorized {
|
||||
client.ErrPasswdMismatch()
|
||||
client.Quit("bad password")
|
||||
return
|
||||
}
|
||||
|
||||
if client.capState == CapNegotiating {
|
||||
client.capState = CapNegotiated
|
||||
}
|
||||
|
||||
if m.nickname == "" {
|
||||
client.ErrNoNicknameGiven()
|
||||
return
|
||||
}
|
||||
|
||||
if s.clients.Get(m.nickname) != nil {
|
||||
client.ErrNickNameInUse(m.nickname)
|
||||
return
|
||||
}
|
||||
|
||||
if !m.nickname.IsNickname() {
|
||||
client.ErrErroneusNickname(m.nickname)
|
||||
return
|
||||
}
|
||||
|
||||
client.SetNickname(m.nickname)
|
||||
s.tryRegister(client)
|
||||
}
|
||||
|
||||
func (msg *RFC1459UserCommand) HandleRegServer(server *Server) {
|
||||
client := msg.Client()
|
||||
if !client.authorized {
|
||||
@ -380,32 +349,6 @@ func (m *PongCommand) HandleServer(s *Server) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
func (msg *NickCommand) HandleServer(server *Server) {
|
||||
client := msg.Client()
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func (m *UserCommand) HandleServer(s *Server) {
|
||||
m.Client().ErrAlreadyRegistered()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user