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 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 { type Server struct {
queue chan *irc.Message queue chan *irc.Message
@ -36,6 +36,8 @@ type Server struct {
created string created string
motd string motd string
opers map[string]bool
clients map[string]Client clients map[string]Client
clModes map[string]string clModes map[string]string
@ -63,6 +65,8 @@ func NewServer(configPath, software, version string) *Server {
sv.addq = make(chan Client, 128) sv.addq = make(chan Client, 128)
sv.delq = make(chan Client, 128) sv.delq = make(chan Client, 128)
sv.opers = make(map[string]bool)
sv.clients = make(map[string]Client) sv.clients = make(map[string]Client)
sv.clModes = make(map[string]string) 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.info, _ = sv.config.GetString("server", "info")
sv.motd, _ = sv.config.GetString("server", "motd") 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.packetsTransferred = 0
sv.connectionsCurrent = 0 sv.connectionsCurrent = 0
sv.connectionsCount = 0 sv.connectionsCount = 0
@ -310,7 +319,7 @@ func (sv *Server) channelNames(nick, ch string) {
names += " " names += " "
} }
modeFlags := "ohv" modeFlags := "ohv"
modeChars := "@%+" modeChars := "@%%+"
for i, mf := range modeFlags { for i, mf := range modeFlags {
if _, exists := sv.chModes[chid][string(mf)+" "+clid]; exists { if _, exists := sv.chModes[chid][string(mf)+" "+clid]; exists {
name = string(modeChars[i]) + name name = string(modeChars[i]) + name
@ -422,12 +431,15 @@ func handleCmdJoin(sv *Server, msg *irc.Message) {
sv.sendMsg(msg) sv.sendMsg(msg)
sv.sendReply(msg.Pre, RPL_TOPIC, msg.Args[0], sv.chTopics[msg.Args[0]]) sv.sendReply(msg.Pre, RPL_TOPIC, msg.Args[0], sv.chTopics[msg.Args[0]])
sv.channelNames(msg.Pre, msg.Args[0]) sv.channelNames(msg.Pre, msg.Args[0])
if !first { _, isop := sv.opers[clid]
return if first || isop {
}
mode := "o " + clid mode := "o " + clid
sv.chModes[chid][mode] = true sv.chModes[chid][mode] = true
sv.sendMsg(irc.M(sv.host, "MODE", chid+" +o "+clid, "")) 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 // Handle user parting the channel and delete channel if last user has