Server admin and operator roles implemented
This commit is contained in:
parent
f51618e559
commit
32f3f5eaf0
|
@ -168,6 +168,7 @@ func (cl *RemoteClient) connReader() {
|
||||||
func (cl *RemoteClient) connWriter() {
|
func (cl *RemoteClient) connWriter() {
|
||||||
for line := range cl.writeq {
|
for line := range cl.writeq {
|
||||||
written := 0
|
written := 0
|
||||||
|
line = strings.Replace(line, "%", "%%", 0)
|
||||||
bytes := []byte(line + "\r\n")
|
bytes := []byte(line + "\r\n")
|
||||||
for written < len(line) {
|
for written < len(line) {
|
||||||
n, err := cl.conn.Write(bytes[written:])
|
n, err := cl.conn.Write(bytes[written:])
|
||||||
|
|
42
handlers.go
42
handlers.go
|
@ -55,7 +55,7 @@ func handleCmdPrivmsg(sv *Server, msg *irc.Message) {
|
||||||
clid := strings.ToLower(msg.Pre)
|
clid := strings.ToLower(msg.Pre)
|
||||||
chid := strings.ToLower(msg.Args[0])
|
chid := strings.ToLower(msg.Args[0])
|
||||||
if sv.channelCheckMode(chid, "m") &&
|
if sv.channelCheckMode(chid, "m") &&
|
||||||
!sv.channelCheckPerm(chid, clid, "ohv") {
|
!sv.channelCheckPerm(chid, clid, "qaohv") {
|
||||||
sv.sendReply(clid, ERR_CANNOTSENDTOCHAN, chid, "Cannot send to channel")
|
sv.sendReply(clid, ERR_CANNOTSENDTOCHAN, chid, "Cannot send to channel")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -84,15 +84,27 @@ 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])
|
||||||
|
_, isadm := sv.admins[clid]
|
||||||
|
if isadm {
|
||||||
|
mode := "q " + clid
|
||||||
|
sv.chModes[chid][mode] = true
|
||||||
|
sv.sendMsg(irc.M(sv.host, "MODE", chid+" +q "+clid, ""))
|
||||||
|
sv.sendMsg(irc.M(sv.host, "PRIVMSG", chid, clid+" is a server administrator"))
|
||||||
|
return
|
||||||
|
}
|
||||||
_, isop := sv.opers[clid]
|
_, isop := sv.opers[clid]
|
||||||
if first || isop {
|
if isop {
|
||||||
|
mode := "a " + clid
|
||||||
|
sv.chModes[chid][mode] = true
|
||||||
|
sv.sendMsg(irc.M(sv.host, "MODE", chid+" +a "+clid, ""))
|
||||||
|
sv.sendMsg(irc.M(sv.host, "PRIVMSG", chid, clid+" is a server operator"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if first {
|
||||||
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
|
||||||
|
@ -108,6 +120,8 @@ func handleCmdPart(sv *Server, msg *irc.Message) {
|
||||||
}
|
}
|
||||||
sv.sendMsg(msg)
|
sv.sendMsg(msg)
|
||||||
delete(sv.chUsers[chid], clid)
|
delete(sv.chUsers[chid], clid)
|
||||||
|
delete(sv.chModes[chid], "q "+clid)
|
||||||
|
delete(sv.chModes[chid], "a "+clid)
|
||||||
delete(sv.chModes[chid], "o "+clid)
|
delete(sv.chModes[chid], "o "+clid)
|
||||||
delete(sv.chModes[chid], "h "+clid)
|
delete(sv.chModes[chid], "h "+clid)
|
||||||
delete(sv.chModes[chid], "v "+clid)
|
delete(sv.chModes[chid], "v "+clid)
|
||||||
|
@ -144,27 +158,27 @@ func handleCmdMode(sv *Server, msg *irc.Message) {
|
||||||
switch modeSwitch[1] {
|
switch modeSwitch[1] {
|
||||||
// maybe this can be done more elegant
|
// maybe this can be done more elegant
|
||||||
case 'o':
|
case 'o':
|
||||||
if !sv.channelCheckPerm(chid, clid, "o") {
|
if !sv.channelCheckPerm(chid, clid, "qao") {
|
||||||
goto noPerm
|
goto noPerm
|
||||||
}
|
}
|
||||||
case 'h':
|
case 'h':
|
||||||
if !sv.channelCheckPerm(chid, clid, "o") {
|
if !sv.channelCheckPerm(chid, clid, "qao") {
|
||||||
goto noPerm
|
goto noPerm
|
||||||
}
|
}
|
||||||
case 'b':
|
case 'b':
|
||||||
if !sv.channelCheckPerm(chid, clid, "oh") {
|
if !sv.channelCheckPerm(chid, clid, "qaoh") {
|
||||||
goto noPerm
|
goto noPerm
|
||||||
}
|
}
|
||||||
case 'v':
|
case 'v':
|
||||||
if !sv.channelCheckPerm(chid, clid, "oh") {
|
if !sv.channelCheckPerm(chid, clid, "qaoh") {
|
||||||
goto noPerm
|
goto noPerm
|
||||||
}
|
}
|
||||||
case 'm':
|
case 'm':
|
||||||
if !sv.channelCheckPerm(chid, clid, "oh") {
|
if !sv.channelCheckPerm(chid, clid, "qaoh") {
|
||||||
goto noPerm
|
goto noPerm
|
||||||
}
|
}
|
||||||
case 't':
|
case 't':
|
||||||
if !sv.channelCheckPerm(chid, clid, "oh") {
|
if !sv.channelCheckPerm(chid, clid, "qaoh") {
|
||||||
goto noPerm
|
goto noPerm
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -196,7 +210,7 @@ func handleCmdTopic(sv *Server, msg *irc.Message) {
|
||||||
sv.sendReply(msg.Pre, RPL_TOPIC, chid, sv.chTopics[chid])
|
sv.sendReply(msg.Pre, RPL_TOPIC, chid, sv.chTopics[chid])
|
||||||
} else {
|
} else {
|
||||||
if sv.channelCheckMode(chid, "t") &&
|
if sv.channelCheckMode(chid, "t") &&
|
||||||
!sv.channelCheckPerm(chid, clid, "oh") {
|
!sv.channelCheckPerm(chid, clid, "qaoh") {
|
||||||
sv.sendReply(clid, ERR_CHANOPRIVSNEEDED, chid, "You're not channel operator")
|
sv.sendReply(clid, ERR_CHANOPRIVSNEEDED, chid, "You're not channel operator")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -210,11 +224,13 @@ func handleCmdKick(sv *Server, msg *irc.Message) {
|
||||||
chid := strings.ToLower(msg.Args[0])
|
chid := strings.ToLower(msg.Args[0])
|
||||||
clid := strings.ToLower(msg.Pre)
|
clid := strings.ToLower(msg.Pre)
|
||||||
target := strings.ToLower(msg.Args[1])
|
target := strings.ToLower(msg.Args[1])
|
||||||
if !sv.channelCheckPerm(chid, clid, "oh") {
|
if !sv.channelCheckPerm(chid, clid, "qaoh") {
|
||||||
sv.sendReply(clid, ERR_CHANOPRIVSNEEDED, chid, "You're not channel operator")
|
sv.sendReply(clid, ERR_CHANOPRIVSNEEDED, chid, "You're not channel operator")
|
||||||
}
|
}
|
||||||
sv.sendMsg(msg)
|
sv.sendMsg(msg)
|
||||||
delete(sv.chUsers[chid], target)
|
delete(sv.chUsers[chid], target)
|
||||||
|
delete(sv.chModes[chid], "q "+target)
|
||||||
|
delete(sv.chModes[chid], "a "+target)
|
||||||
delete(sv.chModes[chid], "o "+target)
|
delete(sv.chModes[chid], "o "+target)
|
||||||
delete(sv.chModes[chid], "h "+target)
|
delete(sv.chModes[chid], "h "+target)
|
||||||
delete(sv.chModes[chid], "v "+target)
|
delete(sv.chModes[chid], "v "+target)
|
||||||
|
|
18
server.go
18
server.go
|
@ -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 MODES=1 PREFIX=(ohv)@%%+"
|
var isupport string = "CASEMAPPING=rfc1459 CHANTYPES=# NICKLEN=32 MODES=1 PREFIX=(qaohv)~&@%+"
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
queue chan *irc.Message
|
queue chan *irc.Message
|
||||||
|
@ -36,6 +36,7 @@ type Server struct {
|
||||||
created string
|
created string
|
||||||
motd string
|
motd string
|
||||||
|
|
||||||
|
admins map[string]bool
|
||||||
opers map[string]bool
|
opers map[string]bool
|
||||||
|
|
||||||
clients map[string]Client
|
clients map[string]Client
|
||||||
|
@ -65,6 +66,7 @@ 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.admins = make(map[string]bool)
|
||||||
sv.opers = make(map[string]bool)
|
sv.opers = make(map[string]bool)
|
||||||
|
|
||||||
sv.clients = make(map[string]Client)
|
sv.clients = make(map[string]Client)
|
||||||
|
@ -84,9 +86,13 @@ 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")
|
nicks, _ := sv.config.GetString("control", "a")
|
||||||
for _, oper := range strings.Split(opers, ",") {
|
for _, nick := range strings.Split(nicks, ",") {
|
||||||
sv.opers[oper] = true
|
sv.admins[nick] = true
|
||||||
|
}
|
||||||
|
nicks, _ = sv.config.GetString("control", "o")
|
||||||
|
for _, nick := range strings.Split(nicks, ",") {
|
||||||
|
sv.opers[nick] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
sv.packetsTransferred = 0
|
sv.packetsTransferred = 0
|
||||||
|
@ -326,8 +332,8 @@ func (sv *Server) channelNames(nick, ch string) {
|
||||||
if names != "" {
|
if names != "" {
|
||||||
names += " "
|
names += " "
|
||||||
}
|
}
|
||||||
modeFlags := "ohv"
|
modeFlags := "qaohv"
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue