48 lines
1.0 KiB
TypeScript
48 lines
1.0 KiB
TypeScript
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;
|
|
}
|
|
|
|
} |