@netifyjs/protocol 0.0.0-stage → 1.0.0-alpha.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.
Files changed (1101) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +38 -2
  3. package/package.json +56 -4
  4. package/src/codec/index.ts +256 -0
  5. package/src/dispatch/dispatcher/index.ts +200 -0
  6. package/src/dispatch/event/index.ts +49 -0
  7. package/src/dispatch/index.ts +11 -0
  8. package/src/dispatch/route/index.ts +141 -0
  9. package/src/dispatch/session/index.ts +60 -0
  10. package/src/format/index.ts +72 -0
  11. package/src/index.ts +66 -0
  12. package/src/names/index.ts +73 -0
  13. package/src/photon/application/index.ts +76 -0
  14. package/src/photon/authentication/admission/index.ts +47 -0
  15. package/src/photon/authentication/authenticator/index.ts +106 -0
  16. package/src/photon/authentication/failure/index.ts +15 -0
  17. package/src/photon/authentication/gate/index.ts +221 -0
  18. package/src/photon/authentication/http/index.ts +337 -0
  19. package/src/photon/authentication/index.ts +18 -0
  20. package/src/photon/authentication/keys/index.ts +67 -0
  21. package/src/photon/authentication/provider/index.ts +48 -0
  22. package/src/photon/authentication/queue/index.ts +284 -0
  23. package/src/photon/authentication/result/index.ts +191 -0
  24. package/src/photon/balancing/catalogue/events/index.ts +93 -0
  25. package/src/photon/balancing/catalogue/index.ts +148 -0
  26. package/src/photon/balancing/catalogue/requests/index.ts +104 -0
  27. package/src/photon/balancing/catalogue/responses/index.ts +106 -0
  28. package/src/photon/balancing/code/actor/index.ts +24 -0
  29. package/src/photon/balancing/code/authentication/index.ts +101 -0
  30. package/src/photon/balancing/code/caching/index.ts +69 -0
  31. package/src/photon/balancing/code/cause/index.ts +115 -0
  32. package/src/photon/balancing/code/error/index.ts +280 -0
  33. package/src/photon/balancing/code/event/index.ts +104 -0
  34. package/src/photon/balancing/code/friends/index.ts +35 -0
  35. package/src/photon/balancing/code/game/index.ts +69 -0
  36. package/src/photon/balancing/code/index.ts +52 -0
  37. package/src/photon/balancing/code/join/index.ts +29 -0
  38. package/src/photon/balancing/code/lobby/index.ts +29 -0
  39. package/src/photon/balancing/code/matchmaking/index.ts +25 -0
  40. package/src/photon/balancing/code/message/index.ts +507 -0
  41. package/src/photon/balancing/code/operation/index.ts +124 -0
  42. package/src/photon/balancing/code/parameter/index.ts +414 -0
  43. package/src/photon/balancing/code/ping/index.ts +29 -0
  44. package/src/photon/balancing/code/port/index.ts +89 -0
  45. package/src/photon/balancing/code/property/index.ts +30 -0
  46. package/src/photon/balancing/code/receiver/index.ts +24 -0
  47. package/src/photon/balancing/code/room/index.ts +45 -0
  48. package/src/photon/balancing/code/state/index.ts +109 -0
  49. package/src/photon/balancing/code/status/index.ts +89 -0
  50. package/src/photon/balancing/code/web/index.ts +29 -0
  51. package/src/photon/balancing/codec/index.ts +294 -0
  52. package/src/photon/balancing/dotnet/index.ts +55 -0
  53. package/src/photon/balancing/entity/authentication/index.ts +51 -0
  54. package/src/photon/balancing/entity/credentials/index.ts +77 -0
  55. package/src/photon/balancing/entity/entry/index.ts +77 -0
  56. package/src/photon/balancing/entity/grant/index.ts +192 -0
  57. package/src/photon/balancing/entity/index.ts +7 -0
  58. package/src/photon/balancing/entity/lobby/index.ts +35 -0
  59. package/src/photon/balancing/entity/options/index.ts +174 -0
  60. package/src/photon/balancing/entity/stat/index.ts +59 -0
  61. package/src/photon/balancing/format/authenticate/index.ts +2 -0
  62. package/src/photon/balancing/format/authenticate/request/index.ts +82 -0
  63. package/src/photon/balancing/format/authenticate/response/index.ts +61 -0
  64. package/src/photon/balancing/format/contract/index.ts +51 -0
  65. package/src/photon/balancing/format/event/auth/index.ts +49 -0
  66. package/src/photon/balancing/format/event/azure/index.ts +56 -0
  67. package/src/photon/balancing/format/event/custom/index.ts +55 -0
  68. package/src/photon/balancing/format/event/disconnect/index.ts +54 -0
  69. package/src/photon/balancing/format/event/error/index.ts +51 -0
  70. package/src/photon/balancing/format/event/index.ts +16 -0
  71. package/src/photon/balancing/format/event/join/index.ts +58 -0
  72. package/src/photon/balancing/format/event/leave/index.ts +60 -0
  73. package/src/photon/balancing/format/event/list/index.ts +53 -0
  74. package/src/photon/balancing/format/event/match/index.ts +55 -0
  75. package/src/photon/balancing/format/event/offline/index.ts +52 -0
  76. package/src/photon/balancing/format/event/properties/index.ts +60 -0
  77. package/src/photon/balancing/format/event/purged/index.ts +44 -0
  78. package/src/photon/balancing/format/event/queue/index.ts +51 -0
  79. package/src/photon/balancing/format/event/slice/index.ts +57 -0
  80. package/src/photon/balancing/format/event/stats/app/index.ts +60 -0
  81. package/src/photon/balancing/format/event/stats/index.ts +2 -0
  82. package/src/photon/balancing/format/event/stats/lobby/index.ts +54 -0
  83. package/src/photon/balancing/format/event/update/index.ts +53 -0
  84. package/src/photon/balancing/format/friends/index.ts +2 -0
  85. package/src/photon/balancing/format/friends/request/index.ts +56 -0
  86. package/src/photon/balancing/format/friends/response/index.ts +64 -0
  87. package/src/photon/balancing/format/game/create/index.ts +2 -0
  88. package/src/photon/balancing/format/game/create/request/index.ts +79 -0
  89. package/src/photon/balancing/format/game/create/response/index.ts +87 -0
  90. package/src/photon/balancing/format/game/debug/index.ts +2 -0
  91. package/src/photon/balancing/format/game/debug/request/index.ts +55 -0
  92. package/src/photon/balancing/format/game/debug/response/index.ts +60 -0
  93. package/src/photon/balancing/format/game/index.ts +17 -0
  94. package/src/photon/balancing/format/game/join/index.ts +2 -0
  95. package/src/photon/balancing/format/game/join/request/index.ts +93 -0
  96. package/src/photon/balancing/format/game/join/response/index.ts +87 -0
  97. package/src/photon/balancing/format/game/list/index.ts +2 -0
  98. package/src/photon/balancing/format/game/list/request/index.ts +59 -0
  99. package/src/photon/balancing/format/game/list/response/index.ts +57 -0
  100. package/src/photon/balancing/format/game/random/index.ts +2 -0
  101. package/src/photon/balancing/format/game/random/request/index.ts +87 -0
  102. package/src/photon/balancing/format/game/random/response/index.ts +66 -0
  103. package/src/photon/balancing/format/groups/index.ts +2 -0
  104. package/src/photon/balancing/format/groups/request/index.ts +54 -0
  105. package/src/photon/balancing/format/groups/response/index.ts +52 -0
  106. package/src/photon/balancing/format/index.ts +88 -0
  107. package/src/photon/balancing/format/leave/index.ts +2 -0
  108. package/src/photon/balancing/format/leave/request/index.ts +54 -0
  109. package/src/photon/balancing/format/leave/response/index.ts +49 -0
  110. package/src/photon/balancing/format/lobby/index.ts +12 -0
  111. package/src/photon/balancing/format/lobby/join/index.ts +2 -0
  112. package/src/photon/balancing/format/lobby/join/request/index.ts +63 -0
  113. package/src/photon/balancing/format/lobby/join/response/index.ts +45 -0
  114. package/src/photon/balancing/format/lobby/leave/index.ts +2 -0
  115. package/src/photon/balancing/format/lobby/leave/request/index.ts +43 -0
  116. package/src/photon/balancing/format/lobby/leave/response/index.ts +45 -0
  117. package/src/photon/balancing/format/lobby/stats/index.ts +2 -0
  118. package/src/photon/balancing/format/lobby/stats/request/index.ts +54 -0
  119. package/src/photon/balancing/format/lobby/stats/response/index.ts +62 -0
  120. package/src/photon/balancing/format/once/index.ts +2 -0
  121. package/src/photon/balancing/format/once/request/index.ts +72 -0
  122. package/src/photon/balancing/format/once/response/index.ts +65 -0
  123. package/src/photon/balancing/format/ping/index.ts +2 -0
  124. package/src/photon/balancing/format/ping/request/index.ts +43 -0
  125. package/src/photon/balancing/format/ping/response/index.ts +49 -0
  126. package/src/photon/balancing/format/properties/get/index.ts +2 -0
  127. package/src/photon/balancing/format/properties/get/request/index.ts +58 -0
  128. package/src/photon/balancing/format/properties/get/response/index.ts +62 -0
  129. package/src/photon/balancing/format/properties/index.ts +8 -0
  130. package/src/photon/balancing/format/properties/set/index.ts +2 -0
  131. package/src/photon/balancing/format/properties/set/request/index.ts +66 -0
  132. package/src/photon/balancing/format/properties/set/response/index.ts +53 -0
  133. package/src/photon/balancing/format/raise/index.ts +2 -0
  134. package/src/photon/balancing/format/raise/request/index.ts +93 -0
  135. package/src/photon/balancing/format/raise/response/index.ts +49 -0
  136. package/src/photon/balancing/format/reader/index.ts +362 -0
  137. package/src/photon/balancing/format/regions/index.ts +2 -0
  138. package/src/photon/balancing/format/regions/request/index.ts +49 -0
  139. package/src/photon/balancing/format/regions/response/index.ts +62 -0
  140. package/src/photon/balancing/format/rpc/index.ts +2 -0
  141. package/src/photon/balancing/format/rpc/request/index.ts +56 -0
  142. package/src/photon/balancing/format/rpc/response/index.ts +62 -0
  143. package/src/photon/balancing/format/settings/index.ts +2 -0
  144. package/src/photon/balancing/format/settings/request/index.ts +52 -0
  145. package/src/photon/balancing/format/settings/response/index.ts +49 -0
  146. package/src/photon/balancing/format/shared/credentials/index.ts +84 -0
  147. package/src/photon/balancing/format/shared/entry/index.ts +43 -0
  148. package/src/photon/balancing/format/shared/grant/index.ts +96 -0
  149. package/src/photon/balancing/format/shared/index.ts +6 -0
  150. package/src/photon/balancing/format/shared/lobby/index.ts +36 -0
  151. package/src/photon/balancing/format/shared/options/index.ts +68 -0
  152. package/src/photon/balancing/format/shared/stats/index.ts +55 -0
  153. package/src/photon/balancing/format/writer/index.ts +187 -0
  154. package/src/photon/balancing/index.ts +239 -0
  155. package/src/photon/balancing/packet/adapter/index.ts +39 -0
  156. package/src/photon/balancing/packet/authenticate/index.ts +2 -0
  157. package/src/photon/balancing/packet/authenticate/request/index.ts +105 -0
  158. package/src/photon/balancing/packet/authenticate/response/index.ts +49 -0
  159. package/src/photon/balancing/packet/event/auth/index.ts +30 -0
  160. package/src/photon/balancing/packet/event/azure/index.ts +54 -0
  161. package/src/photon/balancing/packet/event/custom/index.ts +50 -0
  162. package/src/photon/balancing/packet/event/disconnect/index.ts +30 -0
  163. package/src/photon/balancing/packet/event/error/index.ts +29 -0
  164. package/src/photon/balancing/packet/event/index.ts +16 -0
  165. package/src/photon/balancing/packet/event/join/index.ts +54 -0
  166. package/src/photon/balancing/packet/event/leave/index.ts +63 -0
  167. package/src/photon/balancing/packet/event/list/index.ts +30 -0
  168. package/src/photon/balancing/packet/event/match/index.ts +37 -0
  169. package/src/photon/balancing/packet/event/offline/index.ts +29 -0
  170. package/src/photon/balancing/packet/event/properties/index.ts +58 -0
  171. package/src/photon/balancing/packet/event/purged/index.ts +21 -0
  172. package/src/photon/balancing/packet/event/queue/index.ts +29 -0
  173. package/src/photon/balancing/packet/event/slice/index.ts +40 -0
  174. package/src/photon/balancing/packet/event/stats/app/index.ts +56 -0
  175. package/src/photon/balancing/packet/event/stats/index.ts +2 -0
  176. package/src/photon/balancing/packet/event/stats/lobby/index.ts +30 -0
  177. package/src/photon/balancing/packet/event/update/index.ts +30 -0
  178. package/src/photon/balancing/packet/friends/index.ts +2 -0
  179. package/src/photon/balancing/packet/friends/request/index.ts +40 -0
  180. package/src/photon/balancing/packet/friends/response/index.ts +60 -0
  181. package/src/photon/balancing/packet/game/create/index.ts +2 -0
  182. package/src/photon/balancing/packet/game/create/request/index.ts +160 -0
  183. package/src/photon/balancing/packet/game/create/response/index.ts +122 -0
  184. package/src/photon/balancing/packet/game/debug/index.ts +2 -0
  185. package/src/photon/balancing/packet/game/debug/request/index.ts +40 -0
  186. package/src/photon/balancing/packet/game/debug/response/index.ts +70 -0
  187. package/src/photon/balancing/packet/game/index.ts +8 -0
  188. package/src/photon/balancing/packet/game/join/index.ts +2 -0
  189. package/src/photon/balancing/packet/game/join/request/index.ts +218 -0
  190. package/src/photon/balancing/packet/game/join/response/index.ts +122 -0
  191. package/src/photon/balancing/packet/game/list/index.ts +2 -0
  192. package/src/photon/balancing/packet/game/list/request/index.ts +41 -0
  193. package/src/photon/balancing/packet/game/list/response/index.ts +49 -0
  194. package/src/photon/balancing/packet/game/random/index.ts +2 -0
  195. package/src/photon/balancing/packet/game/random/request/index.ts +172 -0
  196. package/src/photon/balancing/packet/game/random/response/index.ts +95 -0
  197. package/src/photon/balancing/packet/groups/index.ts +2 -0
  198. package/src/photon/balancing/packet/groups/request/index.ts +40 -0
  199. package/src/photon/balancing/packet/groups/response/index.ts +35 -0
  200. package/src/photon/balancing/packet/index.ts +69 -0
  201. package/src/photon/balancing/packet/leave/index.ts +2 -0
  202. package/src/photon/balancing/packet/leave/request/index.ts +40 -0
  203. package/src/photon/balancing/packet/leave/response/index.ts +35 -0
  204. package/src/photon/balancing/packet/lobby/index.ts +3 -0
  205. package/src/photon/balancing/packet/lobby/join/index.ts +2 -0
  206. package/src/photon/balancing/packet/lobby/join/request/index.ts +55 -0
  207. package/src/photon/balancing/packet/lobby/join/response/index.ts +35 -0
  208. package/src/photon/balancing/packet/lobby/leave/index.ts +2 -0
  209. package/src/photon/balancing/packet/lobby/leave/request/index.ts +21 -0
  210. package/src/photon/balancing/packet/lobby/leave/response/index.ts +43 -0
  211. package/src/photon/balancing/packet/lobby/stats/index.ts +2 -0
  212. package/src/photon/balancing/packet/lobby/stats/request/index.ts +43 -0
  213. package/src/photon/balancing/packet/lobby/stats/response/index.ts +49 -0
  214. package/src/photon/balancing/packet/once/index.ts +2 -0
  215. package/src/photon/balancing/packet/once/request/index.ts +70 -0
  216. package/src/photon/balancing/packet/once/response/index.ts +49 -0
  217. package/src/photon/balancing/packet/ping/index.ts +2 -0
  218. package/src/photon/balancing/packet/ping/request/index.ts +21 -0
  219. package/src/photon/balancing/packet/ping/response/index.ts +35 -0
  220. package/src/photon/balancing/packet/properties/get/index.ts +2 -0
  221. package/src/photon/balancing/packet/properties/get/request/index.ts +69 -0
  222. package/src/photon/balancing/packet/properties/get/response/index.ts +66 -0
  223. package/src/photon/balancing/packet/properties/index.ts +2 -0
  224. package/src/photon/balancing/packet/properties/set/index.ts +2 -0
  225. package/src/photon/balancing/packet/properties/set/request/index.ts +122 -0
  226. package/src/photon/balancing/packet/properties/set/response/index.ts +35 -0
  227. package/src/photon/balancing/packet/raise/index.ts +2 -0
  228. package/src/photon/balancing/packet/raise/request/index.ts +219 -0
  229. package/src/photon/balancing/packet/raise/response/index.ts +35 -0
  230. package/src/photon/balancing/packet/regions/index.ts +2 -0
  231. package/src/photon/balancing/packet/regions/request/index.ts +29 -0
  232. package/src/photon/balancing/packet/regions/response/index.ts +60 -0
  233. package/src/photon/balancing/packet/reply/index.ts +59 -0
  234. package/src/photon/balancing/packet/rpc/index.ts +2 -0
  235. package/src/photon/balancing/packet/rpc/request/index.ts +54 -0
  236. package/src/photon/balancing/packet/rpc/response/index.ts +88 -0
  237. package/src/photon/balancing/packet/settings/index.ts +2 -0
  238. package/src/photon/balancing/packet/settings/request/index.ts +29 -0
  239. package/src/photon/balancing/packet/settings/response/index.ts +35 -0
  240. package/src/photon/balancing/packet/unknown/index.ts +71 -0
  241. package/src/photon/balancing/pun/code/index.ts +376 -0
  242. package/src/photon/balancing/pun/destroy/index.ts +2 -0
  243. package/src/photon/balancing/pun/destroy/object/index.ts +48 -0
  244. package/src/photon/balancing/pun/destroy/player/index.ts +53 -0
  245. package/src/photon/balancing/pun/events/index.ts +283 -0
  246. package/src/photon/balancing/pun/filter/index.ts +45 -0
  247. package/src/photon/balancing/pun/index.ts +34 -0
  248. package/src/photon/balancing/pun/instantiation/index.ts +213 -0
  249. package/src/photon/balancing/pun/keys/index.ts +78 -0
  250. package/src/photon/balancing/pun/master/index.ts +48 -0
  251. package/src/photon/balancing/pun/ownership/index.ts +4 -0
  252. package/src/photon/balancing/pun/ownership/request/index.ts +55 -0
  253. package/src/photon/balancing/pun/ownership/transfer/index.ts +55 -0
  254. package/src/photon/balancing/pun/ownership/update/index.ts +57 -0
  255. package/src/photon/balancing/pun/rpc/index.ts +180 -0
  256. package/src/photon/balancing/pun/serialize/batch/index.ts +143 -0
  257. package/src/photon/balancing/pun/serialize/index.ts +2 -0
  258. package/src/photon/balancing/pun/serialize/view/index.ts +96 -0
  259. package/src/photon/balancing/pun/view/index.ts +41 -0
  260. package/src/photon/balancing/role/index.ts +24 -0
  261. package/src/photon/balancing/travel/index.ts +103 -0
  262. package/src/photon/binary/adapter/index.ts +619 -0
  263. package/src/photon/binary/custom/index.ts +148 -0
  264. package/src/photon/binary/dictionary/index.ts +110 -0
  265. package/src/photon/binary/disconnect/index.ts +51 -0
  266. package/src/photon/binary/event/index.ts +48 -0
  267. package/src/photon/binary/factory/index.ts +23 -0
  268. package/src/photon/binary/hashtable/index.ts +83 -0
  269. package/src/photon/binary/index.ts +25 -0
  270. package/src/photon/binary/kind/index.ts +104 -0
  271. package/src/photon/binary/parameters/index.ts +119 -0
  272. package/src/photon/binary/protocol/index.ts +122 -0
  273. package/src/photon/binary/request/index.ts +38 -0
  274. package/src/photon/binary/response/index.ts +92 -0
  275. package/src/photon/binary/shape/index.ts +260 -0
  276. package/src/photon/binary/v16/index.ts +834 -0
  277. package/src/photon/binary/v18/index.ts +1428 -0
  278. package/src/photon/binary/value/index.ts +414 -0
  279. package/src/photon/client/bot/index.ts +662 -0
  280. package/src/photon/client/connection/index.ts +420 -0
  281. package/src/photon/client/endpoint/index.ts +87 -0
  282. package/src/photon/client/failure/index.ts +37 -0
  283. package/src/photon/client/index.ts +5 -0
  284. package/src/photon/client/options/index.ts +78 -0
  285. package/src/photon/cluster/back/index.ts +186 -0
  286. package/src/photon/cluster/carriage/index.ts +334 -0
  287. package/src/photon/cluster/directory/index.ts +103 -0
  288. package/src/photon/cluster/dresser/index.ts +83 -0
  289. package/src/photon/cluster/feed/index.ts +267 -0
  290. package/src/photon/cluster/front/index.ts +205 -0
  291. package/src/photon/cluster/grid/index.ts +429 -0
  292. package/src/photon/cluster/hub/index.ts +434 -0
  293. package/src/photon/cluster/index.ts +18 -0
  294. package/src/photon/cluster/mover/index.ts +173 -0
  295. package/src/photon/cluster/parcel/index.ts +158 -0
  296. package/src/photon/cluster/pooled/index.ts +66 -0
  297. package/src/photon/cluster/press/index.ts +96 -0
  298. package/src/photon/cluster/route/game/index.ts +95 -0
  299. package/src/photon/cluster/route/index.ts +3 -0
  300. package/src/photon/cluster/route/master/index.ts +235 -0
  301. package/src/photon/cluster/route/name/index.ts +176 -0
  302. package/src/photon/cluster/seat/game/index.ts +113 -0
  303. package/src/photon/cluster/seat/index.ts +2 -0
  304. package/src/photon/cluster/seat/master/index.ts +97 -0
  305. package/src/photon/cluster/seed/index.ts +190 -0
  306. package/src/photon/cluster/sessions/index.ts +136 -0
  307. package/src/photon/cluster/spread/index.ts +236 -0
  308. package/src/photon/cluster/value/index.ts +46 -0
  309. package/src/photon/crypto/code/index.ts +149 -0
  310. package/src/photon/crypto/connection/index.ts +127 -0
  311. package/src/photon/crypto/data/index.ts +214 -0
  312. package/src/photon/crypto/datagram/index.ts +119 -0
  313. package/src/photon/crypto/error/index.ts +29 -0
  314. package/src/photon/crypto/exchange/index.ts +187 -0
  315. package/src/photon/crypto/index.ts +31 -0
  316. package/src/photon/crypto/init/binary/index.ts +249 -0
  317. package/src/photon/crypto/init/http/index.ts +222 -0
  318. package/src/photon/crypto/init/index.ts +6 -0
  319. package/src/photon/crypto/init/query/index.ts +85 -0
  320. package/src/photon/crypto/init/socket/index.ts +82 -0
  321. package/src/photon/crypto/method/index.ts +20 -0
  322. package/src/photon/crypto/mode/index.ts +35 -0
  323. package/src/photon/crypto/once/gate/index.ts +60 -0
  324. package/src/photon/crypto/once/index.ts +4 -0
  325. package/src/photon/crypto/once/reply/index.ts +96 -0
  326. package/src/photon/crypto/once/request/index.ts +14 -0
  327. package/src/photon/crypto/payload/index.ts +189 -0
  328. package/src/photon/crypto/protocol/index.ts +30 -0
  329. package/src/photon/crypto/refusal/index.ts +118 -0
  330. package/src/photon/crypto/sequence/index.ts +97 -0
  331. package/src/photon/crypto/token/authority/index.ts +158 -0
  332. package/src/photon/crypto/token/codec/index.ts +18 -0
  333. package/src/photon/crypto/token/index.ts +5 -0
  334. package/src/photon/crypto/token/record/index.ts +116 -0
  335. package/src/photon/crypto/token/sealed/index.ts +285 -0
  336. package/src/photon/crypto/token/verdict/index.ts +43 -0
  337. package/src/photon/enet/client/index.ts +204 -0
  338. package/src/photon/enet/closure/index.ts +90 -0
  339. package/src/photon/enet/command/index.ts +301 -0
  340. package/src/photon/enet/datagram/index.ts +289 -0
  341. package/src/photon/enet/flight/index.ts +93 -0
  342. package/src/photon/enet/gateway/index.ts +311 -0
  343. package/src/photon/enet/handler/index.ts +65 -0
  344. package/src/photon/enet/index.ts +21 -0
  345. package/src/photon/enet/lane/index.ts +403 -0
  346. package/src/photon/enet/link/index.ts +200 -0
  347. package/src/photon/enet/options/index.ts +283 -0
  348. package/src/photon/enet/peer/index.ts +1527 -0
  349. package/src/photon/enet/server/index.ts +107 -0
  350. package/src/photon/enet/transport/index.ts +83 -0
  351. package/src/photon/enet/window/index.ts +48 -0
  352. package/src/photon/envelope/index.ts +83 -0
  353. package/src/photon/family/index.ts +41 -0
  354. package/src/photon/frame/index.ts +88 -0
  355. package/src/photon/game/actor/index.ts +117 -0
  356. package/src/photon/game/authenticator/index.ts +139 -0
  357. package/src/photon/game/bag/index.ts +169 -0
  358. package/src/photon/game/cache/index.ts +456 -0
  359. package/src/photon/game/clock/index.ts +137 -0
  360. package/src/photon/game/compare/index.ts +162 -0
  361. package/src/photon/game/entry/index.ts +334 -0
  362. package/src/photon/game/fault/index.ts +77 -0
  363. package/src/photon/game/gate/index.ts +177 -0
  364. package/src/photon/game/groups/index.ts +115 -0
  365. package/src/photon/game/guard/index.ts +54 -0
  366. package/src/photon/game/handler/index.ts +458 -0
  367. package/src/photon/game/hooked/index.ts +873 -0
  368. package/src/photon/game/index.ts +41 -0
  369. package/src/photon/game/peer/index.ts +186 -0
  370. package/src/photon/game/report/index.ts +120 -0
  371. package/src/photon/game/room/index.ts +2271 -0
  372. package/src/photon/game/rooms/index.ts +149 -0
  373. package/src/photon/game/server/index.ts +503 -0
  374. package/src/photon/game/settings/index.ts +341 -0
  375. package/src/photon/game/shared/index.ts +54 -0
  376. package/src/photon/game/snapshot/index.ts +124 -0
  377. package/src/photon/game/stage/index.ts +74 -0
  378. package/src/photon/game/touch/index.ts +43 -0
  379. package/src/photon/game/wellknown/index.ts +353 -0
  380. package/src/photon/hooks/index.ts +9 -0
  381. package/src/photon/hooks/reason/index.ts +129 -0
  382. package/src/photon/hooks/reply/index.ts +239 -0
  383. package/src/photon/hooks/request/index.ts +383 -0
  384. package/src/photon/hooks/sender/index.ts +268 -0
  385. package/src/photon/hooks/settings/index.ts +383 -0
  386. package/src/photon/hooks/state/index.ts +545 -0
  387. package/src/photon/index.ts +31 -0
  388. package/src/photon/master/application/index.ts +446 -0
  389. package/src/photon/master/balancer/index.ts +170 -0
  390. package/src/photon/master/context/index.ts +127 -0
  391. package/src/photon/master/equality/index.ts +104 -0
  392. package/src/photon/master/fault/index.ts +86 -0
  393. package/src/photon/master/game/index.ts +847 -0
  394. package/src/photon/master/gate/index.ts +243 -0
  395. package/src/photon/master/handler/index.ts +1103 -0
  396. package/src/photon/master/index.ts +20 -0
  397. package/src/photon/master/list/channel/index.ts +417 -0
  398. package/src/photon/master/list/games/index.ts +419 -0
  399. package/src/photon/master/list/index.ts +6 -0
  400. package/src/photon/master/list/limited/index.ts +103 -0
  401. package/src/photon/master/list/plain/index.ts +47 -0
  402. package/src/photon/master/list/silent/index.ts +45 -0
  403. package/src/photon/master/list/sql/index.ts +280 -0
  404. package/src/photon/master/lobbies/index.ts +85 -0
  405. package/src/photon/master/lobby/index.ts +572 -0
  406. package/src/photon/master/peer/index.ts +168 -0
  407. package/src/photon/master/players/index.ts +177 -0
  408. package/src/photon/master/redirect/index.ts +90 -0
  409. package/src/photon/master/rpc/index.ts +2 -0
  410. package/src/photon/master/server/index.ts +212 -0
  411. package/src/photon/master/settings/index.ts +515 -0
  412. package/src/photon/master/sql/error/index.ts +92 -0
  413. package/src/photon/master/sql/host/index.ts +153 -0
  414. package/src/photon/master/sql/index.ts +9 -0
  415. package/src/photon/master/sql/relay/index.ts +141 -0
  416. package/src/photon/master/sql/remote/index.ts +257 -0
  417. package/src/photon/master/sql/store/index.ts +37 -0
  418. package/src/photon/master/sql/table/index.ts +219 -0
  419. package/src/photon/master/sql/value/index.ts +93 -0
  420. package/src/photon/master/sql/watch/index.ts +80 -0
  421. package/src/photon/master/sql/wire/index.ts +98 -0
  422. package/src/photon/master/stats/app/index.ts +122 -0
  423. package/src/photon/master/stats/index.ts +2 -0
  424. package/src/photon/master/stats/lobby/index.ts +180 -0
  425. package/src/photon/master/wellknown/index.ts +220 -0
  426. package/src/photon/message/binary/index.ts +289 -0
  427. package/src/photon/message/client/index.ts +110 -0
  428. package/src/photon/message/dialect/index.ts +61 -0
  429. package/src/photon/message/format/index.ts +21 -0
  430. package/src/photon/message/handler/index.ts +176 -0
  431. package/src/photon/message/index.ts +23 -0
  432. package/src/photon/message/init/classic/index.ts +204 -0
  433. package/src/photon/message/init/form/index.ts +29 -0
  434. package/src/photon/message/init/index.ts +6 -0
  435. package/src/photon/message/init/request/index.ts +388 -0
  436. package/src/photon/message/internal/index.ts +203 -0
  437. package/src/photon/message/json/format/index.ts +129 -0
  438. package/src/photon/message/json/index.ts +3 -0
  439. package/src/photon/message/json/keys/index.ts +44 -0
  440. package/src/photon/message/json/values/index.ts +323 -0
  441. package/src/photon/message/once/index.ts +69 -0
  442. package/src/photon/message/peer/index.ts +276 -0
  443. package/src/photon/message/pipeline/index.ts +350 -0
  444. package/src/photon/message/server/index.ts +208 -0
  445. package/src/photon/message/type/index.ts +59 -0
  446. package/src/photon/message/watch/index.ts +30 -0
  447. package/src/photon/message/wire/index.ts +215 -0
  448. package/src/photon/name/config/index.ts +133 -0
  449. package/src/photon/name/handler/index.ts +816 -0
  450. package/src/photon/name/index.ts +12 -0
  451. package/src/photon/name/node/index.ts +181 -0
  452. package/src/photon/name/peer/index.ts +23 -0
  453. package/src/photon/name/regions/index.ts +110 -0
  454. package/src/photon/name/server/index.ts +207 -0
  455. package/src/photon/registry/index.ts +244 -0
  456. package/src/photon/rpc/fault/index.ts +60 -0
  457. package/src/photon/rpc/http/index.ts +508 -0
  458. package/src/photon/rpc/index.ts +10 -0
  459. package/src/photon/rpc/meter/index.ts +47 -0
  460. package/src/photon/rpc/relay/index.ts +112 -0
  461. package/src/photon/rpc/service/index.ts +67 -0
  462. package/src/photon/seal/index.ts +17 -0
  463. package/src/photon/server/config/index.ts +241 -0
  464. package/src/photon/server/gatekeeper/index.ts +99 -0
  465. package/src/photon/server/host/index.ts +581 -0
  466. package/src/photon/server/index.ts +5 -0
  467. package/src/photon/server/listeners/index.ts +250 -0
  468. package/src/photon/server/ports/index.ts +156 -0
  469. package/src/photon/tcp/client/index.ts +64 -0
  470. package/src/photon/tcp/clock/index.ts +12 -0
  471. package/src/photon/tcp/codec/index.ts +174 -0
  472. package/src/photon/tcp/framing/index.ts +131 -0
  473. package/src/photon/tcp/index.ts +8 -0
  474. package/src/photon/tcp/ping/index.ts +43 -0
  475. package/src/photon/tcp/pong/index.ts +53 -0
  476. package/src/photon/tcp/server/index.ts +81 -0
  477. package/src/photon/timers/index.ts +68 -0
  478. package/src/photon/websocket/binary/index.ts +71 -0
  479. package/src/photon/websocket/bridge/index.ts +301 -0
  480. package/src/photon/websocket/framing/index.ts +45 -0
  481. package/src/photon/websocket/index.ts +14 -0
  482. package/src/photon/websocket/json/index.ts +49 -0
  483. package/src/photon/websocket/message/index.ts +176 -0
  484. package/src/photon/websocket/negotiation/index.ts +99 -0
  485. package/src/photon/websocket/path/index.ts +52 -0
  486. package/src/photon/websocket/plain/index.ts +25 -0
  487. package/src/photon/websocket/query/index.ts +99 -0
  488. package/src/photon/websocket/reassembly/index.ts +75 -0
  489. package/src/photon/websocket/subprotocol/index.ts +24 -0
  490. package/src/photon/websocket/text/index.ts +80 -0
  491. package/src/protocol/index.ts +61 -0
  492. package/src/scale/batch/index.ts +210 -0
  493. package/src/scale/courier/index.ts +726 -0
  494. package/src/scale/datagram/index.ts +337 -0
  495. package/src/scale/fanout/index.ts +654 -0
  496. package/src/scale/handoff/index.ts +271 -0
  497. package/src/scale/hosted/index.ts +68 -0
  498. package/src/scale/index.ts +41 -0
  499. package/src/scale/layout/index.ts +29 -0
  500. package/src/scale/mesh/index.ts +211 -0
  501. package/src/scale/outlet/index.ts +121 -0
  502. package/src/scale/pending/index.ts +165 -0
  503. package/src/scale/placement/index.ts +89 -0
  504. package/src/scale/portable/index.ts +42 -0
  505. package/src/scale/relay/index.ts +136 -0
  506. package/src/scale/sink/index.ts +51 -0
  507. package/src/scale/switchboard/index.ts +91 -0
  508. package/src/scale/transport/index.ts +112 -0
  509. package/src/scale/tunnel/index.ts +743 -0
  510. package/src/smartfox/index.ts +2 -0
  511. package/src/smartfox/pro/bans/index.ts +3 -0
  512. package/src/smartfox/pro/bans/list/index.ts +101 -0
  513. package/src/smartfox/pro/bans/memory/index.ts +57 -0
  514. package/src/smartfox/pro/bans/store/index.ts +43 -0
  515. package/src/smartfox/pro/bluebox/gateway/index.ts +310 -0
  516. package/src/smartfox/pro/bluebox/index.ts +4 -0
  517. package/src/smartfox/pro/bluebox/session/index.ts +63 -0
  518. package/src/smartfox/pro/bluebox/transport/index.ts +104 -0
  519. package/src/smartfox/pro/buddies/index.ts +4 -0
  520. package/src/smartfox/pro/buddies/memory/index.ts +38 -0
  521. package/src/smartfox/pro/buddies/roster/index.ts +411 -0
  522. package/src/smartfox/pro/buddies/store/index.ts +37 -0
  523. package/src/smartfox/pro/buddy/index.ts +65 -0
  524. package/src/smartfox/pro/catalogue/index.ts +141 -0
  525. package/src/smartfox/pro/claims/index.ts +110 -0
  526. package/src/smartfox/pro/codec/index.ts +87 -0
  527. package/src/smartfox/pro/counters/index.ts +3 -0
  528. package/src/smartfox/pro/counters/memory/index.ts +90 -0
  529. package/src/smartfox/pro/counters/offender/index.ts +47 -0
  530. package/src/smartfox/pro/counters/store/index.ts +17 -0
  531. package/src/smartfox/pro/entity/index.ts +111 -0
  532. package/src/smartfox/pro/escalation/index.ts +194 -0
  533. package/src/smartfox/pro/filter/index.ts +226 -0
  534. package/src/smartfox/pro/flood/index.ts +190 -0
  535. package/src/smartfox/pro/format/buddy/add/index.ts +2 -0
  536. package/src/smartfox/pro/format/buddy/add/notice/index.ts +44 -0
  537. package/src/smartfox/pro/format/buddy/add/request/index.ts +37 -0
  538. package/src/smartfox/pro/format/buddy/block/index.ts +44 -0
  539. package/src/smartfox/pro/format/buddy/clear/index.ts +37 -0
  540. package/src/smartfox/pro/format/buddy/index.ts +13 -0
  541. package/src/smartfox/pro/format/buddy/list/index.ts +59 -0
  542. package/src/smartfox/pro/format/buddy/load/index.ts +37 -0
  543. package/src/smartfox/pro/format/buddy/permission/index.ts +2 -0
  544. package/src/smartfox/pro/format/buddy/permission/notice/index.ts +43 -0
  545. package/src/smartfox/pro/format/buddy/permission/request/index.ts +48 -0
  546. package/src/smartfox/pro/format/buddy/remove/index.ts +2 -0
  547. package/src/smartfox/pro/format/buddy/remove/notice/index.ts +37 -0
  548. package/src/smartfox/pro/format/buddy/remove/request/index.ts +37 -0
  549. package/src/smartfox/pro/format/buddy/room/index.ts +2 -0
  550. package/src/smartfox/pro/format/buddy/room/reply/index.ts +50 -0
  551. package/src/smartfox/pro/format/buddy/room/request/index.ts +37 -0
  552. package/src/smartfox/pro/format/buddy/update/index.ts +54 -0
  553. package/src/smartfox/pro/format/buddy/variables/index.ts +48 -0
  554. package/src/smartfox/pro/format/chat/admin/index.ts +48 -0
  555. package/src/smartfox/pro/format/chat/index.ts +13 -0
  556. package/src/smartfox/pro/format/chat/moderator/index.ts +2 -0
  557. package/src/smartfox/pro/format/chat/moderator/message/index.ts +48 -0
  558. package/src/smartfox/pro/format/chat/moderator/request/index.ts +52 -0
  559. package/src/smartfox/pro/format/chat/private/index.ts +2 -0
  560. package/src/smartfox/pro/format/chat/private/message/index.ts +48 -0
  561. package/src/smartfox/pro/format/chat/private/request/index.ts +49 -0
  562. package/src/smartfox/pro/format/chat/public/index.ts +2 -0
  563. package/src/smartfox/pro/format/chat/public/message/index.ts +48 -0
  564. package/src/smartfox/pro/format/chat/public/request/index.ts +40 -0
  565. package/src/smartfox/pro/format/create/added/index.ts +76 -0
  566. package/src/smartfox/pro/format/create/deleted/index.ts +37 -0
  567. package/src/smartfox/pro/format/create/index.ts +4 -0
  568. package/src/smartfox/pro/format/create/refused/index.ts +37 -0
  569. package/src/smartfox/pro/format/create/request/index.ts +95 -0
  570. package/src/smartfox/pro/format/data/group/index.ts +62 -0
  571. package/src/smartfox/pro/format/data/index.ts +3 -0
  572. package/src/smartfox/pro/format/data/message/index.ts +54 -0
  573. package/src/smartfox/pro/format/data/request/index.ts +46 -0
  574. package/src/smartfox/pro/format/entry/buddy/index.ts +62 -0
  575. package/src/smartfox/pro/format/entry/index.ts +5 -0
  576. package/src/smartfox/pro/format/entry/object/index.ts +171 -0
  577. package/src/smartfox/pro/format/entry/room/index.ts +70 -0
  578. package/src/smartfox/pro/format/entry/user/index.ts +60 -0
  579. package/src/smartfox/pro/format/entry/variables/index.ts +148 -0
  580. package/src/smartfox/pro/format/extension/index.ts +3 -0
  581. package/src/smartfox/pro/format/extension/json/index.ts +99 -0
  582. package/src/smartfox/pro/format/extension/object/index.ts +95 -0
  583. package/src/smartfox/pro/format/extension/raw/index.ts +139 -0
  584. package/src/smartfox/pro/format/index.ts +86 -0
  585. package/src/smartfox/pro/format/join/accepted/index.ts +72 -0
  586. package/src/smartfox/pro/format/join/index.ts +3 -0
  587. package/src/smartfox/pro/format/join/refused/index.ts +37 -0
  588. package/src/smartfox/pro/format/join/request/index.ts +54 -0
  589. package/src/smartfox/pro/format/key/index.ts +2 -0
  590. package/src/smartfox/pro/format/key/reply/index.ts +37 -0
  591. package/src/smartfox/pro/format/key/request/index.ts +37 -0
  592. package/src/smartfox/pro/format/leave/index.ts +2 -0
  593. package/src/smartfox/pro/format/leave/notice/index.ts +41 -0
  594. package/src/smartfox/pro/format/leave/request/index.ts +41 -0
  595. package/src/smartfox/pro/format/login/accepted/index.ts +49 -0
  596. package/src/smartfox/pro/format/login/index.ts +3 -0
  597. package/src/smartfox/pro/format/login/refused/index.ts +37 -0
  598. package/src/smartfox/pro/format/login/request/index.ts +53 -0
  599. package/src/smartfox/pro/format/logout/index.ts +2 -0
  600. package/src/smartfox/pro/format/logout/notice/index.ts +37 -0
  601. package/src/smartfox/pro/format/logout/request/index.ts +37 -0
  602. package/src/smartfox/pro/format/ping/index.ts +2 -0
  603. package/src/smartfox/pro/format/ping/reply/index.ts +37 -0
  604. package/src/smartfox/pro/format/ping/request/index.ts +37 -0
  605. package/src/smartfox/pro/format/presence/count/index.ts +44 -0
  606. package/src/smartfox/pro/format/presence/entered/index.ts +47 -0
  607. package/src/smartfox/pro/format/presence/index.ts +3 -0
  608. package/src/smartfox/pro/format/presence/left/index.ts +44 -0
  609. package/src/smartfox/pro/format/rooms/auto/index.ts +37 -0
  610. package/src/smartfox/pro/format/rooms/index.ts +3 -0
  611. package/src/smartfox/pro/format/rooms/list/index.ts +54 -0
  612. package/src/smartfox/pro/format/rooms/request/index.ts +37 -0
  613. package/src/smartfox/pro/format/seat/index.ts +8 -0
  614. package/src/smartfox/pro/format/seat/player/index.ts +2 -0
  615. package/src/smartfox/pro/format/seat/player/notice/index.ts +49 -0
  616. package/src/smartfox/pro/format/seat/player/request/index.ts +37 -0
  617. package/src/smartfox/pro/format/seat/spectator/index.ts +2 -0
  618. package/src/smartfox/pro/format/seat/spectator/notice/index.ts +49 -0
  619. package/src/smartfox/pro/format/seat/spectator/request/index.ts +38 -0
  620. package/src/smartfox/pro/format/system/index.ts +19 -0
  621. package/src/smartfox/pro/format/variables/index.ts +8 -0
  622. package/src/smartfox/pro/format/variables/room/index.ts +2 -0
  623. package/src/smartfox/pro/format/variables/room/request/index.ts +50 -0
  624. package/src/smartfox/pro/format/variables/room/update/index.ts +52 -0
  625. package/src/smartfox/pro/format/variables/user/index.ts +2 -0
  626. package/src/smartfox/pro/format/variables/user/request/index.ts +47 -0
  627. package/src/smartfox/pro/format/variables/user/update/index.ts +52 -0
  628. package/src/smartfox/pro/format/version/accepted/index.ts +37 -0
  629. package/src/smartfox/pro/format/version/index.ts +3 -0
  630. package/src/smartfox/pro/format/version/refused/index.ts +37 -0
  631. package/src/smartfox/pro/format/version/request/index.ts +37 -0
  632. package/src/smartfox/pro/handler/buddy/index.ts +138 -0
  633. package/src/smartfox/pro/handler/chat/index.ts +221 -0
  634. package/src/smartfox/pro/handler/index.ts +7 -0
  635. package/src/smartfox/pro/handler/login/index.ts +175 -0
  636. package/src/smartfox/pro/handler/room/index.ts +121 -0
  637. package/src/smartfox/pro/handler/seat/index.ts +75 -0
  638. package/src/smartfox/pro/handler/shared/index.ts +29 -0
  639. package/src/smartfox/pro/handler/variable/index.ts +77 -0
  640. package/src/smartfox/pro/index.ts +60 -0
  641. package/src/smartfox/pro/login/attempt/index.ts +83 -0
  642. package/src/smartfox/pro/login/authenticator/index.ts +9 -0
  643. package/src/smartfox/pro/login/index.ts +3 -0
  644. package/src/smartfox/pro/login/verdict/index.ts +48 -0
  645. package/src/smartfox/pro/messages/index.ts +136 -0
  646. package/src/smartfox/pro/object/index.ts +12 -0
  647. package/src/smartfox/pro/options/index.ts +189 -0
  648. package/src/smartfox/pro/packet/buddy/add/index.ts +2 -0
  649. package/src/smartfox/pro/packet/buddy/add/notice/index.ts +27 -0
  650. package/src/smartfox/pro/packet/buddy/add/request/index.ts +25 -0
  651. package/src/smartfox/pro/packet/buddy/block/index.ts +33 -0
  652. package/src/smartfox/pro/packet/buddy/clear/index.ts +25 -0
  653. package/src/smartfox/pro/packet/buddy/index.ts +10 -0
  654. package/src/smartfox/pro/packet/buddy/list/index.ts +41 -0
  655. package/src/smartfox/pro/packet/buddy/load/index.ts +25 -0
  656. package/src/smartfox/pro/packet/buddy/permission/index.ts +2 -0
  657. package/src/smartfox/pro/packet/buddy/permission/notice/index.ts +33 -0
  658. package/src/smartfox/pro/packet/buddy/permission/request/index.ts +33 -0
  659. package/src/smartfox/pro/packet/buddy/remove/index.ts +2 -0
  660. package/src/smartfox/pro/packet/buddy/remove/notice/index.ts +25 -0
  661. package/src/smartfox/pro/packet/buddy/remove/request/index.ts +25 -0
  662. package/src/smartfox/pro/packet/buddy/room/index.ts +2 -0
  663. package/src/smartfox/pro/packet/buddy/room/reply/index.ts +25 -0
  664. package/src/smartfox/pro/packet/buddy/room/request/index.ts +25 -0
  665. package/src/smartfox/pro/packet/buddy/update/index.ts +35 -0
  666. package/src/smartfox/pro/packet/buddy/variables/index.ts +27 -0
  667. package/src/smartfox/pro/packet/chat/admin/index.ts +41 -0
  668. package/src/smartfox/pro/packet/chat/index.ts +5 -0
  669. package/src/smartfox/pro/packet/chat/moderator/index.ts +3 -0
  670. package/src/smartfox/pro/packet/chat/moderator/message/index.ts +41 -0
  671. package/src/smartfox/pro/packet/chat/moderator/request/index.ts +64 -0
  672. package/src/smartfox/pro/packet/chat/private/index.ts +2 -0
  673. package/src/smartfox/pro/packet/chat/private/message/index.ts +41 -0
  674. package/src/smartfox/pro/packet/chat/private/request/index.ts +45 -0
  675. package/src/smartfox/pro/packet/chat/public/index.ts +2 -0
  676. package/src/smartfox/pro/packet/chat/public/message/index.ts +41 -0
  677. package/src/smartfox/pro/packet/chat/public/request/index.ts +33 -0
  678. package/src/smartfox/pro/packet/create/added/index.ts +27 -0
  679. package/src/smartfox/pro/packet/create/deleted/index.ts +25 -0
  680. package/src/smartfox/pro/packet/create/index.ts +5 -0
  681. package/src/smartfox/pro/packet/create/refused/index.ts +25 -0
  682. package/src/smartfox/pro/packet/create/request/index.ts +105 -0
  683. package/src/smartfox/pro/packet/data/group/index.ts +51 -0
  684. package/src/smartfox/pro/packet/data/index.ts +3 -0
  685. package/src/smartfox/pro/packet/data/message/index.ts +43 -0
  686. package/src/smartfox/pro/packet/data/request/index.ts +35 -0
  687. package/src/smartfox/pro/packet/extension/index.ts +3 -0
  688. package/src/smartfox/pro/packet/extension/json/index.ts +2 -0
  689. package/src/smartfox/pro/packet/extension/json/reply/index.ts +33 -0
  690. package/src/smartfox/pro/packet/extension/json/request/index.ts +66 -0
  691. package/src/smartfox/pro/packet/extension/object/index.ts +2 -0
  692. package/src/smartfox/pro/packet/extension/object/reply/index.ts +35 -0
  693. package/src/smartfox/pro/packet/extension/object/request/index.ts +68 -0
  694. package/src/smartfox/pro/packet/extension/raw/index.ts +2 -0
  695. package/src/smartfox/pro/packet/extension/raw/reply/index.ts +25 -0
  696. package/src/smartfox/pro/packet/extension/raw/request/index.ts +66 -0
  697. package/src/smartfox/pro/packet/frame/index.ts +2 -0
  698. package/src/smartfox/pro/packet/frame/policy/file/index.ts +25 -0
  699. package/src/smartfox/pro/packet/frame/policy/index.ts +2 -0
  700. package/src/smartfox/pro/packet/frame/policy/request/index.ts +25 -0
  701. package/src/smartfox/pro/packet/frame/unknown/index.ts +25 -0
  702. package/src/smartfox/pro/packet/index.ts +72 -0
  703. package/src/smartfox/pro/packet/join/accepted/index.ts +74 -0
  704. package/src/smartfox/pro/packet/join/index.ts +3 -0
  705. package/src/smartfox/pro/packet/join/refused/index.ts +25 -0
  706. package/src/smartfox/pro/packet/join/request/index.ts +79 -0
  707. package/src/smartfox/pro/packet/key/index.ts +2 -0
  708. package/src/smartfox/pro/packet/key/reply/index.ts +25 -0
  709. package/src/smartfox/pro/packet/key/request/index.ts +25 -0
  710. package/src/smartfox/pro/packet/leave/index.ts +2 -0
  711. package/src/smartfox/pro/packet/leave/notice/index.ts +25 -0
  712. package/src/smartfox/pro/packet/leave/request/index.ts +25 -0
  713. package/src/smartfox/pro/packet/login/accepted/index.ts +45 -0
  714. package/src/smartfox/pro/packet/login/index.ts +3 -0
  715. package/src/smartfox/pro/packet/login/refused/index.ts +25 -0
  716. package/src/smartfox/pro/packet/login/request/index.ts +41 -0
  717. package/src/smartfox/pro/packet/logout/index.ts +2 -0
  718. package/src/smartfox/pro/packet/logout/notice/index.ts +25 -0
  719. package/src/smartfox/pro/packet/logout/request/index.ts +25 -0
  720. package/src/smartfox/pro/packet/ping/index.ts +2 -0
  721. package/src/smartfox/pro/packet/ping/reply/index.ts +25 -0
  722. package/src/smartfox/pro/packet/ping/request/index.ts +25 -0
  723. package/src/smartfox/pro/packet/presence/count/index.ts +41 -0
  724. package/src/smartfox/pro/packet/presence/entered/index.ts +35 -0
  725. package/src/smartfox/pro/packet/presence/index.ts +3 -0
  726. package/src/smartfox/pro/packet/presence/left/index.ts +33 -0
  727. package/src/smartfox/pro/packet/rooms/auto/index.ts +25 -0
  728. package/src/smartfox/pro/packet/rooms/index.ts +3 -0
  729. package/src/smartfox/pro/packet/rooms/list/index.ts +27 -0
  730. package/src/smartfox/pro/packet/rooms/request/index.ts +25 -0
  731. package/src/smartfox/pro/packet/seat/index.ts +2 -0
  732. package/src/smartfox/pro/packet/seat/player/index.ts +2 -0
  733. package/src/smartfox/pro/packet/seat/player/notice/index.ts +45 -0
  734. package/src/smartfox/pro/packet/seat/player/request/index.ts +25 -0
  735. package/src/smartfox/pro/packet/seat/spectator/index.ts +2 -0
  736. package/src/smartfox/pro/packet/seat/spectator/notice/index.ts +45 -0
  737. package/src/smartfox/pro/packet/seat/spectator/request/index.ts +25 -0
  738. package/src/smartfox/pro/packet/variables/index.ts +2 -0
  739. package/src/smartfox/pro/packet/variables/room/index.ts +2 -0
  740. package/src/smartfox/pro/packet/variables/room/request/index.ts +51 -0
  741. package/src/smartfox/pro/packet/variables/room/update/index.ts +47 -0
  742. package/src/smartfox/pro/packet/variables/user/index.ts +2 -0
  743. package/src/smartfox/pro/packet/variables/user/request/index.ts +35 -0
  744. package/src/smartfox/pro/packet/variables/user/update/index.ts +47 -0
  745. package/src/smartfox/pro/packet/version/accepted/index.ts +25 -0
  746. package/src/smartfox/pro/packet/version/index.ts +3 -0
  747. package/src/smartfox/pro/packet/version/refused/index.ts +25 -0
  748. package/src/smartfox/pro/packet/version/request/index.ts +25 -0
  749. package/src/smartfox/pro/penalty/index.ts +65 -0
  750. package/src/smartfox/pro/protocol/index.ts +395 -0
  751. package/src/smartfox/pro/room/index.ts +155 -0
  752. package/src/smartfox/pro/route/index.ts +25 -0
  753. package/src/smartfox/pro/sequence/index.ts +35 -0
  754. package/src/smartfox/pro/user/index.ts +80 -0
  755. package/src/smartfox/pro/variable/index.ts +34 -0
  756. package/src/smartfox/pro/web/index.ts +155 -0
  757. package/src/smartfox/pro/xml/index.ts +2 -0
  758. package/src/smartfox/pro/xml/reader/index.ts +228 -0
  759. package/src/smartfox/pro/xml/templates/index.ts +169 -0
  760. package/src/smartfox/pro/xml/writer/index.ts +147 -0
  761. package/src/smartfox/pro/zone/index.ts +874 -0
  762. package/src/smartfox/pro/zones/index.ts +324 -0
  763. package/src/smartfox/x2/balancer/index.ts +193 -0
  764. package/src/smartfox/x2/ban/index.ts +4 -0
  765. package/src/smartfox/x2/ban/list/index.ts +136 -0
  766. package/src/smartfox/x2/ban/memory/index.ts +71 -0
  767. package/src/smartfox/x2/ban/record/index.ts +36 -0
  768. package/src/smartfox/x2/ban/store/index.ts +28 -0
  769. package/src/smartfox/x2/bluebox/gateway/index.ts +315 -0
  770. package/src/smartfox/x2/bluebox/index.ts +4 -0
  771. package/src/smartfox/x2/bluebox/session/index.ts +63 -0
  772. package/src/smartfox/x2/bluebox/transport/index.ts +125 -0
  773. package/src/smartfox/x2/buddies/index.ts +608 -0
  774. package/src/smartfox/x2/catalogue/index.ts +23 -0
  775. package/src/smartfox/x2/catalogue/requests/index.ts +91 -0
  776. package/src/smartfox/x2/catalogue/responses/index.ts +93 -0
  777. package/src/smartfox/x2/chat/index.ts +383 -0
  778. package/src/smartfox/x2/cipher/index.ts +88 -0
  779. package/src/smartfox/x2/codec/index.ts +201 -0
  780. package/src/smartfox/x2/config/index.ts +383 -0
  781. package/src/smartfox/x2/data/array/index.ts +467 -0
  782. package/src/smartfox/x2/data/entry/index.ts +35 -0
  783. package/src/smartfox/x2/data/index.ts +6 -0
  784. package/src/smartfox/x2/data/object/index.ts +597 -0
  785. package/src/smartfox/x2/data/serializer/index.ts +393 -0
  786. package/src/smartfox/x2/data/type/index.ts +94 -0
  787. package/src/smartfox/x2/entity/buddy/index.ts +114 -0
  788. package/src/smartfox/x2/entity/index.ts +38 -0
  789. package/src/smartfox/x2/entity/invitation/index.ts +90 -0
  790. package/src/smartfox/x2/entity/item/index.ts +74 -0
  791. package/src/smartfox/x2/entity/match/index.ts +269 -0
  792. package/src/smartfox/x2/entity/privilege/index.ts +26 -0
  793. package/src/smartfox/x2/entity/room/index.ts +334 -0
  794. package/src/smartfox/x2/entity/settings/index.ts +239 -0
  795. package/src/smartfox/x2/entity/user/index.ts +118 -0
  796. package/src/smartfox/x2/entity/variable/buddy/index.ts +114 -0
  797. package/src/smartfox/x2/entity/variable/index.ts +16 -0
  798. package/src/smartfox/x2/entity/variable/item/index.ts +114 -0
  799. package/src/smartfox/x2/entity/variable/room/index.ts +153 -0
  800. package/src/smartfox/x2/entity/variable/type/index.ts +166 -0
  801. package/src/smartfox/x2/entity/variable/user/index.ts +134 -0
  802. package/src/smartfox/x2/entity/vector/index.ts +127 -0
  803. package/src/smartfox/x2/flood/gate/index.ts +78 -0
  804. package/src/smartfox/x2/flood/index.ts +162 -0
  805. package/src/smartfox/x2/flood/shared/index.ts +113 -0
  806. package/src/smartfox/x2/format/buddy/add/index.ts +2 -0
  807. package/src/smartfox/x2/format/buddy/add/request/index.ts +42 -0
  808. package/src/smartfox/x2/format/buddy/add/response/index.ts +55 -0
  809. package/src/smartfox/x2/format/buddy/block/index.ts +2 -0
  810. package/src/smartfox/x2/format/buddy/block/request/index.ts +45 -0
  811. package/src/smartfox/x2/format/buddy/block/response/index.ts +60 -0
  812. package/src/smartfox/x2/format/buddy/index.ts +21 -0
  813. package/src/smartfox/x2/format/buddy/init/index.ts +2 -0
  814. package/src/smartfox/x2/format/buddy/init/request/index.ts +38 -0
  815. package/src/smartfox/x2/format/buddy/init/response/index.ts +92 -0
  816. package/src/smartfox/x2/format/buddy/online/index.ts +2 -0
  817. package/src/smartfox/x2/format/buddy/online/request/index.ts +42 -0
  818. package/src/smartfox/x2/format/buddy/online/response/index.ts +61 -0
  819. package/src/smartfox/x2/format/buddy/remove/index.ts +2 -0
  820. package/src/smartfox/x2/format/buddy/remove/request/index.ts +42 -0
  821. package/src/smartfox/x2/format/buddy/remove/response/index.ts +51 -0
  822. package/src/smartfox/x2/format/buddy/variables/index.ts +2 -0
  823. package/src/smartfox/x2/format/buddy/variables/request/index.ts +46 -0
  824. package/src/smartfox/x2/format/buddy/variables/response/index.ts +58 -0
  825. package/src/smartfox/x2/format/cluster/connection/index.ts +1 -0
  826. package/src/smartfox/x2/format/cluster/connection/response/index.ts +52 -0
  827. package/src/smartfox/x2/format/cluster/error/index.ts +1 -0
  828. package/src/smartfox/x2/format/cluster/error/response/index.ts +38 -0
  829. package/src/smartfox/x2/format/cluster/index.ts +4 -0
  830. package/src/smartfox/x2/format/cluster/invite/index.ts +1 -0
  831. package/src/smartfox/x2/format/cluster/invite/request/index.ts +55 -0
  832. package/src/smartfox/x2/format/cluster/join/index.ts +1 -0
  833. package/src/smartfox/x2/format/cluster/join/request/index.ts +107 -0
  834. package/src/smartfox/x2/format/contract/index.ts +37 -0
  835. package/src/smartfox/x2/format/disconnect/index.ts +1 -0
  836. package/src/smartfox/x2/format/disconnect/request/index.ts +39 -0
  837. package/src/smartfox/x2/format/event/count/index.ts +49 -0
  838. package/src/smartfox/x2/format/event/disconnection/index.ts +48 -0
  839. package/src/smartfox/x2/format/event/enter/index.ts +53 -0
  840. package/src/smartfox/x2/format/event/exit/index.ts +45 -0
  841. package/src/smartfox/x2/format/event/index.ts +7 -0
  842. package/src/smartfox/x2/format/event/item/index.ts +51 -0
  843. package/src/smartfox/x2/format/event/lost/index.ts +2 -0
  844. package/src/smartfox/x2/format/event/lost/room/index.ts +42 -0
  845. package/src/smartfox/x2/format/event/lost/user/index.ts +42 -0
  846. package/src/smartfox/x2/format/event/reconnection/index.ts +39 -0
  847. package/src/smartfox/x2/format/extension/index.ts +2 -0
  848. package/src/smartfox/x2/format/extension/request/index.ts +49 -0
  849. package/src/smartfox/x2/format/extension/response/index.ts +47 -0
  850. package/src/smartfox/x2/format/find/index.ts +8 -0
  851. package/src/smartfox/x2/format/find/rooms/index.ts +2 -0
  852. package/src/smartfox/x2/format/find/rooms/request/index.ts +51 -0
  853. package/src/smartfox/x2/format/find/rooms/response/index.ts +74 -0
  854. package/src/smartfox/x2/format/find/users/index.ts +2 -0
  855. package/src/smartfox/x2/format/find/users/request/index.ts +54 -0
  856. package/src/smartfox/x2/format/find/users/response/index.ts +74 -0
  857. package/src/smartfox/x2/format/game/create/index.ts +1 -0
  858. package/src/smartfox/x2/format/game/create/request/index.ts +61 -0
  859. package/src/smartfox/x2/format/game/index.ts +14 -0
  860. package/src/smartfox/x2/format/game/invite/index.ts +2 -0
  861. package/src/smartfox/x2/format/game/invite/request/index.ts +50 -0
  862. package/src/smartfox/x2/format/game/invite/response/index.ts +61 -0
  863. package/src/smartfox/x2/format/game/join/index.ts +1 -0
  864. package/src/smartfox/x2/format/game/join/request/index.ts +55 -0
  865. package/src/smartfox/x2/format/game/quick/index.ts +2 -0
  866. package/src/smartfox/x2/format/game/quick/request/index.ts +56 -0
  867. package/src/smartfox/x2/format/game/quick/response/index.ts +48 -0
  868. package/src/smartfox/x2/format/game/reply/index.ts +2 -0
  869. package/src/smartfox/x2/format/game/reply/request/index.ts +50 -0
  870. package/src/smartfox/x2/format/game/reply/response/index.ts +70 -0
  871. package/src/smartfox/x2/format/group/index.ts +8 -0
  872. package/src/smartfox/x2/format/group/subscribe/index.ts +2 -0
  873. package/src/smartfox/x2/format/group/subscribe/request/index.ts +43 -0
  874. package/src/smartfox/x2/format/group/subscribe/response/index.ts +89 -0
  875. package/src/smartfox/x2/format/group/unsubscribe/index.ts +2 -0
  876. package/src/smartfox/x2/format/group/unsubscribe/request/index.ts +43 -0
  877. package/src/smartfox/x2/format/group/unsubscribe/response/index.ts +52 -0
  878. package/src/smartfox/x2/format/handshake/index.ts +2 -0
  879. package/src/smartfox/x2/format/handshake/request/index.ts +52 -0
  880. package/src/smartfox/x2/format/handshake/response/index.ts +62 -0
  881. package/src/smartfox/x2/format/index.ts +105 -0
  882. package/src/smartfox/x2/format/login/index.ts +2 -0
  883. package/src/smartfox/x2/format/login/request/index.ts +52 -0
  884. package/src/smartfox/x2/format/login/response/index.ts +99 -0
  885. package/src/smartfox/x2/format/logout/index.ts +2 -0
  886. package/src/smartfox/x2/format/logout/request/index.ts +38 -0
  887. package/src/smartfox/x2/format/logout/response/index.ts +42 -0
  888. package/src/smartfox/x2/format/message/index.ts +2 -0
  889. package/src/smartfox/x2/format/message/request/index.ts +126 -0
  890. package/src/smartfox/x2/format/message/response/index.ts +68 -0
  891. package/src/smartfox/x2/format/mmo/index.ts +4 -0
  892. package/src/smartfox/x2/format/mmo/position/index.ts +2 -0
  893. package/src/smartfox/x2/format/mmo/position/request/index.ts +49 -0
  894. package/src/smartfox/x2/format/mmo/position/response/index.ts +107 -0
  895. package/src/smartfox/x2/format/moderation/ban/index.ts +1 -0
  896. package/src/smartfox/x2/format/moderation/ban/request/index.ts +57 -0
  897. package/src/smartfox/x2/format/moderation/index.ts +2 -0
  898. package/src/smartfox/x2/format/moderation/kick/index.ts +1 -0
  899. package/src/smartfox/x2/format/moderation/kick/request/index.ts +48 -0
  900. package/src/smartfox/x2/format/ping/index.ts +2 -0
  901. package/src/smartfox/x2/format/ping/request/index.ts +38 -0
  902. package/src/smartfox/x2/format/ping/response/index.ts +38 -0
  903. package/src/smartfox/x2/format/room/capacity/index.ts +2 -0
  904. package/src/smartfox/x2/format/room/capacity/request/index.ts +50 -0
  905. package/src/smartfox/x2/format/room/capacity/response/index.ts +59 -0
  906. package/src/smartfox/x2/format/room/create/index.ts +2 -0
  907. package/src/smartfox/x2/format/room/create/request/index.ts +55 -0
  908. package/src/smartfox/x2/format/room/create/response/index.ts +55 -0
  909. package/src/smartfox/x2/format/room/index.ts +23 -0
  910. package/src/smartfox/x2/format/room/join/index.ts +2 -0
  911. package/src/smartfox/x2/format/room/join/request/index.ts +53 -0
  912. package/src/smartfox/x2/format/room/join/response/index.ts +84 -0
  913. package/src/smartfox/x2/format/room/leave/index.ts +1 -0
  914. package/src/smartfox/x2/format/room/leave/request/index.ts +42 -0
  915. package/src/smartfox/x2/format/room/password/index.ts +2 -0
  916. package/src/smartfox/x2/format/room/password/request/index.ts +46 -0
  917. package/src/smartfox/x2/format/room/password/response/index.ts +55 -0
  918. package/src/smartfox/x2/format/room/quick/index.ts +1 -0
  919. package/src/smartfox/x2/format/room/quick/request/index.ts +68 -0
  920. package/src/smartfox/x2/format/room/rename/index.ts +2 -0
  921. package/src/smartfox/x2/format/room/rename/request/index.ts +46 -0
  922. package/src/smartfox/x2/format/room/rename/response/index.ts +55 -0
  923. package/src/smartfox/x2/format/room/variables/index.ts +2 -0
  924. package/src/smartfox/x2/format/room/variables/request/index.ts +49 -0
  925. package/src/smartfox/x2/format/room/variables/response/index.ts +49 -0
  926. package/src/smartfox/x2/format/seat/index.ts +8 -0
  927. package/src/smartfox/x2/format/seat/player/index.ts +2 -0
  928. package/src/smartfox/x2/format/seat/player/request/index.ts +43 -0
  929. package/src/smartfox/x2/format/seat/player/response/index.ts +59 -0
  930. package/src/smartfox/x2/format/seat/spectator/index.ts +2 -0
  931. package/src/smartfox/x2/format/seat/spectator/request/index.ts +43 -0
  932. package/src/smartfox/x2/format/seat/spectator/response/index.ts +55 -0
  933. package/src/smartfox/x2/format/settings/index.ts +276 -0
  934. package/src/smartfox/x2/format/user/index.ts +4 -0
  935. package/src/smartfox/x2/format/user/variables/index.ts +2 -0
  936. package/src/smartfox/x2/format/user/variables/request/index.ts +46 -0
  937. package/src/smartfox/x2/format/user/variables/response/index.ts +49 -0
  938. package/src/smartfox/x2/games/index.ts +484 -0
  939. package/src/smartfox/x2/hall/index.ts +240 -0
  940. package/src/smartfox/x2/handler/buddy/index.ts +120 -0
  941. package/src/smartfox/x2/handler/chat/index.ts +213 -0
  942. package/src/smartfox/x2/handler/extension/index.ts +33 -0
  943. package/src/smartfox/x2/handler/game/index.ts +171 -0
  944. package/src/smartfox/x2/handler/index.ts +6 -0
  945. package/src/smartfox/x2/handler/room/index.ts +466 -0
  946. package/src/smartfox/x2/handler/session/index.ts +201 -0
  947. package/src/smartfox/x2/header/index.ts +25 -0
  948. package/src/smartfox/x2/index.ts +275 -0
  949. package/src/smartfox/x2/login/attempt/index.ts +102 -0
  950. package/src/smartfox/x2/login/index.ts +2 -0
  951. package/src/smartfox/x2/login/verdict/index.ts +81 -0
  952. package/src/smartfox/x2/member/index.ts +260 -0
  953. package/src/smartfox/x2/packet/buddy/add/index.ts +2 -0
  954. package/src/smartfox/x2/packet/buddy/add/request/index.ts +25 -0
  955. package/src/smartfox/x2/packet/buddy/add/response/index.ts +43 -0
  956. package/src/smartfox/x2/packet/buddy/block/index.ts +2 -0
  957. package/src/smartfox/x2/packet/buddy/block/request/index.ts +33 -0
  958. package/src/smartfox/x2/packet/buddy/block/response/index.ts +68 -0
  959. package/src/smartfox/x2/packet/buddy/index.ts +13 -0
  960. package/src/smartfox/x2/packet/buddy/init/index.ts +2 -0
  961. package/src/smartfox/x2/packet/buddy/init/request/index.ts +14 -0
  962. package/src/smartfox/x2/packet/buddy/init/response/index.ts +69 -0
  963. package/src/smartfox/x2/packet/buddy/online/index.ts +2 -0
  964. package/src/smartfox/x2/packet/buddy/online/request/index.ts +25 -0
  965. package/src/smartfox/x2/packet/buddy/online/response/index.ts +85 -0
  966. package/src/smartfox/x2/packet/buddy/remove/index.ts +2 -0
  967. package/src/smartfox/x2/packet/buddy/remove/request/index.ts +25 -0
  968. package/src/smartfox/x2/packet/buddy/remove/response/index.ts +42 -0
  969. package/src/smartfox/x2/packet/buddy/variables/index.ts +2 -0
  970. package/src/smartfox/x2/packet/buddy/variables/request/index.ts +29 -0
  971. package/src/smartfox/x2/packet/buddy/variables/response/index.ts +58 -0
  972. package/src/smartfox/x2/packet/cluster/connection/index.ts +1 -0
  973. package/src/smartfox/x2/packet/cluster/connection/response/index.ts +54 -0
  974. package/src/smartfox/x2/packet/cluster/error/index.ts +1 -0
  975. package/src/smartfox/x2/packet/cluster/error/response/index.ts +14 -0
  976. package/src/smartfox/x2/packet/cluster/index.ts +4 -0
  977. package/src/smartfox/x2/packet/cluster/invite/index.ts +1 -0
  978. package/src/smartfox/x2/packet/cluster/invite/request/index.ts +77 -0
  979. package/src/smartfox/x2/packet/cluster/join/index.ts +1 -0
  980. package/src/smartfox/x2/packet/cluster/join/request/index.ts +52 -0
  981. package/src/smartfox/x2/packet/disconnect/index.ts +1 -0
  982. package/src/smartfox/x2/packet/disconnect/request/index.ts +14 -0
  983. package/src/smartfox/x2/packet/error/codes/index.ts +231 -0
  984. package/src/smartfox/x2/packet/error/index.ts +69 -0
  985. package/src/smartfox/x2/packet/event/count/index.ts +45 -0
  986. package/src/smartfox/x2/packet/event/disconnection/index.ts +72 -0
  987. package/src/smartfox/x2/packet/event/enter/index.ts +47 -0
  988. package/src/smartfox/x2/packet/event/exit/index.ts +33 -0
  989. package/src/smartfox/x2/packet/event/index.ts +10 -0
  990. package/src/smartfox/x2/packet/event/item/index.ts +51 -0
  991. package/src/smartfox/x2/packet/event/lost/index.ts +2 -0
  992. package/src/smartfox/x2/packet/event/lost/room/index.ts +25 -0
  993. package/src/smartfox/x2/packet/event/lost/user/index.ts +25 -0
  994. package/src/smartfox/x2/packet/event/reconnection/index.ts +14 -0
  995. package/src/smartfox/x2/packet/extension/index.ts +2 -0
  996. package/src/smartfox/x2/packet/extension/request/index.ts +74 -0
  997. package/src/smartfox/x2/packet/extension/response/index.ts +54 -0
  998. package/src/smartfox/x2/packet/find/index.ts +2 -0
  999. package/src/smartfox/x2/packet/find/rooms/index.ts +2 -0
  1000. package/src/smartfox/x2/packet/find/rooms/request/index.ts +51 -0
  1001. package/src/smartfox/x2/packet/find/rooms/response/index.ts +27 -0
  1002. package/src/smartfox/x2/packet/find/users/index.ts +2 -0
  1003. package/src/smartfox/x2/packet/find/users/request/index.ts +89 -0
  1004. package/src/smartfox/x2/packet/find/users/response/index.ts +27 -0
  1005. package/src/smartfox/x2/packet/game/create/index.ts +1 -0
  1006. package/src/smartfox/x2/packet/game/create/request/index.ts +27 -0
  1007. package/src/smartfox/x2/packet/game/index.ts +8 -0
  1008. package/src/smartfox/x2/packet/game/invite/index.ts +2 -0
  1009. package/src/smartfox/x2/packet/game/invite/request/index.ts +51 -0
  1010. package/src/smartfox/x2/packet/game/invite/response/index.ts +92 -0
  1011. package/src/smartfox/x2/packet/game/join/index.ts +1 -0
  1012. package/src/smartfox/x2/packet/game/join/request/index.ts +77 -0
  1013. package/src/smartfox/x2/packet/game/quick/index.ts +2 -0
  1014. package/src/smartfox/x2/packet/game/quick/request/index.ts +89 -0
  1015. package/src/smartfox/x2/packet/game/quick/response/index.ts +34 -0
  1016. package/src/smartfox/x2/packet/game/reply/index.ts +2 -0
  1017. package/src/smartfox/x2/packet/game/reply/request/index.ts +51 -0
  1018. package/src/smartfox/x2/packet/game/reply/response/index.ts +91 -0
  1019. package/src/smartfox/x2/packet/group/index.ts +8 -0
  1020. package/src/smartfox/x2/packet/group/subscribe/index.ts +2 -0
  1021. package/src/smartfox/x2/packet/group/subscribe/request/index.ts +25 -0
  1022. package/src/smartfox/x2/packet/group/subscribe/response/index.ts +58 -0
  1023. package/src/smartfox/x2/packet/group/unsubscribe/index.ts +2 -0
  1024. package/src/smartfox/x2/packet/group/unsubscribe/request/index.ts +25 -0
  1025. package/src/smartfox/x2/packet/group/unsubscribe/response/index.ts +42 -0
  1026. package/src/smartfox/x2/packet/handshake/index.ts +2 -0
  1027. package/src/smartfox/x2/packet/handshake/request/index.ts +49 -0
  1028. package/src/smartfox/x2/packet/handshake/response/index.ts +83 -0
  1029. package/src/smartfox/x2/packet/index.ts +99 -0
  1030. package/src/smartfox/x2/packet/login/index.ts +2 -0
  1031. package/src/smartfox/x2/packet/login/request/index.ts +95 -0
  1032. package/src/smartfox/x2/packet/login/response/index.ts +131 -0
  1033. package/src/smartfox/x2/packet/logout/index.ts +2 -0
  1034. package/src/smartfox/x2/packet/logout/request/index.ts +14 -0
  1035. package/src/smartfox/x2/packet/logout/response/index.ts +25 -0
  1036. package/src/smartfox/x2/packet/message/index.ts +4 -0
  1037. package/src/smartfox/x2/packet/message/request/index.ts +241 -0
  1038. package/src/smartfox/x2/packet/message/response/index.ts +216 -0
  1039. package/src/smartfox/x2/packet/message/type/index.ts +56 -0
  1040. package/src/smartfox/x2/packet/mmo/index.ts +5 -0
  1041. package/src/smartfox/x2/packet/mmo/position/index.ts +3 -0
  1042. package/src/smartfox/x2/packet/mmo/position/request/index.ts +38 -0
  1043. package/src/smartfox/x2/packet/mmo/position/response/index.ts +114 -0
  1044. package/src/smartfox/x2/packet/moderation/ban/index.ts +1 -0
  1045. package/src/smartfox/x2/packet/moderation/ban/request/index.ts +83 -0
  1046. package/src/smartfox/x2/packet/moderation/index.ts +2 -0
  1047. package/src/smartfox/x2/packet/moderation/kick/index.ts +1 -0
  1048. package/src/smartfox/x2/packet/moderation/kick/request/index.ts +45 -0
  1049. package/src/smartfox/x2/packet/ping/index.ts +2 -0
  1050. package/src/smartfox/x2/packet/ping/request/index.ts +14 -0
  1051. package/src/smartfox/x2/packet/ping/response/index.ts +14 -0
  1052. package/src/smartfox/x2/packet/room/capacity/index.ts +2 -0
  1053. package/src/smartfox/x2/packet/room/capacity/request/index.ts +45 -0
  1054. package/src/smartfox/x2/packet/room/capacity/response/index.ts +67 -0
  1055. package/src/smartfox/x2/packet/room/create/index.ts +2 -0
  1056. package/src/smartfox/x2/packet/room/create/request/index.ts +51 -0
  1057. package/src/smartfox/x2/packet/room/create/response/index.ts +43 -0
  1058. package/src/smartfox/x2/packet/room/index.ts +21 -0
  1059. package/src/smartfox/x2/packet/room/join/index.ts +3 -0
  1060. package/src/smartfox/x2/packet/room/join/request/index.ts +101 -0
  1061. package/src/smartfox/x2/packet/room/join/response/index.ts +74 -0
  1062. package/src/smartfox/x2/packet/room/leave/index.ts +1 -0
  1063. package/src/smartfox/x2/packet/room/leave/request/index.ts +25 -0
  1064. package/src/smartfox/x2/packet/room/password/index.ts +2 -0
  1065. package/src/smartfox/x2/packet/room/password/request/index.ts +33 -0
  1066. package/src/smartfox/x2/packet/room/password/response/index.ts +57 -0
  1067. package/src/smartfox/x2/packet/room/quick/index.ts +1 -0
  1068. package/src/smartfox/x2/packet/room/quick/request/index.ts +67 -0
  1069. package/src/smartfox/x2/packet/room/rename/index.ts +2 -0
  1070. package/src/smartfox/x2/packet/room/rename/request/index.ts +33 -0
  1071. package/src/smartfox/x2/packet/room/rename/response/index.ts +50 -0
  1072. package/src/smartfox/x2/packet/room/variables/index.ts +2 -0
  1073. package/src/smartfox/x2/packet/room/variables/request/index.ts +38 -0
  1074. package/src/smartfox/x2/packet/room/variables/response/index.ts +38 -0
  1075. package/src/smartfox/x2/packet/seat/index.ts +8 -0
  1076. package/src/smartfox/x2/packet/seat/player/index.ts +2 -0
  1077. package/src/smartfox/x2/packet/seat/player/request/index.ts +25 -0
  1078. package/src/smartfox/x2/packet/seat/player/response/index.ts +67 -0
  1079. package/src/smartfox/x2/packet/seat/spectator/index.ts +2 -0
  1080. package/src/smartfox/x2/packet/seat/spectator/request/index.ts +25 -0
  1081. package/src/smartfox/x2/packet/seat/spectator/response/index.ts +50 -0
  1082. package/src/smartfox/x2/packet/unknown/index.ts +47 -0
  1083. package/src/smartfox/x2/packet/user/index.ts +4 -0
  1084. package/src/smartfox/x2/packet/user/variables/index.ts +2 -0
  1085. package/src/smartfox/x2/packet/user/variables/request/index.ts +29 -0
  1086. package/src/smartfox/x2/packet/user/variables/response/index.ts +38 -0
  1087. package/src/smartfox/x2/protocol/index.ts +495 -0
  1088. package/src/smartfox/x2/proximity/index.ts +353 -0
  1089. package/src/smartfox/x2/rooms/index.ts +981 -0
  1090. package/src/smartfox/x2/roster/index.ts +3 -0
  1091. package/src/smartfox/x2/roster/memory/index.ts +41 -0
  1092. package/src/smartfox/x2/roster/record/index.ts +31 -0
  1093. package/src/smartfox/x2/roster/store/index.ts +21 -0
  1094. package/src/smartfox/x2/route/index.ts +17 -0
  1095. package/src/smartfox/x2/sessions/index.ts +18 -0
  1096. package/src/smartfox/x2/udp/index.ts +392 -0
  1097. package/src/smartfox/x2/web/index.ts +183 -0
  1098. package/src/smartfox/x2/websocket/index.ts +119 -0
  1099. package/src/smartfox/x2/words/index.ts +265 -0
  1100. package/src/smartfox/x2/zone/index.ts +1163 -0
  1101. package/src/smartfox/x2/zones/index.ts +608 -0
