Changed join/part handling
This commit is contained in:
parent
038a3589c4
commit
f844505c17
74
server.go
74
server.go
|
@ -28,17 +28,22 @@ type Server struct {
|
|||
queue chan *irc.Message
|
||||
addq chan Client
|
||||
delq chan Client
|
||||
|
||||
host string
|
||||
info string
|
||||
software string
|
||||
version string
|
||||
created string
|
||||
motd string
|
||||
|
||||
clients map[string]Client
|
||||
|
||||
chUsers map[string]map[string]string
|
||||
chTopics map[string]string
|
||||
|
||||
config *conf.ConfigFile
|
||||
configPath string
|
||||
|
||||
packetsTransferred float64
|
||||
connectionsCurrent float64
|
||||
connectionsCount float64
|
||||
|
@ -47,22 +52,26 @@ type Server struct {
|
|||
|
||||
// Create a new server instance.
|
||||
func NewServer(configPath, software, version string) *Server {
|
||||
sv := &Server{software: software, version: version, created: "yes"}
|
||||
sv := &Server{software: software, version: version,
|
||||
created: time.Now().String()}
|
||||
|
||||
sv.queue = make(chan *irc.Message, 1024)
|
||||
sv.addq = make(chan Client, 1024)
|
||||
sv.delq = make(chan Client, 1024)
|
||||
sv.addq = make(chan Client, 128)
|
||||
sv.delq = make(chan Client, 128)
|
||||
|
||||
sv.clients = make(map[string]Client)
|
||||
sv.chUsers = make(map[string]map[string]string)
|
||||
sv.chTopics = make(map[string]string)
|
||||
|
||||
sv.configPath = configPath
|
||||
sv.loadConfig()
|
||||
|
||||
loglevel, _ := sv.config.GetInt("system", "loglevel")
|
||||
xlog.Init(loglevel)
|
||||
|
||||
sv.host, _ = sv.config.GetString("server", "host")
|
||||
sv.info, _ = sv.config.GetString("server", "info")
|
||||
sv.motd, _ = sv.config.GetString("server", "motd")
|
||||
xlog.Init(loglevel)
|
||||
|
||||
sv.packetsTransferred = 0
|
||||
sv.connectionsCurrent = 0
|
||||
|
@ -235,7 +244,7 @@ func (sv *Server) sendLogon(nick string) {
|
|||
fmt.Sprintf("Your host is %s, running on %s/%s",
|
||||
sv.host, sv.software, sv.version))
|
||||
sv.sendReply(nick, RPL_CREATED, "",
|
||||
fmt.Sprintf("Created: %s", sv.created))
|
||||
fmt.Sprintf("This server was created %s", sv.created))
|
||||
sv.sendReply(nick, RPL_MYINFO, "",
|
||||
fmt.Sprintf(myinfo, sv.host, sv.software, sv.version))
|
||||
sv.sendReply(nick, RPL_ISUPPORT, "",
|
||||
|
@ -248,35 +257,6 @@ func (sv *Server) sendLogon(nick string) {
|
|||
sv.sendReply(nick, RPL_ENDOFMOTD, "", "End of MOTD command")
|
||||
}
|
||||
|
||||
func (sv *Server) channelJoin(nick, ch string) {
|
||||
clid := strings.ToLower(nick)
|
||||
chid := strings.ToLower(ch)
|
||||
if _, exists := sv.chUsers[chid]; !exists {
|
||||
sv.chUsers[chid] = make(map[string]string)
|
||||
sv.chTopics[chid] = ""
|
||||
}
|
||||
if _, exists := sv.chUsers[chid][clid]; exists {
|
||||
return
|
||||
}
|
||||
sv.chUsers[chid][clid] = ""
|
||||
sv.sendMsg(irc.M(nick, "JOIN", ch, ""))
|
||||
sv.sendReply(nick, RPL_TOPIC, ch, sv.chTopics[ch])
|
||||
sv.channelNames(nick, ch)
|
||||
}
|
||||
|
||||
func (sv *Server) channelPart(nick, ch, reason string) {
|
||||
clid := strings.ToLower(nick)
|
||||
chid := strings.ToLower(ch)
|
||||
if _, exists := sv.chUsers[chid]; !exists {
|
||||
return
|
||||
}
|
||||
if _, exists := sv.chUsers[chid][clid]; !exists {
|
||||
return
|
||||
}
|
||||
sv.sendMsg(irc.M(nick, "PART", ch, reason))
|
||||
delete(sv.chUsers[chid], clid)
|
||||
}
|
||||
|
||||
func (sv *Server) channelNames(nick, ch string) {
|
||||
chid := strings.ToLower(ch)
|
||||
if _, exists := sv.chUsers[chid]; !exists {
|
||||
|
@ -340,11 +320,33 @@ func handleCmdPrivmsg(sv *Server, msg *irc.Message) {
|
|||
}
|
||||
|
||||
func handleCmdJoin(sv *Server, msg *irc.Message) {
|
||||
sv.channelJoin(msg.Pre, msg.Args[0])
|
||||
clid := strings.ToLower(msg.Pre)
|
||||
chid := strings.ToLower(msg.Args[0])
|
||||
if _, exists := sv.chUsers[chid]; !exists {
|
||||
sv.chUsers[chid] = make(map[string]string)
|
||||
sv.chTopics[chid] = ""
|
||||
}
|
||||
if _, exists := sv.chUsers[chid][clid]; exists {
|
||||
return
|
||||
}
|
||||
sv.chUsers[chid][clid] = ""
|
||||
sv.sendMsg(msg)
|
||||
sv.sendReply(msg.Pre, RPL_TOPIC, msg.Args[0], sv.chTopics[msg.Args[0]])
|
||||
sv.channelNames(msg.Pre, msg.Args[0])
|
||||
}
|
||||
|
||||
func handleCmdPart(sv *Server, msg *irc.Message) {
|
||||
sv.channelPart(msg.Pre, msg.Args[0], msg.Trail)
|
||||
clid := strings.ToLower(msg.Pre)
|
||||
chid := strings.ToLower(msg.Args[0])
|
||||
if _, exists := sv.chUsers[chid]; !exists {
|
||||
return
|
||||
}
|
||||
if _, exists := sv.chUsers[chid][clid]; !exists {
|
||||
return
|
||||
}
|
||||
sv.sendMsg(msg)
|
||||
delete(sv.chUsers[chid], clid)
|
||||
|
||||
}
|
||||
|
||||
func handleCmdQuit(sv *Server, msg *irc.Message) {
|
||||
|
|
Loading…
Reference in New Issue