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
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGameRestService
(BoardService boardService, IdleUsersService idleUsersService, MailService mailService, CommandRunner commandRunner, LogService logService, PlayerAuthenticationService playerAuthenticationService) -
Method Summary
Modifier and TypeMethodDescriptionResponse
create
(HttpServletRequest requestContext, String name, PrivatePerson pperson) Creates a new character, suitable for playing.Response
Removes the log of a player, i.e.Starts playing the game.Retrieves the log of a player.getLogonMessage
(String name) Retrieves the logon message.protected User
This method should be called to verify that the target of a certain action is a user with the appropriate password.boolean
Checks to see if a person is banned from playing.void
logoff
(HttpServletRequest requestContext) Logs a player off.void
Logs a player into the server.Main function for executing a command in the game.Response
Stops a playing character from playing.void
setEntityManager
(EntityManager em)
-
Field Details
-
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 theX_FORWARDED_FOR
header.- See Also:
-
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
-
GameRestService
@Inject public GameRestService(BoardService boardService, IdleUsersService idleUsersService, MailService mailService, CommandRunner commandRunner, LogService logService, PlayerAuthenticationService playerAuthenticationService)
-
-
Method Details
-
getPlayer
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.
-
isBanned
-
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 userpperson
- 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.
-
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 userpassword
- 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 issuedoffset
- the offset used for the loglog
- 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 useroffset
- 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)
-