fix tournament registration bug after disconnect
This commit is contained in:
@@ -345,6 +345,25 @@ shared_ptr<Tournament::Match> Tournament::get_final_match() const {
|
||||
return this->final_match;
|
||||
}
|
||||
|
||||
shared_ptr<Tournament::Team> Tournament::team_for_serial_number(
|
||||
uint32_t serial_number) const {
|
||||
if (!this->all_player_serial_numbers.count(serial_number)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (auto team : this->teams) {
|
||||
if (!team->player_serial_numbers.count(serial_number)) {
|
||||
continue;
|
||||
}
|
||||
if (!team->is_active) {
|
||||
return nullptr;
|
||||
}
|
||||
return team;
|
||||
}
|
||||
|
||||
throw logic_error("serial number registered in tournament but not in any team");
|
||||
}
|
||||
|
||||
void Tournament::start() {
|
||||
if (this->current_state != State::REGISTRATION) {
|
||||
throw runtime_error("tournament has already started");
|
||||
@@ -470,6 +489,20 @@ shared_ptr<Tournament> TournamentIndex::get_tournament(const string& name) const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
shared_ptr<Tournament::Team> TournamentIndex::team_for_serial_number(
|
||||
uint32_t serial_number) const {
|
||||
for (size_t z = 0; z < 0x20; z++) {
|
||||
if (!this->tournaments[z]) {
|
||||
continue;
|
||||
}
|
||||
auto team = this->tournaments[z]->team_for_serial_number(serial_number);
|
||||
if (team) {
|
||||
return team;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
@@ -105,6 +105,8 @@ public:
|
||||
std::shared_ptr<Team> get_winner_team() const;
|
||||
std::shared_ptr<Match> next_match_for_team(std::shared_ptr<Team> team) const;
|
||||
std::shared_ptr<Match> get_final_match() const;
|
||||
std::shared_ptr<Team> team_for_serial_number(uint32_t serial_number) const;
|
||||
|
||||
void start();
|
||||
|
||||
void print_bracket(FILE* stream) const;
|
||||
@@ -155,6 +157,9 @@ public:
|
||||
std::shared_ptr<Tournament> get_tournament(uint8_t number) const;
|
||||
std::shared_ptr<Tournament> get_tournament(const std::string& name) const;
|
||||
|
||||
std::shared_ptr<Tournament::Team> team_for_serial_number(
|
||||
uint32_t serial_number) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Tournament> tournaments[0x20];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user