using SPTarkov.DI.Annotations; using SPTarkov.Server.Core.Controllers; using SPTarkov.Server.Core.Helpers; using SPTarkov.Server.Core.Models.Eft.Common; using SPTarkov.Server.Core.Models.Eft.Launcher; using SPTarkov.Server.Core.Models.Eft.Profile; using SPTarkov.Server.Core.Models.Enums; using SPTarkov.Server.Core.Models.Spt.Launcher; using SPTarkov.Server.Core.Utils; namespace SPTarkov.Server.Core.Callbacks; [Injectable] public class ProfileCallbacks( HttpResponseUtil _httpResponse, TimeUtil _timeUtil, ProfileController _profileController, ProfileHelper _profileHelper ) { /// /// Handle client/game/profile/create /// /// public async ValueTask CreateProfile( string url, ProfileCreateRequestData info, string sessionID ) { var id = await _profileController.CreateProfile(info, sessionID); return _httpResponse.GetBody(new CreateProfileResponse { UserId = id }); } /// /// Handle client/game/profile/list /// Get the complete player profile (scav + pmc character) /// /// public ValueTask GetProfileData(string url, EmptyRequestData _, string sessionID) { return new ValueTask( _httpResponse.GetBody(_profileController.GetCompleteProfile(sessionID)) ); } /// /// Handle client/game/profile/savage/regenerate /// Handle the creation of a scav profile for player /// Occurs post-raid and when profile first created immediately after character details are confirmed by player /// /// public ValueTask RegenerateScav(string url, EmptyRequestData _, string sessionID) { return new ValueTask( _httpResponse.GetBody( new List { _profileController.GeneratePlayerScav(sessionID) } ) ); } /// /// Handle client/game/profile/voice/change event /// /// public ValueTask ChangeVoice( string url, ProfileChangeVoiceRequestData info, string sessionID ) { _profileController.ChangeVoice(info, sessionID); return new ValueTask(_httpResponse.NullResponse()); } /// /// Handle client/game/profile/nickname/change event /// Client allows player to adjust their profile name /// /// Client response as string public ValueTask ChangeNickname( string url, ProfileChangeNicknameRequestData info, string sessionId ) { var output = _profileController.ChangeNickname(info, sessionId); return output switch { NicknameValidationResult.Taken => new ValueTask( _httpResponse.GetBody( null, BackendErrorCodes.NicknameNotUnique, $"{BackendErrorCodes.NicknameNotUnique} - " ) ), NicknameValidationResult.Short => new ValueTask( _httpResponse.GetBody( null, BackendErrorCodes.NicknameNotValid, $"{BackendErrorCodes.NicknameNotValid} - " ) ), _ => new ValueTask( _httpResponse.GetBody( new { status = 0, NicknameChangeDate = _timeUtil.GetTimeStamp() } ) ), }; } /// /// Handle client/game/profile/nickname/validate /// /// Client response as string public ValueTask ValidateNickname( string url, ValidateNicknameRequestData info, string sessionId ) { return _profileController.ValidateNickname(info, sessionId) switch { NicknameValidationResult.Taken => new ValueTask( _httpResponse.GetBody( null, BackendErrorCodes.NicknameNotUnique, $"{BackendErrorCodes.NicknameNotUnique} - " ) ), NicknameValidationResult.Short => new ValueTask( _httpResponse.GetBody( null, BackendErrorCodes.NicknameNotValid, $"{BackendErrorCodes.NicknameNotValid} - " ) ), _ => new ValueTask(_httpResponse.GetBody(new { status = "ok" })), }; } /// /// Handle client/game/profile/nickname/reserved /// /// public ValueTask GetReservedNickname(string url, EmptyRequestData _, string sessionId) { var fullProfile = _profileHelper.GetFullProfile(sessionId); if (fullProfile?.ProfileInfo?.Username is not null) { // Send players name back to them return new ValueTask(_httpResponse.GetBody(fullProfile?.ProfileInfo?.Username)); } return new ValueTask(_httpResponse.GetBody("SPTarkov")); } /// /// Handle client/profile/status /// Called when creating a character when choosing a character face/voice /// /// public ValueTask GetProfileStatus(string url, EmptyRequestData _, string sessionId) { return new ValueTask( _httpResponse.GetBody(_profileController.GetProfileStatus(sessionId)) ); } /// /// Handle client/profile/view /// Called when viewing another players profile /// /// public ValueTask GetOtherProfile( string url, GetOtherProfileRequest request, string sessionID ) { return new ValueTask( _httpResponse.GetBody(_profileController.GetOtherProfile(sessionID, request)) ); } /// /// Handle client/profile/settings /// /// public ValueTask GetProfileSettings( string url, GetProfileSettingsRequest info, string sessionID ) { return new ValueTask( _httpResponse.GetBody(_profileController.SetChosenProfileIcon(sessionID, info)) ); } /// /// Handle client/game/profile/search /// /// public ValueTask SearchProfiles( string url, SearchProfilesRequestData info, string sessionID ) { return new ValueTask( _httpResponse.GetBody(_profileController.SearchProfiles(info, sessionID)) ); } /// /// Handle launcher/profile/info /// /// public ValueTask GetMiniProfile( string url, GetMiniProfileRequestData info, string sessionID ) { return new ValueTask( _httpResponse.NoBody(_profileController.GetMiniProfile(sessionID)) ); } /// /// Handle /launcher/profiles /// /// public ValueTask GetAllMiniProfiles(string url, EmptyRequestData _, string sessionID) { return new ValueTask(_httpResponse.NoBody(_profileController.GetMiniProfiles())); } }