mirror of https://github.com/dirtbags/moth.git
New rule: (category, points) must be unique across the contest. No more having 2 tokens in a category with the same point value.
This commit is contained in:
parent
f914f1d65d
commit
5070c70d25
|
@ -199,7 +199,7 @@ func (ctx Instance) answerHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ctx.AwardPointsUniquely(teamid, category, points); err != nil {
|
if err := ctx.AwardPoints(teamid, category, points); err != nil {
|
||||||
respond(
|
respond(
|
||||||
w, req, Error,
|
w, req, Error,
|
||||||
"Error awarding points",
|
"Error awarding points",
|
||||||
|
|
|
@ -114,27 +114,12 @@ func (ctx *Instance) PointsLog() []*Award {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// awardPoints gives points points to team teamid in category category
|
// awardPoints gives points to teamid in category.
|
||||||
|
// It first checks to make sure these are not duplicate points.
|
||||||
|
// This is not a perfect check, you can trigger a race condition here.
|
||||||
|
// It's just a courtesy to the user.
|
||||||
|
// The maintenance task makes sure we never have duplicate points in the log.
|
||||||
func (ctx *Instance) AwardPoints(teamid, category string, points int) error {
|
func (ctx *Instance) AwardPoints(teamid, category string, points int) error {
|
||||||
fn := fmt.Sprintf("%s-%s-%d", teamid, category, points)
|
|
||||||
tmpfn := ctx.StatePath("points.tmp", fn)
|
|
||||||
newfn := ctx.StatePath("points.new", fn)
|
|
||||||
|
|
||||||
contents := fmt.Sprintf("%d %s %s %d\n", time.Now().Unix(), teamid, category, points)
|
|
||||||
|
|
||||||
if err := ioutil.WriteFile(tmpfn, []byte(contents), 0644); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := os.Rename(tmpfn, newfn); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("Award %s %s %d", teamid, category, points)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ctx *Instance) AwardPointsUniquely(teamid, category string, points int) error {
|
|
||||||
a := Award{
|
a := Award{
|
||||||
When: time.Now(),
|
When: time.Now(),
|
||||||
TeamId: teamid,
|
TeamId: teamid,
|
||||||
|
@ -148,7 +133,20 @@ func (ctx *Instance) AwardPointsUniquely(teamid, category string, points int) er
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.AwardPoints(teamid, category, points)
|
fn := fmt.Sprintf("%s-%s-%d", teamid, category, points)
|
||||||
|
tmpfn := ctx.StatePath("points.tmp", fn)
|
||||||
|
newfn := ctx.StatePath("points.new", fn)
|
||||||
|
|
||||||
|
if err := ioutil.WriteFile(tmpfn, []byte(a.String()), 0644); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.Rename(tmpfn, newfn); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Award %s %s %d", teamid, category, points)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctx *Instance) OpenCategoryFile(category string, parts ...string) (io.ReadCloser, error) {
|
func (ctx *Instance) OpenCategoryFile(category string, parts ...string) (io.ReadCloser, error) {
|
||||||
|
|
Loading…
Reference in New Issue