WIP: remove sql-driver for gorm

This commit is contained in:
jtieri 2021-09-05 21:19:02 -05:00
parent b8636f8eae
commit 9ed04d4f94
17 changed files with 246 additions and 222 deletions

11
config.yaml Normal file
View File

@ -0,0 +1,11 @@
server:
host: 127.0.0.1
port: 11235
maxconns: 2
debug: true
db:
user: ""
password: ""
host: ""
port: 0
name: ""

2
go.mod
View File

@ -6,4 +6,6 @@ require (
github.com/go-sql-driver/mysql v1.6.0
github.com/stretchr/testify v1.7.0
gopkg.in/yaml.v2 v2.4.0
gorm.io/driver/sqlite v1.1.4
gorm.io/gorm v1.21.6
)

12
go.sum
View File

@ -2,6 +2,13 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.2 h1:eVKgfIdy9b6zbWBMgFpfDPoAMifwSZagU9HmEU6zgiI=
github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/mattn/go-sqlite3 v1.14.5 h1:1IdxlwTNazvbKJQSxoJ5/9ECbEeaTTyeU7sEAZ5KKTQ=
github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@ -13,3 +20,8 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/sqlite v1.1.4 h1:PDzwYE+sI6De2+mxAneV9Xs11+ZyKV6oxD3wDGkaNvM=
gorm.io/driver/sqlite v1.1.4/go.mod h1:mJCeTFr7+crvS+TRnWc5Z3UvwxUN1BGBLMrf5LA9DYw=
gorm.io/gorm v1.20.7/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
gorm.io/gorm v1.21.6 h1:xEFbH7WShsnAM+HeRNv7lOeyqmDAK+dDnf1AMf/cVPQ=
gorm.io/gorm v1.21.6/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=

11
habbgo/config/config.yaml Normal file
View File

@ -0,0 +1,11 @@
server:
host: 127.0.0.1
port: 11235
maxconns: 2
debug: true
db:
user: ""
password: ""
host: ""
port: 0
name: ""

View File

