Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel live automatche searches when any live game starts #2906

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading