3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 21:39:25 +01:00

Cleanups reported by goreportcard

This commit is contained in:
Daniel Oaks 2016-06-30 15:43:27 +10:00
parent 5d3b185881
commit 748bc759cb
4 changed files with 37 additions and 39 deletions

View File

@ -43,20 +43,17 @@ func (cs *ClientSocket) Start() {
func (cs *ClientSocket) RunEvents() { func (cs *ClientSocket) RunEvents() {
var exiting bool var exiting bool
var line string var line string
for { for !exiting {
select { select {
case line = <-cs.receiveLines: case line = <-cs.receiveLines:
if line != "" { if line != "" {
fmt.Println("<- ", strings.TrimRight(line, "\r\n")) fmt.Println("<- ", strings.TrimRight(line, "\r\n"))
exiting = cs.processIncomingLine(line) exiting = cs.processIncomingLine(line)
if exiting {
cs.socket.Close()
break
}
} }
} }
} }
// empty the receiveLines queue // empty the receiveLines queue
cs.socket.Close()
select { select {
case <-cs.receiveLines: case <-cs.receiveLines:
// empty // empty

View File

@ -49,105 +49,105 @@ func (cmd *Command) Run(server *Server, client *Client, msg ircmsg.IrcMessage) b
// Commands holds all commands executable by a client connected to us. // Commands holds all commands executable by a client connected to us.
var Commands = map[string]Command{ var Commands = map[string]Command{
"AWAY": Command{ "AWAY": {
handler: awayHandler, handler: awayHandler,
minParams: 0, minParams: 0,
}, },
"CAP": Command{ "CAP": {
handler: capHandler, handler: capHandler,
usablePreReg: true, usablePreReg: true,
minParams: 1, minParams: 1,
}, },
"DEBUG": Command{ "DEBUG": {
handler: debugHandler, handler: debugHandler,
minParams: 1, minParams: 1,
}, },
"INVITE": Command{ "INVITE": {
handler: inviteHandler, handler: inviteHandler,
minParams: 2, minParams: 2,
}, },
"ISON": Command{ "ISON": {
handler: isonHandler, handler: isonHandler,
minParams: 1, minParams: 1,
}, },
"JOIN": Command{ "JOIN": {
handler: joinHandler, handler: joinHandler,
minParams: 1, minParams: 1,
}, },
"KICK": Command{ "KICK": {
handler: kickHandler, handler: kickHandler,
minParams: 2, minParams: 2,
}, },
"KILL": Command{ "KILL": {
handler: killHandler, handler: killHandler,
minParams: 2, minParams: 2,
oper: true, oper: true,
}, },
"LIST": Command{ "LIST": {
handler: listHandler, handler: listHandler,
minParams: 0, minParams: 0,
}, },
"MODE": Command{ "MODE": {
handler: modeHandler, handler: modeHandler,
minParams: 1, minParams: 1,
}, },
"MOTD": Command{ "MOTD": {
handler: motdHandler, handler: motdHandler,
minParams: 0, minParams: 0,
}, },
"NAMES": Command{ "NAMES": {
handler: namesHandler, handler: namesHandler,
minParams: 0, minParams: 0,
}, },
"NICK": Command{ "NICK": {
handler: nickHandler, handler: nickHandler,
usablePreReg: true, usablePreReg: true,
minParams: 1, minParams: 1,
}, },
"NOTICE": Command{ "NOTICE": {
handler: noticeHandler, handler: noticeHandler,
minParams: 2, minParams: 2,
}, },
"OPER": Command{ "OPER": {
handler: operHandler, handler: operHandler,
minParams: 2, minParams: 2,
}, },
"PART": Command{ "PART": {
handler: partHandler, handler: partHandler,
minParams: 1, minParams: 1,
}, },
"PASS": Command{ "PASS": {
handler: passHandler, handler: passHandler,
usablePreReg: true, usablePreReg: true,
minParams: 1, minParams: 1,
}, },
"PING": Command{ "PING": {
handler: pingHandler, handler: pingHandler,
usablePreReg: true, usablePreReg: true,
minParams: 1, minParams: 1,
leaveClientActive: true, leaveClientActive: true,
}, },
"PONG": Command{ "PONG": {
handler: pongHandler, handler: pongHandler,
usablePreReg: true, usablePreReg: true,
minParams: 1, minParams: 1,
leaveClientActive: true, leaveClientActive: true,
}, },
"PRIVMSG": Command{ "PRIVMSG": {
handler: privmsgHandler, handler: privmsgHandler,
minParams: 2, minParams: 2,
}, },
"PROXY": Command{ "PROXY": {
handler: proxyHandler, handler: proxyHandler,
usablePreReg: true, usablePreReg: true,
minParams: 5, minParams: 5,
}, },
"SANICK": Command{ "SANICK": {
handler: sanickHandler, handler: sanickHandler,
minParams: 2, minParams: 2,
oper: true, oper: true,
}, },
"QUIT": Command{ "QUIT": {
handler: quitHandler, handler: quitHandler,
usablePreReg: true, usablePreReg: true,
minParams: 0, minParams: 0,
@ -157,32 +157,32 @@ var Commands = map[string]Command{
handler: theatreHandler, handler: theatreHandler,
minParams: 1, minParams: 1,
},*/ },*/
"TIME": Command{ "TIME": {
handler: timeHandler, handler: timeHandler,
minParams: 0, minParams: 0,
}, },
"TOPIC": Command{ "TOPIC": {
handler: topicHandler, handler: topicHandler,
minParams: 1, minParams: 1,
}, },
"USER": Command{ "USER": {
handler: userHandler, handler: userHandler,
usablePreReg: true, usablePreReg: true,
minParams: 4, minParams: 4,
}, },
"VERSION": Command{ "VERSION": {
handler: versionHandler, handler: versionHandler,
minParams: 0, minParams: 0,
}, },
"WHO": Command{ "WHO": {
handler: whoHandler, handler: whoHandler,
minParams: 0, minParams: 0,
}, },
"WHOIS": Command{ "WHOIS": {
handler: whoisHandler, handler: whoisHandler,
minParams: 1, minParams: 1,
}, },
"WHOWAS": Command{ "WHOWAS": {
handler: whowasHandler, handler: whowasHandler,
minParams: 1, minParams: 1,
}, },

View File

@ -834,6 +834,8 @@ func kickHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
} }
// make sure client has privs to kick the given user // make sure client has privs to kick the given user
//TODO(dan): split this into a separate function that checks if users have privs
// over other users, useful for things like -aoh as well
var hasPrivs bool var hasPrivs bool
for _, mode := range ChannelPrivModes { for _, mode := range ChannelPrivModes {
if channel.members[client][mode] { if channel.members[client][mode] {
@ -852,10 +854,9 @@ func kickHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
if hasPrivs { if hasPrivs {
if comment == "" { if comment == "" {
channel.Kick(client, target, nickname) comment = nickname
} else {
channel.Kick(client, target, comment)
} }
channel.Kick(client, target, comment)
} else { } else {
client.Send(nil, client.server.nameString, ERR_CHANOPRIVSNEEDED, chname, "You're not a channel operator") client.Send(nil, client.server.nameString, ERR_CHANOPRIVSNEEDED, chname, "You're not a channel operator")
} }

View File

@ -120,7 +120,7 @@ Options:
keyOut, err := os.OpenFile(conf.Key, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) keyOut, err := os.OpenFile(conf.Key, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil { if err != nil {
log.Print("failed to open %s for writing:", conf.Key, err) log.Print(fmt.Sprintf("failed to open %s for writing:", conf.Key), err)
return return
} }
b, err := x509.MarshalECPrivateKey(priv) b, err := x509.MarshalECPrivateKey(priv)