|
|
@@ -2,15 +2,16 @@
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
+ "flag"
|
|
|
"fmt"
|
|
|
"log"
|
|
|
- "math/rand"
|
|
|
"net/http"
|
|
|
"os"
|
|
|
- "time"
|
|
|
+ "strconv"
|
|
|
|
|
|
extStomp "github.com/go-stomp/stomp"
|
|
|
|
|
|
+ bcFlag "battlecamp-go-server/flag"
|
|
|
"battlecamp-go-server/games"
|
|
|
"battlecamp-go-server/stomp"
|
|
|
)
|
|
|
@@ -20,6 +21,17 @@ var stompConnection *extStomp.Conn
|
|
|
|
|
|
func main() {
|
|
|
fmt.Println("Game server version 0.1")
|
|
|
+
|
|
|
+ initLogging()
|
|
|
+
|
|
|
+ initCliFlags()
|
|
|
+
|
|
|
+ initStompConnection()
|
|
|
+
|
|
|
+ log.Fatal(http.ListenAndServe(":"+strconv.Itoa(*bcFlag.Port), newUrlRouter()))
|
|
|
+}
|
|
|
+
|
|
|
+func initLogging() {
|
|
|
logFile, err := os.Create("server.log")
|
|
|
|
|
|
if err == nil {
|
|
|
@@ -28,9 +40,14 @@ func main() {
|
|
|
log.Println("ERROR: Cannot open log file, using console.")
|
|
|
log.Printf("%v=n", err)
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+func initCliFlags() {
|
|
|
+ bcFlag.CreateFlags()
|
|
|
+ flag.Parse()
|
|
|
+}
|
|
|
|
|
|
- rand.Seed(time.Now().UnixNano())
|
|
|
- stompConnection = stomp.DailStomp()
|
|
|
+func initStompConnection() {
|
|
|
+ stompConnection = stomp.DailStomp(*bcFlag.StompUrl)
|
|
|
defer stompConnection.Disconnect()
|
|
|
- log.Fatal(http.ListenAndServe(":8080", newUrlRouter()))
|
|
|
}
|