settings: Challenge can never ends

This commit is contained in:
nemunaire 2023-05-12 14:53:15 +02:00
parent d4f69059bf
commit aad95f1e53
12 changed files with 36 additions and 22 deletions

View File

@ -115,11 +115,13 @@ const indextpl = `<!DOCTYPE html>
<span>{{"{{ startIn }}"}}</span>" <span>{{"{{ startIn }}"}}</span>"
<span class="point">|</span> <span class="point">|</span>
</span> </span>
<span id="hours">{{"{{ time.hours | time }}"}}</span> <span ng-show="settings && settings.end > 0">
<span class="point">:</span> <span id="hours">{{"{{ time.hours | time }}"}}</span>
<span id="min">{{"{{ time.minutes | time }}"}}</span> <span class="point">:</span>
<span class="point">:</span> <span id="min">{{"{{ time.minutes | time }}"}}</span>
<span id="sec">{{"{{ time.seconds | time }}"}}</span> <span class="point">:</span>
<span id="sec">{{"{{ time.seconds | time }}"}}</span>
</span>
</span> </span>
</nav> </nav>

View File

@ -545,7 +545,8 @@ angular.module("FICApp")
response.enableExerciceDepend = response.unlockedChallengeDepth >= 0; response.enableExerciceDepend = response.unlockedChallengeDepth >= 0;
response.disabledsubmitbutton = response.disablesubmitbutton && response.disablesubmitbutton.length > 0; response.disabledsubmitbutton = response.disablesubmitbutton && response.disablesubmitbutton.length > 0;
$rootScope.settings.start = new Date(response.start); $rootScope.settings.start = new Date(response.start);
$rootScope.settings.end = new Date(response.end); if (response.end) $rootScope.settings.end = new Date(response.end);
else $rootScope.settings.end = null;
$rootScope.settings.generation = new Date(response.generation); $rootScope.settings.generation = new Date(response.generation);
$rootScope.settings.activateTime = new Date(response.activateTime); $rootScope.settings.activateTime = new Date(response.activateTime);
}) })
@ -581,8 +582,10 @@ angular.module("FICApp")
} }
$scope.saveSettings = function(msg) { $scope.saveSettings = function(msg) {
if (msg === undefined) { msg = 'New settings saved!'; } if (msg === undefined) { msg = 'New settings saved!'; }
var nStart = this.config.start; if (this.config.end == "") this.config.end = null;
var nEnd = this.config.end;
var nStart = this.config.start;
var nEnd = this.config.end;
var nGen = this.config.generation; var nGen = this.config.generation;
var state = this.config.enableExerciceDepend; var state = this.config.enableExerciceDepend;
this.config.unlockedChallengeDepth = (this.config.enableExerciceDepend?this.config.unlockedChallengeDepth:-1) this.config.unlockedChallengeDepth = (this.config.enableExerciceDepend?this.config.unlockedChallengeDepth:-1)
@ -602,7 +605,11 @@ angular.module("FICApp")
response.enableExerciceDepend = response.unlockedChallengeDepth >= 0; response.enableExerciceDepend = response.unlockedChallengeDepth >= 0;
response.disabledsubmitbutton = response.disablesubmitbutton && response.disablesubmitbutton.length > 0; response.disabledsubmitbutton = response.disablesubmitbutton && response.disablesubmitbutton.length > 0;
$rootScope.settings.start = new Date(nStart); $rootScope.settings.start = new Date(nStart);
$rootScope.settings.end = new Date(nEnd); if (nEnd) {
$rootScope.settings.end = new Date(nEnd);
} else {
$rootScope.settings.end = null;
}
$rootScope.settings.generation = new Date(nGen); $rootScope.settings.generation = new Date(nGen);
}, function(response) { }, function(response) {
$scope.addToast('danger', 'An error occurs when saving settings:', response.data.errmsg); $scope.addToast('danger', 'An error occurs when saving settings:', response.data.errmsg);

View File

@ -263,7 +263,7 @@ angular.module("FICApp")
} }
function updTime() { function updTime() {
if (time && $rootScope.settings) { if (time && $rootScope.settings && $rootScope.settings.end) {
var srv_cur = new Date(Date.now() + (time.cu - time.he)); var srv_cur = new Date(Date.now() + (time.cu - time.he));
// Refresh on start/activate time reached // Refresh on start/activate time reached

View File

@ -510,7 +510,7 @@
</div> </div>
</div> </div>
<div ng-controller="CountdownController" style="position: fixed; bottom: {{ display.hideCarousel?'0':'109px' }}; right: 0; width: 33vw; overflow: hidden; padding-top: 25px;" ng-if="!display.hideCountdown" ng-cloak> <div ng-controller="CountdownController" style="position: fixed; bottom: {{ display.hideCarousel?'0':'109px' }}; right: 0; width: 33vw; overflow: hidden; padding-top: 25px;" ng-if="!display.hideCountdown && time.end" ng-cloak>
<div class="bg-light text-center text-dark" ng-if="time.hours === 0 || time.hours" style="margin-top: -5px; width: inherit; {{ display.customCountdown?'':'box-shadow: white 0px -10px 15px 0px;' }}"> <div class="bg-light text-center text-dark" ng-if="time.hours === 0 || time.hours" style="margin-top: -5px; width: inherit; {{ display.customCountdown?'':'box-shadow: white 0px -10px 15px 0px;' }}">
<div class="clock" ng-class="{expired: time.expired, end: time.end}" style="font-size: 50px"> <div class="clock" ng-class="{expired: time.expired, end: time.end}" style="font-size: 50px">
<span id="hours">{{ time.hours | time }}</span> <span id="hours">{{ time.hours | time }}</span>
@ -594,7 +594,7 @@
<td>{{ settings.start | date:"HH'&nbsp;h&nbsp;'mm" }}</td> <td>{{ settings.start | date:"HH'&nbsp;h&nbsp;'mm" }}</td>
<td>Début du challenge</td> <td>Début du challenge</td>
</tr> </tr>
<tr> <tr ng-if="settings.end">
<td>{{ settings.end | date:"HH'&nbsp;h&nbsp;'mm" }}</td> <td>{{ settings.end | date:"HH'&nbsp;h&nbsp;'mm" }}</td>
<td>Fin du challenge</td> <td>Fin du challenge</td>
</tr> </tr>

View File

@ -7,7 +7,7 @@ import (
) )
func WantChoicesHandler(w http.ResponseWriter, r *http.Request, team string, sURL []string) { func WantChoicesHandler(w http.ResponseWriter, r *http.Request, team string, sURL []string) {
if time.Now().After(challengeEnd) { if challengeEnd != nil && time.Now().After(*challengeEnd) {
http.Error(w, "{\"errmsg\":\"Le challenge est terminé, trop tard !\"}", http.StatusGone) http.Error(w, "{\"errmsg\":\"Le challenge est terminé, trop tard !\"}", http.StatusGone)
return return
} }

View File

@ -7,7 +7,7 @@ import (
) )
func HintHandler(w http.ResponseWriter, r *http.Request, team string, sURL []string) { func HintHandler(w http.ResponseWriter, r *http.Request, team string, sURL []string) {
if time.Now().After(challengeEnd) { if challengeEnd != nil && time.Now().After(*challengeEnd) {
http.Error(w, "{\"errmsg\":\"Le challenge est terminé, trop tard pour un indice !\"}", http.StatusGone) http.Error(w, "{\"errmsg\":\"Le challenge est terminé, trop tard pour un indice !\"}", http.StatusGone)
return return
} }

View File

@ -17,7 +17,7 @@ const resolutiontpl = `<!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Challenge Forensic - Résolution</title> <title>Résolution</title>
</head> </head>
<body style="margin: 0"> <body style="margin: 0">
<video src="{{.}}" controls width="100%" height="100%"></video> <video src="{{.}}" controls width="100%" height="100%"></video>

