Skip to content

Commit d70283e

Browse files
bhoopesh369shubham-1806avyjitkillerninjacatAadit-Krishnaa-R
authored
fix: fixes (#7)
* fix: deafault locked pvp code * update: player code * fix: tutorial images * fix: pvp locked code * fix: pvp gameparams * check: logging for errors * add more logs * add even more logs * last logs check * fix: pvp logs too much error * fix: remove all printlns * Code Daily Chall (#8) * map dc 1 * fix: change map * feat: dc map 1 * feat: DC Map 2 * code dc 1 * wip: dc * fix: dc saved code --------- Co-authored-by: nithin balan <[email protected]> Co-authored-by: Nithin Balan <[email protected]> Co-authored-by: Aadit Krishnaa R <[email protected]> Co-authored-by: Bhoopesh <[email protected]> * update: send warning for same code in pvp-auto-match * fix: blind code dc * feat: dc day 5 --------- Co-authored-by: shubham-1806 <[email protected]> Co-authored-by: Avyyukt Ajith <[email protected]> Co-authored-by: nithin balan <[email protected]> Co-authored-by: Nithin Balan <[email protected]> Co-authored-by: Aadit Krishnaa R <[email protected]>
1 parent 80052cb commit d70283e

File tree

10 files changed

+66
-119
lines changed

10 files changed

+66
-119
lines changed

server/src/main/kotlin/delta/codecharacter/server/code/locked_code/LockedCodeService.kt

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ class LockedCodeService(
2121
codeType: CodeTypeDto
2222
): Pair<LanguageEnum, String> {
2323
val lockedCode = HashMap<CodeTypeDto, Code>()
24-
lockedCode[codeType] = defaultCodeMapConfiguration.defaultLockedCode
24+
if(codeType == CodeTypeDto.NORMAL) {
25+
lockedCode[codeType] = defaultCodeMapConfiguration.defaultLockedCode
26+
}
27+
else if(codeType == CodeTypeDto.PVP) {
28+
lockedCode[codeType] = defaultCodeMapConfiguration.defaultPvPLockedCode
29+
}
2530
return lockedCodeRepository
2631
.findById(userId)
2732
.orElse(
@@ -33,7 +38,7 @@ class LockedCodeService(
3338
.let { code ->
3439
Pair(
3540
code.lockedCode[codeType]?.language ?: defaultCodeMapConfiguration.defaultLanguage,
36-
code.lockedCode[codeType]?.code ?: defaultCodeMapConfiguration.defaultCode
41+
code.lockedCode[codeType]?.code ?: if (codeType == CodeTypeDto.NORMAL) defaultCodeMapConfiguration.defaultCode else defaultCodeMapConfiguration.defaultPvPCode,
3742
)
3843
}
3944
}

server/src/main/kotlin/delta/codecharacter/server/daily_challenge/DailyChallengeService.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package delta.codecharacter.server.daily_challenge
22

33
import delta.codecharacter.dtos.ChallengeTypeDto
44
import delta.codecharacter.dtos.DailyChallengeGetRequestDto
5+
import delta.codecharacter.dtos.DailyChallengeObjectDto
56
import delta.codecharacter.server.daily_challenge.match.DailyChallengeMatchVerdictEnum
67
import delta.codecharacter.server.exception.CustomException
78
import delta.codecharacter.server.game.GameEntity
@@ -43,9 +44,11 @@ class DailyChallengeService(
4344
fun getDailyChallengeByDateForUser(userId: UUID): DailyChallengeGetRequestDto {
4445
val user = publicUserService.getPublicUser(userId)
4546
val currentDailyChallenge = getDailyChallengeByDate()
47+
val blindCode = "This is a blind code challenge, you have to build a map to counter this attack. Godspeed, commander."
48+
val blindCodeDC = DailyChallengeObjectDto(blindCode,blindCode,blindCode,"can be anything")
4649
return DailyChallengeGetRequestDto(
4750
challName = currentDailyChallenge.challName,
48-
chall = currentDailyChallenge.chall,
51+
chall = if (currentDailyChallenge.challType == ChallengeTypeDto.CODE) blindCodeDC else currentDailyChallenge.chall,
4952
challType = currentDailyChallenge.challType,
5053
description = currentDailyChallenge.description,
5154
completionStatus = user.dailyChallengeHistory.containsKey(currentDailyChallenge.day)

server/src/main/kotlin/delta/codecharacter/server/match/MatchService.kt

+8-4
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ class MatchService(
129129

130130
private fun createPvPSelfMatch(userId: UUID, codeRevisionId1: UUID?, codeRevisionId2: UUID?) {
131131
if (codeRevisionId1==codeRevisionId2) {
132-
throw CustomException(HttpStatus.BAD_REQUEST, "Codes must be different")
132+
notificationService.sendNotification(
133+
userId,
134+
"PvP Self Match: Warning",
135+
"You are matching against same code"
136+
)
133137
}
134138
val (code1, language1) = getCodeFromRevision(userId, codeRevisionId1, CodeTypeDto.PVP)
135139
val (code2, language2) = getCodeFromRevision(userId, codeRevisionId2, CodeTypeDto.PVP)
@@ -267,8 +271,8 @@ class MatchService(
267271
when (challType) {
268272
ChallengeTypeDto.CODE -> { // code as question and map as answer
269273
mapValidator.validateMap(value)
270-
code = chall.cpp.toString()
271-
language = LanguageEnum.CPP
274+
code = dc.chall.python.toString()
275+
language = LanguageEnum.PYTHON
272276
map = value
273277
}
274278
ChallengeTypeDto.MAP -> {
@@ -857,7 +861,7 @@ class MatchService(
857861
}
858862
notificationService.sendNotification(
859863
match.player1.userId,
860-
"Auto Match Result",
864+
"PvP Auto Match Result",
861865
"${
862866
when (verdict) {
863867
MatchVerdictEnum.PLAYER1 -> "Won"

server/src/main/kotlin/delta/codecharacter/server/pvp_game/PvPGameService.kt

+12-3
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ class PvPGameService(
4141
}
4242

4343
fun sendPvPGameRequest(pvPGame: PvPGameEntity, player1Code: GameCode, player2Code: GameCode) {
44+
val pvPGameParameters = parameters.copy(
45+
numberOfCoins = 10,
46+
)
4447
val pvPGameRequest =
4548
PvPGameRequestEntity(
4649
gameId = pvPGame.matchId,
47-
parameters = parameters,
50+
parameters = pvPGameParameters,
4851
player1 = player1Code,
4952
player2 = player2Code
5053
)
@@ -79,9 +82,15 @@ class PvPGameService(
7982
scorePlayer2 = gameResultPlayer2.score,
8083
status = gameStatus
8184
)
82-
8385
val pvPGame = pvPGameRepository.save(newPvPGameEntity)
84-
pvPGameLogService.savePvPGameLog(pvPGame.matchId, gameResultPlayer1.log, gameResultPlayer2.log)
86+
try {
87+
pvPGameLogService.savePvPGameLog(pvPGame.matchId, gameResultPlayer1.log, gameResultPlayer2.log)
88+
}
89+
catch (e : Exception){
90+
println("log size too much")
91+
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"
92+
pvPGameLogService.savePvPGameLog(pvPGame.matchId,logSizeHighError,logSizeHighError)
93+
}
8594
return Triple(pvPGame, gameResultPlayer1.hasErrors, gameResultPlayer2.hasErrors)
8695
}
8796
}

server/src/main/resources/dcConstants.example.json

+18-100
Large diffs are not rendered by default.

server/src/main/resources/tutorialConstants.json

+6-3
Large diffs are not rendered by default.

server/src/test/kotlin/delta/codecharacter/server/SecurityTestConfiguration.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class TestAttributes {
5454
day = 0,
5555
challName = "challengeName",
5656
challType = ChallengeTypeDto.CODE,
57-
chall = DailyChallengeObjectDto(cpp = "example cpp code"),
57+
chall = DailyChallengeObjectDto(cpp = "example cpp code", python = "example python code"),
5858
perfectScore = 500,
5959
numberOfCompletions = 2,
6060
toleratedDestruction = 60,

server/src/test/kotlin/delta/codecharacter/server/match/MatchServiceTest.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import delta.codecharacter.server.code.latest_code.LatestCodeService
88
import delta.codecharacter.server.code.locked_code.LockedCodeService
99
import delta.codecharacter.server.code_tutorial.CodeTutorialService
1010
import delta.codecharacter.server.code_tutorial.match.CodeTutorialMatchRepository
11+
import delta.codecharacter.server.daily_challenge.DailyChallengeEntity
1112
import delta.codecharacter.server.daily_challenge.DailyChallengeService
1213
import delta.codecharacter.server.daily_challenge.match.DailyChallengeMatchRepository
1314
import delta.codecharacter.server.exception.CustomException
@@ -441,13 +442,13 @@ internal class MatchServiceTest {
441442
val matchRequest = DailyChallengeMatchRequestDto(value = "[[0,0,0]]")
442443
every { dailyChallengeService.getDailyChallengeByDateForUser(any()) } returns
443444
dailyChallengeForUser
445+
every { dailyChallengeService.getDailyChallengeByDate() } returns TestAttributes.dailyChallengeCode
444446
every { dailyChallengeMatchRepository.save(any()) } returns mockk()
445447
every { publicUserService.getPublicUser(any()) } returns TestAttributes.publicUser
446448
every { gameService.createGame(any()) } returns mockk()
447-
every { dailyChallengeService.getDailyChallengeByDate() } returns mockk()
448449
every {
449450
gameService.sendGameRequest(
450-
any(), dailyChallengeForUser.chall.cpp.toString(), LanguageEnum.CPP, matchRequest.value
451+
any(), dailyChallengeForUser.chall.python.toString(), LanguageEnum.PYTHON, matchRequest.value
451452
)
452453
} returns Unit
453454

@@ -457,7 +458,7 @@ internal class MatchServiceTest {
457458
dailyChallengeMatchRepository.save(any())
458459
gameService.createGame(any())
459460
gameService.sendGameRequest(
460-
any(), dailyChallengeForUser.chall.cpp.toString(), LanguageEnum.CPP, matchRequest.value
461+
any(), dailyChallengeForUser.chall.python.toString(), LanguageEnum.PYTHON, matchRequest.value
461462
)
462463
}
463464
confirmVerified(dailyChallengeMatchRepository, gameService)

server/src/test/kotlin/delta/codecharacter/server/pvp_game/PvPGameServiceTest.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,16 @@ internal class PvPGameServiceTest {
8080
val pvPGame = mockk<PvPGameEntity>()
8181
val matchId = UUID.randomUUID()
8282

83+
val pvPGameParameters = gameParameters.copy(
84+
numberOfCoins = 10,
85+
)
86+
8387
val expectedPvPGameRequest =
8488
PvPGameRequestEntity(
8589
gameId = matchId,
8690
player1 = GameCode("player1 code", LanguageEnum.CPP),
8791
player2 = GameCode("player2 code", LanguageEnum.JAVA),
88-
parameters = gameParameters,
92+
parameters = pvPGameParameters,
8993
)
9094

9195
every {pvPGame.matchId} returns matchId

0 commit comments

Comments
 (0)