Skip to content

Commit

Permalink
Don't allow players to choose monster/NPC name (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpawel10 authored and DSpeichert committed Jan 8, 2018
1 parent 1bc82eb commit bb944ad
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions DevAAC/routes/players.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,23 @@
if($player)
throw new InputErrorException('Player with this name already exists.', 400);

$forbiddenPlayerNames = [];

if (file_exists(TFS_ROOT . '/data/monster/monsters.xml')) {
$xml = simplexml_load_file(TFS_ROOT . '/data/monster/monsters.xml');
if (property_exists($xml, 'monster'))
$forbiddenPlayerNames = array_map('strtolower', array_column(xml2array($xml)['monster'], 'name'));
}

foreach (glob(TFS_ROOT . '/data/npc/*.xml') as $npcFile) {
$xml = simplexml_load_file($npcFile);
if (property_exists($xml->attributes(), 'name'))
array_push($forbiddenPlayerNames, strtolower(xml2array($xml->attributes()->name)[0]));
}

if( in_array(strtolower($req->getAPIParam('name')), $forbiddenPlayerNames) )
throw new InputErrorException('This player name is forbidden.', 400);

$player = new Player(
array(
'name' => ucwords(strtolower($req->getAPIParam('name'))),
Expand Down

0 comments on commit bb944ad

Please sign in to comment.