View File

@ -12,7 +12,7 @@ var startedFile = "started"
var touchTimer *time.Timer = nil var touchTimer *time.Timer = nil
var challengeStart time.Time var challengeStart time.Time
var challengeEnd time.Time var challengeEnd *time.Time
func touchStartedFile() { func touchStartedFile() {
if fd, err := os.Create(startedFile); err == nil { if fd, err := os.Create(startedFile); err == nil {

View File

@ -9,7 +9,7 @@ import (
) )
func SubmissionHandler(w http.ResponseWriter, r *http.Request, team string, sURL []string) { func SubmissionHandler(w http.ResponseWriter, r *http.Request, team string, sURL []string) {
if time.Now().After(challengeEnd) { if challengeEnd != nil && time.Now().After(*challengeEnd) {
http.Error(w, "{\"errmsg\":\"Vous ne pouvez plus soumettre, le challenge est terminé.\"}", http.StatusGone) http.Error(w, "{\"errmsg\":\"Vous ne pouvez plus soumettre, le challenge est terminé.\"}", http.StatusGone)
return return
} }

View File

@ -8,7 +8,7 @@
import { settings, time } from '$lib/stores/settings.js'; import { settings, time } from '$lib/stores/settings.js';
</script> </script>
{#if $settings} {#if $settings && $settings.end}
{#if $settings.end - $settings.start > 0} {#if $settings.end - $settings.start > 0}
<div <div
class="clock display-2 text-end text-md-center" class="clock display-2 text-end text-md-center"
@ -69,7 +69,7 @@
{:else} {:else}
<div class="d-flex h-100 justify-content-center align-items-center"> <div class="d-flex h-100 justify-content-center align-items-center">
<h1 class="display-3 m-0"> <h1 class="display-3 m-0">
Challenge forensic {$challengeInfo.title}
</h1> </h1>
</div> </div>
{/if} {/if}

View File

@ -1,6 +1,7 @@
package fic package fic
import ( import (
"fmt"
"time" "time"
"srs.epita.fr/fic-server/settings" "srs.epita.fr/fic-server/settings"
@ -36,6 +37,10 @@ func GenZQDSSessionFile(c *settings.ChallengeInfo, s *settings.Settings) (*Sessi
return nil, err return nil, err
} }
if s.End == nil {
return nil, fmt.Errorf("Please define an end date")
}
var challenges []*ChallengeZQDS var challenges []*ChallengeZQDS
for _, th := range themes { for _, th := range themes {
@ -75,7 +80,7 @@ func GenZQDSSessionFile(c *settings.ChallengeInfo, s *settings.Settings) (*Sessi
Rules: c.Rules, Rules: c.Rules,
YourMission: c.YourMission, YourMission: c.YourMission,
Start: s.Start, Start: s.Start,
End: s.End, End: *s.End,
Challenges: challenges, Challenges: challenges,
}, nil }, nil
} }

View File

@ -27,8 +27,8 @@ type Settings struct {
// Start is the departure time (expected or effective). // Start is the departure time (expected or effective).
Start time.Time `json:"start"` Start time.Time `json:"start"`
// End is the expected end time. // End is the expected end time (if empty their is no end-date).
End time.Time `json:"end"` End *time.Time `json:"end,omitempty"`
// Generation is a value used to regenerate static files. // Generation is a value used to regenerate static files.
Generation time.Time `json:"generation"` Generation time.Time `json:"generation"`
// ActivateTime is the time when the current file should be proceed. // ActivateTime is the time when the current file should be proceed.