2015-01-17 01:37:21 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
2015-02-02 23:25:52 +00:00
|
|
|
"strings"
|
2015-01-17 01:37:21 +00:00
|
|
|
"sync"
|
|
|
|
|
2015-02-02 23:25:52 +00:00
|
|
|
"github.com/julienschmidt/httprouter"
|
2015-01-17 01:37:21 +00:00
|
|
|
"golang.org/x/net/websocket"
|
|
|
|
|
2015-01-21 21:59:08 +00:00
|
|
|
"github.com/khlieng/name_pending/storage"
|
2015-01-17 01:37:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
channelStore *storage.ChannelStore
|
|
|
|
sessions map[string]*Session
|
|
|
|
sessionLock sync.Mutex
|
2015-02-02 23:25:52 +00:00
|
|
|
fs http.Handler
|
2015-01-17 01:37:21 +00:00
|
|
|
)
|
|
|
|
|
2015-02-02 23:25:52 +00:00
|
|
|
func serveFiles(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if strings.HasSuffix(r.URL.Path, "bundle.js") {
|
|
|
|
r.URL.Path = "/bundle.js"
|
|
|
|
} else if strings.HasSuffix(r.URL.Path, "style.css") {
|
|
|
|
r.URL.Path = "/style.css"
|
|
|
|
} else {
|
|
|
|
r.URL.Path = "/"
|
|
|
|
}
|
|
|
|
|
|
|
|
fs.ServeHTTP(w, r)
|
|
|
|
}
|
|
|
|
|
2015-01-17 01:37:21 +00:00
|
|
|
func main() {
|
|
|
|
defer storage.Cleanup()
|
|
|
|
|
|
|
|
channelStore = storage.NewChannelStore()
|
|
|
|
sessions = make(map[string]*Session)
|
2015-02-02 23:25:52 +00:00
|
|
|
fs = http.FileServer(http.Dir("client/dist"))
|
2015-01-17 01:37:21 +00:00
|
|
|
|
|
|
|
/*for _, user := range storage.LoadUsers() {
|
|
|
|
channels := user.GetChannels()
|
|
|
|
|
|
|
|
for _, server := range user.GetServers() {
|
|
|
|
session := NewSession()
|
|
|
|
session.user = user
|
|
|
|
sessions[user.UUID] = session
|
|
|
|
|
|
|
|
irc := NewIRC(server.Nick, server.Username)
|
2015-02-02 00:54:26 +00:00
|
|
|
irc.TLS = server.TLS
|
2015-01-17 01:37:21 +00:00
|
|
|
irc.Connect(server.Address)
|
|
|
|
|
|
|
|
session.setIRC(irc.Host, irc)
|
|
|
|
|
|
|
|
go session.write()
|
|
|
|
go handleMessages(irc, session)
|
|
|
|
|
|
|
|
var joining []string
|
|
|
|
for _, channel := range channels {
|
|
|
|
if channel.Server == server.Address {
|
|
|
|
joining = append(joining, channel.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
irc.Join(joining...)
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
2015-02-02 23:25:52 +00:00
|
|
|
router := httprouter.New()
|
|
|
|
|
|
|
|
router.Handler("GET", "/ws", websocket.Handler(handleWS))
|
|
|
|
router.NotFound = serveFiles
|
2015-01-17 01:37:21 +00:00
|
|
|
|
|
|
|
log.Println("Listening on port 1337")
|
2015-02-02 23:25:52 +00:00
|
|
|
http.ListenAndServe(":1337", router)
|
2015-01-17 01:37:21 +00:00
|
|
|
}
|