Browse Source

Run gofmt on source files

master
Trevor Slocum 6 years ago
parent
commit
5f2275700d
  1. 1
      .gitignore
  2. 5
      anonircd.go
  3. 2
      channel.go
  4. 18
      client.go
  5. 4
      entity.go
  6. 56
      server.go

1
.gitignore vendored

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

5
anonircd.go

@ -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 = `
_|_| _|_|_| _|_|_| _|_|_|

2
channel.go

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

18
client.go

@ -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) {

4
entity.go

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

56
server.go

@ -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)
}

Loading…
Cancel
Save