Server operators implemented

This commit is contained in:
Andreas Neue 2016-08-02 00:00:17 +02:00
parent e128089c09
commit 5100578e7b
1 changed files with 19 additions and 7 deletions

View File

@ -22,7 +22,7 @@ const (
)
var myinfo string = "%s %s/%s * *"
var isupport string = "CASEMAPPING=rfc1459 CHANTYPES=# NICKLEN=32 PREFIX=(ohv)@%%+"
var isupport string = "CASEMAPPING=rfc1459 CHANTYPES=# NICKLEN=32 MODES=1 PREFIX=(ohv)@%%+"
type Server struct {
queue chan *irc.Message
@ -36,6 +36,8 @@ type Server struct {
created string
motd string
opers map[string]bool
clients map[string]Client
clModes map[string]string
@ -63,6 +65,8 @@ func NewServer(configPath, software, version string) *Server {
sv.addq = make(chan Client, 128)
sv.delq = make(chan Client, 128)
sv.opers = make(map[string]bool)
sv.clients = make(map[string]Client)
sv.clModes = make(map[string]string)
@ -80,6 +84,11 @@ func NewServer(configPath, software, version string) *Server {
sv.info, _ = sv.config.GetString("server", "info")
sv.motd, _ = sv.config.GetString("server", "motd")
opers, _ := sv.config.GetString("control", "o")
for _, oper := range strings.Split(opers, ",") {
sv.opers[oper] = true
}
sv.packetsTransferred = 0
sv.connectionsCurrent = 0
sv.connectionsCount = 0
@ -310,7 +319,7 @@ func (sv *Server) channelNames(nick, ch string) {
names += " "
}
modeFlags := "ohv"
modeChars := "@%+"
modeChars := "@%%+"
for i, mf := range modeFlags {
if _, exists := sv.chModes[chid][string(mf)+" "+clid]; exists {
name = string(modeChars[i]) + name
@ -422,13 +431,16 @@ func handleCmdJoin(sv *Server, msg *irc.Message) {
sv.sendMsg(msg)
sv.sendReply(msg.Pre, RPL_TOPIC, msg.Args[0], sv.chTopics[msg.Args[0]])
sv.channelNames(msg.Pre, msg.Args[0])
if !first {
return
}
_, isop := sv.opers[clid]
if first || isop {
mode := "o " + clid
sv.chModes[chid][mode] = true
sv.sendMsg(irc.M(sv.host, "MODE", chid+" +o "+clid, ""))
}
if isop {
sv.sendMsg(irc.M(sv.host, "PRIVMSG", chid, clid+" is a server operator"))
}
}
// Handle user parting the channel and delete channel if last user has
// left