diff --git a/.gitignore b/.gitignore index 1c06632..15553bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ server.* .env +./tmp/ diff --git a/internal/handlers/auth.go b/internal/handlers/auth.go index eaff965..7ea9016 100644 --- a/internal/handlers/auth.go +++ b/internal/handlers/auth.go @@ -34,7 +34,7 @@ func (h *Handler) Callback(w http.ResponseWriter, r *http.Request) { store := sessions.NewCookieStore([]byte(key)) store.MaxAge(maxAge) store.Options.Path = "/" - store.Options.HttpOnly = true // HttpOnly should always be enabled + store.Options.HttpOnly = true store.Options.Secure = isProd gothic.Store = store diff --git a/main.go b/main.go index 2e73d81..e3809ed 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( "context" - "flag" "fmt" "net/http" "os" @@ -19,9 +18,6 @@ import ( ) func main() { - dev := flag.Bool("dev", true, "is this a dev env?") - flag.Parse() - err := godotenv.Load() if err != nil { fmt.Printf("error loading .env file: %v", err) @@ -38,6 +34,8 @@ func main() { os.Getenv("TWITCH_CLIENT_ID"), os.Getenv("TWITCH_SECRET"), os.Getenv("TWITCH_CALLBACK"), + "channel:read:redemptions", + "channel:manage:redemptions", ), ) @@ -61,16 +59,11 @@ func main() { } go func() { - if *dev { - fmt.Println("Dev server started...") - if err := server.ListenAndServe(); err != http.ErrServerClosed { - fmt.Printf("Serve error: %v\n", err) - } - } else { - fmt.Println("Server started...") - if err := server.ListenAndServeTLS("server.crt", "server.key"); err != http.ErrServerClosed { - fmt.Printf("Serve error: %v\n", err) - } + fmt.Println("Server started...") + fmt.Println(os.Getenv("TWITCH_CALLBACK")) + + if err := server.ListenAndServe(); err != http.ErrServerClosed { + fmt.Printf("Serve error: %v\n", err) } }() diff --git a/static/script.js b/static/script.js index 3d96a37..51a23bc 100644 --- a/static/script.js +++ b/static/script.js @@ -25,6 +25,8 @@ window.addEventListener("DOMContentLoaded", function() { this.isPunching = false; this.punchHasHit = false; this.sentJoin = false; + this.hp = 10; + this.isAlive = true; } @@ -36,6 +38,15 @@ window.addEventListener("DOMContentLoaded", function() { this.facing = -1; } + if (this.crouching && this.keys.l) { + this.speed = 0.5; + this.vx = this.speed; + } + if (this.crouching && this.keys.h) { + this.speed = 0.5; + this.vx = -this.speed; + } + if (this.keys.l) { this.vx = this.speed; this.facing = 1; @@ -146,7 +157,7 @@ window.addEventListener("DOMContentLoaded", function() { // speech bubble if (this.talking) { const padding = 12; - const maxMessageWidth = 150; + const maxMessageWidth = 100; // set font BEFORE measuring ctx.font = "12px sans-serif"; @@ -155,11 +166,11 @@ window.addEventListener("DOMContentLoaded", function() { const textWidth = ctx.measureText(this.message).width; const widths = lines.map(line => ctx.measureText(line).width); const contentWidth = Math.max(...widths, textWidth); - const bubbleWidth = Math.min(contentWidth + padding * 2, maxMessageWidth + padding * 2); - const lineHeight = 18; + const bubbleWidth = Math.min(contentWidth + padding + 10, maxMessageWidth + padding + 10); + const lineHeight = 14; const bubbleHeight = lines.length * lineHeight + padding; - const bubbleX = x - bubbleWidth; - const bubbleY = y - 30; + const bubbleX = x - bubbleWidth - 15; + const bubbleY = y - 20; ctx.beginPath(); ctx.fillStyle = "white"; @@ -180,11 +191,11 @@ window.addEventListener("DOMContentLoaded", function() { // name tag ctx.save(); - ctx.font = "14px sans-serif"; + ctx.font = "10px sans-serif"; ctx.textAlign = "center"; ctx.textBaseline = "bottom"; ctx.fillStyle = "black"; - ctx.fillText(this.id, x, y - 12); + ctx.fillText(this.id, x, y - 19); ctx.restore(); } @@ -272,7 +283,11 @@ window.addEventListener("DOMContentLoaded", function() { this.leaveBtn = document.getElementById(leaveBtnId); this.time = 0; - this.players = {}; + this.players = { + "player": new StickFigure(10, 1, "player", this.canvas), + "player1": new StickFigure(100, 1, "player1", this.canvas) + + }; this.pageData = this._getPageData(); this.ws = null; @@ -362,11 +377,21 @@ window.addEventListener("DOMContentLoaded", function() { if (playerAPunch && !playerA.punchHasHit && rectangleOverlap(playerAPunch, playerBBody)) { playerA.punchHasHit = true; console.log("Player A hits player B"); + playerB.hp -= 1; + if (playerB.hp == 0) { + playerB.isAlive = false; + delete this.players[playerB.id] + } } if (playerBPunch && !playerB.punchHasHit && rectangleOverlap(playerBPunch, playerABody)) { playerB.punchHasHit = true; console.log("Player B hits player A") + playerA.hp -= 1; + if (playerA.hp == 0) { + playerA.isAlive = false; + delete this.players[playerA.id] + } } } } @@ -400,16 +425,16 @@ window.addEventListener("DOMContentLoaded", function() { me.punch() this._sendAction('e', "keyDown") break; - case 'w': + case 'k': me.jump(); this._sendAction('k', "keyDown") break; - case 's': + case 'j': me.crouching = true; this._sendAction('j', 'keyDown') break; - case 'a': - case 'd': + case 'h': + case 'l': if (!me.keys) me.keys = {}; if (!me.keys[e.key]) me.keys[e.key] = true; this._sendAction(e.key, 'keyDown') @@ -431,12 +456,13 @@ window.addEventListener("DOMContentLoaded", function() { this.chatInput.focus(); } - if (e.key === 's') { + if (e.key === 'j') { me.crouching = false; + me.speed = 2; this._sendAction('j', 'keyUp') } - if (e.key === 'a' || e.key === 'd') { + if (e.key === 'h' || e.key === 'l') { if (!me.keys) me.keys = {}; me.keys[e.key] = false; this._sendAction(e.key, 'keyUp') diff --git a/tmp/build-errors.log b/tmp/build-errors.log index 7582694..1abbe85 100644 --- a/tmp/build-errors.log +++ b/tmp/build-errors.log @@ -1 +1 @@ -exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1 \ No newline at end of file +exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1 \ No newline at end of file diff --git a/tmp/main b/tmp/main index 70dcad7..0a2f587 100755 Binary files a/tmp/main and b/tmp/main differ diff --git a/todo.md b/todo.md index 482ce9c..27a872f 100644 --- a/todo.md +++ b/todo.md @@ -1,9 +1,5 @@ - fix sending empty messages -- hit points - death - weapons from channel point - - https://dev.twitch.tv/docs/eventsub/ - jetpack -- remap wasd -- allow users to set their own keybindings -- map attack to mouse click as well