@sanctumterra/raknet 1.3.79 → 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 (286) hide show
  1. package/README.md +1 -1
  2. package/dist/client/client.d.ts +19 -24
  3. package/dist/client/client.d.ts.map +1 -1
  4. package/dist/client/client.js +135 -278
  5. package/dist/client/index.d.ts +1 -2
  6. package/dist/client/index.d.ts.map +1 -1
  7. package/dist/client/index.js +1 -2
  8. package/dist/client/types/client-events.d.ts +8 -0
  9. package/dist/client/types/client-events.d.ts.map +1 -0
  10. package/dist/client/types/client-options.d.ts +12 -0
  11. package/dist/client/types/client-options.d.ts.map +1 -0
  12. package/dist/client/types/client-options.js +14 -0
  13. package/dist/client/types/index.d.ts +3 -0
  14. package/dist/client/types/index.d.ts.map +1 -0
  15. package/dist/{proto/decorators → client/types}/index.js +2 -2
  16. package/dist/index.d.ts +1 -3
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +1 -3
  19. package/dist/server/connection.d.ts +20 -59
  20. package/dist/server/connection.d.ts.map +1 -1
  21. package/dist/server/connection.js +53 -365
  22. package/dist/server/index.d.ts +2 -3
  23. package/dist/server/index.d.ts.map +1 -1
  24. package/dist/server/index.js +2 -3
  25. package/dist/server/server.d.ts +11 -18
  26. package/dist/server/server.d.ts.map +1 -1
  27. package/dist/server/server.js +98 -137
  28. package/dist/{proto → server}/types/advertisement.d.ts +1 -1
  29. package/dist/server/types/advertisement.d.ts.map +1 -0
  30. package/dist/{proto → server}/types/advertisement.js +14 -10
  31. package/dist/server/types/connection-events.d.ts +4 -0
  32. package/dist/server/types/connection-events.d.ts.map +1 -0
  33. package/dist/server/types/index.d.ts +5 -0
  34. package/dist/server/types/index.d.ts.map +1 -0
  35. package/dist/{proto → server}/types/index.js +3 -1
  36. package/dist/server/types/server-events.d.ts +7 -0
  37. package/dist/server/types/server-events.d.ts.map +1 -0
  38. package/dist/server/types/server-options.d.ts +12 -0
  39. package/dist/server/types/server-options.d.ts.map +1 -0
  40. package/dist/server/types/server-options.js +14 -0
  41. package/dist/shared/emitter.d.ts +28 -0
  42. package/dist/shared/emitter.d.ts.map +1 -0
  43. package/dist/shared/emitter.js +71 -0
  44. package/dist/shared/index.d.ts +5 -0
  45. package/dist/shared/index.d.ts.map +1 -0
  46. package/dist/{utils → shared}/index.js +4 -1
  47. package/dist/{utils/Logger.d.ts → shared/logger.d.ts} +1 -1
  48. package/dist/shared/logger.d.ts.map +1 -0
  49. package/dist/shared/network_session.d.ts +34 -0
  50. package/dist/shared/network_session.d.ts.map +1 -0
  51. package/dist/shared/network_session.js +247 -0
  52. package/dist/shared/proto/enums/connectionStatus.d.ts +8 -0
  53. package/dist/shared/proto/enums/connectionStatus.d.ts.map +1 -0
  54. package/dist/shared/proto/enums/connectionStatus.js +11 -0
  55. package/dist/shared/proto/enums/index.d.ts +5 -0
  56. package/dist/shared/proto/enums/index.d.ts.map +1 -0
  57. package/dist/{proto → shared/proto}/enums/index.js +2 -3
  58. package/dist/shared/proto/enums/packets.d.ts +19 -0
  59. package/dist/shared/proto/enums/packets.d.ts.map +1 -0
  60. package/dist/shared/proto/enums/packets.js +23 -0
  61. package/dist/shared/proto/enums/priority.d.ts +6 -0
  62. package/dist/shared/proto/enums/priority.d.ts.map +1 -0
  63. package/dist/shared/proto/enums/priority.js +4 -0
  64. package/dist/shared/proto/enums/reliability.d.ts.map +1 -0
  65. package/dist/shared/proto/index.d.ts +5 -0
  66. package/dist/shared/proto/index.d.ts.map +1 -0
  67. package/dist/{proto → shared/proto}/index.js +3 -3
  68. package/dist/shared/proto/offline/index.d.ts +7 -0
  69. package/dist/shared/proto/offline/index.d.ts.map +1 -0
  70. package/dist/shared/proto/offline/index.js +22 -0
  71. package/dist/shared/proto/offline/open-connection-reply-one.d.ts +9 -0
  72. package/dist/shared/proto/offline/open-connection-reply-one.d.ts.map +1 -0
  73. package/dist/shared/proto/offline/open-connection-reply-one.js +28 -0
  74. package/dist/shared/proto/offline/open-connection-reply-two.d.ts +11 -0
  75. package/dist/shared/proto/offline/open-connection-reply-two.d.ts.map +1 -0
  76. package/dist/shared/proto/offline/open-connection-reply-two.js +31 -0
  77. package/dist/shared/proto/offline/open-connection-request-one.d.ts +8 -0
  78. package/dist/shared/proto/offline/open-connection-request-one.d.ts.map +1 -0
  79. package/dist/shared/proto/offline/open-connection-request-one.js +25 -0
  80. package/dist/shared/proto/offline/open-connection-request-two.d.ts +10 -0
  81. package/dist/shared/proto/offline/open-connection-request-two.d.ts.map +1 -0
  82. package/dist/shared/proto/offline/open-connection-request-two.js +28 -0
  83. package/dist/shared/proto/offline/unconnected-ping.d.ts +8 -0
  84. package/dist/shared/proto/offline/unconnected-ping.d.ts.map +1 -0
  85. package/dist/shared/proto/offline/unconnected-ping.js +25 -0
  86. package/dist/shared/proto/offline/unconnected-pong.d.ts +9 -0
  87. package/dist/shared/proto/offline/unconnected-pong.d.ts.map +1 -0
  88. package/dist/shared/proto/offline/unconnected-pong.js +28 -0
  89. package/dist/shared/proto/online/ack.d.ts +7 -0
  90. package/dist/shared/proto/online/ack.d.ts.map +1 -0
  91. package/dist/{proto/packets → shared/proto/online}/ack.js +16 -31
  92. package/dist/shared/proto/online/connected-ping.d.ts +7 -0
  93. package/dist/shared/proto/online/connected-ping.d.ts.map +1 -0
  94. package/dist/shared/proto/online/connected-ping.js +19 -0
  95. package/dist/shared/proto/online/connected-pong.d.ts +8 -0
  96. package/dist/shared/proto/online/connected-pong.d.ts.map +1 -0
  97. package/dist/shared/proto/online/connected-pong.js +22 -0
  98. package/dist/shared/proto/online/connection-request-accepted.d.ts +12 -0
  99. package/dist/shared/proto/online/connection-request-accepted.d.ts.map +1 -0
  100. package/dist/shared/proto/online/connection-request-accepted.js +37 -0
  101. package/dist/shared/proto/online/connection-request.d.ts +9 -0
  102. package/dist/shared/proto/online/connection-request.d.ts.map +1 -0
  103. package/dist/shared/proto/online/connection-request.js +25 -0
  104. package/dist/shared/proto/online/disconnect-message.d.ts +6 -0
  105. package/dist/shared/proto/online/disconnect-message.d.ts.map +1 -0
  106. package/dist/shared/proto/online/disconnect-message.js +15 -0
  107. package/dist/shared/proto/online/frame-set.d.ts +9 -0
  108. package/dist/shared/proto/online/frame-set.d.ts.map +1 -0
  109. package/dist/shared/proto/online/frame-set.js +23 -0
  110. package/dist/shared/proto/online/index.d.ts +9 -0
  111. package/dist/shared/proto/online/index.d.ts.map +1 -0
  112. package/dist/shared/proto/online/index.js +24 -0
  113. package/dist/shared/proto/online/new-incomming-connection.d.ts +11 -0
  114. package/dist/shared/proto/online/new-incomming-connection.d.ts.map +1 -0
  115. package/dist/shared/proto/online/new-incomming-connection.js +33 -0
  116. package/dist/shared/proto/types/address.d.ts +12 -0
  117. package/dist/shared/proto/types/address.d.ts.map +1 -0
  118. package/dist/shared/proto/types/address.js +61 -0
  119. package/dist/shared/proto/types/frame.d.ts +23 -0
  120. package/dist/shared/proto/types/frame.d.ts.map +1 -0
  121. package/dist/shared/proto/types/frame.js +119 -0
  122. package/dist/{proto/packets → shared/proto}/types/index.d.ts +0 -2
  123. package/dist/shared/proto/types/index.d.ts.map +1 -0
  124. package/dist/{proto/packets → shared/proto}/types/index.js +0 -2
  125. package/dist/shared/proto/types/magic.d.ts +7 -0
  126. package/dist/shared/proto/types/magic.d.ts.map +1 -0
  127. package/dist/shared/proto/types/magic.js +15 -0
  128. package/dist/shared/proto/types/mtu.d.ts +7 -0
  129. package/dist/shared/proto/types/mtu.d.ts.map +1 -0
  130. package/dist/shared/proto/types/mtu.js +13 -0
  131. package/dist/tests/client-connect.d.ts +2 -0
  132. package/dist/tests/client-connect.d.ts.map +1 -0
  133. package/dist/tests/client-connect.js +32 -0
  134. package/dist/tests/client-once.d.ts +2 -0
  135. package/dist/tests/client-once.d.ts.map +1 -0
  136. package/dist/tests/client-once.js +11 -0
  137. package/dist/tests/server-listen.d.ts +2 -0
  138. package/dist/tests/server-listen.d.ts.map +1 -0
  139. package/dist/tests/server-listen.js +5 -0
  140. package/package.json +8 -8
  141. package/bun.lock +0 -67
  142. package/dist/client/client-events.d.ts +0 -23
  143. package/dist/client/client-events.d.ts.map +0 -1
  144. package/dist/client/client-options.d.ts +0 -13
  145. package/dist/client/client-options.d.ts.map +0 -1
  146. package/dist/client/client-options.js +0 -14
  147. package/dist/client/client_options.d.ts +0 -10
  148. package/dist/client/client_options.d.ts.map +0 -1
  149. package/dist/client/client_options.js +0 -11
  150. package/dist/client/framer.d.ts +0 -56
  151. package/dist/client/framer.d.ts.map +0 -1
  152. package/dist/client/framer.js +0 -467
  153. package/dist/proto/decorators/create.d.ts +0 -8
  154. package/dist/proto/decorators/create.d.ts.map +0 -1
  155. package/dist/proto/decorators/create.js +0 -77
  156. package/dist/proto/decorators/index.d.ts +0 -3
  157. package/dist/proto/decorators/index.d.ts.map +0 -1
  158. package/dist/proto/decorators/serialize.d.ts +0 -4
  159. package/dist/proto/decorators/serialize.d.ts.map +0 -1
  160. package/dist/proto/decorators/serialize.js +0 -12
  161. package/dist/proto/enums/flags.d.ts +0 -7
  162. package/dist/proto/enums/flags.d.ts.map +0 -1
  163. package/dist/proto/enums/flags.js +0 -10
  164. package/dist/proto/enums/index.d.ts +0 -6
  165. package/dist/proto/enums/index.d.ts.map +0 -1
  166. package/dist/proto/enums/packet.d.ts +0 -122
  167. package/dist/proto/enums/packet.d.ts.map +0 -1
  168. package/dist/proto/enums/packet.js +0 -125
  169. package/dist/proto/enums/priority.d.ts +0 -5
  170. package/dist/proto/enums/priority.d.ts.map +0 -1
  171. package/dist/proto/enums/priority.js +0 -8
  172. package/dist/proto/enums/reliability.d.ts.map +0 -1
  173. package/dist/proto/enums/status.d.ts +0 -7
  174. package/dist/proto/enums/status.d.ts.map +0 -1
  175. package/dist/proto/enums/status.js +0 -10
  176. package/dist/proto/index.d.ts +0 -5
  177. package/dist/proto/index.d.ts.map +0 -1
  178. package/dist/proto/packets/ack.d.ts +0 -10
  179. package/dist/proto/packets/ack.d.ts.map +0 -1
  180. package/dist/proto/packets/base-packet.d.ts +0 -26
  181. package/dist/proto/packets/base-packet.d.ts.map +0 -1
  182. package/dist/proto/packets/base-packet.js +0 -37
  183. package/dist/proto/packets/connected-ping.d.ts +0 -5
  184. package/dist/proto/packets/connected-ping.d.ts.map +0 -1
  185. package/dist/proto/packets/connected-ping.js +0 -27
  186. package/dist/proto/packets/connected-pong.d.ts +0 -6
  187. package/dist/proto/packets/connected-pong.d.ts.map +0 -1
  188. package/dist/proto/packets/connected-pong.js +0 -32
  189. package/dist/proto/packets/connection-request-accepted.d.ts +0 -10
  190. package/dist/proto/packets/connection-request-accepted.d.ts.map +0 -1
  191. package/dist/proto/packets/connection-request-accepted.js +0 -48
  192. package/dist/proto/packets/connection-request.d.ts +0 -7
  193. package/dist/proto/packets/connection-request.d.ts.map +0 -1
  194. package/dist/proto/packets/connection-request.js +0 -37
  195. package/dist/proto/packets/disconnect.d.ts +0 -5
  196. package/dist/proto/packets/disconnect.d.ts.map +0 -1
  197. package/dist/proto/packets/disconnect.js +0 -17
  198. package/dist/proto/packets/frame.d.ts +0 -1
  199. package/dist/proto/packets/frame.d.ts.map +0 -1
  200. package/dist/proto/packets/frame.js +0 -1
  201. package/dist/proto/packets/frameset.d.ts +0 -11
  202. package/dist/proto/packets/frameset.d.ts.map +0 -1
  203. package/dist/proto/packets/frameset.js +0 -37
  204. package/dist/proto/packets/incompatible-protocol-version.d.ts +0 -8
  205. package/dist/proto/packets/incompatible-protocol-version.d.ts.map +0 -1
  206. package/dist/proto/packets/incompatible-protocol-version.js +0 -38
  207. package/dist/proto/packets/index.d.ts +0 -19
  208. package/dist/proto/packets/index.d.ts.map +0 -1
  209. package/dist/proto/packets/index.js +0 -34
  210. package/dist/proto/packets/nack.d.ts +0 -8
  211. package/dist/proto/packets/nack.d.ts.map +0 -1
  212. package/dist/proto/packets/nack.js +0 -88
  213. package/dist/proto/packets/new-incoming-connection.d.ts +0 -9
  214. package/dist/proto/packets/new-incoming-connection.d.ts.map +0 -1
  215. package/dist/proto/packets/new-incoming-connection.js +0 -43
  216. package/dist/proto/packets/open-connection-reply-one.d.ts +0 -8
  217. package/dist/proto/packets/open-connection-reply-one.d.ts.map +0 -1
  218. package/dist/proto/packets/open-connection-reply-one.js +0 -43
  219. package/dist/proto/packets/open-connection-reply-two.d.ts +0 -10
  220. package/dist/proto/packets/open-connection-reply-two.d.ts.map +0 -1
  221. package/dist/proto/packets/open-connection-reply-two.js +0 -48
  222. package/dist/proto/packets/open-connection-request-one.d.ts +0 -7
  223. package/dist/proto/packets/open-connection-request-one.d.ts.map +0 -1
  224. package/dist/proto/packets/open-connection-request-one.js +0 -38
  225. package/dist/proto/packets/open-connection-request-two.d.ts +0 -9
  226. package/dist/proto/packets/open-connection-request-two.d.ts.map +0 -1
  227. package/dist/proto/packets/open-connection-request-two.js +0 -43
  228. package/dist/proto/packets/types/address.d.ts +0 -48
  229. package/dist/proto/packets/types/address.d.ts.map +0 -1
  230. package/dist/proto/packets/types/address.js +0 -99
  231. package/dist/proto/packets/types/data-type.d.ts +0 -21
  232. package/dist/proto/packets/types/data-type.d.ts.map +0 -1
  233. package/dist/proto/packets/types/data-type.js +0 -29
  234. package/dist/proto/packets/types/frame.d.ts +0 -23
  235. package/dist/proto/packets/types/frame.d.ts.map +0 -1
  236. package/dist/proto/packets/types/frame.js +0 -94
  237. package/dist/proto/packets/types/index.d.ts.map +0 -1
  238. package/dist/proto/packets/types/magic.d.ts +0 -7
  239. package/dist/proto/packets/types/magic.d.ts.map +0 -1
  240. package/dist/proto/packets/types/magic.js +0 -14
  241. package/dist/proto/packets/types/mtu.d.ts +0 -9
  242. package/dist/proto/packets/types/mtu.d.ts.map +0 -1
  243. package/dist/proto/packets/types/mtu.js +0 -18
  244. package/dist/proto/packets/types/sys-address.d.ts +0 -11
  245. package/dist/proto/packets/types/sys-address.d.ts.map +0 -1
  246. package/dist/proto/packets/types/sys-address.js +0 -32
  247. package/dist/proto/packets/unconnected-ping.d.ts +0 -7
  248. package/dist/proto/packets/unconnected-ping.d.ts.map +0 -1
  249. package/dist/proto/packets/unconnected-ping.js +0 -38
  250. package/dist/proto/packets/unconnected-pong.d.ts +0 -8
  251. package/dist/proto/packets/unconnected-pong.d.ts.map +0 -1
  252. package/dist/proto/packets/unconnected-pong.js +0 -43
  253. package/dist/proto/types/advertisement.d.ts.map +0 -1
  254. package/dist/proto/types/index.d.ts +0 -3
  255. package/dist/proto/types/index.d.ts.map +0 -1
  256. package/dist/proto/types/valid.d.ts +0 -4
  257. package/dist/proto/types/valid.d.ts.map +0 -1
  258. package/dist/server/server-events.d.ts +0 -9
  259. package/dist/server/server-events.d.ts.map +0 -1
  260. package/dist/server/server-options.d.ts +0 -26
  261. package/dist/server/server-options.d.ts.map +0 -1
  262. package/dist/server/server-options.js +0 -20
  263. package/dist/tests/client.d.ts +0 -2
  264. package/dist/tests/client.d.ts.map +0 -1
  265. package/dist/tests/client.js +0 -15
  266. package/dist/tests/localhost.d.ts +0 -2
  267. package/dist/tests/localhost.d.ts.map +0 -1
  268. package/dist/tests/localhost.js +0 -34
  269. package/dist/tests/server.d.ts +0 -2
  270. package/dist/tests/server.d.ts.map +0 -1
  271. package/dist/tests/server.js +0 -32
  272. package/dist/tests/test.d.ts +0 -2
  273. package/dist/tests/test.d.ts.map +0 -1
  274. package/dist/tests/test.js +0 -49
  275. package/dist/utils/Logger.d.ts.map +0 -1
  276. package/dist/utils/decorators.d.ts +0 -2
  277. package/dist/utils/decorators.d.ts.map +0 -1
  278. package/dist/utils/decorators.js +0 -17
  279. package/dist/utils/index.d.ts +0 -2
  280. package/dist/utils/index.d.ts.map +0 -1
  281. /package/dist/client/{client-events.js → types/client-events.js} +0 -0
  282. /package/dist/{proto/types/valid.js → server/types/connection-events.js} +0 -0
  283. /package/dist/server/{server-events.js → types/server-events.js} +0 -0
  284. /package/dist/{utils/Logger.js → shared/logger.js} +0 -0
  285. /package/dist/{proto → shared/proto}/enums/reliability.d.ts +0 -0
  286. /package/dist/{proto → shared/proto}/enums/reliability.js +0 -0
