Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a generic "JoinServer" function #693

Merged
merged 18 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
global function AddNorthstarConnectWithPasswordMenu
global function SetPasswordTargetServer

struct
{
var menu
var enterPasswordBox
var enterPasswordDummy
var connectButton
ServerInfo& targetServer
} file

void function AddNorthstarConnectWithPasswordMenu()
Expand Down Expand Up @@ -51,11 +53,16 @@ void function OnConnectWithPasswordMenuOpened()

}

void function SetPasswordTargetServer( ServerInfo server )
{
file.targetServer = server
}

void function ConnectWithPassword( var button )
{
if ( GetTopNonDialogMenu() == file.menu )
{
TriggerConnectToServerCallbacks()
thread ThreadedAuthAndConnectToServer( Hud_GetUTF8Text( Hud_GetChild( file.menu, "EnterPasswordBox" ) ) )
thread JoinServer( file.targetServer, Hud_GetUTF8Text( Hud_GetChild( file.menu, "EnterPasswordBox" ) ) )
}
}
215 changes: 118 additions & 97 deletions Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ untyped
// Only way to get Hud_GetPos(sliderButton) working was to use untyped

global function AddNorthstarServerBrowserMenu
global function ThreadedAuthAndConnectToServer

global function JoinServer
global function CancelJoinServer

global function AddConnectToServerCallback
global function RemoveConnectToServerCallback
Expand Down Expand Up @@ -370,7 +372,7 @@ void function ToggleConnectingHUD( bool vis )

void function ConnectingButton_Activate( var button )
{
file.cancelConnection = true
CancelJoinServer()
}

////////////////////////////
Expand Down Expand Up @@ -1021,103 +1023,12 @@ void function OnServerSelected( var button )
if ( server.requiresPassword )
{
OnCloseServerBrowserMenu()
SetPasswordTargetServer( file.lastSelectedServer )
AdvanceMenu( GetMenu( "ConnectWithPasswordMenu" ) )
}
else
{
TriggerConnectToServerCallbacks()
thread ThreadedAuthAndConnectToServer()
}
}


void function ThreadedAuthAndConnectToServer( string password = "" )
{
if ( NSIsAuthenticatingWithServer() )
return

NSTryAuthWithServer( file.lastSelectedServer.index, password )

ToggleConnectingHUD( true )

while ( NSIsAuthenticatingWithServer() && !file.cancelConnection )
{
WaitFrame()
}

ToggleConnectingHUD( false )

if ( file.cancelConnection )
{
file.cancelConnection = false
// re-focus server list
Hud_SetFocused( Hud_GetChild( file.menu, "BtnServer" + ( file.serverButtonFocusedID + 1 ) ) )
return
}

file.cancelConnection = false

if ( NSWasAuthSuccessful() )
{
bool modsChanged = false

// disable all RequiredOnClient mods that are not required by the server and are currently enabled
foreach ( string modName in NSGetModNames() )
{
if ( NSIsModRequiredOnClient( modName ) && NSIsModEnabled( modName ) )
{
// find the mod name in the list of server required mods
bool found = false
foreach ( RequiredModInfo mod in file.lastSelectedServer.requiredMods )
{
if (mod.name == modName)
{
found = true
break
}
}
// if we didnt find the mod name, disable the mod
if (!found)
{
modsChanged = true
NSSetModEnabled( modName, false )
}
}
}

// enable all RequiredOnClient mods that are required by the server and are currently disabled
foreach ( RequiredModInfo mod in file.lastSelectedServer.requiredMods )
{
if ( NSIsModRequiredOnClient( mod.name ) && !NSIsModEnabled( mod.name ))
{
modsChanged = true
NSSetModEnabled( mod.name, true )
}
}

// only actually reload if we need to since the uiscript reset on reload lags hard
if ( modsChanged )
ReloadMods()

NSConnectToAuthedServer()
}
else
{
string reason = NSGetAuthFailReason()

DialogData dialogData
dialogData.header = "#ERROR"
dialogData.message = reason
dialogData.image = $"ui/menu/common/dialog_error"

#if PC_PROG
AddDialogButton( dialogData, "#DISMISS" )

AddDialogFooter( dialogData, "#A_BUTTON_SELECT" )
#endif // PC_PROG
AddDialogFooter( dialogData, "#B_BUTTON_DISMISS_RUI" )

OpenDialog( dialogData )
thread JoinServer( file.lastSelectedServer )
}
}

