diff --git a/admin.go b/admin.go index 0735153..6d308ab 100644 --- a/admin.go +++ b/admin.go @@ -122,7 +122,7 @@ func adminTeamsHandler(w http.ResponseWriter, r *http.Request) { } // Fetch all teams with their difficulty levels // 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 { http.Error(w, "Database error", http.StatusInternalServerError) return @@ -131,7 +131,7 @@ func adminTeamsHandler(w http.ResponseWriter, r *http.Request) { var teams []TeamTemplateS for rows.Next() { 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) return } @@ -176,7 +176,7 @@ func AdminStartHandler(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/admin/login", http.StatusSeeOther) 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 { http.Error(w, "Database error", http.StatusInternalServerError) return diff --git a/create.sql b/create.sql index b730177..3a32c78 100644 --- a/create.sql +++ b/create.sql @@ -13,6 +13,7 @@ CREATE TABLE TEAMS ( difficulty_level INTEGER NOT NULL, password VARCHAR(255) NOT NULL, 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, FOREIGN KEY (difficulty_level) REFERENCES DIFFICULTY_LEVELS(id) ); diff --git a/insertTestData.sql b/insertTestData.sql index 5980336..f7774cf 100644 --- a/insertTestData.sql +++ b/insertTestData.sql @@ -5,10 +5,10 @@ INSERT INTO DIFFICULTY_LEVELS (id, level_name) VALUES (3, 'Těžká'); -- Vložení týmů: heslo1, heslo2, heslo3 -INSERT INTO TEAMS (id, name, difficulty_level, password, last_cipher, penalty) VALUES - (1, 'Rychlé šípy', 1, '4bc2ef0648cdf275032c83bb1e87dd554d47f4be293670042212c8a01cc2ccbe', 1, 0), - (2, 'Vlčí smečka', 2, '274efeaa827a33d7e35be9a82cd6150b7caf98f379a4252aa1afce45664dcbe1', 1, 10), - (3, 'Orli', 3, '05af533c6614544a704c4cf51a45be5c10ff19bd10b7aa1dfe47efc0fd059ede', 1, 5); +INSERT INTO TEAMS (id, name, difficulty_level, password, last_cipher, last_loaded_cipher, penalty) VALUES + (1, 'Rychlé šípy', 1, '4bc2ef0648cdf275032c83bb1e87dd554d47f4be293670042212c8a01cc2ccbe', 1, 0, 0), + (2, 'Vlčí smečka', 2, '274efeaa827a33d7e35be9a82cd6150b7caf98f379a4252aa1afce45664dcbe1', 1, 0, 10), + (3, 'Orli', 3, '05af533c6614544a704c4cf51a45be5c10ff19bd10b7aa1dfe47efc0fd059ede', 1, 0, 5); -- Vložení pozic INSERT INTO POSITIONS (id, gps, clue) VALUES diff --git a/klice.go b/klice.go index 5f25d72..abbcc4d 100644 --- a/klice.go +++ b/klice.go @@ -198,12 +198,12 @@ func qrHandler(w http.ResponseWriter, r *http.Request) { http.Error(w, "This task is not yet available", http.StatusForbidden) return } else if order == last_cipher { - last_cipher = order - _, err = db.Exec("UPDATE teams SET last_cipher = ? WHERE id = ?", order, teamID) + _, err := db.Exec("UPDATE teams SET last_loaded_cipher = ? WHERE id = ?", order, teamID) 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 } + } else if order < last_cipher { help = 2 } diff --git a/templates.go b/templates.go index 716c541..c63ac32 100644 --- a/templates.go +++ b/templates.go @@ -19,11 +19,12 @@ type CipherTemplateS struct { } type TeamTemplateS struct { - ID int - TeamName string - Difficulty string - LastCipher int - Penalties int + ID int + TeamName string + Difficulty string + LastCipher int + LastLoadedCipher int + Penalties int } type DifficultyLevelS struct { diff --git a/templates/adminTeams.html b/templates/adminTeams.html index 894305e..be6294e 100644 --- a/templates/adminTeams.html +++ b/templates/adminTeams.html @@ -13,10 +13,10 @@