package player; import gen.PlayerContext; import http.gen.*; import http.server.*; /** Server class for the player. Dispatches to HTTP methods with context. */ @Server(PlayerServer.PORT) public class PlayerServer { public static final String EntryPath = "/player"; public static final String SERVER = "127.0.0.1"; public static final int PORT = 8000; /** Handle an Admin request */ @Path(EntryPath) public HTTPResp playerResponse(HTTPReq req){ try { PlayerContext pContext = PlayerContext.parse(req.getBody()); return createResponse(pContext); } catch (Exception e) { // Error Creating the Player's Context return HTTPResp.error(e.getMessage()); } } /** Default Handler */ @Path() public HTTPResp defaultResponse(HTTPReq req){ return HTTPResp.error("Unknown Request"); } /** Formulate a player response for a given PlyerContext */ public HTTPResp createResponse(PlayerContext ctx){ return HTTPResp.textResponse(new Player(ctx).play().toString()); } }