From b3d36c7a66463595a2be1ed4b3bb68f03e6462b9 Mon Sep 17 00:00:00 2001 From: gyboth Date: Sun, 23 Nov 2008 15:06:00 +0000 Subject: [PATCH] Added cup fixture checking. --- src/cup.c | 21 +++++++++++++++++++++ src/cup.h | 3 +++ src/fixture.c | 4 +++- src/fixture.h | 2 +- src/start_end.c | 20 ++++++++++++++------ 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/cup.c b/src/cup.c index aac35208..795c7434 100644 --- a/src/cup.c +++ b/src/cup.c @@ -1102,3 +1102,24 @@ cup_get_highlight_colour(const Cup *cup) return NULL; } + +/** Check the cup fixtures for suspicious entries. */ +gboolean +cup_check_fixtures(const Cup *cup) +{ + gint i; + + for(i = 0; i < cup->fixtures->len; i++) + { + if(g_array_index(cup->fixtures, Fixture, i).teams[0] == + g_array_index(cup->fixtures, Fixture, i).teams[1]) + { + if(!query_cup_has_property(cup->id, "silent_on_fixture_error")) + g_warning("cup_check_fixture: bad fixture found in cup %s; cup will be disabled\n", cup->name); + + return FALSE; + } + } + + return TRUE; +} diff --git a/src/cup.h b/src/cup.h index c0ba8c3b..bc81c78e 100644 --- a/src/cup.h +++ b/src/cup.h @@ -133,4 +133,7 @@ query_cup_transfer(void); gchar* cup_get_highlight_colour(const Cup *cup); +gboolean +cup_check_fixtures(const Cup *cup); + #endif diff --git a/src/fixture.c b/src/fixture.c index 56825316..d5db55bd 100644 --- a/src/fixture.c +++ b/src/fixture.c @@ -99,7 +99,7 @@ fixture_write_league_fixtures(League *league) /** Write the fixtures for the given cup at the beginning of a new season. @param cup The cup we write the fixtures for. */ -void +gboolean fixture_write_cup_fixtures(Cup *cup) { gint i; @@ -115,6 +115,8 @@ fixture_write_cup_fixtures(Cup *cup) fixture_write_knockout_round( cup, 0, misc_copy_ptr_array( g_array_index(cup->rounds, CupRound, 0).team_ptrs)); + + return cup_check_fixtures(cup); } /** Update the fixtures for the given cup. diff --git a/src/fixture.h b/src/fixture.h index 8209b0e0..04c37d65 100644 --- a/src/fixture.h +++ b/src/fixture.h @@ -43,7 +43,7 @@ enum FixtureCompare void fixture_write_league_fixtures(League *league); -void +gboolean fixture_write_cup_fixtures(Cup *cup); void diff --git a/src/start_end.c b/src/start_end.c index 811c393d..5e106232 100644 --- a/src/start_end.c +++ b/src/start_end.c @@ -111,7 +111,7 @@ start_new_season(void) { cup_reset(&cp(i)); fixture_write_cup_fixtures(&cp(i)); - } + } if(season > 1) { @@ -183,7 +183,14 @@ start_new_season(void) } } } - + + for(i = acps->len - 1; i >= 0; i--) + if(!cup_check_fixtures(acp(i))) + { + cup_reset(acp(i)); + g_ptr_array_remove_index(acps, i); + } + stat5 = -1; for(i=0;ilen;i++) @@ -433,8 +440,9 @@ end_week_round_update_fixtures(void) query_cup_begins(&cp(i))) { cp(i).last_week = cup_get_last_week_from_first(&cp(i), week + 1); - fixture_write_cup_fixtures(&cp(i)); - g_ptr_array_add(acps, &cp(i)); + + if(fixture_write_cup_fixtures(&cp(i))) + g_ptr_array_add(acps, &cp(i)); } } } @@ -525,8 +533,8 @@ start_week_add_cups(void) for(i=0;ilen;i++) if(cp(i).add_week == week) { - g_ptr_array_add(acps, &cp(i)); - fixture_write_cup_fixtures(&cp(i)); + if(fixture_write_cup_fixtures(&cp(i))) + g_ptr_array_add(acps, &cp(i)); } }