Example #1
0
func EnterRollOff(w http.ResponseWriter, r *http.Request) {
	id := r.URL.Path[len("/roll-off-entry/"):]
	fmt.Println("User wishes to enter rolloff ", id)
	rollingUser := ParseUser(r)
	entry := &RollOffEntry{User: rollingUser, Score: rand.Intn(100) + 1}

	for _, r := range rolloffs {
		fmt.Println("Checking rolloff ", r.Id)
		if r.Id == id {
			r.AddEntry(entry)
			for elem := room.Users.Front(); elem != nil; elem = elem.Next() {
				go func(e *list.Element) {
					var tName string
					u := e.Value.(*User)
					if u == rollingUser {
						tName = "templates/roll-off/user-joins.html"
					} else {
						tName = "templates/roll-off/other-user-joins.html"
					}
					t := template.Must(template.ParseFile(tName))
					m := NewMessage("system", "", "system")
					t.Execute(m, entry)
					u.c <- m
				}(elem)
			}
		}
	}
}