Skip to content

Commit 228f503

Browse files
committed
Merge branch 'feature/ui-overhaul'
# Conflicts: # hasura/fixtures/fixtures.sql # src/app.module.ts # src/fixtures/fixtures.controller.ts # src/fixtures/fixtures.module.ts
2 parents a72020d + 71a7e8b commit 228f503

18 files changed

Lines changed: 1361 additions & 121 deletions

File tree

hasura/fixtures/fixtures.sql

Lines changed: 501 additions & 83 deletions
Large diffs are not rendered by default.

hasura/functions/tournaments/schedule_tournament_match.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ CREATE OR REPLACE FUNCTION public.schedule_tournament_match(bracket public.tourn
4444
INNER JOIN tournaments t ON t.id = ts.tournament_id
4545
WHERE tb.id = bracket.id;
4646

47-
-- Check if stage has match_options_id first, otherwise use tournament match_options_id
48-
IF stage.match_options_id IS NOT NULL THEN
49-
_match_options_id := stage.match_options_id;
50-
ELSIF bracket.match_options_id IS NOT NULL THEN
47+
-- Check bracket first (decider overrides), then stage, then tournament
48+
IF bracket.match_options_id IS NOT NULL THEN
5149
_match_options_id := bracket.match_options_id;
50+
ELSIF stage.match_options_id IS NOT NULL THEN
51+
_match_options_id := stage.match_options_id;
5252
ELSE
5353
_match_options_id := tournament.match_options_id;
5454
END IF;

hasura/functions/tournaments/update_match_options_best_of.sql

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ DECLARE
66
original_match_options_id uuid;
77
match_options_record match_options%ROWTYPE;
88
final_match_options_id uuid;
9+
_decider_best_of int;
10+
_effective_best_of int;
911
BEGIN
1012
-- Get match_options_id from stage first, then tournament if stage doesn't have one
1113
SELECT COALESCE(
@@ -15,44 +17,59 @@ BEGIN
1517
FROM tournament_stages ts
1618
INNER JOIN tournaments t ON t.id = ts.tournament_id
1719
WHERE ts.id = _stage_id;
18-
20+
1921
-- If no match_options_id found, return NULL
2022
IF original_match_options_id IS NULL THEN
2123
RETURN NULL;
2224
END IF;
23-
24-
-- Get match_options record and check if best_of needs to be changed
25+
26+
-- Get match_options record
2527
SELECT * INTO match_options_record
2628
FROM match_options
2729
WHERE id = original_match_options_id;
28-
29-
-- If best_of is 1, create a new match_options with best_of = 3
30-
IF match_options_record.best_of = 1 THEN
31-
match_options_record.best_of := 3;
32-
-- Insert the modified record (id will be auto-generated)
33-
INSERT INTO match_options (
34-
overtime, knife_round, mr, best_of, coaches, number_of_substitutes,
35-
map_veto, timeout_setting, tech_timeout_setting, map_pool_id, type,
36-
regions, prefer_dedicated_server, invite_code, lobby_access,
37-
region_veto, ready_setting, check_in_setting, default_models, tv_delay
38-
) VALUES (
39-
match_options_record.overtime, match_options_record.knife_round,
40-
match_options_record.mr, match_options_record.best_of,
41-
match_options_record.coaches, match_options_record.number_of_substitutes,
42-
match_options_record.map_veto, match_options_record.timeout_setting,
43-
match_options_record.tech_timeout_setting, match_options_record.map_pool_id,
44-
match_options_record.type, match_options_record.regions,
45-
match_options_record.prefer_dedicated_server, match_options_record.invite_code,
46-
match_options_record.lobby_access, match_options_record.region_veto,
47-
match_options_record.ready_setting, match_options_record.check_in_setting,
48-
match_options_record.default_models, match_options_record.tv_delay
49-
)
50-
RETURNING id INTO final_match_options_id;
30+
31+
-- Read decider_best_of from the stage
32+
SELECT ts.decider_best_of INTO _decider_best_of
33+
FROM tournament_stages ts WHERE ts.id = _stage_id;
34+
35+
-- Determine effective best_of for decider matches
36+
IF _decider_best_of IS NOT NULL THEN
37+
_effective_best_of := _decider_best_of;
5138
ELSE
52-
final_match_options_id := original_match_options_id;
39+
-- Legacy behavior: only BO1 -> BO3, others unchanged
40+
IF match_options_record.best_of = 1 THEN
41+
_effective_best_of := 3;
42+
ELSE
43+
RETURN original_match_options_id;
44+
END IF;
5345
END IF;
54-
46+
47+
-- If target BO equals current BO, no clone needed
48+
IF _effective_best_of = match_options_record.best_of THEN
49+
RETURN original_match_options_id;
50+
END IF;
51+
52+
-- Clone match_options with the new best_of
53+
match_options_record.best_of := _effective_best_of;
54+
INSERT INTO match_options (
55+
overtime, knife_round, mr, best_of, coaches, number_of_substitutes,
56+
map_veto, timeout_setting, tech_timeout_setting, map_pool_id, type,
57+
regions, prefer_dedicated_server, invite_code, lobby_access,
58+
region_veto, ready_setting, check_in_setting, default_models, tv_delay
59+
) VALUES (
60+
match_options_record.overtime, match_options_record.knife_round,
61+
match_options_record.mr, match_options_record.best_of,
62+
match_options_record.coaches, match_options_record.number_of_substitutes,
63+
match_options_record.map_veto, match_options_record.timeout_setting,
64+
match_options_record.tech_timeout_setting, match_options_record.map_pool_id,
65+
match_options_record.type, match_options_record.regions,
66+
match_options_record.prefer_dedicated_server, match_options_record.invite_code,
67+
match_options_record.lobby_access, match_options_record.region_veto,
68+
match_options_record.ready_setting, match_options_record.check_in_setting,
69+
match_options_record.default_models, match_options_record.tv_delay
70+
)
71+
RETURNING id INTO final_match_options_id;
72+
5573
RETURN final_match_options_id;
5674
END;
5775
$$ LANGUAGE plpgsql;
58-

hasura/functions/tournaments/update_tournament_stages.sql

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,62 @@ BEGIN
293293
ELSE
294294
RAISE NOTICE ' => Linking matches within stage %', stage."order";
295295
PERFORM link_tournament_stage_matches(stage.id);
296+
297+
-- SE decider: apply decider best_of to final and optionally create 3rd place match
298+
IF stage.decider_best_of IS NOT NULL THEN
299+
DECLARE
300+
_decider_match_options_id uuid;
301+
_final_bracket_id uuid;
302+
_third_place_id uuid;
303+
_semi_record RECORD;
304+
BEGIN
305+
_decider_match_options_id := update_match_options_best_of(stage.id);
306+
307+
-- Apply decider match_options to the final (last round, match 1)
308+
SELECT id INTO _final_bracket_id
309+
FROM tournament_brackets
310+
WHERE tournament_stage_id = stage.id
311+
AND path = 'WB'
312+
AND round = total_rounds
313+
AND match_number = 1
314+
LIMIT 1;
315+
316+
IF _final_bracket_id IS NOT NULL AND _decider_match_options_id IS NOT NULL THEN
317+
UPDATE tournament_brackets
318+
SET match_options_id = _decider_match_options_id
319+
WHERE id = _final_bracket_id;
320+
321+
RAISE NOTICE ' => SE decider: applied decider match_options to final bracket %', _final_bracket_id;
322+
END IF;
323+
324+
-- Create 3rd place match if there are at least 2 rounds (semifinals exist)
325+
IF total_rounds >= 2 THEN
326+
INSERT INTO tournament_brackets (
327+
round, tournament_stage_id, match_number, "group", path, match_options_id
328+
) VALUES (
329+
total_rounds, stage.id, 2, 1, 'WB', _decider_match_options_id
330+
)
331+
RETURNING id INTO _third_place_id;
332+
333+
RAISE NOTICE ' => SE decider: created 3rd place bracket % in round %', _third_place_id, total_rounds;
334+
335+
-- Set loser_parent_bracket_id on semifinal brackets to route losers to 3rd place match
336+
FOR _semi_record IN
337+
SELECT id FROM tournament_brackets
338+
WHERE tournament_stage_id = stage.id
339+
AND path = 'WB'
340+
AND round = total_rounds - 1
341+
ORDER BY match_number ASC
342+
LOOP
343+
UPDATE tournament_brackets
344+
SET loser_parent_bracket_id = _third_place_id
345+
WHERE id = _semi_record.id;
346+
347+
RAISE NOTICE ' => SE decider: set semifinal % loser -> 3rd place %', _semi_record.id, _third_place_id;
348+
END LOOP;
349+
END IF;
350+
END;
351+
END IF;
296352
END IF;
297353
END LOOP;
298354

hasura/metadata/actions.graphql

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ type Mutation {
215215
): SuccessOutput
216216
}
217217

218+
type Mutation {
219+
refreshAllPlayers: SuccessOutput
220+
}
221+
218222
type Query {
219223
readServerFile(
220224
node_id: String!
@@ -330,6 +334,36 @@ type Mutation {
330334
): SuccessOutput
331335
}
332336

337+
type Query {
338+
getLeaderboard(
339+
category: String!
340+
window_days: Int!
341+
match_type: String
342+
limit: Int
343+
offset: Int
344+
exclude_tournaments: Boolean
345+
sort_by: String
346+
sort_dir: String
347+
): LeaderboardResponse!
348+
}
349+
350+
type LeaderboardResponse {
351+
entries: [LeaderboardEntry!]!
352+
total: Int!
353+
}
354+
355+
type LeaderboardEntry {
356+
rank: Int!
357+
player_steam_id: String!
358+
player_name: String!
359+
player_avatar_url: String
360+
player_country: String
361+
value: Float!
362+
secondary_value: Float
363+
tertiary_value: Float
364+
matches_played: Int
365+
}
366+
333367
input SampleInput {
334368
username: String!
335369
password: String!

hasura/metadata/actions.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,14 @@ actions:
304304
permissions:
305305
- role: administrator
306306
comment: Read file content from game server
307+
- name: refreshAllPlayers
308+
definition:
309+
kind: synchronous
310+
handler: '{{HASURA_GRAPHQL_ACTIONS_HOOK}}'
311+
forward_client_headers: true
312+
permissions:
313+
- role: administrator
314+
comment: Refresh all players in Typesense index
307315
- name: registerName
308316
definition:
309317
kind: synchronous
@@ -435,6 +443,14 @@ actions:
435443
permissions:
436444
- role: administrator
437445
comment: Write content to file on game server
446+
- name: getLeaderboard
447+
definition:
448+
kind: ""
449+
handler: '{{HASURA_GRAPHQL_ACTIONS_HOOK}}'
450+
forward_client_headers: true
451+
permissions:
452+
- role: guest
453+
comment: Get leaderboard rankings by category and time window
438454
custom_types:
439455
enums: []
440456
input_objects:
@@ -488,4 +504,6 @@ custom_types:
488504
- name: StorageStats
489505
- name: StorageSummary
490506
- name: TableSizeInfo
507+
- name: LeaderboardResponse
508+
- name: LeaderboardEntry
491509
scalars: []

hasura/metadata/databases/default/tables/public_player_elo.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ event_triggers:
3131
columns: '*'
3232
retry_conf:
3333
interval_sec: 10
34-
num_retries: 0
34+
num_retries: 6
3535
timeout_sec: 60
3636
webhook: '{{HASURA_GRAPHQL_EVENT_HOOK}}'

hasura/metadata/databases/default/tables/public_player_sanctions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ event_triggers:
6464
- type
6565
retry_conf:
6666
interval_sec: 10
67-
num_retries: 0
67+
num_retries: 6
6868
timeout_sec: 60
6969
webhook: '{{HASURA_GRAPHQL_EVENT_HOOK}}'

hasura/metadata/databases/default/tables/public_team_roster.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ event_triggers:
7878
columns: '*'
7979
retry_conf:
8080
interval_sec: 10
81-
num_retries: 0
81+
num_retries: 6
8282
timeout_sec: 60
8383
webhook: '{{HASURA_GRAPHQL_EVENT_HOOK}}'

hasura/metadata/databases/default/tables/public_tournament_stages.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ insert_permissions:
4242
is_organizer:
4343
_eq: true
4444
columns:
45+
- decider_best_of
4546
- groups
4647
- match_options_id
4748
- max_teams
@@ -55,6 +56,7 @@ select_permissions:
5556
- role: guest
5657
permission:
5758
columns:
59+
- decider_best_of
5860
- groups
5961
- id
6062
- match_options_id
@@ -71,6 +73,7 @@ update_permissions:
7173
- role: user
7274
permission:
7375
columns:
76+
- decider_best_of
7477
- groups
7578
- match_options_id
7679
- max_teams

0 commit comments

Comments
 (0)