func ProcessGuildInviteJoin(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 } player, err := url.QueryUnescape(mux.Vars(req)["player"]) if err != nil { http.Error(res, "Error while getting player name", 500) return } player_info := models.GetCharacterByName(player) if player_info.Name == "" { http.Error(res, "Unknown player", 500) return } guild_info := models.GetGuildIdByName(name) if guild_info.Name == "" { http.Error(res, "Unknown guild", 500) return } if !models.CheckCharacterNameOfAccount(player_info.Name, base.Account.Id) { http.Error(res, "Unkown character", 500) return } if !models.CheckGuildInvitation(player_info.Id, guild_info.Id) { http.Error(res, "Unkown guild invitation", 500) return } err, _ = models.DeleteGuildInvite(player_info.Id, guild_info.Id) if err != nil { http.Error(res, "Error while deleting guild invitation", 500) return } err = models.JoinGuild(player_info.Id, guild_info.Id) if err != nil { http.Error(res, "Error while joining guild: "+err.Error(), 500) return } base.Session.SetFlash("You joined the guild successfully", "success") http.Redirect(res, req, fmt.Sprintf("/guilds/view/%v", url.QueryEscape(name)), 301) }
func ProcessGuildInviteRemove(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 } player, err := url.QueryUnescape(mux.Vars(req)["player"]) if err != nil { http.Error(res, "Error while getting player name", 500) return } player_info := models.GetCharacterByName(player) if player_info.Name == "" { http.Error(res, "Unknown player", 500) return } guild_info := models.GetGuildIdByName(name) if guild_info.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 } if !checkAccountOwner(characters, guild_info) { http.Error(res, "You arent the owner of this guild", 500) return } err, _ = models.DeleteGuildInvite(player_info.Id, guild_info.Id) if err != nil { http.Error(res, "Error while deleting guild invitation", 500) return } base.Session.SetFlash("Removed guild invitation successfully!", "success") http.Redirect(res, req, fmt.Sprintf("/guilds/view/%v", url.QueryEscape(name)), 301) }