From 5100578e7b284a8070a2b7beb1b34eb231e9b281 Mon Sep 17 00:00:00 2001 From: Andreas Neue Date: Tue, 2 Aug 2016 00:00:17 +0200 Subject: [PATCH] Server operators implemented --- server.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/server.go b/server.go index a4aafa4..fe0467d 100644 --- a/server.go +++ b/server.go @@ -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,12 +431,15 @@ 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")) } - mode := "o " + clid - sv.chModes[chid][mode] = true - sv.sendMsg(irc.M(sv.host, "MODE", chid+" +o "+clid, "")) } // Handle user parting the channel and delete channel if last user has