battleship

Safe HaskellSafe

Command

Contents

Description

This untrusted module implements the protocol by which the client and server sides of a player communicate, over a TCP connection.

The handles supplied to the following functions should be labeled dcPublic. The DC actions returned by the functions should be invoked with current label dcPublic, and they maintain the current label at dcPublic throughout their executions.

Synopsis

Server Functions

doneServer :: Handle -> DC ()

doneServer clnt returns a DC action that, when run, tells the client (via clnt) to exit.

infoServer :: Handle -> [String] -> DC ()

infoServer clnt msgs returns a DC action that, when run, tells the client (via clnt) to display the elements of msgs as separate lines, in order.

promptServer :: Handle -> String -> String -> DC (Maybe String)

promptServer clnt prompt quitMsg returns a DC action that, when run, tells the client (via clnt) to prompt its user for a line of input, using prompt, and then send this input -- stripped of leading/trailing whitespace -- to the server, so it may be returned, decorated by Just, as the result of the DC action.

quitMsg (which should not have leading or trailing whitespace) should be the same quit message passed to clientLoop. If the client's user signals end-of-file, or enters quitMsg (optionally surrounded by whitespace) as its line, then the client will send quitMsg to the server, causing the DC action to return Nothing. If the client's user interrupts (usually CTRL-c) (or has already interrupted at the point when promptServer is called), then the DC action will also return Nothing.

Client Function

clientLoop :: Handle -> Handle -> Handle -> String -> DC ()

clientLoop stdin stdout serv quitMsg returns a DC action that, when run, runs the client loop, communicating with the user via stdin/stdout, and with the server via serv. It uses quitMsg (see promptServer) as the quit message. Upon termination, the DC action returns ().