add the killzone for fine grained management of enemies
Ted Unangst tedu@tedunangst.com
Mon, 22 Apr 2019 13:08:35 -0400
3 files changed,
82 insertions(+),
0 deletions(-)
M
honk.go
→
honk.go
@@ -958,6 +958,55 @@ }
http.Redirect(w, r, "/honkers", http.StatusSeeOther) } +type Zonker struct { + Name string + Wherefore string +} + +func killzone(w http.ResponseWriter, r *http.Request) { + db := opendatabase() + userinfo := GetUserInfo(r) + rows, err := db.Query("select name, wherefore from zonkers where userid = ?", userinfo.UserID) + if err != nil { + log.Printf("err: %s", err) + return + } + var zonkers []Zonker + for rows.Next() { + var z Zonker + rows.Scan(&z.Name, &z.Wherefore) + zonkers = append(zonkers, z) + } + templinfo := getInfo(r) + templinfo["Zonkers"] = zonkers + templinfo["KillCSRF"] = GetCSRF("killitwithfire", r) + err = readviews.ExecuteTemplate(w, "zonkers.html", templinfo) + if err != nil { + log.Print(err) + } +} + +func killitwithfire(w http.ResponseWriter, r *http.Request) { + userinfo := GetUserInfo(r) + wherefore := r.FormValue("wherefore") + name := r.FormValue("name") + if name == "" { + return + } + switch wherefore { + case "zonker": + case "zurl": + case "zonvoy": + default: + return + } + db := opendatabase() + db.Exec("insert into zonkers (userid, name, wherefore) values (?, ?, ?)", + userinfo.UserID, name, wherefore) + + http.Redirect(w, r, "/killzone", http.StatusSeeOther) +} + func somedays() string { secs := 432000 + notrand.Int63n(432000) return fmt.Sprintf("%d", secs)@@ -1020,6 +1069,7 @@ readviews = ParseTemplates(debug,
"views/homepage.html", "views/honkpage.html", "views/honkers.html", + "views/zonkers.html", "views/honkform.html", "views/honk.html", "views/login.html",@@ -1040,6 +1090,7 @@ getters := mux.Methods("GET").Subrouter()
getters.HandleFunc("/", homepage) getters.Handle("/atme", LoginRequired(http.HandlerFunc(homepage))) + getters.Handle("/killzone", LoginRequired(http.HandlerFunc(killzone))) getters.HandleFunc("/rss", showrss) getters.HandleFunc("/u/{name:[[:alnum:]]+}", viewuser) getters.HandleFunc("/u/{name:[[:alnum:]]+}/h/{xid:[[:alnum:]]+}", viewhonk)@@ -1063,6 +1114,7 @@ loggedin.Use(LoginRequired)
loggedin.Handle("/honk", CSRFWrap("honkhonk", http.HandlerFunc(savehonk))) loggedin.Handle("/bonk", CSRFWrap("honkhonk", http.HandlerFunc(savebonk))) loggedin.Handle("/zonkit", CSRFWrap("honkhonk", http.HandlerFunc(zonkit))) + loggedin.Handle("/killitwithfire", CSRFWrap("killitwithfire", http.HandlerFunc(killitwithfire))) loggedin.Handle("/saveuser", CSRFWrap("saveuser", http.HandlerFunc(saveuser))) loggedin.HandleFunc("/honkers", showhonkers) loggedin.Handle("/savehonker", CSRFWrap("savehonker", http.HandlerFunc(savehonker)))
M
views/header.html
→
views/header.html
@@ -16,6 +16,7 @@ {{ if .UserInfo }}
<span><a href="/atme">@me</a></span> <span><a href="/u/{{ .UserInfo.Username }}">{{ .UserInfo.Username }}</a></span> <span><a href="/honkers">honkers</a></span> +<span><a href="/killzone">killzone</a></span> <span><a href="/logout?CSRF={{ .LogoutCSRF }}">logout</a></span> {{ else }} <span><a href="/login">login</a></span>
A
views/zonkers.html
@@ -0,0 +1,29 @@
+{{ template "header.html" . }} +<div class="center"> +<div class="info"> +<p> +<form action="/killitwithfire" method="POST"> +<span class="title">kill another zonker</span> +<input type="hidden" name="CSRF" value="{{ .KillCSRF }}"> +<p> +<input tabindex=1 type="text" name="name" value="" autocomplete=off> - name +<p> +<input type="radio" id="iszonker" name="wherefore" value="zonker"> +<label for="iszonker">Zonker</label> +<p> +<input type="radio" id="iszurl" name="wherefore" value="zurl"> +<label for="iszurl">Zurl</label> +<p> +<input type="radio" id="iszonvoy" name="wherefore" value="zonvoy"> +<label for="iszonvoy">Zonvoy</label> +<p><input tabindex=1 type="submit" name="kill" value="kill"> +</form> +</div> +{{ range .Zonkers }} +<div class="honk" id="honkerID"> +<p>What: {{ .Name }} +<p>Where: {{ .Wherefore }} +</div> +{{ end }} +</div> +</div>