diff options
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/api/generated.go | 58 | ||||
| -rw-r--r-- | backend/db/query.sql.go | 13 | ||||
| -rw-r--r-- | backend/game/hub.go | 11 | ||||
| -rw-r--r-- | backend/query.sql | 5 |
4 files changed, 56 insertions, 31 deletions
diff --git a/backend/api/generated.go b/backend/api/generated.go index ac536c0..dd85f04 100644 --- a/backend/api/generated.go +++ b/backend/api/generated.go @@ -213,8 +213,7 @@ type GameWatcherMessageS2CSubmit struct { // GameWatcherMessageS2CSubmitPayload defines model for GameWatcherMessageS2CSubmitPayload. type GameWatcherMessageS2CSubmitPayload struct { - PlayerID int `json:"player_id"` - PreliminaryScore int `json:"preliminary_score"` + PlayerID int `json:"player_id"` } // GameWatcherMessageS2CSubmitResult defines model for GameWatcherMessageS2CSubmitResult. @@ -226,6 +225,7 @@ type GameWatcherMessageS2CSubmitResult struct { // GameWatcherMessageS2CSubmitResultPayload defines model for GameWatcherMessageS2CSubmitResultPayload. type GameWatcherMessageS2CSubmitResultPayload struct { PlayerID int `json:"player_id"` + Score nullable.Nullable[int] `json:"score"` Status GameWatcherMessageS2CSubmitResultPayloadStatus `json:"status"` } @@ -1108,33 +1108,33 @@ func (sh *strictHandler) GetToken(ctx echo.Context, params GetTokenParams) error // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/9xaX2/bNhD/Kho3oBugxX8SFJ3f0qzNOnRdULfbQxEYtHS2mVGkSlJxvEDffSApW6JE", - "W3KidEX7UNgW7+53dz/eUbzco4gnKWfAlESTe5RigRNQIMy3FeAYxAxnasUF+Rcrwpn+nTA0KR6iEDGc", - "AJqgc2dViAR8zoiAGE2UyCBEMlpBgrW42qRaQCpB2BLleYhSrFazJU5gRuKdAf1jqX77tINiwhQsQaBc", - "qxYgU84kGIde4vg9fM5AKv0t4kwBMx9xmlISGeiDG2m9LPX+IGCBJuj7QRmsgX0qB6+E4IWpGGQkSGqj", - "pG0FojCWh+g1F3MSx8Ce3nJpKg/RO65e84zFT2/2HVfBwpjKQ/SRbVkDX8C0Y00/LiS0QiukuS14CkIR", - "S4UEpMRL0B/hDicp1cx5w24xJWXeQg9XS/p92im53i3k8xuITMIvDW/rZmMiU4o3M1Y8LW3r9cGoaTJE", - "cSZMtGYSIs5i6cidPh+GDeKHqLKZdktHexfan+8RsCzRfo1uNZAko4potCC0hyVU+7iB0y418IiCRLal", - "86O0EApFWAi8MXoEn1NI2sSvimU63QoLBfEMK8fhX86eP39x9mLojZBUWDlOR5RL0AVmjYnSLhV67ccl", - "TuyHBWFEriB2Q7ITbkTlFgRZFHyfSQVp9wD9VRGdKkibwarxsSySZVq3noYu9zy0KiNf5tKLfx/dr4zQ", - "H+XO4gz+XKDJp8NuNkSn4wuUh0cKXYynKL/2IdFPHg7mYjy94DE8CNA0mydE7YdlFDdrBFatpXCftiu8", - "oRzHJVNM6dX9rkjpJBrLSaTtthW3gj0GTaeM1yA0/IoKb8tdkwrC1I/PfgNKeRisuaDxd89+akVmFHWF", - "VOSgtyhbfd3iLK3tp4i0C+NriLXetY/a81NdbY/fZ9Pxxas7iN6DzOi+veau6YcLjs52PshxNIE7iITF", - "0DsnvHAansqIC5cYI90eWUYpnuuv9kztb5eZrPZLmUURSN0iFpjQTJiKQhLgmfZOiwqG6QzM+Ss0LxqE", - "wu77WnC2nGEm1/XjRan4cIgKSGHhVNcoWZr1xgGjrlv6zXHiSTLvgGgmXT894nDUjLMV34fmb6yi1QMb", - "vytrOv+1V+3R5aUh3r2+NEQ7nwCaRosjwENkq2Xt4bbrhdHv3IP3g1fdgf2wtuvNhujtHHIQRI/NcXsw", - "7vBqVfOilAsP99RDLOgvSZ06VzVVPbeuDoAaznYO/eFu5TSeassSGdNfdh2qpYV161kaSwxCuHzbs07j", - "cNY5hPQJKZAqwtL3rt/W0w8QtKo1rPRZi3DnUufkPrLl+vV1JG5/TfcwjP+565atpscwt73qOHHu712n", - "BchjCkMqgJKEMCw2sz1n4SP2SVPbkS71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XUkbn9Ndz+Mv7nrlq2mxzC3veo4ce7v", + "XacFyPGFYSflD0TSezmuqj0o3qcsyT5QzyrKp3j3+LbVfE/N7PA2cltebNZ4U73Nrtb/T0siAyIDHJRX", + "c80jiX3UKQeKKFo7+xSofHfPdXdLQxtN7k28z2lzy3vAPfjPfMmCHzn4PCURZ1MzF3JEBiTBC5CDe75k", + "Z/fpwisqpzhOiBvfOaayZNyMcwrYTE0y6eH06MIXUb206YWG0hrPjZWKksYt7Ra3L7aNC+JGnCmeAa1x", + "CqQKdHf3Txv6O1G4pwiLpOmFliJszs0Az7ITXdEZVoJLGWx2bbCCWXB1+85eSEs79hmenZ8NNWaeAsMp", + "QWN0cTY8GyI7UTQBGCxwYkOxAFOxdXRMwN7FaIxuQN2YBaEz+9zxelkuGXhno/ldbeA4Gg4Pmn65ydtC", + "7zQtMAOnLhMCuSML7kztPZEq4PPASuQhuhye74Kw9XngTuK00EW7UGVgqat9liRYrDcQCvt5WKRy8FRM", + "OfK2pPaU07BVzhlfn4AD3TLvyXSnRF+ZEH+zDGuJy3aJ7dzapcQNqAAXgDUlKF/Ymp5y6WHCLZfqvVli", + "gwNSvebx+hn5SLGUKy7i2v1B8ev56MJXUwUsiFTFuE3xP6DW5h9r/3w6ntln2GZDFPD9zHD/tiLvlcm7", + "/D6r/N9+kDVKutB6Ys9w84zSdaApC0xpqBvWHkx1h4f6VBNY8hkebp3bVZA+mQXfY5f5R+XF1ge55EL9", + "n5IHiANszAUWYJ7n+V8BAAD//+IyXiP0JAAA", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/backend/db/query.sql.go b/backend/db/query.sql.go index 583389e..34b0ae9 100644 --- a/backend/db/query.sql.go +++ b/backend/db/query.sql.go @@ -174,6 +174,19 @@ func (q *Queries) GetGameByID(ctx context.Context, gameID int32) (GetGameByIDRow return i, err } +const getSubmissionCodeSizeByID = `-- name: GetSubmissionCodeSizeByID :one +SELECT code_size FROM submissions +WHERE submission_id = $1 +LIMIT 1 +` + +func (q *Queries) GetSubmissionCodeSizeByID(ctx context.Context, submissionID int32) (int32, error) { + row := q.db.QueryRow(ctx, getSubmissionCodeSizeByID, submissionID) + var code_size int32 + err := row.Scan(&code_size) + return code_size, err +} + const getUserAuthByUsername = `-- name: GetUserAuthByUsername :one SELECT users.user_id, username, display_name, icon_path, is_admin, created_at, user_auth_id, user_auths.user_id, auth_type, password_hash FROM users JOIN user_auths ON users.user_id = user_auths.user_id diff --git a/backend/game/hub.go b/backend/game/hub.go index 97303ec..670b05f 100644 --- a/backend/game/hub.go +++ b/backend/game/hub.go @@ -101,8 +101,7 @@ func (hub *gameHub) run() { hub.broadcastToWatchers(&watcherMessageS2CSubmit{ Type: watcherMessageTypeS2CSubmit, Data: watcherMessageS2CSubmitPayload{ - PlayerID: message.client.playerID, - PreliminaryScore: codeSize, + PlayerID: message.client.playerID, }, }) default: @@ -338,11 +337,19 @@ func (hub *gameHub) processTaskResults() { }) } if aggregatedStatus != "running" { + var score nullable.Nullable[int] + if aggregatedStatus == "success" { + codeSize, err := hub.q.GetSubmissionCodeSizeByID(hub.ctx, int32(taskResult.TaskPayload.SubmissionID)) + if err == nil { + score = nullable.NewNullableWithValue(int(codeSize)) + } + } hub.broadcastToWatchers(&watcherMessageS2CSubmitResult{ Type: watcherMessageTypeS2CSubmitResult, Data: watcherMessageS2CSubmitResultPayload{ PlayerID: taskResult.TaskPayload.UserID(), Status: api.GameWatcherMessageS2CSubmitResultPayloadStatus(aggregatedStatus), + Score: score, }, }) } diff --git a/backend/query.sql b/backend/query.sql index 408bf2d..25eb4df 100644 --- a/backend/query.sql +++ b/backend/query.sql @@ -78,6 +78,11 @@ INSERT INTO submissions (game_id, user_id, code, code_size, code_hash) VALUES ($1, $2, $3, $4, $5) RETURNING submission_id; +-- name: GetSubmissionCodeSizeByID :one +SELECT code_size FROM submissions +WHERE submission_id = $1 +LIMIT 1; + -- name: ListTestcasesByGameID :many SELECT * FROM testcases WHERE testcases.problem_id = (SELECT problem_id FROM games WHERE game_id = $1) |
