-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
45 lines (35 loc) · 918 Bytes
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"log"
"math/rand"
"net/http"
"time"
"golang.org/x/net/websocket"
"github.com/julienschmidt/httprouter"
)
var totalMobs int
var totalMaps int
func main() {
rand.Seed(time.Now().UnixNano())
mapChan := make(chan bool)
go startMapServer(mapChan)
<-mapChan
fmt.Println("Total Maps loaded:", totalMaps)
fmt.Println("Total Monsters loaded:", totalMobs)
go startWebSocketServer()
startHTTPServer()
}
func startHTTPServer() {
router := httprouter.New()
router.GET("/", HomeHandler)
router.ServeFiles("/src/*filepath", http.Dir("./public"))
log.Fatal(http.ListenAndServe(":8080", router))
}
func startWebSocketServer() {
WSMux := http.NewServeMux()
WSMux.Handle("/ws/getMap", websocket.Handler(getMap))
WSMux.Handle("/ws/getMob", websocket.Handler(getMob))
WSMux.Handle("/ws/getPlayer", websocket.Handler(getPlayer))
log.Fatal(http.ListenAndServe(":9020", WSMux))
}