Run gofmt on source files

This commit is contained in:
Trevor Slocum 2016-09-15 18:25:52 -07:00
parent 3dff531449
commit 5f2275700d
6 changed files with 43 additions and 43 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
.idea
*.iml
*.db
AnonIRCd
anonircd
anonircd.conf

View File

@ -15,13 +15,12 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"math/rand"
"sort"
"sync"
"math/rand"
"time"
"github.com/BurntSushi/toml"
@ -31,7 +30,7 @@ import (
)
var anonymous = irc.Prefix{"Anonymous", "Anon", "IRC"}
var anonirc = irc.Prefix{Name:"AnonIRC"}
var anonirc = irc.Prefix{Name: "AnonIRC"}
const motd = `
_|_| _|_|_| _|_|_| _|_|_|

View File

@ -3,7 +3,7 @@ package main
type Channel struct {
Entity
clients map[string]int
clients map[string]int
topic string
topictime int64

View File

@ -9,22 +9,22 @@ import (
type Client struct {
Entity
ssl bool
nick string
user string
host string
ssl bool
nick string
user string
host string
conn net.Conn
writebuffer chan *irc.Message
conn net.Conn
writebuffer chan *irc.Message
reader *irc.Decoder
writer *irc.Encoder
reader *irc.Decoder
writer *irc.Encoder
capHostInNames bool
}
func (c *Client) getPrefix() *irc.Prefix {
return &irc.Prefix{Name:c.nick, User:c.user, Host:c.host}
return &irc.Prefix{Name: c.nick, User: c.user, Host: c.host}
}
func (c *Client) sendNotice(notice string) {

View File

@ -1,9 +1,9 @@
package main
import (
"sync"
"strings"
"fmt"
"strings"
"sync"
)
const ENTITY_CLIENT = 0

View File

@ -2,16 +2,16 @@ package main
import (
"fmt"
"net"
"sync"
"time"
"log"
"net"
"strconv"
"strings"
"sync"
"time"
"crypto/tls"
irc "gopkg.in/sorcix/irc.v2"
"math/rand"
"crypto/tls"
"reflect"
)
@ -254,7 +254,7 @@ func (s *Server) handleMode(c *Client, params []string) {
// Send channel creation time
c.writebuffer <- &irc.Message{&anonirc, strings.Join([]string{"329", c.nick, params[0], fmt.Sprintf("%d", int32(channel.created))}, " "), []string{}}
} else if len(params) > 1 && len(params[1]) > 0 && (params[1][0] == '+' || params[1][0] == '-') {
} else if len(params) > 1 && len(params[1]) > 0 && (params[1][0] == '+' || params[1][0] == '-') {
lastmodes := make(map[string]string)
for mode, modevalue := range channel.modes {
lastmodes[mode] = modevalue
@ -281,7 +281,7 @@ func (s *Server) handleMode(c *Client, params []string) {
resendusercount = true
}
if (len(addedmodes) == 0 && len(removedmodes) == 0) {
if len(addedmodes) == 0 && len(removedmodes) == 0 {
addedmodes = c.modes
}
@ -305,7 +305,7 @@ func (s *Server) handleMode(c *Client, params []string) {
lastmodes[mode] = modevalue
}
if len(params) > 1 && len(params[1]) > 0 && (params[1][0] == '+' || params[1][0] == '-') {
if len(params) > 1 && len(params[1]) > 0 && (params[1][0] == '+' || params[1][0] == '-') {
c.Lock()
if params[1][0] == '+' {
c.addModes(params[1][1:])
@ -326,7 +326,7 @@ func (s *Server) handleMode(c *Client, params []string) {
resendusercount = true
}
if (len(addedmodes) == 0 && len(removedmodes) == 0) {
if len(addedmodes) == 0 && len(removedmodes) == 0 {
addedmodes = c.modes
}
@ -362,27 +362,27 @@ func (s *Server) handleRead(c *Client) {
s.partAllChannels(c.identifier)
return
}
if (msg.Command != irc.PING && msg.Command != irc.PONG) {
if msg.Command != irc.PING && msg.Command != irc.PONG {
fmt.Println(c.identifier, "<-", fmt.Sprintf("%s", msg))
}
if (msg.Command == irc.CAP && len(msg.Params) > 0 && len(msg.Params[0]) > 0 && msg.Params[0] == irc.CAP_LS) {
if msg.Command == irc.CAP && len(msg.Params) > 0 && len(msg.Params[0]) > 0 && msg.Params[0] == irc.CAP_LS {
c.writebuffer <- &irc.Message{&anonirc, irc.CAP, []string{msg.Params[0], "userhost-in-names"}}
} else if (msg.Command == irc.CAP && len(msg.Params) > 0 && len(msg.Params[0]) > 0 && msg.Params[0] == irc.CAP_REQ) {
} else if msg.Command == irc.CAP && len(msg.Params) > 0 && len(msg.Params[0]) > 0 && msg.Params[0] == irc.CAP_REQ {
if strings.Contains(msg.Trailing(), "userhost-in-names") {
c.capHostInNames = true
}
c.writebuffer <- &irc.Message{&anonirc, irc.CAP, []string{irc.CAP_ACK, msg.Trailing()}}
} else if (msg.Command == irc.CAP && len(msg.Params) > 0 && len(msg.Params[0]) > 0 && msg.Params[0] == irc.CAP_LIST) {
} else if msg.Command == irc.CAP && len(msg.Params) > 0 && len(msg.Params[0]) > 0 && msg.Params[0] == irc.CAP_LIST {
caps := []string{}
if c.capHostInNames {
caps = append(caps, "userhost-in-names")
}
c.writebuffer <- &irc.Message{&anonirc, irc.CAP, []string{msg.Params[0], strings.Join(caps, " ")}}
} else if (msg.Command == irc.PING) {
} else if msg.Command == irc.PING {
c.writebuffer <- &irc.Message{&anonirc, irc.PONG + " AnonIRC", []string{msg.Trailing()}}
} else if (msg.Command == irc.NICK && c.nick == "*" && len(msg.Params) > 0 && len(msg.Params[0]) > 0 && msg.Params[0] != "" && msg.Params[0] != "*") {
} else if msg.Command == irc.NICK && c.nick == "*" && len(msg.Params) > 0 && len(msg.Params[0]) > 0 && msg.Params[0] != "" && msg.Params[0] != "*" {
c.nick = strings.Trim(msg.Params[0], "\"")
} else if (msg.Command == irc.USER && c.user == "" && len(msg.Params) >= 3 && msg.Params[0] != "" && msg.Params[2] != "") {
} else if msg.Command == irc.USER && c.user == "" && len(msg.Params) >= 3 && msg.Params[0] != "" && msg.Params[2] != "" {
c.user = strings.Trim(msg.Params[0], "\"")
c.host = strings.Trim(msg.Params[2], "\"")
@ -394,9 +394,9 @@ func (s *Server) handleRead(c *Client) {
motdsplit := strings.Split(motd, "\n")
for i, motdmsg := range motdsplit {
var motdcode string
if (i == 0) {
if i == 0 {
motdcode = irc.RPL_MOTDSTART
} else if (i < len(motdsplit) - 1) {
} else if i < len(motdsplit)-1 {
motdcode = irc.RPL_MOTD
} else {
motdcode = irc.RPL_ENDOFMOTD
@ -405,7 +405,7 @@ func (s *Server) handleRead(c *Client) {
}
s.joinChannel("#", c.identifier)
} else if (msg.Command == irc.LIST) {
} else if msg.Command == irc.LIST {
var ccount int
chans := make(map[string]int)
for channelname, channel := range s.channels {
@ -420,15 +420,15 @@ func (s *Server) handleRead(c *Client) {
c.writebuffer <- &irc.Message{&anonirc, irc.RPL_LIST, []string{pl.Key, strconv.Itoa(pl.Value), "[" + s.channels[pl.Key].printModes(s.channels[pl.Key].modes, nil) + "] " + s.channels[pl.Key].topic}}
}
c.writebuffer <- &irc.Message{&anonirc, irc.RPL_LISTEND, []string{"End of /LIST"}}
} else if (msg.Command == irc.JOIN && len(msg.Params) > 0 && len(msg.Params[0]) > 0 && msg.Params[0][0] == '#') {
} else if msg.Command == irc.JOIN && len(msg.Params) > 0 && len(msg.Params[0]) > 0 && msg.Params[0][0] == '#' {
for _, channel := range strings.Split(msg.Params[0], ",") {
s.joinChannel(channel, c.identifier)
}
} else if (msg.Command == irc.NAMES && len(msg.Params) > 0 && len(msg.Params[0]) > 0 && msg.Params[0][0] == '#') {
} else if msg.Command == irc.NAMES && len(msg.Params) > 0 && len(msg.Params[0]) > 0 && msg.Params[0][0] == '#' {
for _, channel := range strings.Split(msg.Params[0], ",") {
s.sendNames(channel, c.identifier)
}
} else if (msg.Command == irc.WHO && len(msg.Params) > 0 && len(msg.Params[0]) > 0 && msg.Params[0][0] == '#') {
} else if msg.Command == irc.WHO && len(msg.Params) > 0 && len(msg.Params[0]) > 0 && msg.Params[0][0] == '#' {
var ccount int
for _, channel := range strings.Split(msg.Params[0], ",") {
if s.inChannel(channel, c.identifier) {
@ -446,21 +446,21 @@ func (s *Server) handleRead(c *Client) {
c.writebuffer <- &irc.Message{&anonirc, irc.RPL_ENDOFWHO, []string{channel, "End of /WHO list."}}
}
}
} else if (msg.Command == irc.MODE) {
} else if msg.Command == irc.MODE {
if len(msg.Params) == 2 && msg.Params[0][0] == '#' && msg.Params[1] == "b" {
c.writebuffer <- &irc.Message{&anonirc, irc.RPL_ENDOFBANLIST, []string{msg.Params[0], "End of Channel Ban List"}}
} else {
s.handleMode(c, msg.Params)
}
} else if (msg.Command == irc.TOPIC && len(msg.Params) > 0 && len(msg.Params[0]) > 0) {
} else if msg.Command == irc.TOPIC && len(msg.Params) > 0 && len(msg.Params[0]) > 0 {
s.handleTopic(msg.Params[0], c.identifier, msg.Trailing())
} else if (msg.Command == irc.PRIVMSG && len(msg.Params) > 0 && len(msg.Params[0]) > 0) {
} else if msg.Command == irc.PRIVMSG && len(msg.Params) > 0 && len(msg.Params[0]) > 0 {
s.handlePrivmsg(msg.Params[0], c.identifier, msg.Trailing())
} else if (msg.Command == irc.PART && len(msg.Params) > 0 && len(msg.Params[0]) > 0 && msg.Params[0][0] == '#') {
} else if msg.Command == irc.PART && len(msg.Params) > 0 && len(msg.Params[0]) > 0 && msg.Params[0][0] == '#' {
for _, channel := range strings.Split(msg.Params[0], ",") {
s.partChannel(channel, c.identifier, "")
}
} else if (msg.Command == irc.QUIT) {
} else if msg.Command == irc.QUIT {
s.partAllChannels(c.identifier)
}
}
@ -479,7 +479,7 @@ func (s *Server) handleWrite(c *Client) {
msg.Params = append([]string{c.nick}, msg.Params...)
}
if (msg.Command != irc.PING && msg.Command != irc.PONG) {
if msg.Command != irc.PING && msg.Command != irc.PONG {
fmt.Println(c.identifier, "->", msg)
}
c.writer.Encode(msg)
@ -534,7 +534,7 @@ func (s *Server) listenSSL() {
log.Fatalf("Failed to load SSL certificate: %v", err)
}
listen, err := tls.Listen("tcp", ":6697", &tls.Config{Certificates:[]tls.Certificate{cert}})
listen, err := tls.Listen("tcp", ":6697", &tls.Config{Certificates: []tls.Certificate{cert}})
if err != nil {
log.Fatalf("Failed to listen: %v", err)
}