Some tweaking

This commit is contained in:
Harry Jeffery 2013-08-24 08:36:57 +01:00
parent a2f8d79c75
commit e4261d73b8
3 changed files with 17 additions and 30 deletions

View File

@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"log"
"sort"
"strings"
"time"
@ -159,8 +158,6 @@ func (c *Client) reply(code int, args ...string) {
}
func (c *Client) clientThread() {
defer c.connection.Close()
readSignalChan := make(chan int, 3)
writeSignalChan := make(chan int, 3)
writeChan := make(chan string, 100)
@ -175,6 +172,8 @@ func (c *Client) clientThread() {
}
delete(c.server.clientMap, c.nick)
c.connection.Close()
}()
for {
@ -188,10 +187,9 @@ func (c *Client) clientThread() {
case line := <-c.outputChan:
select {
case writeChan <- line:
//It worked
continue
default:
log.Printf("Dropped a line for client: %q", c.nick)
//Do nothing, dropping the line
c.disconnect()
}
}
}

20
main.go
View File

@ -8,17 +8,16 @@ import (
"strings"
)
var (
tlsKeyFile = flag.String("tls-key", "tls.key", "The private key file used for TLS")
tlsCertFile = flag.String("tls-cert", "tls.crt", "The certificate file used for TLS")
ircAddress = flag.String("irc-address", ":6697", "The address:port to bind to and listen for clients on")
serverName = flag.String("irc-servername", "rosella", "Server name displayed to clients")
authFile = flag.String("irc-authfile", "", "File containing usernames and passwords of operators.")
)
func main() {
tlsKeyFile := flag.String("tls-key", "tls.key", "The private key file used for TLS")
tlsCertFile := flag.String("tls-cert", "tls.crt", "The certificate file used for TLS")
ircAddress := flag.String("irc-address", ":6697", "The address:port to bind to and listen for clients on")
serverName := flag.String("irc-servername", "rosella", "Server name displayed to clients")
authFile := flag.String("irc-authfile", "", "File containing usernames and passwords of operators.")
flag.Parse()
log.Printf("Rosella Initialising.")
@ -52,7 +51,8 @@ func main() {
}
}
}
server.Run()
go server.Run()
tlsConfig := new(tls.Config)

View File

@ -4,7 +4,6 @@ import (
"crypto/sha1"
"fmt"
"io"
"log"
"net"
"regexp"
"strings"
@ -24,19 +23,9 @@ func NewServer() *Server {
}
func (s *Server) Run() {
go func() {
for event := range s.eventChan {
defer func() {
if err := recover(); err != nil {
log.Printf("Recovered from panic()")
log.Printf("%s sent %q", event.client.nick, event.input)
log.Println(err)
}
}()
s.handleEvent(<-s.eventChan)
}
}()
}
func (s *Server) HandleConnection(conn net.Conn) {