about summary refs log tree commit diff
path: root/src/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.go')
-rw-r--r--src/main.go25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/main.go b/src/main.go
index 65a3212..c789cf8 100644
--- a/src/main.go
+++ b/src/main.go
@@ -30,7 +30,7 @@ func initFlags() {
 
 	flag.StringVar(&logFilePath, "logfilepath", "./server.log", "The path to the log file")
 	flag.StringVar(&databasePath, "databasepath", "./main.db", "The path to the main database")
-	flag.StringVar(&sessiondbPath, "sessiondbpath", "./sesions.db", "The path to the session database")
+	flag.StringVar(&sessiondbPath, "sessiondbpath", "./sessions.db", "The path to the session database")
 	flag.StringVar(&templatesPath, "templates", "./templates", "The path to the templates used")
 }
 
@@ -86,11 +86,30 @@ func main() {
 	auth_needed.HandleFunc("/user/{id}", userHandler)
 	auth_needed.HandleFunc("/user/{id}/profile", profileHandler)
 
-	auth_needed.HandleFunc("/battle", battlesHandler)
+	r.HandleFunc("/battle", battlesHandler)
+	r.HandleFunc("/battle/{id}", battleSingleHandler)
 	auth_needed.HandleFunc("/battle/new", battleNewHandler)
-	auth_needed.HandleFunc("/battle/{id}", battleSingleHandler)
+	auth_needed.HandleFunc("/battle/quick", battleQuickHandler)
 	auth_needed.HandleFunc("/battle/{id}/submit", battleSubmitHandler)
+	auth_needed.HandleFunc("/battle/{id}/run", battleRunHandler)
+	auth_needed.HandleFunc("/battle/{id}/delete", battleDeleteHandler)
 
 	log.Printf("[i] HTTP Server running on %s:%d\n", host, port)
 	log.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%d", host, port), r))
 }
+
+/* Convenience functions */
+
+// log_and_redir_with_msg takes a few args, let's go through them one by one:
+//   - w: the response writer
+//   - r: the initial request
+//   - err: the error that occurred, this one will be logged
+//   - target: the target of the redirect, this must be a format string with some format parameter
+//     receiving a string, for example `/battles/?err=%s`, the `%s` format string will then be
+//     filled with the message
+//   - msg: the message to print after being redirected
+func log_and_redir_with_msg(w http.ResponseWriter, r *http.Request, err error, target string, msg string) {
+	log.Println(err)
+	http.Redirect(w, r, fmt.Sprintf(target, msg), http.StatusSeeOther)
+	return
+}