Advanced Server Features

From Hopmod Wiki

Jump to: navigation, search

Contents

The Script Pipe

The script pipe is a named pipe (a fifo file) that exists while the server is running and its purpose is to allow you to feed and execute CubeScript code on the server on demand. The server reads from the script pipe a stream of code, parsing and evaluating expressions as they come; evaluation of an expression begins when parsing is complete; it's possible a single expression could be received in multiple read operations. Only one-way communication is supported: the server can read and execute your code, but there is nowhere for it to send a reply, and because of this limitation the script pipe is only useful for sending command statements, where no reply is expected. When the server detects any kind of error in the received code it logs an error message to stderr (located "./log/error.log").

Configuration

The server completely controls, with no opportunity for configuration, when the script pipe is created and destroyed and gives the named pipe the file name serverexec.

script_pipe_pending_idle_timeout

Acceptable values: positive integer
Default value: 2000

This variable sets, in milliseconds, how long to wait between receiving data until it discards the currently parsing expression.

Usage Examples

echo "shutdown" > serverexec


The Script Socket

The script socket is an embedded HTTP server that runs in the game server and its purpose is to receive and process post requests to a resource known as /serverexec. This resource performs the same function as the script (to run arbitrary code as its received), but is able to reply with the expression's evaluation result back to the sender. The script socket can talk back to the sender; even error messages are sent to the request sender. The script socket service is the successor to the script pipe.

For security reason, the HTTP server only accepts connections coming from localhost.

Configuration

use_script_socket_server

Acceptable values: 0 or 1
Default value: 1

script_socket_port

Acceptable values: valid TCP port number.
Defaut value: 7894

Stopping the service

To stop the HTTP server listening execute the command <code>close_script_socket_server.

Usage Examples

Using a shell script

$ ./bin/shell.rb
Connected to 127.0.0.1:7894
server> get servername
House of Pain
server> servername "World of Pain"
World of Pain

Manual request and response

Sending the request:

POST /serverexec HTTP/1.1
Accept: */*
Content-Type: text/x-cubescript
Host: 127.0.0.1:7894
Content-Length: 14

get servername

Server's reply:

HTTP/1.1 200 OK
Content-Length: 13
Date: Wed, 08 Jul 2009 22:42:45 GMT

House of Pain

Error response

HTTP/1.1 400 Bad Request
Content-Length: 45
Date: Wed, 08 Jul 2009 22:48:18 GMT

Error in :1: unknown symbol 'aroweiruweoriu'
Personal tools