]> git.pond.sub.org Git - empserver/blobdiff - doc/clients-howto
Fix generation numbers for autonav
[empserver] / doc / clients-howto
index cb59fde65326b41aaa3638ebf3bfc09579bde482..2a986e3765c24edf0b6dd33e535a47beb32af7cb 100644 (file)
@@ -12,14 +12,17 @@ ASCII.
 
 Client-server communication is line-oriented.
 
-The server sends lines of output.  Each output line starts with a
-character identifying the line, followed by a space, then arbitrary
-text, then a line feed.
+The server sends lines of output.  Each output line starts with an
+identification string, followed by a space, then arbitrary text, then
+a line feed.
 
-Identification characters encode small integers called ids.  Ids less
-than 10 are encoded as decimal digits, and larger ids as lower case
-letters starting with 'a'.  Symbolic names for ids are defined in
-proto.h.
+Identification strings encode small integers called output ids as base
+36 numbers.  Characters '0' to '9' represent digits 0 to 9, and 'a' to
+'z' represent 10..35, as do 'A' to 'Z'.  Symbolic names for ids are
+defined in proto.h.
+
+emp_client versions before version 4.3.11 parse large output ids
+incorrectly.  Such ids do not currently occur.
 
 Clients shall be able to safely handle output lines of arbitrary
 length.  Naturally, a client may not be able to handle a sufficiently
