Skip to content

Commit

Permalink
Cancel live automatche searches when any live game starts
Browse files Browse the repository at this point in the history
  • Loading branch information
anoek committed Jan 1, 2025
1 parent 482c73d commit bd0d802
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/components/Notifications/NotificationManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface NotificationManagerEvents {
notification: any;
"notification-list-updated": never;
"notification-count": number;
"game-started": Notification;
}

const boot_time = Date.now();
Expand Down Expand Up @@ -458,6 +459,10 @@ export class NotificationManager {
);
}

if (notification.type === "gameStarted") {
this.event_emitter.emit("game-started", notification);
}

if (
notification.type === "gameStarted" ||
notification.type === "gameEnded" ||
Expand Down
7 changes: 6 additions & 1 deletion src/views/Play/CustomGames.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,12 @@ export function CustomGames(): JSX.Element {
<div style={{ marginTop: "2em" }}></div>

<div className="challenge-row" style={{ marginTop: "1em" }}>
<span className="cell break">{_("Long Games")}</span>
<span className="cell break">
{pgettext(
"Game speed: multi-day games",
"Daily Correspondence",
)}
</span>
<CellBreaks width={8} />
</div>

Expand Down
12 changes: 12 additions & 0 deletions src/views/Play/QuickMatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import Select from "react-select";
import { SPEED_OPTIONS } from "./SPEED_OPTIONS";
import { useHaveActiveGameSearch } from "./hooks";
import { openPlayPageHelp } from "./PlayPageHelp";
import { notification_manager, Notification } from "@/components/Notifications/NotificationManager";

moment.relativeTimeThreshold("m", 56);
export interface SelectOption {
Expand Down Expand Up @@ -179,11 +180,21 @@ export function QuickMatch(): JSX.Element {
automatch_manager.on("cancel", refresh);
bot_event_emitter.on("updated", refresh);

function onGameStarted(game?: Notification) {
console.log("game-started", game);
if (game?.speed !== "correspondence" && automatch_manager.active_live_automatcher) {
automatch_manager.cancel(automatch_manager.active_live_automatcher?.uuid);
}
}

notification_manager.event_emitter.on("game-started", onGameStarted);

return () => {
automatch_manager.off("entry", refresh);
automatch_manager.off("start", refresh);
automatch_manager.off("cancel", refresh);
bot_event_emitter.off("updated", refresh);
notification_manager.event_emitter.off("game-started", onGameStarted);
};
}, []);

Expand Down Expand Up @@ -747,6 +758,7 @@ export function QuickMatch(): JSX.Element {
styles={select_styles}
isSearchable={false}
value={game_clock_options.find((o) => o.value === game_clock)}
menuPlacement="auto"
onChange={(opt) => {
if (opt) {
setGameClock(opt.value as "flexible" | "exact" | "multiple");
Expand Down

0 comments on commit bd0d802

Please sign in to comment.