Variables

Detailed Description

Handles the client-side scripting interface.

Each script is an external process that keeps two pipes open between the client and the script (one in each direction). When the script starts, it defaults to receiving no data from the client. Normally, the first command it sends to the client will be a request to have certain types of data sent to the script as the client receives them from the server (such as drawinfo commands). The script can also request current information from the client, such as the contents of the inventory or the map data (either live or last viewed "fog-of-war" data). The script can also send commands for the client to pass to the server.

Script Commands:

watch {command type} whenever the server sends the given command type to the client, also send a copy to the script. Note that this checked before the client processes the command, so it will automatically handle new options that may be added in the future. If the command type is NULL, all commands are watched.

unwatch {command type} turn off a previous watch command. There may be a slight delay in response before the command is processed, so some unwanted data may still be sent to the script.

request {data type} have the client send the given data to the script.

issue [{repeat} {must_send}] {command} issue the specified command to the server. if {repeat} isn't numeric then the command is sent directly For "lock" and "mark" only, the parameters are converted to binary.

draw {color} {text} display the text in the specified color as if the server had sent a drawinfo command.

monitor send the script a copy of every command that is sent to the server.

unmonitor turn off monitoring.

sync {#} wait until the server has acknowledged all but {#} commands have been received

To implement this:

Processing script commands: gtk/gx11.c:do_network() and x11/x11.c:event_loop() are modified to also watch for input from scripts in the select() call, in which case script_process(fd) in this file is called.

Handling of requests: global variables are directly accessed from within this file.

Handling of issues: send_command() is called directly. Note that this command will be sent to any scripts that are monitoring output.

Launching new scripts: common/player.c:extended_command() is extended to add a check for "script <scriptname>" as an additional command, calling script_init(). Also added is the "scripts" command to list all running scripts, the "scriptkill" command to terminate a script (close the pipes and assume it takes the hint), and the "scripttell" command to send a message to a running script.