Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixes #7

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ class LockedCodeService(
codeType: CodeTypeDto
): Pair<LanguageEnum, String> {
val lockedCode = HashMap<CodeTypeDto, Code>()
lockedCode[codeType] = defaultCodeMapConfiguration.defaultLockedCode
if(codeType == CodeTypeDto.NORMAL) {
lockedCode[codeType] = defaultCodeMapConfiguration.defaultLockedCode
}
else if(codeType == CodeTypeDto.PVP) {
lockedCode[codeType] = defaultCodeMapConfiguration.defaultPvPLockedCode
}
return lockedCodeRepository
.findById(userId)
.orElse(
Expand All @@ -33,7 +38,7 @@ class LockedCodeService(
.let { code ->
Pair(
code.lockedCode[codeType]?.language ?: defaultCodeMapConfiguration.defaultLanguage,
code.lockedCode[codeType]?.code ?: defaultCodeMapConfiguration.defaultCode
code.lockedCode[codeType]?.code ?: if (codeType == CodeTypeDto.NORMAL) defaultCodeMapConfiguration.defaultCode else defaultCodeMapConfiguration.defaultPvPCode,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package delta.codecharacter.server.daily_challenge

import delta.codecharacter.dtos.ChallengeTypeDto
import delta.codecharacter.dtos.DailyChallengeGetRequestDto
import delta.codecharacter.dtos.DailyChallengeObjectDto
import delta.codecharacter.server.daily_challenge.match.DailyChallengeMatchVerdictEnum
import delta.codecharacter.server.exception.CustomException
import delta.codecharacter.server.game.GameEntity
Expand Down Expand Up @@ -43,9 +44,11 @@ class DailyChallengeService(
fun getDailyChallengeByDateForUser(userId: UUID): DailyChallengeGetRequestDto {
val user = publicUserService.getPublicUser(userId)
val currentDailyChallenge = getDailyChallengeByDate()
val blindCode = "This is a blind code challenge, you have to build a map to counter this attack. Godspeed, commander."
val blindCodeDC = DailyChallengeObjectDto(blindCode,blindCode,blindCode,"can be anything")
return DailyChallengeGetRequestDto(
challName = currentDailyChallenge.challName,
chall = currentDailyChallenge.chall,
chall = if (currentDailyChallenge.challType == ChallengeTypeDto.CODE) blindCodeDC else currentDailyChallenge.chall,
challType = currentDailyChallenge.challType,
description = currentDailyChallenge.description,
completionStatus = user.dailyChallengeHistory.containsKey(currentDailyChallenge.day)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ class MatchService(

private fun createPvPSelfMatch(userId: UUID, codeRevisionId1: UUID?, codeRevisionId2: UUID?) {
if (codeRevisionId1==codeRevisionId2) {
throw CustomException(HttpStatus.BAD_REQUEST, "Codes must be different")
notificationService.sendNotification(
userId,
"PvP Self Match: Warning",
"You are matching against same code"
)
}
val (code1, language1) = getCodeFromRevision(userId, codeRevisionId1, CodeTypeDto.PVP)
val (code2, language2) = getCodeFromRevision(userId, codeRevisionId2, CodeTypeDto.PVP)
Expand Down Expand Up @@ -267,8 +271,8 @@ class MatchService(
when (challType) {
ChallengeTypeDto.CODE -> { // code as question and map as answer
mapValidator.validateMap(value)
code = chall.cpp.toString()
language = LanguageEnum.CPP
code = dc.chall.python.toString()
language = LanguageEnum.PYTHON
map = value
}
ChallengeTypeDto.MAP -> {
Expand Down Expand Up @@ -857,7 +861,7 @@ class MatchService(
}
notificationService.sendNotification(
match.player1.userId,
"Auto Match Result",
"PvP Auto Match Result",
"${
when (verdict) {
MatchVerdictEnum.PLAYER1 -> "Won"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ class PvPGameService(
}

fun sendPvPGameRequest(pvPGame: PvPGameEntity, player1Code: GameCode, player2Code: GameCode) {
val pvPGameParameters = parameters.copy(
numberOfCoins = 10,
)
val pvPGameRequest =
PvPGameRequestEntity(
gameId = pvPGame.matchId,
parameters = parameters,
parameters = pvPGameParameters,
player1 = player1Code,
player2 = player2Code
)
Expand Down Expand Up @@ -79,9 +82,15 @@ class PvPGameService(
scorePlayer2 = gameResultPlayer2.score,
status = gameStatus
)

val pvPGame = pvPGameRepository.save(newPvPGameEntity)
pvPGameLogService.savePvPGameLog(pvPGame.matchId, gameResultPlayer1.log, gameResultPlayer2.log)
try {
pvPGameLogService.savePvPGameLog(pvPGame.matchId, gameResultPlayer1.log, gameResultPlayer2.log)
}
catch (e : Exception){
println("log size too much")
val logSizeHighError = "ERRORS, ERROR TYPE: LOGS TOO BIG\nERRORS, ERROR LOG:\n THE GAME RAN PERFECTLY BUT THE LOGS ARE TOO BIG TO RENDER\n"
pvPGameLogService.savePvPGameLog(pvPGame.matchId,logSizeHighError,logSizeHighError)
}
return Triple(pvPGame, gameResultPlayer1.hasErrors, gameResultPlayer2.hasErrors)
}
}
118 changes: 18 additions & 100 deletions server/src/main/resources/dcConstants.example.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions server/src/main/resources/tutorialConstants.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TestAttributes {
day = 0,
challName = "challengeName",
challType = ChallengeTypeDto.CODE,
chall = DailyChallengeObjectDto(cpp = "example cpp code"),
chall = DailyChallengeObjectDto(cpp = "example cpp code", python = "example python code"),
perfectScore = 500,
numberOfCompletions = 2,
toleratedDestruction = 60,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import delta.codecharacter.server.code.latest_code.LatestCodeService
import delta.codecharacter.server.code.locked_code.LockedCodeService
import delta.codecharacter.server.code_tutorial.CodeTutorialService
import delta.codecharacter.server.code_tutorial.match.CodeTutorialMatchRepository
import delta.codecharacter.server.daily_challenge.DailyChallengeEntity
import delta.codecharacter.server.daily_challenge.DailyChallengeService
import delta.codecharacter.server.daily_challenge.match.DailyChallengeMatchRepository
import delta.codecharacter.server.exception.CustomException
Expand Down Expand Up @@ -441,13 +442,13 @@ internal class MatchServiceTest {
val matchRequest = DailyChallengeMatchRequestDto(value = "[[0,0,0]]")
every { dailyChallengeService.getDailyChallengeByDateForUser(any()) } returns
dailyChallengeForUser
every { dailyChallengeService.getDailyChallengeByDate() } returns TestAttributes.dailyChallengeCode
every { dailyChallengeMatchRepository.save(any()) } returns mockk()
every { publicUserService.getPublicUser(any()) } returns TestAttributes.publicUser
every { gameService.createGame(any()) } returns mockk()
every { dailyChallengeService.getDailyChallengeByDate() } returns mockk()
every {
gameService.sendGameRequest(
any(), dailyChallengeForUser.chall.cpp.toString(), LanguageEnum.CPP, matchRequest.value
any(), dailyChallengeForUser.chall.python.toString(), LanguageEnum.PYTHON, matchRequest.value
)
} returns Unit

Expand All @@ -457,7 +458,7 @@ internal class MatchServiceTest {
dailyChallengeMatchRepository.save(any())
gameService.createGame(any())
gameService.sendGameRequest(
any(), dailyChallengeForUser.chall.cpp.toString(), LanguageEnum.CPP, matchRequest.value
any(), dailyChallengeForUser.chall.python.toString(), LanguageEnum.PYTHON, matchRequest.value
)
}
confirmVerified(dailyChallengeMatchRepository, gameService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ internal class PvPGameServiceTest {
val pvPGame = mockk<PvPGameEntity>()
val matchId = UUID.randomUUID()

val pvPGameParameters = gameParameters.copy(
numberOfCoins = 10,
)

val expectedPvPGameRequest =
PvPGameRequestEntity(
gameId = matchId,
player1 = GameCode("player1 code", LanguageEnum.CPP),
player2 = GameCode("player2 code", LanguageEnum.JAVA),
parameters = gameParameters,
parameters = pvPGameParameters,
)

every {pvPGame.matchId} returns matchId
Expand Down
Loading