diff --git a/addons/main_menu/CfgEventHandlers.hpp b/addons/main_menu/CfgEventHandlers.hpp index fe0ce50..47109d0 100644 --- a/addons/main_menu/CfgEventHandlers.hpp +++ b/addons/main_menu/CfgEventHandlers.hpp @@ -25,4 +25,16 @@ class Extended_DisplayLoad_EventHandlers { ARR_2([_this select 0,'RscDisplayMultiplayerSetup']) call COMPILE_SCRIPT(XEH_multiplayerDisplay);\ }); }; + + class RscDisplayPassword { + ADDON = QUOTE(with uiNamespace do {\ + [_this select 0] call COMPILE_SCRIPT(XEH_displayPassword);\ + }); + }; + + class RscMsgBox { + ADDON = QUOTE(with uiNamespace do {\ + [_this select 0] call COMPILE_SCRIPT(XEH_msgBox);\ + }); + }; }; diff --git a/addons/main_menu/CfgMainMenuSpotlight.hpp b/addons/main_menu/CfgMainMenuSpotlight.hpp index 11c17cb..19f47a4 100644 --- a/addons/main_menu/CfgMainMenuSpotlight.hpp +++ b/addons/main_menu/CfgMainMenuSpotlight.hpp @@ -5,7 +5,7 @@ class CfgMainMenuSpotlight { text = CSTRING(SpotlightJoin); textIsQuote = 0; picture = QUOTE(\z\afm\addons\main\ui\logo_sm_ca.paa); - action = QUOTE(_this call (uiNamespace getVariable QQFUNC(join))); + action = QUOTE(ARR_3([_this,'server.armaforces.com',2302]) call (uiNamespace getVariable QQFUNC(join))); actionText = CSTRING(SpotlightHeader); condition = QUOTE(true); }; diff --git a/addons/main_menu/XEH_displayPassword.sqf b/addons/main_menu/XEH_displayPassword.sqf new file mode 100644 index 0000000..af6195b --- /dev/null +++ b/addons/main_menu/XEH_displayPassword.sqf @@ -0,0 +1,26 @@ +#include "script_component.hpp" +/* + * Author: veteran29 + * Handles initialization of password display. + * + * Arguments: + * 0: Server password prompt display + * + * Return Value: + * None + * + * Public: No + */ + +params ["_display"]; + +if !(uiNamespace getVariable [QGVAR(autoConfirm), true]) exitWith {INFO("Auto password confirm disabled")}; + +private _ctrlConfirm = _display displayCtrl IDC_OK; +private _ctrlPassword = _display displayCtrl IDC_PASSWORD; + +if (ctrlText _ctrlPassword == "") exitWith {}; + +ctrlActivate _ctrlConfirm; + +nil diff --git a/addons/main_menu/XEH_msgBox.sqf b/addons/main_menu/XEH_msgBox.sqf new file mode 100644 index 0000000..e2c9742 --- /dev/null +++ b/addons/main_menu/XEH_msgBox.sqf @@ -0,0 +1,22 @@ +#include "script_component.hpp" +/* + * Author: veteran29 + * Handle initialization of message box. Disables auto password confirm if wrong password was provided. + * + * Arguments: + * 0: RscMsgBox display [DISPLAY] + * + * Return Value: + * None + * + * Public: No + */ + +params ["_display"]; + +private _ctrlText = _display displayCtrl IDC_MSGBOX_TEXT; +if (ctrlText _ctrlText != localize "STR_Msg_MP_Password") exitWith {}; + +INFO("Invalid server password, disabling auto confirm"); + +uiNamespace setVariable [QGVAR(autoConfirm), false]; diff --git a/addons/main_menu/config.cpp b/addons/main_menu/config.cpp index 2ae1e00..1c2fa15 100644 --- a/addons/main_menu/config.cpp +++ b/addons/main_menu/config.cpp @@ -7,7 +7,8 @@ class CfgPatches { weapons[] = {}; requiredVersion = REQUIRED_VERSION; requiredAddons[] = { - "afm_main" + "afm_main", + "cba_ui" }; author = "ArmaForces"; authors[] = {"veteran29"}; diff --git a/addons/main_menu/functions/fnc_join.sqf b/addons/main_menu/functions/fnc_join.sqf index e227950..01f6b0d 100644 --- a/addons/main_menu/functions/fnc_join.sqf +++ b/addons/main_menu/functions/fnc_join.sqf @@ -5,7 +5,9 @@ * Based on article from KillZonekid * * Arguments: - * 1: Spotlight tile control that was clicked + * 0: Spotlight tile control that was clicked + * 1: Server address + * 2: Server port * * Return Value: * None @@ -13,9 +15,7 @@ * Public: No */ -#define MULTI_SESSIONS_CTRL (findDisplay IDD_MULTIPLAYER displayCtrl IDC_MULTI_SESSIONS) - -params ["_button"]; +params ["_button", "_server", ["_port", 2302]]; // if no world is loaded missionNamespace will be empty // copy logging function from uiNamespace @@ -26,76 +26,8 @@ if (isNil "CBA_fnc_log") then { // Disable Enchanced Multiplayer Menu for compatiblity with this script uiNamespace setVariable ["EMM_multiplayerMenu_enabled", false]; -INFO("Auto joining to ArmaForces server"); - -GVAR(serverAddress) = "server.armaforces.com"; -GVAR(serverPort) = "2302"; -GVAR(joinTimeout) = diag_tickTime + 5; - -// "Click" server browser from main menu -ctrlActivate ((ctrlParent _button) displayCtrl IDC_MAIN_MULTIPLAYER); - -onEachFrame { - onEachFrame { - // Direct connect button - ctrlActivate (findDisplay IDD_MULTIPLAYER displayCtrl IDC_MULTI_TAB_DIRECT_CONNECT); - - onEachFrame { - // Fill server data - private _ctrlServerAddress = findDisplay IDD_IP_ADDRESS displayCtrl 2300; - _ctrlServerAddress controlsGroupCtrl IDC_IP_ADDRESS ctrlSetText GVAR(serverAddress); - _ctrlServerAddress controlsGroupCtrl IDC_IP_PORT ctrlSetText GVAR(serverPort); - ctrlActivate (_ctrlServerAddress controlsGroupCtrl IDC_OK); - - onEachFrame { - (MULTI_SESSIONS_CTRL lbData 0) call { - LOG_2("Joining - time: %1 - timeout: %2",diag_tickTime,GVAR(joinTimeout)); - - if (diag_tickTime > GVAR(joinTimeout)) then { - ERROR("Join timeout - no server"); - onEachFrame {}; - }; +INFO_2("Auto joining to %1:%2",_server,_port); - if (_this != "") then { - MULTI_SESSIONS_CTRL lbSetCurSel 0; - - onEachFrame { - INFO("Activating join button"); - ctrlActivate (findDisplay IDD_MULTIPLAYER displayCtrl IDC_MULTI_JOIN); - - onEachFrame { - if (diag_tickTime > GVAR(joinTimeout)) then { - WARNING("Join timeout"); - onEachFrame {}; - }; - - if (!isNull findDisplay IDD_PASSWORD) then { - INFO("Password prompt"); - private _ctrlPassword = findDisplay IDD_PASSWORD displayCtrl IDC_PASSWORD; - private _savedPassword = ctrlText _ctrlPassword; - - if(count _savedPassword > 0) then { - _ctrlPassword ctrlSetText _savedPassword; - ctrlActivate (findDisplay IDD_PASSWORD displayCtrl IDC_OK); - INFO("Saved password found, joining"); - onEachFrame {}; - } else { - INFO("No saved password, user interaction required"); - onEachFrame {}; - }; - }; - - if (getClientStateNumber >= 3) then { - INFO("Connection successful"); - onEachFrame {}; - }; - }; - }; - }; - }; - }; - }; - }; -}; +connectToServer [_server, _port, ""]; nil diff --git a/addons/main_menu/script_component.hpp b/addons/main_menu/script_component.hpp index 0f8d6f8..0072b28 100644 --- a/addons/main_menu/script_component.hpp +++ b/addons/main_menu/script_component.hpp @@ -42,3 +42,5 @@ #define IDC_SERVERSTATUS_PASSWORD 1002 #define IDC_SERVERSTATUS_LOGIN 1003 #define IDC_SERVERSTATUS_MISSIONS 1004 + +#define IDC_MSGBOX_TEXT 101