From d779d380fe55f38303850eab528dd51f66d07824 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Wed, 10 Jul 2019 01:17:35 -0700 Subject: [PATCH] Compile ODYSSEY text into binary --- main.go | 6 ------ ODYSSEY => odyssey.go | 25 ++++++++++++++++++++++-- server.go | 44 ++++++++----------------------------------- 3 files changed, 31 insertions(+), 44 deletions(-) rename ODYSSEY => odyssey.go (99%) diff --git a/main.go b/main.go index dd5c75b..bc52feb 100644 --- a/main.go +++ b/main.go @@ -100,11 +100,5 @@ func main() { } }() - s.odyssey, err = os.Open("ODYSSEY") - if err != nil { - log.Fatal(err) - } - defer s.odyssey.Close() - s.listen() } diff --git a/ODYSSEY b/odyssey.go similarity index 99% rename from ODYSSEY rename to odyssey.go index 3d56458..3fae548 100644 --- a/ODYSSEY +++ b/odyssey.go @@ -1,4 +1,25 @@ -Tell me, O Muse, of that ingenious hero who travelled far and wide after +package main + +func readOdyssey(line int) string { + var out string + + currentline := 1 + for _, char := range odyssey { + if currentline == line { + if char == '\n' { + break + } + + out += string(char) + } else if char == '\n' { + currentline++ + } + } + + return out +} + +var odyssey = `Tell me, O Muse, of that ingenious hero who travelled far and wide after he had sacked the famous town of Troy. Many cities did he visit, and many were the nations with whose manners and customs he was acquainted; moreover he suffered much by sea while trying to save his own life and @@ -10259,4 +10280,4 @@ Most people start at our Web site which has the main PG search facility: This Web site includes information about Project Gutenberg-tm, including how to make donations to the Project Gutenberg Literary Archive Foundation, how to help produce our new eBooks, and how to -subscribe to our email newsletter to hear about new eBooks. \ No newline at end of file +subscribe to our email newsletter to hear about new eBooks.` diff --git a/server.go b/server.go index 9eecce5..7456c53 100644 --- a/server.go +++ b/server.go @@ -1,7 +1,6 @@ package main import ( - "bufio" "crypto/tls" "encoding/base64" "fmt" @@ -148,14 +147,12 @@ type Config struct { } type Server struct { - config *Config - configfile string - created int64 - motd []string - clients *sync.Map - channels *sync.Map - odyssey *os.File - odysseymutex *sync.RWMutex + config *Config + configfile string + created int64 + motd []string + clients *sync.Map + channels *sync.Map restartplain chan bool restartssl chan bool @@ -172,7 +169,6 @@ func NewServer(configfile string) *Server { s.created = time.Now().Unix() s.clients = new(sync.Map) s.channels = new(sync.Map) - s.odysseymutex = new(sync.RWMutex) s.restartplain = make(chan bool, 1) s.restartssl = make(chan bool, 1) @@ -1283,12 +1279,12 @@ func (s *Server) handleRead(c *Client) { whoisnick += strconv.Itoa(whoisindex) } - easteregg := s.readOdyssey(whoisindex) + easteregg := readOdyssey(whoisindex) if easteregg == "" { easteregg = "I am the owner of my actions, heir of my actions, actions are the womb (from which I have sprung), actions are my relations, actions are my protection. Whatever actions I do, good or bad, of these I shall become the heir." } - c.writeMessage(irc.RPL_AWAY, []string{whoisnick, easteregg}) + c.writeMessage(irc.RPL_WHOISUSER, []string{whoisnick, "Anon", "IRC", "*", easteregg}) c.writeMessage(irc.RPL_ENDOFWHOIS, []string{whoisnick, "End of /WHOIS list."}) }() } else if msg.Command == irc.ISON { @@ -1600,30 +1596,6 @@ func (s *Server) reload() error { return nil } -func (s *Server) readOdyssey(line int) string { - s.odysseymutex.Lock() - defer s.odysseymutex.Unlock() - - scanner := bufio.NewScanner(s.odyssey) - currentline := 1 - for scanner.Scan() { - if currentline == line { - s.odyssey.Seek(0, 0) - return scanner.Text() - } - - currentline++ - } - - if err := scanner.Err(); err != nil { - log.Printf("Failed to read ODYSSEY: %v", err) - return "" - } - - s.odyssey.Seek(0, 0) - return "" -} - func (s *Server) listen() { go s.listenPlain() go s.listenSSL()