aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-05 22:01:08 +0900
committernsfisis <nsfisis@gmail.com>2024-08-05 22:01:08 +0900
commitdff6cfdc04fb7c93f74a53787539702cf6b982a9 (patch)
treebdb238c530826b6545f7208b0e4bb75051ebb446
parentb0ff29a3c88bd3014cc966c619683c8d7e33d703 (diff)
parenta5eaed753368a1fa701a0503dcb6522e19ccbcb0 (diff)
downloadiosdc-japan-2024-albatross-dff6cfdc04fb7c93f74a53787539702cf6b982a9.tar.gz
iosdc-japan-2024-albatross-dff6cfdc04fb7c93f74a53787539702cf6b982a9.tar.zst
iosdc-japan-2024-albatross-dff6cfdc04fb7c93f74a53787539702cf6b982a9.zip
Merge branch 'fix/multiplayer'
-rw-r--r--backend/admin/handlers.go6
-rw-r--r--backend/admin/templates/game_edit.html6
-rw-r--r--backend/admin/templates/user_edit.html2
-rw-r--r--backend/db/query.sql.go5
-rw-r--r--backend/fixtures/dev.sql10
-rw-r--r--backend/game/hub.go25
-rw-r--r--backend/game/message.go4
-rw-r--r--backend/query.sql15
-rw-r--r--backend/taskqueue/processor.go3
-rw-r--r--frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx3
-rw-r--r--worker/main.go9
11 files changed, 44 insertions, 44 deletions
diff --git a/backend/admin/handlers.go b/backend/admin/handlers.go
index d9a6977..d445de8 100644
--- a/backend/admin/handlers.go
+++ b/backend/admin/handlers.go
@@ -126,7 +126,7 @@ func (h *AdminHandler) getGames(c echo.Context) error {
for i, g := range rows {
var startedAt string
if !g.StartedAt.Valid {
- startedAt = g.StartedAt.Time.In(jst).Format("2006-01-02T15:04:05")
+ startedAt = g.StartedAt.Time.In(jst).Format("2006-01-02T15:04")
}
games[i] = echo.Map{
"GameID": g.GameID,
@@ -161,7 +161,7 @@ func (h *AdminHandler) getGameEdit(c echo.Context) error {
var startedAt string
if !row.StartedAt.Valid {
- startedAt = row.StartedAt.Time.In(jst).Format("2006-01-02T15:04:05")
+ startedAt = row.StartedAt.Time.In(jst).Format("2006-01-02T15:04")
}
return c.Render(http.StatusOK, "game_edit", echo.Map{
@@ -214,7 +214,7 @@ func (h *AdminHandler) postGameEdit(c echo.Context) error {
{
startedAtRaw := c.FormValue("started_at")
if startedAtRaw != "" {
- startedAtTime, err := time.Parse("2006-01-02T15:04:05", startedAtRaw)
+ startedAtTime, err := time.Parse("2006-01-02T15:04", startedAtRaw)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid started_at")
}
diff --git a/backend/admin/templates/game_edit.html b/backend/admin/templates/game_edit.html
index 764b577..108ae99 100644
--- a/backend/admin/templates/game_edit.html
+++ b/backend/admin/templates/game_edit.html
@@ -5,7 +5,7 @@
{{ end }}
{{ define "content" }}
-<form>
+<form method="post">
<div>
<label>Game ID</label>
<input type="text" name="game_id" value="{{ .Game.GameID }}" readonly required>
@@ -39,11 +39,11 @@
</div>
<div>
<label>Started At</label>
- <input type="datetime-local" name="started_at" value="{{ .Game.StartedAt }}">
+ <input type="datetime-local" name="started_at" value="{{ if .Game.StartedAt }}{{ .Game.StartedAt }}{{ end }}">
</div>
<div>
<label>Problem ID</label>
- <input type="text" name="problem_id" value="{{ .Game.ProblemID }}" disabled>
+ <input type="text" name="problem_id" value="{{ if .Game.ProblemID }}{{ .Game.ProblemID }}{{ end }}">
</div>
<div>
<button type="submit">Save</button>
diff --git a/backend/admin/templates/user_edit.html b/backend/admin/templates/user_edit.html
index 9089b1e..bde7c84 100644
--- a/backend/admin/templates/user_edit.html
+++ b/backend/admin/templates/user_edit.html
@@ -5,7 +5,7 @@
{{ end }}
{{ define "content" }}
-<form>
+<form method="post">
<div>
<label>User ID</label>
<input type="text" name="user_id" value="{{ .User.UserID }}" readonly required>
diff --git a/backend/db/query.sql.go b/backend/db/query.sql.go
index 89506d0..18acfda 100644
--- a/backend/db/query.sql.go
+++ b/backend/db/query.sql.go
@@ -162,6 +162,7 @@ const listGamePlayers = `-- name: ListGamePlayers :many
SELECT game_id, game_players.user_id, users.user_id, username, display_name, icon_path, is_admin, created_at FROM game_players
LEFT JOIN users ON game_players.user_id = users.user_id
WHERE game_players.game_id = $1
+ORDER BY game_players.user_id
`
type ListGamePlayersRow struct {
@@ -207,6 +208,7 @@ func (q *Queries) ListGamePlayers(ctx context.Context, gameID int32) ([]ListGame
const listGames = `-- name: ListGames :many
SELECT game_id, game_type, state, display_name, duration_seconds, created_at, started_at, games.problem_id, problems.problem_id, title, description FROM games
LEFT JOIN problems ON games.problem_id = problems.problem_id
+ORDER BY games.game_id
`
type ListGamesRow struct {
@@ -260,6 +262,7 @@ SELECT games.game_id, game_type, state, display_name, duration_seconds, created_
LEFT JOIN problems ON games.problem_id = problems.problem_id
JOIN game_players ON games.game_id = game_players.game_id
WHERE game_players.user_id = $1
+ORDER BY games.game_id
`
type ListGamesForPlayerRow struct {
@@ -315,6 +318,7 @@ func (q *Queries) ListGamesForPlayer(ctx context.Context, userID int32) ([]ListG
const listTestcasesByGameID = `-- name: ListTestcasesByGameID :many
SELECT testcase_id, problem_id, stdin, stdout FROM testcases
WHERE testcases.problem_id = (SELECT problem_id FROM games WHERE game_id = $1)
+ORDER BY testcases.testcase_id
`
func (q *Queries) ListTestcasesByGameID(ctx context.Context, gameID int32) ([]Testcase, error) {
@@ -344,6 +348,7 @@ func (q *Queries) ListTestcasesByGameID(ctx context.Context, gameID int32) ([]Te
const listUsers = `-- name: ListUsers :many
SELECT user_id, username, display_name, icon_path, is_admin, created_at FROM users
+ORDER BY users.user_id
`
func (q *Queries) ListUsers(ctx context.Context) ([]User, error) {
diff --git a/backend/fixtures/dev.sql b/backend/fixtures/dev.sql
index e8b8716..89f709a 100644
--- a/backend/fixtures/dev.sql
+++ b/backend/fixtures/dev.sql
@@ -20,7 +20,8 @@ VALUES
('TEST problem 3', 'This is TEST problem 3'),
('TEST problem 4', 'This is TEST problem 4'),
('TEST problem 5', 'This is TEST problem 5'),
- ('TEST problem 6', 'This is TEST problem 6');
+ ('TEST problem 6', 'This is TEST problem 6'),
+ ('TEST problem 7', 'This is TEST problem 7');
INSERT INTO games
(game_type, state, display_name, duration_seconds, problem_id)
@@ -30,7 +31,8 @@ VALUES
('1v1', 'finished', 'TEST game 3', 180, 3),
('multiplayer', 'waiting_start', 'TEST game 4', 180, 4),
('multiplayer', 'closed', 'TEST game 5', 180, 5),
- ('multiplayer', 'finished', 'TEST game 6', 180, 6);
+ ('multiplayer', 'finished', 'TEST game 6', 180, 6),
+ ('multiplayer', 'waiting_entries', 'TEST game 7', 180, 7);
INSERT INTO game_players
(game_id, user_id)
@@ -46,9 +48,11 @@ VALUES
(5, 1),
(5, 2),
(6, 1),
- (6, 2);
+ (6, 2),
+ (7, 1);
INSERT INTO testcases
(problem_id, stdin, stdout)
VALUES
(4, '', '42'),
+ (7, '', '42');
diff --git a/backend/game/hub.go b/backend/game/hub.go
index bb82170..719b216 100644
--- a/backend/game/hub.go
+++ b/backend/game/hub.go
@@ -7,7 +7,6 @@ import (
"time"
"github.com/jackc/pgx/v5/pgtype"
- "github.com/oapi-codegen/nullable"
"github.com/nsfisis/iosdc-japan-2024-albatross/backend/api"
"github.com/nsfisis/iosdc-japan-2024-albatross/backend/db"
@@ -149,14 +148,6 @@ func (hub *gameHub) run() {
// TODO: assert game state is gaming
log.Printf("code: %v", message.message)
code := msg.Data.Code
- score := len(code)
- message.client.s2cMessages <- &playerMessageS2CExecResult{
- Type: playerMessageTypeS2CExecResult,
- Data: playerMessageS2CExecResultPayload{
- Score: nullable.NewNullableWithValue(score),
- Status: api.GamePlayerMessageS2CExecResultPayloadStatusSuccess,
- },
- }
for watcher := range hub.watchers {
watcher.s2cMessages <- &watcherMessageS2CCode{
Type: watcherMessageTypeS2CCode,
@@ -165,15 +156,6 @@ func (hub *gameHub) run() {
Code: code,
},
}
- watcher.s2cMessages <- &watcherMessageS2CExecResult{
- Type: watcherMessageTypeS2CExecResult,
- Data: watcherMessageS2CExecResultPayload{
- PlayerID: message.client.playerID,
- Score: nullable.NewNullableWithValue(score),
- Stdout: "",
- Stderr: "",
- },
- }
}
case *playerMessageC2SSubmit:
// TODO: assert game state is gaming
@@ -188,6 +170,7 @@ func (hub *gameHub) run() {
log.Printf("unexpected message type: %T", message.message)
}
case executionStatus := <-hub.testcaseExecution:
+ _ = executionStatus
for player := range hub.players {
player.s2cMessages <- &playerMessageS2CExecResult{
Type: playerMessageTypeS2CExecResult,
@@ -197,6 +180,7 @@ func (hub *gameHub) run() {
},
}
}
+ // broadcast to watchers
case <-ticker.C:
if hub.game.state == gameStateStarting {
if time.Now().After(*hub.game.startedAt) {
@@ -220,8 +204,8 @@ func (hub *gameHub) run() {
}
hub.game.state = gameStateFinished
hub.close()
+ return
}
- return
}
}
}
@@ -291,6 +275,7 @@ func NewGameHubs(q *db.Queries, taskQueue *taskqueue.Queue) *GameHubs {
}
func (hubs *GameHubs) Close() {
+ log.Println("closing all game hubs")
for _, hub := range hubs.hubs {
hub.close()
}
@@ -358,5 +343,5 @@ func (hubs *GameHubs) StartGame(gameID int) error {
}
func (hubs *GameHubs) C() chan string {
- return hubs.hubs[4].testcaseExecution
+ return hubs.hubs[7].testcaseExecution
}
diff --git a/backend/game/message.go b/backend/game/message.go
index d4007a3..1eedabd 100644
--- a/backend/game/message.go
+++ b/backend/game/message.go
@@ -10,7 +10,7 @@ import (
const (
playerMessageTypeS2CPrepare = "player:s2c:prepare"
playerMessageTypeS2CStart = "player:s2c:start"
- playerMessageTypeS2CExecResult = "player:s2c:execreslut"
+ playerMessageTypeS2CExecResult = "player:s2c:execresult"
playerMessageTypeC2SEntry = "player:c2s:entry"
playerMessageTypeC2SReady = "player:c2s:ready"
playerMessageTypeC2SCode = "player:c2s:code"
@@ -80,7 +80,7 @@ func asPlayerMessageC2S(raw map[string]json.RawMessage) (playerMessageC2S, error
const (
watcherMessageTypeS2CStart = "watcher:s2c:start"
- watcherMessageTypeS2CExecResult = "watcher:s2c:execreslut"
+ watcherMessageTypeS2CExecResult = "watcher:s2c:execresult"
watcherMessageTypeS2CCode = "watcher:s2c:code"
)
diff --git a/backend/query.sql b/backend/query.sql
index 6395b9b..ea04c08 100644
--- a/backend/query.sql
+++ b/backend/query.sql
@@ -4,7 +4,8 @@ WHERE users.user_id = $1
LIMIT 1;
-- name: ListUsers :many
-SELECT * FROM users;
+SELECT * FROM users
+ORDER BY users.user_id;
-- name: GetUserAuthByUsername :one
SELECT * FROM users
@@ -14,13 +15,15 @@ LIMIT 1;
-- name: ListGames :many
SELECT * FROM games
-LEFT JOIN problems ON games.problem_id = problems.problem_id;
+LEFT JOIN problems ON games.problem_id = problems.problem_id
+ORDER BY games.game_id;
-- name: ListGamesForPlayer :many
SELECT * FROM games
LEFT JOIN problems ON games.problem_id = problems.problem_id
JOIN game_players ON games.game_id = game_players.game_id
-WHERE game_players.user_id = $1;
+WHERE game_players.user_id = $1
+ORDER BY games.game_id;
-- name: UpdateGameState :exec
UPDATE games
@@ -41,7 +44,8 @@ LIMIT 1;
-- name: ListGamePlayers :many
SELECT * FROM game_players
LEFT JOIN users ON game_players.user_id = users.user_id
-WHERE game_players.game_id = $1;
+WHERE game_players.game_id = $1
+ORDER BY game_players.user_id;
-- name: UpdateGame :exec
UPDATE games
@@ -61,7 +65,8 @@ RETURNING submission_id;
-- name: ListTestcasesByGameID :many
SELECT * FROM testcases
-WHERE testcases.problem_id = (SELECT problem_id FROM games WHERE game_id = $1);
+WHERE testcases.problem_id = (SELECT problem_id FROM games WHERE game_id = $1)
+ORDER BY testcases.testcase_id;
-- name: CreateTestcaseExecution :exec
INSERT INTO testcase_executions (submission_id, testcase_id, status, stdout, stderr)
diff --git a/backend/taskqueue/processor.go b/backend/taskqueue/processor.go
index e505c5a..1d4c412 100644
--- a/backend/taskqueue/processor.go
+++ b/backend/taskqueue/processor.go
@@ -173,7 +173,7 @@ func (p *ExecProcessor) ProcessTask(ctx context.Context, t *asynq.Task) error {
p.c <- resData.Result
return fmt.Errorf("testrun failed: %v", resData.Stderr)
}
- if isTestcaseExecutionCorrect(testcase.Stdout, resData.Stdout) {
+ if !isTestcaseExecutionCorrect(testcase.Stdout, resData.Stdout) {
err := p.q.CreateTestcaseExecution(ctx, db.CreateTestcaseExecutionParams{
SubmissionID: submissionID,
TestcaseID: &testcase.TestcaseID,
@@ -189,6 +189,7 @@ func (p *ExecProcessor) ProcessTask(ctx context.Context, t *asynq.Task) error {
}
}
+ p.c <- "success"
return nil
}
diff --git a/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx b/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx
index 1a08b98..fdf0e0c 100644
--- a/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx
+++ b/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx
@@ -38,8 +38,7 @@ export default function GolfPlayAppGaming({
<div className="mb-4 mt-auto">
<div className="mb-2">
<div className="font-semibold text-green-500">
- Score: {currentScore == null ? "-" : `${currentScore}`} (
- {lastExecStatus})
+ Score: {currentScore ?? "-"} ({lastExecStatus ?? "-"})
</div>
</div>
<button
diff --git a/worker/main.go b/worker/main.go
index 8134a56..51c0eb1 100644
--- a/worker/main.go
+++ b/worker/main.go
@@ -4,7 +4,7 @@ import (
"log"
"net/http"
- echojwt "github.com/labstack/echo-jwt/v4"
+ // echojwt "github.com/labstack/echo-jwt/v4"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
@@ -19,9 +19,10 @@ func main() {
e.Use(middleware.Logger())
e.Use(middleware.Recover())
- e.Use(echojwt.WithConfig(echojwt.Config{
- SigningKey: []byte("TODO"),
- }))
+ // TODO: temporarily disabled
+ // e.Use(echojwt.WithConfig(echojwt.Config{
+ // SigningKey: []byte("TODO"),
+ // }))
e.POST("/api/swiftc", handleSwiftCompile)
e.POST("/api/wasmc", handleWasmCompile)