aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/game/hub.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-08 21:17:13 +0900
committernsfisis <nsfisis@gmail.com>2024-08-08 21:17:13 +0900
commita100dc8ba76aaeda2229940c1743c33cc0ef84b5 (patch)
treee2e48d8d92e2601d65e3ce7d794d8727026c14e0 /backend/game/hub.go
parentbb62b6ff19d9f8008458d1c0ad0b8b76090f091e (diff)
parent3b13a61123becc63823ab0c0941aaff2048b020e (diff)
downloadiosdc-japan-2024-albatross-a100dc8ba76aaeda2229940c1743c33cc0ef84b5.tar.gz
iosdc-japan-2024-albatross-a100dc8ba76aaeda2229940c1743c33cc0ef84b5.tar.zst
iosdc-japan-2024-albatross-a100dc8ba76aaeda2229940c1743c33cc0ef84b5.zip
Merge branch 'feat/code-hash'
Diffstat (limited to 'backend/game/hub.go')
-rw-r--r--backend/game/hub.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/backend/game/hub.go b/backend/game/hub.go
index ac71152..aa1b9f2 100644
--- a/backend/game/hub.go
+++ b/backend/game/hub.go
@@ -2,7 +2,9 @@ package game
import (
"context"
+ "crypto/md5"
"errors"
+ "fmt"
"log"
"strings"
"time"
@@ -163,11 +165,13 @@ func (hub *gameHub) run() {
log.Printf("submit: %v", message.message)
code := msg.Data.Code
codeSize := len(code) // TODO: exclude whitespaces.
+ codeHash := calcHash(code)
if err := hub.taskQueue.EnqueueTaskCreateSubmissionRecord(
hub.game.gameID,
message.client.playerID,
code,
codeSize,
+ taskqueue.MD5HexHash(codeHash),
); err != nil {
// TODO: notify failure to player
log.Fatalf("failed to enqueue task: %v", err)
@@ -329,7 +333,8 @@ func (hub *gameHub) processTaskResultCreateSubmissionRecord(
if err := hub.taskQueue.EnqueueTaskCompileSwiftToWasm(
taskResult.TaskPayload.GameID(),
taskResult.TaskPayload.UserID(),
- taskResult.TaskPayload.Code(),
+ taskResult.TaskPayload.Code,
+ taskResult.TaskPayload.CodeHash(),
taskResult.SubmissionID,
); err != nil {
return &codeSubmissionError{
@@ -371,7 +376,7 @@ func (hub *gameHub) processTaskResultCompileSwiftToWasm(
if err := hub.taskQueue.EnqueueTaskCompileWasmToNativeExecutable(
taskResult.TaskPayload.GameID(),
taskResult.TaskPayload.UserID(),
- taskResult.TaskPayload.Code(),
+ taskResult.TaskPayload.CodeHash(),
taskResult.TaskPayload.SubmissionID,
); err != nil {
return &codeSubmissionError{
@@ -429,7 +434,7 @@ func (hub *gameHub) processTaskResultCompileWasmToNativeExecutable(
if err := hub.taskQueue.EnqueueTaskRunTestcase(
taskResult.TaskPayload.GameID(),
taskResult.TaskPayload.UserID(),
- taskResult.TaskPayload.Code(),
+ taskResult.TaskPayload.CodeHash(),
taskResult.TaskPayload.SubmissionID,
int(testcase.TestcaseID),
testcase.Stdin,
@@ -644,3 +649,7 @@ func isTestcaseResultCorrect(expectedStdout, actualStdout string) bool {
actualStdout = strings.TrimSpace(actualStdout)
return actualStdout == expectedStdout
}
+
+func calcHash(code string) string {
+ return fmt.Sprintf("%x", md5.Sum([]byte(code)))
+}