Esempio n. 1
0
func validateJoinTeam(ctx *_Context) error {
	if phrase, ok := ctx.urlParams["phrase"]; !ok || phrase == "" {
		return util.NewHttpError("Please provide a phrase", 400)
	}

	return nil
}
Esempio n. 2
0
package clues

import (
	"github.com/pjherring/ggc/biz/progress"
	"github.com/pjherring/ggc/table"
	"github.com/pjherring/ggc/util"
)

var (
	WrongAnswer = util.NewHttpError("Incorrent answer.", 400)
)

//Answer will try the potential answer and advance the progress if correct
func Answer(clueId, teamId int64, potential string) error {
	clue, err := table.FindClue(clueId)
	if err != nil {
		return err
	}

	if !clue.TryAnswer(potential) {
		return WrongAnswer
	}

	return progress.Advance(clueId, teamId)
}
Esempio n. 3
0
package record

import (
	"strconv"
	"strings"
	"time"

	"github.com/go-sql-driver/mysql"
	"github.com/pjherring/ggc/util"
)

var (
	WrongTrack    = util.NewHttpError("Incorrect track", 500)
	NoCluesRemain = util.NewHttpError("No clues left in track.", 400)
)

type Track struct {
	TrackId            int64
	Name               string
	questionIdOrderRaw string
	QuestionIdOrder    PipeSeparatedList
	StartTime          mysql.NullTime
	EndTime            mysql.NullTime
}

func (t Track) Active(now time.Time) bool {
	return (t.EndTime.Valid && t.EndTime.Time.After(now)) && (t.StartTime.Valid && t.StartTime.Time.Before(now))
}

func ExtractClueIdsFromTracks(tracks []*Track) (clueIds []int64) {
	unique := map[int64]bool{}
Esempio n. 4
0
package table

import (
	"database/sql"

	"github.com/pjherring/ggc/record"
	"github.com/pjherring/ggc/util"
)

var (
	InvalidTelephone = util.NewHttpError("Invalid Telephone", 400)
	DuplicateUser    = util.NewHttpError("Duplicate User", 400)
	NoUser           = util.NewHttpError("User does not exist", 400)
)

func CreateUser(telephone string, teamId int64) (*record.User, error) {
	telephone = util.FormatTelephone(telephone)

	if len(telephone) != 10 {
		return nil, InvalidTelephone
	}

	if dup, err := isDuplicateUserTelephone(telephone); err != nil {
		return nil, err
	} else if dup {
		return nil, DuplicateUser
	}

	u := &record.User{
		Telephone:       telephone,
		TeamId:          teamId,
Esempio n. 5
0
	"github.com/pjherring/ggc/record"
	"github.com/pjherring/ggc/util"
)

const (
	startProgressQuery = `
	INSERT INTO team_progress
	(team_id, question_id, start_time)
	VALUES
	(?, ?, ?)
	`
)

var (
	TeamProgressExists = util.NewHttpError("Team already in progress", 400)
	NoProgress         = util.NewHttpError("No progress for team", 400)
)

func StartProgress(clueId, teamId int64) error {
	_, err := db.Exec(startProgressQuery, teamId, clueId, time.Now())
	return err
}

const updateClueTeamQuery = `
UPDATE team_progress
SET answer_time = ?
WHERE question_id = ? AND team_id = ?
`

func FinishProgressForClueTeam(now time.Time, clueId, teamId int64) error {
Esempio n. 6
0
File: ask.go Progetto: pjherring/ggc
package hint

import (
	"github.com/pjherring/ggc/table"
	"github.com/pjherring/ggc/util"
)

var NoHintsLeft error = util.NewHttpError(
	"No hints remain", 400,
)

//Ask should get the current hint for team
//It should return nothing when all hints have been taken
//This assumes each clue only has two hints
func Ask(teamId int64) (string, error) {

	currentClue, err := table.FindClueWithProgressForTeam(teamId)
	if err != nil {
		return "", err
	}

	if currentClue.HintCnt < 2 {
		err = table.IncrementHintsTakenForClueTeam(currentClue.Clue.ClueId, teamId)
		if err != nil {
			return "", err
		}
	}

	switch currentClue.HintCnt {
	case 0:
		return currentClue.Clue.HintOne, nil
Esempio n. 7
0
package table

import (
	"database/sql"
	"strings"
	"time"

	"github.com/pjherring/ggc/record"
	"github.com/pjherring/ggc/util"
)

var (
	ErrBadPhrase = util.NewHttpError("No team matches that phrase", 400)
)

const updateTeamStartTimeQuery = `
UPDATE teams SET start_time = ? WHERE team_id = ?
`

//sets the team start time
func UpdateTeamStartTime(teamId int64, t time.Time) error {
	_, err := db.Exec(updateTeamStartTimeQuery, t, teamId)
	return err
}

func UpdateTeamFinishTime(teamId int64, t *time.Time) error {

	var err error

	if t == nil {
		_, err = db.Exec(
Esempio n. 8
0
package biz

import (
	"time"

	"github.com/pjherring/ggc/record"
	"github.com/pjherring/ggc/table"
	"github.com/pjherring/ggc/util"
)

const (
	clueDisabledAdvancement = "You have gone to the next clue because the previous clue was disabled."
	clueAnsweredAdvancement = "You have gone to the next clue because the previous clue was answered by a teammate of yours."
)

var (
	WrongAnswerForClue   = util.NewHttpError("Incorrect answer.", 400)
	WrongLocationForClue = util.NewHttpError("Incorrect location.", 400)
)

func FindCurrentClues(now time.Time) ([]*record.Clue, error) {
	//find current tracks
	tracks, err := table.FindCurrentTracks(now)
	if err != nil {
		return nil, err
	}

	clueIds := record.ExtractClueIdsFromTracks(tracks)
	return table.FindManyClues(clueIds)
}