last loaded cipher
This commit is contained in:
6
admin.go
6
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
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
|
||||
@@ -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
|
||||
|
||||
6
klice.go
6
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
|
||||
}
|
||||
|
||||
11
templates.go
11
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 {
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
<th>ID</th>
|
||||
<th>Název týmu</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>Smazat tým</th>
|
||||
</th>
|
||||
</tr>
|
||||
{{range .Teams}}
|
||||
<tr>
|
||||
@@ -24,6 +24,7 @@
|
||||
<td>{{.TeamName}}</td>
|
||||
<td>{{.Difficulty}}</td>
|
||||
<td>{{.LastCipher}}</td>
|
||||
<td>{{.LastLoadedCipher}}</td>
|
||||
<td>{{.Penalties}}</td>
|
||||
<td>
|
||||
<form action="/admin/teams" method="post">
|
||||
|
||||
Reference in New Issue
Block a user