@@ -152,6 +152,7 @@ public async Task ReloadAsync(CancellationToken cancellationToken)
152152 Lock = new SemaphoreSlim ( 1 , 1 ) ,
153153 GroupId = userStateFile . GroupId ,
154154 GroupMembers = [ ] ,
155+ DockerUserId = userStateFile . DockerUserId ,
155156 UserName = userStateFile . UserName ,
156157 Password = userStateFile . Password ,
157158 Exercises = new ConcurrentDictionary < int , UserStateFileExerciseEntry > ( userStateFile . Exercises . ToDictionary ( e => e . ExerciseId ) ) ,
@@ -251,6 +252,7 @@ private async Task WriteUserStateFileAsync(int userId, CancellationToken cancell
251252 var userStateFile = new UserStateFile
252253 {
253254 GroupId = userState . GroupId ,
255+ DockerUserId = userState . DockerUserId ,
254256 UserName = userState . UserName ,
255257 Password = userState . Password ,
256258 Exercises = userState . Exercises . Values . ToList ( )
@@ -289,14 +291,20 @@ public async Task ProcessLoginAsync(int userId, int? groupId, string labUserName
289291 }
290292 else
291293 {
294+ // If the CTF system sends a lab user name and that matches 'userXX', use 'XX' as docker user ID
295+ int dockerUserId = userId ;
296+ if ( labUserName != null && labUserName . StartsWith ( "user" ) && int . TryParse ( labUserName [ 4 ..] , out int duid ) )
297+ dockerUserId = duid ;
298+
292299 // Create new account
293300 userState = new UserState
294301 {
295302 Lock = new SemaphoreSlim ( 1 , 1 ) ,
296303 GroupId = groupId ,
297304 GroupMembers = [ ] , // Will be filled later
298305 Exercises = new ConcurrentDictionary < int , UserStateFileExerciseEntry > ( ) ,
299- UserName = labUserName ?? ( _dockerSupportEnabled ? $ "user{ userId } " : null ) ,
306+ DockerUserId = dockerUserId ,
307+ UserName = labUserName ?? ( _dockerSupportEnabled ? $ "user{ dockerUserId } " : null ) ,
300308 Password = labPassword ?? ( _dockerSupportEnabled ? RandomStringGenerator . GetRandomString ( 10 ) : null ) ,
301309 Log = new UserStateLogContainer ( Math . Max ( 1 , _options . Value . UserStateLogSize ) )
302310 } ;
@@ -323,7 +331,7 @@ public async Task ProcessLoginAsync(int userId, int? groupId, string labUserName
323331 if ( _dockerSupportEnabled
324332 && ! string . IsNullOrWhiteSpace ( _options . Value . DockerContainerName )
325333 && ! string . IsNullOrWhiteSpace ( _options . Value . DockerContainerInitUserScriptPath ) )
326- await _dockerService . InitUserAsync ( userId , userState . UserName , userState . Password , CancellationToken . None ) ;
334+ await _dockerService . InitUserAsync ( userState . DockerUserId , userState . UserName , userState . Password , CancellationToken . None ) ;
327335
328336 // Store new user state
329337 _userStates . TryAdd ( userId , userState ) ;
@@ -438,7 +446,7 @@ public async Task<bool> CheckInputAsync(int exerciseId, int userId, object input
438446 var scriptExercise = exercise as LabConfigurationScriptExerciseEntry ;
439447 string containerName = scriptExercise . ContainerName ?? _options . Value . DockerContainerName ;
440448 string gradingScriptPath = scriptExercise . GradeScriptPath ?? _options . Value . DockerContainerGradeScriptPath ;
441- ( correct , string stderr ) = await _dockerService . GradeAsync ( containerName , gradingScriptPath , userId , exerciseId , input as string , cancellationToken ) ;
449+ ( correct , string stderr ) = await _dockerService . GradeAsync ( containerName , gradingScriptPath , userState . DockerUserId , exerciseId , input as string , cancellationToken ) ;
442450
443451 userState . Log . AddMessage ( "Script stderr output" , stderr ) ;
444452 }
0 commit comments