func ProcessCreateGuild(res http.ResponseWriter, req *http.Request, base *BaseController) { owner := req.PostFormValue("owner") name := req.PostFormValue("name") if len(name) > 20 || len(name) < 5 { base.Session.SetFlash("Guild name must be between 5 - 20 characters", "error") http.Redirect(res, req, "/guilds/list", 301) return } rgxp, err := regexp.Compile(`^[A-Z a-z]+$`) if err != nil { http.Error(res, "Error while compiling regexp at process create guild", 500) return } if !rgxp.MatchString(name) { base.Session.SetFlash("Guild name can only contain A - z characters", "error") http.Redirect(res, req, "/guilds/list", 301) return } if !models.CheckCharacterNameOfAccount(owner, base.Account.Id) { base.Session.SetFlash("Wrong character selected", "error") http.Redirect(res, req, "/guilds/list", 301) return } owner_info := models.GetCharacterByName(owner) if models.CheckGuildName(name) { base.Session.SetFlash("Guild name already in use", "error") http.Redirect(res, req, "/guilds/list", 301) return } if models.CheckGuildOwner(owner_info.Id) { base.Session.SetFlash("Character already owns a guild", "error") http.Redirect(res, req, "/guilds/list", 301) return } if models.CheckCharacterInGuild(owner_info.Id) { base.Session.SetFlash("Character already in a guild", "error") http.Redirect(res, req, "/guilds/list", 301) return } logo, err := ioutil.ReadFile(config.Parser.Style.Template + "/public/images/logo.gif") if err != nil { http.Error(res, "Error while creating reading base logo "+err.Error(), 500) return } guild_logo, err := os.Create(config.Parser.Style.Template + "/public/guilds/" + name + ".gif") if err != nil { http.Error(res, "Error while creating your guild logo "+err.Error(), 500) return } defer guild_logo.Close() guild_logo.Write(logo) err = models.CreateGuild(name, owner_info.Id) if err != nil { http.Error(res, "Error while creating your guild "+err.Error(), 500) return } http.Redirect(res, req, fmt.Sprintf("/guilds/view/%v", url.QueryEscape(name)), 301) }
func ProcessGuildInvite(res http.ResponseWriter, req *http.Request, base *BaseController) { name, err := url.QueryUnescape(mux.Vars(req)["name"]) if err != nil { http.Error(res, "Error while unescaping guild name", 500) return } captcha_response, err := captcha.Verify(req.FormValue("g-recaptcha-response")) if err != nil { http.Error(res, "Error while checking captcha code", 500) return } if !captcha_response { base.Session.SetFlash("Wrong captcha response", "error") http.Redirect(res, req, fmt.Sprintf("/guilds/view/%v", mux.Vars(req)["name"]), 301) return } if !models.CheckGuildName(name) { http.Error(res, "Unknown guild", 500) return } characters, err := models.GetAccountCharacters(base.Account.Id) if err != nil { http.Error(res, "Error while getting account characters", 500) return } guild_info := models.GetGuildIdByName(name) if !checkAccountOwner(characters, guild_info) { http.Error(res, "You arent the owner of this guild", 500) return } player_name := req.PostFormValue("player") if !models.CheckCharacterName(player_name) { base.Session.SetFlash("Player not found", "error") http.Redirect(res, req, fmt.Sprintf("/guilds/view/%v", url.QueryEscape(name)), 301) return } player_info := models.GetCharacterByName(player_name) if models.CheckCharacterInGuild(player_info.Id) { base.Session.SetFlash("Player is already in a guild", "error") http.Redirect(res, req, fmt.Sprintf("/guilds/view/%v", url.QueryEscape(name)), 301) return } err = models.CreateGuildInvite(guild_info.Id, player_info.Id) if err != nil { log.Println(err) http.Error(res, "Error while inviting player", 301) return } base.Session.SetFlash("Player invited to the guild", "success") http.Redirect(res, req, fmt.Sprintf("/guilds/view/%v", url.QueryEscape(name)), 301) return }