# `QuakeServer.Console`
[🔗](https://github.com/jaman/quake_server/blob/v0.1.0/lib/quake_server/console.ex#L1)

The console: the commands a program queues with `localcmd`, the lines of the
configuration files they `exec`, and commands typed or sent to it, run against the
host's `QuakeServer.Cvars` table as FTE's console runs them.

    server = QuakeServer.Console.run(server, "exec default.cfg; set skill 2")
    server = QuakeServer.Console.flush(server)

Text splits into commands at newlines and at `;` outside quotes and outside a `//`
comment; a comment runs to the end of its line and stays with its command (`set` reads
a description from it). A command's first word is looked up as FTE looks it up: the
console's own commands, then aliases, then console variables, then the program.

The console's own commands:

  * the variable commands of `QuakeServer.Console.Variables`: `set`, `seta`,
    `set_tp`, `setfl`, `toggle`, `inc`, `cvarreset`, `cvar_lockdefaults`,
    `cvar_purgedefaults`, `cvar_resettodefaults_all`, `cvar_resettodefaults_saveonly`,
    `cvar_resettodefaults_nosaveonly`, `vid_reload`, `vid_restart`
  * `exec file`, `cfg_save [name]`, `cfg_save_ifmodified` (`QuakeServer.Console.Configs`)
  * `alias name commands` — kept in the table, so every holder of it shares them; an
    alias runs its commands before the rest, with the command's arguments after a
    one-word alias that names a variable or command
  * `serverinfo key value` (a variable of that name is set too), `localinfo key
    value`, `setinfo key value` (the player's; a `:userinfo` variable of that name is
    set instead), `setinfoblob key file` (as `setinfo`, the value the file's bytes;
    `pmodel` and `emodel` ignored, `*` keys refused)
  * the key binding commands of `QuakeServer.Console.Bindings`: `bind`, `in_bind`,
    `bindlevel`, `unbind`, `unbindall`
  * `setpos [x y z [pitch yaw roll]]` and `noclip` (`QuakeServer.Cheats`)
  * `echo text`, `sky name` (kept in `ext.sky`), `wait` (the rest waits for the next
    `flush/1`), `map name`, `changelevel name [startspot]`
  * `watchpoint`, `watchpoint_ssqc`, `watchpoint_csqc` and `watchpoint_menuqc` with a
    term (a global, or `entity.field` with the entity a number or an entity global):
    the term is kept in `ext.watchpoint` and answered `Watchpoint set`, or `Watchpoint
    cleared` with no term or one that names nothing; changes to what it names are not
    reported

A variable's name alone prints it; with a value it sets it
(`QuakeServer.Console.Variables.command/5`). Any other command goes to the program's
`ConsoleCmd(string)`, or a client program's `CSQC_ConsoleCommand(string)`, when it has
one, or a menu program's `m_consolecommand(string)` (a command the menu registered
with `registercommand` counts as taken whatever it returns); `ConsoleCmd` runs as
FTE's server runs it, with `self` the world and `time` the
server's, `self` put back afterwards. A command nothing takes is reported as unknown
while `cl_warncmd` (or `developer`) is set, as FTE reports it. One run expands at most
4096 aliases and `exec`s; past that the commands they would add are dropped.

# `command?`

```elixir
@spec command?(String.t()) :: boolean()
```

Whether `name` is one of the console's own commands.

# `commands`

```elixir
@spec commands(String.t()) :: [String.t()]
```

The commands of `text`, split at newlines and at `;` outside quotes and outside a
`//` comment, each trimmed, blank ones dropped; a comment stays with its command.

# `flush`

```elixir
@spec flush(QuakeServer.Server.t()) :: QuakeServer.Server.t()
```

Run the commands `localcmd` queued since the last flush.

# `run`

```elixir
@spec run(QuakeServer.Server.t(), String.t(), keyword()) :: QuakeServer.Server.t()
```

Run `text` as console commands now. Option `from: :server` runs them as commands the
server sent (FTE's commands from game code), which may not set `:notfromserver`
variables and take over the variables they set.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