@@ -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
@@ -1 +1 @@
1
- {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/server/connection.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,qBAAqB,CAAC;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAEN,OAAO,EAKP,KAAK,EAIL,QAAQ,EAER,MAAM,EAEN,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAGxD,KAAK,gBAAgB,GAAG;IACvB,UAAU,EAAE,EAAE,CAAC;IACf,YAAY,EAAE,CAAC,MAAM,CAAC,CAAC;CACvB,CAAC;AAEF,UAAU,WAAW;IACpB,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,aAAa;IACtB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IA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CAAC,IAAI,EAAE,MAAM;IAInB,UAAU,CAAC,QAAQ,EAAE,QAAQ;IAI7B,UAAU,IAAI,UAAU;IAIxB,SAAS,CAAC,IAAI,EAAE,MAAM;IAqDtB,KAAK,CAAC,OAAO,EAAE,GAAG;IAIzB,uFAAuF;IAChF,MAAM,CAAC,OAAO,EAAE,GAAG;IAInB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,GAAE,QAAwB;IAI1D,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,GAAE,QAAwB;IAIhE,IAAI,CAAC,IAAI,EAAE,MAAM;CAGxB"}
@@ -1,400 +1,88 @@
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.Connection = void 0;
7
- const emitter_1 = __importDefault(require("@serenityjs/emitter"));
8
- const proto_1 = require("../proto");
9
- const utils_1 = require("../utils");
10
- const binarystream_1 = require("@serenityjs/binarystream");
11
- const disconnect_1 = __importDefault(require("../proto/packets/disconnect"));
12
- class Connection extends emitter_1.default {
4
+ const shared_1 = require("../shared");
5
+ class Connection extends shared_1.EventEmitter {
13
6
  server;
14
- remoteInfo;
15
- guid;
7
+ rinfo;
16
8
  mtu;
17
- status = proto_1.Status.Disconnected;
18
- lastUpdate;
19
- receivedFrameSequences = new Set();
20
- lostFrameSequences = new Set();
21
- lastInputSequence = -1;
22
- fragmentsQueue = new Map();
23
- inputOrderIndex = new Array(64).fill(0);
24
- inputOrderingQueue = new Map();
25
- inputHighestSequenceIndex = new Array(64).fill(0);
26
- outputOrderIndex;
27
- outputSequenceIndex;
28
- outputFrameQueue = [];
29
- outputFramesByteLength = 0;
30
- outputSequence = 0;
31
- outputSplitIndex = 0;
32
- outputReliableIndex = 0;
33
- outputBackup = new Map();
34
- ORDERING_QUEUE_TIMEOUT = 500;
35
- constructor(server, remoteInfo, guid, mtu) {
9
+ guid;
10
+ session;
11
+ constructor(server, rinfo, mtu, guid) {
36
12
  super();
37
13
  this.server = server;
38
- this.remoteInfo = remoteInfo;
39
- this.guid = guid;
14
+ this.rinfo = rinfo;
40
15
  this.mtu = mtu;
41
- this.lastUpdate = Date.now();
42
- this.status = proto_1.Status.Connecting;
43
- this.outputOrderIndex = new Array(32).fill(0);
44
- this.outputSequenceIndex = new Array(32).fill(0);
45
- for (let i = 0; i < 64; i++) {
46
- this.inputOrderingQueue.set(i, new Map());
47
- }
16
+ this.guid = guid;
17
+ this.session = new shared_1.NetworkSession(this.mtu);
18
+ this.session.send = this.send.bind(this);
19
+ this.session.handle = this.onMessage.bind(this);
48
20
  }
49
- tick() {
50
- const now = Date.now();
51
- utils_1.Logger.debug(`[Connection] Time since last update: ${now - this.lastUpdate} ms`);
52
- if (now - this.lastUpdate > this.server.options.connectionTimeout) {
53
- utils_1.Logger.warn(`Connection to ${this.remoteInfo.address}:${this.remoteInfo.port} timed out`);
54
- this.server.deleteConnection(`${this.remoteInfo.address}:${this.remoteInfo.port}`);
55
- return;
56
- }
57
- if (this.receivedFrameSequences.size > 0) {
58
- const ack = new proto_1.Ack();
59
- ack.sequences = Array.from(this.receivedFrameSequences);
60
- this.receivedFrameSequences.clear();
61
- this.send(ack.serialize());
62
- }
63
- if (this.lostFrameSequences.size > 0) {
64
- const nack = new proto_1.Nack();
65
- nack.sequences = Array.from(this.lostFrameSequences);
66
- this.lostFrameSequences.clear();
67
- this.send(nack.serialize());
68
- }
69
- for (let channel = 0; channel < 64; channel++) {
70
- const queue = this.inputOrderingQueue.get(channel);
71
- if (!queue)
72
- continue;
73
- const expectedIndex = this.inputOrderIndex[channel];
74
- if (queue.has(expectedIndex)) {
75
- const queued = queue.get(expectedIndex);
76
- if (queued && now - queued.timestamp > this.ORDERING_QUEUE_TIMEOUT) {
77
- utils_1.Logger.warn(`[Connection] Timeout waiting for ordered frame ${expectedIndex} on channel ${channel}; processing it to unblock.`);
78
- this.handlePackets(queued.frame.payload);
79
- queue.delete(expectedIndex);
80
- this.inputOrderIndex[channel] = expectedIndex + 1;
81
- }
82
- }
83
- }
84
- this.sendQueue(this.outputFrameQueue.length);
21
+ onTick(tick) {
22
+ this.session.onTick(tick);
85
23
  }
86
- handlePackets(message) {
87
- const packetId = message[0];
88
- utils_1.Logger.debug(`Received packet ${packetId} from ${this.remoteInfo.address}:${this.remoteInfo.port}`);
89
- switch (packetId) {
90
- case proto_1.Packet.ConnectionRequest: {
91
- const connectionRequest = new proto_1.ConnectionRequest(message).deserialize();
92
- utils_1.Logger.debug(`Received ConnectionRequest from ${this.remoteInfo.address}:${this.remoteInfo.port}`);
93
- const accepted = new proto_1.ConnectionRequestAccepted();
94
- const version = this.remoteInfo.address.includes(":") ? 6 : 4;
95
- accepted.address = new proto_1.Address(this.remoteInfo.address, this.remoteInfo.port, version);
96
- accepted.requestTimestamp = connectionRequest.timestamp;
97
- accepted.systemAddresses = new Array(20).fill(new proto_1.Address(this.remoteInfo.address, this.remoteInfo.port, version));
98
- accepted.timestamp = BigInt(Date.now());
24
+ onFrameSet(frameSet) {
25
+ this.session.onFrameSet(frameSet);
26
+ }
27
+ getAddress() {
28
+ return this.rinfo;
29
+ }
30
+ onMessage(data) {
31
+ const id = data[0];
32
+ switch (id) {
33
+ case shared_1.Packets.ConnectionRequest: {
34
+ const request = new shared_1.ConnectionRequest(data).deserialize();
35
+ const accepted = new shared_1.ConnectionRequestAccepted();
36
+ accepted.address = new shared_1.Address(this.rinfo.address, this.rinfo.port, this.rinfo.family === "IPv4" ? 4 : 6);
37
+ // 20 addresses
38
+ accepted.addresses = Array().fill(new shared_1.Address("0.0.0.0", this.server.options.port, 4), 0, 20);
39
+ accepted.requestTimestamp = request.timestamp;
99
40
  accepted.systemIndex = 0;
100
- this.frameAndSend(accepted.serialize(), proto_1.Priority.Immediate);
41
+ accepted.timestamp = BigInt(Date.now());
42
+ this.session.frameAndSend(accepted.serialize(), shared_1.Priority.High);
101
43
  break;
102
44
  }
103
- case proto_1.Packet.NewIncomingConnection: {
104
- const packet = new proto_1.NewIncomingConnection(message).deserialize();
105
- if (packet.serverAddress.port !== this.server.options.port) {
106
- this.disconnect();
107
- return;
108
- }
109
- this.status = proto_1.Status.Connected;
110
- const startTime = this.server.connectionTimes.get(`${this.remoteInfo.address}:${this.remoteInfo.port}`);
111
- if (startTime) {
112
- const latency = Date.now() - startTime;
113
- this.server.connectionTimes.set(`${this.remoteInfo.address}:${this.remoteInfo.port}`, latency);
114
- }
45
+ case shared_1.Packets.NewIncomingConnection: {
115
46
  this.server.emit("connect", this);
116
47
  break;
117
48
  }
118
- case proto_1.Packet.ConnectedPing: {
119
- const connectedPing = new proto_1.ConnectedPing(message).deserialize();
120
- const pong = new proto_1.ConnectedPong();
121
- pong.pongTime = BigInt(Date.now());
122
- pong.pingTime = connectedPing.timestamp;
123
- this.frameAndSend(pong.serialize(), proto_1.Priority.Immediate);
49
+ case shared_1.Packets.Disconnect: {
50
+ this.server.emit("disconnect", this);
124
51
  break;
125
52
  }
126
- case proto_1.Packet.DisconnectionNotification: {
127
- this.emit("disconnect");
128
- this.server.deleteConnection(`${this.remoteInfo.address}:${this.remoteInfo.port}`);
53
+ case shared_1.Packets.ConnectedPing: {
54
+ const ping = new shared_1.ConnectedPing(data).deserialize();
55
+ const pong = new shared_1.ConnectedPong();
56
+ pong.pingTimestamp = ping.timestamp;
57
+ pong.pongTimestamp = BigInt(Date.now());
58
+ this.session.frameAndSend(pong.serialize(), shared_1.Priority.High);
129
59
  break;
130
60
  }
131
61
  case 254: {
132
- this.server.emit("encapsulated", message, this);
133
- this.emit("encapsulated", message);
62
+ this.emit("encapsulated", data);
134
63
  break;
135
64
  }
136
65
  default: {
137
- utils_1.Logger.warn(`Received unknown packet ${packetId} from ${this.remoteInfo.address}:${this.remoteInfo.port}`);
66
+ shared_1.Logger.warn(`Unknown packet received ${id} - `, data.slice(0, 25));
138
67
  break;
139
68
  }
140
69
  }
141
70
  }
142
- handle(message) {
143
- if (this.status === proto_1.Status.Disconnected)
144
- return;
145
- this.lastUpdate = Date.now();
146
- let packetId = message[0];
147
- if ((packetId & 0xf0) === 0x80)
148
- packetId = 0x80;
149
- switch (packetId) {
150
- case proto_1.Packet.FrameSet: {
151
- const frameset = new proto_1.Frameset(message).deserialize();
152
- utils_1.Logger.debug(`Received FrameSet from ${this.remoteInfo.address}:${this.remoteInfo.port} with sequence ${frameset.sequence}`);
153
- this.handleFrameSet(frameset);
154
- break;
155
- }
156
- case proto_1.Packet.Ack: {
157
- const ack = new proto_1.Ack(message).deserialize();
158
- for (const seq of ack.sequences) {
159
- this.outputBackup.delete(seq);
160
- }
161
- break;
162
- }
163
- case proto_1.Packet.Nack: {
164
- const nack = new proto_1.Nack(message).deserialize();
165
- for (const seq of nack.sequences) {
166
- const lostFrames = this.outputBackup.get(seq);
167
- if (lostFrames && lostFrames.length > 0) {
168
- for (const lostFrame of lostFrames) {
169
- this.sendFrame(lostFrame, proto_1.Priority.Immediate);
170
- }
171
- }
172
- }
173
- break;
174
- }
175
- default: {
176
- utils_1.Logger.warn(`Received unknown packet ${packetId} from ${this.remoteInfo.address}:${this.remoteInfo.port}`);
177
- break;
178
- }
179
- }
71
+ onAck(message) {
72
+ this.session.onAck(message);
180
73
  }
181
- handleFrameSet(frameset) {
182
- const sequence = frameset.sequence;
183
- if (sequence <= this.lastInputSequence ||
184
- this.receivedFrameSequences.has(sequence)) {
185
- utils_1.Logger.debug(`Skipping FrameSet from ${this.remoteInfo.address}:${this.remoteInfo.port} - sequence ${sequence} (duplicate/old)`);
186
- return;
187
- }
188
- this.lostFrameSequences.delete(sequence);
189
- if (frameset.sequence < this.lastInputSequence ||
190
- frameset.sequence === this.lastInputSequence) {
191
- utils_1.Logger.debug(`Out of order Frameset from ${this.remoteInfo.address}:${this.remoteInfo.port}`);
192
- return;
193
- }
194
- this.receivedFrameSequences.add(sequence);
195
- if (frameset.sequence - this.lastInputSequence > 1) {
196
- for (let index = this.lastInputSequence + 1; index < frameset.sequence; index++)
197
- this.lostFrameSequences.add(index);
198
- }
199
- this.lastInputSequence = sequence;
200
- for (let i = 0, len = frameset.frames.length; i < len; i++) {
201
- this.handleFrame(frameset.frames[i]);
202
- }
74
+ /** Nack Packet is same as Ack just different id's and we do not care about the ids. */
75
+ onNack(message) {
76
+ this.session.onNack(message);
203
77
  }
204
- handleFrame(frame) {
205
- if (frame.isSplit) {
206
- this.handleSplit(frame);
207
- }
208
- else if (frame.isSequenced) {
209
- this.handleSequenced(frame);
210
- }
211
- else if (frame.isOrdered) {
212
- this.handleOrdered(frame);
213
- }
214
- else {
215
- this.handlePackets(frame.payload);
216
- }
217
- }
218
- handleSplit(frame) {
219
- const splitId = frame.splitId;
220
- let group = this.fragmentsQueue.get(splitId);
221
- if (!group) {
222
- group = { fragments: new Map(), timestamp: Date.now() };
223
- this.fragmentsQueue.set(splitId, group);
224
- }
225
- group.fragments.set(frame.splitFrameIndex, frame);
226
- if (group.fragments.size === frame.splitCount) {
227
- let totalSize = 0;
228
- for (let i = 0; i < frame.splitCount; i++) {
229
- const sframe = group.fragments.get(i);
230
- if (!sframe) {
231
- utils_1.Logger.error(`Missing fragment at index ${i} for splitId=${splitId}`);
232
- return;
233
- }
234
- totalSize += sframe.payload.length;
235
- }
236
- const buffer = Buffer.allocUnsafe(totalSize);
237
- let offset = 0;
238
- for (let i = 0; i < frame.splitCount; i++) {
239
- const sframe = group.fragments.get(i);
240
- if (sframe) {
241
- sframe.payload.copy(buffer, offset);
242
- offset += sframe.payload.length;
243
- }
244
- }
245
- const reassembledFrame = new proto_1.Frame();
246
- reassembledFrame.reliability = frame.reliability;
247
- reassembledFrame.reliableFrameIndex = frame.reliableFrameIndex;
248
- reassembledFrame.sequenceFrameIndex = frame.sequenceFrameIndex;
249
- reassembledFrame.orderedFrameIndex = frame.orderedFrameIndex;
250
- reassembledFrame.orderChannel = frame.orderChannel;
251
- reassembledFrame.payload = buffer;
252
- this.fragmentsQueue.delete(splitId);
253
- this.handleFrame(reassembledFrame);
254
- }
255
- }
256
- handleOrdered(frame) {
257
- const channel = frame.orderChannel;
258
- const expectedIndex = this.inputOrderIndex[channel];
259
- const frameIndex = frame.orderedFrameIndex;
260
- if (frameIndex === expectedIndex) {
261
- this.handlePackets(frame.payload);
262
- this.inputOrderIndex[channel] = frameIndex + 1;
263
- this.inputHighestSequenceIndex[channel] = 0;
264
- const queue = this.inputOrderingQueue.get(channel);
265
- if (queue) {
266
- let nextIndex = frameIndex + 1;
267
- while (queue.has(nextIndex)) {
268
- const queued = queue.get(nextIndex);
269
- if (queued) {
270
- this.handlePackets(queued.frame.payload);
271
- queue.delete(nextIndex);
272
- nextIndex++;
273
- }
274
- }
275
- this.inputOrderIndex[channel] = nextIndex;
276
- }
277
- }
278
- else if (frameIndex > expectedIndex) {
279
- const queue = this.inputOrderingQueue.get(channel);
280
- if (queue) {
281
- queue.set(frameIndex, { frame, timestamp: Date.now() });
282
- }
283
- }
284
- }
285
- handleSequenced(frame) {
286
- const channel = frame.orderChannel;
287
- const newSequence = frame.sequenceFrameIndex;
288
- const currentHighest = this.inputHighestSequenceIndex[channel];
289
- if (newSequence >= currentHighest &&
290
- frame.orderedFrameIndex >= this.inputOrderIndex[channel]) {
291
- this.inputHighestSequenceIndex[channel] = newSequence + 1;
292
- this.handlePackets(frame.payload);
293
- }
294
- }
295
- sendFrame(frame, priority) {
296
- const channel = frame.orderChannel;
297
- if (frame.isSequenced) {
298
- frame.orderedFrameIndex = this.outputOrderIndex[channel];
299
- frame.sequenceFrameIndex = this.outputSequenceIndex[channel]++;
300
- }
301
- else if (frame.isOrdered) {
302
- frame.orderedFrameIndex = this.outputOrderIndex[channel]++;
303
- this.outputSequenceIndex[channel] = 0;
304
- }
305
- const payloadSize = frame.payload.byteLength;
306
- const maxSize = this.mtu - 36;
307
- if (payloadSize > maxSize) {
308
- const splitSize = Math.ceil(payloadSize / maxSize);
309
- this.handleLargePayload(frame, maxSize, splitSize);
310
- return;
311
- }
312
- if (frame.isReliable) {
313
- frame.reliableFrameIndex = this.outputReliableIndex++;
314
- }
315
- this.queueFrame(frame, priority);
316
- }
317
- handleLargePayload(frame, maxSize, splitSize) {
318
- const splitId = this.outputSplitIndex++ % 65536;
319
- for (let index = 0; index < frame.payload.byteLength; index += maxSize) {
320
- const nframe = this.createSplitFrame(frame, index, maxSize, splitId, splitSize);
321
- this.queueFrame(nframe, proto_1.Priority.Immediate);
322
- }
323
- }
324
- createSplitFrame(originalFrame, index, maxSize, splitId, splitSize) {
325
- const nframe = new proto_1.Frame();
326
- nframe.reliableFrameIndex = this.outputReliableIndex++;
327
- nframe.sequenceFrameIndex = originalFrame.sequenceFrameIndex;
328
- nframe.orderedFrameIndex = originalFrame.orderedFrameIndex;
329
- nframe.orderChannel = originalFrame.orderChannel;
330
- nframe.reliability = originalFrame.reliability;
331
- nframe.payload = originalFrame.payload.subarray(index, index + maxSize);
332
- nframe.splitFrameIndex = index / maxSize;
333
- nframe.splitId = splitId;
334
- nframe.splitCount = splitSize;
335
- return nframe;
78
+ sendFrame(frame, priority = shared_1.Priority.High) {
79
+ this.session.sendFrame(frame, priority);
336
80
  }
337
- queueFrame(frame, priority) {
338
- const frameLength = frame.getByteLength();
339
- utils_1.Logger.debug(`[Connection] Queueing frame (length=${frameLength}). Queue count before push: ${this.outputFrameQueue.length}.`);
340
- this.outputFrameQueue.push(frame);
341
- this.outputFramesByteLength += frameLength;
342
- if (priority === proto_1.Priority.Immediate) {
343
- utils_1.Logger.debug("[Connection] Immediate frame queued. Flushing output queue.");
344
- this.sendQueue(this.outputFrameQueue.length);
345
- }
81
+ frameAndSend(payload, priority = shared_1.Priority.High) {
82
+ this.session.frameAndSend(payload, priority);
346
83
  }
347
- sendQueue(amount) {
348
- if (this.outputFrameQueue.length === 0)
349
- return;
350
- utils_1.Logger.debug(`[Connection] Flushing output queue: sending ${amount} frame(s), total bytes = ${this.outputFramesByteLength}.`);
351
- const frameset = new proto_1.Frameset();
352
- frameset.sequence = this.outputSequence++;
353
- const framesToSend = this.outputFrameQueue.splice(0, amount);
354
- let sentLength = 0;
355
- for (const frame of framesToSend) {
356
- sentLength += frame.getByteLength();
357
- }
358
- this.outputFramesByteLength -= sentLength;
359
- frameset.frames = framesToSend;
360
- this.outputBackup.set(frameset.sequence, frameset.frames);
361
- const serialized = frameset.serialize();
362
- utils_1.Logger.debug(`[Connection] Sending frameset sequence ${frameset.sequence}, serialized length = ${serialized.byteLength}.`);
363
- this.send(serialized);
364
- }
365
- frameAndSend(payload, priority) {
366
- const frame = new proto_1.Frame();
367
- frame.payload =
368
- payload instanceof binarystream_1.BinaryStream ? payload.getBuffer() : payload;
369
- frame.reliability = proto_1.Reliability.ReliableOrdered;
370
- frame.orderChannel = 0;
371
- this.sendFrame(frame, priority);
372
- }
373
- send(message) {
374
- this.server.send(message, this.remoteInfo);
375
- }
376
- disconnect(timeout = true) {
377
- const disconnect = new disconnect_1.default();
378
- this.frameAndSend(disconnect.serialize(), proto_1.Priority.Immediate);
379
- this.status = proto_1.Status.Disconnected;
380
- if (timeout) {
381
- setTimeout(() => {
382
- this.server.deleteConnection(`${this.remoteInfo.address}:${this.remoteInfo.port}`);
383
- }, 1000);
384
- }
385
- }
386
- getConnectionTime(type = "ms") {
387
- const time = this.server.connectionTimes.get(`${this.remoteInfo.address}:${this.remoteInfo.port}`) ?? 0;
388
- if (type === "ms")
389
- return time;
390
- if (type === "s")
391
- return time / 1000;
392
- if (type === "min")
393
- return time / 60000;
394
- return time;
395
- }
396
- getAddress() {
397
- return proto_1.Address.fromIdentifier(this.remoteInfo);
84
+ send(data) {
85
+ this.server.send(data, this.rinfo.address, this.rinfo.port);
398
86
  }
399
87
  }
400
88
  exports.Connection = Connection;
@@ -1,5 +1,4 @@
1
- export * from "./server";
2
- export * from "./server-events";
3
1
  export * from "./connection";
4
- export * from "./server-options";
2
+ export * from "./server";
3
+ export * from "./types";
5
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
@@ -14,7 +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
- __exportStar(require("./server"), exports);
18
- __exportStar(require("./server-events"), exports);
19
17
  __exportStar(require("./connection"), exports);
20
- __exportStar(require("./server-options"), exports);
18
+ __exportStar(require("./server"), exports);
19
+ __exportStar(require("./types"), exports);
@@ -1,24 +1,17 @@
1
- import Emitter from "@serenityjs/emitter";
2
- import type { ServerEvents } from "./server-events";
3
- import { type ServerOptions } from "./server-options";
4
- import { type RemoteInfo } from "node:dgram";
5
- declare class Server extends Emitter<ServerEvents> {
6
- options: ServerOptions;
7
- connectionTimes: Map<string, number>;
1
+ import { EventEmitter } from "../shared";
2
+ import { type Advertisement, type RaknetServerEvents, type RaknetServerOptions } from "./types";
3
+ export declare class Server extends EventEmitter<RaknetServerEvents> {
8
4
  private socket;
5
+ readonly options: RaknetServerOptions;
6
+ advertisement: Advertisement;
9
7
  private connections;
10
- private timer;
11
8
  private tickCount;
12
- private blockedConnections;
13
- private packetsPerSecond;
14
- private readonly validFlagsMask;
15
- constructor(options: Partial<ServerOptions>);
16
- start(): Promise<void>;
9
+ private tickInterval;
10
+ constructor(options?: Partial<RaknetServerOptions>);
17
11
  tick(): void;
18
- send(message: Buffer, remote: RemoteInfo): void;
19
- handle(message: Buffer, remote: RemoteInfo): Promise<void>;
20
- deleteConnection(address: string): void;
21
- close(): void;
12
+ listen(): void;
13
+ private onDisconnect;
14
+ private onMessage;
15
+ send(buffer: Buffer, address: string, port: number): void;
22
16
  }
23
- export { Server };
24
17
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,qBAAqB,CAAC;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAgB,KAAK,UAAU,EAAe,MAAM,YAAY,CAAC;AAmBxE,cAAM,MAAO,SAAQ,OAAO,CAAC,YAAY,CAAC;IAClC,OAAO,EAAE,aAAa,CAAC;IACvB,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAa;IACxD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,WAAW,CAAsC;IACzD,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAAO,CAAC,SAAS,CAAK;IAEtB,OAAO,CAAC,kBAAkB,CAAkC;IAC5D,OAAO,CAAC,gBAAgB,CAAkC;IAE1D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAe;gBAElC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC;IAO9B,KAAK;IAUX,IAAI;IAsBJ,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;IAIlC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;IA2HhD,gBAAgB,CAAC,OAAO,EAAE,MAAM;IAShC,KAAK;CAUZ;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,YAAY,EAQZ,MAAM,WAAW,CAAC;AA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