MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / SaveRoomScript

Function SaveRoomScript

internal/rooms/admin.go:360–376  ·  view source on GitHub ↗

SaveRoomScript writes (or overwrites) the JavaScript file for a room. If content is empty the script file is deleted instead.

(roomId int, content string)

Source from the content-addressed store, hash-verified

358// SaveRoomScript writes (or overwrites) the JavaScript file for a room. If
359// content is empty the script file is deleted instead.
360func SaveRoomScript(roomId int, content string) error {
361 r := LoadRoomTemplate(roomId)
362 if r == nil {
363 return fmt.Errorf("room %d not found", roomId)
364 }
365
366 scriptPath := r.GetScriptPath()
367
368 if content == "" {
369 if err := os.Remove(scriptPath); err != nil && !os.IsNotExist(err) {
370 return fmt.Errorf("removing room script: %w", err)
371 }
372 return nil
373 }
374
375 return util.WriteFile(scriptPath, []byte(content), 0644)
376}
377
378type MapperRoomData struct {
379 RoomId int `json:"RoomId"`

Callers 1

apiV1PutRoomScriptFunction · 0.92

Calls 4

WriteFileFunction · 0.92
LoadRoomTemplateFunction · 0.85
GetScriptPathMethod · 0.45
RemoveMethod · 0.45

Tested by

no test coverage detected