habbgo/main.go

41 lines
963 B
Go
Raw Normal View History

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"
_ "github.com/go-sql-driver/mysql"
2022-01-08 14:35:12 +00:00
2022-01-08 22:29:51 +00:00
"github.com/jtieri/HabbGo/config"
"github.com/jtieri/HabbGo/server"
2019-11-27 07:28:20 +00:00
)
func main() {
2019-12-04 03:13:18 +00:00
log.Println("Booting up HabbGo... ")
log.Println("Loading config file... ")
2021-09-06 02:48:30 +00:00
c := config.LoadConfig("config.yml")
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)
}
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)
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-11-27 07:28:20 +00:00
defer gameServer.Stop()
}