mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-05 19:20:54 +00:00
add username to the player object
This commit is contained in:
parent
c3f0645771
commit
a00082b57a
4 changed files with 18 additions and 12 deletions
|
|
@ -41,6 +41,7 @@
|
||||||
- [Player](#player)
|
- [Player](#player)
|
||||||
- [Properties](#properties-1)
|
- [Properties](#properties-1)
|
||||||
- [player.entity](#playerentity)
|
- [player.entity](#playerentity)
|
||||||
|
- [player.username](#playerusername)
|
||||||
- [Events](#events-1)
|
- [Events](#events-1)
|
||||||
- ["connected"](#connected)
|
- ["connected"](#connected)
|
||||||
- ["spawned"](#spawned)
|
- ["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`
|
The entity of the player, of type `CraftyJS.Entity`
|
||||||
|
|
||||||
|
#### player.username
|
||||||
|
|
||||||
|
The username of the player
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
#### "connected"
|
#### "connected"
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ module.exports=inject;
|
||||||
function inject(serv,player)
|
function inject(serv,player)
|
||||||
{
|
{
|
||||||
player._client.on('chat', function (data) {
|
player._client.on('chat', function (data) {
|
||||||
serv.broadcast('<' + player._client.username + '>' + ' ' + data.message);
|
serv.broadcast('<' + player.username + '>' + ' ' + data.message);
|
||||||
player.emit("chat",data.message);
|
player.emit("chat",data.message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ function inject(serv,player)
|
||||||
|
|
||||||
player.on("connected",function(){
|
player.on("connected",function(){
|
||||||
var addr = player._client.socket.remoteAddress + ':' + player._client.socket.remotePort;
|
var addr = player._client.socket.remoteAddress + ':' + player._client.socket.remotePort;
|
||||||
console.log("[INFO]: " + player._client.username + ' connected', '(' + addr + ')');
|
console.log("[INFO]: " + player.username + ' connected', '(' + addr + ')');
|
||||||
serv.log("[INFO]: " + player._client.username + ' connected', '(' + addr + ')');
|
serv.log("[INFO]: " + player.username + ' connected', '(' + addr + ')');
|
||||||
});
|
});
|
||||||
|
|
||||||
player.on("spawned",function(){
|
player.on("spawned",function(){
|
||||||
|
|
@ -15,8 +15,8 @@ function inject(serv,player)
|
||||||
});
|
});
|
||||||
|
|
||||||
player.on("disconnected",function(){
|
player.on("disconnected",function(){
|
||||||
console.log("[INFO]: " + player._client.username + ' disconnected', '(' + addr + ')');
|
console.log("[INFO]: " + player.username + ' disconnected', '(' + addr + ')');
|
||||||
serv.log("[INFO]: " + player._client.username + ' disconnected', '(' + addr + ')');
|
serv.log("[INFO]: " + player.username + ' disconnected', '(' + addr + ')');
|
||||||
});
|
});
|
||||||
|
|
||||||
player.on("error",function(error){
|
player.on("error",function(error){
|
||||||
|
|
@ -25,7 +25,7 @@ function inject(serv,player)
|
||||||
});
|
});
|
||||||
|
|
||||||
player.on("chat",function(message){
|
player.on("chat",function(message){
|
||||||
message = '<' + player._client.username + '>' + ' ' + message;
|
message = '<' + player.username + '>' + ' ' + message;
|
||||||
console.log("[INFO] " + message);
|
console.log("[INFO] " + message);
|
||||||
serv.log("[INFO] " + message);
|
serv.log("[INFO] " + message);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ function inject(serv,player)
|
||||||
{
|
{
|
||||||
serv.entityMaxId++;
|
serv.entityMaxId++;
|
||||||
player.entity=new Entity(serv.entityMaxId);
|
player.entity=new Entity(serv.entityMaxId);
|
||||||
|
player.username=player._client.username;
|
||||||
serv.players.push(player);
|
serv.players.push(player);
|
||||||
serv.uuidToPlayer[player._client.uuid] = player;
|
serv.uuidToPlayer[player._client.uuid] = player;
|
||||||
}
|
}
|
||||||
|
|
@ -78,12 +79,12 @@ function inject(serv,player)
|
||||||
action: 0,
|
action: 0,
|
||||||
data: [{
|
data: [{
|
||||||
UUID: transformUuid(player._client.uuid),
|
UUID: transformUuid(player._client.uuid),
|
||||||
name: player._client.username,
|
name: player.username,
|
||||||
properties: [],
|
properties: [],
|
||||||
gamemode: 0,
|
gamemode: 0,
|
||||||
ping: 1,
|
ping: 1,
|
||||||
hasDisplayName: true,
|
hasDisplayName: true,
|
||||||
displayName: player._client.username
|
displayName: player.username
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -93,12 +94,12 @@ function inject(serv,player)
|
||||||
.map(function (otherPlayer) {
|
.map(function (otherPlayer) {
|
||||||
return {
|
return {
|
||||||
UUID: transformUuid(otherPlayer._client.uuid),
|
UUID: transformUuid(otherPlayer._client.uuid),
|
||||||
name: otherPlayer._client.username,
|
name: otherPlayer.username,
|
||||||
properties: [],
|
properties: [],
|
||||||
gamemode: 0,
|
gamemode: 0,
|
||||||
ping: 1,
|
ping: 1,
|
||||||
hasDisplayName: true,
|
hasDisplayName: true,
|
||||||
displayName: otherPlayer._client.username
|
displayName: otherPlayer.username
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
@ -136,7 +137,7 @@ function inject(serv,player)
|
||||||
|
|
||||||
function announceJoin()
|
function announceJoin()
|
||||||
{
|
{
|
||||||
serv.broadcast(player._client.username + ' joined the game.', "yellow");
|
serv.broadcast(player.username + ' joined the game.', "yellow");
|
||||||
player.emit("connected");
|
player.emit("connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,7 +163,7 @@ function inject(serv,player)
|
||||||
|
|
||||||
|
|
||||||
player._client.on('end', function () {
|
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');
|
player.emit('disconnect');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue