package game import ( "thehouseoficarus/internal/net" "thehouseoficarus/internal/player" ) func (g *Game) executeMap(sess *net.Session, args []string, rawInput string) { g.doMap(sess) } // maxMapDimension bounds the grid a player may request. buildFullMap // allocates mapHeight x mapWidth cells, so an unbounded option value would let // any authenticated player trigger a fatal (unrecoverable) out-of-memory // allocation that takes the whole server down. The option parser accepts any // int and the value persists in the account file, so the clamp must live here. const maxMapDimension = 200 // mapDimensions returns the clamped map grid size requested by the player. func mapDimensions(p *player.Player) (int, int) { mapWidth := p.OptionInt("map_width") mapHeight := p.OptionInt("map_height") if mapWidth < 5 { mapWidth = 5 } if mapHeight < 5 { mapHeight = 5 } if mapWidth > maxMapDimension { mapWidth = maxMapDimension } if mapHeight > maxMapDimension { mapHeight = maxMapDimension } return mapWidth, mapHeight } func (g *Game) doMap(sess *net.Session) { p := sess.Player mapWidth, mapHeight := mapDimensions(p) lines := buildFullMap(g, sess, p.RoomID, mapWidth, mapHeight, mapGlyphsForPlayer(p.OptionBool("unicode"))) mode := p.OptionString("map_padding") if mode == "none" || mode == "x" { lines = stripBlankRows(lines) } if mode == "none" || mode == "y" { lines = leftTrimCommon(lines) } if len(lines) == 0 { sess.WriteLine("No map data to display.") return } sess.WriteLine("") for _, line := range lines { sess.WriteLine(line) } }