<commit_before>// Imports
var GameMode = require('../gamemodes');
var Entity = require('../entity');
var ini = require('./ini.js');
var Logger = require('./Logger');

function Commands() {
    this.list = {}; // Empty
}

module.exports = Commands;

// Utils
var fillChar = function (data, char, fieldLength, rTL) {
    var result = data.toString();
    if (rTL === true) {
        for (var i = result.length; i < fieldLength; i++)
            result = char.concat(result);
    } else {
        for (var i = result.length; i < fieldLength; i++)
            result = result.concat(char);
    }
    return result;
};

// Commands

Commands.list = {
    help: function (gameServer, split) {
        console.log("======================== HELP ======================");
        console.log("addbot [number]              : adds bots to the server");
        console.log("kickbot [number]             : kick a number of bots");
        console.log("ban [PlayerID | IP]          : bans a(n) (player's) IP");
        console.log("banlist                      : get list of banned IPs.");
        console.log("board [string] [string] ...  : set scoreboard text");
        console.log("boardreset                   : reset scoreboard text");
        console.log("change [setting] [value]     : change specified settings");
        console.log("clear                        : clear console output");
        console.log("color [PlayerID] [R] [G] [B] : set cell(s) color by client ID");
        console.log("exit                         : stop the server");
        console.log("gamemode [id]                : change server gamemode");
        console.log("kick [PlayerID]              : kick player or bot by client ID");
        console.log("kickall                      : kick all players and bots");
        console.log("mute [PlayerID]              : mute player (block chat messages from him)");
        console.log("unmute [PlayerID]            : unmute player (allow chat messages from him)");
        console.log("kill [PlayerID]              : kill cell(s) by client ID");
        console.log("killall                      : kill everyone");
        console.log("mass [PlayerID] [mass]       : set cell(s) mass by client ID");
        console.log("merge [PlayerID]             : merge all client's cells once");
        console.log("skin [PlayerID] [SkinName]   : change player skin");
        console.log("name [PlayerID] [name]       : change cell(s) name by client ID");
        console.log("playerlist                   : get list of players and bots");
        console.log("pause                        : pause game , freeze all cells");
        console.log("reload                       : reload config");
        console.log("status                       : get server status");
        console.log("tp [PlayerID] [X] [Y]        : teleport player to specified location");
        console.log("unban [IP]                   : unban an IP");
        console.log("virus [X] [Y] [mass]         : spawn virus at a specified Location");
        console.log("minion [PlayerID] [#] [name] : adds suicide minions to the server");
        console.log("spawnmass [PlayerID] [mass]  : sets players spawn mass");
        console.log("freeze [PlayerID]            : freezes a player");
        console.log("speed [PlayerID]             : sets a players base speed");
        console.log("rec [PlayerID]               : puts a player in rec mode");
        console.log("st                           : alias for status");
        console.log("pl                           : alias for playerlist");
        console.log("m                            : alias for mass");
        console.log("sm                           : alias for spawnmass");
        console.log("ka                           : alias for killall");
        console.log("k                            : alias for kill");
        console.log("mg                           : alias for merge");
        console.log("s                            : alias for speed");
        console.log("====================================================");
    },
    debug: function (gameServer, split) {
        // Used for checking node lengths (for now)
        
        // Count client cells
        var clientCells = 0;
        for (var i in gameServer.clients) {
            clientCells += gameServer.clients[i].playerTracker.cells.length;
        }
        // Output node information
        console.log("Clients:        " + fillChar(gameServer.clients.length, " ", 4, true) + " / " + gameServer.config.serverMaxConnections + " + bots");
        console.log("Total nodes:" + fillChar(gameServer.nodes.length, " ", 8, true));
        console.log("- Client cells: " + fillChar(clientCells, " ", 4, true) + " / " + (gameServer.clients.length * gameServer.config.playerMaxCells));
        console.log("- Ejected cells:" + fillChar(gameServer.nodesEjected.length, " ", 4, true));
        console.log("- Foods:        " + fillChar(gameServer.currentFood, " ", 4, true) + " / " + gameServer.config.foodMaxAmount);
        console.log("- Viruses:      " + fillChar(gameServer.nodesVirus.length, " ", 4, true) + " / " + gameServer.config.virusMaxAmount);
        console.log("Moving nodes:   " + fillChar(gameServer.movingNodes.length, " ", 4, true));
        console.log("Quad nodes:     " + fillChar(gameServer.quadTree.scanNodeCount(), " ", 4, true));
        console.log("Quad items:     " + fillChar(gameServer.quadTree.scanItemCount(), " ", 4, true));
    },
    minion: function(gameServer, split) {
        var g = gameServer;
        var id = parseInt(split[1]);
        var add = parseInt(split[2]);
        g.minionName = split[3];
            
        // Error! ID is NaN
        if (isNaN(id)) {
            Logger.warn("Please specify a valid player id!");
            return;
        }
        
        // If no amount is specified
        if (isNaN(add)) {
            add = 1; 
        }
        
        // Default minion names
        if (typeof g.minionName == "undefined") {
            g.minionName = "minion";
        }
        
        // Find ID specified and add/remove minions for them
        for (var i in g.clients) {
            g.minionLeader = g.clients[i].playerTracker;
            var client = g.minionLeader;
            
            if (client.pID == id) {
                // Remove minions
                if (client.minionControl == true && isNaN(add)) {
                    g.minionEnabled = false,
                    client.mi = 0;
                    client.minionControl = false,
                    console.log("Succesfully removed minions for " + client.getFriendlyName());
                // Add minions
                } else {
                    g.minionEnabled = true;
                    client.minionControl = true;
                    // Add minions for client
                    for (var i = 0; i < add; i++) {
                        g.minions.addBot(client);
                    }
                    console.log("Added " + add + " minions for " + client.getFriendlyName());
                }
                break;
            }
        }
    },
    addbot: function (gameServer, split) {
        var add = parseInt(split[1]);
        if (isNaN(add)) {
            add = 1; // Adds 1 bot if user doesnt specify a number
        }
        
        for (var i = 0; i < add; i++) {
            gameServer.bots.addBot();
        }
        console.log("Added " + add + " player bots");
    },
    ban: function (gameServer, split) {
        // Error message
        var logInvalid = "Please specify a valid player ID or IP address!";
        <commit_msg>Minions<commit_after>// Imports
var GameMode = require('../gamemodes');
var Entity = require('../entity');
var ini = require('./ini.js');
var Logger = require('./Logger');

function Commands() {
    this.list = {}; // Empty
}

module.exports = Commands;

// Utils
var fillChar = function (data, char, fieldLength, rTL) {
    var result = data.toString();
    if (rTL === true) {
        for (var i = result.length; i < fieldLength; i++)
            result = char.concat(result);
    } else {
        for (var i = result.length; i < fieldLength; i++)
            result = result.concat(char);
    }
    return result;
};

// Commands

Commands.list = {
    help: function (gameServer, split) {
        console.log("======================== HELP ======================");
        console.log("addbot [number]              : adds bots to the server");
        console.log("kickbot [number]             : kick a number of bots");
        console.log("ban [PlayerID | IP]          : bans a(n) (player's) IP");
        console.log("banlist                      : get list of banned IPs.");
        console.log("board [string] [string] ...  : set scoreboard text");
        console.log("boardreset                   : reset scoreboard text");
        console.log("change [setting] [value]     : change specified settings");
        console.log("clear                        : clear console output");
        console.log("color [PlayerID] [R] [G] [B] : set cell(s) color by client ID");
        console.log("exit                         : stop the server");
        console.log("gamemode [id]                : change server gamemode");
        console.log("kick [PlayerID]              : kick player or bot by client ID");
        console.log("kickall                      : kick all players and bots");
        console.log("mute [PlayerID]              : mute player (block chat messages from him)");
        console.log("unmute [PlayerID]            : unmute player (allow chat messages from him)");
        console.log("kill [PlayerID]              : kill cell(s) by client ID");
        console.log("killall                      : kill everyone");
        console.log("mass [PlayerID] [mass]       : set cell(s) mass by client ID");
        console.log("merge [PlayerID]             : merge all client's cells once");
        console.log("skin [PlayerID] [SkinName]   : change player skin");
        console.log("name [PlayerID] [name]       : change cell(s) name by client ID");
        console.log("playerlist                   : get list of players and bots");
        console.log("pause                        : pause game , freeze all cells");
        console.log("reload                       : reload config");
        console.log("status                       : get server status");
        console.log("tp [PlayerID] [X] [Y]        : teleport player to specified location");
        console.log("unban [IP]                   : unban an IP");
        console.log("virus [X] [Y] [mass]         : spawn virus at a specified Location");
        console.log("minion [PlayerID] [#] [name] : adds suicide minions to the server");
        console.log("spawnmass [PlayerID] [mass]  : sets players spawn mass");
        console.log("freeze [PlayerID]            : freezes a player");
        console.log("speed [PlayerID]             : sets a players base speed");
        console.log("rec [PlayerID]               : puts a player in rec mode");
        console.log("st                           : alias for status");
        console.log("pl                           : alias for playerlist");
        console.log("m                            : alias for mass");
        console.log("sm                           : alias for spawnmass");
        console.log("ka                           : alias for killall");
        console.log("k                            : alias for kill");
        console.log("mg                           : alias for merge");
        console.log("s                            : alias for speed");
        console.log("====================================================");
    },
    debug: function (gameServer, split) {
        // Used for checking node lengths (for now)
        
        // Count client cells
        var clientCells = 0;
        for (var i in gameServer.clients) {
            clientCells += gameServer.clients[i].playerTracker.cells.length;
        }
        // Output node information
        console.log("Clients:        " + fillChar(gameServer.clients.length, " ", 4, true) + " / " + gameServer.config.serverMaxConnections + " + bots");
        console.log("Total nodes:" + fillChar(gameServer.nodes.length, " ", 8, true));
        console.log("- Client cells: " + fillChar(clientCells, " ", 4, true) + " / " + (gameServer.clients.length * gameServer.config.playerMaxCells));
        console.log("- Ejected cells:" + fillChar(gameServer.nodesEjected.length, " ", 4, true));
        console.log("- Foods:        " + fillChar(gameServer.currentFood, " ", 4, true) + " / " + gameServer.config.foodMaxAmount);
        console.log("- Viruses:      " + fillChar(gameServer.nodesVirus.length, " ", 4, true) + " / " + gameServer.config.virusMaxAmount);
        console.log("Moving nodes:   " + fillChar(gameServer.movingNodes.length, " ", 4, true));
        console.log("Quad nodes:     " + fillChar(gameServer.quadTree.scanNodeCount(), " ", 4, true));
        console.log("Quad items:     " + fillChar(gameServer.quadTree.scanItemCount(), " ", 4, true));
    },
    minion: function(gameServer, split) {
        var g = gameServer;
        var id = parseInt(split[1]);
        var add = parseInt(split[2]);
        g.minionName = split[3];
            
        // Error! ID is NaN
        if (isNaN(id)) {
            Logger.warn("Please specify a valid player id!");
            return;
        }
        
        // If no amount is specified
        if (isNaN(add)) {
            add = 1; 
        }
        
        // Default minion names
        if (typeof g.minionName == "undefined") {
            g.minionName = "minion";
        }
        
        // Find ID specified and add/remove minions for them
        for (var i in g.clients) {
            g.minionLeader = g.clients[i].playerTracker;
            var client = g.minionLeader;
            
            if (client.pID == id) {
                // Remove minions
                if (client.minionControl == true && isNaN(add)) {
                    g.minionEnabled = false,
                    client.miQ = 0;
                    client.minionControl = false,
                    console.log("Succesfully removed minions for " + client.getFriendlyName());
                // Add minions
                } else {
                    g.minionEnabled = true;
                    client.minionControl = true;
                    // Add minions for client
                    for (var i = 0; i < add; i++) {
                        g.minions.addBot(client);
                    }
                    console.log("Added " + add + " minions for " + client.getFriendlyName());
                }
                break;
            }
        }
    },
    addbot: function (gameServer, split) {
        var add = parseInt(split[1]);
        if (isNaN(add)) {
            add = 1; // Adds 1 bot if user doesnt specify a number
        }
        
        for (var i = 0; i < add; i++) {
            gameServer.bots.addBot();
        }
        console.log("Added " + add + " player bots");
    },
    ban: function (gameServer, split) {
        // Error message
        var logInvalid = "Please specify a valid player ID or IP address!";
        
{'fraction_non_alphanumeric': 0.14034169012240624, 'fraction_numerical': 0.002618315114223997, 'mean_word_length': 1.6473748050597816, 'pattern_counts': {'":': 0, '<': 11, '<?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': '329084', 'n_tokens_mistral': 4153, 'n_tokens_neox': 4016, 'n_words': 1106}