Skip to content

Commit

Permalink
Fixes #203. Auto Refresh Not Working Properly
Browse files Browse the repository at this point in the history
- added the possibility to turn on/off websockets in the player settings.
- TODO: fix it so turning off websockets, results in getting the messages only every time you hit a command. -> the old way.
  • Loading branch information
Maarten van Leunen committed Dec 5, 2022
1 parent 9576a4d commit e31acc0
Show file tree
Hide file tree
Showing 35 changed files with 464 additions and 268 deletions.
Expand Up @@ -16,6 +16,7 @@
*/
package mmud.database.entities.characters;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
Expand Down Expand Up @@ -85,11 +86,12 @@
@NamedQuery(name = "Person.findAll", query = "SELECT p FROM Person p")
@NamedQuery(name = "Person.findByName", query = "SELECT p FROM Person p WHERE lower(p.name) = lower(:name)")
@NamedQuery(name = "Person.countAll", query = "SELECT count(p) FROM Person p")
abstract public class Person implements Serializable, AttributeWrangler, DisplayInterface, ItemWrangler, Ownage
public abstract class Person implements Serializable, AttributeWrangler, DisplayInterface, ItemWrangler, Ownage
{

private static final Logger LOGGER = java.util.logging.Logger.getLogger(Person.class.getName());
private static final Logger LOGGER = Logger.getLogger(Person.class.getName());

@Serial
private static final long serialVersionUID = 1L;

public static final String EMPTY_LOG = "";
Expand Down Expand Up @@ -359,6 +361,9 @@ abstract public class Person implements Serializable, AttributeWrangler, Display
@ManyToOne(fetch = FetchType.LAZY)
private Item wearaboutbody;

@Column(name = "websockets")
private boolean websocketSupport;

public Person()
{

Expand Down Expand Up @@ -770,7 +775,7 @@ public void setSleep(Boolean sleep)
*/
public Boolean getFightable()
{
return fightable == null ? false : fightable != 0;
return fightable != null && fightable != 0;
}

/**
Expand Down Expand Up @@ -2208,4 +2213,19 @@ public void setVisible(boolean visible)
// purposefully empty,
}

/**
* The idea here is that some people are having problems with websockets, meaning we need to
* fall back to the standard request-response model.
*
* @return true in case of websocket support, this is the default.
*/
public boolean getWebsocketSupport()
{
return websocketSupport;
}

public void setWebsocketSupport(boolean websocketSupport)
{
this.websocketSupport = websocketSupport;
}
}
19 changes: 7 additions & 12 deletions karchangame/src/main/java/mmud/rest/services/GameRestService.java
Expand Up @@ -364,7 +364,7 @@ public Response create(@Context HttpServletRequest requestContext, @PathParam("n
{
throw new MudWebException(name, "No data received.", Response.Status.BAD_REQUEST);
}
if (name == null || !pperson.name.equals(name))
if (pperson.name == null || !pperson.name.equals(name))
{
throw new MudWebException(name, "Wrong data received.", Response.Status.BAD_REQUEST);
}
Expand Down Expand Up @@ -696,7 +696,7 @@ public PrivateDisplay playGame(@PathParam(value = "name") String name, String co
// macro
if (parsedCommand.length == 2)
{
command = command.replaceAll("%t", parsedCommand[1]);
command = command.replace("%t", parsedCommand[1]);
}
display = runMultipleCommands(person, command);
}
Expand Down Expand Up @@ -804,27 +804,22 @@ private PrivateDisplay gameMain(User person, String command) throws MudException
{
MediaType.TEXT_HTML
})
public String getLog(@PathParam("name") String name, @QueryParam("offset") Integer offset)
public String getLog(@PathParam("name") String name, @QueryParam("offset") Long offset)
{
LOGGER.finer("entering retrieveLog");
Person person = authenticateToEnterGame(name);
if (offset == null)
{
offset = 0;
offset = 0L;
}
try
{
Integer offset1 = offset;
if (offset1 == null)
{
offset1 = 0;
}
String log = CommunicationService.getCommunicationService(person).getLog(offset1);
String log = CommunicationService.getCommunicationService(person).getLog(offset);
PrivateLog plog = new PrivateLog();
plog.offset = offset1;
plog.offset = offset;
plog.log = log;
plog.size = plog.log.length();
return log.substring(offset);
return log.substring(offset.intValue());
} catch (WebApplicationException e)
{
//ignore
Expand Down

0 comments on commit e31acc0

Please sign in to comment.