Expand Down Expand Up @@ -1274,10 +1185,120 @@ void function RemoveConnectToServerCallback( void functionref( ServerInfo ) call
file.connectCallbacks.fastremovebyvalue( callback )
}

void function TriggerConnectToServerCallbacks()
void function TriggerConnectToServerCallbacks( ServerInfo ornull targetServer = null )
{
ServerInfo server
Klemmbaustein marked this conversation as resolved.
Show resolved Hide resolved
if (targetServer == null)
{
targetServer = file.lastSelectedServer
}
Klemmbaustein marked this conversation as resolved.
Show resolved Hide resolved

Klemmbaustein marked this conversation as resolved.
Show resolved Hide resolved
foreach( callback in file.connectCallbacks )
{
callback( file.lastSelectedServer )
callback( expect ServerInfo( targetServer ) )
Klemmbaustein marked this conversation as resolved.
Show resolved Hide resolved
}
}

void function CancelJoinServer()
{
file.cancelConnection = true
}

bool function JoinServer( ServerInfo server, string password = "" )
{
if ( NSIsAuthenticatingWithServer() )
return false

print("Connecting to server " + server.name + " with id of " + server.id)
Klemmbaustein marked this conversation as resolved.
Show resolved Hide resolved
if ( password != "" )
{
print ( "password is: " + password )
}
Klemmbaustein marked this conversation as resolved.
Show resolved Hide resolved
TriggerConnectToServerCallbacks( server )
Klemmbaustein marked this conversation as resolved.
Show resolved Hide resolved
NSTryAuthWithServer( server.index, password )

ToggleConnectingHUD( true )

while ( NSIsAuthenticatingWithServer() && !file.cancelConnection )
{
WaitFrame()
}
Klemmbaustein marked this conversation as resolved.
Show resolved Hide resolved

ToggleConnectingHUD( false )

if ( file.cancelConnection )
{
file.cancelConnection = false
// re-focus server list
// Hud_SetFocused( Hud_GetChild( file.menu, "BtnServer" + ( file.serverButtonFocusedID + 1 ) ) )
Klemmbaustein marked this conversation as resolved.
Show resolved Hide resolved
return false
}

file.cancelConnection = false

if ( NSWasAuthSuccessful() )
{
bool modsChanged = false

// disable all RequiredOnClient mods that are not required by the server and are currently enabled
foreach ( string modName in NSGetModNames() )
{
if ( NSIsModRequiredOnClient( modName ) && NSIsModEnabled( modName ) )
{
// find the mod name in the list of server required mods
bool found = false
foreach ( RequiredModInfo mod in server.requiredMods )
{
if (mod.name == modName)
Klemmbaustein marked this conversation as resolved.
Show resolved Hide resolved
{
found = true
break
}
}
// if we didnt find the mod name, disable the mod
if (!found)
Klemmbaustein marked this conversation as resolved.
Show resolved Hide resolved
{
modsChanged = true
NSSetModEnabled( modName, false )
}
}
}

// enable all RequiredOnClient mods that are required by the server and are currently disabled
foreach ( RequiredModInfo mod in server.requiredMods )
{
if ( NSIsModRequiredOnClient( mod.name ) && !NSIsModEnabled( mod.name ))
Klemmbaustein marked this conversation as resolved.
Show resolved Hide resolved
{
modsChanged = true
NSSetModEnabled( mod.name, true )
}
}

// only actually reload if we need to since the uiscript reset on reload lags hard
if ( modsChanged )
ReloadMods()

NSConnectToAuthedServer()
return true
}
else
{
string reason = NSGetAuthFailReason()

DialogData dialogData
dialogData.header = "#ERROR"
dialogData.message = reason
dialogData.image = $"ui/menu/common/dialog_error"

#if PC_PROG
GeckoEidechse marked this conversation as resolved.
Show resolved Hide resolved
AddDialogButton( dialogData, "#DISMISS" )

AddDialogFooter( dialogData, "#A_BUTTON_SELECT" )
#endif // PC_PROG
AddDialogFooter( dialogData, "#B_BUTTON_DISMISS_RUI" )

OpenDialog( dialogData )
return false
}
return false
}
Klemmbaustein marked this conversation as resolved.
Show resolved Hide resolved
Loading