Browse Source

Compile ODYSSEY text into binary

master
Trevor Slocum 2 years ago
parent
commit
d779d380fe
  1. 6
      main.go
  2. 25
      odyssey.go
  3. 44
      server.go

6
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()
}

25
ODYSSEY → 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.
subscribe to our email newsletter to hear about new eBooks.`

44
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()

Loading…
Cancel
Save