WIP: Basic room design

Began work on modeling of rooms in the server as well as start on its related service/database components.
This commit is contained in:
Justin T 2020-01-03 22:38:22 -06:00
parent 69746e7c92
commit 639a50fca0
8 changed files with 111 additions and 10 deletions

View File

@ -45,9 +45,9 @@ func LoadBadges(player *model.Player) {
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 = ?"
"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,

View File

@ -0,0 +1,11 @@
package database
import "database/sql"
type RoomRepo struct {
database *sql.DB
}
func NewRoomRepo(db *sql.DB) *RoomRepo {
return &RoomRepo{database: db}
}

49
habbgo/game/model/room.go Normal file
View File

@ -0,0 +1,49 @@
package model
type Room struct {
Details *Data
Model *Model
Map *Map
}
type Data struct {
Id int
CatId int
Name string
Desc string
CCTs string
Wallpaper int
Floor int
Landscape float32
Owner_Id int
Owner_Name string
ShowOwner bool
SudoUsers bool
HideRoom bool
AccessType int
Password string
CurrentVisitors int
MaxVisitors int
Rating int
CreatedAt string
UpdatedAt string
ChildRooms []*Room
}
type Model struct {
Id int
Name string
DoorX int
DoorY int
DoorZ float32
DoorDirection int
Heightmap string
}
type Map struct {
mapping [][]*Tile
}
type Tile struct {
// May incorporate this into pathfinding later down the line
}

View File

@ -9,10 +9,10 @@ import (
func Login(player *model.Player) {
// Set player logged in & ping ready for latency test
// Possibly add player to a list of online players? Health endpoint with server stats?
// Save current time to DB for players last online time
// Save current time to Conn for players last online time
// Check if player is banned & if so send USER_BANNED
// Log IP address to DB
// Log IP address to Conn
database.LoadBadges(player)
go player.Session.Send(composers.ComposeLoginOk())

View File

@ -0,0 +1,31 @@
package service
import (
"database/sql"
"github.com/jtieri/HabbGo/habbgo/database"
"github.com/jtieri/HabbGo/habbgo/game/model"
"sync"
)
var rs *roomService
var ronce sync.Once
type roomService struct {
repo *database.RoomRepo
rooms []*model.Room
}
func RoomService() *roomService {
ronce.Do(func() {
rs = &roomService{
repo: nil,
rooms: make([]*model.Room, 50),
}
})
return rs
}
func (rs *roomService) SetDBConn(db *sql.DB) {
rs.repo = database.NewRoomRepo(db)
}

View File

@ -2,11 +2,10 @@ package composers
import (
"github.com/jtieri/HabbGo/habbgo/protocol/packets"
"github.com/jtieri/HabbGo/habbgo/utils"
"github.com/jtieri/HabbGo/habbgo/shared"
"strconv"
)
const ( // Used in ComposeSessionParams
registerCoppa = 0 // toggle conf_coppa or conf_strong_coppa_req by setting value > 0 or > 1
voucherEnabled = 1 // Enables in-game vouchers when value is set > 0
@ -26,7 +25,7 @@ func ComposeHello() *packets.OutgoingPacket {
func ComposeCryptoParams() *packets.OutgoingPacket {
packet := packets.NewOutgoing(277) // Base64 Header DU
packet.WriteInt(0) // Toggles server->client encryption; 0=off | non-zero=on
packet.WriteInt(0) // Toggles server->client encryption; 0=off | non-zero=on
return packet
}
@ -55,7 +54,7 @@ func ComposeSessionParams() *packets.OutgoingPacket {
for i, v := range params {
packet.WriteInt(i)
if utils.IsNumber(v) {
if shared.IsNumber(v) {
num, _ := strconv.Atoi(v)
packet.WriteInt(num)
} else {

View File

@ -134,7 +134,7 @@ func (session *Session) Flush(packet *packets.OutgoingPacket) {
}
}
// Database returns a pointer to a Session's DB access struct.
// Database returns a pointer to a Session's Conn access struct.
func (session *Session) Database() *sql.DB {
return session.database
}

11
habbgo/shared/num.go Normal file
View File

@ -0,0 +1,11 @@
package shared
import "strconv"
func IsNumber(s string) bool {
if _, err := strconv.Atoi(s); err == nil {
return true
}
return false
}