func (c *Tags) Tag(player_id int, code string) revel.Result { errJson := make(map[string]string) err := c.Auth() if err != nil { return c.RenderError(err) } if !c.SentAuth() { c.Response.Status = 401 errJson["error"] = "No authentication information was sent" return c.RenderJson(errJson) } if c.User == nil { c.Response.Status = 403 errJson["error"] = "User credentials bad" return c.RenderJson(errJson) } tagger, err := models.PlayerFromId(player_id) if err != nil { return c.RenderError(err) } if !tagger.IsZombie() { c.Response.Status = 403 errJson["error"] = "You cannot tag because you are not a zombie" return c.RenderJson(errJson) } if tagger.User_id != c.User.Id { c.Response.Status = 403 errJson["error"] = "Tags cannot be registered for other users" return c.RenderJson(errJson) } human, status, err := models.PlayerFromHumanCode(code) if err != nil { c.Response.Status = status return c.RenderError(err) } game := human.Game() if !game.IsRunning() { c.Response.Status = 422 errJson["error"] = "Tags cannot be registered when the game is closed" return c.RenderJson(errJson) } now := time.Now() _, status, err = models.NewTag(game, tagger, human, &now) if err != nil { c.Response.Status = status return c.RenderError(err) } return c.Redirect(routes.Players.Read(human.Id)) }
func TagByRandomTaggedZombie() { oz := SelectRandomTaggedZombie() oz_player, _ := models.PlayerFromId(oz.Id) human := SelectTestHuman("AND player.game_id = $1", oz_player.Game_id) if human == nil { return } now := time.Now() game, _ := models.GameFromId(human.Game_id) _, _, err := models.NewTag(game, oz_player, human, &now) if err != nil { revel.WARN.Print(err) } }