Skip to content

Commit

Permalink
Fixed client input validation for double battles
Browse files Browse the repository at this point in the history
Multiplayer double battles were effectively completely broken before,
validation-wise.
  • Loading branch information
varkor committed Jan 7, 2016
1 parent 2d2147d commit 5d613f7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions battle/scripts/objects/general/BattleContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ function BattleContext (client) {
});
return waitingFor;
},
communicationForTrainerIsValid : function (team, actions, issues) {
communicationForTrainerIsValid : function (team, actions, selection, issues) {
// This function assumes that all the actions required for this point are sent — i.e. split data packets are not allowed as it makes it difficult to determine the current Pokémon
var properties = [], requireProperty = function (action, property) {
if (action.hasOwnProperty(property)) {
Expand All @@ -1404,7 +1404,7 @@ function BattleContext (client) {
issues.push("There was no trainer with a team equal to `" + team + "`.");
return false; // This should never be true, as we receive the trainer data from the Supervisor, who is assumed trustworhy
}
var inBattle = [], currentBattler, selection = 0;
var inBattle = [], currentBattler;
foreach(battleContext.all(true), function (poke) {
if (poke.trainer === character)
inBattle.push(poke);
Expand Down
2 changes: 1 addition & 1 deletion battle/scripts/objects/unique/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ Cursor = {
click : function () {
Input.controlScheme = "mouse";
var bubble = true;
if (bubble && typeof Battle === "object" && Battle.canvas) {
if (bubble && typeof Battle === "object" && Battle !== null && Battle.canvas) {
if (Cursor.inArea(Battle.canvas, 0, 0, Battle.canvas.width, Battle.canvas.height)) {
if (Battle.drawing.respondToClick()) {
bubble = false;
Expand Down
3 changes: 2 additions & 1 deletion battle/scripts/objects/unique/Supervisor.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ Supervisor = {
});
// Assumes that the correct number of actions will be sent at once (i.e. no split data packets)
var issues = [];
if (process.battle.communicationForTrainerIsValid(data.team, data.data, issues)) {
var selection = process.relay.slice(process.relayed).filter(action => action.action === "command" && action.trainer === data.team).length;
if (process.battle.communicationForTrainerIsValid(data.team, data.data, selection, issues)) {
process.relay = process.relay.concat(data.data);
var actionsToSend = process.relay.slice(process.relayed);
if (process.battle.state.kind === "waiting" && process.battle.hasCommunicationForTrainers(process.battle.state.for, actionsToSend)) {
Expand Down

0 comments on commit 5d613f7

Please sign in to comment.