2020-02-25 15:51:22 +00:00
|
|
|
package irc
|
2019-08-20 02:15:56 +00:00
|
|
|
|
2019-08-21 08:15:45 +00:00
|
|
|
import log "github.com/sirupsen/logrus"
|
2019-08-20 02:15:56 +00:00
|
|
|
|
|
|
|
type ircUserSession struct {
|
2019-08-21 08:15:45 +00:00
|
|
|
//FIXME add a mutex and protect during writes
|
|
|
|
nick string
|
|
|
|
user string
|
|
|
|
specifiedHostname string
|
|
|
|
realName string
|
|
|
|
remoteHost string
|
|
|
|
state string
|
|
|
|
// FIXME make the connection check its state for invalidity periodically
|
|
|
|
// and .Kill() it if the irc protocol session wants the client
|
|
|
|
// connection gone
|
|
|
|
invalid bool
|
2019-08-21 06:15:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewIrcUserSession() *ircUserSession {
|
|
|
|
// FIXME get conn.RemoteAddr passed in and stringify it here and put it
|
2019-08-21 08:15:45 +00:00
|
|
|
// in the session
|
2019-08-21 06:15:12 +00:00
|
|
|
s := new(ircUserSession)
|
2019-08-21 08:15:45 +00:00
|
|
|
s.nick = "*" //default for s2c messages pre-NICK
|
|
|
|
s.state = "init"
|
|
|
|
s.invalid = false
|
2019-08-21 06:15:12 +00:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2019-08-21 08:15:45 +00:00
|
|
|
func (s *ircUserSession) CheckState(wantedState string) bool {
|
|
|
|
if s.state == wantedState {
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ircUserSession) SetState(newState string) bool {
|
|
|
|
log.Infof("state changing: %s->%s", s.state, newState) //FIXME remove this
|
|
|
|
s.state = newState
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ircUserSession) SetNick(input string) bool {
|
|
|
|
// FIXME check for valid nick-ness
|
|
|
|
s.nick = input
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ircUserSession) SetUserInfo(params []string) bool {
|
|
|
|
if !s.CheckState("init") {
|
|
|
|
// can only do this when going init->normal
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if s.nick == "*" {
|
|
|
|
// must set nick first
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if len(params) >= 4 {
|
|
|
|
s.user = params[0]
|
|
|
|
s.specifiedHostname = params[1]
|
|
|
|
s.realName = params[3]
|
|
|
|
s.SetState("normal")
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
2019-08-20 02:15:56 +00:00
|
|
|
}
|