All registered worlds are a part of a universe. Technically, the universe is a so-called server, a program that receives messages, processes them, replies and/or broadcasts messages of its own. Most of the time, the server just acts as a channel of communication. In the case of universe2.ss, it connects two world programs.
The server is parameterized over user-supplied code. It can thus act as either
a "pass through" channel, which communicates messages from one player to another without any interference;
a "back and forth" channel, which enforces a back-and-forth exchange between worlds, giving each world a chance to send a message and to get a reply; or
a special-purpose arbiter.
The last option means that the server can plan the role of a "game referee."
An instantiated server accepts connections from exactly two world programs. Once it has two connections, it uses a programmer-specified function to create a server state. For every message it receives, it applies another function to determine the next server state and the messages it should broadcast.
Using the teachpack requires that you provide a data definition that captures the sate of the server. In principle, there are no constraints on this data definition. You can even keep it implicit, even if this violates the Design Recipe.
|(universe initial process) → true|
|initial : (-> player? player? (cons ServerState Mail))|
|process : (-> ServerState player? sexp? (cons ServerState Mail))|
starts the server, specifying how to initialize the server and how to process incoming messages from individual worlds.
The process function is used every time the server receives a Message from a participating world. It is then applied to the current ServerState a representation of the message-sending world, and the Message that was received. The function produces that starts with the the new ServerState followed by Mails.
For both functions, the server deconstructs the resulting list, saves the server state, and sends out the messages specified via Mails to the appropriate players.
Mail is a list of two-element lists. The first element specifies the player to which the second element – a message–should be sent.
The picture provides a graphical overview of the server’s workings.