@@ -0,0 +1,2271 @@
1
+ import { ActorProperty } from '../../balancing/code/actor/index.ts'
2
+ import { EventCaching } from '../../balancing/code/caching/index.ts'
3
+ import { ErrorCode } from '../../balancing/code/error/index.ts'
4
+ import { EventRange } from '../../balancing/code/event/index.ts'
5
+ import { GameProperty } from '../../balancing/code/game/index.ts'
6
+ import { JoinMode } from '../../balancing/code/join/index.ts'
7
+ import { ErrorMessage } from '../../balancing/code/message/index.ts'
8
+ import { ReceiverGroup } from '../../balancing/code/receiver/index.ts'
9
+ import { RoomOptionFlag } from '../../balancing/code/room/index.ts'
10
+ import { WebFlag } from '../../balancing/code/web/index.ts'
11
+ import { RoomEntry } from '../../balancing/entity/entry/index.ts'
12
+ import { Lobby } from '../../balancing/entity/lobby/index.ts'
13
+ import { CustomEvent } from '../../balancing/packet/event/custom/index.ts'
14
+ import { ErrorInfoEvent } from '../../balancing/packet/event/error/index.ts'
15
+ import { JoinEvent } from '../../balancing/packet/event/join/index.ts'
16
+ import { LeaveEvent } from '../../balancing/packet/event/leave/index.ts'
17
+ import { PropertiesChangedEvent } from '../../balancing/packet/event/properties/index.ts'
18
+ import { CacheSliceChangedEvent } from '../../balancing/packet/event/slice/index.ts'
19
+ import type { ChangeGroupsRequest } from '../../balancing/packet/groups/request/index.ts'
20
+ import type { LeaveRequest } from '../../balancing/packet/leave/request/index.ts'
21
+ import { LeaveResponse } from '../../balancing/packet/leave/response/index.ts'
22
+ import type { GetPropertiesRequest } from '../../balancing/packet/properties/get/request/index.ts'
23
+ import { GetPropertiesResponse } from '../../balancing/packet/properties/get/response/index.ts'
24
+ import type { SetPropertiesRequest } from '../../balancing/packet/properties/set/request/index.ts'
25
+ import { SetPropertiesResponse } from '../../balancing/packet/properties/set/response/index.ts'
26
+ import type { RaiseEventRequest } from '../../balancing/packet/raise/request/index.ts'
27
+ import { RaiseEventResponse } from '../../balancing/packet/raise/response/index.ts'
28
+ import { PhotonHashtable } from '../../binary/hashtable/index.ts'
29
+ import { Kind } from '../../binary/kind/index.ts'
30
+ import { Shape } from '../../binary/shape/index.ts'
31
+ import { PhotonValue } from '../../binary/value/index.ts'
32
+ import { LeaveReason } from '../../hooks/reason/index.ts'
33
+ import type { HookSender } from '../../hooks/sender/index.ts'
34
+ import { JsonKeys } from '../../message/json/keys/index.ts'
35
+ import type { ExcludedUser } from '../../registry/index.ts'
36
+ import { Actor } from '../actor/index.ts'
37
+ import type { Authenticator } from '../authenticator/index.ts'
38
+ import { PropertyBag } from '../bag/index.ts'
39
+ import { ActorCache, RoomCache } from '../cache/index.ts'
40
+ import type { Alarm, Clock } from '../clock/index.ts'
41
+ import { EntrySetup } from '../entry/index.ts'
42
+ import { Fault } from '../fault/index.ts'
43
+ import { InterestGroups } from '../groups/index.ts'
44
+ import type { GamePeer } from '../peer/index.ts'
45
+ import type { GameChanges, GameSummary, Herald } from '../report/index.ts'
46
+ import type { GameConfiguration } from '../settings/index.ts'
47
+ import { SharedFrames } from '../shared/index.ts'
48
+ import type { ActorSnapshot, RoomSnapshot } from '../snapshot/index.ts'
49
+ import { JoinStage } from '../stage/index.ts'
50
+ import { WellKnownProperties } from '../wellknown/index.ts'
51
+
52
+ /**
53
+ * What every room of a Game Server shares
54
+ */
55
+ export type RoomServices = {
56
+ /**
57
+ * Limits and waits
58
+ */
59
+ readonly configuration: GameConfiguration
60
+
61
+ /**
62
+ * Tells the time and runs the waits
63
+ */
64
+ readonly clock: Clock
65
+
66
+ /**
67
+ * Tells the Master what happens
68
+ */
69
+ readonly herald: Herald
70
+
71
+ /**
72
+ * Compares the tokens of two connections
73
+ */
74
+ readonly authenticator: Authenticator
75
+
76
+ /**
77
+ * Posts the WebHooks, or null
78
+ */
79
+ readonly hooks: HookSender | null
80
+
81
+ /**
82
+ * Encodes an event once for the clients that read the same bytes, or null
83
+ */
84
+ readonly shared: SharedFrames | null
85
+ }
86
+
87
+ /**
88
+ * One game on a Game Server
89
+ * @class
90
+ */
91
+ export class Room {
92
+ /**
93
+ * A player time to live that never runs out
94
+ */
95
+ protected static readonly FOREVER: number = 2 ** 31 - 1
96
+
97
+ /**
98
+ * Lowest property code the server owns
99
+ */
100
+ private static readonly LOWEST_WELL_KNOWN: number = 235
101
+
102
+ /**
103
+ * How a GUID user id looks
104
+ */
105
+ private static readonly GUID: RegExp =
106
+ /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i
107
+
108
+ /**
109
+ * Its name
110
+ */
111
+ public readonly name: string
112
+
113
+ /**
114
+ * Application it belongs to
115
+ */
116
+ public readonly application: string
117
+
118
+ /**
119
+ * Version of that application
120
+ */
121
+ public readonly version: string
122
+
123
+ /**
124
+ * Whether it's gone for good
125
+ */
126
+ public closed: boolean
127
+
128
+ /**
129
+ * What every room shares
130
+ */
131
+ protected readonly services: RoomServices
132
+
133
+ /**
134
+ * Takes the room off the server's list
135
+ */
136
+ private readonly dispose: (room: Room) => void
137
+
138
+ /**
139
+ * Its own properties
140
+ */
141
+ private readonly properties: PropertyBag
142
+
143
+ /**
144
+ * Connected actors in the order they came
145
+ */
146
+ protected readonly active: Actor[]
147
+
148
+ /**
149
+ * The connected actor of each connection
150
+ */
151
+ private readonly seats: Map<GamePeer, Actor>
152
+
153
+ /**
154
+ * Actors that are away, in the order they went
155
+ */
156
+ protected readonly inactive: Actor[]
157
+
158
+ /**
159
+ * Connections that keep it alive
160
+ */
161
+ private readonly references: Set<GamePeer>
162
+
163
+ /**
164
+ * Who hears which group
165
+ */
166
+ private readonly groups: InterestGroups
167
+
168
+ /**
169
+ * Events kept for the whole room
170
+ */
171
+ private readonly roomCache: RoomCache
172
+
173
+ /**
174
+ * Events actors keep about themselves
175
+ */
176
+ private readonly actorCache: ActorCache
177
+
178
+ /**
179
+ * User ids with a seat kept
180
+ */
181
+ private expected: string[]
182
+
183
+ /**
184
+ * Users kept out
185
+ */
186
+ private excluded: readonly ExcludedUser[]
187
+
188
+ /**
189
+ * Room option bits
190
+ */
191
+ private flags: number
192
+
193
+ /**
194
+ * Highest actor number given out
195
+ */
196
+ private counter: number
197
+
198
+ /**
199
+ * Actor number of the master client, or 0
200
+ */
201
+ private master: number
202
+
203
+ /**
204
+ * Lobby it's listed in, or null
205
+ */
206
+ private lobby: Lobby | null
207
+
208
+ /**
209
+ * Property keys lobbies show, or null
210
+ */
211
+ private filter: readonly PhotonValue[] | null
212
+
213
+ /**
214
+ * Closes the empty room once its time is up, or null
215
+ */
216
+ private removal: Alarm | null
217
+
218
+ /**
219
+ * Clock second the forward count belongs to
220
+ */
221
+ private forwardSecond: number
222
+
223
+ /**
224
+ * Forwarded operations in that second
225
+ */
226
+ private forwardCount: number
227
+
228
+ /**
229
+ * @param name its name
230
+ * @param application application it belongs to
231
+ * @param version version of that application
232
+ * @param services what every room shares
233
+ * @param dispose takes the room off the server's list
234
+ */
235
+ public constructor(
236
+ name: string,
237
+ application: string,
238
+ version: string,
239
+ services: RoomServices,
240
+ dispose: (room: Room) => void,
241
+ ) {
242
+ const configuration = services.configuration
243
+
244
+ this.name = name
245
+ this.application = application
246
+ this.version = version
247
+ this.closed = false
248
+ this.services = services
249
+ this.dispose = dispose
250
+ this.properties = PropertyBag.of()
251
+ this.active = []
252
+ this.seats = new Map<GamePeer, Actor>()
253
+ this.inactive = []
254
+ this.references = new Set<GamePeer>()
255
+ this.groups = new InterestGroups()
256
+ this.roomCache = new RoomCache(
257
+ configuration.eventCacheLimit,
258
+ configuration.sliceLimit,
259
+ )
260
+ this.actorCache = new ActorCache(configuration.actorEventCacheLimit)
261
+ this.expected = []
262
+ this.excluded = []
263
+ this.flags = 0
264
+ this.counter = 0
265
+ this.master = 0
266
+ this.lobby = null
267
+ this.filter = null
268
+ this.removal = null
269
+ this.forwardSecond = 0
270
+ this.forwardCount = 0
271
+
272
+ this.properties.set(Room.key(GameProperty.MAX_PLAYERS), PhotonValue.byte(0))
273
+ this.properties.set(Room.key(GameProperty.IS_OPEN), PhotonValue.bool(true))
274
+ this.properties.set(
275
+ Room.key(GameProperty.IS_VISIBLE),
276
+ PhotonValue.bool(true),
277
+ )
278
+ }
279
+
280
+ /**
281
+ * The key of a well-known property
282
+ * @param code which property
283
+ */
284
+ private static key(code: number): PhotonValue {
285
+ return PhotonValue.byte(code)
286
+ }
287
+
288
+ /**
289
+ * Whether a property is one a saved room keeps outside its table
290
+ * @param key typed key
291
+ */
292
+ private static wellKnown(key: PhotonValue): boolean {
293
+ const code = key.kind === Kind.BYTE ? (key.integer() ?? 0) : 0
294
+
295
+ return (
296
+ code >= Room.LOWEST_WELL_KNOWN &&
297
+ code !== GameProperty.PROPS_LISTED_IN_LOBBY
298
+ )
299
+ }
300
+
301
+ /**
302
+ * The refusal for a user the room keeps out
303
+ * @param ban who's kept out and why
304
+ */
305
+ private static banned(ban: ExcludedUser): Fault {
306
+ switch (ban.reason) {
307
+ case 1:
308
+ return Fault.of(
309
+ ErrorCode.JOIN_FAILED_FOUND_EXCLUDED_USER_ID,
310
+ 'User {0} is banned in this game',
311
+ ban.userId,
312
+ )
313
+ case 2:
314
+ return Fault.of(
315
+ ErrorCode.JOIN_FAILED_FOUND_EXCLUDED_USER_ID,
316
+ 'User {0} is global banned',
317
+ ban.userId,
318
+ )
319
+ default:
320
+ return Fault.of(
321
+ ErrorCode.JOIN_FAILED_FOUND_EXCLUDED_USER_ID,
322
+ 'Unknown reason {0} for excluding ',
323
+ ban.reason,
324
+ )
325
+ }
326
+ }
327
+
328
+ /**
329
+ * A table with one well-known property
330
+ * @param code which property
331
+ * @param value what it holds
332
+ */
333
+ private static single(code: number, value: PhotonValue): PhotonHashtable {
334
+ return PhotonHashtable.of().set(Room.key(code), value)
335
+ }
336
+
337
+ /**
338
+ * User ids as a property value
339
+ * @param users who has a seat kept
340
+ */
341
+ private static names(users: readonly string[]): PhotonValue {
342
+ return PhotonValue.array(Shape.string(), [...users])
343
+ }
344
+
345
+ /**
346
+ * Lets a connection in, or tells it why not
347
+ * @param peer who's asking
348
+ * @param setup the request as the room needs it
349
+ */
350
+ public enter(peer: GamePeer, setup: EntrySetup): void {
351
+ const fresh = this.counter === 0
352
+ if (!this.claim(peer, setup, fresh)) return
353
+
354
+ this.settle(peer, setup, fresh)
355
+ }
356
+
357
+ /**
358
+ * Holds the room for a connection and says whether its request may go on
359
+ * @param peer who's asking
360
+ * @param setup the request as the room needs it
361
+ * @param fresh whether the request starts the room
362
+ */
363
+ protected claim(peer: GamePeer, setup: EntrySetup, fresh: boolean): boolean {
364
+ peer.stage = JoinStage.CREATING_OR_LOADING_GAME
365
+ peer.room = this
366
+ this.references.add(peer)
367
+
368
+ const unfit = fresh ? this.founding(setup) : null
369
+ if (unfit === null) return true
370
+
371
+ this.reject(peer, setup, unfit, null)
372
+ return false
373
+ }
374
+
375
+ /**
376
+ * Seats a connection that holds the room, or tells it why not
377
+ * @param peer who's asking
378
+ * @param setup the request as the room needs it
379
+ * @param fresh whether the request starts the room
380
+ */
381
+ protected settle(peer: GamePeer, setup: EntrySetup, fresh: boolean): void {
382
+ peer.stage = JoinStage.CONVERTING_PARAMS
383
+ const unfit = fresh ? null : this.admission(peer, setup)
384
+ if (unfit !== null) {
385
+ this.reject(peer, setup, unfit, null)
386
+ return
387
+ }
388
+
389
+ if (fresh) {
390
+ this.lobby = setup.lobby
391
+ this.list(setup.properties)
392
+ }
393
+
394
+ peer.stage = JoinStage.CHECKING_CACHE_SLICE
395
+ const slice = setup.cacheSliceIndex
396
+ if (slice !== null && !this.roomCache.has(slice)) {
397
+ this.reject(
398
+ peer,
399
+ setup,
400
+ Fault.invalid(ErrorMessage.CACHE_SLICE_NOT_AVAILABLE, slice),
401
+ null,
402
+ )
403
+ return
404
+ }
405
+
406
+ peer.stage = JoinStage.ADDING_ACTOR
407
+ const seat = this.seat(peer, setup)
408
+ if (seat instanceof Fault) {
409
+ this.reject(peer, setup, seat, null)
410
+ return
411
+ }
412
+
413
+ const actor = seat === null ? this.add(peer) : this.reactivate(seat, peer)
414
+
415
+ this.removal?.cancel()
416
+ this.removal = null
417
+ if (this.master === 0) this.elect()
418
+
419
+ peer.stage = JoinStage.CHECK_AFTER_JOIN_PARAMS
420
+ const unfurnished = fresh ? this.furnish(setup) : null
421
+ const reserved =
422
+ unfurnished === null ? this.reserve(setup.expectedUsers ?? []) : null
423
+ if (reserved === null) {
424
+ this.reject(
425
+ peer,
426
+ setup,
427
+ unfurnished ??
428
+ Fault.of(ErrorCode.SLOT_ERROR, ErrorMessage.CANT_ADD_SLOTS),
429
+ actor,
430
+ )
431
+ return
432
+ }
433
+
434
+ peer.stage = JoinStage.APPLY_ACTOR_PROPERTIES
435
+ actor.properties.merge(setup.actorProperties)
436
+
437
+ const extended = !fresh && reserved.length > 0
438
+ if (extended) {
439
+ this.properties.set(
440
+ Room.key(GameProperty.EXPECTED_USERS),
441
+ Room.names(this.expected),
442
+ )
443
+ }
444
+
445
+ peer.stage = JoinStage.SENDING_USER_RESPONSE
446
+ peer.send(setup.accept(this.entry(actor, setup)))
447
+
448
+ peer.stage = JoinStage.PUBLISHING_EVENTS
449
+ this.announce(actor, setup)
450
+ if (extended) {
451
+ this.tell(
452
+ this.active,
453
+ PropertiesChangedEvent.of(
454
+ actor.number,
455
+ 0,
456
+ Room.single(GameProperty.EXPECTED_USERS, Room.names(this.expected)),
457
+ ),
458
+ )
459
+ }
460
+
461
+ peer.stage = JoinStage.EVENTS_PUBLISHED
462
+ this.replay(peer, slice ?? 0)
463
+
464
+ peer.stage = JoinStage.COMPLETE
465
+ const arrival: GameChanges = {
466
+ newUsers: [actor.userId],
467
+ expectedUsers: extended ? [...this.expected] : null,
468
+ }
469
+ this.report(fresh ? this.describe() : arrival)
470
+ }
471
+
472
+ /**
473
+ * Takes a connection out because it asked
474
+ * @param peer who's leaving
475
+ * @param packet what the client sent
476
+ */
477
+ public leave(peer: GamePeer, packet: LeaveRequest): void {
478
+ const actor = this.playing(peer)
479
+
480
+ if (actor !== null) {
481
+ if (packet.isInactive && this.playerTtl !== 0) {
482
+ this.deactivate(actor)
483
+ } else {
484
+ this.remove(actor, false)
485
+ }
486
+
487
+ peer.send(LeaveResponse.success().to(packet))
488
+ }
489
+
490
+ this.release(peer)
491
+ }
492
+
493
+ /**
494
+ * Takes a connection out because it closed
495
+ * @param peer who's gone
496
+ */
497
+ public disconnected(peer: GamePeer): void {
498
+ const actor = this.playing(peer)
499
+
500
+ if (actor !== null) {
501
+ if (peer.stage === JoinStage.COMPLETE && this.playerTtl !== 0) {
502
+ this.deactivate(actor)
503
+ } else {
504
+ this.remove(actor, false)
505
+ }
506
+ }
507
+
508
+ this.release(peer)
509
+ }
510
+
511
+ /**
512
+ * Sends an event around, keeps it, or changes the cache
513
+ * @param peer who raised it
514
+ * @param packet what the client sent
515
+ */
516
+ public raise(peer: GamePeer, packet: RaiseEventRequest): void {
517
+ const fault = this.raised(peer, packet)
518
+ if (fault === null) return
519
+
520
+ peer.send(RaiseEventResponse.failure(fault.code, fault.message).to(packet))
521
+ }
522
+
523
+ /**
524
+ * Changes properties of the room or of one actor
525
+ * @param peer who's changing them
526
+ * @param packet what the client sent
527
+ */
528
+ public change(peer: GamePeer, packet: SetPropertiesRequest): void {
529
+ const fault = this.altered(peer, packet)
530
+ if (fault === null) return
531
+
532
+ peer.send(
533
+ SetPropertiesResponse.failure(fault.code, fault.message).to(packet),
534
+ )
535
+ }
536
+
537
+ /**
538
+ * Answers with properties of the room, its actors, or both
539
+ * @param peer who's asking
540
+ * @param packet what the client sent
541
+ */
542
+ public inspect(peer: GamePeer, packet: GetPropertiesRequest): void {
543
+ const kinds = packet.kinds ?? 0
544
+ const publish = this.has(RoomOptionFlag.PUBLISH_USER_ID)
545
+ let game: PhotonHashtable | null = null
546
+ let actors: PhotonHashtable | null = null
547
+
548
+ if ((kinds & 0x01) !== 0) {
549
+ const keys = packet.gameProperties
550
+ game =
551
+ keys === null
552
+ ? this.properties.all()
553
+ : this.properties.pick(this.keys(keys, peer.json, JsonKeys.ROOM))
554
+ }
555
+
556
+ if ((kinds & 0x02) !== 0) {
557
+ const keys = packet.actorProperties
558
+ const wanted =
559
+ packet.actors === null ? null : new Set<number>(packet.actors)
560
+ actors = PhotonHashtable.of()
561
+
562
+ for (const actor of this.active) {
563
+ if (wanted !== null && !wanted.has(actor.number)) continue
564
+
565
+ const table =
566
+ keys === null
567
+ ? actor.properties.all()
568
+ : actor.properties.pick(this.keys(keys, peer.json, JsonKeys.ACTOR))
569
+ if (keys === null && publish) {
570
+ table.set(
571
+ Room.key(ActorProperty.USER_ID),
572
+ PhotonValue.string(actor.userId),
573
+ )
574
+ }
575
+
576
+ actors.set(PhotonValue.int(actor.number), PhotonValue.hashtable(table))
577
+ }
578
+ }
579
+
580
+ peer.send(GetPropertiesResponse.success(actors, game).to(packet))
581
+ }
582
+
583
+ /**
584
+ * Moves a connection in and out of interest groups
585
+ * @param peer who's changing its groups
586
+ * @param packet what the client sent
587
+ */
588
+ public regroup(peer: GamePeer, packet: ChangeGroupsRequest): void {
589
+ const actor = this.playing(peer)
590
+ if (actor === null) return
591
+
592
+ if (packet.remove !== null) this.groups.remove(actor, packet.remove)
593
+ if (packet.add !== null) this.groups.add(actor, packet.add)
594
+ }
595
+
596
+ /**
597
+ * Drops connections that went quiet for too long
598
+ */
599
+ public check(): void {
600
+ const configuration = this.services.configuration
601
+ const now = this.services.clock.now()
602
+ const quiet = configuration.lastTouchLimit * 1000
603
+ const idle = configuration.noActivityLimit * 3_600_000
604
+
605
+ for (const actor of [...this.active]) {
606
+ const peer = actor.peer
607
+ if (peer === null) continue
608
+ if (now - peer.touched <= quiet && now - peer.operated <= idle) continue
609
+
610
+ peer.reason = LeaveReason.PEER_LAST_TOUCH_TIMEDOUT
611
+ this.disconnected(peer)
612
+ peer.drop()
613
+ }
614
+ }
615
+
616
+ /**
617
+ * Everything the Master needs to list the room from nothing
618
+ */
619
+ public describe(): GameChanges {
620
+ const herald = this.services.herald
621
+ const everyone = [...this.active, ...this.inactive]
622
+
623
+ return {
624
+ reinitialize: true,
625
+ newUsers: everyone.map<string>((actor: Actor): string => actor.userId),
626
+ inactiveUsers: this.inactive.map<string>(
627
+ (actor: Actor): string => actor.userId,
628
+ ),
629
+ expectedUsers: [...this.expected],
630
+ maxPlayers: this.maxPlayers,
631
+ isOpen: this.isOpen,
632
+ isVisible: this.isVisible,
633
+ excludedUsers: [...this.excluded],
634
+ checkUserIdOnJoin: this.has(RoomOptionFlag.CHECK_USER_ON_JOIN),
635
+ propertyFilter: this.filter === null ? null : herald.filter(this.filter),
636
+ properties: herald.properties(this.listed(this.properties.all())),
637
+ }
638
+ }
639
+
640
+ /**
641
+ * Tells the Master something about the room
642
+ * @param changes what's new
643
+ */
644
+ public report(changes: GameChanges): void {
645
+ this.services.herald.update(this.summary(), changes)
646
+ }
647
+
648
+ /**
649
+ * A line about the room for whoever debugs it
650
+ */
651
+ public debug(): string {
652
+ return (
653
+ `Game ${this.name}: ` +
654
+ `actors=${String(this.active.length)}, ` +
655
+ `inactive=${String(this.inactive.length)}, ` +
656
+ `master=${String(this.master)}, ` +
657
+ `open=${String(this.isOpen)}, ` +
658
+ `visible=${String(this.isVisible)}, ` +
659
+ `cached=${String(this.roomCache.size)}`
660
+ )
661
+ }
662
+
663
+ /**
664
+ * Lets go of a connection and closes the room if nobody holds it
665
+ * @param peer who's letting go
666
+ */
667
+ public release(peer: GamePeer): void {
668
+ if (!this.references.delete(peer)) return
669
+ if (peer.room === this) peer.room = null
670
+ if (this.references.size > 0 || this.closed) return
671
+
672
+ const wait = this.emptyRoomTtl
673
+ if (wait <= 0) {
674
+ this.close()
675
+ return
676
+ }
677
+
678
+ this.removal?.cancel()
679
+ this.removal = this.services.clock.after(wait, (): void => {
680
+ this.removal = null
681
+ if (this.references.size > 0 || this.active.length > 0) return
682
+ this.close()
683
+ })
684
+ }
685
+
686
+ /**
687
+ * Ends the room and tells the Master
688
+ */
689
+ public close(): void {
690
+ if (this.closed) return
691
+ this.closed = true
692
+
693
+ this.removal?.cancel()
694
+ this.removal = null
695
+ for (const actor of this.inactive) {
696
+ actor.expiry?.cancel()
697
+ actor.expiry = null
698
+ }
699
+
700
+ this.services.herald.remove(this.application, this.version, this.name)
701
+ this.dispose(this)
702
+ }
703
+
704
+ /**
705
+ * Stops every wait without telling anyone
706
+ */
707
+ public halt(): void {
708
+ this.closed = true
709
+ this.removal?.cancel()
710
+ this.removal = null
711
+
712
+ for (const actor of this.inactive) {
713
+ actor.expiry?.cancel()
714
+ actor.expiry = null
715
+ }
716
+ }
717
+
718
+ /**
719
+ * Everything the room needs to come back later
720
+ */
721
+ protected snapshot(): RoomSnapshot {
722
+ const everyone = [...this.active, ...this.inactive]
723
+ const properties = PhotonHashtable.of()
724
+ for (const [key, value] of this.properties.all().entries()) {
725
+ if (!Room.wellKnown(key)) properties.set(key, value)
726
+ }
727
+
728
+ const groups = new Map<number, readonly number[]>()
729
+ for (const id of this.groups.ids()) {
730
+ groups.set(
731
+ id,
732
+ everyone
733
+ .filter((actor: Actor): boolean => actor.groups.has(id))
734
+ .map<number>((actor: Actor): number => actor.number),
735
+ )
736
+ }
737
+
738
+ return {
739
+ counter: this.counter,
740
+ actors: everyone.map<ActorSnapshot>((actor: Actor): ActorSnapshot => ({
741
+ number: actor.number,
742
+ userId: actor.userId,
743
+ active: actor.active,
744
+ properties: actor.properties.all(),
745
+ deactivatedAt: actor.deactivatedAt,
746
+ })),
747
+ properties,
748
+ slices: this.roomCache.filled(),
749
+ groups,
750
+ emptyRoomTtl: this.emptyRoomTtl,
751
+ isOpen: this.isOpen,
752
+ isVisible: this.isVisible,
753
+ lobbyId: this.lobby?.name ?? null,
754
+ lobbyType: this.lobby?.type ?? 0,
755
+ lobbyProperties: this.filter,
756
+ maxPlayers: this.maxPlayers,
757
+ playerTtl: this.playerTtl,
758
+ slice: this.roomCache.current,
759
+ flags: this.flags,
760
+ excluded: this.excluded,
761
+ expected: this.expected,
762
+ }
763
+ }
764
+
765
+ /**
766
+ * Brings back a saved room with every seat empty
767
+ * @param snapshot the room as it was saved
768
+ */
769
+ protected restore(snapshot: RoomSnapshot): void {
770
+ this.counter = snapshot.counter
771
+ for (const saved of snapshot.actors ?? []) {
772
+ this.inactive.push(
773
+ Actor.away(
774
+ saved.number,
775
+ saved.userId,
776
+ saved.properties,
777
+ saved.deactivatedAt,
778
+ ),
779
+ )
780
+ }
781
+
782
+ if (snapshot.properties !== null) {
783
+ this.properties.merge(snapshot.properties)
784
+ }
785
+
786
+ this.roomCache.load(snapshot.slices, snapshot.slice)
787
+ for (const [id, numbers] of snapshot.groups ?? []) {
788
+ for (const number of numbers) {
789
+ this.groups.recall(this.numbered(number), id)
790
+ }
791
+ }
792
+
793
+ this.flags = snapshot.flags
794
+ this.properties.deleteNull = this.has(RoomOptionFlag.DELETE_NULL_PROPS)
795
+ this.revive(snapshot)
796
+
797
+ this.lobby =
798
+ snapshot.lobbyId === null
799
+ ? null
800
+ : Lobby.of(snapshot.lobbyId, snapshot.lobbyType)
801
+ if (snapshot.lobbyProperties !== null) {
802
+ this.filter = snapshot.lobbyProperties
803
+ }
804
+
805
+ this.master = 0
806
+ this.excluded = [...snapshot.excluded]
807
+ this.expected = [...snapshot.expected]
808
+ }
809
+
810
+ /**
811
+ * Writes the well-known properties of a saved room
812
+ * @param snapshot the room as it was saved
813
+ */
814
+ private revive(snapshot: RoomSnapshot): void {
815
+ const properties = PhotonHashtable.of()
816
+ .set(Room.key(GameProperty.IS_OPEN), PhotonValue.bool(snapshot.isOpen))
817
+ .set(
818
+ Room.key(GameProperty.IS_VISIBLE),
819
+ PhotonValue.bool(snapshot.isVisible),
820
+ )
821
+ .set(Room.key(GameProperty.MASTER_CLIENT_ID), PhotonValue.int(0))
822
+
823
+ if (snapshot.emptyRoomTtl !== 0) {
824
+ properties.set(
825
+ Room.key(GameProperty.EMPTY_ROOM_TTL),
826
+ PhotonValue.int(snapshot.emptyRoomTtl),
827
+ )
828
+ }
829
+
830
+ if (snapshot.maxPlayers !== 0) {
831
+ properties.set(
832
+ Room.key(GameProperty.MAX_PLAYERS),
833
+ PhotonValue.byte(snapshot.maxPlayers & 0xff),
834
+ )
835
+ }
836
+
837
+ if (snapshot.playerTtl !== 0) {
838
+ properties.set(
839
+ Room.key(GameProperty.PLAYER_TTL),
840
+ PhotonValue.int(snapshot.playerTtl),
841
+ )
842
+ }
843
+
844
+ if (snapshot.expected.length > 0) {
845
+ properties.set(
846
+ Room.key(GameProperty.EXPECTED_USERS),
847
+ Room.names(snapshot.expected),
848
+ )
849
+ }
850
+
851
+ this.properties.merge(properties)
852
+ }
853
+
854
+ /**
855
+ * Starts the wait of every empty seat of a saved room
856
+ */
857
+ protected vacate(): void {
858
+ const ttl = this.playerTtl
859
+ const now = this.services.clock.now()
860
+ if (ttl <= 0 || ttl >= Room.FOREVER) return
861
+
862
+ for (const actor of [...this.inactive]) {
863
+ const left = actor.deactivatedAt ?? now
864
+ actor.deactivatedAt = left
865
+
866
+ if (left + ttl <= now) {
867
+ this.expire(actor)
868
+ continue
869
+ }
870
+
871
+ actor.expiry = this.services.clock.after(left + ttl - now, (): void => {
872
+ this.expire(actor)
873
+ })
874
+ }
875
+ }
876
+
877
+ /**
878
+ * Most players allowed, 0 for any number
879
+ */
880
+ private get maxPlayers(): number {
881
+ return this.number(GameProperty.MAX_PLAYERS) ?? 0
882
+ }
883
+
884
+ /**
885
+ * Whether players may join
886
+ */
887
+ private get isOpen(): boolean {
888
+ return this.flag(GameProperty.IS_OPEN) ?? true
889
+ }
890
+
891
+ /**
892
+ * Whether lobbies list it
893
+ */
894
+ private get isVisible(): boolean {
895
+ return this.flag(GameProperty.IS_VISIBLE) ?? true
896
+ }
897
+
898
+ /**
899
+ * How long a player's seat is kept in ms
900
+ */
901
+ protected get playerTtl(): number {
902
+ return this.number(GameProperty.PLAYER_TTL) ?? 0
903
+ }
904
+
905
+ /**
906
+ * How long the empty room stays in ms
907
+ */
908
+ private get emptyRoomTtl(): number {
909
+ return this.number(GameProperty.EMPTY_ROOM_TTL) ?? 0
910
+ }
911
+
912
+ /**
913
+ * Whether a cache passed its limit
914
+ */
915
+ private get discarded(): boolean {
916
+ return this.roomCache.discarded || this.actorCache.discarded
917
+ }
918
+
919
+ /**
920
+ * Whether players hear nothing about each other
921
+ */
922
+ private get quiet(): boolean {
923
+ return this.has(RoomOptionFlag.SUPPRESS_PLAYER_INFO)
924
+ }
925
+
926
+ /**
927
+ * Whether join and leave events stay unsent
928
+ */
929
+ private get suppressed(): boolean {
930
+ return this.quiet || this.has(RoomOptionFlag.SUPPRESS_ROOM_EVENTS)
931
+ }
932
+
933
+ /**
934
+ * User ids with a seat kept that never showed up
935
+ */
936
+ private get awaited(): number {
937
+ return this.pending(this.expected)
938
+ }
939
+
940
+ /**
941
+ * Numbers of the connected actors in the order they came
942
+ */
943
+ private get numbers(): readonly number[] {
944
+ return this.active.map<number>((actor: Actor): number => actor.number)
945
+ }
946
+
947
+ /**
948
+ * Whether a room option is on
949
+ * @param bit which option
950
+ */
951
+ private has(bit: number): boolean {
952
+ return (this.flags & bit) !== 0
953
+ }
954
+
955
+ /**
956
+ * A whole number property of the room, or null
957
+ * @param code which property
958
+ */
959
+ private number(code: number): number | null {
960
+ return this.properties.get(Room.key(code))?.integer() ?? null
961
+ }
962
+
963
+ /**
964
+ * A yes or no property of the room, or null
965
+ * @param code which property
966
+ */
967
+ private flag(code: number): boolean | null {
968
+ return this.properties.get(Room.key(code))?.flag() ?? null
969
+ }
970
+
971
+ /**
972
+ * Which game this is and how full
973
+ */
974
+ private summary(): GameSummary {
975
+ return {
976
+ application: this.application,
977
+ version: this.version,
978
+ game: this.name,
979
+ lobby: this.lobby?.name ?? null,
980
+ lobbyType: this.lobby?.type ?? 0,
981
+ actorCount: this.active.length,
982
+ inactiveCount: this.inactive.length,
983
+ }
984
+ }
985
+
986
+ /**
987
+ * How many of some user ids have no actor
988
+ * @param users user ids to look for
989
+ */
990
+ private pending(users: readonly string[]): number {
991
+ return users.filter((user: string): boolean => this.user(user) === null)
992
+ .length
993
+ }
994
+
995
+ /**
996
+ * The connected actor of a connection, or null
997
+ * @param peer the connection
998
+ */
999
+ protected playing(peer: GamePeer): Actor | null {
1000
+ return this.seats.get(peer) ?? null
1001
+ }
1002
+
1003
+ /**
1004
+ * The actor with a number, connected or away, or null
1005
+ * @param number actor number
1006
+ */
1007
+ private numbered(number: number): Actor | null {
1008
+ for (const actor of this.active) {
1009
+ if (actor.number === number) return actor
1010
+ }
1011
+
1012
+ for (const actor of this.inactive) {
1013
+ if (actor.number === number) return actor
1014
+ }
1015
+
1016
+ return null
1017
+ }
1018
+
1019
+ /**
1020
+ * The actor of a user, connected or away, or null
1021
+ * @param userId who to look for
1022
+ */
1023
+ private user(userId: string): Actor | null {
1024
+ return (
1025
+ [...this.active, ...this.inactive].find(
1026
+ (actor: Actor): boolean => actor.userId === userId,
1027
+ ) ?? null
1028
+ )
1029
+ }
1030
+
1031
+ /**
1032
+ * Sends one packet to several actors
1033
+ * @param actors who gets it
1034
+ * @param packet a typed packet
1035
+ */
1036
+ protected tell(actors: readonly Actor[], packet: unknown): void {
1037
+ const shared = actors.length > 1 ? this.services.shared : null
1038
+ let frame: Uint8Array | null = null
1039
+ let framed = false
1040
+
1041
+ for (const actor of [...actors]) {
1042
+ const peer = actor.peer
1043
+ if (
1044
+ shared === null ||
1045
+ peer === null ||
1046
+ !SharedFrames.reads(peer.channel)
1047
+ ) {
1048
+ actor.send(packet)
1049
+ continue
1050
+ }
1051
+
1052
+ if (!framed) {
1053
+ frame = shared.frame(packet)
1054
+ framed = true
1055
+ }
1056
+
1057
+ if (frame === null) actor.send(packet)
1058
+ else peer.pass(frame)
1059
+ }
1060
+ }
1061
+
1062
+ /**
1063
+ * Why a request can't start this room, or null
1064
+ * @param setup the request as the room needs it
1065
+ */
1066
+ private founding(setup: EntrySetup): Fault | null {
1067
+ if (!this.creatable(setup)) {
1068
+ return Fault.of(
1069
+ ErrorCode.GAME_DOES_NOT_EXIST,
1070
+ ErrorMessage.GAME_ID_DOES_NOT_EXIST,
1071
+ )
1072
+ }
1073
+
1074
+ const plugins = setup.plugins
1075
+ if (plugins === null) return null
1076
+ if (plugins.length > 1) {
1077
+ return Fault.of(
1078
+ ErrorCode.PLUGIN_MISMATCH,
1079
+ 'Currently only one plugin per game supported.',
1080
+ )
1081
+ }
1082
+
1083
+ return this.mismatch(plugins[0] ?? null)
1084
+ }
1085
+
1086
+ /**
1087
+ * Whether a request may start this room
1088
+ * @param setup the request as the room needs it
1089
+ */
1090
+ protected creatable(setup: EntrySetup): boolean {
1091
+ return setup.creating || setup.mode === JoinMode.CREATE_IF_NOT_EXISTS
1092
+ }
1093
+
1094
+ /**
1095
+ * Why the room's plugin isn't the one a request names, or null
1096
+ * @param wanted plugin the request names, null for none
1097
+ */
1098
+ protected mismatch(wanted: string | null): Fault | null {
1099
+ if (wanted === null || wanted === 'Default') return null
1100
+
1101
+ return wanted === ''
1102
+ ? Fault.of(
1103
+ ErrorCode.PLUGIN_MISMATCH,
1104
+ "Plugin Mismatch requested='{0}' got='{1}'",
1105
+ wanted,
1106
+ 'Default',
1107
+ )
1108
+ : Fault.of(
1109
+ ErrorCode.PLUGIN_MISMATCH,
1110
+ "Plugin Mismatch requested='{0}' got ErrorPlugin with message:'{1}'",
1111
+ wanted,
1112
+ 'PluginManager initialization failed.',
1113
+ )
1114
+ }
1115
+
1116
+ /**
1117
+ * Why a connection can't get into this room, or null
1118
+ * @param peer who's asking
1119
+ * @param setup the request as the room needs it
1120
+ */
1121
+ private admission(peer: GamePeer, setup: EntrySetup): Fault | null {
1122
+ const userId = peer.userId
1123
+ const awaited = this.expected.includes(userId)
1124
+
1125
+ if (setup.rejoining) {
1126
+ const fault = this.rejoin(peer, setup)
1127
+ if (fault !== undefined) return fault
1128
+ if (awaited) {
1129
+ return Fault.denied(ErrorMessage.REJOIN_OR_JOIN_WITH_EXPECTED_PLAYER)
1130
+ }
1131
+ }
1132
+
1133
+ if (!this.isOpen) {
1134
+ return Fault.of(
1135
+ ErrorCode.GAME_CLOSED,
1136
+ this.discarded
1137
+ ? ErrorMessage.GAME_CLOSED_CACHE_DISCARDED
1138
+ : ErrorMessage.GAME_CLOSED,
1139
+ )
1140
+ }
1141
+
1142
+ const limit = this.maxPlayers
1143
+ const taken = this.active.length + this.inactive.length + this.awaited
1144
+ if (limit > 0 && taken >= limit && !awaited) {
1145
+ return Fault.of(ErrorCode.GAME_FULL, ErrorMessage.GAME_FULL)
1146
+ }
1147
+
1148
+ return null
1149
+ }
1150
+
1151
+ /**
1152
+ * How a rejoin request fares, undefined to go on as a plain join
1153
+ * @param peer who's asking
1154
+ * @param setup the request as the room needs it
1155
+ */
1156
+ private rejoin(peer: GamePeer, setup: EntrySetup): Fault | null | undefined {
1157
+ if (this.discarded) {
1158
+ return Fault.of(
1159
+ ErrorCode.EVENT_CACHE_EXCEEDED,
1160
+ ErrorMessage.REJOINING_BLOCKED_CACHE_EXCEEDED,
1161
+ )
1162
+ }
1163
+
1164
+ const lasting = this.playerTtl !== 0
1165
+ const only = setup.mode === JoinMode.REJOIN_ONLY
1166
+ if (!lasting && only) {
1167
+ return Fault.denied(ErrorMessage.REJOIN_NOT_SUPPORTED)
1168
+ }
1169
+
1170
+ const named = this.has(RoomOptionFlag.CHECK_USER_ON_JOIN)
1171
+ const actor = named
1172
+ ? this.user(peer.userId)
1173
+ : this.numbered(setup.actorNumber)
1174
+ if (actor !== null) {
1175
+ return lasting || only
1176
+ ? null
1177
+ : Fault.denied(ErrorMessage.REJOIN_NOT_SUPPORTED)
1178
+ }
1179
+
1180
+ if (!only) return undefined
1181
+
1182
+ return named
1183
+ ? Fault.of(
1184
+ ErrorCode.JOIN_FAILED_WITH_REJOINER_NOT_FOUND,
1185
+ ErrorMessage.USER_NOT_FOUND,
1186
+ )
1187
+ : Fault.of(
1188
+ ErrorCode.JOIN_FAILED_WITH_REJOINER_NOT_FOUND,
1189
+ ErrorMessage.ACTOR_NOT_FOUND,
1190
+ setup.actorNumber,
1191
+ )
1192
+ }
1193
+
1194
+ /**
1195
+ * The seat a connection comes back to, null for a new one, or why it can't sit
1196
+ * @param peer who's asking
1197
+ * @param setup the request as the room needs it
1198
+ */
1199
+ private seat(peer: GamePeer, setup: EntrySetup): Actor | Fault | null {
1200
+ if (this.playing(peer) !== null) {
1201
+ return Fault.of(
1202
+ ErrorCode.JOIN_FAILED_PEER_ALREADY_JOINED,
1203
+ 'Join failed: Peer already joined the specified game.',
1204
+ )
1205
+ }
1206
+
1207
+ const found = this.has(RoomOptionFlag.CHECK_USER_ON_JOIN)
1208
+ ? this.seatByUser(peer, setup)
1209
+ : this.seatByNumber(peer, setup)
1210
+ if (found !== null) return found
1211
+
1212
+ return setup.mode === JoinMode.REJOIN_ONLY
1213
+ ? Fault.of(
1214
+ ErrorCode.JOIN_FAILED_WITH_REJOINER_NOT_FOUND,
1215
+ 'Rejoin failed: userid={0} not found, actor nr={1}.',
1216
+ peer.userId,
1217
+ setup.actorNumber,
1218
+ )
1219
+ : null
1220
+ }
1221
+
1222
+ /**
1223
+ * The seat of a connection's user id, null for none, or why it can't sit
1224
+ * @param peer who's asking
1225
+ * @param setup the request as the room needs it
1226
+ */
1227
+ private seatByUser(peer: GamePeer, setup: EntrySetup): Actor | Fault | null {
1228
+ const userId = peer.userId
1229
+ if (userId === '') {
1230
+ return Fault.invalid(
1231
+ 'Join failed: UserId is not set, checkUserIdOnJoin=true expects a UserId.',
1232
+ )
1233
+ }
1234
+
1235
+ const ban = this.excluded.find(
1236
+ (user: ExcludedUser): boolean => user.userId === userId,
1237
+ )
1238
+ if (ban !== undefined) return Room.banned(ban)
1239
+
1240
+ const actor = this.user(userId)
1241
+ if (actor === null) return null
1242
+
1243
+ if (actor.active) {
1244
+ return this.takeover(actor, peer, setup, setup.forceRejoin)
1245
+ ? actor
1246
+ : Fault.of(
1247
+ ErrorCode.JOIN_FAILED_FOUND_ACTIVE_JOINER,
1248
+ ErrorMessage.USER_ALREADY_JOINED,
1249
+ userId,
1250
+ setup.mode,
1251
+ )
1252
+ }
1253
+
1254
+ if (this.expired(actor)) {
1255
+ return Fault.of(
1256
+ ErrorCode.JOIN_FAILED_WITH_REJOINER_NOT_FOUND,
1257
+ "Join failed: UserId '{0}' is expired (JoinMode={1}).",
1258
+ userId,
1259
+ setup.mode,
1260
+ )
1261
+ }
1262
+
1263
+ return setup.rejoining
1264
+ ? actor
1265
+ : Fault.of(
1266
+ ErrorCode.JOIN_FAILED_FOUND_INACTIVE_JOINER,
1267
+ "Found inactive UserId '{0}', but not rejoining (JoinMode={1}).",
1268
+ userId,
1269
+ setup.mode,
1270
+ )
1271
+ }
1272
+
1273
+ /**
1274
+ * The seat a request names by number, null for none, or why it can't sit
1275
+ * @param peer who's asking
1276
+ * @param setup the request as the room needs it
1277
+ */
1278
+ private seatByNumber(
1279
+ peer: GamePeer,
1280
+ setup: EntrySetup,
1281
+ ): Actor | Fault | null {
1282
+ const number = setup.actorNumber
1283
+ if (number <= 0) return null
1284
+
1285
+ const actor = this.numbered(number)
1286
+ if (actor === null) {
1287
+ return Fault.of(
1288
+ ErrorCode.JOIN_FAILED_WITH_REJOINER_NOT_FOUND,
1289
+ 'Rejoin failed: actor nr={0} not found.',
1290
+ number,
1291
+ )
1292
+ }
1293
+
1294
+ if (actor.active) {
1295
+ return this.takeover(actor, peer, setup, false)
1296
+ ? actor
1297
+ : Fault.of(
1298
+ ErrorCode.JOIN_FAILED_FOUND_ACTIVE_JOINER,
1299
+ ErrorMessage.USER_WITH_ACTOR_ID_ALREADY_JOINED,
1300
+ number,
1301
+ setup.mode,
1302
+ )
1303
+ }
1304
+
1305
+ const strangers =
1306
+ actor.userId !== peer.userId &&
1307
+ !(Room.GUID.test(actor.userId) && Room.GUID.test(peer.userId))
1308
+ if (strangers) {
1309
+ return Fault.internal(
1310
+ "Rejoin failed: userId of peer doesn't match userid of actor.",
1311
+ )
1312
+ }
1313
+
1314
+ if (this.expired(actor)) {
1315
+ return Fault.of(
1316
+ ErrorCode.JOIN_FAILED_WITH_REJOINER_NOT_FOUND,
1317
+ "Join failed: ActorNr '{0}' is expired.",
1318
+ number,
1319
+ )
1320
+ }
1321
+
1322
+ return setup.rejoining
1323
+ ? actor
1324
+ : Fault.internal(
1325
+ "Found inactive ActorNr '{0}', but not rejoining (JoinMode={1}).",
1326
+ number,
1327
+ setup.mode,
1328
+ )
1329
+ }
1330
+
1331
+ /**
1332
+ * Whether a seat's time away has run out
1333
+ * @param actor the seat
1334
+ */
1335
+ private expired(actor: Actor): boolean {
1336
+ const ttl = this.playerTtl
1337
+ const since = actor.deactivatedAt
1338
+ if (ttl <= 0 || ttl >= Room.FOREVER || since === null) return false
1339
+
1340
+ return this.services.clock.now() - since > ttl
1341
+ }
1342
+
1343
+ /**
1344
+ * Frees a taken seat for a second connection of the same login
1345
+ * @param actor the seat
1346
+ * @param peer who's asking
1347
+ * @param setup the request as the room needs it
1348
+ * @param forced whether the request insists
1349
+ */
1350
+ private takeover(
1351
+ actor: Actor,
1352
+ peer: GamePeer,
1353
+ setup: EntrySetup,
1354
+ forced: boolean,
1355
+ ): boolean {
1356
+ const holder = actor.peer
1357
+ if (holder === null || this.playerTtl === 0 || !setup.rejoining) {
1358
+ return false
1359
+ }
1360
+
1361
+ const first = holder.token
1362
+ const second = peer.token
1363
+ const same =
1364
+ first !== null &&
1365
+ second !== null &&
1366
+ this.services.authenticator.same(first, second)
1367
+ if (!forced && !same) return false
1368
+
1369
+ this.groups.suspend(actor)
1370
+ if (actor.peer !== null) this.seats.delete(actor.peer)
1371
+ actor.peer = null
1372
+ actor.deactivatedAt = this.services.clock.now()
1373
+ this.active.splice(this.active.indexOf(actor), 1)
1374
+ this.inactive.push(actor)
1375
+
1376
+ this.references.delete(holder)
1377
+ holder.room = null
1378
+ holder.drop()
1379
+
1380
+ return true
1381
+ }
1382
+
1383
+ /**
1384
+ * Gives a connection a new seat
1385
+ * @param peer who sits down
1386
+ */
1387
+ private add(peer: GamePeer): Actor {
1388
+ this.counter += 1
1389
+
1390
+ const actor = Actor.of(this.counter, peer)
1391
+ this.active.push(actor)
1392
+ this.seats.set(peer, actor)
1393
+
1394
+ return actor
1395
+ }
1396
+
1397
+ /**
1398
+ * Gives a connection its old seat back
1399
+ * @param actor the seat
1400
+ * @param peer who sits down
1401
+ */
1402
+ private reactivate(actor: Actor, peer: GamePeer): Actor {
1403
+ actor.expiry?.cancel()
1404
+ actor.expiry = null
1405
+ actor.peer = peer
1406
+ actor.deactivatedAt = null
1407
+
1408
+ this.inactive.splice(this.inactive.indexOf(actor), 1)
1409
+ this.active.push(actor)
1410
+ this.seats.set(peer, actor)
1411
+ this.groups.resume(actor)
1412
+
1413
+ return actor
1414
+ }
1415
+
1416
+ /**
1417
+ * Makes the connected actor with the lowest number the master client
1418
+ */
1419
+ private elect(): void {
1420
+ this.master = this.numbers.reduce<number>(
1421
+ (lowest: number, number: number): number =>
1422
+ lowest === 0 || number < lowest ? number : lowest,
1423
+ 0,
1424
+ )
1425
+ this.properties.set(
1426
+ Room.key(GameProperty.MASTER_CLIENT_ID),
1427
+ PhotonValue.int(this.master),
1428
+ )
1429
+ }
1430
+
1431
+ /**
1432
+ * Takes over the options of the request that made the room, or says why not
1433
+ * @param setup the request as the room needs it
1434
+ */
1435
+ private furnish(setup: EntrySetup): Fault | null {
1436
+ const longest = this.services.configuration.maxEmptyRoomTtl
1437
+
1438
+ this.flags = setup.flags
1439
+ this.properties.deleteNull = this.has(RoomOptionFlag.DELETE_NULL_PROPS)
1440
+ if (setup.emptyRoomTtl > longest) {
1441
+ return Fault.invalid(
1442
+ ErrorMessage.MAX_TTL_EXCEEDED,
1443
+ setup.emptyRoomTtl,
1444
+ longest,
1445
+ )
1446
+ }
1447
+
1448
+ this.properties.merge(setup.properties)
1449
+ if (setup.expectedUsers !== null) {
1450
+ this.properties.set(
1451
+ Room.key(GameProperty.EXPECTED_USERS),
1452
+ Room.names(setup.expectedUsers),
1453
+ )
1454
+ }
1455
+
1456
+ if (setup.emptyRoomTtl !== 0) {
1457
+ this.properties.set(
1458
+ Room.key(GameProperty.EMPTY_ROOM_TTL),
1459
+ PhotonValue.int(setup.emptyRoomTtl),
1460
+ )
1461
+ }
1462
+
1463
+ if (setup.playerTtl !== 0) {
1464
+ this.properties.set(
1465
+ Room.key(GameProperty.PLAYER_TTL),
1466
+ PhotonValue.int(setup.playerTtl),
1467
+ )
1468
+ }
1469
+
1470
+ return null
1471
+ }
1472
+
1473
+ /**
1474
+ * Keeps seats for some users and says who's new, or null if there's no room
1475
+ * @param users user ids to keep a seat for
1476
+ */
1477
+ private reserve(users: readonly string[]): readonly string[] | null {
1478
+ const added = users.filter(
1479
+ (user: string): boolean => !this.expected.includes(user),
1480
+ )
1481
+ const limit = this.maxPlayers
1482
+ const taken = this.active.length + this.awaited + this.pending(added)
1483
+ if (limit !== 0 && taken > limit) return null
1484
+
1485
+ let seats = this.active.length + this.inactive.length + this.awaited
1486
+ for (const user of added) {
1487
+ if (this.user(user) !== null) continue
1488
+ if (limit !== 0 && seats === limit) return null
1489
+ seats += 1
1490
+ }
1491
+
1492
+ this.expected.push(...added)
1493
+ return added
1494
+ }
1495
+
1496
+ /**
1497
+ * Remembers which properties lobbies show
1498
+ * @param properties room properties of a request
1499
+ */
1500
+ private list(properties: PhotonHashtable): void {
1501
+ const key = Room.key(GameProperty.PROPS_LISTED_IN_LOBBY)
1502
+ if (!properties.has(key)) return
1503
+
1504
+ this.filter = WellKnownProperties.filter(properties.get(key))
1505
+ }
1506
+
1507
+ /**
1508
+ * The properties of a table that lobbies show
1509
+ * @param table properties to pick from
1510
+ */
1511
+ private listed(table: PhotonHashtable): PhotonHashtable {
1512
+ const filter = this.filter
1513
+ const shown =
1514
+ filter === null
1515
+ ? null
1516
+ : new Set<string | null>(
1517
+ filter.map<string | null>(
1518
+ (key: PhotonValue): string | null => key.identity,
1519
+ ),
1520
+ )
1521
+ const hidden = new Set<string | null>(
1522
+ [
1523
+ GameProperty.MAX_PLAYERS,
1524
+ GameProperty.IS_OPEN,
1525
+ GameProperty.IS_VISIBLE,
1526
+ GameProperty.PROPS_LISTED_IN_LOBBY,
1527
+ ].map<string | null>(
1528
+ (code: number): string | null => Room.key(code).identity,
1529
+ ),
1530
+ )
1531
+ const listed = PhotonHashtable.of()
1532
+
1533
+ for (const [key, value] of table.entries()) {
1534
+ const identity = key.identity
1535
+ if (shown === null ? hidden.has(identity) : !shown.has(identity)) continue
1536
+ listed.set(key, value)
1537
+ }
1538
+
1539
+ return listed
1540
+ }
1541
+
1542
+ /**
1543
+ * What a joiner learns about the room
1544
+ * @param joiner who got in
1545
+ * @param setup the request as the room needs it
1546
+ */
1547
+ private entry(joiner: Actor, setup: EntrySetup): RoomEntry {
1548
+ const publish = this.has(RoomOptionFlag.PUBLISH_USER_ID)
1549
+ const everyone = [...this.active, ...this.inactive]
1550
+ const players = PhotonHashtable.of()
1551
+
1552
+ for (const actor of this.quiet ? [] : everyone) {
1553
+ const self = actor === joiner && !(setup.rejoining && actor.active)
1554
+ if (self || (actor.properties.size === 0 && !publish)) continue
1555
+
1556
+ const table = actor.properties.all()
1557
+ if (!actor.active) {
1558
+ table.set(Room.key(ActorProperty.IS_INACTIVE), PhotonValue.bool(true))
1559
+ }
1560
+
1561
+ if (publish) {
1562
+ table.set(
1563
+ Room.key(ActorProperty.USER_ID),
1564
+ PhotonValue.string(actor.userId),
1565
+ )
1566
+ }
1567
+
1568
+ players.set(PhotonValue.int(actor.number), PhotonValue.hashtable(table))
1569
+ }
1570
+
1571
+ return RoomEntry.of(
1572
+ joiner.number,
1573
+ this.suppressed
1574
+ ? null
1575
+ : everyone.map<number>((actor: Actor): number => actor.number),
1576
+ this.properties.all(),
1577
+ players.size === 0 ? null : players,
1578
+ this.flags,
1579
+ )
1580
+ }
1581
+
1582
+ /**
1583
+ * Tells every connected actor who got in
1584
+ * @param joiner who got in
1585
+ * @param setup the request as the room needs it
1586
+ */
1587
+ private announce(joiner: Actor, setup: EntrySetup): void {
1588
+ if (this.suppressed) return
1589
+
1590
+ let properties: PhotonHashtable | null = null
1591
+ if (setup.broadcast) {
1592
+ properties = PropertyBag.copy(setup.actorProperties)
1593
+ if (this.has(RoomOptionFlag.PUBLISH_USER_ID)) {
1594
+ properties.set(
1595
+ Room.key(ActorProperty.USER_ID),
1596
+ PhotonValue.string(joiner.userId),
1597
+ )
1598
+ }
1599
+ }
1600
+
1601
+ this.tell(
1602
+ this.active,
1603
+ JoinEvent.of(joiner.number, this.numbers, properties),
1604
+ )
1605
+ }
1606
+
1607
+ /**
1608
+ * Sends a joiner every cached event
1609
+ * @param peer who got in
1610
+ * @param from first room cache slice to send
1611
+ */
1612
+ private replay(peer: GamePeer, from: number): void {
1613
+ for (const event of this.actorCache.replay()) {
1614
+ peer.send(CustomEvent.of(event.code, event.actor, event.data))
1615
+ }
1616
+
1617
+ for (const slice of this.roomCache.replay(from)) {
1618
+ if (slice.index !== 0) {
1619
+ peer.send(CacheSliceChangedEvent.of(slice.index, 0))
1620
+ }
1621
+
1622
+ for (const event of slice.events) {
1623
+ peer.send(CustomEvent.of(event.code, event.actor, event.data))
1624
+ }
1625
+ }
1626
+ }
1627
+
1628
+ /**
1629
+ * Answers a failed join and undoes what it did
1630
+ * @param peer who was refused
1631
+ * @param setup the request as the room needs it
1632
+ * @param fault why
1633
+ * @param actor the seat it already got, or null
1634
+ */
1635
+ protected reject(
1636
+ peer: GamePeer,
1637
+ setup: EntrySetup,
1638
+ fault: Fault,
1639
+ actor: Actor | null,
1640
+ ): void {
1641
+ peer.send(setup.refuse(fault))
1642
+
1643
+ if (actor === null) {
1644
+ const refused: GameChanges = { failedToAdd: [peer.userId] }
1645
+ this.report(refused)
1646
+ } else {
1647
+ this.remove(actor, true)
1648
+ }
1649
+
1650
+ this.release(peer)
1651
+ peer.part(this.services.clock, this.services.configuration.disconnectDelay)
1652
+ }
1653
+
1654
+ /**
1655
+ * Keeps the seat of an actor that went away
1656
+ * @param actor who went away
1657
+ */
1658
+ private deactivate(actor: Actor): void {
1659
+ const ttl = this.playerTtl
1660
+ const leading = this.master === actor.number
1661
+
1662
+ this.groups.suspend(actor)
1663
+ if (actor.peer !== null) this.seats.delete(actor.peer)
1664
+ actor.peer = null
1665
+ actor.deactivatedAt = this.services.clock.now()
1666
+ this.active.splice(this.active.indexOf(actor), 1)
1667
+ this.inactive.push(actor)
1668
+
1669
+ if (ttl > 0 && ttl < Room.FOREVER) {
1670
+ actor.expiry = this.services.clock.after(ttl, (): void => {
1671
+ this.expire(actor)
1672
+ })
1673
+ }
1674
+
1675
+ if (leading) this.elect()
1676
+ if (!this.suppressed && this.active.length > 0) {
1677
+ this.tell(
1678
+ this.active,
1679
+ LeaveEvent.of(
1680
+ actor.number,
1681
+ this.numbers,
1682
+ true,
1683
+ leading ? this.master : null,
1684
+ ),
1685
+ )
1686
+ }
1687
+
1688
+ const away: GameChanges = { inactiveUsers: [actor.userId] }
1689
+ this.report(away)
1690
+ }
1691
+
1692
+ /**
1693
+ * Takes out an actor whose time away ran out
1694
+ * @param actor who stayed away
1695
+ */
1696
+ protected expire(actor: Actor): void {
1697
+ actor.expiry = null
1698
+ if (this.closed || !this.inactive.includes(actor)) return
1699
+
1700
+ this.remove(actor, false)
1701
+ }
1702
+
1703
+ /**
1704
+ * Takes an actor out for good
1705
+ * @param actor who's out
1706
+ * @param failed whether its join never finished
1707
+ */
1708
+ private remove(actor: Actor, failed: boolean): void {
1709
+ const peer = actor.peer
1710
+ const leading = this.master === actor.number
1711
+ const known = peer === null || peer.stage >= JoinStage.EVENTS_PUBLISHED
1712
+ const list = actor.active ? this.active : this.inactive
1713
+
1714
+ list.splice(list.indexOf(actor), 1)
1715
+ if (this.has(RoomOptionFlag.DELETE_CACHE_ON_LEAVE)) {
1716
+ this.actorCache.forget(actor.number)
1717
+ this.roomCache.forget(actor.number)
1718
+ }
1719
+
1720
+ actor.expiry?.cancel()
1721
+ actor.expiry = null
1722
+ if (actor.peer !== null) this.seats.delete(actor.peer)
1723
+ actor.peer = null
1724
+ this.groups.forget(actor)
1725
+
1726
+ if (leading) this.elect()
1727
+ if (known && !this.suppressed && this.active.length > 0) {
1728
+ this.tell(
1729
+ this.active,
1730
+ LeaveEvent.of(
1731
+ actor.number,
1732
+ this.numbers,
1733
+ false,
1734
+ leading ? this.master : null,
1735
+ ),
1736
+ )
1737
+ }
1738
+
1739
+ const gone: GameChanges = failed
1740
+ ? { failedToAdd: [actor.userId] }
1741
+ : { removedUsers: [actor.userId] }
1742
+ this.report(gone)
1743
+ peer?.part(this.services.clock, this.services.configuration.disconnectDelay)
1744
+ }
1745
+
1746
+ /**
1747
+ * Whether one more forwarded operation is over the limit
1748
+ * @param webFlags web flags of the request, or null
1749
+ */
1750
+ private throttled(webFlags: number | null): boolean {
1751
+ const limit = this.services.configuration.httpForwardLimit
1752
+ if (limit <= 0 || ((webFlags ?? 0) & WebFlag.HTTP_FORWARD) === 0) {
1753
+ return false
1754
+ }
1755
+
1756
+ const second = Math.floor(this.services.clock.now() / 1000)
1757
+ if (second !== this.forwardSecond) {
1758
+ this.forwardSecond = second
1759
+ this.forwardCount = 0
1760
+ }
1761
+
1762
+ this.forwardCount += 1
1763
+ return this.forwardCount > limit
1764
+ }
1765
+
1766
+ /**
1767
+ * Handles a raised event and says why it failed, or null
1768
+ * @param peer who raised it
1769
+ * @param packet what the client sent
1770
+ */
1771
+ private raised(peer: GamePeer, packet: RaiseEventRequest): Fault | null {
1772
+ const everyone = this.active.length + this.inactive.length
1773
+ if ((packet.actors?.length ?? 0) > 2 * everyone) {
1774
+ return Fault.invalid('Actors excceds CurrentPlayers count')
1775
+ }
1776
+
1777
+ const sender = this.playing(peer)
1778
+ if (sender === null) return null
1779
+ if (this.throttled(packet.webFlags)) {
1780
+ return Fault.of(
1781
+ ErrorCode.HTTP_LIMIT_REACHED,
1782
+ ErrorMessage.HTTP_FORWARDED_OPERATIONS_LIMIT_REACHED,
1783
+ )
1784
+ }
1785
+
1786
+ if (packet.eventCode > EventRange.LAST_RAISABLE) {
1787
+ return Fault.invalid(
1788
+ ErrorMessage.SIMULATES_PHOTON_EVENT,
1789
+ EventRange.LAST_RAISABLE,
1790
+ )
1791
+ }
1792
+
1793
+ return this.spread(sender, packet)
1794
+ }
1795
+
1796
+ /**
1797
+ * Carries out a raised event that passed its checks, or says why not
1798
+ * @param sender who raised it
1799
+ * @param packet what the client sent
1800
+ */
1801
+ protected spread(sender: Actor, packet: RaiseEventRequest): Fault | null {
1802
+ const targets = [...new Set<number>(packet.actors ?? [])]
1803
+ const caching = packet.caching
1804
+ if (caching >= EventCaching.SLICE_INCREASE_INDEX) {
1805
+ return this.slice(sender, packet)
1806
+ }
1807
+
1808
+ if (caching === EventCaching.REMOVE_FROM_ROOM_CACHE) {
1809
+ this.roomCache.remove(packet.eventCode, packet.actors, packet.data)
1810
+ sender.send(RaiseEventResponse.success().to(packet))
1811
+ return null
1812
+ }
1813
+
1814
+ if (caching === EventCaching.REMOVE_FROM_ROOM_CACHE_FOR_ACTORS_LEFT) {
1815
+ this.roomCache.prune(new Set<number>(this.numbers))
1816
+ sender.send(RaiseEventResponse.success().to(packet))
1817
+ return null
1818
+ }
1819
+
1820
+ let recipients: readonly Actor[]
1821
+ let cacheable = false
1822
+
1823
+ if (targets.length > 0) {
1824
+ recipients = this.active.filter((actor: Actor): boolean =>
1825
+ targets.includes(actor.number),
1826
+ )
1827
+ } else if (packet.group !== 0) {
1828
+ recipients = [...this.groups.of(packet.group)].filter(
1829
+ (actor: Actor): boolean => actor !== sender,
1830
+ )
1831
+ } else if (packet.receiverGroup === ReceiverGroup.ALL) {
1832
+ recipients = [...this.active]
1833
+ cacheable = true
1834
+ } else if (packet.receiverGroup === ReceiverGroup.OTHERS) {
1835
+ recipients = this.active.filter(
1836
+ (actor: Actor): boolean => actor !== sender,
1837
+ )
1838
+ cacheable = true
1839
+ } else if (packet.receiverGroup === ReceiverGroup.MASTER_CLIENT) {
1840
+ recipients = this.active.filter(
1841
+ (actor: Actor): boolean => actor.number === this.master,
1842
+ )
1843
+ if (recipients.length === 0) return null
1844
+ } else {
1845
+ return Fault.invalid(
1846
+ `${ErrorMessage.INVALID_RECEIVER_GROUP}{0}`,
1847
+ packet.receiverGroup,
1848
+ )
1849
+ }
1850
+
1851
+ if (cacheable && caching !== EventCaching.DO_NOT_CACHE && !this.discarded) {
1852
+ const fault = this.keep(sender, packet)
1853
+ if (fault !== null) return fault
1854
+ }
1855
+
1856
+ if (this.discarded) this.overflow()
1857
+
1858
+ this.tell(
1859
+ recipients,
1860
+ CustomEvent.of(packet.eventCode, sender.number, packet.data).via(
1861
+ packet.travel,
1862
+ ),
1863
+ )
1864
+
1865
+ return null
1866
+ }
1867
+
1868
+ /**
1869
+ * Puts a raised event in a cache, or says why not
1870
+ * @param sender who raised it
1871
+ * @param packet what the client sent
1872
+ */
1873
+ private keep(sender: Actor, packet: RaiseEventRequest): Fault | null {
1874
+ const code = packet.eventCode
1875
+ const data = packet.data
1876
+
1877
+ switch (packet.caching) {
1878
+ case EventCaching.MERGE_CACHE:
1879
+ if (!ActorCache.suits(data)) return Room.unsuited('MergeCache')
1880
+ this.actorCache.merge(sender.number, code, data)
1881
+ return null
1882
+ case EventCaching.REPLACE_CACHE:
1883
+ if (!ActorCache.suits(data)) return Room.unsuited('ReplaceCache')
1884
+ this.actorCache.replace(sender.number, code, data)
1885
+ return null
1886
+ case EventCaching.REMOVE_CACHE:
1887
+ if (!ActorCache.suits(data)) return Room.unsuited('RemoveCache')
1888
+ this.actorCache.remove(sender.number, code)
1889
+ return null
1890
+ case EventCaching.ADD_TO_ROOM_CACHE:
1891
+ this.roomCache.add(sender.number, code, data)
1892
+ return null
1893
+ case EventCaching.ADD_TO_ROOM_CACHE_GLOBAL:
1894
+ this.roomCache.add(0, code, data)
1895
+ return null
1896
+ default:
1897
+ return Fault.invalid("Unknown cache operation '{0}'.", packet.caching)
1898
+ }
1899
+ }
1900
+
1901
+ /**
1902
+ * The refusal for content an actor cache can't hold
1903
+ * @param operation name of the cache operation
1904
+ */
1905
+ private static unsuited(operation: string): Fault {
1906
+ return Fault.invalid(
1907
+ "Cache operation '{0}' requires a Hashtable as event data.",
1908
+ operation,
1909
+ )
1910
+ }
1911
+
1912
+ /**
1913
+ * Closes the room after a cache passed its limit and tells everyone
1914
+ */
1915
+ private overflow(): void {
1916
+ const closing = this.isOpen
1917
+
1918
+ if (closing) {
1919
+ const closed = Room.single(GameProperty.IS_OPEN, PhotonValue.bool(false))
1920
+ this.properties.merge(closed)
1921
+ this.tell(this.active, PropertiesChangedEvent.of(0, 0, closed))
1922
+ const shut: GameChanges = { isOpen: false }
1923
+ this.report(shut)
1924
+ }
1925
+
1926
+ this.tell(
1927
+ this.active,
1928
+ ErrorInfoEvent.of(
1929
+ closing
1930
+ ? ErrorMessage.ROOM_CLOSED_CACHED_EVENTS_LIMIT_EXCEEDED
1931
+ : ErrorMessage.CACHED_EVENTS_LIMIT_EXCEEDED,
1932
+ ),
1933
+ )
1934
+ }
1935
+
1936
+ /**
1937
+ * Moves or purges cache slices, or says why not
1938
+ * @param sender who asked
1939
+ * @param packet what the client sent
1940
+ */
1941
+ private slice(sender: Actor, packet: RaiseEventRequest): Fault | null {
1942
+ const index = packet.cacheSliceIndex
1943
+ const before = this.roomCache.current
1944
+ let fault: Fault | null
1945
+
1946
+ switch (packet.caching) {
1947
+ case EventCaching.SLICE_INCREASE_INDEX:
1948
+ fault = this.roomCache.increase()
1949
+ break
1950
+ case EventCaching.SLICE_SET_INDEX:
1951
+ fault =
1952
+ index === null
1953
+ ? Fault.invalid('SliceSetIndex: Missing paramter CacheSliceIndex.')
1954
+ : this.roomCache.move(index)
1955
+ break
1956
+ case EventCaching.SLICE_PURGE_INDEX:
1957
+ return index === null
1958
+ ? Fault.invalid('SlicePurgeIndex: Missing paramter CacheSliceIndex.')
1959
+ : this.roomCache.purge(index)
1960
+ case EventCaching.SLICE_PURGE_UP_TO_INDEX:
1961
+ return index === null
1962
+ ? Fault.invalid(
1963
+ 'SlicePurgeUpToIndex: Missing paramter CacheSliceIndex.',
1964
+ )
1965
+ : this.roomCache.purgeBelow(index)
1966
+ default:
1967
+ return Fault.invalid('Unknown cache operation={0}.', packet.caching)
1968
+ }
1969
+
1970
+ if (fault !== null || this.roomCache.current === before) return fault
1971
+
1972
+ this.tell(
1973
+ this.active,
1974
+ CacheSliceChangedEvent.of(this.roomCache.current, sender.number),
1975
+ )
1976
+
1977
+ return null
1978
+ }
1979
+
1980
+ /**
1981
+ * Property keys as a bag knows them
1982
+ * @param keys keys as the client sent them
1983
+ * @param json whether the client speaks JSON
1984
+ * @param codes property codes a JSON client sends as text
1985
+ */
1986
+ private keys(
1987
+ keys: readonly PhotonValue[],
1988
+ json: boolean,
1989
+ codes: readonly number[],
1990
+ ): readonly PhotonValue[] {
1991
+ if (!json) return keys
1992
+
1993
+ return keys.map<PhotonValue>((key: PhotonValue): PhotonValue => {
1994
+ const code = Number(key.text() ?? '')
1995
+ return codes.includes(code) ? PhotonValue.byte(code) : key
1996
+ })
1997
+ }
1998
+
1999
+ /**
2000
+ * Who hears about a property change
2001
+ * @param sender who made it
2002
+ * @param packet what the client sent
2003
+ * @param swapping whether expected values came along
2004
+ */
2005
+ private audience(
2006
+ sender: Actor,
2007
+ packet: SetPropertiesRequest,
2008
+ swapping: boolean,
2009
+ ): readonly Actor[] {
2010
+ if (!packet.broadcast && !swapping) return []
2011
+ if (swapping || this.has(RoomOptionFlag.BROADCAST_PROPS_CHANGE_TO_ALL)) {
2012
+ return [...this.active]
2013
+ }
2014
+
2015
+ return this.active.filter((actor: Actor): boolean => actor !== sender)
2016
+ }
2017
+
2018
+ /**
2019
+ * The actor behind a property request, or why there's none
2020
+ * @param peer who's changing properties
2021
+ * @param packet what the client sent
2022
+ */
2023
+ private setter(peer: GamePeer, packet: SetPropertiesRequest): Actor | Fault {
2024
+ const sender = this.playing(peer)
2025
+ if (sender === null) {
2026
+ return Fault.invalid(ErrorMessage.PEER_NOT_JOINED_TO_ROOM)
2027
+ }
2028
+
2029
+ return this.throttled(packet.webFlags)
2030
+ ? Fault.of(
2031
+ ErrorCode.HTTP_LIMIT_REACHED,
2032
+ ErrorMessage.HTTP_FORWARDED_OPERATIONS_LIMIT_REACHED,
2033
+ )
2034
+ : sender
2035
+ }
2036
+
2037
+ /**
2038
+ * Changes properties of the room or of one actor and says why it failed, or null
2039
+ * @param peer who's changing them
2040
+ * @param packet what the client sent
2041
+ */
2042
+ protected altered(
2043
+ peer: GamePeer,
2044
+ packet: SetPropertiesRequest,
2045
+ ): Fault | null {
2046
+ return packet.actorNumber > 0
2047
+ ? this.changeActor(peer, packet)
2048
+ : this.changeRoom(peer, packet)
2049
+ }
2050
+
2051
+ /**
2052
+ * Changes the properties of one actor and says why it failed, or null
2053
+ * @param peer who's changing them
2054
+ * @param packet what the client sent
2055
+ */
2056
+ private changeActor(
2057
+ peer: GamePeer,
2058
+ packet: SetPropertiesRequest,
2059
+ ): Fault | null {
2060
+ const sender = this.setter(peer, packet)
2061
+ if (sender instanceof Fault) return sender
2062
+
2063
+ const target = this.numbered(packet.actorNumber)
2064
+ if (target === null) {
2065
+ return Fault.invalid(ErrorMessage.ACTOR_NOT_FOUND, packet.actorNumber)
2066
+ }
2067
+
2068
+ const joining =
2069
+ target.peer !== null && target.peer.stage !== JoinStage.COMPLETE
2070
+ if (packet.broadcast && joining) {
2071
+ return Fault.invalid(
2072
+ ErrorMessage.ACTOR_JOINING_NOT_COMPLETE,
2073
+ packet.actorNumber,
2074
+ )
2075
+ }
2076
+
2077
+ const expected = EntrySetup.promoted(
2078
+ packet.expectedValues,
2079
+ peer.json,
2080
+ JsonKeys.ACTOR,
2081
+ )
2082
+ const properties = EntrySetup.stripped(
2083
+ EntrySetup.promoted(packet.properties, peer.json, JsonKeys.ACTOR),
2084
+ )
2085
+ const swapping = expected !== null && expected.size > 0
2086
+ const unmet = target.properties.swap(properties, swapping ? expected : null)
2087
+ if (unmet !== null) return Fault.of(ErrorCode.OPERATION_INVALID, unmet)
2088
+
2089
+ peer.send(SetPropertiesResponse.success().to(packet))
2090
+ this.tell(
2091
+ this.quiet ? [] : this.audience(sender, packet, swapping),
2092
+ PropertiesChangedEvent.of(sender.number, target.number, properties).via(
2093
+ packet.travel,
2094
+ ),
2095
+ )
2096
+
2097
+ return null
2098
+ }
2099
+
2100
+ /**
2101
+ * Changes the properties of the room and says why it failed, or null
2102
+ * @param peer who's changing them
2103
+ * @param packet what the client sent
2104
+ */
2105
+ private changeRoom(
2106
+ peer: GamePeer,
2107
+ packet: SetPropertiesRequest,
2108
+ ): Fault | null {
2109
+ const known = WellKnownProperties.read(
2110
+ EntrySetup.promoted(packet.properties, peer.json, JsonKeys.ROOM),
2111
+ )
2112
+ if (known.fault !== null) {
2113
+ return Fault.of(ErrorCode.OPERATION_INVALID, known.fault)
2114
+ }
2115
+
2116
+ const sender = this.setter(peer, packet)
2117
+ if (sender instanceof Fault) return sender
2118
+
2119
+ const wanted = WellKnownProperties.read(
2120
+ EntrySetup.promoted(packet.expectedValues, peer.json, JsonKeys.ROOM),
2121
+ )
2122
+ const expected =
2123
+ wanted.fault === null ? wanted.properties : packet.expectedValues
2124
+ const swapping = expected !== null && expected.size > 0
2125
+ const before = this.properties.all()
2126
+ const seats = [...this.expected]
2127
+ const state = [this.maxPlayers, this.isOpen, this.isVisible] as const
2128
+
2129
+ const fault = this.revise(known, swapping ? expected : null)
2130
+ if (fault !== null) {
2131
+ this.properties.restore(before)
2132
+ this.expected = seats
2133
+ return fault
2134
+ }
2135
+
2136
+ peer.send(SetPropertiesResponse.success().to(packet))
2137
+ this.tell(
2138
+ this.audience(sender, packet, swapping),
2139
+ PropertiesChangedEvent.of(sender.number, 0, known.properties).via(
2140
+ packet.travel,
2141
+ ),
2142
+ )
2143
+ this.publish(known, state)
2144
+
2145
+ return null
2146
+ }
2147
+
2148
+ /**
2149
+ * Writes checked room properties and says why it failed, or null
2150
+ * @param known the properties after their type check
2151
+ * @param expected values the room must hold first, or null
2152
+ */
2153
+ private revise(
2154
+ known: WellKnownProperties,
2155
+ expected: PhotonHashtable | null,
2156
+ ): Fault | null {
2157
+ const longest = this.services.configuration.maxEmptyRoomTtl
2158
+ const stay = known.number(GameProperty.EMPTY_ROOM_TTL)
2159
+ if (stay !== null && stay > longest) {
2160
+ return Fault.invalid(
2161
+ ErrorMessage.SET_PROPERTIES_MAX_TTL_EXCEEDED,
2162
+ stay,
2163
+ longest,
2164
+ )
2165
+ }
2166
+
2167
+ const leader = known.number(GameProperty.MASTER_CLIENT_ID)
2168
+ if (leader !== null && !this.numbers.includes(leader)) {
2169
+ return Fault.invalid(
2170
+ "MasterClientId value '{0}' is invalid. No actor with such number",
2171
+ leader,
2172
+ )
2173
+ }
2174
+
2175
+ if (known.has(GameProperty.EXPECTED_USERS) && expected === null) {
2176
+ return Fault.invalid('ExpectedUsers may be updated only in CAS mode')
2177
+ }
2178
+
2179
+ const limit = known.number(GameProperty.MAX_PLAYERS) ?? 0
2180
+ if (limit !== 0 && limit < this.active.length + this.inactive.length) {
2181
+ return Fault.invalid(
2182
+ 'new MaxPlayer can not be less then current amount of players',
2183
+ )
2184
+ }
2185
+
2186
+ const unmet = this.properties.swap(known.properties, expected)
2187
+ if (unmet !== null) return Fault.of(ErrorCode.OPERATION_INVALID, unmet)
2188
+
2189
+ if (leader !== null) this.master = leader
2190
+ this.list(known.properties)
2191
+
2192
+ return known.has(GameProperty.EXPECTED_USERS)
2193
+ ? this.reseat(known, expected)
2194
+ : null
2195
+ }
2196
+
2197
+ /**
2198
+ * Swaps the list of kept seats and says why it failed, or null
2199
+ * @param known the properties after their type check
2200
+ * @param expected values the room held first, or null
2201
+ */
2202
+ private reseat(
2203
+ known: WellKnownProperties,
2204
+ expected: PhotonHashtable | null,
2205
+ ): Fault | null {
2206
+ const key = Room.key(GameProperty.EXPECTED_USERS)
2207
+ const old = WellKnownProperties.users(expected?.get(key) ?? null) ?? []
2208
+ const users =
2209
+ WellKnownProperties.users(known.value(GameProperty.EXPECTED_USERS)) ?? []
2210
+ if (users.includes('')) {
2211
+ return Fault.invalid(ErrorMessage.SLOT_CAN_NOT_HAVE_EMPTY_NAME)
2212
+ }
2213
+
2214
+ const kept = this.expected.filter(
2215
+ (user: string): boolean => !old.includes(user) || users.includes(user),
2216
+ )
2217
+ const seats = [...new Set<string>([...kept, ...users])]
2218
+ const limit = this.maxPlayers
2219
+ const taken =
2220
+ this.active.length + this.inactive.length + this.pending(seats)
2221
+ if (limit !== 0 && taken > limit) {
2222
+ return Fault.invalid('Not enough places to reserve all requested slots')
2223
+ }
2224
+
2225
+ this.expected = seats
2226
+ return null
2227
+ }
2228
+
2229
+ /**
2230
+ * Tells the Master about changed room properties if it cares
2231
+ * @param known the properties that were written
2232
+ * @param state player limit, open and visible as they were before
2233
+ */
2234
+ private publish(
2235
+ known: WellKnownProperties,
2236
+ state: readonly [number, boolean, boolean],
2237
+ ): void {
2238
+ const herald = this.services.herald
2239
+ const refiltered = known.has(GameProperty.PROPS_LISTED_IN_LOBBY)
2240
+ const reseated = known.has(GameProperty.EXPECTED_USERS)
2241
+ const limited =
2242
+ known.has(GameProperty.MAX_PLAYERS) && this.maxPlayers !== state[0]
2243
+ const opened = known.has(GameProperty.IS_OPEN) && this.isOpen !== state[1]
2244
+ const shown =
2245
+ known.has(GameProperty.IS_VISIBLE) && this.isVisible !== state[2]
2246
+ const listed = this.listed(
2247
+ refiltered ? this.properties.all() : known.properties,
2248
+ )
2249
+ if (
2250
+ !limited &&
2251
+ !opened &&
2252
+ !shown &&
2253
+ !refiltered &&
2254
+ !reseated &&
2255
+ listed.size === 0
2256
+ ) {
2257
+ return
2258
+ }
2259
+
2260
+ const changes: GameChanges = {
2261
+ maxPlayers: limited ? this.maxPlayers : null,
2262
+ isOpen: opened ? this.isOpen : null,
2263
+ isVisible: shown ? this.isVisible : null,
2264
+ expectedUsers: reseated ? [...this.expected] : null,
2265
+ propertyFilter:
2266
+ refiltered && this.filter !== null ? herald.filter(this.filter) : null,
2267
+ properties: listed.size === 0 ? null : herald.properties(listed),
2268
+ }
2269
+ this.report(changes)
2270
+ }
2271
+ }