@ -1,39 +1,37 @@
package database
import (
"database/sql"
"github.com/jtieri/HabbGo/habbgo/game/model"
"log"
"gorm.io/gorm"
)
type NavRepo struct {
database *sql.DB
database gorm.DB
}
// NewNavRepo returns a new instance of NavRepo for use in the navigator service.
func NewNavRepo(db *sql.DB) *NavRepo {
func NewNavRepo(db gorm.DB) *NavRepo {
return &NavRepo{database: db}
}
// Categories retrieves the navigator categories found in database table room_categories and returns them as a slice of
// Category structs.
func (navRepo *NavRepo) Categories() []model.Category {
rows, err := navRepo.database.Query("SELECT * FROM room_categories")
if err != nil {
log.Printf("%v", err)
}
defer rows.Close()
var categories []model.Category
for rows.Next() {
var cat model.Category
err = rows.Scan(&cat.Id, &cat.Pid, &cat.Node, &cat.Name, &cat.Public, &cat.Trading, &cat.MinRankAccess)
if err != nil {
log.Printf("%v", err)
}
categories = append(categories, cat)
}
return categories
}
//func (navRepo *NavRepo) Categories() []model.Category {
// rows, err := navRepo.database.Query("SELECT * FROM room_categories")
// if err != nil {
// log.Printf("%v", err)
// }
// defer rows.Close()
//
// var categories []model.Category
// for rows.Next() {
// var cat model.Category
// err = rows.Scan(&cat.Id, &cat.Pid, &cat.Node, &cat.Name, &cat.Public, &cat.Trading, &cat.MinRankAccess)
// if err != nil {
// log.Printf("%v", err)
// }
//
// categories = append(categories, cat)
// }
//
// return categories
//}

View File

@ -1,60 +1,55 @@
package database
import (
"github.com/jtieri/HabbGo/habbgo/game/model"
"log"
)
//func Login(player *model.Player, username string, password string) bool {
// var pw, name string
// err := player.Session.Database().QueryRow("SELECT P.passwrd, P.username FROM Players P WHERE P.username = ?", username).Scan(&pw, &name)
//
// if err != nil {
// log.Printf("%v ", err) // TODO log database errors properly
// }
//
// if password == pw {
// player.Details.Username = name
// fillDetails(player)
// return true
// }
//
// return false
//}
func Login(player *model.Player, username string, password string) bool {
var pw, name string
err := player.Session.Database().QueryRow("SELECT P.passwrd, P.username FROM Players P WHERE P.username = ?", username).Scan(&pw, &name)
//func LoadBadges(player *model.Player) {
// rows, err := player.Session.Database().Query("SELECT P.badge FROM Players_Badges P WHERE P.pid = ?", player.Details.Id)
// if err != nil {
// log.Printf("%v ", err) // TODO properly log error
// }
// defer rows.Close()
//
// var badges []string
// for rows.Next() {
// var badge string
// err := rows.Scan(&badge)
// if err != nil {
// log.Printf("%v ", err) // TODO properly log error
// }
//
// badges = append(badges, badge)
// }
//
// player.Details.Badges = badges
//}
if err != nil {
log.Printf("%v ", err) // TODO log database errors properly
}
if password == pw {
player.Details.Username = name
fillDetails(player)
return true
}
return false
}
func LoadBadges(player *model.Player) {
rows, err := player.Session.Database().Query("SELECT P.badge FROM Players_Badges P WHERE P.pid = ?", player.Details.Id)
if err != nil {
log.Printf("%v ", err) // TODO properly log error
}
defer rows.Close()
var badges []string
for rows.Next() {
var badge string
err := rows.Scan(&badge)
if err != nil {
log.Printf("%v ", err) // TODO properly log error
}
badges = append(badges, badge)
}
player.Details.Badges = badges
}
func fillDetails(p *model.Player) {
query := "SELECT P.id, P.username, P.sex, P.figure, P.pool_figure, P.film, P.credits, P.tickets, P.motto, " +
"P.console_motto, P.current_badge, P.display_badge, P.last_online, P.sound_enabled " +
"FROM Players P " +
"WHERE P.username = ?"
err := p.Session.Database().QueryRow(query, p.Details.Username).Scan(&p.Details.Id, &p.Details.Username,
&p.Details.Sex, &p.Details.Figure, &p.Details.PoolFigure, &p.Details.Film, &p.Details.Credits,
&p.Details.Tickets, &p.Details.Motto, &p.Details.ConsoleMotto, &p.Details.CurrentBadge, &p.Details.DisplayBadge,
&p.Details.LastOnline, &p.Details.SoundEnabled)
if err != nil {
log.Printf("%v ", err) // TODO log database errors properly
}
}
//func fillDetails(p *model.Player) {
// query := "SELECT P.id, P.username, P.sex, P.figure, P.pool_figure, P.film, P.credits, P.tickets, P.motto, " +
// "P.console_motto, P.current_badge, P.display_badge, P.last_online, P.sound_enabled " +
// "FROM Players P " +
// "WHERE P.username = ?"
//
// err := p.Session.Database().QueryRow(query, p.Details.Username).Scan(&p.Details.Id, &p.Details.Username,
// &p.Details.Sex, &p.Details.Figure, &p.Details.PoolFigure, &p.Details.Film, &p.Details.Credits,
// &p.Details.Tickets, &p.Details.Motto, &p.Details.ConsoleMotto, &p.Details.CurrentBadge, &p.Details.DisplayBadge,
// &p.Details.LastOnline, &p.Details.SoundEnabled)
//
// if err != nil {
// log.Printf("%v ", err) // TODO log database errors properly
// }
//}

View File

@ -1,51 +1,50 @@
package database
import (
"database/sql"
"github.com/jtieri/HabbGo/habbgo/game/model"
"log"
"gorm.io/gorm"
)
type RoomRepo struct {
database *sql.DB
database gorm.DB
}
func NewRoomRepo(db *sql.DB) *RoomRepo {
func NewRoomRepo(db gorm.DB) *RoomRepo {
return &RoomRepo{database: db}
}
func (rr *RoomRepo) RoomsByPlayerId(id int) []*model.Room {
stmt, err := rr.database.Prepare("SELECT r.id, r.cat_id, r.name, r.`desc`, r.ccts, r.wallpaper, r.floor, r.landscape, r.owner_id, r.owner_name, r.show_owner, r.sudo_users, r.access_type, r.password, r.current_visitors, r.max_visitors, r.rating FROM rooms r WHERE r.owner_id = ?")
if err != nil {
log.Printf("%v", err)
}
defer stmt.Close()
rows, err := stmt.Query(id)
if err != nil {
log.Printf("%v", err)
}
defer rows.Close()
var rooms []*model.Room
for rows.Next() {
room := new(model.Room)
room.Details = new(model.Data)
err := rows.Scan(&room.Details.Id, &room.Details.CatId, &room.Details.Name, &room.Details.Desc, &room.Details.CCTs,
&room.Details.Wallpaper, &room.Details.Floor, &room.Details.Landscape, &room.Details.Owner_Id, &room.Details.Owner_Name,
&room.Details.ShowOwner, &room.Details.SudoUsers, &room.Details.AccessType, &room.Details.Password,
&room.Details.CurrentVisitors, &room.Details.MaxVisitors, &room.Details.Rating)
if err != nil {
log.Printf("%v", err)
}
rooms = append(rooms, room)
}
return rooms
}
//func (rr *RoomRepo) RoomsByPlayerId(id int) []*model.Room {
// stmt, err := rr.database.Prepare("SELECT r.id, r.cat_id, r.name, r.`desc`, r.ccts, r.wallpaper, r.floor, r.landscape, r.owner_id, r.owner_name, r.show_owner, r.sudo_users, r.access_type, r.password, r.current_visitors, r.max_visitors, r.rating FROM rooms r WHERE r.owner_id = ?")
// if err != nil {
// log.Printf("%v", err)
// }
// defer stmt.Close()
//
// rows, err := stmt.Query(id)
// if err != nil {
// log.Printf("%v", err)
// }
// defer rows.Close()
//
// var rooms []*model.Room
// for rows.Next() {
// room := new(model.Room)
// room.Details = new(model.Data)
//
// err := rows.Scan(&room.Details.Id, &room.Details.CatId, &room.Details.Name, &room.Details.Desc, &room.Details.CCTs,
// &room.Details.Wallpaper, &room.Details.Floor, &room.Details.Landscape, &room.Details.Owner_Id, &room.Details.Owner_Name,
// &room.Details.ShowOwner, &room.Details.SudoUsers, &room.Details.AccessType, &room.Details.Password,
// &room.Details.CurrentVisitors, &room.Details.MaxVisitors, &room.Details.Rating)
// if err != nil {
// log.Printf("%v", err)
// }
//
// rooms = append(rooms, room)
// }
//
// return rooms
//}
func (rr *RoomRepo) fillData(data *model.Data) {
}
}

View File

@ -1,7 +1,6 @@
package model
import (
"database/sql"
"github.com/jtieri/HabbGo/habbgo/protocol/packets"
)
@ -33,7 +32,6 @@ type Session interface {
Send(packet *packets.OutgoingPacket)
Queue(packet *packets.OutgoingPacket)
Flush(packet *packets.OutgoingPacket)
Database() *sql.DB
Close()
}

View File

@ -1,9 +1,9 @@
package service
import (
"database/sql"
"github.com/jtieri/HabbGo/habbgo/database"
"github.com/jtieri/HabbGo/habbgo/game/model"
"gorm.io/gorm"
"sync"
)
@ -23,7 +23,7 @@ func NavigatorService() *navService {
ns = &navService{
repo: nil,
nav: new(model.Navigator),
mux: &sync.Mutex{},
mux: &sync.Mutex{},
}
})
@ -31,14 +31,14 @@ func NavigatorService() *navService {
}
// SetDBCon is called when a NavService struct is allocated initially so that it has access to the applications db.
func (ns *navService) SetDBCon(db *sql.DB) {
func (ns *navService) SetDBCon(db gorm.DB) {
ns.repo = database.NewNavRepo(db)
}
// BuildNavigator retrieves the room categories from the database and builds the in-game Navigator with them.
func (ns *navService) BuildNavigator() {
ns.nav.Categories = ns.repo.Categories()
}
//func (ns *navService) BuildNavigator() {
// ns.nav.Categories = ns.repo.Categories()
//}
// CategoryById retrieves a navigator category given the int parameter id and returns it if there is a match.
func (ns *navService) CategoryById(id int) *model.Category {

View File

@ -1,7 +1,6 @@
package service
import (
"github.com/jtieri/HabbGo/habbgo/database"
"github.com/jtieri/HabbGo/habbgo/game/model"
)
@ -13,7 +12,7 @@ func Login(player *model.Player) {
// Check if player is banned & if so send USER_BANNED
// Log IP address to Conn
database.LoadBadges(player)
// database.LoadBadges(player)
// If Config has alerts enabled, send player ALERT

View File

@ -1,15 +1,16 @@
package service
import (
"database/sql"
"github.com/jtieri/HabbGo/habbgo/database"
"github.com/jtieri/HabbGo/habbgo/game/model"
"gorm.io/gorm"
"strings"
"sync"
)
var rs *roomService
var ronce sync.Once
const PublicRoomOffset = 1000
type roomService struct {
@ -28,7 +29,7 @@ func RoomService() *roomService {
return rs
}
func (rs *roomService) SetDBConn(db *sql.DB) {
func (rs *roomService) SetDBConn(db gorm.DB) {
rs.repo = database.NewRoomRepo(db)
}
@ -47,9 +48,9 @@ func (rs *roomService) RoomById(id int) *model.Room {
return nil
}
func (rs *roomService) RoomsByPlayerId(id int) []*model.Room {
return rs.repo.RoomsByPlayerId(id)
}
//func (rs *roomService) RoomsByPlayerId(id int) []*model.Room {
// return rs.repo.RoomsByPlayerId(id)
//}
func (rs *roomService) RoomByModelName(name string) *model.Room {
return &model.Room{}
@ -89,13 +90,13 @@ func (rs *roomService) PublicRoom(room *model.Room) bool {
}
func (rs *roomService) PublicName(room *model.Room) string {
if rs.PublicRoom(room) {
if strings.HasPrefix(room.Details.Name, "Upper Hallways") {
if rs.PublicRoom(room) {
if strings.HasPrefix(room.Details.Name, "Upper Hallways") {
return "Upper Hallways"
}
if strings.HasPrefix(room.Details.Name, "Lower Hallways") {
return "Lower Hallways"
return "Lower Hallways"
}
if strings.HasPrefix(room.Details.Name, "Club Massiva") {
@ -103,15 +104,15 @@ func (rs *roomService) PublicName(room *model.Room) string {
}
if strings.HasPrefix(room.Details.Name, "The Chromide Club") {
return "The Chromide Club"
return "The Chromide Club"
}
if room.Details.CCTs == "hh_room_gamehall,hh_games" {
return "Cunning Fox Gamehall"
}
}
}
return room.Details.Name
return room.Details.Name
}
func (rs *roomService) CurrentVisitors() int {
@ -128,6 +129,6 @@ func (rs *roomService) MaxVisitors() int {
func (rs *roomService) LoadChildRooms(room *model.Room) {
if room.Model.Name == "gate_park" {
room.Details.ChildRooms = append(room.Details.ChildRooms, )
room.Details.ChildRooms = append(room.Details.ChildRooms)
}
}
}

View File

@ -1,12 +1,11 @@
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/jtieri/HabbGo/habbgo/config"
"github.com/jtieri/HabbGo/habbgo/game/service"
"github.com/jtieri/HabbGo/habbgo/server"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"log"
)
@ -17,27 +16,34 @@ func main() {
c := config.LoadConfig()
log.Println("Attempting to make connection with the database... ")
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)
db, err := gorm.Open(sqlite.Open(c.DB.Name), &gorm.Config{})
if err != nil {
log.Fatal(err)
log.Fatal("Failed to connect to the database: " + err.Error())
}
err = db.Ping()
if err != nil {
log.Fatalf("Failed to connect to database %v at %v:%v %v", c.DB.Name, c.DB.Host, c.DB.Port, err)
}
defer db.Close()
log.Printf("Successfully connected to database %v at %v:%v ", c.DB.Name, c.DB.Host, c.DB.Port)
/*
host := fmt.Sprintf("%v:%v@tcp(%v:%v)/%v", c.DB.User, c.DB.Password, c.DB.Host, c.DB.Port, c.DB.Name)
log.Printf("Setting up in-game services and models...")
service.NavigatorService().SetDBCon(db)
service.NavigatorService().BuildNavigator()
db, err := sql.Open("mysql", host)
if err != nil {
log.Fatal(err)
}
service.RoomService().SetDBConn(db)
err = db.Ping()
if err != nil {
log.Fatalf("Failed to connect to database %v at %v:%v %v", c.DB.Name, c.DB.Host, c.DB.Port, err)
}
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... ")
//log.Printf("Setting up in-game services and models...")
//service.NavigatorService().SetDBCon(db)
//service.NavigatorService().BuildNavigator()
//
//service.RoomService().SetDBConn(db)
//
//log.Println("Starting the game server... ")
gameServer := server.New(c, db)
gameServer.Start()

View File

@ -1,7 +1,6 @@
package handlers
import (
"github.com/jtieri/HabbGo/habbgo/database"
"github.com/jtieri/HabbGo/habbgo/game/model"
"github.com/jtieri/HabbGo/habbgo/game/service"
"github.com/jtieri/HabbGo/habbgo/protocol/composers"
@ -32,13 +31,13 @@ func HandleSSO(player *model.Player, packet *packets.IncomingPacket) {
}
func HandleTryLogin(player *model.Player, packet *packets.IncomingPacket) {
username := packet.ReadString()
password := packet.ReadString()
//username := packet.ReadString()
//password := packet.ReadString()
if database.Login(player, username, password) {
service.Login(player)
player.Session.Send(composers.ComposeLoginOk())
} else {
// TODO send LOCALISED ERROR
}
//if database.Login(player, username, password) {
// service.Login(player)
// player.Session.Send(composers.ComposeLoginOk())
//} else {
// // TODO send LOCALISED ERROR
//}
}

View File

@ -1,50 +1,43 @@
package handlers
import (
"github.com/jtieri/HabbGo/habbgo/game/model"
"github.com/jtieri/HabbGo/habbgo/game/service"
"github.com/jtieri/HabbGo/habbgo/protocol/composers"
"github.com/jtieri/HabbGo/habbgo/protocol/packets"
)
func HandleNavigate(player *model.Player, packet *packets.IncomingPacket) {
roomService := service.RoomService()
nodeMask := packet.ReadInt()==1
catId := packet.ReadInt()
if catId >= service.PublicRoomOffset {
room := roomService.RoomById(catId - service.PublicRoomOffset)
if room != nil {
catId = room.Details.CatId
}
}
category := service.NavigatorService().CategoryById(catId)
// TODO also check that access rank isnt higher than players rank
if category == nil {
return
}
subCategories := service.NavigatorService().CategoriesByParentId(category.Id)
// sort categories by player count
currentVisitors := service.CurrentVisitors(category)
maxVisitors := service.MaxVisitors(category)
var rooms []*model.Room
if category.Public {
for _, room := range roomService.ReplaceRooms(roomService.RoomsByPlayerId(0)) {
if room.Details.CatId == category.Id && (!nodeMask) && room.Details.CurrentVisitors < room.Details.MaxVisitors {
rooms = append(rooms, room)
}
}
} else {
// TODO finish private room logic
}
// TODO sort rooms by player count before sending NavNodeInfo
player.Session.Send(composers.ComposeNavNodeInfo(player, category, nodeMask, subCategories, rooms, currentVisitors, maxVisitors))
}
//func HandleNavigate(player *model.Player, packet *packets.IncomingPacket) {
// roomService := service.RoomService()
//
// nodeMask := packet.ReadInt()==1
// catId := packet.ReadInt()
//
// if catId >= service.PublicRoomOffset {
// room := roomService.RoomById(catId - service.PublicRoomOffset)
// if room != nil {
// catId = room.Details.CatId
// }
// }
//
// category := service.NavigatorService().CategoryById(catId)
//
// // TODO also check that access rank isnt higher than players rank
// if category == nil {
// return
// }
//
// subCategories := service.NavigatorService().CategoriesByParentId(category.Id)
// // sort categories by player count
//
// currentVisitors := service.CurrentVisitors(category)
// maxVisitors := service.MaxVisitors(category)
//
// var rooms []*model.Room
// if category.Public {
// for _, room := range roomService.ReplaceRooms(roomService.RoomsByPlayerId(0)) {
// if room.Details.CatId == category.Id && (!nodeMask) && room.Details.CurrentVisitors < room.Details.MaxVisitors {
// rooms = append(rooms, room)
// }
// }
// } else {
// // TODO finish private room logic
// }
//
// // TODO sort rooms by player count before sending NavNodeInfo
//
// player.Session.Send(composers.ComposeNavNodeInfo(player, category, nodeMask, subCategories, rooms, currentVisitors, maxVisitors))
//}

View File

@ -41,7 +41,7 @@ func Handle(player *model.Player, packet *packets.IncomingPacket) {
// Navigator Packets ----------------------------------------------------------------------------------------------
case 150: // NAVIGATE
handlers.HandleNavigate(player, packet)
//handlers.HandleNavigate(player, packet)
case 151: // GETUSERFLATCATS
case 21: // GETFLATINFO

View File

@ -1,8 +1,8 @@
package server
import (
"database/sql"
"github.com/jtieri/HabbGo/habbgo/config"
"gorm.io/gorm"
"log"
"net"
"os"
@ -12,12 +12,12 @@ import (
type Server struct {
Config *config.Config
Database *sql.DB
Database *gorm.DB
activeSessions []*Session
}
// New returns a pointer to a newly allocated server struct.
func New(config *config.Config, db *sql.DB) *Server {
func New(config *config.Config, db *gorm.DB) *Server {
return &Server{
Config: config,
Database: db,

View File

@ -3,11 +3,11 @@ package server
import (
"bufio"
"bytes"
"database/sql"
"github.com/jtieri/HabbGo/habbgo/game/model"
"github.com/jtieri/HabbGo/habbgo/protocol/composers"
"github.com/jtieri/HabbGo/habbgo/protocol/encoding"
"github.com/jtieri/HabbGo/habbgo/protocol/packets"
"gorm.io/gorm"
"log"
"net"
"sync"
@ -15,7 +15,7 @@ import (
type Session struct {
connection net.Conn
database *sql.DB
database *gorm.DB
buffer *buffer
active bool
server *Server
@ -135,7 +135,7 @@ func (session *Session) Flush(packet *packets.OutgoingPacket) {
}
// Database returns a pointer to a Session's Conn access struct.
func (session *Session) Database() *sql.DB {
func (session *Session) Database() *gorm.DB {
return session.database
}