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:
parent
69746e7c92
commit
639a50fca0
|
@ -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}
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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())
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -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
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package shared
|
||||
|
||||
import "strconv"
|
||||
|
||||
func IsNumber(s string) bool {
|
||||
if _, err := strconv.Atoi(s); err == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
Loading…
Reference in New Issue