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:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user