aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/server.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/admin/server.go')
-rw-r--r--internal/admin/server.go56
1 files changed, 31 insertions, 25 deletions
diff --git a/internal/admin/server.go b/internal/admin/server.go
index f0fa58e..6ad20f5 100644
--- a/internal/admin/server.go
+++ b/internal/admin/server.go
@@ -36,22 +36,27 @@ import (
var embedded embed.FS
type AdminServer struct {
- cfg *config.Config
- useTLS bool
- accountStore *player.AccountStore
- world *world.World
- itemStore *item.ItemStore
- objectStore *object.ObjectStore
- mobStore *world.MobStore
- dataDir string
- httpServer *http.Server
- undoStack *UndoStack
- tmpl *template.Template
- cookieSecret []byte
+ cfg *config.Config
+ useTLS bool
+ accountStore *player.AccountStore
+ world *world.World
+ itemStore *item.ItemStore
+ objectStore *object.ObjectStore
+ mobStore *world.MobStore
+ dataDir string
+ httpServer *http.Server
+ undoStack *UndoStack
+ tmpl *template.Template
+ cookieSecret []byte
reloadCourses func()
+ // rewriteRoomIDs migrates room-ID-embedded state across all characters
+ // (online + offline) when a room ID changes. Wired from the Game so the
+ // admin web GUI can trigger the same migration as the swapid command
+ // without the admin package depending on game.
+ rewriteRoomIDs func(idMap map[int]int)
}
-func NewServer(cfg *config.Config, useTLS bool, accountStore *player.AccountStore, w *world.World, is *item.ItemStore, os *object.ObjectStore, ms *world.MobStore, dataDir string, reloadCourses func()) (*AdminServer, error) {
+func NewServer(cfg *config.Config, useTLS bool, accountStore *player.AccountStore, w *world.World, is *item.ItemStore, os *object.ObjectStore, ms *world.MobStore, dataDir string, reloadCourses func(), rewriteRoomIDs func(map[int]int)) (*AdminServer, error) {
secret := make([]byte, 32)
if _, err := rand.Read(secret); err != nil {
return nil, fmt.Errorf("cookie secret: %w", err)
@@ -83,18 +88,19 @@ func NewServer(cfg *config.Config, useTLS bool, accountStore *player.AccountStor
}
s := &AdminServer{
- cfg: cfg,
- useTLS: useTLS,
- accountStore: accountStore,
- world: w,
- itemStore: is,
- objectStore: os,
- mobStore: ms,
- dataDir: dataDir,
- undoStack: NewUndoStack(dataDir),
- tmpl: tmpl,
- cookieSecret: secret,
- reloadCourses: reloadCourses,
+ cfg: cfg,
+ useTLS: useTLS,
+ accountStore: accountStore,
+ world: w,
+ itemStore: is,
+ objectStore: os,
+ mobStore: ms,
+ dataDir: dataDir,
+ undoStack: NewUndoStack(dataDir),
+ tmpl: tmpl,
+ cookieSecret: secret,
+ reloadCourses: reloadCourses,
+ rewriteRoomIDs: rewriteRoomIDs,
}
mux := http.NewServeMux()