diff --git a/habbgo/main.go b/habbgo/main.go index a81519f..3b342d9 100644 --- a/habbgo/main.go +++ b/habbgo/main.go @@ -1,16 +1,37 @@ package main import ( + "database/sql" + _ "github.com/go-sql-driver/mysql" + "github.com/jtieri/HabbGo/habbgo/config" "github.com/jtieri/HabbGo/habbgo/server" - "github.com/jtieri/HabbGo/habbgo/utils" "log" + "strconv" ) func main() { - //log.Println(string(encoding.EncodeB64(206, 2))) log.Println("Booting up HabbGo... ") - config := utils.LoadConfig() - gameServer := server.New(&config) + + log.Println("Loading config file... ") + c := config.LoadConfig() + + log.Println("Attempting to make connection with the database... ") + db, err := sql.Open("mysql", c.Database.User+":"+c.Database.Password+"@tcp"+ + "("+c.Database.Host+":"+strconv.Itoa(int(c.Database.Port))+")"+"/"+c.Database.Name) + + if err != nil { + log.Fatal(err) + } + + err = db.Ping() + if err != nil { + log.Fatalf("Failed to connect to database %v at %v:%v %v", c.Database.Name, c.Database.Host, c.Database.Port, err) + } + defer db.Close() + log.Printf("Successfully connected to database %v at %v:%v ", c.Database.Name, c.Database.Host, c.Database.Port) + + log.Println("Starting the game server... ") + gameServer := server.New(&c, db) gameServer.Start() defer gameServer.Stop() }