last loaded cipher

This commit is contained in:
2025-10-28 17:00:46 +01:00
parent 94440e78de
commit cbe7ddc51b
6 changed files with 20 additions and 17 deletions

View File

@@ -122,7 +122,7 @@ func adminTeamsHandler(w http.ResponseWriter, r *http.Request) {
} }
// Fetch all teams with their difficulty levels // Fetch all teams with their difficulty levels
// Teams // Teams
rows, err := db.Query("SELECT teams.id, name, difficulty_levels.level_name, last_cipher, penalty FROM teams JOIN difficulty_levels ON teams.difficulty_level = difficulty_levels.id ORDER BY teams.difficulty_level, teams.name") rows, err := db.Query("SELECT teams.id, name, difficulty_levels.level_name, last_cipher, last_loaded_cipher, penalty FROM teams JOIN difficulty_levels ON teams.difficulty_level = difficulty_levels.id ORDER BY teams.difficulty_level, teams.name")
if err != nil { if err != nil {
http.Error(w, "Database error", http.StatusInternalServerError) http.Error(w, "Database error", http.StatusInternalServerError)
return return
@@ -131,7 +131,7 @@ func adminTeamsHandler(w http.ResponseWriter, r *http.Request) {
var teams []TeamTemplateS var teams []TeamTemplateS
for rows.Next() { for rows.Next() {
var team TeamTemplateS var team TeamTemplateS
if err := rows.Scan(&team.ID, &team.TeamName, &team.Difficulty, &team.LastCipher, &team.Penalties); err != nil { if err := rows.Scan(&team.ID, &team.TeamName, &team.Difficulty, &team.LastCipher, &team.LastLoadedCipher, &team.Penalties); err != nil {
http.Error(w, "Database error", http.StatusInternalServerError) http.Error(w, "Database error", http.StatusInternalServerError)
return return
} }
@@ -176,7 +176,7 @@ func AdminStartHandler(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/admin/login", http.StatusSeeOther) http.Redirect(w, r, "/admin/login", http.StatusSeeOther)
return return
} }
_, err := db.Exec("UPDATE teams SET last_cipher = 1, penalty = 0") _, err := db.Exec("UPDATE teams SET last_cipher = 1, last_loaded_cipher = 0, penalty = 0")
if err != nil { if err != nil {
http.Error(w, "Database error", http.StatusInternalServerError) http.Error(w, "Database error", http.StatusInternalServerError)
return return

View File

@@ -13,6 +13,7 @@ CREATE TABLE TEAMS (
difficulty_level INTEGER NOT NULL, difficulty_level INTEGER NOT NULL,
password VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL,
last_cipher INTEGER DEFAULT 0, -- index of cipher which team is solving or searching now last_cipher INTEGER DEFAULT 0, -- index of cipher which team is solving or searching now
last_loaded_cipher INTEGER DEFAULT 0, -- index of cipher which team has loaded last time
penalty INTEGER DEFAULT 0, penalty INTEGER DEFAULT 0,
FOREIGN KEY (difficulty_level) REFERENCES DIFFICULTY_LEVELS(id) FOREIGN KEY (difficulty_level) REFERENCES DIFFICULTY_LEVELS(id)
); );

View File

@@ -5,10 +5,10 @@ INSERT INTO DIFFICULTY_LEVELS (id, level_name) VALUES
(3, 'Těžká'); (3, 'Těžká');
-- Vložení týmů: heslo1, heslo2, heslo3 -- Vložení týmů: heslo1, heslo2, heslo3
INSERT INTO TEAMS (id, name, difficulty_level, password, last_cipher, penalty) VALUES INSERT INTO TEAMS (id, name, difficulty_level, password, last_cipher, last_loaded_cipher, penalty) VALUES
(1, 'Rychlé šípy', 1, '4bc2ef0648cdf275032c83bb1e87dd554d47f4be293670042212c8a01cc2ccbe', 1, 0), (1, 'Rychlé šípy', 1, '4bc2ef0648cdf275032c83bb1e87dd554d47f4be293670042212c8a01cc2ccbe', 1, 0, 0),
(2, 'Vlčí smečka', 2, '274efeaa827a33d7e35be9a82cd6150b7caf98f379a4252aa1afce45664dcbe1', 1, 10), (2, 'Vlčí smečka', 2, '274efeaa827a33d7e35be9a82cd6150b7caf98f379a4252aa1afce45664dcbe1', 1, 0, 10),
(3, 'Orli', 3, '05af533c6614544a704c4cf51a45be5c10ff19bd10b7aa1dfe47efc0fd059ede', 1, 5); (3, 'Orli', 3, '05af533c6614544a704c4cf51a45be5c10ff19bd10b7aa1dfe47efc0fd059ede', 1, 0, 5);
-- Vložení pozic -- Vložení pozic
INSERT INTO POSITIONS (id, gps, clue) VALUES INSERT INTO POSITIONS (id, gps, clue) VALUES

View File

@@ -198,12 +198,12 @@ func qrHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, "This task is not yet available", http.StatusForbidden) http.Error(w, "This task is not yet available", http.StatusForbidden)
return return
} else if order == last_cipher { } else if order == last_cipher {
last_cipher = order _, err := db.Exec("UPDATE teams SET last_loaded_cipher = ? WHERE id = ?", order, teamID)
_, err = db.Exec("UPDATE teams SET last_cipher = ? WHERE id = ?", order, teamID)
if err != nil { if err != nil {
http.Error(w, "Could not update last cipher", http.StatusInternalServerError) http.Error(w, "Could not update last loaded cipher", http.StatusInternalServerError)
return return
} }
} else if order < last_cipher { } else if order < last_cipher {
help = 2 help = 2
} }

View File

@@ -19,11 +19,12 @@ type CipherTemplateS struct {
} }
type TeamTemplateS struct { type TeamTemplateS struct {
ID int ID int
TeamName string TeamName string
Difficulty string Difficulty string
LastCipher int LastCipher int
Penalties int LastLoadedCipher int
Penalties int
} }
type DifficultyLevelS struct { type DifficultyLevelS struct {

View File

@@ -13,10 +13,10 @@
<th>ID</th> <th>ID</th>
<th>Název týmu</th> <th>Název týmu</th>
<th>Obtížnost</th> <th>Obtížnost</th>
<th>Poslední šifra</th> <th>Právě řešená šifra</th>
<th>Poslední načtená šifra</th>
<th>Penalizace (minuty)</th> <th>Penalizace (minuty)</th>
<th>Smazat tým</th> <th>Smazat tým</th>
</th>
</tr> </tr>
{{range .Teams}} {{range .Teams}}
<tr> <tr>
@@ -24,6 +24,7 @@
<td>{{.TeamName}}</td> <td>{{.TeamName}}</td>
<td>{{.Difficulty}}</td> <td>{{.Difficulty}}</td>
<td>{{.LastCipher}}</td> <td>{{.LastCipher}}</td>
<td>{{.LastLoadedCipher}}</td>
<td>{{.Penalties}}</td> <td>{{.Penalties}}</td>
<td> <td>
<form action="/admin/teams" method="post"> <form action="/admin/teams" method="post">