threesome fixed
This commit is contained in:
@@ -295,14 +295,17 @@ app.get('/', async (req: Request, res: Response) => {
|
||||
roomValid = false;
|
||||
}
|
||||
if (roomValid) {
|
||||
element.Players = element.Players.filter((player) => {
|
||||
const expired = isPlayerExpired(player);
|
||||
if (expired) {
|
||||
logInfo(`Player ${player.Name} expired in room ${element.Port}, removing.`);
|
||||
recordHistory(`${player.Name} timed out in room on port ${element.Port} (removed)`);
|
||||
}
|
||||
return !expired;
|
||||
});
|
||||
// In-game players stop GET / heartbeats; do not expire them or reopen the slot.
|
||||
if (!element.instance_started) {
|
||||
element.Players = element.Players.filter((player) => {
|
||||
const expired = isPlayerExpired(player);
|
||||
if (expired) {
|
||||
logInfo(`Player ${player.Name} expired in room ${element.Port}, removing.`);
|
||||
recordHistory(`${player.Name} timed out in room on port ${element.Port} (removed)`);
|
||||
}
|
||||
return !expired;
|
||||
});
|
||||
}
|
||||
element.Players.forEach(player => {
|
||||
if (player.UserId === userId) {
|
||||
player.LastSeen = Date.now();
|
||||
@@ -317,7 +320,11 @@ app.get('/', async (req: Request, res: Response) => {
|
||||
Rooms.splice(index, 1);
|
||||
recordHistory(`Room on port ${element.Port} removed (empty)`);
|
||||
}
|
||||
} else if (element.Players.length < typedSettings.maximum_players && element.GameName === gameName) {
|
||||
} else if (
|
||||
!element.instance_started &&
|
||||
element.Players.length < typedSettings.maximum_players &&
|
||||
element.GameName === gameName
|
||||
) {
|
||||
possibleRoom = element;
|
||||
}
|
||||
}
|
||||
@@ -347,6 +354,11 @@ app.get('/', async (req: Request, res: Response) => {
|
||||
}
|
||||
Rooms.push(newRoom);
|
||||
removeUserFromQueue(userId);
|
||||
logInfo(`${username} seated in room`, {
|
||||
port: newPort,
|
||||
match_id: newRoom.match_id ?? null,
|
||||
instance_started: Boolean(newRoom.instance_started),
|
||||
});
|
||||
recordHistory(
|
||||
`${username} created a room on port ${newPort} (match id ${newRoom.match_id ?? '—'}) — waiting for opponent`
|
||||
);
|
||||
@@ -354,26 +366,34 @@ app.get('/', async (req: Request, res: Response) => {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// We know possibleRoom is a Room type here since we checked it's not null
|
||||
const room: Room = possibleRoom;
|
||||
const l10 = await getPlayerLast10MatchRecord(typedSettings, userId);
|
||||
room.Players.push({ Name: username, LastSeen: Date.now(), UserId: userId, ...l10 });
|
||||
removeUserFromQueue(userId);
|
||||
if (room.match_id != null) {
|
||||
await updateMatchUserBlue(typedSettings, room.match_id, userId);
|
||||
const alreadySeated = room.Players.some((p) => p.UserId === userId);
|
||||
const hasFreeSlot = room.Players.length < typedSettings.maximum_players;
|
||||
if (!room.instance_started && hasFreeSlot && !alreadySeated) {
|
||||
const l10 = await getPlayerLast10MatchRecord(typedSettings, userId);
|
||||
room.Players.push({ Name: username, LastSeen: Date.now(), UserId: userId, ...l10 });
|
||||
removeUserFromQueue(userId);
|
||||
if (room.match_id != null) {
|
||||
await updateMatchUserBlue(typedSettings, room.match_id, userId);
|
||||
}
|
||||
const hasTwoActivePlayers =
|
||||
room.Players.length === 2 && room.Players.every((player) => !isPlayerExpired(player));
|
||||
if (hasTwoActivePlayers && !room.instance_started) {
|
||||
room.instance_started = true;
|
||||
OpenGameInstance(configuredGame.exe, room.Port, room.match_id ?? undefined);
|
||||
const [p0, p1] = room.Players;
|
||||
recordHistory(
|
||||
`new room created with port ${room.Port} and matchId ${room.match_id ?? '—'} for ${p0.Name} and ${p1.Name}`
|
||||
);
|
||||
}
|
||||
logInfo(`${username} seated in room`, {
|
||||
port: room.Port,
|
||||
match_id: room.match_id ?? null,
|
||||
instance_started: Boolean(room.instance_started),
|
||||
});
|
||||
res.json(roomMatchSuccessEnvelope(room, betFeePercent));
|
||||
return;
|
||||
}
|
||||
const hasTwoActivePlayers =
|
||||
room.Players.length === 2 && room.Players.every((player) => !isPlayerExpired(player));
|
||||
if (hasTwoActivePlayers && !room.instance_started) {
|
||||
room.instance_started = true;
|
||||
OpenGameInstance(configuredGame.exe, room.Port, room.match_id ?? undefined);
|
||||
const [p0, p1] = room.Players;
|
||||
recordHistory(
|
||||
`new room created with port ${room.Port} and matchId ${room.match_id ?? '—'} for ${p0.Name} and ${p1.Name}`
|
||||
);
|
||||
}
|
||||
res.json(roomMatchSuccessEnvelope(room, betFeePercent));
|
||||
return;
|
||||
}
|
||||
|
||||
// Not even got a new room. Back to queue
|
||||
|
||||
Reference in New Issue
Block a user