@sanctumterra/raknet 1.3.80 → 1.4.0

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.
Files changed (275) hide show
  1. package/README.md +1 -1
  2. package/dist/client/client.d.ts +19 -20
  3. package/dist/client/client.d.ts.map +1 -1
  4. package/dist/client/client.js +139 -184
  5. package/dist/client/types/client-events.d.ts +5 -20
  6. package/dist/client/types/client-events.d.ts.map +1 -1
  7. package/dist/client/types/client-options.d.ts +7 -8
  8. package/dist/client/types/client-options.d.ts.map +1 -1
  9. package/dist/client/types/client-options.js +9 -9
  10. package/dist/client/types/index.d.ts +1 -1
  11. package/dist/client/types/index.d.ts.map +1 -1
  12. package/dist/client/types/index.js +1 -1
  13. package/dist/index.d.ts +1 -3
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +1 -3
  16. package/dist/server/connection.d.ts +20 -59
  17. package/dist/server/connection.d.ts.map +1 -1
  18. package/dist/server/connection.js +53 -365
  19. package/dist/server/index.d.ts +2 -3
  20. package/dist/server/index.d.ts.map +1 -1
  21. package/dist/server/index.js +2 -3
  22. package/dist/server/server.d.ts +11 -18
  23. package/dist/server/server.d.ts.map +1 -1
  24. package/dist/server/server.js +98 -137
  25. package/dist/{proto → server}/types/advertisement.d.ts +1 -1
  26. package/dist/server/types/advertisement.d.ts.map +1 -0
  27. package/dist/{proto → server}/types/advertisement.js +14 -10
  28. package/dist/server/types/connection-events.d.ts +4 -0
  29. package/dist/server/types/connection-events.d.ts.map +1 -0
  30. package/dist/server/types/index.d.ts +5 -0
  31. package/dist/server/types/index.d.ts.map +1 -0
  32. package/dist/{proto → server}/types/index.js +3 -1
  33. package/dist/server/types/server-events.d.ts +7 -0
  34. package/dist/server/types/server-events.d.ts.map +1 -0
  35. package/dist/server/types/server-options.d.ts +12 -0
  36. package/dist/server/types/server-options.d.ts.map +1 -0
  37. package/dist/server/types/server-options.js +14 -0
  38. package/dist/shared/emitter.d.ts +28 -0
  39. package/dist/shared/emitter.d.ts.map +1 -0
  40. package/dist/shared/emitter.js +71 -0
  41. package/dist/shared/index.d.ts +5 -0
  42. package/dist/shared/index.d.ts.map +1 -0
  43. package/dist/{proto/decorators → shared}/index.js +4 -2
  44. package/dist/{utils/Logger.d.ts → shared/logger.d.ts} +1 -1
  45. package/dist/shared/logger.d.ts.map +1 -0
  46. package/dist/shared/network_session.d.ts +34 -0
  47. package/dist/shared/network_session.d.ts.map +1 -0
  48. package/dist/shared/network_session.js +247 -0
  49. package/dist/shared/proto/enums/connectionStatus.d.ts +8 -0
  50. package/dist/shared/proto/enums/connectionStatus.d.ts.map +1 -0
  51. package/dist/shared/proto/enums/connectionStatus.js +11 -0
  52. package/dist/shared/proto/enums/index.d.ts +5 -0
  53. package/dist/shared/proto/enums/index.d.ts.map +1 -0
  54. package/dist/{proto → shared/proto}/enums/index.js +2 -3
  55. package/dist/shared/proto/enums/packets.d.ts +19 -0
  56. package/dist/shared/proto/enums/packets.d.ts.map +1 -0
  57. package/dist/shared/proto/enums/packets.js +23 -0
  58. package/dist/shared/proto/enums/priority.d.ts +6 -0
  59. package/dist/shared/proto/enums/priority.d.ts.map +1 -0
  60. package/dist/shared/proto/enums/priority.js +4 -0
  61. package/dist/shared/proto/enums/reliability.d.ts.map +1 -0
  62. package/dist/shared/proto/index.d.ts +5 -0
  63. package/dist/shared/proto/index.d.ts.map +1 -0
  64. package/dist/{proto → shared/proto}/index.js +3 -3
  65. package/dist/shared/proto/offline/index.d.ts +7 -0
  66. package/dist/shared/proto/offline/index.d.ts.map +1 -0
  67. package/dist/shared/proto/offline/index.js +22 -0
  68. package/dist/shared/proto/offline/open-connection-reply-one.d.ts +9 -0
  69. package/dist/shared/proto/offline/open-connection-reply-one.d.ts.map +1 -0
  70. package/dist/shared/proto/offline/open-connection-reply-one.js +28 -0
  71. package/dist/shared/proto/offline/open-connection-reply-two.d.ts +11 -0
  72. package/dist/shared/proto/offline/open-connection-reply-two.d.ts.map +1 -0
  73. package/dist/shared/proto/offline/open-connection-reply-two.js +31 -0
  74. package/dist/shared/proto/offline/open-connection-request-one.d.ts +8 -0
  75. package/dist/shared/proto/offline/open-connection-request-one.d.ts.map +1 -0
  76. package/dist/shared/proto/offline/open-connection-request-one.js +25 -0
  77. package/dist/shared/proto/offline/open-connection-request-two.d.ts +10 -0
  78. package/dist/shared/proto/offline/open-connection-request-two.d.ts.map +1 -0
  79. package/dist/shared/proto/offline/open-connection-request-two.js +28 -0
  80. package/dist/shared/proto/offline/unconnected-ping.d.ts +8 -0
  81. package/dist/shared/proto/offline/unconnected-ping.d.ts.map +1 -0
  82. package/dist/shared/proto/offline/unconnected-ping.js +25 -0
  83. package/dist/shared/proto/offline/unconnected-pong.d.ts +9 -0
  84. package/dist/shared/proto/offline/unconnected-pong.d.ts.map +1 -0
  85. package/dist/shared/proto/offline/unconnected-pong.js +28 -0
  86. package/dist/shared/proto/online/ack.d.ts +7 -0
  87. package/dist/shared/proto/online/ack.d.ts.map +1 -0
  88. package/dist/{proto/packets → shared/proto/online}/ack.js +16 -31
  89. package/dist/shared/proto/online/connected-ping.d.ts +7 -0
  90. package/dist/shared/proto/online/connected-ping.d.ts.map +1 -0
  91. package/dist/shared/proto/online/connected-ping.js +19 -0
  92. package/dist/shared/proto/online/connected-pong.d.ts +8 -0
  93. package/dist/shared/proto/online/connected-pong.d.ts.map +1 -0
  94. package/dist/shared/proto/online/connected-pong.js +22 -0
  95. package/dist/shared/proto/online/connection-request-accepted.d.ts +12 -0
  96. package/dist/shared/proto/online/connection-request-accepted.d.ts.map +1 -0
  97. package/dist/shared/proto/online/connection-request-accepted.js +37 -0
  98. package/dist/shared/proto/online/connection-request.d.ts +9 -0
  99. package/dist/shared/proto/online/connection-request.d.ts.map +1 -0
  100. package/dist/shared/proto/online/connection-request.js +25 -0
  101. package/dist/shared/proto/online/disconnect-message.d.ts +6 -0
  102. package/dist/shared/proto/online/disconnect-message.d.ts.map +1 -0
  103. package/dist/shared/proto/online/disconnect-message.js +15 -0
  104. package/dist/shared/proto/online/frame-set.d.ts +9 -0
  105. package/dist/shared/proto/online/frame-set.d.ts.map +1 -0
  106. package/dist/shared/proto/online/frame-set.js +23 -0
  107. package/dist/shared/proto/online/index.d.ts +9 -0
  108. package/dist/shared/proto/online/index.d.ts.map +1 -0
  109. package/dist/shared/proto/online/index.js +24 -0
  110. package/dist/shared/proto/online/new-incomming-connection.d.ts +11 -0
  111. package/dist/shared/proto/online/new-incomming-connection.d.ts.map +1 -0
  112. package/dist/shared/proto/online/new-incomming-connection.js +33 -0
  113. package/dist/shared/proto/types/address.d.ts +12 -0
  114. package/dist/shared/proto/types/address.d.ts.map +1 -0
  115. package/dist/shared/proto/types/address.js +61 -0
  116. package/dist/shared/proto/types/frame.d.ts +23 -0
  117. package/dist/shared/proto/types/frame.d.ts.map +1 -0
  118. package/dist/shared/proto/types/frame.js +119 -0
  119. package/dist/{proto/packets → shared/proto}/types/index.d.ts +0 -2
  120. package/dist/shared/proto/types/index.d.ts.map +1 -0
  121. package/dist/{proto/packets → shared/proto}/types/index.js +0 -2
  122. package/dist/shared/proto/types/magic.d.ts +7 -0
  123. package/dist/shared/proto/types/magic.d.ts.map +1 -0
  124. package/dist/shared/proto/types/magic.js +15 -0
  125. package/dist/shared/proto/types/mtu.d.ts +7 -0
  126. package/dist/shared/proto/types/mtu.d.ts.map +1 -0
  127. package/dist/shared/proto/types/mtu.js +13 -0
  128. package/dist/tests/client-connect.d.ts +2 -0
  129. package/dist/tests/client-connect.d.ts.map +1 -0
  130. package/dist/tests/client-connect.js +32 -0
  131. package/dist/tests/client-once.d.ts +2 -0
  132. package/dist/tests/client-once.d.ts.map +1 -0
  133. package/dist/tests/client-once.js +11 -0
  134. package/dist/tests/server-listen.d.ts +2 -0
  135. package/dist/tests/server-listen.d.ts.map +1 -0
  136. package/dist/tests/server-listen.js +5 -0
  137. package/package.json +6 -6
  138. package/bun.lock +0 -67
  139. package/dist/client/framer.d.ts +0 -55
  140. package/dist/client/framer.d.ts.map +0 -1
  141. package/dist/client/framer.js +0 -458
  142. package/dist/proto/decorators/create.d.ts +0 -8
  143. package/dist/proto/decorators/create.d.ts.map +0 -1
  144. package/dist/proto/decorators/create.js +0 -77
  145. package/dist/proto/decorators/index.d.ts +0 -3
  146. package/dist/proto/decorators/index.d.ts.map +0 -1
  147. package/dist/proto/decorators/serialize.d.ts +0 -4
  148. package/dist/proto/decorators/serialize.d.ts.map +0 -1
  149. package/dist/proto/decorators/serialize.js +0 -12
  150. package/dist/proto/enums/flags.d.ts +0 -7
  151. package/dist/proto/enums/flags.d.ts.map +0 -1
  152. package/dist/proto/enums/flags.js +0 -10
  153. package/dist/proto/enums/index.d.ts +0 -6
  154. package/dist/proto/enums/index.d.ts.map +0 -1
  155. package/dist/proto/enums/packet.d.ts +0 -122
  156. package/dist/proto/enums/packet.d.ts.map +0 -1
  157. package/dist/proto/enums/packet.js +0 -125
  158. package/dist/proto/enums/priority.d.ts +0 -5
  159. package/dist/proto/enums/priority.d.ts.map +0 -1
  160. package/dist/proto/enums/priority.js +0 -8
  161. package/dist/proto/enums/reliability.d.ts.map +0 -1
  162. package/dist/proto/enums/status.d.ts +0 -7
  163. package/dist/proto/enums/status.d.ts.map +0 -1
  164. package/dist/proto/enums/status.js +0 -10
  165. package/dist/proto/index.d.ts +0 -5
  166. package/dist/proto/index.d.ts.map +0 -1
  167. package/dist/proto/packets/ack.d.ts +0 -10
  168. package/dist/proto/packets/ack.d.ts.map +0 -1
  169. package/dist/proto/packets/base-packet.d.ts +0 -26
  170. package/dist/proto/packets/base-packet.d.ts.map +0 -1
  171. package/dist/proto/packets/base-packet.js +0 -37
  172. package/dist/proto/packets/connected-ping.d.ts +0 -5
  173. package/dist/proto/packets/connected-ping.d.ts.map +0 -1
  174. package/dist/proto/packets/connected-ping.js +0 -27
  175. package/dist/proto/packets/connected-pong.d.ts +0 -6
  176. package/dist/proto/packets/connected-pong.d.ts.map +0 -1
  177. package/dist/proto/packets/connected-pong.js +0 -32
  178. package/dist/proto/packets/connection-request-accepted.d.ts +0 -10
  179. package/dist/proto/packets/connection-request-accepted.d.ts.map +0 -1
  180. package/dist/proto/packets/connection-request-accepted.js +0 -48
  181. package/dist/proto/packets/connection-request.d.ts +0 -7
  182. package/dist/proto/packets/connection-request.d.ts.map +0 -1
  183. package/dist/proto/packets/connection-request.js +0 -37
  184. package/dist/proto/packets/disconnect.d.ts +0 -5
  185. package/dist/proto/packets/disconnect.d.ts.map +0 -1
  186. package/dist/proto/packets/disconnect.js +0 -17
  187. package/dist/proto/packets/frame.d.ts +0 -1
  188. package/dist/proto/packets/frame.d.ts.map +0 -1
  189. package/dist/proto/packets/frame.js +0 -1
  190. package/dist/proto/packets/frameset.d.ts +0 -11
  191. package/dist/proto/packets/frameset.d.ts.map +0 -1
  192. package/dist/proto/packets/frameset.js +0 -37
  193. package/dist/proto/packets/incompatible-protocol-version.d.ts +0 -8
  194. package/dist/proto/packets/incompatible-protocol-version.d.ts.map +0 -1
  195. package/dist/proto/packets/incompatible-protocol-version.js +0 -38
  196. package/dist/proto/packets/index.d.ts +0 -19
  197. package/dist/proto/packets/index.d.ts.map +0 -1
  198. package/dist/proto/packets/index.js +0 -34
  199. package/dist/proto/packets/nack.d.ts +0 -8
  200. package/dist/proto/packets/nack.d.ts.map +0 -1
  201. package/dist/proto/packets/nack.js +0 -88
  202. package/dist/proto/packets/new-incoming-connection.d.ts +0 -9
  203. package/dist/proto/packets/new-incoming-connection.d.ts.map +0 -1
  204. package/dist/proto/packets/new-incoming-connection.js +0 -43
  205. package/dist/proto/packets/open-connection-reply-one.d.ts +0 -8
  206. package/dist/proto/packets/open-connection-reply-one.d.ts.map +0 -1
  207. package/dist/proto/packets/open-connection-reply-one.js +0 -43
  208. package/dist/proto/packets/open-connection-reply-two.d.ts +0 -10
  209. package/dist/proto/packets/open-connection-reply-two.d.ts.map +0 -1
  210. package/dist/proto/packets/open-connection-reply-two.js +0 -48
  211. package/dist/proto/packets/open-connection-request-one.d.ts +0 -7
  212. package/dist/proto/packets/open-connection-request-one.d.ts.map +0 -1
  213. package/dist/proto/packets/open-connection-request-one.js +0 -38
  214. package/dist/proto/packets/open-connection-request-two.d.ts +0 -9
  215. package/dist/proto/packets/open-connection-request-two.d.ts.map +0 -1
  216. package/dist/proto/packets/open-connection-request-two.js +0 -43
  217. package/dist/proto/packets/types/address.d.ts +0 -48
  218. package/dist/proto/packets/types/address.d.ts.map +0 -1
  219. package/dist/proto/packets/types/address.js +0 -99
  220. package/dist/proto/packets/types/data-type.d.ts +0 -21
  221. package/dist/proto/packets/types/data-type.d.ts.map +0 -1
  222. package/dist/proto/packets/types/data-type.js +0 -29
  223. package/dist/proto/packets/types/frame.d.ts +0 -23
  224. package/dist/proto/packets/types/frame.d.ts.map +0 -1
  225. package/dist/proto/packets/types/frame.js +0 -94
  226. package/dist/proto/packets/types/index.d.ts.map +0 -1
  227. package/dist/proto/packets/types/magic.d.ts +0 -7
  228. package/dist/proto/packets/types/magic.d.ts.map +0 -1
  229. package/dist/proto/packets/types/magic.js +0 -14
  230. package/dist/proto/packets/types/mtu.d.ts +0 -9
  231. package/dist/proto/packets/types/mtu.d.ts.map +0 -1
  232. package/dist/proto/packets/types/mtu.js +0 -18
  233. package/dist/proto/packets/types/sys-address.d.ts +0 -11
  234. package/dist/proto/packets/types/sys-address.d.ts.map +0 -1
  235. package/dist/proto/packets/types/sys-address.js +0 -32
  236. package/dist/proto/packets/unconnected-ping.d.ts +0 -7
  237. package/dist/proto/packets/unconnected-ping.d.ts.map +0 -1
  238. package/dist/proto/packets/unconnected-ping.js +0 -38
  239. package/dist/proto/packets/unconnected-pong.d.ts +0 -8
  240. package/dist/proto/packets/unconnected-pong.d.ts.map +0 -1
  241. package/dist/proto/packets/unconnected-pong.js +0 -43
  242. package/dist/proto/types/advertisement.d.ts.map +0 -1
  243. package/dist/proto/types/index.d.ts +0 -3
  244. package/dist/proto/types/index.d.ts.map +0 -1
  245. package/dist/proto/types/valid.d.ts +0 -4
  246. package/dist/proto/types/valid.d.ts.map +0 -1
  247. package/dist/server/server-events.d.ts +0 -9
  248. package/dist/server/server-events.d.ts.map +0 -1
  249. package/dist/server/server-options.d.ts +0 -26
  250. package/dist/server/server-options.d.ts.map +0 -1
  251. package/dist/server/server-options.js +0 -20
  252. package/dist/tests/client.d.ts +0 -2
  253. package/dist/tests/client.d.ts.map +0 -1
  254. package/dist/tests/client.js +0 -15
  255. package/dist/tests/localhost.d.ts +0 -2
  256. package/dist/tests/localhost.d.ts.map +0 -1
  257. package/dist/tests/localhost.js +0 -34
  258. package/dist/tests/server.d.ts +0 -2
  259. package/dist/tests/server.d.ts.map +0 -1
  260. package/dist/tests/server.js +0 -32
  261. package/dist/tests/test.d.ts +0 -2
  262. package/dist/tests/test.d.ts.map +0 -1
  263. package/dist/tests/test.js +0 -49
  264. package/dist/utils/Logger.d.ts.map +0 -1
  265. package/dist/utils/decorators.d.ts +0 -2
  266. package/dist/utils/decorators.d.ts.map +0 -1
  267. package/dist/utils/decorators.js +0 -17
  268. package/dist/utils/index.d.ts +0 -3
  269. package/dist/utils/index.d.ts.map +0 -1
  270. package/dist/utils/index.js +0 -18
  271. /package/dist/{proto/types/valid.js → server/types/connection-events.js} +0 -0
  272. /package/dist/server/{server-events.js → types/server-events.js} +0 -0
  273. /package/dist/{utils/Logger.js → shared/logger.js} +0 -0
  274. /package/dist/{proto → shared/proto}/enums/reliability.d.ts +0 -0
  275. /package/dist/{proto → shared/proto}/enums/reliability.js +0 -0
