2019-11-27 07:28:20 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-09-09 02:14:06 +00:00
|
|
|
"database/sql"
|
|
|
|
"fmt"
|
2021-09-19 03:24:51 +00:00
|
|
|
"log"
|
|
|
|
|
2019-12-13 07:17:28 +00:00
|
|
|
_ "github.com/go-sql-driver/mysql"
|
2021-09-19 03:24:51 +00:00
|
|
|
"github.com/jtieri/HabbGo/habbgo/app"
|
2019-12-13 07:17:28 +00:00
|
|
|
"github.com/jtieri/HabbGo/habbgo/config"
|
2019-11-27 07:28:20 +00:00
|
|
|
"github.com/jtieri/HabbGo/habbgo/server"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2019-12-04 03:13:18 +00:00
|
|
|
log.Println("Booting up HabbGo... ")
|
2019-12-13 07:17:28 +00:00
|
|
|
|
|
|
|
log.Println("Loading config file... ")
|
2021-09-06 02:48:30 +00:00
|
|
|
c := config.LoadConfig("config.yml")
|
2019-12-13 07:17:28 +00:00
|
|
|
|
|
|
|
log.Println("Attempting to make connection with the database... ")
|
2021-09-09 02:14:06 +00:00
|
|
|
host := fmt.Sprintf("%v:%v@tcp(%v:%v)/%v", c.DB.User, c.DB.Password, c.DB.Host, c.DB.Port, c.DB.Name)
|
|
|
|
|
|
|
|
db, err := sql.Open("mysql", host)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-09-19 03:24:51 +00:00
|
|
|
// Check that the connection to the DB is alive
|
|
|
|
if err = db.Ping(); err != nil {
|
2021-09-09 02:14:06 +00:00
|
|
|
log.Fatalf("Failed to connect to database %v at %v:%v %v", c.DB.Name, c.DB.Host, c.DB.Port, err)
|
2019-12-13 07:17:28 +00:00
|
|
|
}
|
2021-09-09 02:14:06 +00:00
|
|
|
defer db.Close()
|
|
|
|
log.Printf("Successfully connected to database %v at %v:%v ", c.DB.Name, c.DB.Host, c.DB.Port)
|
|
|
|
|
2021-09-19 03:24:51 +00:00
|
|
|
// Create the global App context for accessing Config and DB across the server
|
|
|
|
app.New(c, db)
|
2019-12-30 00:04:33 +00:00
|
|
|
|
2021-09-09 02:14:06 +00:00
|
|
|
log.Println("Starting the game server... ")
|
2021-09-19 03:24:51 +00:00
|
|
|
gameServer := server.New()
|
2019-11-27 07:28:20 +00:00
|
|
|
gameServer.Start()
|
2019-12-30 00:04:33 +00:00
|
|
|
|
2019-11-27 07:28:20 +00:00
|
|
|
defer gameServer.Stop()
|
|
|
|
}
|