2021-09-06 02:48:30 +00:00
|
|
|
package room
|
2020-01-04 04:38:22 +00:00
|
|
|
|
|
|
|
import (
|
2021-09-09 02:14:06 +00:00
|
|
|
"database/sql"
|
2020-04-13 16:02:47 +00:00
|
|
|
"strings"
|
2020-01-04 04:38:22 +00:00
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
var rs *roomService
|
|
|
|
var ronce sync.Once
|
2021-09-06 02:19:02 +00:00
|
|
|
|
2020-04-13 16:02:47 +00:00
|
|
|
const PublicRoomOffset = 1000
|
2020-01-04 04:38:22 +00:00
|
|
|
|
|
|
|
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
|
2020-01-04 04:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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),
|
2020-01-04 04:38:22 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return rs
|
|
|
|
}
|
|
|
|
|
2021-09-09 02:14:06 +00:00
|
|
|
func (rs *roomService) SetDBConn(db *sql.DB) {
|
|
|
|
rs.repo = NewRoomRepo(db)
|
2020-01-04 04:38:22 +00:00
|
|
|
}
|
2020-04-13 16:02:47 +00:00
|
|
|
|
2021-09-06 02:48:30 +00:00
|
|
|
func (rs *roomService) Rooms() []*Room {
|
|
|
|
var rooms []*Room
|
2020-04-13 16:02:47 +00:00
|
|
|
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 {
|
2020-04-13 16:02:47 +00:00
|
|
|
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)
|
|
|
|
}
|
2020-04-13 16:02:47 +00:00
|
|
|
|
2021-09-06 02:48:30 +00:00
|
|
|
func (rs *roomService) RoomByModelName(name string) *Room {
|
|
|
|
return &Room{}
|
2020-04-13 16:02:47 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 02:48:30 +00:00
|
|
|
func (rs *roomService) ReplaceRooms(queryRooms []*Room) []*Room {
|
|
|
|
var rooms []*Room
|
2020-04-13 16:02:47 +00:00
|
|
|
|
|
|
|
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 {
|
2020-04-13 16:02:47 +00:00
|
|
|
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") {
|
2020-04-13 16:02:47 +00:00
|
|
|
return "Upper Hallways"
|
|
|
|
}
|
|
|
|
|
|
|
|
if strings.HasPrefix(room.Details.Name, "Lower Hallways") {
|
2021-09-06 02:19:02 +00:00
|
|
|
return "Lower Hallways"
|
2020-04-13 16:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
2020-04-13 16:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if room.Details.CCTs == "hh_room_gamehall,hh_games" {
|
|
|
|
return "Cunning Fox Gamehall"
|
|
|
|
}
|
2021-09-06 02:19:02 +00:00
|
|
|
}
|
2020-04-13 16:02:47 +00:00
|
|
|
|
2021-09-06 02:19:02 +00:00
|
|
|
return room.Details.Name
|
2020-04-13 16:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2020-04-13 16:02:47 +00:00
|
|
|
if room.Model.Name == "gate_park" {
|
2021-09-06 02:19:02 +00:00
|
|
|
room.Details.ChildRooms = append(room.Details.ChildRooms)
|
2020-04-13 16:02:47 +00:00
|
|
|
}
|
2021-09-06 02:19:02 +00:00
|
|
|
}
|