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

Main Menu - Use connectToServer for server join #230

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions addons/main_menu/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);\
});
};
};
2 changes: 1 addition & 1 deletion addons/main_menu/CfgMainMenuSpotlight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
26 changes: 26 additions & 0 deletions addons/main_menu/XEH_displayPassword.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "script_component.hpp"
/*
* Author: veteran29
* Handles initialization of password display.
*
* Arguments:
* 0: Server password prompt display <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
22 changes: 22 additions & 0 deletions addons/main_menu/XEH_msgBox.sqf
Original file line number Diff line number Diff line change
@@ -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];
3 changes: 2 additions & 1 deletion addons/main_menu/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class CfgPatches {
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {
"afm_main"
"afm_main",
"cba_ui"
};
author = "ArmaForces";
authors[] = {"veteran29"};
Expand Down
80 changes: 6 additions & 74 deletions addons/main_menu/functions/fnc_join.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
* Based on article from KillZonekid
*
* Arguments:
* 1: Spotlight tile control that was clicked <CONTROL>
* 0: Spotlight tile control that was clicked <CONTROL>
* 1: Server address <STRING>
* 2: Server port <NUMBER>
*
* Return Value:
* None
*
* 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
Expand All @@ -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
2 changes: 2 additions & 0 deletions addons/main_menu/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@
#define IDC_SERVERSTATUS_PASSWORD 1002
#define IDC_SERVERSTATUS_LOGIN 1003
#define IDC_SERVERSTATUS_MISSIONS 1004

#define IDC_MSGBOX_TEXT 101
Loading