lol cursor is multiplayer now

This commit is contained in:
ari melody 2025-03-14 20:42:44 +00:00
parent a797e82a68
commit 4b3c8f9449
Signed by: ari
GPG key ID: 60B5F0386E3DDB7E
7 changed files with 362 additions and 107 deletions

16
main.go
View file

@ -1,11 +1,13 @@
package main
import (
"bufio"
"errors"
"fmt"
stdLog "log"
"math"
"math/rand"
"net"
"net/http"
"os"
"path/filepath"
@ -17,9 +19,10 @@ import (
"arimelody-web/api"
"arimelody-web/colour"
"arimelody-web/controller"
"arimelody-web/cursor"
"arimelody-web/log"
"arimelody-web/model"
"arimelody-web/templates"
"arimelody-web/log"
"arimelody-web/view"
"github.com/jmoiron/sqlx"
@ -428,6 +431,8 @@ func main() {
os.Exit(1)
}
go cursor.StartCursor(&app)
// start the web server!
mux := createServeMux(&app)
fmt.Printf("Now serving at http://%s:%d\n", app.Config.Host, app.Config.Port)
@ -444,6 +449,7 @@ func createServeMux(app *model.AppState) *http.ServeMux {
mux.Handle("/api/", http.StripPrefix("/api", api.Handler(app)))
mux.Handle("/music/", http.StripPrefix("/music", view.MusicHandler(app)))
mux.Handle("/uploads/", http.StripPrefix("/uploads", staticHandler(filepath.Join(app.Config.DataDirectory, "uploads"))))
mux.Handle("/cursor-ws", cursor.Handler(app))
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodHead {
w.WriteHeader(http.StatusOK)
@ -536,6 +542,14 @@ type LoggingResponseWriter struct {
Status int
}
func (lrw *LoggingResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
hijack, ok := lrw.ResponseWriter.(http.Hijacker)
if !ok {
return nil, nil, errors.New("Server does not support hijacking\n")
}
return hijack.Hijack()
}
func (lrw *LoggingResponseWriter) WriteHeader(status int) {
lrw.Status = status
lrw.ResponseWriter.WriteHeader(status)