- RequestEntry() 시 CheckStaleSlots() 호출하여 좀비 슬롯 자동 정리 - 블록체인 보상 실패 시 BossRoom 상태를 reward_failed로 업데이트 - UpdateRoomStatus() 레포지토리 메서드 추가 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
74 lines
3.1 KiB
Go
74 lines
3.1 KiB
Go
package bossraid
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type RoomStatus string
|
|
|
|
const (
|
|
StatusWaiting RoomStatus = "waiting"
|
|
StatusInProgress RoomStatus = "in_progress"
|
|
StatusCompleted RoomStatus = "completed"
|
|
StatusFailed RoomStatus = "failed"
|
|
StatusRewardFailed RoomStatus = "reward_failed"
|
|
)
|
|
|
|
// BossRoom represents a boss raid session room.
|
|
type BossRoom struct {
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
UpdatedAt time.Time `json:"updatedAt"`
|
|
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
|
|
SessionName string `json:"sessionName" gorm:"type:varchar(100);uniqueIndex;not null"`
|
|
BossID int `json:"bossId" gorm:"index;not null"`
|
|
Status RoomStatus `json:"status" gorm:"type:varchar(20);index;default:waiting;not null"`
|
|
MaxPlayers int `json:"maxPlayers" gorm:"default:3;not null"`
|
|
// Players is stored as a JSON text column for simplicity.
|
|
// TODO: For better query performance, consider migrating to a junction table
|
|
// (boss_room_players with room_id + username columns).
|
|
Players string `json:"players" gorm:"type:text"` // JSON array of usernames
|
|
StartedAt *time.Time `json:"startedAt,omitempty"`
|
|
CompletedAt *time.Time `json:"completedAt,omitempty"`
|
|
}
|
|
|
|
// SlotStatus represents the status of a dedicated server room slot.
|
|
type SlotStatus string
|
|
|
|
const (
|
|
SlotIdle SlotStatus = "idle"
|
|
SlotWaiting SlotStatus = "waiting"
|
|
SlotInProgress SlotStatus = "in_progress"
|
|
)
|
|
|
|
|
|
// DedicatedServer represents a server group (e.g., "Dedi1").
|
|
// Multiple containers (replicas) share the same server group name.
|
|
type DedicatedServer struct {
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
UpdatedAt time.Time `json:"updatedAt"`
|
|
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
|
|
ServerName string `json:"serverName" gorm:"type:varchar(100);uniqueIndex;not null"`
|
|
MaxRooms int `json:"maxRooms" gorm:"default:10;not null"`
|
|
}
|
|
|
|
// RoomSlot represents a room slot on a dedicated server.
|
|
// Each slot has a stable session name that the Fusion NetworkRunner uses.
|
|
// InstanceID tracks which container process currently owns this slot.
|
|
type RoomSlot struct {
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
UpdatedAt time.Time `json:"updatedAt"`
|
|
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
|
|
DedicatedServerID uint `json:"dedicatedServerId" gorm:"index;not null"`
|
|
SlotIndex int `json:"slotIndex" gorm:"not null"`
|
|
SessionName string `json:"sessionName" gorm:"type:varchar(100);uniqueIndex;not null"`
|
|
Status SlotStatus `json:"status" gorm:"type:varchar(20);index;default:idle;not null"`
|
|
BossRoomID *uint `json:"bossRoomId" gorm:"index"`
|
|
InstanceID string `json:"instanceId" gorm:"type:varchar(100);index"`
|
|
LastHeartbeat *time.Time `json:"lastHeartbeat"`
|
|
}
|