h1z1-server 0.23.4-0 → 0.23.4-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 +1 -1
- package/src/packets/ClientProtocol/ClientProtocol_1080/voice.ts +41 -41
- package/src/protocols/h1emuprotocol.ts +216 -216
- package/src/servers/H1emuServer/h1emuLoginServer.ts +58 -58
- package/src/servers/LoginServer/loginserver.ts +1086 -1086
- package/src/servers/LoginServer/workers/httpServer.ts +124 -124
- package/src/servers/SoeServer/soeclient.ts +105 -105
- package/src/servers/SoeServer/soeserver.ts +593 -593
- package/src/servers/ZoneServer2015/zoneserver.ts +2674 -2674
- package/src/servers/ZoneServer2016/classes/baseItem.ts +43 -43
- package/src/servers/ZoneServer2016/classes/gridcell.ts +13 -13
- package/src/servers/ZoneServer2016/classes/loadoutItem.ts +71 -71
- package/src/servers/ZoneServer2016/classes/zoneclient.ts +128 -128
- package/src/servers/ZoneServer2016/commands/commandhandler.ts +148 -148
- package/src/servers/ZoneServer2016/commands/commands.ts +2 -4
- package/src/servers/ZoneServer2016/data/lootspawns.ts +2594 -2594
- package/src/servers/ZoneServer2016/entities/basefullcharacter.ts +1027 -1027
- package/src/servers/ZoneServer2016/entities/character.ts +775 -775
- package/src/servers/ZoneServer2016/entities/constructionchildentity.ts +547 -547
- package/src/servers/ZoneServer2016/entities/constructiondoor.ts +310 -310
- package/src/servers/ZoneServer2016/entities/constructionparententity.ts +585 -585
- package/src/servers/ZoneServer2016/entities/explosiveentity.ts +118 -118
- package/src/servers/ZoneServer2016/entities/itemobject.ts +100 -100
- package/src/servers/ZoneServer2016/entities/npc.ts +144 -144
- package/src/servers/ZoneServer2016/entities/vehicle.ts +608 -608
- package/src/servers/ZoneServer2016/managers/weathermanager.ts +293 -293
- package/src/servers/ZoneServer2016/managers/worlddatamanager.ts +1216 -1204
- package/src/servers/ZoneServer2016/managers/worldobjectmanager.ts +546 -546
- package/src/servers/ZoneServer2016/models/enums.ts +621 -621
- package/src/servers/ZoneServer2016/zonepackethandlers.ts +15 -2
- package/src/servers/ZoneServer2016/zoneserver.ts +20 -18
- package/src/utils/constants.ts +21 -21
- package/src/utils/enums.ts +51 -51
- package/src/utils/utils.ts +7 -8
package/package.json
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
// ======================================================================
|
|
2
|
-
//
|
|
3
|
-
// GNU GENERAL PUBLIC LICENSE
|
|
4
|
-
// Version 3, 29 June 2007
|
|
5
|
-
// copyright (C) 2020 - 2021 Quentin Gruber
|
|
6
|
-
// copyright (C) 2021 - 2023 H1emu community
|
|
7
|
-
//
|
|
8
|
-
// https://github.com/QuentinGruber/h1z1-server
|
|
9
|
-
// https://www.npmjs.com/package/h1z1-server
|
|
10
|
-
//
|
|
11
|
-
// Based on https://github.com/psemu/soe-network
|
|
12
|
-
// ======================================================================
|
|
13
|
-
|
|
14
|
-
export const voicePackets: any = [
|
|
15
|
-
[
|
|
16
|
-
"Voice.Login",
|
|
17
|
-
0x8200,
|
|
18
|
-
{
|
|
19
|
-
fields: [
|
|
20
|
-
{ name: "clientName", type: "string", defaultValue: "" },
|
|
21
|
-
{ name: "sessionId", type: "string", defaultValue: "" },
|
|
22
|
-
{ name: "url", type: "string", defaultValue: "" },
|
|
23
|
-
{ name: "characterName", type: "string", defaultValue: "" },
|
|
24
|
-
],
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
[
|
|
28
|
-
"Voice.JoinChannel",
|
|
29
|
-
0x8201,
|
|
30
|
-
{
|
|
31
|
-
fields: [
|
|
32
|
-
{ name: "roomType", type: "uint8", defaultValue: 0 },
|
|
33
|
-
{ name: "uri", type: "string", defaultValue: "" },
|
|
34
|
-
{ name: "unknown1", type: "uint32", defaultValue: 0 },
|
|
35
|
-
],
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
["Voice.LeaveChannel", 0x8202, { fields: [] }],
|
|
39
|
-
["Voice.RadioChannel", 0x8207, { fields: [] }],
|
|
40
|
-
["Voice.LeaveRadio", 0x8208, { fields: [] }],
|
|
41
|
-
];
|
|
1
|
+
// ======================================================================
|
|
2
|
+
//
|
|
3
|
+
// GNU GENERAL PUBLIC LICENSE
|
|
4
|
+
// Version 3, 29 June 2007
|
|
5
|
+
// copyright (C) 2020 - 2021 Quentin Gruber
|
|
6
|
+
// copyright (C) 2021 - 2023 H1emu community
|
|
7
|
+
//
|
|
8
|
+
// https://github.com/QuentinGruber/h1z1-server
|
|
9
|
+
// https://www.npmjs.com/package/h1z1-server
|
|
10
|
+
//
|
|
11
|
+
// Based on https://github.com/psemu/soe-network
|
|
12
|
+
// ======================================================================
|
|
13
|
+
|
|
14
|
+
export const voicePackets: any = [
|
|
15
|
+
[
|
|
16
|
+
"Voice.Login",
|
|
17
|
+
0x8200,
|
|
18
|
+
{
|
|
19
|
+
fields: [
|
|
20
|
+
{ name: "clientName", type: "string", defaultValue: "" },
|
|
21
|
+
{ name: "sessionId", type: "string", defaultValue: "" },
|
|
22
|
+
{ name: "url", type: "string", defaultValue: "" },
|
|
23
|
+
{ name: "characterName", type: "string", defaultValue: "" },
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
[
|
|
28
|
+
"Voice.JoinChannel",
|
|
29
|
+
0x8201,
|
|
30
|
+
{
|
|
31
|
+
fields: [
|
|
32
|
+
{ name: "roomType", type: "uint8", defaultValue: 0 },
|
|
33
|
+
{ name: "uri", type: "string", defaultValue: "" },
|
|
34
|
+
{ name: "unknown1", type: "uint32", defaultValue: 0 },
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
["Voice.LeaveChannel", 0x8202, { fields: [] }],
|
|
39
|
+
["Voice.RadioChannel", 0x8207, { fields: [] }],
|
|
40
|
+
["Voice.LeaveRadio", 0x8208, { fields: [] }],
|
|
41
|
+
];
|
|
@@ -1,216 +1,216 @@
|
|
|
1
|
-
// ======================================================================
|
|
2
|
-
//
|
|
3
|
-
// GNU GENERAL PUBLIC LICENSE
|
|
4
|
-
// Version 3, 29 June 2007
|
|
5
|
-
// copyright (C) 2020 - 2021 Quentin Gruber
|
|
6
|
-
// copyright (C) 2021 - 2023 H1emu community
|
|
7
|
-
//
|
|
8
|
-
// https://github.com/QuentinGruber/h1z1-server
|
|
9
|
-
// https://www.npmjs.com/package/h1z1-server
|
|
10
|
-
//
|
|
11
|
-
// Based on https://github.com/psemu/soe-network
|
|
12
|
-
// ======================================================================
|
|
13
|
-
|
|
14
|
-
const debug = require("debug")("H1emuProtocol");
|
|
15
|
-
import DataSchema from "h1z1-dataschema";
|
|
16
|
-
import { H1emuProtocolReadingFormat } from "types/protocols";
|
|
17
|
-
import PacketTableBuild from "../packets/packettable";
|
|
18
|
-
const packets = [
|
|
19
|
-
[
|
|
20
|
-
"SessionRequest",
|
|
21
|
-
0x01,
|
|
22
|
-
{
|
|
23
|
-
fields: [
|
|
24
|
-
{ name: "serverId", type: "uint32", defaultValue: 0 },
|
|
25
|
-
{ name: "h1emuVersion", type: "string", defaultValue: "" },
|
|
26
|
-
],
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
[
|
|
30
|
-
"SessionReply",
|
|
31
|
-
0x02,
|
|
32
|
-
{
|
|
33
|
-
fields: [{ name: "status", type: "uint8", defaultValue: 0 }],
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
[
|
|
37
|
-
"Ping",
|
|
38
|
-
0x03,
|
|
39
|
-
{
|
|
40
|
-
fields: [],
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
["Ack", 0x04, {}],
|
|
44
|
-
[
|
|
45
|
-
"CharacterCreateRequest",
|
|
46
|
-
0x05,
|
|
47
|
-
{
|
|
48
|
-
fields: [
|
|
49
|
-
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
50
|
-
{ name: "characterObjStringify", type: "string", defaultValue: "" },
|
|
51
|
-
],
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
[
|
|
55
|
-
"CharacterCreateReply",
|
|
56
|
-
0x06,
|
|
57
|
-
{
|
|
58
|
-
fields: [
|
|
59
|
-
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
60
|
-
{ name: "status", type: "boolean", defaultValue: 0 },
|
|
61
|
-
],
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
[
|
|
65
|
-
"CharacterDeleteRequest",
|
|
66
|
-
0x07,
|
|
67
|
-
{
|
|
68
|
-
fields: [
|
|
69
|
-
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
70
|
-
{ name: "characterId", type: "uint64string", defaultValue: 0 },
|
|
71
|
-
],
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
[
|
|
75
|
-
"CharacterDeleteReply",
|
|
76
|
-
0x08,
|
|
77
|
-
{
|
|
78
|
-
fields: [
|
|
79
|
-
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
80
|
-
{ name: "status", type: "boolean", defaultValue: 0 },
|
|
81
|
-
],
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
[
|
|
85
|
-
"UpdateZonePopulation",
|
|
86
|
-
0x09,
|
|
87
|
-
{
|
|
88
|
-
fields: [{ name: "population", type: "uint8", defaultValue: 0 }],
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
[
|
|
92
|
-
"ZonePingRequest",
|
|
93
|
-
0x10,
|
|
94
|
-
{
|
|
95
|
-
fields: [
|
|
96
|
-
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
97
|
-
{ name: "address", type: "string", defaultValue: 0 },
|
|
98
|
-
],
|
|
99
|
-
},
|
|
100
|
-
],
|
|
101
|
-
[
|
|
102
|
-
"ZonePingReply",
|
|
103
|
-
0x11,
|
|
104
|
-
{
|
|
105
|
-
fields: [
|
|
106
|
-
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
107
|
-
{ name: "status", type: "boolean", defaultValue: 0 },
|
|
108
|
-
],
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
[
|
|
112
|
-
"CharacterExistRequest",
|
|
113
|
-
0x12,
|
|
114
|
-
{
|
|
115
|
-
fields: [
|
|
116
|
-
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
117
|
-
{ name: "characterId", type: "uint64string", defaultValue: 0 },
|
|
118
|
-
],
|
|
119
|
-
},
|
|
120
|
-
],
|
|
121
|
-
[
|
|
122
|
-
"CharacterExistReply",
|
|
123
|
-
0x13,
|
|
124
|
-
{
|
|
125
|
-
fields: [
|
|
126
|
-
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
127
|
-
{ name: "status", type: "boolean", defaultValue: 0 },
|
|
128
|
-
],
|
|
129
|
-
},
|
|
130
|
-
],
|
|
131
|
-
[
|
|
132
|
-
"ClientIsAdminRequest",
|
|
133
|
-
0x14,
|
|
134
|
-
{
|
|
135
|
-
fields: [
|
|
136
|
-
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
137
|
-
{ name: "guid", type: "uint64string", defaultValue: 0 },
|
|
138
|
-
],
|
|
139
|
-
},
|
|
140
|
-
],
|
|
141
|
-
[
|
|
142
|
-
"ClientIsAdminReply",
|
|
143
|
-
0x15,
|
|
144
|
-
{
|
|
145
|
-
fields: [
|
|
146
|
-
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
147
|
-
{ name: "status", type: "boolean", defaultValue: 0 },
|
|
148
|
-
],
|
|
149
|
-
},
|
|
150
|
-
],
|
|
151
|
-
];
|
|
152
|
-
|
|
153
|
-
export const [H1emuPacketsPacketTypes, H1emuPacketsPackets] =
|
|
154
|
-
PacketTableBuild(packets);
|
|
155
|
-
|
|
156
|
-
const H1emuPackets = {
|
|
157
|
-
PacketTypes: H1emuPacketsPacketTypes,
|
|
158
|
-
Packets: H1emuPacketsPackets,
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
export class H1emuProtocol {
|
|
162
|
-
parse(data: Buffer): H1emuProtocolReadingFormat | null {
|
|
163
|
-
const packetType = data.readUInt8(0);
|
|
164
|
-
let result;
|
|
165
|
-
const packet = H1emuPackets.Packets[packetType];
|
|
166
|
-
if (packet) {
|
|
167
|
-
if (packet.schema) {
|
|
168
|
-
try {
|
|
169
|
-
result = DataSchema.parse(packet.schema, data, 1).result;
|
|
170
|
-
} catch (e) {
|
|
171
|
-
console.error(`${packet.name} : ${e}`);
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
return {
|
|
175
|
-
type: packet.type,
|
|
176
|
-
name: packet.name,
|
|
177
|
-
data: result,
|
|
178
|
-
};
|
|
179
|
-
} else {
|
|
180
|
-
debug("parse()", "No parser for packet " + packet.name);
|
|
181
|
-
return null;
|
|
182
|
-
}
|
|
183
|
-
} else {
|
|
184
|
-
debug("parse()", "Unknown or unhandled H1emu packet type: " + packetType);
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
pack(packetName: string, object: any): Buffer | null {
|
|
190
|
-
const packetType = H1emuPackets.PacketTypes[packetName],
|
|
191
|
-
packet = H1emuPackets.Packets[packetType];
|
|
192
|
-
let data;
|
|
193
|
-
if (packet) {
|
|
194
|
-
if (packet.schema) {
|
|
195
|
-
const packetData = DataSchema.pack(packet.schema, object);
|
|
196
|
-
if (packetData) {
|
|
197
|
-
data = Buffer.allocUnsafe(1 + packetData.length);
|
|
198
|
-
data.writeUInt8(packetType, 0);
|
|
199
|
-
packetData.data.copy(data, 1);
|
|
200
|
-
} else {
|
|
201
|
-
debug("Could not pack data schema for " + packet.name);
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
204
|
-
} else {
|
|
205
|
-
debug("pack()", "No pack function for packet " + packet.name);
|
|
206
|
-
return null;
|
|
207
|
-
}
|
|
208
|
-
} else {
|
|
209
|
-
debug("pack()", "Unknown or unhandled H1emu packet type: " + packetType);
|
|
210
|
-
return null;
|
|
211
|
-
}
|
|
212
|
-
return data;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
exports.H1emuPackets = H1emuPackets as any;
|
|
1
|
+
// ======================================================================
|
|
2
|
+
//
|
|
3
|
+
// GNU GENERAL PUBLIC LICENSE
|
|
4
|
+
// Version 3, 29 June 2007
|
|
5
|
+
// copyright (C) 2020 - 2021 Quentin Gruber
|
|
6
|
+
// copyright (C) 2021 - 2023 H1emu community
|
|
7
|
+
//
|
|
8
|
+
// https://github.com/QuentinGruber/h1z1-server
|
|
9
|
+
// https://www.npmjs.com/package/h1z1-server
|
|
10
|
+
//
|
|
11
|
+
// Based on https://github.com/psemu/soe-network
|
|
12
|
+
// ======================================================================
|
|
13
|
+
|
|
14
|
+
const debug = require("debug")("H1emuProtocol");
|
|
15
|
+
import DataSchema from "h1z1-dataschema";
|
|
16
|
+
import { H1emuProtocolReadingFormat } from "types/protocols";
|
|
17
|
+
import PacketTableBuild from "../packets/packettable";
|
|
18
|
+
const packets = [
|
|
19
|
+
[
|
|
20
|
+
"SessionRequest",
|
|
21
|
+
0x01,
|
|
22
|
+
{
|
|
23
|
+
fields: [
|
|
24
|
+
{ name: "serverId", type: "uint32", defaultValue: 0 },
|
|
25
|
+
{ name: "h1emuVersion", type: "string", defaultValue: "" },
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
[
|
|
30
|
+
"SessionReply",
|
|
31
|
+
0x02,
|
|
32
|
+
{
|
|
33
|
+
fields: [{ name: "status", type: "uint8", defaultValue: 0 }],
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
[
|
|
37
|
+
"Ping",
|
|
38
|
+
0x03,
|
|
39
|
+
{
|
|
40
|
+
fields: [],
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
["Ack", 0x04, {}],
|
|
44
|
+
[
|
|
45
|
+
"CharacterCreateRequest",
|
|
46
|
+
0x05,
|
|
47
|
+
{
|
|
48
|
+
fields: [
|
|
49
|
+
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
50
|
+
{ name: "characterObjStringify", type: "string", defaultValue: "" },
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
[
|
|
55
|
+
"CharacterCreateReply",
|
|
56
|
+
0x06,
|
|
57
|
+
{
|
|
58
|
+
fields: [
|
|
59
|
+
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
60
|
+
{ name: "status", type: "boolean", defaultValue: 0 },
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
"CharacterDeleteRequest",
|
|
66
|
+
0x07,
|
|
67
|
+
{
|
|
68
|
+
fields: [
|
|
69
|
+
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
70
|
+
{ name: "characterId", type: "uint64string", defaultValue: 0 },
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
"CharacterDeleteReply",
|
|
76
|
+
0x08,
|
|
77
|
+
{
|
|
78
|
+
fields: [
|
|
79
|
+
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
80
|
+
{ name: "status", type: "boolean", defaultValue: 0 },
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
[
|
|
85
|
+
"UpdateZonePopulation",
|
|
86
|
+
0x09,
|
|
87
|
+
{
|
|
88
|
+
fields: [{ name: "population", type: "uint8", defaultValue: 0 }],
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
[
|
|
92
|
+
"ZonePingRequest",
|
|
93
|
+
0x10,
|
|
94
|
+
{
|
|
95
|
+
fields: [
|
|
96
|
+
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
97
|
+
{ name: "address", type: "string", defaultValue: 0 },
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
[
|
|
102
|
+
"ZonePingReply",
|
|
103
|
+
0x11,
|
|
104
|
+
{
|
|
105
|
+
fields: [
|
|
106
|
+
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
107
|
+
{ name: "status", type: "boolean", defaultValue: 0 },
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
"CharacterExistRequest",
|
|
113
|
+
0x12,
|
|
114
|
+
{
|
|
115
|
+
fields: [
|
|
116
|
+
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
117
|
+
{ name: "characterId", type: "uint64string", defaultValue: 0 },
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
[
|
|
122
|
+
"CharacterExistReply",
|
|
123
|
+
0x13,
|
|
124
|
+
{
|
|
125
|
+
fields: [
|
|
126
|
+
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
127
|
+
{ name: "status", type: "boolean", defaultValue: 0 },
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
[
|
|
132
|
+
"ClientIsAdminRequest",
|
|
133
|
+
0x14,
|
|
134
|
+
{
|
|
135
|
+
fields: [
|
|
136
|
+
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
137
|
+
{ name: "guid", type: "uint64string", defaultValue: 0 },
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
[
|
|
142
|
+
"ClientIsAdminReply",
|
|
143
|
+
0x15,
|
|
144
|
+
{
|
|
145
|
+
fields: [
|
|
146
|
+
{ name: "reqId", type: "uint32", defaultValue: 0 },
|
|
147
|
+
{ name: "status", type: "boolean", defaultValue: 0 },
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
];
|
|
152
|
+
|
|
153
|
+
export const [H1emuPacketsPacketTypes, H1emuPacketsPackets] =
|
|
154
|
+
PacketTableBuild(packets);
|
|
155
|
+
|
|
156
|
+
const H1emuPackets = {
|
|
157
|
+
PacketTypes: H1emuPacketsPacketTypes,
|
|
158
|
+
Packets: H1emuPacketsPackets,
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export class H1emuProtocol {
|
|
162
|
+
parse(data: Buffer): H1emuProtocolReadingFormat | null {
|
|
163
|
+
const packetType = data.readUInt8(0);
|
|
164
|
+
let result;
|
|
165
|
+
const packet = H1emuPackets.Packets[packetType];
|
|
166
|
+
if (packet) {
|
|
167
|
+
if (packet.schema) {
|
|
168
|
+
try {
|
|
169
|
+
result = DataSchema.parse(packet.schema, data, 1).result;
|
|
170
|
+
} catch (e) {
|
|
171
|
+
console.error(`${packet.name} : ${e}`);
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
type: packet.type,
|
|
176
|
+
name: packet.name,
|
|
177
|
+
data: result,
|
|
178
|
+
};
|
|
179
|
+
} else {
|
|
180
|
+
debug("parse()", "No parser for packet " + packet.name);
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
debug("parse()", "Unknown or unhandled H1emu packet type: " + packetType);
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
pack(packetName: string, object: any): Buffer | null {
|
|
190
|
+
const packetType = H1emuPackets.PacketTypes[packetName],
|
|
191
|
+
packet = H1emuPackets.Packets[packetType];
|
|
192
|
+
let data;
|
|
193
|
+
if (packet) {
|
|
194
|
+
if (packet.schema) {
|
|
195
|
+
const packetData = DataSchema.pack(packet.schema, object);
|
|
196
|
+
if (packetData) {
|
|
197
|
+
data = Buffer.allocUnsafe(1 + packetData.length);
|
|
198
|
+
data.writeUInt8(packetType, 0);
|
|
199
|
+
packetData.data.copy(data, 1);
|
|
200
|
+
} else {
|
|
201
|
+
debug("Could not pack data schema for " + packet.name);
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
} else {
|
|
205
|
+
debug("pack()", "No pack function for packet " + packet.name);
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
} else {
|
|
209
|
+
debug("pack()", "Unknown or unhandled H1emu packet type: " + packetType);
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
return data;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
exports.H1emuPackets = H1emuPackets as any;
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
// ======================================================================
|
|
2
|
-
//
|
|
3
|
-
// GNU GENERAL PUBLIC LICENSE
|
|
4
|
-
// Version 3, 29 June 2007
|
|
5
|
-
// copyright (C) 2020 - 2021 Quentin Gruber
|
|
6
|
-
// copyright (C) 2021 - 2023 H1emu community
|
|
7
|
-
//
|
|
8
|
-
// https://github.com/QuentinGruber/h1z1-server
|
|
9
|
-
// https://www.npmjs.com/package/h1z1-server
|
|
10
|
-
//
|
|
11
|
-
// Based on https://github.com/psemu/soe-network
|
|
12
|
-
// ======================================================================
|
|
13
|
-
|
|
14
|
-
import { H1emuClient } from "./shared/h1emuclient";
|
|
15
|
-
import { H1emuServer } from "./shared/h1emuserver";
|
|
16
|
-
|
|
17
|
-
export class H1emuLoginServer extends H1emuServer {
|
|
18
|
-
constructor(serverPort?: number) {
|
|
19
|
-
super(serverPort);
|
|
20
|
-
this.messageHandler = function (
|
|
21
|
-
messageType: string,
|
|
22
|
-
data: Buffer,
|
|
23
|
-
client: H1emuClient
|
|
24
|
-
): void {
|
|
25
|
-
const packet = this._protocol.parse(data);
|
|
26
|
-
if (!packet) return;
|
|
27
|
-
switch (packet.name) {
|
|
28
|
-
case "Ping":
|
|
29
|
-
this.ping(client);
|
|
30
|
-
break;
|
|
31
|
-
case "CharacterCreateReply":
|
|
32
|
-
case "CharacterExistReply":
|
|
33
|
-
case "CharacterDeleteReply":
|
|
34
|
-
case "ClientIsAdminReply": {
|
|
35
|
-
this.emit("processInternalReq", packet, ["status"]);
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
default:
|
|
39
|
-
this.emit("data", null, client, packet);
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
this.ping = (client: H1emuClient) => {
|
|
44
|
-
this.updateClientLastPing(client.clientId);
|
|
45
|
-
super.ping(client);
|
|
46
|
-
};
|
|
47
|
-
this._pingTimer = setTimeout(() => {
|
|
48
|
-
for (const key in this._clients) {
|
|
49
|
-
const client = this._clients[key];
|
|
50
|
-
if (Date.now() > client.lastPing + this._pingTimeout) {
|
|
51
|
-
this.emit("disconnect", null, client, 1);
|
|
52
|
-
delete this._clients[client.clientId];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
this._pingTimer.refresh();
|
|
56
|
-
}, this._pingTime);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
1
|
+
// ======================================================================
|
|
2
|
+
//
|
|
3
|
+
// GNU GENERAL PUBLIC LICENSE
|
|
4
|
+
// Version 3, 29 June 2007
|
|
5
|
+
// copyright (C) 2020 - 2021 Quentin Gruber
|
|
6
|
+
// copyright (C) 2021 - 2023 H1emu community
|
|
7
|
+
//
|
|
8
|
+
// https://github.com/QuentinGruber/h1z1-server
|
|
9
|
+
// https://www.npmjs.com/package/h1z1-server
|
|
10
|
+
//
|
|
11
|
+
// Based on https://github.com/psemu/soe-network
|
|
12
|
+
// ======================================================================
|
|
13
|
+
|
|
14
|
+
import { H1emuClient } from "./shared/h1emuclient";
|
|
15
|
+
import { H1emuServer } from "./shared/h1emuserver";
|
|
16
|
+
|
|
17
|
+
export class H1emuLoginServer extends H1emuServer {
|
|
18
|
+
constructor(serverPort?: number) {
|
|
19
|
+
super(serverPort);
|
|
20
|
+
this.messageHandler = function (
|
|
21
|
+
messageType: string,
|
|
22
|
+
data: Buffer,
|
|
23
|
+
client: H1emuClient
|
|
24
|
+
): void {
|
|
25
|
+
const packet = this._protocol.parse(data);
|
|
26
|
+
if (!packet) return;
|
|
27
|
+
switch (packet.name) {
|
|
28
|
+
case "Ping":
|
|
29
|
+
this.ping(client);
|
|
30
|
+
break;
|
|
31
|
+
case "CharacterCreateReply":
|
|
32
|
+
case "CharacterExistReply":
|
|
33
|
+
case "CharacterDeleteReply":
|
|
34
|
+
case "ClientIsAdminReply": {
|
|
35
|
+
this.emit("processInternalReq", packet, ["status"]);
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
default:
|
|
39
|
+
this.emit("data", null, client, packet);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
this.ping = (client: H1emuClient) => {
|
|
44
|
+
this.updateClientLastPing(client.clientId);
|
|
45
|
+
super.ping(client);
|
|
46
|
+
};
|
|
47
|
+
this._pingTimer = setTimeout(() => {
|
|
48
|
+
for (const key in this._clients) {
|
|
49
|
+
const client = this._clients[key];
|
|
50
|
+
if (Date.now() > client.lastPing + this._pingTimeout) {
|
|
51
|
+
this.emit("disconnect", null, client, 1);
|
|
52
|
+
delete this._clients[client.clientId];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
this._pingTimer.refresh();
|
|
56
|
+
}, this._pingTime);
|
|
57
|
+
}
|
|
58
|
+
}
|