Class GameRestService

Object
GameRestService

@DeclareRoles("player") @RolesAllowed("player") @Path("/game") public class GameRestService extends Object
Takes care of all the game-related functions.
Author:
maartenl

umldiagram

  • Field Details

    • VPS386

      public static final String VPS386
      The ip address of the karchan server (vps386.directvps.nl). This address means that the call to the game came from the server itself, and therefore we require access to the X_FORWARDED_FOR header.
      See Also:
    • X_FORWARDED_FOR

      public static final String X_FORWARDED_FOR
      If the call was forwarded from an Internet proxy, then the original ip is stored in this http header.
      See Also:
  • Constructor Details

  • Method Details

    • getPlayer

      protected User getPlayer(String name)

      This method should be called to verify that the target of a certain action is a user with the appropriate password.

      Parameters:
      name - the name to identify the person
      Returns:
      the authenticated User
      Throws:
      WebApplicationException - BAD_REQUEST if an unexpected exception crops up or provided info is really not proper. UNAUTHORIZED if session passwords do not match or user not found.

      umldiagram

    • isBanned

      public boolean isBanned(String name, String address)

      Checks to see if a person is banned from playing.

      Parameters:
      name - the name of the person
      address - the ip address the person is playing from
      Returns:
      true if banned, false otherwise.

      umldiagram

    • create

      @PermitAll @POST @Path("{name}") public Response create(@Context HttpServletRequest requestContext, @PathParam("name") String name, PrivatePerson pperson)

      Creates a new character, suitable for playing.

      Parameters:
      requestContext - for determining the remote address.
      name - the name of the user
      pperson - the data of the new character
      Returns:
      NO_CONTENT if the game is offline for maintenance.
      Throws:
      WebApplicationException - BAD_REQUEST if an unexpected exception crops up or something could not be validated.

      umldiagram

    • logon

      @PermitAll @PUT @Path("{name}/logon") public void logon(@Context HttpServletRequest requestContext, @PathParam("name") String name, @QueryParam("password") String password)
      Logs a player into the server. Once logged in, he/she can start playing the game. Url is for example http://localhost:8080/karchangame/resources/game/Karn/logon?password=itsasecret..
      Parameters:
      requestContext - the context of the request, useful for example querying for the IP address.
      name - the name of the user
      password - password for verification of the user.
    • logoff

      @PUT @Path("{name}/logoff") public void logoff(@Context HttpServletRequest requestContext)
      Logs a player off. TODO MLE: should be moved elsewhere, is not specifically part of the game.
      Parameters:
      requestContext - the context of the request, useful for example querying for the IP address.
    • getLogonMessage

      @GET @Path("{name}/logonmessage") @Produces("application/json") public String getLogonMessage(@PathParam("name") String name)
      Retrieves the logon message.
      Parameters:
      name - the name of the character/player
      Throws:
      WebApplicationException -
      • BAD_REQUEST if an unexpected exception crops up.
      • NO_CONTENT if the game is offline
      • FORBIDDEN, if the player is banned.
    • enterGame

      @POST @Path("{name}/enter") @Produces("application/json") public String enterGame(@Context HttpServletRequest requestContext, @PathParam("name") String name)
      Starts playing the game.
      Parameters:
      requestContext - used for retrieving the ip address/hostname of the player for determining ban-rules and the like.
      name - the name of the character/player
      Returns:
      A simple log, containing a message that you logged on.
      Throws:
      WebApplicationException -
      • BAD_REQUEST if an unexpected exception crops up.
      • NO_CONTENT if the game is offline
      • FORBIDDEN, if the player is banned.
    • playGame

      @POST @Path("{name}/play") @Produces("application/json") public PrivateDisplay playGame(@PathParam("name") String name, String command, @QueryParam("offset") Long offset, @QueryParam("log") Boolean log) throws MudException
      Main function for executing a command in the game.
      Parameters:
      name - the name of the player. Should match the authorized user.
      command - the command issued
      offset - the offset used for the log
      log - indicates with true or false, whether or not we are interested in the log.
      Returns:
      NO_CONTENT if the game is offline for maintenance.
      Throws:
      WebApplicationException - BAD_REQUEST if an unexpected exception crops up or something could not be validated.
      MudException
    • getLog

      @GET @Path("{name}/log") @Produces("application/json") public String getLog(@PathParam("name") String name, @QueryParam("offset") Long offset)
      Retrieves the log of a player.
      Parameters:
      name - the name of the user
      offset - the offset from whence to read the log
      Returns:
      returns the log
      Throws:
      WebApplicationException - BAD_REQUEST if an unexpected exception crops up.
      See Also:
    • deleteLog

      @DELETE @Path("{name}/log") @Produces("application/json") public Response deleteLog(@PathParam("name") String name)
      Removes the log of a player, i.e. creates a new empty log.
      Parameters:
      name - the name of the user
      Returns:
      Response.ok if everything's okay
      Throws:
      WebApplicationException - BAD_REQUEST if an unexpected exception crops up.
    • quitGame

      @GET @Path("{name}/quit") @Produces("application/json") public Response quitGame(@PathParam("name") String name)
      Stops a playing character from playing.
      Parameters:
      name - the name of the user
      Returns:
      An Ok response.
      Throws:
      WebApplicationException - BAD_REQUEST if an unexpected exception crops up.
    • setEntityManager

      public void setEntityManager(EntityManager em)