Private
Public Access
Add WebAssembly support for assets and chunks, implement gameover screen rendering, and enhance server gameplay logic with dynamic speeds, team naming, and score components.
This commit is contained in:
1 parent
ce51a2ba4f
commit
95d61bf66e
68 files changed
+913
-424
No files matched your search
@@ -26,13 +26,15 @@ type WebSocketMessage struct {
|
||||
|
||||
// WebSocketClient repräsentiert einen verbundenen WebSocket-Client
|
||||
type WebSocketClient struct {
|
||||
conn *websocket.Conn
|
||||
natsConn *nats.EncodedConn
|
||||
playerID string
|
||||
roomID string
|
||||
send chan []byte
|
||||
mutex sync.Mutex
|
||||
subUpdates *nats.Subscription
|
||||
conn *websocket.Conn
|
||||
natsConn *nats.EncodedConn
|
||||
playerID string
|
||||
playerCode string
|
||||
roomID string
|
||||
send chan []byte
|
||||
mutex sync.Mutex
|
||||
subUpdates *nats.Subscription
|
||||
subScoreResp *nats.Subscription
|
||||
}
|
||||
|
||||
// handleWebSocket verwaltet eine WebSocket-Verbindung
|
||||
@@ -62,6 +64,9 @@ func (c *WebSocketClient) readPump() {
|
||||
if c.subUpdates != nil {
|
||||
c.subUpdates.Unsubscribe()
|
||||
}
|
||||
if c.subScoreResp != nil {
|
||||
c.subScoreResp.Unsubscribe()
|
||||
}
|
||||
c.conn.Close()
|
||||
log.Printf("🔌 WebSocket-Client getrennt: %s", c.conn.RemoteAddr())
|
||||
}()
|
||||
@@ -208,6 +213,35 @@ func (c *WebSocketClient) handleMessage(msg WebSocketMessage) {
|
||||
}
|
||||
|
||||
log.Printf("📊 WebSocket Score-Submit: Player=%s, Score=%d", submit.PlayerCode, submit.Score)
|
||||
|
||||
// Speichere PlayerCode und subscribe auf Response-Channel
|
||||
if c.playerCode == "" && submit.PlayerCode != "" {
|
||||
c.playerCode = submit.PlayerCode
|
||||
|
||||
// Subscribe auf Score-Response für diesen Spieler
|
||||
responseChannel := "score.response." + submit.PlayerCode
|
||||
sub, err := c.natsConn.Subscribe(responseChannel, func(resp *game.ScoreSubmissionResponse) {
|
||||
// ScoreSubmissionResponse an WebSocket-Client senden
|
||||
data, _ := json.Marshal(map[string]interface{}{
|
||||
"type": "score_response",
|
||||
"payload": resp,
|
||||
})
|
||||
select {
|
||||
case c.send <- data:
|
||||
log.Printf("📤 Proof-Code an Client gesendet: %s", resp.ProofCode)
|
||||
default:
|
||||
log.Printf("⚠️ Send channel voll, Proof-Code verworfen")
|
||||
}
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Printf("❌ Fehler beim Subscribe auf %s: %v", responseChannel, err)
|
||||
} else {
|
||||
c.subScoreResp = sub
|
||||
log.Printf("👂 WebSocket-Client lauscht auf Score-Responses: %s", responseChannel)
|
||||
}
|
||||
}
|
||||
|
||||
c.natsConn.Publish("score.submit", &submit)
|
||||
|
||||
default:
|
||||
|
||||
Reference in new issue
Block a user