@hadoku/game-server 0.1.199 → 0.1.201
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/room/lobby.js +64 -97
- package/package.json +5 -5
package/dist/room/lobby.js
CHANGED
|
@@ -679,13 +679,35 @@ export class RoomLobby {
|
|
|
679
679
|
this.#avatarListeners.delete(listener);
|
|
680
680
|
};
|
|
681
681
|
}
|
|
682
|
-
/** The room by id
|
|
683
|
-
#
|
|
682
|
+
/** The room by id, refused `no-room`, then `not-member` unless `override` (an operator's reach). */
|
|
683
|
+
#memberRoom(roomId, memberId, override = false) {
|
|
684
684
|
const room = this.#rooms.get(roomId);
|
|
685
685
|
if (room === undefined)
|
|
686
686
|
return { refused: 'no-room' };
|
|
687
687
|
if (!override && !isRoomMember(room, memberId))
|
|
688
688
|
return { refused: 'not-member' };
|
|
689
|
+
return { room };
|
|
690
|
+
}
|
|
691
|
+
/** `found`, or `not-leader` when `memberId` does not lead its room; `override` (an operator's reach) skips the check. */
|
|
692
|
+
#led(found, memberId, override) {
|
|
693
|
+
return 'refused' in found || override || found.room.leader === memberId ? found : { refused: 'not-leader' };
|
|
694
|
+
}
|
|
695
|
+
/** The room `memberId` leads: `no-room`, then `not-member`, then `not-leader`, the opening the leader's ops share. */
|
|
696
|
+
#leaderRoom(roomId, memberId, override) {
|
|
697
|
+
return this.#led(this.#memberRoom(roomId, memberId, override), memberId, override);
|
|
698
|
+
}
|
|
699
|
+
/** A seat op's change, kept: saved, logged, the type told its seats changed (given `hooks`), and the room answered. */
|
|
700
|
+
#kept(room, entry, hooks) {
|
|
701
|
+
this.persist(room);
|
|
702
|
+
this.log(entry);
|
|
703
|
+
hooks?.seatsChanged?.(room);
|
|
704
|
+
return { ok: true, room: this.view(room) };
|
|
705
|
+
}
|
|
706
|
+
/** `found`'s room when it seats through its game seats, with the refusal every seat op shares otherwise. */
|
|
707
|
+
#seatRoom(found) {
|
|
708
|
+
if ('refused' in found)
|
|
709
|
+
return found;
|
|
710
|
+
const { room } = found;
|
|
689
711
|
const hooks = this.hooksOf(room);
|
|
690
712
|
// `not-draft`, the wire's name for a room that does not seat through its game seats.
|
|
691
713
|
if (!hooks.usesSeats(room))
|
|
@@ -707,12 +729,10 @@ export class RoomLobby {
|
|
|
707
729
|
* this way). `room.seats` always `supportsBot` (its `AI_SEAT` marker); a type's own stand-in
|
|
708
730
|
* says for itself.
|
|
709
731
|
*/
|
|
710
|
-
#seatOpRoom(
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
if (!override && !isRoomMember(room, memberId))
|
|
715
|
-
return { refused: 'not-member' };
|
|
732
|
+
#seatOpRoom(found) {
|
|
733
|
+
if ('refused' in found)
|
|
734
|
+
return found;
|
|
735
|
+
const { room } = found;
|
|
716
736
|
const hooks = this.hooksOf(room);
|
|
717
737
|
if (hooks.usesSeats(room)) {
|
|
718
738
|
if (hooks.seatsFixed(room))
|
|
@@ -741,7 +761,7 @@ export class RoomLobby {
|
|
|
741
761
|
* any seat they held.
|
|
742
762
|
*/
|
|
743
763
|
sitSeat(roomId, memberId, seat) {
|
|
744
|
-
const found = this.#seatRoom(roomId, memberId);
|
|
764
|
+
const found = this.#seatRoom(this.#memberRoom(roomId, memberId));
|
|
745
765
|
if ('refused' in found)
|
|
746
766
|
return { ok: false, reason: found.refused };
|
|
747
767
|
const { room, hooks } = found;
|
|
@@ -763,33 +783,26 @@ export class RoomLobby {
|
|
|
763
783
|
hooks.growSeats(room, target);
|
|
764
784
|
takeGameSeat(room, memberId, target);
|
|
765
785
|
hooks.trimSeats(room);
|
|
766
|
-
this
|
|
767
|
-
this.log({ event: 'pod-sit', roomId, memberId, seat: target });
|
|
768
|
-
hooks.seatsChanged?.(room);
|
|
769
|
-
return { ok: true, room: this.view(room) };
|
|
786
|
+
return this.#kept(room, { event: 'pod-sit', roomId, memberId, seat: target }, hooks);
|
|
770
787
|
}
|
|
771
788
|
/** Give up a game seat. Idempotent: not seated is not a failure. */
|
|
772
789
|
standSeat(roomId, memberId) {
|
|
773
|
-
const found = this.#seatRoom(roomId, memberId);
|
|
790
|
+
const found = this.#seatRoom(this.#memberRoom(roomId, memberId));
|
|
774
791
|
if ('refused' in found)
|
|
775
792
|
return { ok: false, reason: found.refused };
|
|
776
793
|
const { room, hooks } = found;
|
|
777
794
|
if (!leaveGameSeat(room, memberId))
|
|
778
795
|
return { ok: true, room: this.view(room) };
|
|
779
796
|
hooks.trimSeats(room);
|
|
780
|
-
this
|
|
781
|
-
this.log({ event: 'pod-stand', roomId, memberId });
|
|
782
|
-
hooks.seatsChanged?.(room);
|
|
783
|
-
return { ok: true, room: this.view(room) };
|
|
797
|
+
return this.#kept(room, { event: 'pod-stand', roomId, memberId }, hooks);
|
|
784
798
|
}
|
|
785
799
|
/** Put the AI in an open seat (`on`), or take it out. The leader's, or `override`'s (see `removeFromSeat`). */
|
|
786
800
|
aiSeat(roomId, memberId, seat, on, override = false) {
|
|
787
|
-
|
|
801
|
+
// The seat checks come before the leader's here, as they always have.
|
|
802
|
+
const found = this.#led(this.#seatRoom(this.#memberRoom(roomId, memberId, override)), memberId, override);
|
|
788
803
|
if ('refused' in found)
|
|
789
804
|
return { ok: false, reason: found.refused };
|
|
790
805
|
const { room, hooks } = found;
|
|
791
|
-
if (!override && room.leader !== memberId)
|
|
792
|
-
return { ok: false, reason: 'not-leader' };
|
|
793
806
|
if (hooks.fieldFixed?.(room) === true)
|
|
794
807
|
return { ok: false, reason: 'historical' };
|
|
795
808
|
if (on && this.seatsShut(room) !== null)
|
|
@@ -805,24 +818,14 @@ export class RoomLobby {
|
|
|
805
818
|
setGameSeat(room, seat, on ? AI_SEAT : null);
|
|
806
819
|
hooks.aiSeated?.(room, seat, on);
|
|
807
820
|
hooks.trimSeats(room);
|
|
808
|
-
this
|
|
809
|
-
this.log({ event: on ? 'pod-ai-sit' : 'pod-ai-stand', roomId, memberId, seat });
|
|
810
|
-
hooks.seatsChanged?.(room);
|
|
811
|
-
return { ok: true, room: this.view(room) };
|
|
821
|
+
return this.#kept(room, { event: on ? 'pod-ai-sit' : 'pod-ai-stand', roomId, memberId, seat }, hooks);
|
|
812
822
|
}
|
|
813
823
|
/** Close an empty seat, or open a closed one: the leader's, or `override`'s (see `removeFromSeat`); never fewer than `MIN_OPEN_SEATS` open. */
|
|
814
824
|
closeSeat(roomId, memberId, seat, closed, override = false) {
|
|
815
|
-
const
|
|
816
|
-
if (room === undefined)
|
|
817
|
-
return { ok: false, reason: 'no-room' };
|
|
818
|
-
if (!override && !isRoomMember(room, memberId))
|
|
819
|
-
return { ok: false, reason: 'not-member' };
|
|
820
|
-
if (!override && room.leader !== memberId)
|
|
821
|
-
return { ok: false, reason: 'not-leader' };
|
|
822
|
-
const found = this.#seatRoom(roomId, memberId, override);
|
|
825
|
+
const found = this.#seatRoom(this.#leaderRoom(roomId, memberId, override));
|
|
823
826
|
if ('refused' in found)
|
|
824
827
|
return { ok: false, reason: found.refused };
|
|
825
|
-
const { hooks } = found;
|
|
828
|
+
const { room, hooks } = found;
|
|
826
829
|
if (hooks.fieldFixed?.(room) === true)
|
|
827
830
|
return { ok: false, reason: 'historical' };
|
|
828
831
|
if (!this.#inReach(room, hooks, seat) || seat >= room.seats.length)
|
|
@@ -837,30 +840,23 @@ export class RoomLobby {
|
|
|
837
840
|
return { ok: false, reason: 'too-few' };
|
|
838
841
|
setGameSeat(room, seat, closed ? CLOSED_SEAT : null);
|
|
839
842
|
hooks.trimSeats(room);
|
|
840
|
-
this
|
|
841
|
-
this.log({ event: closed ? 'pod-seat-closed' : 'pod-seat-opened', roomId, memberId, seat, size: size() });
|
|
842
|
-
return { ok: true, room: this.view(room) };
|
|
843
|
+
return this.#kept(room, { event: closed ? 'pod-seat-closed' : 'pod-seat-opened', roomId, memberId, seat, size: size() });
|
|
843
844
|
}
|
|
844
845
|
/**
|
|
845
846
|
* The leader hands the room's leadership to `targetId`, another member, seated or watching.
|
|
846
847
|
* Passing it to yourself is answered `ok` and changes nothing.
|
|
847
848
|
*/
|
|
848
849
|
passLeader(roomId, memberId, targetId, override = false) {
|
|
849
|
-
const
|
|
850
|
-
if (
|
|
851
|
-
return { ok: false, reason:
|
|
852
|
-
|
|
853
|
-
return { ok: false, reason: 'not-member' };
|
|
854
|
-
if (!override && room.leader !== memberId)
|
|
855
|
-
return { ok: false, reason: 'not-leader' };
|
|
850
|
+
const found = this.#leaderRoom(roomId, memberId, override);
|
|
851
|
+
if ('refused' in found)
|
|
852
|
+
return { ok: false, reason: found.refused };
|
|
853
|
+
const { room } = found;
|
|
856
854
|
// Already theirs: nothing to move. An operator naming themselves takes a lead that was someone else's.
|
|
857
855
|
if (targetId === room.leader)
|
|
858
856
|
return { ok: true, room: this.view(room) };
|
|
859
857
|
if (!passRoomLeader(room, targetId))
|
|
860
858
|
return { ok: false, reason: 'target-not-member' };
|
|
861
|
-
this
|
|
862
|
-
this.log({ event: 'leader-passed', roomId, memberId, targetId });
|
|
863
|
-
return { ok: true, room: this.view(room) };
|
|
859
|
+
return this.#kept(room, { event: 'leader-passed', roomId, memberId, targetId });
|
|
864
860
|
}
|
|
865
861
|
/**
|
|
866
862
|
* The leader removes `targetId` from whatever game seat they hold, to the spectator row.
|
|
@@ -877,30 +873,21 @@ export class RoomLobby {
|
|
|
877
873
|
* needing to be neither the leader nor a member.
|
|
878
874
|
*/
|
|
879
875
|
removeFromSeat(roomId, memberId, targetId, override = false) {
|
|
880
|
-
const
|
|
881
|
-
if (
|
|
882
|
-
return { ok: false, reason: 'no-room' };
|
|
883
|
-
if (!override && !isRoomMember(room, memberId))
|
|
884
|
-
return { ok: false, reason: 'not-member' };
|
|
885
|
-
if (!override && room.leader !== memberId)
|
|
886
|
-
return { ok: false, reason: 'not-leader' };
|
|
887
|
-
if (!isRoomMember(room, targetId))
|
|
876
|
+
const led = this.#leaderRoom(roomId, memberId, override);
|
|
877
|
+
if (!('refused' in led) && !isRoomMember(led.room, targetId))
|
|
888
878
|
return { ok: false, reason: 'target-not-member' };
|
|
889
|
-
const found = this.#seatOpRoom(
|
|
879
|
+
const found = this.#seatOpRoom(led);
|
|
890
880
|
if ('refused' in found)
|
|
891
881
|
return { ok: false, reason: found.refused };
|
|
892
|
-
const { room
|
|
882
|
+
const { room, hooks, target, generic } = found;
|
|
893
883
|
const seats = target.read();
|
|
894
884
|
const at = seats.indexOf(targetId);
|
|
895
885
|
if (at === -1)
|
|
896
|
-
return { ok: true, room: this.view(
|
|
886
|
+
return { ok: true, room: this.view(room) };
|
|
897
887
|
target.write(seats.map((s, i) => (i === at ? null : s)));
|
|
898
888
|
if (generic)
|
|
899
|
-
hooks.trimSeats(
|
|
900
|
-
this
|
|
901
|
-
this.log({ event: 'seat-removed-by-leader', roomId, memberId, targetId });
|
|
902
|
-
hooks.seatsChanged?.(r);
|
|
903
|
-
return { ok: true, room: this.view(r) };
|
|
889
|
+
hooks.trimSeats(room);
|
|
890
|
+
return this.#kept(room, { event: 'seat-removed-by-leader', roomId, memberId, targetId }, hooks);
|
|
904
891
|
}
|
|
905
892
|
/**
|
|
906
893
|
* The leader closes seats from the TOP down until `count` are open, evicting any occupant
|
|
@@ -913,32 +900,22 @@ export class RoomLobby {
|
|
|
913
900
|
* Resolved through `#seatOpRoom` (wave 120 §S2): see `removeFromSeat`'s header.
|
|
914
901
|
*/
|
|
915
902
|
lowerSeatCapacity(roomId, memberId, count, override = false) {
|
|
916
|
-
const
|
|
917
|
-
if (room === undefined)
|
|
918
|
-
return { ok: false, reason: 'no-room' };
|
|
919
|
-
if (!override && !isRoomMember(room, memberId))
|
|
920
|
-
return { ok: false, reason: 'not-member' };
|
|
921
|
-
if (!override && room.leader !== memberId)
|
|
922
|
-
return { ok: false, reason: 'not-leader' };
|
|
923
|
-
const found = this.#seatOpRoom(roomId, memberId, override);
|
|
903
|
+
const found = this.#seatOpRoom(this.#leaderRoom(roomId, memberId, override));
|
|
924
904
|
if ('refused' in found)
|
|
925
905
|
return { ok: false, reason: found.refused };
|
|
926
|
-
const { room
|
|
927
|
-
if (hooks.fieldFixed?.(
|
|
906
|
+
const { room, hooks, target, generic } = found;
|
|
907
|
+
if (hooks.fieldFixed?.(room) === true)
|
|
928
908
|
return { ok: false, reason: 'historical' };
|
|
929
909
|
if (!Number.isInteger(count) || count < MIN_OPEN_SEATS)
|
|
930
910
|
return { ok: false, reason: 'too-few' };
|
|
931
911
|
const before = target.read();
|
|
932
912
|
const { seats, evicted } = lowerCapacity(before, count);
|
|
933
913
|
if (evicted.length === 0 && seats.every((s, i) => s === before[i]))
|
|
934
|
-
return { ok: true, room: this.view(
|
|
914
|
+
return { ok: true, room: this.view(room), evicted };
|
|
935
915
|
target.write(seats);
|
|
936
916
|
if (generic)
|
|
937
|
-
hooks.trimSeats(
|
|
938
|
-
this.
|
|
939
|
-
this.log({ event: 'seat-capacity-lowered', roomId, memberId, count, evicted: evicted.length });
|
|
940
|
-
hooks.seatsChanged?.(r);
|
|
941
|
-
return { ok: true, room: this.view(r), evicted };
|
|
917
|
+
hooks.trimSeats(room);
|
|
918
|
+
return { ...this.#kept(room, { event: 'seat-capacity-lowered', roomId, memberId, count, evicted: evicted.length }, hooks), evicted };
|
|
942
919
|
}
|
|
943
920
|
/**
|
|
944
921
|
* The leader puts the AI in `seat`, evicting whoever holds it first — a human to the spectator
|
|
@@ -952,35 +929,25 @@ export class RoomLobby {
|
|
|
952
929
|
* needing to be neither the leader nor a member.
|
|
953
930
|
*/
|
|
954
931
|
botReplacesHuman(roomId, memberId, seat, override = false) {
|
|
955
|
-
const
|
|
956
|
-
if (room === undefined)
|
|
957
|
-
return { ok: false, reason: 'no-room' };
|
|
958
|
-
if (!override && !isRoomMember(room, memberId))
|
|
959
|
-
return { ok: false, reason: 'not-member' };
|
|
960
|
-
if (!override && room.leader !== memberId)
|
|
961
|
-
return { ok: false, reason: 'not-leader' };
|
|
962
|
-
const found = this.#seatOpRoom(roomId, memberId, override);
|
|
932
|
+
const found = this.#seatOpRoom(this.#leaderRoom(roomId, memberId, override));
|
|
963
933
|
if ('refused' in found)
|
|
964
934
|
return { ok: false, reason: found.refused };
|
|
965
|
-
const { room
|
|
966
|
-
if (hooks.fieldFixed?.(
|
|
935
|
+
const { room, hooks, target, generic } = found;
|
|
936
|
+
if (hooks.fieldFixed?.(room) === true)
|
|
967
937
|
return { ok: false, reason: 'historical' };
|
|
968
938
|
if (!target.supportsBot)
|
|
969
939
|
return { ok: false, reason: 'no-bot-seat' };
|
|
970
|
-
if (!this.#inReach(
|
|
940
|
+
if (!this.#inReach(room, hooks, seat) || seat >= room.seats.length)
|
|
971
941
|
return { ok: false, reason: 'bad-seat' };
|
|
972
942
|
const before = target.read();
|
|
973
943
|
const { seats, evicted } = replaceWithBot(before, seat);
|
|
974
944
|
if (evicted === null && seats[seat] === before[seat])
|
|
975
|
-
return { ok: true, room: this.view(
|
|
945
|
+
return { ok: true, room: this.view(room), evicted: null };
|
|
976
946
|
target.write(seats);
|
|
977
|
-
hooks.aiSeated?.(
|
|
947
|
+
hooks.aiSeated?.(room, seat, true);
|
|
978
948
|
if (generic)
|
|
979
|
-
hooks.trimSeats(
|
|
980
|
-
this
|
|
981
|
-
this.log({ event: 'seat-bot-replaced-human', roomId, memberId, seat, evicted: evicted !== null });
|
|
982
|
-
hooks.seatsChanged?.(r);
|
|
983
|
-
return { ok: true, room: this.view(r), evicted };
|
|
949
|
+
hooks.trimSeats(room);
|
|
950
|
+
return { ...this.#kept(room, { event: 'seat-bot-replaced-human', roomId, memberId, seat, evicted: evicted !== null }, hooks), evicted };
|
|
984
951
|
}
|
|
985
952
|
/**
|
|
986
953
|
* Forget every room untouched for longer than `idleMs` (or its type's own idle window), on disk as
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/game-server",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.201",
|
|
4
|
+
"gitHead": "5f99a4b32b35131c69046b111e7ce269ca333b6c",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "The server parts any hosted game shares, above the kernel: the app config and edge auth, the room core (identity, seats, sessions, membership, the room list, the generic room routes), match hosting (the host contract, local and remote JVMs, placement, the start queue, recordings, the in-process and relay runtimes), streams, erase, telemetry and usage. Knows no game; Magic plugs in from apps/server. MIT; imports only node built-ins, express, socket.io, @wolffm/* and the platform packages.",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"play/remote/"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.
|
|
21
|
-
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.
|
|
22
|
-
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.
|
|
20
|
+
"@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.201",
|
|
21
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.201",
|
|
22
|
+
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.234",
|
|
23
23
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.3",
|
|
24
24
|
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.150",
|
|
25
25
|
"@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.150",
|