h1z1-server 0.22.2-1 → 0.22.2-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -56,6 +56,7 @@ export class ZoneClient2016 {
|
|
|
56
56
|
avgPingLen: number = 4;
|
|
57
57
|
pingWarnings: number = 0;
|
|
58
58
|
isWeaponLock: boolean = false;
|
|
59
|
+
avgPingReady: boolean = false;
|
|
59
60
|
constructor(
|
|
60
61
|
sessionId: number,
|
|
61
62
|
soeClientId: string,
|
|
@@ -84,13 +85,20 @@ export class ZoneClient2016 {
|
|
|
84
85
|
this.character = new Character2016(characterId, transientId);
|
|
85
86
|
}
|
|
86
87
|
addPing(ping: number) {
|
|
87
|
-
|
|
88
|
+
if (ping > 0) {
|
|
89
|
+
this.pings.push(ping);
|
|
90
|
+
}
|
|
88
91
|
if (this.pings.length > this.avgPingLen) {
|
|
89
92
|
this.pings.shift();
|
|
90
93
|
}
|
|
91
|
-
this.
|
|
94
|
+
if (this.pings.length === this.avgPingLen) {
|
|
95
|
+
this.updateAvgPing();
|
|
96
|
+
} else {
|
|
97
|
+
this.avgPingReady = false;
|
|
98
|
+
}
|
|
92
99
|
}
|
|
93
100
|
updateAvgPing() {
|
|
94
101
|
this.avgPing = toInt(_.sum(this.pings) / this.pings.length);
|
|
102
|
+
this.avgPingReady = true;
|
|
95
103
|
}
|
|
96
104
|
}
|
|
@@ -132,7 +132,11 @@ export const commands: Array<Command> = [
|
|
|
132
132
|
const soeClient = server.getSoeClient(client.soeClientId);
|
|
133
133
|
if (soeClient) {
|
|
134
134
|
const stats = soeClient.getNetworkStats();
|
|
135
|
-
|
|
135
|
+
if (client.avgPingReady) {
|
|
136
|
+
stats.push(`Ping: ${client.avgPing}ms`);
|
|
137
|
+
} else {
|
|
138
|
+
stats.push(`Ping: estimates in progress`);
|
|
139
|
+
}
|
|
136
140
|
for (let index = 0; index < stats.length; index++) {
|
|
137
141
|
const stat = stats[index];
|
|
138
142
|
server.sendChatText(client, stat, index == 0);
|
|
@@ -295,26 +295,28 @@ export class zonePacketHandlers {
|
|
|
295
295
|
client: Client,
|
|
296
296
|
packet: { data: GameTimeSync }
|
|
297
297
|
) {
|
|
298
|
-
const serverTime = Date.now();
|
|
299
|
-
const clientTime = Number(packet.data.time) * 1000;
|
|
300
|
-
const rawPing = serverTime - clientTime;
|
|
301
|
-
client.addPing(rawPing);
|
|
302
|
-
if (client.avgPing > server.maxPing) {
|
|
303
|
-
server.warnHighPing(client);
|
|
304
|
-
} else if (client.isWeaponLock && client.avgPing < server.maxPing) {
|
|
305
|
-
client.pingWarnings = 0;
|
|
306
|
-
server.unlockWeapon(client);
|
|
307
|
-
}
|
|
308
298
|
server.sendGameTimeSync(client);
|
|
309
299
|
}
|
|
310
300
|
Synchronization(server: ZoneServer2016, client: Client, packet: any) {
|
|
301
|
+
const fullServerTime = Date.now();
|
|
311
302
|
const serverTime = Int64String(Number((Date.now() / 1000).toFixed(0)));
|
|
312
303
|
const reflectedPacket: Synchronization = {
|
|
313
304
|
...packet.data,
|
|
314
305
|
serverTime: serverTime,
|
|
315
306
|
serverTime2: serverTime,
|
|
316
|
-
time3: Int64String(Number(packet.data.clientTime)
|
|
307
|
+
time3: Int64String(Number(packet.data.clientTime)),
|
|
317
308
|
};
|
|
309
|
+
const fullClientTimestamp =
|
|
310
|
+
Number(packet.data.clientTime) * 1000 +
|
|
311
|
+
Number(String(Number(packet.data.clientHoursMs)).slice(-3));
|
|
312
|
+
const rawPing = fullServerTime - fullClientTimestamp;
|
|
313
|
+
client.addPing(rawPing);
|
|
314
|
+
if (client.avgPing > server.maxPing) {
|
|
315
|
+
server.warnHighPing(client);
|
|
316
|
+
} else if (client.isWeaponLock && client.avgPing < server.maxPing) {
|
|
317
|
+
client.pingWarnings = 0;
|
|
318
|
+
server.unlockWeapon(client);
|
|
319
|
+
}
|
|
318
320
|
server.sendData(client, "Synchronization", reflectedPacket);
|
|
319
321
|
}
|
|
320
322
|
CommandExecuteCommand(server: ZoneServer2016, client: Client, packet: any) {
|