<commit_before>/**
 * PlayerController
 *
 * @description :: Server-side logic for managing players
 * @help        :: See http://links.sailsjs.org/docs/controllers
 */

module.exports = {

	create: function(req, res) {
    var newPlayer;

    Player.create({name: req.body.name,
                   game: req.body.game,
                   room: req.body.room,
                   locX: 64,
                   locY: 64,
                   socket: req.socket.id,
                   color: req.body.color,
                   maxHealth: 3,
                   curHealth: 3,
                   speed: 5,
                   weapon: 1,
                   relics: 0,
                   keys: 0,
                   isTraitor: false})
      .then(function(player) {
        newPlayer = player;

        Room.subscribe(req, newPlayer.room, ['message']);

        return Player.find({game: newPlayer.game});
      })
      .then(function(players) {
        Player.watch(req);
        Player.subscribe(req, players, ['update', 'destroy']);

        /* Publish player creation */
        Player.publishCreate(newPlayer);

        res.json(newPlayer);
      })
      .catch(function(err) {
        sails.log.error(err);
        res.json(err);
      });
  },

  update: function(req, res) {
    Player.update(req.param('id'), req.body)
      .then(function(players) {
        var updatedPlayer = players[0];

        if (req.body.locX !== undefined && req.body.locY !== undefined) {
          Room.message(updatedPlayer.room, {id: updatedPlayer.id,
                                            verb: 'playerUpdated',
                                            data: req.body});
        } else {
          Player.publishUpdate(updatedPlayer.id, req.body);
        }

        res.json();
      })
      .catch(function(err) {
        sails.log.error(err);
        res.json(err);
      });
  },

  destroy: function(req, res) {
    Player.findOne(req.param('id'))
      .then(function(player) {
      if (!player.isTraitor) {
        Game.message(player.game, {verb: 'traitorWon'});<commit_msg>Fixed bug that caused infinite loop of stat updates.<commit_after>/**
 * PlayerController
 *
 * @description :: Server-side logic for managing players
 * @help        :: See http://links.sailsjs.org/docs/controllers
 */

module.exports = {

	create: function(req, res) {
    var newPlayer;

    Player.create({name: req.body.name,
                   game: req.body.game,
                   room: req.body.room,
                   locX: 64,
                   locY: 64,
                   socket: req.socket.id,
                   color: req.body.color,
                   maxHealth: 3,
                   curHealth: 3,
                   speed: 5,
                   weapon: 1,
                   relics: 0,
                   keys: 0,
                   isTraitor: false})
      .then(function(player) {
        newPlayer = player;

        Room.subscribe(req, newPlayer.room, ['message']);

        return Player.find({game: newPlayer.game});
      })
      .then(function(players) {
        Player.watch(req);
        Player.subscribe(req, players, ['update', 'destroy']);

        /* Publish player creation */
        Player.publishCreate(newPlayer);

        res.json(newPlayer);
      })
      .catch(function(err) {
        sails.log.error(err);
        res.json(err);
      });
  },

  update: function(req, res) {
    Player.update(req.param('id'), req.body)
      .then(function(players) {
        var updatedPlayer = players[0];

        if (req.body.locX !== undefined && req.body.locY !== undefined) {
          Room.message(updatedPlayer.room, {id: updatedPlayer.id,
                                            verb: 'playerUpdated',
                                            data: req.body});
        } else {
          Player.publishUpdate(updatedPlayer.id, req.body, req);
        }

        res.json();
      })
      .catch(function(err) {
        sails.log.error(err);
        res.json(err);
      });
  },

  destroy: function(req, res) {
    Player.findOne(req.param('id'))
      .then(function(player) {
      if (!player.isTraitor) {
        Game.message(player.game, {verb: 'traitorWon'});
{'fraction_non_alphanumeric': 0.13651551312649166, 'fraction_numerical': 0.005250596658711217, 'mean_word_length': 1.5262206148282098, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1062108', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1166, 'n_words': 220}