Skip to content

Commit

Permalink
Automatically set run time to minimumInGameTimeToAllowBreaks and stor…
Browse files Browse the repository at this point in the history
…e the save file time
  • Loading branch information
timoschwarzer committed Dec 16, 2024
1 parent 73f6881 commit b78a022
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/kotlin/wotw/io/messages/protobuf/Messages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,5 @@ data class LeagueGameSubmissionRankingData(
@ProtoNumber(3) @Required val rank: Int? = null,
@ProtoNumber(5) @Required val videoUrl: String? = null,
@ProtoNumber(6) val rankingMultiplier: Float,
@ProtoNumber(7) @Required val saveFileTime: Float? = null,
)
6 changes: 5 additions & 1 deletion src/main/kotlin/wotw/server/api/LeagueEndpoint.kt
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,13 @@ class LeagueEndpoint(server: WotwBackendServer) : Endpoint(server) {
saveFileBuffer.get(saveFileArray)

val autoValidationErrors = mutableListOf<String>()
var timeOverride: Float? = null

if (
saveData.inGameTime < minimumInGameTimeToAllowBreaks &&
playerDisconnectedTime > LEAGUE_MAX_DISCONNECTED_TIME
) {
timeOverride = minimumInGameTimeToAllowBreaks
autoValidationErrors += """
Taking breaks during the run is only allowed after ${floor(minimumInGameTimeToAllowBreaks / 60f)} minutes of in-game time.
You were disconnected for $playerDisconnectedTime seconds.
Expand All @@ -260,7 +262,9 @@ class LeagueEndpoint(server: WotwBackendServer) : Endpoint(server) {

newSuspendedTransaction {
handler.createSubmission(authenticatedUser()) {
it.time = saveData.inGameTime
it.time = timeOverride ?: saveData.inGameTime
it.saveFileTime = saveData.inGameTime

it.saveFile = saveFileArray

if (autoValidationErrors.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ object LeagueGameSubmissions : LongIdTable("league_game_submissions") {
val submittedAt = timestamp("submitted_at").defaultExpression(CurrentTimestamp)
val saveFile = binary("save_file", 512 * 1024).nullable()
val time = float("time").nullable()
val save_file_time = float("save_file_time").nullable()
val points = integer("points").default(0)
val rank = integer("rank").nullable()
val videoUrl = varchar("video_url", 128).nullable()
Expand All @@ -35,6 +36,7 @@ class LeagueGameSubmission(id: EntityID<Long>) : LongEntity(id) {
var submittedAt by LeagueGameSubmissions.submittedAt
var saveFile by LeagueGameSubmissions.saveFile
var time by LeagueGameSubmissions.time
var saveFileTime by LeagueGameSubmissions.save_file_time
var points by LeagueGameSubmissions.points
var rank by LeagueGameSubmissions.rank
var videoUrl by LeagueGameSubmissions.videoUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class InfoMessagesService(private val server: WotwBackendServer) {
submission.rank,
submission.videoUrl,
submission.rankingMultiplier,
submission.saveFileTime,
)
)

Expand Down

0 comments on commit b78a022

Please sign in to comment.