@@ -2,11 +2,10 @@ untyped
22// Only way to get Hud_GetPos(sliderButton) working was to use untyped
33
44global function AddNorthstarServerBrowserMenu
5- global function ThreadedAuthAndConnectToServer
5+ global function OnServerSelected_Threaded
66
77global function AddConnectToServerCallback
88global function RemoveConnectToServerCallback
9- global function TriggerConnectToServerCallbacks
109
1110// Stop peeking
1211
@@ -952,17 +951,68 @@ string function FillInServerModsLabel( array<RequiredModInfo> mods )
952951
953952void function OnServerSelected ( var button )
954953{
955- thread OnServerSelected_Threaded ( button )
954+ thread OnServerSelected_Threaded ()
956955}
957956
958- void function OnServerSelected_Threaded ( var button )
957+ void function OnServerSelected_Threaded ( string password = " " )
959958{
960959 if ( NSIsRequestingServerList () || NSGetServerCount () == 0 || file. serverListRequestFailed )
961960 return
962961
963962 ServerInfo server = file. focusedServer
964963 file. lastSelectedServer = server
965964
965+ // Ensure user is authenticated to server before eventually downloading mods
966+ if ( server. requiresPassword )
967+ {
968+ if ( password == " " )
969+ {
970+ OnCloseServerBrowserMenu ()
971+ AdvanceMenu ( GetMenu ( " ConnectWithPasswordMenu" ) )
972+ return
973+ }
974+ }
975+
976+ if ( NSIsAuthenticatingWithServer () )
977+ return
978+ NSTryAuthWithServer ( file. lastSelectedServer . index , password )
979+ ToggleConnectingHUD ( true )
980+
981+ while ( NSIsAuthenticatingWithServer () && ! file. cancelConnection )
982+ {
983+ WaitFrame ()
984+ }
985+
986+ ToggleConnectingHUD ( false )
987+
988+ if ( file. cancelConnection )
989+ {
990+ file. cancelConnection = false
991+ // re-focus server list
992+ Hud_SetFocused ( Hud_GetChild ( file. menu , " BtnServer" + ( file. serverButtonFocusedID + 1 ) ) )
993+ return
994+ }
995+
996+ if ( ! NSWasAuthSuccessful () )
997+ {
998+ string reason = NSGetAuthFailReason ()
999+
1000+ DialogData dialogData
1001+ dialogData. header = " #ERROR"
1002+ dialogData. message = reason
1003+ dialogData. image = $" ui/menu/common/dialog_error"
1004+
1005+ # if PC_PROG
1006+ AddDialogButton ( dialogData, " #DISMISS" )
1007+
1008+ AddDialogFooter ( dialogData, " #A_BUTTON_SELECT" )
1009+ # endif // PC_PROG
1010+ AddDialogFooter ( dialogData, " #B_BUTTON_DISMISS_RUI" )
1011+
1012+ OpenDialog ( dialogData )
1013+ return
1014+ }
1015+
9661016 // Count mods that have been successfully downloaded
9671017 bool autoDownloadAllowed = GetConVarBool ( " allow_mod_auto_download" )
9681018 int downloadedMods = 0 ;
@@ -1067,134 +1117,81 @@ void function OnServerSelected_Threaded( var button )
10671117 // If we get here, means that mod version exists locally => we good
10681118 }
10691119
1070- if ( server. requiresPassword )
1071- {
1072- OnCloseServerBrowserMenu ()
1073- AdvanceMenu ( GetMenu ( " ConnectWithPasswordMenu" ) )
1074- }
1075- else
1076- {
1077- TriggerConnectToServerCallbacks ()
1078- thread ThreadedAuthAndConnectToServer ( " " , downloadedMods != 0 )
1079- }
1120+ TriggerConnectToServerCallbacks ()
1121+ ConnectToServer ( downloadedMods != 0 )
10801122}
10811123
10821124
1083- void function ThreadedAuthAndConnectToServer ( string password = " " , bool modsChanged = false )
1125+ void function ConnectToServer ( bool modsChanged = false )
10841126{
1085- if ( NSIsAuthenticatingWithServer () )
1086- return
1087-
1088- NSTryAuthWithServer ( file. lastSelectedServer . index , password )
1089-
1090- ToggleConnectingHUD ( true )
1091-
1092- while ( NSIsAuthenticatingWithServer () && ! file. cancelConnection )
1127+ // disable all RequiredOnClient mods that are not required by the server and are currently enabled
1128+ foreach ( ModInfo mod in NSGetModsInformation () )
10931129 {
1094- WaitFrame ()
1095- }
1096-
1097- ToggleConnectingHUD ( false )
1130+ string modName = mod. name
1131+ string modVersion = mod. version
10981132
1099- if ( file. cancelConnection )
1100- {
1101- file. cancelConnection = false
1102- // re-focus server list
1103- Hud_SetFocused ( Hud_GetChild ( file. menu , " BtnServer" + ( file. serverButtonFocusedID + 1 ) ) )
1104- return
1105- }
1106-
1107- file. cancelConnection = false
1108-
1109- if ( NSWasAuthSuccessful () )
1110- {
1111- // disable all RequiredOnClient mods that are not required by the server and are currently enabled
1112- foreach ( ModInfo mod in NSGetModsInformation () )
1133+ if ( mod. requiredOnClient && mod. enabled )
11131134 {
1114- string modName = mod. name
1115- string modVersion = mod. version
1116-
1117- if ( mod. requiredOnClient && mod. enabled )
1135+ // find the mod name in the list of server required mods
1136+ bool found = false
1137+ foreach ( RequiredModInfo mod in file. lastSelectedServer . requiredMods )
11181138 {
1119- // find the mod name in the list of server required mods
1120- bool found = false
1121- foreach ( RequiredModInfo mod in file. lastSelectedServer . requiredMods )
1139+ // this tolerates a version difference for requiredOnClient core mods (only Northstar.Custom for now)
1140+ if (mod. name == modName && ( IsCoreMod ( modName ) || mod. version == modVersion ))
11221141 {
1123- // this tolerates a version difference for requiredOnClient core mods (only Northstar.Custom for now)
1124- if (mod. name == modName && ( IsCoreMod ( modName ) || mod. version == modVersion ))
1125- {
1126- found = true
1127- print (format (" \" %s\" (v%s) is required and already enabled." , modName, modVersion))
1128- break
1129- }
1130- }
1131- // if we didn't find the mod name, disable the mod
1132- if (! found)
1133- {
1134- modsChanged = true
1135- NSSetModEnabled ( modName, modVersion, false )
1136- print (format (" Disabled \" %s\" (v%s) since it's not required on server." , modName, modVersion))
1142+ found = true
1143+ print (format (" \" %s\" (v%s) is required and already enabled." , modName, modVersion))
1144+ break
11371145 }
11381146 }
1147+ // if we didn't find the mod name, disable the mod
1148+ if (! found)
1149+ {
1150+ modsChanged = true
1151+ NSSetModEnabled ( modName, modVersion, false )
1152+ print (format (" Disabled \" %s\" (v%s) since it's not required on server." , modName, modVersion))
1153+ }
11391154 }
1155+ }
11401156
1141- // enable all RequiredOnClient mods that are required by the server and are currently disabled
1142- foreach ( RequiredModInfo mod in file. lastSelectedServer . requiredMods )
1143- {
1144- string modName = mod. name
1145- string modVersion = mod. version
1146- array< ModInfo> localModInfos = NSGetModInformation ( modName )
1157+ // enable all RequiredOnClient mods that are required by the server and are currently disabled
1158+ foreach ( RequiredModInfo mod in file. lastSelectedServer . requiredMods )
1159+ {
1160+ string modName = mod. name
1161+ string modVersion = mod. version
1162+ array< ModInfo> localModInfos = NSGetModInformation ( modName )
11471163
1148- // Tolerate core mods (only Northstar.Custom for now) having a different version than server
1149- if ( IsCoreMod (modName) )
1164+ // Tolerate core mods (only Northstar.Custom for now) having a different version than server
1165+ if ( IsCoreMod (modName) )
1166+ {
1167+ if ( ! localModInfos[0 ]. enabled )
11501168 {
1151- if ( ! localModInfos[0 ]. enabled )
1152- {
1153- modsChanged = true
1154- NSSetModEnabled ( modName, localModInfos[0 ]. version , true )
1155- print (format (" Enabled \" %s\" (v%s) to join server." , modName, localModInfos[0 ]. version ))
1156- }
1169+ modsChanged = true
1170+ NSSetModEnabled ( modName, localModInfos[0 ]. version , true )
1171+ print (format (" Enabled \" %s\" (v%s) to join server." , modName, localModInfos[0 ]. version ))
11571172 }
1173+ }
11581174
1159- else
1175+ else
1176+ {
1177+ foreach ( localMod in localModInfos )
11601178 {
1161- foreach ( localMod in localModInfos )
1179+ if ( localMod. version == mod . version )
11621180 {
1163- if ( localMod. version == mod. version && ! localMod. enabled )
1164- {
1165- modsChanged = true
1166- NSSetModEnabled ( mod. name , mod. version , true )
1167- print (format (" Enabled \" %s\" (v%s) to join server." , modName, modVersion))
1168- break
1169- }
1181+ modsChanged = true
1182+ NSSetModEnabled ( mod. name , mod. version , true )
1183+ print (format (" Enabled \" %s\" (v%s) to join server." , modName, modVersion))
1184+ break
11701185 }
11711186 }
11721187 }
1173-
1174- // only actually reload if we need to since the uiscript reset on reload lags hard
1175- if ( modsChanged )
1176- ReloadMods ()
1177-
1178- NSConnectToAuthedServer ()
11791188 }
1180- else
1181- {
1182- string reason = NSGetAuthFailReason ()
1183-
1184- DialogData dialogData
1185- dialogData. header = " #ERROR"
1186- dialogData. message = reason
1187- dialogData. image = $" ui/menu/common/dialog_error"
1188-
1189- # if PC_PROG
1190- AddDialogButton ( dialogData, " #DISMISS" )
11911189
1192- AddDialogFooter ( dialogData, " #A_BUTTON_SELECT " )
1193- # endif // PC_PROG
1194- AddDialogFooter ( dialogData, " #B_BUTTON_DISMISS_RUI " )
1190+ // only actually reload if we need to since the uiscript reset on reload lags hard
1191+ if ( modsChanged )
1192+ ReloadMods ( )
11951193
1196- OpenDialog ( dialogData )
1197- }
1194+ NSConnectToAuthedServer ()
11981195}
11991196
12001197// ////////////////////////////////////
0 commit comments