package/README.md CHANGED
@@ -41,6 +41,6 @@ server.start();
41
41
  debug: false,
42
42
  });
43
43
  client.connect().then((ad) => {
44
- console.log(ad);
44
+ if(ad) console.log(ad);
45
45
  });
46
46
  ```
@@ -1,24 +1,23 @@
1
- import { Emitter } from "@serenityjs/emitter";
2
- import { type Socket } from "node:dgram";
3
- import { type Address, type Advertisement, Frame, type Priority, Status } from "../proto";
4
- import { Framer } from "./framer";
5
- import { type ClientEvents, type ClientOptions } from "./types";
6
- export declare class Client extends Emitter<ClientEvents> {
7
- socket: Socket | null;
8
- framer: Framer | null;
1
+ import { EventEmitter, Priority, type Frame } from "../shared";
2
+ import type { ClientEvents } from "./types";
3
+ import { type ClientOptions } from "./types/client-options";
4
+ import { type RemoteInfo } from "node:dgram";
5
+ export declare class Client extends EventEmitter<ClientEvents> {
9
6
  options: ClientOptions;
10
- private tickTimer?;
11
- private connectionTimeout?;
12
- private requestInterval?;
13
- serverAddress: Address | null;
14
- status: Status;
7
+ private socket;
8
+ private interval;
9
+ private status;
10
+ tick: number;
11
+ private session;
15
12
  constructor(options?: Partial<ClientOptions>);
16
- initSocket(): void;
17
- ping(): Promise<Advertisement>;
18
- connect(): Promise<Advertisement | null>;
19
- sendFrame(frame: Frame, priority: Priority): void;
20
- frameAndSend(payload: Buffer, priority: Priority): void;
21
- send(buffer: Buffer): void;
22
- disconnect(): Promise<void>;
13
+ connect(): Promise<void>;
14
+ onTick(): void;
15
+ onMessage(data: Buffer, rinfo: RemoteInfo): void;
16
+ handleOnline(data: Buffer): void;
17
+ sendFrame(frame: Frame, priority?: Priority): void;
18
+ frameAndSend(data: Buffer, priority?: Priority): void;
19
+ ping(): void;
20
+ send(data: Buffer): void;
21
+ disconnect(): void;
23
22
  }
24
23
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,EAIL,KAAK,QAAQ,EACb,MAAM,EAGN,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,aAAa,EAElB,MAAM,SAAS,CAAC;AAKjB,qBAAa,MAAO,SAAQ,OAAO,CAAC,YAAY,CAAC;IACzC,MAAM,EAAG,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAG,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,EAAE,aAAa,CAAC;IAC9B,OAAO,CAAC,SAAS,CAAC,CAAiB;IACnC,OAAO,CAAC,iBAAiB,CAAC,CAAiB;IAC3C,OAAO,CAAC,eAAe,CAAC,CAAiB;IAClC,aAAa,EAAG,OAAO,GAAG,IAAI,CAAC;IAE/B,MAAM,SAAuB;gBAExB,OAAO,GAAE,OAAO,CAAC,aAAa,CAAwB;IAM3D,UAAU;IAuBJ,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC;IAkB9B,OAAO,IAAI,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAmG9C,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAYjD,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAOvD,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAiC1B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAiClC"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,YAAY,EAWZ,QAAQ,EAIR,KAAK,KAAK,EAIV,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EACN,KAAK,aAAa,EAElB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAgB,KAAK,UAAU,EAAe,MAAM,YAAY,CAAC;AAGxE,qBAAa,MAAO,SAAQ,YAAY,CAAC,YAAY,CAAC;IAC9C,OAAO,EAAE,aAAa,CAAC;IAC9B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAwB;IACxC,OAAO,CAAC,MAAM,CAAmB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,OAAO,CAAiB;gBAEpB,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM;IAmBzC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAkBxB,MAAM,IAAI,IAAI;IAYd,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI;IAqDhD,YAAY,CAAC,IAAI,EAAE,MAAM;IAwCzB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,GAAE,QAA0B;IAI5D,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,QAA0B;IAI/D,IAAI,IAAI,IAAI;IAQZ,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIxB,UAAU,IAAI,IAAI;CAIzB"}
@@ -1,210 +1,165 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Client = void 0;
7
- const emitter_1 = require("@serenityjs/emitter");
4
+ const shared_1 = require("../shared");
5
+ const client_options_1 = require("./types/client-options");
8
6
  const node_dgram_1 = require("node:dgram");
9
- const proto_1 = require("../proto");
10
- const disconnect_1 = __importDefault(require("../proto/packets/disconnect"));
11
- const utils_1 = require("../utils");
12
- const framer_1 = require("./framer");
13
- const types_1 = require("./types");
14
- const TICK_INTERVAL = 50;
15
- const REQUEST_INTERVAL = 500;
16
- class Client extends emitter_1.Emitter {
17
- socket;
18
- framer;
7
+ const shared_2 = require("../shared");
8
+ class Client extends shared_1.EventEmitter {
19
9
  options;
20
- tickTimer;
21
- connectionTimeout;
22
- requestInterval;
23
- serverAddress;
24
- status = proto_1.Status.Disconnected;
25
- constructor(options = types_1.defaultClientOptions) {
10
+ socket;
11
+ interval;
12
+ status;
13
+ tick;
14
+ session;
15
+ constructor(options = {}) {
26
16
  super();
27
- this.options = { ...types_1.defaultClientOptions, ...options };
28
- this.maxListeners = 60;
29
- }
30
- initSocket() {
31
- try {
32
- this.socket = (0, node_dgram_1.createSocket)("udp4");
33
- this.framer = new framer_1.Framer(this);
34
- this.remove("tick", () => this.framer?.tick());
35
- this.on("tick", () => this.framer?.tick());
36
- this.socket.removeAllListeners();
37
- this.socket.on("message", (payload, rinfo) => {
38
- this.framer?.incomingMessage(payload, rinfo);
39
- });
40
- this.socket.on("error", (err) => {
41
- utils_1.Logger.error(`[Client] Socket error: ${err}`);
42
- });
43
- utils_1.Logger.disabled = this.options.loggerDisabled;
44
- }
45
- catch (error) {
46
- utils_1.Logger.error(`Failed to create socket: ${error}`);
47
- }
17
+ this.options = { ...client_options_1.defaultClientOptions, ...options };
18
+ this.status = shared_1.ConnectionStatus.Disconnected;
19
+ this.tick = 0;
20
+ this.socket = (0, node_dgram_1.createSocket)("udp4");
21
+ this.socket.bind();
22
+ this.interval = setInterval(this.onTick.bind(this), 1000 / this.options.tickRate);
23
+ this.socket.on("message", this.onMessage.bind(this));
24
+ this.session = new shared_1.NetworkSession(this.options.mtu);
25
+ this.session.send = this.send.bind(this);
26
+ this.session.handle = (data) => {
27
+ this.handleOnline(data);
28
+ };
48
29
  }
49
- async ping() {
30
+ connect() {
50
31
  return new Promise((resolve, reject) => {
32
+ this.status = shared_1.ConnectionStatus.Connecting;
33
+ const request = new shared_1.OpenConnectionRequestOne();
34
+ request.mtu = this.options.mtu;
35
+ request.protocol = 11; // Only 11 is supported
36
+ const serialized = request.serialize();
37
+ this.send(serialized);
51
38
  const timeout = setTimeout(() => {
52
- reject(new Error("Failed to ping, timed out."));
39
+ reject(new Error("Connection timed out"));
53
40
  }, this.options.timeout);
54
- this.once("unconnected-pong", (packet) => {
41
+ this.once("connect", () => {
55
42
  clearTimeout(timeout);
56
- resolve((0, proto_1.fromString)(packet.message));
43
+ resolve();
57
44
  });
58
- const unconnectedPing = new proto_1.UnconnectedPing();
59
- unconnectedPing.guid = this.options.clientId;
60
- unconnectedPing.clientTimestamp = BigInt(Date.now());
61
- this.send(unconnectedPing.serialize());
62
45
  });
63
46
  }
64
- async connect() {
65
- if (this.status === proto_1.Status.Connecting) {
66
- throw new Error("Connection attempt already in progress");
47
+ onTick() {
48
+ const isDisconnected = this.status === shared_1.ConnectionStatus.Disconnected;
49
+ const isDisconnecting = this.status === shared_1.ConnectionStatus.Disconnecting;
50
+ const canPing = isDisconnected && this.tick % this.options.pingRate === 0;
51
+ if (canPing)
52
+ this.ping();
53
+ if (!isDisconnecting || !isDisconnected) {
54
+ this.session.onTick(this.tick);
67
55
  }
68
- if (this.status === proto_1.Status.Connected) {
69
- throw new Error("Already connected");
70
- }
71
- this.status = proto_1.Status.Connecting;
72
- this.initSocket();
73
- this.tickTimer = setInterval(() => this.emit("tick"), TICK_INTERVAL);
74
- let advertisement = null;
75
- const pongHandler = (packet) => {
76
- advertisement = (0, proto_1.fromString)(packet.message);
77
- };
78
- this.once("unconnected-pong", pongHandler);
79
- const ping = new proto_1.UnconnectedPing();
80
- ping.guid = this.options.clientId;
81
- ping.clientTimestamp = BigInt(Date.now());
82
- this.send(ping.serialize());
83
- return new Promise((resolve, reject) => {
84
- let isResolved = false;
85
- let currentStage = 0; // 0: request-one, 1: request-two, 2: completed
86
- this.connectionTimeout = setTimeout(() => {
87
- if (!isResolved) {
88
- isResolved = true;
89
- this.disconnect();
90
- reject(new Error("Connection timed out"));
91
- }
92
- }, this.options.timeout);
93
- const requestOne = new proto_1.OpenConnectionRequestOne();
94
- requestOne.mtu = this.options.mtuSize;
95
- requestOne.protocol = this.options.protocolVersion;
96
- this.once("open-connection-reply-one", () => {
97
- currentStage = 1;
98
- utils_1.Logger.debug("[Client] Received OpenConnectionReplyOne, sending OpenConnectionRequestTwo");
99
- if (this.requestInterval)
100
- clearInterval(this.requestInterval);
101
- });
102
- this.once("open-connection-reply-two", (packet) => {
103
- const mtu = packet.mtu;
104
- if (mtu < 400 || mtu > 1500) {
105
- if (!isResolved) {
106
- isResolved = true;
107
- this.disconnect();
108
- reject(new Error(`Invalid MTU size: ${mtu}`));
109
- }
110
- return;
111
- }
112
- currentStage = 2;
113
- utils_1.Logger.debug(`[Client] Received OpenConnectionReplyTwo with MTU: ${mtu}`);
114
- });
115
- this.once("new-incoming-connection", () => {
116
- if (!isResolved) {
117
- isResolved = true;
118
- this.status = proto_1.Status.Connected;
119
- this.emit("connect");
120
- if (this.connectionTimeout)
121
- clearTimeout(this.connectionTimeout);
122
- if (this.requestInterval)
123
- clearInterval(this.requestInterval);
124
- resolve(advertisement);
125
- }
126
- });
127
- this.once("error", (error) => {
128
- if (!isResolved) {
129
- isResolved = true;
130
- this.disconnect();
131
- reject(error);
132
- }
133
- });
134
- this.emit("open-connection-request-one", requestOne);
135
- this.send(requestOne.serialize());
136
- this.requestInterval = setInterval(() => {
137
- if (!isResolved && currentStage === 0) {
138
- utils_1.Logger.debug("[Client] Resending OpenConnectionRequestOne");
139
- this.send(requestOne.serialize());
140
- }
141
- }, REQUEST_INTERVAL);
142
- });
56
+ this.tick++;
143
57
  }
144
- sendFrame(frame, priority) {
145
- try {
146
- if (!this.framer) {
147
- utils_1.Logger.error("[Client] Cannot send frame: framer is null");
148
- return;
58
+ onMessage(data, rinfo) {
59
+ let id = data[0];
60
+ const isOnline = (id & 0xf0) === 0x80;
61
+ if (isOnline)
62
+ id = 0x80;
63
+ switch (id) {
64
+ case shared_1.Packets.UnconnectedPong: {
65
+ const pong = new shared_1.UnconnectedPong(data).deserialize();
66
+ this.emit("unconnectedPong", pong);
67
+ break;
68
+ }
69
+ case shared_1.Packets.OpenConnectionReply1: {
70
+ const reply = new shared_1.OpenConnectionReplyOne(data).deserialize();
71
+ const request = new shared_1.OpenConnectionRequestTwo();
72
+ request.address = shared_1.Address.fromIdentifier(rinfo);
73
+ request.mtu = reply.mtu;
74
+ request.guid = this.options.guid;
75
+ this.send(request.serialize());
76
+ break;
77
+ }
78
+ case shared_1.Packets.OpenConnectionReply2: {
79
+ const reply = new shared_1.OpenConnectionReplyTwo(data).deserialize();
80
+ const request = new shared_1.ConnectionRequest();
81
+ request.guid = this.options.guid;
82
+ request.timestamp = BigInt(Date.now());
83
+ const serialized = request.serialize();
84
+ this.frameAndSend(serialized, shared_1.Priority.High);
85
+ break;
86
+ }
87
+ case shared_1.Packets.FrameSet: {
88
+ const frameSet = new shared_1.FrameSet(data).deserialize();
89
+ this.session.onFrameSet(frameSet);
90
+ break;
91
+ }
92
+ case shared_1.Packets.Ack: {
93
+ const ack = new shared_1.Ack(data).deserialize();
94
+ this.session.onAck(ack);
95
+ break;
96
+ }
97
+ case shared_1.Packets.Nack: {
98
+ const nack = new shared_1.Ack(data).deserialize();
99
+ this.session.onNack(nack);
100
+ break;
101
+ }
102
+ default: {
103
+ shared_2.Logger.warn(`Unknown packet type: ${id}`);
104
+ break;
149
105
  }
150
- this.framer.sendFrame(frame, priority);
151
106
  }
152
- catch (error) {
153
- utils_1.Logger.error("[Client] Failed to send frame", error);
107
+ }
108
+ handleOnline(data) {
109
+ const id = data[0];
110
+ switch (id) {
111
+ case 254: {
112
+ this.emit("encapsulated", data);
113
+ break;
114
+ }
115
+ case shared_1.Packets.ConnectedPong: {
116
+ break;
117
+ }
118
+ case shared_1.Packets.ConnectedPing: {
119
+ const ping = new shared_1.ConnectedPing(data).deserialize();
120
+ const pong = new shared_1.ConnectedPong();
121
+ pong.pingTimestamp = ping.timestamp;
122
+ pong.pongTimestamp = BigInt(Date.now());
123
+ this.frameAndSend(ping.serialize(), shared_1.Priority.High);
124
+ break;
125
+ }
126
+ case shared_1.Packets.ConnectionRequestAccepted: {
127
+ const accepted = new shared_1.ConnectionRequestAccepted(data).deserialize();
128
+ const nic = new shared_1.NewIncomingConnection();
129
+ nic.address = new shared_1.Address(this.socket.address().address, this.socket.address().port, this.socket.address().family === "IPv4" ? 4 : 6);
130
+ nic.internalAddress = new shared_1.Address("127.0.0.1", 0, 4);
131
+ nic.incomingTimestamp = BigInt(Date.now());
132
+ nic.serverTimestamp = accepted.timestamp;
133
+ this.frameAndSend(nic.serialize(), shared_1.Priority.High);
134
+ this.emit("connect");
135
+ break;
136
+ }
137
+ default: {
138
+ shared_2.Logger.warn(`Unknown packet type: ${id}`);
139
+ break;
140
+ }
154
141
  }
155
142
  }
156
- frameAndSend(payload, priority) {
157
- const frame = new proto_1.Frame();
158
- frame.payload = payload;
159
- frame.orderChannel = 0;
160
- this.sendFrame(frame, priority);
143
+ sendFrame(frame, priority = shared_1.Priority.Medium) {
144
+ this.session.sendFrame(frame, priority);
161
145
  }
162
- send(buffer) {
163
- if (this.status === proto_1.Status.Disconnected) {
164
- utils_1.Logger.warn("[Client] Attempting to send packet while disconnected");
165
- return;
166
- }
167
- if (!this.socket) {
168
- utils_1.Logger.error("[Client] Cannot send packet: socket is null");
169
- return;
170
- }
171
- utils_1.Logger.debug(`[Client] Sending packet ${buffer[0]}, ${buffer.length} bytes to ${this.options.address}:${this.options.port}`);
172
- try {
173
- this.socket.send(buffer, 0, buffer.length, this.options.port, this.options.address, (err) => {
174
- if (err) {
175
- utils_1.Logger.error("[Client] Failed to send packet", err);
176
- }
177
- });
178
- }
179
- catch (error) {
180
- utils_1.Logger.error("[Client] Failed to send packet", error);
181
- }
146
+ frameAndSend(data, priority = shared_1.Priority.Medium) {
147
+ this.session.frameAndSend(data, priority);
148
+ }
149
+ ping() {
150
+ const ping = new shared_1.UnconnectedPing();
151
+ ping.guid = this.options.guid;
152
+ ping.timestamp = BigInt(Date.now());
153
+ const serialized = ping.serialize();
154
+ this.send(serialized);
155
+ }
156
+ send(data) {
157
+ this.socket.send(data, this.options.port, this.options.address);
182
158
  }
183
159
  disconnect() {
184
- return new Promise((resolve) => {
185
- if (this.status === proto_1.Status.Disconnected) {
186
- resolve();
187
- return;
188
- }
189
- const wasConnected = this.status === proto_1.Status.Connected;
190
- this.status = proto_1.Status.Disconnected;
191
- if (this.tickTimer)
192
- clearInterval(this.tickTimer);
193
- if (this.connectionTimeout)
194
- clearTimeout(this.connectionTimeout);
195
- if (this.requestInterval)
196
- clearInterval(this.requestInterval);
197
- if (this.socket) {
198
- if (wasConnected) {
199
- const disconnect = new disconnect_1.default();
200
- this.socket.send(disconnect.serialize(), 0, disconnect.serialize().length, this.options.port, this.options.address);
201
- }
202
- this.socket.close();
203
- this.socket = null;
204
- }
205
- this.framer = null;
206
- resolve();
207
- });
160
+ this.socket.close();
161
+ if (this.interval)
162
+ clearInterval(this.interval);
208
163
  }
209
164
  }
210
165
  exports.Client = Client;
@@ -1,23 +1,8 @@
1
- import type { Ack, ConnectedPing, ConnectedPong, ConnectionRequest, ConnectionRequestAccepted, NewIncomingConnection, OpenConnectionReplyOne, OpenConnectionReplyTwo, OpenConnectionRequestOne, OpenConnectionRequestTwo, UnconnectedPing, UnconnectedPong } from "../../proto";
2
- import type { Frameset } from "../../proto/packets/frameset";
1
+ import type { UnconnectedPong } from "../../shared";
3
2
  export interface ClientEvents {
4
- "open-connection-reply-one": [OpenConnectionReplyOne];
5
- "open-connection-reply-two": [OpenConnectionReplyTwo];
6
- "open-connection-request-one": [OpenConnectionRequestOne];
7
- "open-connection-request-two": [OpenConnectionRequestTwo];
8
- "unconnected-ping": [UnconnectedPing];
9
- "unconnected-pong": [UnconnectedPong];
10
- frameset: [Frameset];
11
- "connected-ping": [ConnectedPing];
12
- "connected-pong": [ConnectedPong];
13
- "connection-request": [ConnectionRequest];
14
- "connection-request-accepted": [ConnectionRequestAccepted];
15
- "new-incoming-connection": [NewIncomingConnection];
16
- encapsulated: [Buffer];
17
- ack: [Ack];
18
- error: [Error];
19
- close: [];
20
- connect: [];
21
- tick: [];
3
+ unconnectedPong: UnconnectedPong;
4
+ error: Error;
5
+ connect: undefined;
6
+ encapsulated: Buffer;
22
7
  }
23
8
  //# sourceMappingURL=client-events.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client-events.d.ts","sourceRoot":"","sources":["../../../src/client/types/client-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,GAAG,EAEH,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,eAAe,EACf,eAAe,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAE7D,MAAM,WAAW,YAAY;IAC5B,2BAA2B,EAAE,CAAC,sBAAsB,CAAC,CAAC;IACtD,2BAA2B,EAAE,CAAC,sBAAsB,CAAC,CAAC;IACtD,6BAA6B,EAAE,CAAC,wBAAwB,CAAC,CAAC;IAC1D,6BAA6B,EAAE,CAAC,wBAAwB,CAAC,CAAC;IAC1D,kBAAkB,EAAE,CAAC,eAAe,CAAC,CAAC;IACtC,kBAAkB,EAAE,CAAC,eAAe,CAAC,CAAC;IACtC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC;IACrB,gBAAgB,EAAE,CAAC,aAAa,CAAC,CAAC;IAClC,gBAAgB,EAAE,CAAC,aAAa,CAAC,CAAC;IAClC,oBAAoB,EAAE,CAAC,iBAAiB,CAAC,CAAC;IAC1C,6BAA6B,EAAE,CAAC,yBAAyB,CAAC,CAAC;IAC3D,yBAAyB,EAAE,CAAC,qBAAqB,CAAC,CAAC;IACnD,YAAY,EAAE,CAAC,MAAM,CAAC,CAAC;IACvB,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IACX,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;IACf,KAAK,EAAE,EAAE,CAAC;IACV,OAAO,EAAE,EAAE,CAAC;IACZ,IAAI,EAAE,EAAE,CAAC;CACT"}
1
+ {"version":3,"file":"client-events.d.ts","sourceRoot":"","sources":["../../../src/client/types/client-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,WAAW,YAAY;IAC5B,eAAe,EAAE,eAAe,CAAC;IACjC,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,SAAS,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACrB"}
@@ -1,13 +1,12 @@
1
- type ClientOptions = {
1
+ export type ClientOptions = {
2
+ mtu: number;
2
3
  address: string;
3
4
  port: number;
4
- protocolVersion: number;
5
- mtuSize: number;
6
- clientId: bigint;
7
- debug: boolean;
5
+ guid: bigint;
6
+ tickRate: number;
7
+ pingRate: number;
8
8
  timeout: number;
9
- loggerDisabled: boolean;
10
9
  };
11
- declare const defaultClientOptions: ClientOptions;
12
- export { defaultClientOptions, type ClientOptions };
10
+ export declare const getRandomGuid: () => bigint;
11
+ export declare const defaultClientOptions: ClientOptions;
13
12
  //# sourceMappingURL=client-options.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client-options.d.ts","sourceRoot":"","sources":["../../../src/client/types/client-options.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,GAAG;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,QAAA,MAAM,oBAAoB,EAAE,aAS3B,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,KAAK,aAAa,EAAE,CAAC"}
1
+ {"version":3,"file":"client-options.d.ts","sourceRoot":"","sources":["../../../src/client/types/client-options.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,aAAa,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CAChB,CAAC;AACF,eAAO,MAAM,aAAa,cACgC,CAAC;AAE3D,eAAO,MAAM,oBAAoB,EAAE,aAQlC,CAAC"}
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultClientOptions = void 0;
4
- const defaultClientOptions = {
3
+ exports.defaultClientOptions = exports.getRandomGuid = void 0;
4
+ const getRandomGuid = () => BigInt(Math.floor(Date.now() + Math.random() * 10000000));
5
+ exports.getRandomGuid = getRandomGuid;
6
+ exports.defaultClientOptions = {
7
+ mtu: 1492,
5
8
  address: "127.0.0.1",
6
9
  port: 19132,
7
- protocolVersion: 11,
8
- mtuSize: 1492,
9
- clientId: BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)),
10
- debug: false,
11
- timeout: 10000,
12
- loggerDisabled: false,
10
+ guid: (0, exports.getRandomGuid)(),
11
+ tickRate: 20,
12
+ pingRate: 40,
13
+ timeout: 30000,
13
14
  };
14
- exports.defaultClientOptions = defaultClientOptions;
@@ -1,3 +1,3 @@
1
- export * from "./client-events";
2
1
  export * from "./client-options";
2
+ export * from "./client-events";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./client-events"), exports);
18
17
  __exportStar(require("./client-options"), exports);
18
+ __exportStar(require("./client-events"), exports);
package/dist/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- import "reflect-metadata";
2
- export * from "./proto";
3
- export * from "./utils";
4
1
  export * from "./client";
2
+ export * from "./shared";
5
3
  export * from "./server";
6
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -14,8 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- require("reflect-metadata");
18
- __exportStar(require("./proto"), exports);
19
- __exportStar(require("./utils"), exports);
20
17
  __exportStar(require("./client"), exports);
18
+ __exportStar(require("./shared"), exports);
21
19
  __exportStar(require("./server"), exports);
@@ -1,62 +1,23 @@
1
- import Emitter from "@serenityjs/emitter";
2
- import type { RemoteInfo } from "node:dgram";
1
+ import { type Ack, EventEmitter, type Frame, type FrameSet, Priority } from "../shared";
3
2
  import type { Server } from "./server";
4
- import { Address, Frame, Priority, Status } from "../proto";
5
- import { BinaryStream } from "@serenityjs/binarystream";
6
- type ConnectionEvents = {
7
- disconnect: [];
8
- encapsulated: [Buffer];
9
- };
10
- interface QueuedFrame {
11
- frame: Frame;
12
- timestamp: number;
13
- }
14
- interface FragmentGroup {
15
- fragments: Map<number, Frame>;
16
- timestamp: number;
17
- }
18
- declare class Connection extends Emitter<ConnectionEvents> {
19
- readonly server: Server;
20
- readonly remoteInfo: RemoteInfo;
21
- readonly guid: bigint;
22
- readonly mtu: number;
23
- status: Status;
24
- private lastUpdate;
25
- protected readonly receivedFrameSequences: Set<number>;
26
- protected readonly lostFrameSequences: Set<number>;
27
- protected lastInputSequence: number;
28
- protected fragmentsQueue: Map<number, FragmentGroup>;
29
- private inputOrderIndex;
30
- protected inputOrderingQueue: Map<number, Map<number, QueuedFrame>>;
31
- private inputHighestSequenceIndex;
32
- outputOrderIndex: number[];
33
- outputSequenceIndex: number[];
34
- protected outputFrameQueue: Frame[];
35
- protected outputFramesByteLength: number;
36
- protected outputSequence: number;
37
- protected outputSplitIndex: number;
38
- protected outputReliableIndex: number;
39
- outputBackup: Map<number, Frame[]>;
40
- private readonly ORDERING_QUEUE_TIMEOUT;
41
- constructor(server: Server, remoteInfo: RemoteInfo, guid: bigint, mtu: number);
42
- tick(): void;
43
- private handlePackets;
44
- handle(message: Buffer): void;
45
- private handleFrameSet;
46
- private handleFrame;
47
- private handleSplit;
48
- private handleOrdered;
49
- private handleSequenced;
50
- sendFrame(frame: Frame, priority: Priority): void;
51
- private handleLargePayload;
52
- private createSplitFrame;
53
- private queueFrame;
54
- sendQueue(amount: number): void;
55
- frameAndSend(payload: Buffer | BinaryStream, priority: Priority): void;
56
- send(message: Buffer): void;
57
- disconnect(timeout?: boolean): void;
58
- getConnectionTime(type?: "ms" | "s" | "min"): number;
59
- getAddress(): Address;
3
+ import type { RemoteInfo } from "node:dgram";
4
+ import type { ConnectionEvents } from "./types";
5
+ export declare class Connection extends EventEmitter<ConnectionEvents> {
6
+ private server;
7
+ private rinfo;
8
+ private mtu;
9
+ private guid;
10
+ private session;
11
+ constructor(server: Server, rinfo: RemoteInfo, mtu: number, guid: bigint);
12
+ onTick(tick: number): void;
13
+ onFrameSet(frameSet: FrameSet): void;
14
+ getAddress(): RemoteInfo;
15
+ onMessage(data: Buffer): void;
16
+ onAck(message: Ack): void;
17
+ /** Nack Packet is same as Ack just different id's and we do not care about the ids. */
18
+ onNack(message: Ack): void;
19
+ sendFrame(frame: Frame, priority?: Priority): void;
20
+ frameAndSend(payload: Buffer, priority?: Priority): void;
21
+ send(data: Buffer): void;
60
22
  }
61
- export { Connection };
62
23
  //# sourceMappingURL=connection.d.ts.map