add username to the player object

This commit is contained in:
Romain Beaumont 2015-08-26 21:48:56 +02:00
parent c3f0645771
commit a00082b57a
4 changed files with 18 additions and 12 deletions

View file

@ -41,6 +41,7 @@
- [Player](#player)
- [Properties](#properties-1)
- [player.entity](#playerentity)
- [player.username](#playerusername)
- [Events](#events-1)
- ["connected"](#connected)
- ["spawned"](#spawned)
@ -201,6 +202,10 @@ broadcasts `message` to all the players with the optional `color`.
The entity of the player, of type `CraftyJS.Entity`
#### player.username
The username of the player
### Events
#### "connected"

View file

@ -3,7 +3,7 @@ module.exports=inject;
function inject(serv,player)
{
player._client.on('chat', function (data) {
serv.broadcast('<' + player._client.username + '>' + ' ' + data.message);
serv.broadcast('<' + player.username + '>' + ' ' + data.message);
player.emit("chat",data.message);
});

View file

@ -5,8 +5,8 @@ function inject(serv,player)
player.on("connected",function(){
var addr = player._client.socket.remoteAddress + ':' + player._client.socket.remotePort;
console.log("[INFO]: " + player._client.username + ' connected', '(' + addr + ')');
serv.log("[INFO]: " + player._client.username + ' connected', '(' + addr + ')');
console.log("[INFO]: " + player.username + ' connected', '(' + addr + ')');
serv.log("[INFO]: " + player.username + ' connected', '(' + addr + ')');
});
player.on("spawned",function(){
@ -15,8 +15,8 @@ function inject(serv,player)
});
player.on("disconnected",function(){
console.log("[INFO]: " + player._client.username + ' disconnected', '(' + addr + ')');
serv.log("[INFO]: " + player._client.username + ' disconnected', '(' + addr + ')');
console.log("[INFO]: " + player.username + ' disconnected', '(' + addr + ')');
serv.log("[INFO]: " + player.username + ' disconnected', '(' + addr + ')');
});
player.on("error",function(error){
@ -25,7 +25,7 @@ function inject(serv,player)
});
player.on("chat",function(message){
message = '<' + player._client.username + '>' + ' ' + message;
message = '<' + player.username + '>' + ' ' + message;
console.log("[INFO] " + message);
serv.log("[INFO] " + message);
});

View file

@ -16,6 +16,7 @@ function inject(serv,player)
{
serv.entityMaxId++;
player.entity=new Entity(serv.entityMaxId);
player.username=player._client.username;
serv.players.push(player);
serv.uuidToPlayer[player._client.uuid] = player;
}
@ -78,12 +79,12 @@ function inject(serv,player)
action: 0,
data: [{
UUID: transformUuid(player._client.uuid),
name: player._client.username,
name: player.username,
properties: [],
gamemode: 0,
ping: 1,
hasDisplayName: true,
displayName: player._client.username
displayName: player.username
}]
});
@ -93,12 +94,12 @@ function inject(serv,player)
.map(function (otherPlayer) {
return {
UUID: transformUuid(otherPlayer._client.uuid),
name: otherPlayer._client.username,
name: otherPlayer.username,
properties: [],
gamemode: 0,
ping: 1,
hasDisplayName: true,
displayName: otherPlayer._client.username
displayName: otherPlayer.username
};
})
});
@ -136,7 +137,7 @@ function inject(serv,player)
function announceJoin()
{
serv.broadcast(player._client.username + ' joined the game.', "yellow");
serv.broadcast(player.username + ' joined the game.', "yellow");
player.emit("connected");
}
@ -162,7 +163,7 @@ function inject(serv,player)
player._client.on('end', function () {
serv.broadcast(player._client.username + ' quit the game.', "yellow");
serv.broadcast(player.username + ' quit the game.', "yellow");
player.emit('disconnect');
});