示例#1
0
func AdminGetGame(c *common.HTTPContext) (err error) {
	gameId, err := base64.URLEncoding.DecodeString(c.Vars()["game_id"])
	if err != nil {
		return
	}
	g := &Game{Id: gameId}
	if err = c.DB().Get(g); err != nil {
		return
	}
	members, err := g.Members(c.DB())
	if err != nil {
		return
	}
	memberStates, err := members.ToStates(c.DB(), g, "", true)
	if err != nil {
		return
	}
	phases, err := g.Phases(c.DB())
	if err != nil {
		return
	}
	sort.Sort(phases)
	return c.RenderJSON(AdminGameState{
		Game:    g,
		Phases:  phases,
		Members: memberStates,
	})
}
示例#2
0
func Token(c *common.HTTPContext) (err error) {
	if emailIf, found := c.Session().Values[common.SessionEmail]; found {
		token := &gosubs.Token{
			Principal: fmt.Sprint(emailIf),
			Timeout:   time.Now().Add(time.Second * 10),
		}
		if err = token.Encode(c.Secret()); err != nil {
			return
		}
		err = c.RenderJSON(token)
	} else {
		err = c.RenderJSON(gosubs.Token{})
	}
	return
}
示例#3
0
func AdminGetOptions(c *common.HTTPContext) (err error) {
	gameId, err := base64.URLEncoding.DecodeString(c.Vars()["game_id"])
	if err != nil {
		return
	}
	game := &Game{Id: gameId}
	if err = c.DB().Get(game); err != nil {
		return
	}
	_, last, err := game.Phase(c.DB(), 0)
	if err != nil {
		return
	}
	opts, err := last.Options(dip.Nation(c.Vars()["nation"]))
	if err != nil {
		return
	}
	return c.RenderJSON(opts)
}