Промежуточный этап синхронизации

This commit is contained in:
RoyceDa
2026-02-15 14:56:44 +02:00
parent 40ff99e66d
commit 8b906169ce
15 changed files with 609 additions and 427 deletions

View File

@@ -0,0 +1,48 @@
import Packet from "../packet";
import Stream from "../stream";
export enum SyncStatus {
NOT_NEEDED,
BATCH_START,
BATCH_END
}
export class PacketSync extends Packet {
private status : SyncStatus = SyncStatus.NOT_NEEDED;
private timestamp : number = 0;
public getPacketId(): number {
return 25; //0x19
}
public _receive(stream: Stream): void {
this.status = stream.readInt8() as SyncStatus;
this.timestamp = stream.readInt64();
}
public _send(): Promise<Stream> | Stream {
let stream = new Stream();
stream.writeInt16(this.getPacketId());
stream.writeInt8(this.status);
stream.writeInt64(this.timestamp);
return stream;
}
public getStatus() : SyncStatus {
return this.status;
}
public setStatus(status: SyncStatus) {
this.status = status;
}
public getTimestamp() : number {
return this.timestamp;
}
public setTimestamp(timestamp: number) {
this.timestamp = timestamp;
}
}

View File

@@ -24,6 +24,7 @@ import { PacketGroupBan } from "./packets/packet.group.ban";
import { PacketDeviceNew } from "./packets/packet.device.new";
import { PacketDeviceList } from "./packets/packet.device.list";
import { PacketDeviceResolve } from "./packets/packet.device.resolve";
import { PacketSync } from "./packets/packet.sync";
export default class Protocol extends EventEmitter {
private serverAddress: string;
@@ -123,6 +124,7 @@ export default class Protocol extends EventEmitter {
this._supportedPackets.set(0x16, new PacketGroupBan());
this._supportedPackets.set(0x17, new PacketDeviceList());
this._supportedPackets.set(0x18, new PacketDeviceResolve());
this._supportedPackets.set(25, new PacketSync());
}
private _findWaiters(packetId: number): ((packet: Packet) => void)[] {