Fix player ID issues FULLY
This commit is contained in:
parent
b8ca8c13d1
commit
cf8772f0ed
|
@ -8,7 +8,7 @@ export class Player {
|
|||
private server: Server;
|
||||
|
||||
username: string;
|
||||
|
||||
id: number;
|
||||
world = "main";
|
||||
position: Position;
|
||||
rotation: Rotation = { yaw: 0, pitch: 0 };
|
||||
|
@ -23,6 +23,14 @@ export class Player {
|
|||
this.username = username;
|
||||
this.position = position;
|
||||
this.server = server;
|
||||
|
||||
let id = Math.floor(Math.random() * 255);
|
||||
|
||||
// reassigns ID until finds available one
|
||||
// if we reach 255 players this will loop forever
|
||||
while(server.players.find(e => e.id == id)) id = Math.floor(Math.random() * 255);
|
||||
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
async writeToSocket(ar: Uint8Array) {
|
||||
|
@ -46,7 +54,7 @@ export class Player {
|
|||
|
||||
async toWorld(world: World) {
|
||||
this.server.broadcastPacket(
|
||||
(e) => PacketDefinitions.despawn(this.server.players.indexOf(this), e),
|
||||
(e) => PacketDefinitions.despawn(this.id, e),
|
||||
this,
|
||||
);
|
||||
|
||||
|
@ -56,11 +64,11 @@ export class Player {
|
|||
|
||||
this.server.broadcastPacket(
|
||||
(e) =>
|
||||
PacketDefinitions.spawn(this, this.server.players.indexOf(this), e),
|
||||
PacketDefinitions.spawn(this, this.id, e),
|
||||
this,
|
||||
);
|
||||
this.server.broadcastPacket(
|
||||
(e) => PacketDefinitions.spawn(e, this.server.players.indexOf(e), this),
|
||||
(e) => PacketDefinitions.spawn(e, e.id, this),
|
||||
this,
|
||||
);
|
||||
|
||||
|
|
|
@ -134,14 +134,12 @@ export class Server {
|
|||
|
||||
if (!player) return;
|
||||
|
||||
const index = this.players.indexOf(player);
|
||||
|
||||
this.players = this.players.filter((e) => e != player);
|
||||
|
||||
this.broadcast(`${player.username} has &cleft`);
|
||||
this.worlds.find((e) => e.name == player.world)!.save();
|
||||
|
||||
this.broadcastPacket((e) => PacketDefinitions.despawn(index, e), player);
|
||||
this.broadcastPacket((e) => PacketDefinitions.despawn(player.id, e), player);
|
||||
}
|
||||
|
||||
async handlePacket(packet: PacketReader, connection: Deno.Conn) {
|
||||
|
@ -216,7 +214,7 @@ export class Server {
|
|||
this.broadcastPacket((e) =>
|
||||
PacketDefinitions.movement(
|
||||
player,
|
||||
this.players.indexOf(player),
|
||||
player.id,
|
||||
e,
|
||||
), player);
|
||||
} else if (packetType == 0x0d) {
|
||||
|
|
|
@ -34,7 +34,6 @@ your environment variables
|
|||
### issues:
|
||||
1. plugin system event handling is lackluster in some palces
|
||||
2. tcp packet splitting fails sometimes
|
||||
3. the player-id implementation totally sucks!! it sometimes merges players together and soforth
|
||||
4. no cpe support! i want to get all of the above issues fixed before implementing CPE support
|
||||
5. proper rank support (implemented as plugin)
|
||||
6. no discord bridge (implemented as plugin)
|
||||
3. no cpe support! i want to get all of the above issues fixed before implementing CPE support
|
||||
4. proper rank support (implemented as plugin)
|
||||
5. no discord bridge (implemented as plugin)
|
||||
|
|
Loading…
Reference in a new issue