44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package fic
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// truncateTable performs an insecure wipe on the given tables.
|
|
func truncateTable(tables ...string) (error) {
|
|
if tx, err := db.BeginTx(context.TODO(), nil); err != nil {
|
|
return err
|
|
} else {
|
|
if _, err := tx.Exec("SET FOREIGN_KEY_CHECKS = 0;"); err != nil {
|
|
return err
|
|
}
|
|
for _, table := range tables {
|
|
if _, err := tx.Exec("TRUNCATE TABLE " + table + ";"); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if _, err := tx.Exec("SET FOREIGN_KEY_CHECKS = 1;"); err != nil {
|
|
return err
|
|
}
|
|
if err := tx.Commit(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ResetGame resets all tables containing team attempts and solves.
|
|
func ResetGame() (error) {
|
|
return truncateTable("team_hints", "key_found", "mcq_found", "exercice_solved", "exercice_tries")
|
|
}
|
|
|
|
// ResetExercices wipes out all challenges (both attempts and statements).
|
|
func ResetExercices() (error) {
|
|
return truncateTable("team_hints", "exercice_files_deps", "exercice_files", "key_found", "exercice_keys", "exercice_solved", "exercice_tries", "exercice_hints", "mcq_found", "mcq_entries", "exercice_mcq", "exercices", "themes")
|
|
}
|
|
|
|
// ResetTeams wipes out all teams, incluings members and attempts.
|
|
func ResetTeams() (error) {
|
|
return truncateTable("team_hints", "key_found", "mcq_found", "exercice_solved", "exercice_tries", "team_members", "teams")
|
|
}
|