3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 21:39:25 +01:00

user: Don't parse the second and third params anymore

This commit is contained in:
Daniel Oaks 2016-04-15 18:45:05 +10:00
parent 9acdeedec6
commit fb345a2dd4
3 changed files with 8 additions and 66 deletions

View File

@ -20,6 +20,7 @@ Initial release of Oragono!
### Removed
* Gitconfig config format completely removed and replaced with YAML.
* USER: No longer parse out the second and third parameters.
### Fixed
* CAP: Registration is now properly suspended during CAP negotiation.

View File

@ -270,50 +270,11 @@ type UserCommand struct {
realname Text
}
// USER <username> <hostname> <servername> <realname>
type RFC1459UserCommand struct {
UserCommand
hostname Name
servername Name
}
// USER <user> <mode> <unused> <realname>
type RFC2812UserCommand struct {
UserCommand
mode uint8
unused string
}
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 ParseUserCommand(args []string) (Command, error) {
mode, err := strconv.ParseUint(args[1], 10, 8)
if err == nil {
msg := &RFC2812UserCommand{
mode: uint8(mode),
unused: args[2],
}
msg.username = NewName(args[0])
msg.realname = NewText(args[3])
return msg, nil
}
msg := &RFC1459UserCommand{
hostname: NewName(args[1]),
servername: NewName(args[2]),
}
msg.username = NewName(args[0])
msg.realname = NewText(args[3])
return msg, nil
return &UserCommand{
username: NewName(args[0]),
realname: NewText(args[3]),
}, nil
}
// QUIT [ <Quit Command> ]

View File

@ -372,37 +372,17 @@ func (msg *ProxyCommand) HandleRegServer(server *Server) {
msg.Client().hostname = msg.hostname
}
func (msg *RFC1459UserCommand) HandleRegServer(server *Server) {
func (msg *UserCommand) HandleRegServer(server *Server) {
client := msg.Client()
if !client.authorized {
client.ErrPasswdMismatch()
client.Quit("bad password")
return
}
msg.setUserInfo(server)
}
func (msg *RFC2812UserCommand) HandleRegServer(server *Server) {
client := msg.Client()
if !client.authorized {
client.ErrPasswdMismatch()
client.Quit("bad password")
return
}
flags := msg.Flags()
if len(flags) > 0 {
for _, mode := range flags {
client.flags[mode] = true
}
client.RplUModeIs(client)
}
msg.setUserInfo(server)
}
func (msg *UserCommand) setUserInfo(server *Server) {
client := msg.Client()
// set user info and log client in
server.clients.Remove(client)
//TODO(dan): Could there be a race condition here with adding/removing the client?
client.username, client.realname = msg.username, msg.realname
server.clients.Add(client)