http service: add pets list length check

0 length lists cause a redis exception from sadd, which I think is not being handled correctly by jedis and leaking the error into further commands
This commit is contained in:
Adam
2021-08-04 12:54:49 -04:00
parent 92e85d5db0
commit 912a68effa
2 changed files with 10 additions and 1 deletions

View File

@@ -51,6 +51,7 @@ public class ChatController
private static final Pattern STRING_VALIDATION = Pattern.compile("[^a-zA-Z0-9' -]"); private static final Pattern STRING_VALIDATION = Pattern.compile("[^a-zA-Z0-9' -]");
private static final int STRING_MAX_LENGTH = 50; private static final int STRING_MAX_LENGTH = 50;
private static final int MAX_LAYOUT_ROOMS = 16; private static final int MAX_LAYOUT_ROOMS = 16;
private static final int MAX_PETS = 256;
private final Cache<KillCountKey, Integer> killCountCache = CacheBuilder.newBuilder() private final Cache<KillCountKey, Integer> killCountCache = CacheBuilder.newBuilder()
.expireAfterWrite(2, TimeUnit.MINUTES) .expireAfterWrite(2, TimeUnit.MINUTES)
@@ -251,6 +252,11 @@ public class ChatController
@PostMapping("/pets") @PostMapping("/pets")
public void submitPetList(@RequestParam String name, @RequestBody int[] petList) public void submitPetList(@RequestParam String name, @RequestBody int[] petList)
{ {
if (petList.length == 0 || petList.length > MAX_PETS)
{
return;
}
chatService.setPetList(name, petList); chatService.setPetList(name, petList);
} }

View File

@@ -1238,7 +1238,10 @@ public class ChatCommandsPlugin extends Plugin
try try
{ {
List<Integer> petList = getPetList().stream().map(Pet::getIconID).collect(Collectors.toList()); List<Integer> petList = getPetList().stream().map(Pet::getIconID).collect(Collectors.toList());
chatClient.submitPetList(playerName, petList); if (!petList.isEmpty())
{
chatClient.submitPetList(playerName, petList);
}
} }
catch (Exception ex) catch (Exception ex)
{ {