Skip to content

Commit

Permalink
fix hdu subimit failed
Browse files Browse the repository at this point in the history
  • Loading branch information
HimitZH committed Jul 20, 2022
1 parent 4d84ba5 commit 13a3782
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package top.hcode.hoj.remoteJudge.task.Impl;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ReUtil;
import cn.hutool.http.*;
Expand All @@ -11,6 +12,7 @@
import top.hcode.hoj.util.Constants;

import java.net.HttpCookie;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -55,13 +57,26 @@ public void submit() {
.put("check", "0")
.put("language", getLanguage(remoteJudgeDTO.getLanguage()))
.put("problemid", remoteJudgeDTO.getCompleteProblemId())
.put("usercode", remoteJudgeDTO.getUserCode() + getRandomBlankString())
.put("_usercode", Base64.encode(URLEncoder.encode(remoteJudgeDTO.getUserCode() + getRandomBlankString())))
.map())
.cookie(cookies);

HttpResponse response = request.execute();
remoteJudgeDTO.setSubmitStatus(response.getStatus());
if (response.getStatus() != 302) {
// 提交频率限制了 等待5秒再次提交
if (response.getStatus() == 200 && response.body() != null && response.body().contains("Please don't re-submit")) {
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
response = request.execute();
remoteJudgeDTO.setSubmitStatus(response.getStatus());
if (response.getStatus() != 302) {
String log = String.format("[HDU] [%s]: Failed to submit code, the http response status is [%s].", remoteJudgeDTO.getCompleteProblemId(), response.getStatus());
throw new RuntimeException(log);
}
} else if (response.getStatus() != 302) {
String log = String.format("[HDU] [%s]: Failed to submit code, the http response status is [%s].", remoteJudgeDTO.getCompleteProblemId(), response.getStatus());
throw new RuntimeException(log);
}
Expand Down
2 changes: 1 addition & 1 deletion hoj-springboot/JudgeServer/src/main/resources/banner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ ${AnsiColor.BRIGHT_YELLOW}
'---' `---` '---' `----'
Hcode Online Judge(HOJ) - JudgeServer
@Author Himit_ZH
@Last Update 20220627
@Last Update 20220720
->Github<- https://www.github.com/HimitZH/HOJ
->Gitee<- https://gitee.com/himitzh0730/hoj

0 comments on commit 13a3782

Please sign in to comment.