mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 18:52:41 +01:00
support USER from both RFCs 1459 and 2812
This commit is contained in:
parent
bb64d38684
commit
baf83e73d2
@ -254,5 +254,6 @@ func (client *Client) Quit(message string) {
|
|||||||
channel.Quit(client)
|
channel.Quit(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client.Reply(RplError(client.server, client))
|
||||||
client.Destroy()
|
client.Destroy()
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ var (
|
|||||||
PROXY: NewProxyCommand,
|
PROXY: NewProxyCommand,
|
||||||
QUIT: NewQuitCommand,
|
QUIT: NewQuitCommand,
|
||||||
TOPIC: NewTopicCommand,
|
TOPIC: NewTopicCommand,
|
||||||
USER: NewUserMsgCommand,
|
USER: NewUserCommand,
|
||||||
WHO: NewWhoCommand,
|
WHO: NewWhoCommand,
|
||||||
WHOIS: NewWhoisCommand,
|
WHOIS: NewWhoisCommand,
|
||||||
}
|
}
|
||||||
@ -223,34 +223,68 @@ func NewNickCommand(args []string) (editableCommand, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// USER <user> <mode> <unused> <realname>
|
type UserCommand struct {
|
||||||
|
|
||||||
type UserMsgCommand struct {
|
|
||||||
BaseCommand
|
BaseCommand
|
||||||
user string
|
username string
|
||||||
mode uint8
|
|
||||||
unused string
|
|
||||||
realname string
|
realname string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cmd *UserMsgCommand) String() string {
|
// USER <username> <hostname> <servername> <realname>
|
||||||
return fmt.Sprintf("USER(user=%s, mode=%o, unused=%s, realname=%s)",
|
type RFC1459UserCommand struct {
|
||||||
cmd.user, cmd.mode, cmd.unused, cmd.realname)
|
UserCommand
|
||||||
|
hostname string
|
||||||
|
servername string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUserMsgCommand(args []string) (editableCommand, error) {
|
func (cmd *RFC1459UserCommand) String() string {
|
||||||
|
return fmt.Sprintf("USER(username=%s, hostname=%s, servername=%s, realname=%s)",
|
||||||
|
cmd.username, cmd.hostname, cmd.servername, cmd.realname)
|
||||||
|
}
|
||||||
|
|
||||||
|
// USER <user> <mode> <unused> <realname>
|
||||||
|
type RFC2812UserCommand struct {
|
||||||
|
UserCommand
|
||||||
|
mode uint8
|
||||||
|
unused string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cmd *RFC2812UserCommand) String() string {
|
||||||
|
return fmt.Sprintf("USER(username=%s, mode=%d, unused=%s, realname=%s)",
|
||||||
|
cmd.username, cmd.mode, cmd.unused, cmd.realname)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cmd *RFC2812UserCommand) Flags() []UserMode {
|
||||||
|
flags := make([]UserMode, 0)
|
||||||
|
if (cmd.mode & 4) == 4 {
|
||||||
|
flags = append(flags, WallOps)
|
||||||
|
}
|
||||||
|
if (cmd.mode & 8) == 8 {
|
||||||
|
flags = append(flags, Invisible)
|
||||||
|
}
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUserCommand(args []string) (editableCommand, error) {
|
||||||
if len(args) != 4 {
|
if len(args) != 4 {
|
||||||
return nil, NotEnoughArgsError
|
return nil, NotEnoughArgsError
|
||||||
}
|
}
|
||||||
msg := &UserMsgCommand{
|
|
||||||
user: args[0],
|
|
||||||
unused: args[2],
|
|
||||||
realname: args[3],
|
|
||||||
}
|
|
||||||
mode, err := strconv.ParseUint(args[1], 10, 8)
|
mode, err := strconv.ParseUint(args[1], 10, 8)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
msg.mode = uint8(mode)
|
msg := &RFC2812UserCommand{
|
||||||
|
mode: uint8(mode),
|
||||||
|
unused: args[2],
|
||||||
}
|
}
|
||||||
|
msg.username = args[0]
|
||||||
|
msg.realname = args[3]
|
||||||
|
return msg, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := &RFC1459UserCommand{
|
||||||
|
hostname: args[1],
|
||||||
|
servername: args[2],
|
||||||
|
}
|
||||||
|
msg.username = args[0]
|
||||||
|
msg.realname = args[3]
|
||||||
return msg, nil
|
return msg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,9 +283,25 @@ func (m *NickCommand) HandleRegServer(s *Server) {
|
|||||||
s.tryRegister(client)
|
s.tryRegister(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *UserMsgCommand) HandleRegServer(server *Server) {
|
func (msg *RFC1459UserCommand) HandleRegServer(server *Server) {
|
||||||
|
msg.HandleRegServer2(server)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (msg *RFC2812UserCommand) HandleRegServer(server *Server) {
|
||||||
client := msg.Client()
|
client := msg.Client()
|
||||||
client.username, client.realname = msg.user, msg.realname
|
flags := msg.Flags()
|
||||||
|
if len(flags) > 0 {
|
||||||
|
for _, mode := range msg.Flags() {
|
||||||
|
client.flags[mode] = true
|
||||||
|
}
|
||||||
|
client.Reply(RplUModeIs(server, client))
|
||||||
|
}
|
||||||
|
msg.HandleRegServer2(server)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (msg *UserCommand) HandleRegServer2(server *Server) {
|
||||||
|
client := msg.Client()
|
||||||
|
client.username, client.realname = msg.username, msg.realname
|
||||||
server.tryRegister(client)
|
server.tryRegister(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,7 +339,7 @@ func (msg *NickCommand) HandleServer(server *Server) {
|
|||||||
server.clients.Add(client)
|
server.clients.Add(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *UserMsgCommand) HandleServer(s *Server) {
|
func (m *UserCommand) HandleServer(s *Server) {
|
||||||
m.Client().Reply(ErrAlreadyRegistered(s))
|
m.Client().Reply(ErrAlreadyRegistered(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user