@@ -45,17 +48,25 @@ clients.  Likewise, overlong or malformed UTF-8 sequences should not
 occur and may be ignored.
 
 The server prompts for input.  Each prompt `consumes' one line of
-input.  Input lines are arbitrary text, terminated by line feed,
-optionally preceded by carriage return (decimal 13).  Lines should not
-contain ASCII control characters other than horizontal tab.  Clients
-should not send overlong or malformed UTF-8 sequences.
+input (except for C_EXECUTE, and when the update aborts a command, as
+described below).  Input lines are arbitrary text, terminated by line
+feed, which is optionally preceded by carriage return (decimal 13).
+Lines should not contain ASCII control characters other than
+horizontal tab.  Clients should not send overlong or malformed UTF-8
+sequences.
 
 A client is called synchronous if it waits for a prompt before it
 sends another line of input.  Else it is called asynchronous.
 
+Asynchronous clients must take care to avoid blocking on sending
+input.  If the client process blocks that way, it can't receive server
+output until the server reads more input.  That may never happen,
+because the server may well block on output, which then deadlocks the
+session.
+
 An Empire session consists of two phases: login and playing.
 emp_client is synchronous during the former and asynchronous during
-the latter.
+the latter.  Versions before 4.3.11 could deadlock as described above.
 
 Login phase
 -----------
@@ -84,10 +95,10 @@ Login commands are:
 
 * kill
 
-  Country must be logged in.
-
   If another connection is open for this country, forcibly close it,
-  else do nothing.  Reply is C_EXIT in either case.
+  else do nothing.  Country must be authenticated.
+
+  Reply is C_EXIT regardless of success.
 
 * options OPTION[=VALUE]...
 
@@ -99,28 +110,31 @@ Login commands are:
   The server accepts the request by sending C_CMDOK.  If the server
   encounters an unknown option, it rejects the request by sending
   C_BADCMD.  It rejects unsupported values by sending C_CMDERR.  It
-  may or may not process valid parts of such a rejected request.
+  may or may not process valid parts of rejected requests.
 
   If there are no arguments, the server lists its options.  For each
-  option, it sends a C_DATA line with OPTION=VALUE as text.
+  option, it sends a C_DATA line with OPTION=VALUE as text, and
+  finally a C_CMDOK.  If it supports no options at all, it may reply
+  with C_BADCMD instead.
 
   See below for supported session options.
 
 * pass PASSWORD
 
-  Log in.  Country name must be set already.
+  Authenticate.  Country name must be set already.
 
-* play [USER [COUNTRY [PASSWORD]]]
+* play [USER COUNTRY PASSWORD]
 
-  Optional argument USER sets the user name.
+  Start playing.
 
-  Optional argument COUNTRY sets the country name.
+  If no arguments are given, the country must be authenticated
+  already.
 
-  Optional argument PASSWORD logs in.  If it isn't present, the
-  country must be logged in already.
+  Else, argument USER sets the user name, COUNTRY sets the country
+  name, and PASSWORD authenticates.
 
-  If another connection is open for this country, the server replies
-  C_EXIT.
+  Some error conditions result in a C_EXIT reply.  Clients should
+  treat it just like C_CMDERR.
 
   On success, the server sends C_INIT.  The text is the protocol
   version number in decimal, currently 2.  The client should terminate
@@ -160,6 +174,10 @@ sending "aborted\n".  The server treats these conditions specially, as
 described below.  Anything else is either a command or input for a
 command, depending on how the server prompts for the line.
 
+emp_client signals `EOF' when it encounters an end-of-file condition
+while reading player input.  It signals `interrupt' when it catches
+SIGINT, which is normally triggered by Ctrl-C.
+
 The following ids occur:
 
 * Command prompt C_PROMPT
@@ -176,10 +194,17 @@ The following ids occur:
   Clients with a tty-like user interface are advised to use a similar
   format, to minimize differences to the examples in info.
 
-* Sub-prompt C_FLUSH
+* Argument prompt C_FLUSH
 
   The server consumes a line of input and passes it to the currently
-  executing command.  Commands usually fail on EOF or interrupt.
+  executing command.  Commands usually fail on interrupt.  The server
+  terminates the session on EOF (but see C_EXECUTE for an exception).
+
+  If an update runs while the server waits for the line of input to
+  arrive, the current command is aborted.  Whether the server consumes
+  a line of input for this argument prompt is unpredictable.  Any
+  argument prompts it may send before the next command prompt do not
+  consume input.
 
   Text is a human-readable prompt supplied by the command.
 
@@ -193,26 +218,44 @@ The following ids occur:
 
 * Control C_EXECUTE
 
-  Request execution of a script.  The text is a copy of the execute
-  command's first argument.  Its syntax and semantics is left to the
-  client.
+  Request execution of a batch file.  The text is whatever was on the
+  line of input after the execute command.  Its syntax and semantics
+  are left to the client.
+
+  emp_client interprets the first word (sequence of non-space
+  characters) in the text as file name, and sends the contents of that
+  file.
 
-  emp_client interprets the text as file name, and sends the contents
-  of that file.
+  The security considerations on C_PIPE (below) apply to C_EXECUTE as
+  well.
 
-  The client shall mark the end of the script by signalling EOF as
-  described above.  It may signal interrupt if it is unable or
-  unwilling to send the complete script.
+  Note that servers before 4.3.11 sent a copy of the execute command's
+  first argument as text.  This made it hard for clients to ensure
+  that the text is identical to what was sent, because the server
+  strips funny characters and interprets and strips '"' characters
+  when splitting input lines into command and arguments.
 
-  While executing the script, the server sends no C_PROMPT command
-  prompts.  It still sends C_FLUSH sub-prompts.
+  emp_client gets confused when old servers mangle the text that way.
 
-  Certain bad failures make the server ignore the rest of the script
-  file.  This feature is too hard to predict to be really useful.
+  The client shall mark the end of the batch file by signalling EOF as
+  described above.  This does not terminate the session.  It may
+  signal interrupt if it is unable or unwilling to send the complete
+  batch file.
 
-  Strictly asynchronous clients cannot support C_EXECUTE correctly.
-  By the time C_EXECUTE arrives, the client may have sent more input
-  already.  That input `overtakes' the script in the input stream.
+  While executing the batch file, the server sends no C_PROMPT command
+  prompts.  It still sends C_FLUSH argument prompts.
+
+  Protocol flaw: not sending C_PROMPT here screws up redirections:
+  they apply until the next C_PROMPT, i.e. from start of redirected
+  command until end of containing batch file.
+
+  Certain bad failures make the server ignore the rest of the batch
+  file file.  This feature is too hard to predict to be really useful.
+
+  Protocol flaw: strictly asynchronous clients cannot support
+  C_EXECUTE correctly.  By the time C_EXECUTE arrives, the client may
+  have sent more input already.  That input `overtakes' the contents
+  of the batch file in the input stream.
 
   emp_client has this problem.
 
@@ -221,8 +264,8 @@ The following ids occur:
 
 * Control C_EXIT
 
-  End of session.  The server will close the connection.  Text is a
-  human-readable farewell.
+  End of session.  The server is about to close the connection.  Text
+  is a human-readable farewell.
 
   emp_client prints this text prepended with "Exit: ".
 
@@ -231,7 +274,7 @@ The following ids occur:
   Asynchronous message.  The client should display the text
   immediately.
 
-  emp_client prints the text verbatim, prepended by a newline.  This
+  emp_client prints the text verbatim, prepended by a line feed.  This
   is clearly sub-optimal, because it can be inserted in the middle of
   user input.  Clients wishing to to display asynchronous messages
   together with normal I/O should insert them before the current
@@ -259,7 +302,7 @@ The following ids occur:
 
 * Control C_PIPE
 
-  When a command is redirected to a pipeline, its output is prededed
+  When a command is redirected to a pipeline, its output is preceded
   by a C_PIPE line.  The text is a copy of the redirection, starting
   with '|'.  Syntax and semantics of the text after the '|' are left
   to the client.
@@ -267,6 +310,9 @@ The following ids occur:
   emp_client executes text after '|' as shell command, with standard
   input connected to the Empire command's output.
 
+  The redirection applies to a single command, i.e. until the next
+  C_PROMPT.
+
   For obvious security reasons, clients supporting pipes shall ensure
   that the text is identical to whatever was sent to the server.  Note
   that the server recognizes redirection only in command lines, not
@@ -277,7 +323,7 @@ The following ids occur:
 
 * Control C_REDIR
 
-  When a command is redirected to a file, its output is prededed by a
+  When a command is redirected to a file, its output is preceded by a
   C_REDIR line.  The text is a copy of the redirection, starting with
   '>', optionally followed by '>' or '!'.  Syntax and semantics of the
   remaining text are left to the client.
@@ -290,6 +336,9 @@ The following ids occur:
   existing file, with '>>' it appends to the file, and with just '>'
   it refuses to overwrite an existing file.
 
+  The redirection applies to a single command, i.e. until the next
+  C_PROMPT.
+
   The security considerations on C_PIPE apply to C_REDIR as well.
 
 * Other ids
@@ -297,9 +346,9 @@ The following ids occur:
   Other ids do not occur currently.  Clients shall deal gracefully
   with ids they don't know.
 
-  emp_client treats unknown ids like C_DATA.  For historical reasons,
-  it prepends "Aborted\n" to C_ABORT lines, and "Error; " to C_CMDERR
-  and C_BADCMD lines.
+  emp_client treats unknown ids like C_DATA.  Versions before 4.3.11
+  prepend "Aborted\n" to C_ABORT lines, and "Error; " to C_CMDERR and
+  C_BADCMD lines for historical reasons.
 
 
 Session Options
@@ -350,21 +399,17 @@ change between a dump and the next timestamp increase.
 Timestamp values are currently seconds since the epoch, but this might
 change, and clients are advised not to rely on it.
 
-Experimental extended dump
---------------------------
+Extended dump
+-------------
 
 Traditional dumps have a number of shortcomings.  They cover only the
-most important part of the game statesectors, ships, planes, land
-units, nukes, but not game configuration, loans, news, and so forth.
+most important part of the game state (sectors, ships, planes, land
+units, nukes), but not game configuration, loans, news, and so forth.
 They are not quite complete even for what they attempt to cover.
 Finally, their output is harder to parse than necessary.
 
 The new `xdump' command is designed to overcome these deficiencies.
-It still needs significant work, and is subject to change in
-incompatible ways.  To protect real games from known and unknown flaws
-in xdump, it is only accessible when option GUINEA_PIGS is enabled.
-
-Technical xdump documentation to be written.
+See doc/xdump for the full story.
 
 
 Advice on parsing human-readable command output