Пример #1
0
func ProcessPlayerDelete(res http.ResponseWriter, req *http.Request, base *BaseController) {
	name, err := url.QueryUnescape(mux.Vars(req)["name"])
	if err != nil {
		http.Error(res, "Error processing name url query", 500)
		return
	}
	if !models.CheckCharacterNameOfAccount(name, base.Account.Id) || !models.CheckCharacterAlive(name) {
		http.Redirect(res, req, "/account/manage", 301)
		return
	}
	password := sha1.Sum([]byte(req.PostFormValue("password")))
	if !models.CheckAccountPassword(fmt.Sprintf("%x", password)) {
		base.Session.SetFlash("Password is not correct!", "error")
		http.Redirect(res, req, "/account/manage/delete/"+name, 301)
		return
	}
	delete_time := time.Now().Unix() + (86400 * 60)
	err = models.SoftDeletePlayer(delete_time, name)
	if err != nil {
		http.Error(res, "Error while deleting character", 500)
		return
	}
	delete_time_date := time.Unix(delete_time, 0)
	delete_time_string := fmt.Sprintf("%v %v %v, %v:%v:%v", delete_time_date.Month().String()[:3], delete_time_date.Day(), delete_time_date.Year(), delete_time_date.Hour(), delete_time_date.Minute(), delete_time_date.Second())
	views.Parser.ExecuteTemplate(res, "delete_character_success.html", &DeleteCharacterSuccessResponse{"account-manage", name, delete_time_string})
}
Пример #2
0
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)
}
Пример #3
0
func ShowPlayerEdit(res http.ResponseWriter, req *http.Request, base *BaseController) {
	name, err := url.QueryUnescape(mux.Vars(req)["name"])
	if err != nil {
		http.Error(res, "Error processing name url query", 500)
		return
	}
	if !models.CheckCharacterNameOfAccount(name, base.Account.Id) || !models.CheckCharacterAlive(name) {
		http.Redirect(res, req, "/account/manage", 301)
		return
	}
	csrf_token := GenerateToken(12)
	base.Session.SetValue("csrf", csrf_token)
	character_info := models.GetCharacterByName(name)
	r := &EditCharacterResponse{"account-manage", character_info, csrf_token, base.Session.GetFlashes("error")}
	views.Parser.ExecuteTemplate(res, "edit_character.html", r)
}
Пример #4
0
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)
}
Пример #5
0
func ProcessPlayerEdit(res http.ResponseWriter, req *http.Request, base *BaseController) {
	name, err := url.QueryUnescape(mux.Vars(req)["name"])
	if err != nil {
		http.Error(res, "Error processing name url query", 500)
		return
	}
	captcha_response, err := captcha.Verify(req.PostFormValue("g-recaptcha-response"))
	if err != nil {
		http.Error(res, "Error checking captcha response", 500)
		return
	}
	if !captcha_response {
		base.Session.SetFlash("Wrong captcha response", "error")
		http.Redirect(res, req, "/account/manage/edit/"+name, 301)
		return
	}
	if !models.CheckCharacterNameOfAccount(name, base.Account.Id) || !models.CheckCharacterAlive(name) {
		http.Redirect(res, req, "/account/manage", 301)
		return
	}
	comment := req.PostFormValue("comment")
	if len(comment) > 100 {
		base.Session.SetFlash("Comment is bigger than 100 characters", "error")
		http.Redirect(res, req, "/account/manage/edit/"+name, 301)
		return
	}
	comment_lines := strings.Split(comment, "\n")
	if len(comment_lines) > 10 {
		base.Session.SetFlash("You cant have more than 10 comment lines", "error")
		http.Redirect(res, req, "/account/manage/edit/"+name, 301)
		return
	}
	signature := req.PostFormValue("signature")
	hide := req.PostFormValue("accountvisible")
	err = models.EditCharacter(name, comment, signature, hide)
	if err != nil {
		http.Error(res, "Error editing character", 500)
		return
	}
	views.Parser.ExecuteTemplate(res, "edit_character_success.html", &EditCharacterSuccessResponse{"account-manage"})
}