There are a few ways you can go about doing this.

Firstly, you would want to create a list in Game Data Service to store the details of the cheaters you want to ban.

var bannedPlayerId = Spark.getData().bannedPlayer //assuming the playerId is being passed in as an event attribute
var gds = Spark.getGameDataService();
var item = gds.createItem("bannedPlayers", bannedPlayerId);
item.setData({"userName":Spark.loadPlayer(bannedPlayerId).getUserName(),"reason":"cheating"});
item.persistor().persist();


If you are working with usernames, you can simply check the username of the player in an AuthenticationRequest against the list of players in your list and if the player is listed then throw an error.

var gds = Spark.getGameDataService();
var cond = gds.S("userName").eq(Spark.getData().userName);
var res = gds.queryItems("bannedPlayers", cond);
if(res.cursor().hasNext()){ //a match was found, the player is on the banned list
    Spark.setScriptError("error", "Banned for " + res.cursor().next().getData().reason);
}


Note: you will need to add 'userName' as an index to your data type for the above to work. You can read more on how to do this in our documentation.

Alternatively, you can get the player's ID, and check that against your list in your Cloud Code System script GS_PLAYER_CONNECT which runs when the player first connects. If the player's ID matches one from your list, disconnect them.

For checking playerId in the AuthenticationResponse:

var gds = Spark.getGameDataService();
var item = gds.getItem("bannedPlayers", Spark.getPlayer().getPlayerId());
if(item.document()){
 Spark.setScriptError("error", "Banned for " + item.document().getData().reason);
 Spark.getPlayer().disconnect(false);
}


Finally, if you are planning on permanently banning these players, you could also just delete the accounts.

Note: 'deletePlayer' doesn't return a value. If you're trying to return the userName you would need to get it prior to deletion, e.g.:

var player = Spark.loadPlayer(playerId);
if(player){ //I suspect the playerId you're using will cause this check to fail
var userName = player.getUserName();
player.deletePlayer();
}