Skip to content

Commit

Permalink
Hide nicknames of Pokemon used by locked users (#2639)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirDonovan authored and Zarel committed Jul 24, 2016
1 parent c16bc58 commit 1daec1a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
32 changes: 19 additions & 13 deletions team-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ class Validator {
this.tools = Tools.mod(this.format);
}

validateTeam(team) {
validateTeam(team, removeNicknames) {
let format = Tools.getFormat(this.format);
if (format.validateTeam) return format.validateTeam.call(this, team);
return this.baseValidateTeam(team);
if (format.validateTeam) return format.validateTeam.call(this, team, removeNicknames);
return this.baseValidateTeam(team, removeNicknames);
}

prepTeam(team) {
return PM.send(this.format.id, team);
prepTeam(team, removeNicknames) {
removeNicknames = removeNicknames ? '1' : '0';
return PM.send(this.format.id, removeNicknames, team);
}

baseValidateTeam(team) {
baseValidateTeam(team, removeNicknames) {
let format = this.format;
let tools = this.tools;

Expand Down Expand Up @@ -60,6 +61,7 @@ class Validator {
if (setProblems) {
problems = problems.concat(setProblems);
}
if (removeNicknames) team[i].name = team[i].baseSpecies;
}

for (let i = 0; i < format.teamBanTable.length; i++) {
Expand Down Expand Up @@ -879,22 +881,26 @@ PM = TeamValidator.PM = new ProcessManager({
},
onMessageDownstream: function (message) {
// protocol:
// "[id]|[format]|[team]"
// "[id]|[format]|[removeNicknames]|[team]"
let pipeIndex = message.indexOf('|');
let pipeIndex2 = message.indexOf('|', pipeIndex + 1);
let nextPipeIndex = message.indexOf('|', pipeIndex + 1);
let id = message.substr(0, pipeIndex);
let format = message.substr(pipeIndex + 1, nextPipeIndex - pipeIndex - 1);

let format = message.substr(pipeIndex + 1, pipeIndex2 - pipeIndex - 1);
let team = message.substr(pipeIndex2 + 1);
pipeIndex = nextPipeIndex;
nextPipeIndex = message.indexOf('|', pipeIndex + 1);
let removeNicknames = message.substr(pipeIndex + 1, nextPipeIndex - pipeIndex - 1);
let team = message.substr(nextPipeIndex + 1);

process.send(id + '|' + this.receive(format, team));
process.send(id + '|' + this.receive(format, removeNicknames, team));
},
receive: function (format, team) {
receive: function (format, removeNicknames, team) {
let parsedTeam = Tools.fastUnpackTeam(team);
removeNicknames = removeNicknames === '1';

let problems;
try {
problems = TeamValidator(format).validateTeam(parsedTeam);
problems = TeamValidator(format).validateTeam(parsedTeam, removeNicknames);
} catch (err) {
require('./crashlogger.js')(err, 'A team validation', {
format: format,
Expand Down
2 changes: 1 addition & 1 deletion users.js
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ class User {
connection.popup("You are already searching a battle in that format.");
return Promise.resolve(false);
}
return TeamValidator(formatid).prepTeam(this.team).then(result => this.finishPrepBattle(connection, result));
return TeamValidator(formatid).prepTeam(this.team, this.locked || this.namelocked).then(result => this.finishPrepBattle(connection, result));
}
finishPrepBattle(connection, result) {
if (result.charAt(0) !== '1') {
Expand Down

0 comments on commit 1daec1a

Please sign in to comment.