habbgo/game/room/room_service.go

133 lines
2.3 KiB
Go
Raw Permalink Normal View History

2021-09-06 02:48:30 +00:00
package room
import (
2021-09-09 02:14:06 +00:00
"database/sql"
"strings"
"sync"
)
var rs *roomService
var ronce sync.Once
2021-09-06 02:19:02 +00:00
const PublicRoomOffset = 1000
type roomService struct {
2021-09-09 02:14:06 +00:00
repo *RoomRepo
2021-09-06 02:48:30 +00:00
rooms map[int]*Room
}
func RoomService() *roomService {
ronce.Do(func() {
rs = &roomService{
2021-09-09 02:14:06 +00:00
repo: nil,
2021-09-06 02:48:30 +00:00
rooms: make(map[int]*Room, 50),
}
})
return rs
}
2021-09-09 02:14:06 +00:00
func (rs *roomService) SetDBConn(db *sql.DB) {
rs.repo = NewRoomRepo(db)
}
2021-09-06 02:48:30 +00:00
func (rs *roomService) Rooms() []*Room {
var rooms []*Room
for _, room := range rs.rooms {
rooms = append(rooms, room)
}
return rooms
}
2021-09-06 02:48:30 +00:00
func (rs *roomService) RoomById(id int) *Room {
if room, ok := rs.rooms[id]; ok {
return room
}
return nil
}
2021-09-09 02:14:06 +00:00
func (rs *roomService) RoomsByPlayerId(id int) []*Room {
return rs.repo.RoomsByPlayerId(id)
}
2021-09-06 02:48:30 +00:00
func (rs *roomService) RoomByModelName(name string) *Room {
return &Room{}
}
2021-09-06 02:48:30 +00:00
func (rs *roomService) ReplaceRooms(queryRooms []*Room) []*Room {
var rooms []*Room
for _, room := range queryRooms {
if _, ok := rs.rooms[room.Details.Id]; ok {
rooms = append(rooms, rs.RoomById(room.Details.Id))
} else {
rooms = append(rooms, room)
}
}
return rooms
}
func AccessType(accessId int) string {
switch accessId {
case 1:
return "closed"
case 2:
return "password"
default:
return "open"
}
}
2021-09-06 02:48:30 +00:00
func (rs *roomService) PublicRoom(room *Room) bool {
if room.Details.Owner_Id == 0 {
return true
} else {
return false
}
}
2021-09-06 02:48:30 +00:00
func (rs *roomService) PublicName(room *Room) string {
2021-09-06 02:19:02 +00:00
if rs.PublicRoom(room) {
if strings.HasPrefix(room.Details.Name, "Upper Hallways") {
return "Upper Hallways"
}
if strings.HasPrefix(room.Details.Name, "Lower Hallways") {
2021-09-06 02:19:02 +00:00
return "Lower Hallways"
}
if strings.HasPrefix(room.Details.Name, "Club Massiva") {
return "Club Massiva"
}
if strings.HasPrefix(room.Details.Name, "The Chromide Club") {
2021-09-06 02:19:02 +00:00
return "The Chromide Club"
}
if room.Details.CCTs == "hh_room_gamehall,hh_games" {
return "Cunning Fox Gamehall"
}
2021-09-06 02:19:02 +00:00
}
2021-09-06 02:19:02 +00:00
return room.Details.Name
}
func (rs *roomService) CurrentVisitors() int {
var visitors int
return visitors
}
func (rs *roomService) MaxVisitors() int {
var visitors int
return visitors
}
2021-09-06 02:48:30 +00:00
func (rs *roomService) LoadChildRooms(room *Room) {
if room.Model.Name == "gate_park" {
2021-09-06 02:19:02 +00:00
room.Details.ChildRooms = append(room.Details.ChildRooms)
}
2021-09-06 02:19:02 +00:00
}