Safe Haskell | Safe |
---|
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.
- doneServer :: Handle -> DC ()
- infoServer :: Handle -> [String] -> DC ()
- promptServer :: Handle -> String -> String -> DC (Maybe String)
- clientLoop :: Handle -> Handle -> Handle -> String -> DC ()
Server Functions
doneServer :: Handle -> DC ()
returns a doneServer
clntDC
action that, when run, tells the client
(via clnt
) to exit.
infoServer :: Handle -> [String] -> DC ()
returns a infoServer
clnt msgsDC
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)
returns a promptServer
clnt prompt quitMsgDC
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 ()
returns a clientLoop
stdin stdout serv quitMsgDC
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 ()
.