<commit_before>(function() {
  var BasicMode = require('./basic_mode.js'),
      _ = require('underscore');
  
  var MasterMode = BasicMode.extend({
    init: function(mpd, clients, cmdProcessors) {
      this._super(mpd, clients, cmdProcessors);
      
      this.type = 'master';
      
      this.master = null;
    },
    
    connected: function(client) {
      this.clients.push(client);
      
      if (!this.master && this.clients.length) {
        this.setMaster(this.clients[0]);
      }
      
      client.emit('connected', {
        id: client.userid,
        clients: _.map(this.clients, function(v) { return v.userid; }),
        mode: this.type,
        master: this.master && this.master.userid
      });
    },
    
    disconnected: function(client) {
      this.clients = this.clients.splice(this.clients.indexOf(client), 1);
      
      if (!this.clients.length) {
        console.log('hit 1');
        this.setMaster(null);
      } else if (this.clients[0] !== this.master) {
        console.log('hit 2');
        this.setMaster(this.clients[0]);
      }
    },
    
    canExecute: function(command, client) {
      return this.isMaster(client) || true;
    },
    
    isMaster: function(client) {
      return this.master === client;
    },
    
    setMaster: function(client) {
      
      console.log('master changed');
    
      this.master = client;
      
      if (this.master) {
        this.master.emit('master', this.master.userid);
        this.master.broadcast.emit('master', this.master.userid);
      }
    }
    
  });
  
  if (this.define && define.amd) {
    // Publish as AMD module
    define(function() {
      return MasterMode;
    });
  } else if (typeof(module) != 'undefined' && module.exports) {
    // Publish as node.js module
    module.exports = MasterMode;
  }
})();<commit_msg>Added whitelist of read-only or publicly-allowed commands for Master Mode.<commit_after>(function() {
  var BasicMode = require('./basic_mode.js'),
      _ = require('underscore');
  
  var MasterMode = BasicMode.extend({
    init: function(mpd, clients, cmdProcessors) {
      this._super(mpd, clients, cmdProcessors);
      
      this.type = 'master';
      
      this.master = null;
    },
    
    connected: function(client) {
      this.clients.push(client);
      
      if (!this.master && this.clients.length) {
        this.setMaster(this.clients[0]);
      }
      
      client.emit('connected', {
        id: client.userid,
        clients: _.map(this.clients, function(v) { return v.userid; }),
        mode: this.type,
        master: this.master && this.master.userid
      });
    },
    
    disconnected: function(client) {
      this.clients = this.clients.splice(this.clients.indexOf(client), 1);
      
      if (!this.clients.length) {
        this.setMaster(null);
      } else if (this.clients[0] !== this.master) {
        this.setMaster(this.clients[0]);
      }
    },
    
    canExecute: function(command, client) {
      return this.isMaster(client) || isWhitelistCommand(command);
    },
    
    isMaster: function(client) {
      return this.master === client;
    },
    
    setMaster: function(client) {
      
      console.log('master changed');
    
      this.master = client;
      
      if (this.master) {
        this.master.emit('master', this.master.userid);
        this.master.broadcast.emit('master', this.master.userid);
      }
    },
    
    isWhitelistCommand: function(cmd) {
      return (this.commandWhitelist.indexOf(cmd.command) !== -1);
    },
    
    commandWhitelist: ['currentsong', 'status', 'playlistinfo', 'list']
    
  });
  
  if (this.define && define.amd) {
    // Publish as AMD module
    define(function() {
      return MasterMode;
    });
  } else if (typeof(module) != 'undefined' && module.exports) {
    // Publish as node.js module
    module.exports = MasterMode;
  }
})();
{'fraction_non_alphanumeric': 0.14938398357289528, 'fraction_numerical': 0.0028234086242299797, 'mean_word_length': 2.2100494233937398, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4784992', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1223, 'n_words': 215}