remoteExec: Difference between revisions
Jump to navigation
Jump to search
BrettMayson (talk | contribs) mNo edit summary |
No edit summary |
||
(12 intermediate revisions by 4 users not shown) | |||
Line 15: | Line 15: | ||
{{Feature|important|The direct execution of [[call]] or [[spawn]] via [[remoteExec]] (or [[remoteExecCall]]) should be avoided to prevent issues in cases where the remote execution of [[call]] or [[spawn]] is blocked by [[Arma 3: CfgRemoteExec|CfgRemoteExec]]. It is instead recommended to create a function to be itself remote-executed.}} | {{Feature|important|The direct execution of [[call]] or [[spawn]] via [[remoteExec]] (or [[remoteExecCall]]) should be avoided to prevent issues in cases where the remote execution of [[call]] or [[spawn]] is blocked by [[Arma 3: CfgRemoteExec|CfgRemoteExec]]. It is instead recommended to create a function to be itself remote-executed.}} | ||
{{Feature|warning|The order of persistent remote execution for JIP players is not guaranteed, i.e. the order in which multiple calls are added is not necessarily the order they will be executed for joining player.}} | |||
|mp= Remote executions are queued and are therefore executed in the same order on remote clients (see {{Link|#Example 8}}). | |mp= Remote executions are queued and are therefore executed in the same order on remote clients (see {{Link|#Example 8}}). | ||
Line 22: | Line 24: | ||
|p1= '''params''': [[Anything]] '''but''' [[Structured Text]] - ''order''<nowiki/>'s parameter {{Feature|important|[[Structured Text]] is '''not''' meant to be sent over network.}} | |p1= '''params''': [[Anything]] '''but''' [[Structured Text]] - ''order''<nowiki/>'s parameter {{Feature|important|[[Structured Text]] is '''not''' meant to be sent over network.}} | ||
|p2= '''order''': [[String]] - | |p2= '''order''': [[String]] - function or command name; while any function or command can be used here, only those allowed by [[Arma 3: CfgRemoteExec|CfgRemoteExec]] will actually be executed | ||
|p3= '''targets''' (Optional, default 0): | |p3= '''targets''' - (Optional, default 0): | ||
* [[Number]] (See also [[Multiplayer Scripting#Machine network ID|Machine network ID]]): | * [[Number]] (See also [[Multiplayer Scripting#Machine network ID|Machine network ID]]): | ||
** '''0:''' the order will be executed globally, i.e. on the server and every connected client, including the machine where [[remoteExec]] originated | ** '''0:''' the order will be executed globally, i.e. on the server and every connected client, including the machine where [[remoteExec]] originated | ||
** '''2:''' the order will only be executed on the server | ** '''2:''' the order will only be executed on the server - is both dedicated and hosted server. See [[Multiplayer_Scripting#Different_machines_and_how_to_target_them|for more info]] | ||
** '''Other number:''' the order will be executed on the machine where [[clientOwner]] matches the given number | ** '''Other number:''' the order will be executed on the machine where [[clientOwner]] matches the given number | ||
** '''Negative number:''' the effect is inverted: '''-2''' means every client but not the server, '''-12''' means the server and every client, except for the client where [[clientOwner]] returns 12 | ** '''Negative number:''' the effect is inverted: '''-2''' means every client but not the server, '''-12''' means the server and every client, except for the client where [[clientOwner]] returns 12 | ||
Line 36: | Line 38: | ||
* [[Array]] - array of any combination of the types listed above | * [[Array]] - array of any combination of the types listed above | ||
|p4= '''JIP''' (Optional, default [[false]]): | |p4= '''JIP''' - (Optional, default [[false]]): | ||
* [[Boolean]] - if [[true]], a unique JIP ID is generated and the [[remoteExec]] statement is added to the JIP queue from which it will be executed for every JIP | * [[Boolean]] - if [[true]], a unique JIP ID is generated and the [[remoteExec]] statement is added to the JIP queue from which it will be executed for every JIP | ||
* [[String]]: | * [[String]]: | ||
** | ** if the string is empty, it is interpreted as [[false]] | ||
** | ** if the string is in format "[[Number]]:[[Number]]" (e.g. "0:0"), it is interpreted as a [[netId]] (see below) | ||
** else the string is treated as a custom JIP ID and the [[remoteExec]] statement is added to the JIP queue, replacing statements that have the same JIP ID | ** else the string is treated as a custom JIP ID and the [[remoteExec]] statement is added to the JIP queue, replacing statements that have the same JIP ID | ||
* [[Object]], [[Group]] or [[netId]] - the persistent execution of the [[remoteExec]] statement is attached to the given object or group.<br>When the object / group is deleted, the [[remoteExec]] statement is automatically removed from the JIP queue | * [[Object]], [[Group]] or [[netId]] - the persistent execution of the [[remoteExec]] statement is attached to the given object or group, replacing any previous statement that has the same JIP ID.<br>When the object / group is deleted, the [[remoteExec]] statement is automatically removed from the JIP queue | ||
The '''JIP''' parameter can only be used if the '''targets''' parameter is 0 or a negative number.<br> | The '''JIP''' parameter can only be used if the '''targets''' parameter is 0 or a negative number.<br> | ||
Line 49: | Line 51: | ||
|r1= | |r1= | ||
* [[nil]] - In case of error. | * [[nil]] - In case of error. | ||
* [[String]] - In case of success. | * [[String]] - In case of success (see [[remoteExecutedJIPID]]). | ||
** If the '''JIP''' parameter was [[false]] or an empty string, the return value is "". | ** If the '''JIP''' parameter was [[false]] or an empty string, the return value is "". | ||
** If the '''JIP''' parameter was [[true]] or a custom JIP ID, the JIP ID is returned. | ** If the '''JIP''' parameter was [[true]] or a custom JIP ID, the JIP ID is returned. | ||
Line 58: | Line 60: | ||
|p21= '''functionName''': [[String]] - see the main syntax above for more details. | |p21= '''functionName''': [[String]] - see the main syntax above for more details. | ||
|p22= '''targets''' | |p22= '''targets''': [[Number]], [[Object]], [[String]], [[Side]], [[Group]] or [[Array]] - (Optional, default 0) see the main syntax above for more details. | ||
|p23= '''JIP''' | |p23= '''JIP''': [[Boolean]], [[String]], [[Object]], [[Group]] or [[netId]] - (Optional, default [[false]]) see the main syntax above for more details. | ||
|r2= [[nil]] or [[String]] - see the main syntax above for more details. | |r2= [[nil]] or [[String]] - see the main syntax above for more details. | ||
Line 82: | Line 84: | ||
[{{Color|darkred|["", "BLACK OUT"]}}] remoteExec ["{{Color|darkorange|cutRsc}}"]; {{cc|double brackets are needed as the unary command takes an array}}</code> | [{{Color|darkred|["", "BLACK OUT"]}}] remoteExec ["{{Color|darkorange|cutRsc}}"]; {{cc|double brackets are needed as the unary command takes an array}}</code> | ||
<code style="display: block">{{cc|functions, however, do not need double squared brackets}} | <code style="display: block"> | ||
{{cc|functions, however, do not need double squared brackets}} | |||
{{Color|teal|["line 1", "line 2"]}} spawn {{Color|darkorange|BIS_fnc_infoText}}; | {{Color|teal|["line 1", "line 2"]}} spawn {{Color|darkorange|BIS_fnc_infoText}}; | ||
{{cc|becomes}} | {{cc|becomes}} | ||
{{Color|teal|["line 1", "line 2"]}} remoteExec ["{{Color|darkorange|BIS_fnc_infoText}}"];</code> | {{Color|teal|["line 1", "line 2"]}} remoteExec ["{{Color|darkorange|BIS_fnc_infoText}}"]; | ||
</code> | |||
|x2= send an order to specific machines: | |x2= send an order to specific machines: | ||
<sqf> | <sqf> | ||
"message" remoteExec ["hint", 0]; // sends a hint message to everyone, identical to "message" remoteExec ["hint"] | "message" remoteExec ["hint", 0]; // sends a hint message to everyone, identical to "message" remoteExec ["hint"] | ||
"message" remoteExec ["hint", -2]; // sends a hint message to everybody but the server | "message" remoteExec ["hint", -2]; // sends a hint message to everybody but the server (also not hosted server) | ||
"message" remoteExec ["hint", myCar]; // sends a hint message where myCar is local | "message" remoteExec ["hint", myCar]; // sends a hint message where myCar is local | ||
"message" remoteExec ["hint", -clientOwner]; // sends a hint message to everybody but the current machine | "message" remoteExec ["hint", -clientOwner]; // sends a hint message to everybody but the current machine | ||
Line 125: | Line 129: | ||
|x5= A tricky example: executing <sqf inline>player setAmmo [primaryWeapon player, 1];</sqf> (on machines where the player is in MyGroup): | |x5= A tricky example: executing <sqf inline>player setAmmo [primaryWeapon player, 1];</sqf> (on machines where the player is in MyGroup): | ||
<sqf> | <sqf> | ||
[player, [primaryWeapon player, 1]] remoteExec ["setAmmo", MyGroup]; // WRONG: the local player object is used here! | [player, [primaryWeapon player, 1]] remoteExec ["setAmmo", MyGroup]; // WRONG: the local player object is used here! | ||
{ player setAmmo [primaryWeapon player, 1]; } remoteExec ["call", MyGroup]; // CORRECT: the remote player object is used here | [{ player setAmmo [primaryWeapon player, 1]; }] remoteExec ["call", MyGroup]; // CORRECT: the remote player object is used here | ||
</sqf> | </sqf> | ||
|x6= '''[[Multiplayer Scripting]] "performance trick"'''<br> | |x6= '''[[Multiplayer Scripting]] "performance trick"'''<br> | ||
This <sqf inline>[0, -2] select isDedicated</sqf> check is worth to avoid '''function''' server-side calculations only | This <sqf inline>[0, -2] select isDedicated</sqf> check is worth it to avoid '''function''' server-side calculations only. See also {{Link|#Example 9}} for an advanced solution. | ||
<sqf> | <sqf> | ||
["message"] remoteExec ["BIS_fnc_infoText"]; // not ideal - the function will still run on the dedicated server for nothing | ["message"] remoteExec ["BIS_fnc_infoText"]; // not ideal - the function will still run on the dedicated server for nothing | ||
["message"] remoteExec ["BIS_fnc_infoText", [0, -2] select isDedicated]; // ideal - the dedicated server will not run the code, a player-hosted server will | ["message"] remoteExec ["BIS_fnc_infoText", [0, -2] select isDedicated]; // ideal - the dedicated server will not run the code, a player-hosted server will | ||
"message" remoteExec ["hint", [0, -2] select isDedicated]; // the check is too | ["message"] remoteExec ["hint", [0, -2] select isDedicated]; // the check is too expensive to be worthy - it becomes worthy if the server logs an RPT warning | ||
"message" remoteExec ["hint"]; // the (dedicated) server will automatically ditch hint usage due to it not having an interface | ["message"] remoteExec ["hint"]; // the (dedicated) server will automatically ditch hint usage due to it not having an interface | ||
private _allPlayersTarget = [0, -2] select isDedicated; // caching the result for multiple usages makes it worthy - think of {{Link|Arma 3: Headless_Client|headless clients}} as well | |||
["message 1"] remoteExec ["hint", _allPlayersTarget]; | |||
["message 2"] remoteExec ["hint", _allPlayersTarget]; | |||
</sqf> | </sqf> | ||
{{Feature|informative|See {{Link|#Example 9}} below for an advanced example.}} | |||
|x7= <!-- This example is referenced in the Description section. --> | |x7= <!-- This example is referenced in the Description section. --> | ||
Line 153: | Line 162: | ||
</sqf> | </sqf> | ||
|seealso= [[remoteExecCall]] [[remoteExecutedOwner]] [[isRemoteExecuted]] [[isRemoteExecutedJIP]] [[Arma 3: Remote Execution]] [[canSuspend]] [[BIS_fnc_MP]] | |x9= <!-- This example is referenced in the Syntax section. --> | ||
It is possible to create a "to all players" remote exec target variable: | |||
<sqf> | |||
if (isServer) then | |||
{ | |||
TO_ALL_PLAYERS = [0, -2] select isDedicated; | |||
publicVariable "TO_ALL_PLAYERS"; | |||
}; | |||
</sqf> | |||
<spoiler text="Show HC-compatible version"> | |||
If {{Link|Arma 3: Headless Client|Headless Clients}} are involved: | |||
<sqf> | |||
if (isServer) then | |||
{ | |||
TO_ALL_PLAYERS = [0, -2] select isDedicated; | |||
private _allNegativeHCs = allPlayers apply { getPlayerID _x } select { _x != "-1" } // all valid playerIDs | |||
apply { getUserInfo _x } select { _x select 7 } // filter by HC | |||
apply { -(_x select 1) }; // get negative network ID | |||
if (_allNegativeHCs isNotEqualTo []) then | |||
{ | |||
TO_ALL_PLAYERS = [TO_ALL_PLAYERS] + _allNegativeHCs; | |||
}; | |||
publicVariable "TO_ALL_PLAYERS"; | |||
addMissionEventHandler ["OnUserConnected", { | |||
params ["_networkId"]; | |||
private _userInfo = getUserInfo _networkId; | |||
if !(_userInfo select 7) exitWith {}; // not a HC | |||
if (TO_ALL_PLAYERS isEqualType 0) then // number to array conversion | |||
{ | |||
if (TO_ALL_PLAYERS == 0) then // player-hosted | |||
{ | |||
TO_ALL_PLAYERS = [-(_userInfo select 1)]; | |||
} | |||
else // -2, dedicated server | |||
{ | |||
TO_ALL_PLAYERS = [TO_ALL_PLAYERS, -(_userInfo select 1)]; | |||
}; | |||
} | |||
else // already an array | |||
{ | |||
TO_ALL_PLAYERS pushBackUnique -(_userInfo select 1); | |||
}; | |||
publicVariable "TO_ALL_PLAYERS"; | |||
}]; | |||
}; | |||
</sqf> | |||
</spoiler> | |||
<sqf> | |||
// client or server will always target the good machines | |||
["Yay!"] remoteExec ["hint", TO_ALL_PLAYERS]; | |||
</sqf> | |||
|seealso= [[Multiplayer Scripting]] [[remoteExecCall]] [[remoteExecutedOwner]] [[isRemoteExecuted]] [[isRemoteExecutedJIP]] [[Arma 3: Remote Execution]] [[canSuspend]] [[BIS_fnc_MP]] [[remoteExecutedJIPID]] | |||
}} | }} | ||
Line 193: | Line 260: | ||
</sqf> | </sqf> | ||
Will display a hint for every client. This is especially useful for when the server is running a mod that is not required by clients. | Will display a hint for every client. This is especially useful for when the server is running a mod that is not required by clients. | ||
}} | |||
{{Note | |||
|user= Sa-Matra | |||
|timestamp= 20240919083305 | |||
|text= It is not possible to use two negative owners to exclude two clients, you'll end up REing all clients: | |||
<sqf>args remoteExec ["func", [-2, -3]]; // Doesn't work, gonna execute on every client</sqf> | |||
}} | }} |
Latest revision as of 09:33, 19 September 2024
Description
- Description:
- Asks the server to execute the given function or script command on the given target machine(s).
- Functions are executed in the scheduled environment; suspension is allowed.
- Script commands are executed in the unscheduled environment; suspension is not allowed (see Example 7).
- Multiplayer:
- Remote executions are queued and are therefore executed in the same order on remote clients (see Example 8).
- Groups:
- Multiplayer
Syntax
- Syntax:
- params remoteExec [order, targets, JIP]
- Parameters:
- params: Anything but Structured Text - order's parameter
- order: String - function or command name; while any function or command can be used here, only those allowed by CfgRemoteExec will actually be executed
- targets - (Optional, default 0):
- Number (See also Machine network ID):
- 0: the order will be executed globally, i.e. on the server and every connected client, including the machine where remoteExec originated
- 2: the order will only be executed on the server - is both dedicated and hosted server. See for more info
- Other number: the order will be executed on the machine where clientOwner matches the given number
- Negative number: the effect is inverted: -2 means every client but not the server, -12 means the server and every client, except for the client where clientOwner returns 12
- Object - the order will be executed where the given object is local
- String - interpreted as an Identifier (variable name); the function / command will be executed where the object or group identified by the variable with the provided name is local
- Side - the order will be executed on machines where the player is on the specified side
- Group - the order will be executed on machines where the player is in the specified group (not where said group is local!)
- Array - array of any combination of the types listed above
- Number (See also Machine network ID):
- JIP - (Optional, default false):
- Boolean - if true, a unique JIP ID is generated and the remoteExec statement is added to the JIP queue from which it will be executed for every JIP
- String:
- if the string is empty, it is interpreted as false
- if the string is in format "Number:Number" (e.g. "0:0"), it is interpreted as a netId (see below)
- else the string is treated as a custom JIP ID and the remoteExec statement is added to the JIP queue, replacing statements that have the same JIP ID
- Object, Group or netId - the persistent execution of the remoteExec statement is attached to the given object or group, replacing any previous statement that has the same JIP ID.
When the object / group is deleted, the remoteExec statement is automatically removed from the JIP queue
See also Example 3 on how to remove statements from the JIP queue. - Return Value:
-
- nil - In case of error.
- String - In case of success (see remoteExecutedJIPID).
Alternative Syntax
- Syntax:
- remoteExec [functionName, targets, JIP]
- Parameters:
- functionName: String - see the main syntax above for more details.
- targets: Number, Object, String, Side, Group or Array - (Optional, default 0) see the main syntax above for more details.
- JIP: Boolean, String, Object, Group or netId - (Optional, default false) see the main syntax above for more details.
- Return Value:
- nil or String - see the main syntax above for more details.
Examples
- Example 1:
- How to write remoteExec/remoteExecCall:
hint "Hello"; // becomes ["Hello"] remoteExec ["hint"]; "Hello" remoteExec ["hint"]; // alternatively
unit1 setFace "Miller"; // becomes [unit1, "Miller"] remoteExec ["setFace"];
cutRsc ["", "BLACK OUT"]; // becomes [["", "BLACK OUT"]] remoteExec ["cutRsc"]; // double brackets are needed as the unary command takes an array
// functions, however, do not need double squared brackets ["line 1", "line 2"] spawn BIS_fnc_infoText; // becomes ["line 1", "line 2"] remoteExec ["BIS_fnc_infoText"];
- Example 2:
- send an order to specific machines:
"message" remoteExec ["hint", 0]; // sends a hint message to everyone, identical to "message" remoteExec ["hint"] "message" remoteExec ["hint", -2]; // sends a hint message to everybody but the server (also not hosted server) "message" remoteExec ["hint", myCar]; // sends a hint message where myCar is local "message" remoteExec ["hint", -clientOwner]; // sends a hint message to everybody but the current machine
- Example 3:
- Add statements to the JIP queue:
["mission state: the car is broken"] remoteExec ["systemChat", 0, _queueObject]; // ... remoteExec ["", _queueObject]; // the order attached to _queueObject is removedprivate _jipId = ["mission state: the car is broken"] remoteExec ["systemChat", 0, "MY_JIP_ID"]; // _jipId is actually "MY_JIP_ID" now waitUntil { canMove _car }; ["mission state: the car is repaired"] remoteExec ["systemChat", 0, "MY_JIP_ID"]; // this order replaces the previous one // ... remoteExec ["", "MY_JIP_ID"]; // the "MY_JIP_ID" order is removed from the JIP queue
- Example 4:
- Some more complex examples:
- Example 5:
- A tricky example: executing player setAmmo [primaryWeapon player, 1]; (on machines where the player is in MyGroup):
[player, [primaryWeapon player, 1]] remoteExec ["setAmmo", MyGroup]; // WRONG: the local player object is used here! [{ player setAmmo [primaryWeapon player, 1]; }] remoteExec ["call", MyGroup]; // CORRECT: the remote player object is used here
- Example 6:
- Multiplayer Scripting "performance trick"
This [0, -2] select isDedicated check is worth it to avoid function server-side calculations only. See also Example 9 for an advanced solution.["message"] remoteExec ["BIS_fnc_infoText"]; // not ideal - the function will still run on the dedicated server for nothing ["message"] remoteExec ["BIS_fnc_infoText", [0, -2] select isDedicated]; // ideal - the dedicated server will not run the code, a player-hosted server will ["message"] remoteExec ["hint", [0, -2] select isDedicated]; // the check is too expensive to be worthy - it becomes worthy if the server logs an RPT warning ["message"] remoteExec ["hint"]; // the (dedicated) server will automatically ditch hint usage due to it not having an interface private _allPlayersTarget = [0, -2] select isDedicated; // caching the result for multiple usages makes it worthy - think of headless clients as well ["message 1"] remoteExec ["hint", _allPlayersTarget]; ["message 2"] remoteExec ["hint", _allPlayersTarget]; - Example 7:
- As said in the description: commands will be executed in an unscheduled environment
[{ sleep 1 }] remoteExec ["call"]; // will throw an error: it is forbidden to use sleep (or waitUntil, etc) in unscheduled environment
- Example 8:
- "Message 1" remoteExec ["systemChat"]; "Message 2" remoteExec ["systemChat"]; // will result in // "Message 1" // "Message 2" // in this exact order on clients
- Example 9:
- It is possible to create a "to all players" remote exec target variable:
if (isServer) then { TO_ALL_PLAYERS = [0, -2] select isDedicated; publicVariable "TO_ALL_PLAYERS"; };
If Headless Clients are involved:
↑ Back to spoiler's topif (isServer) then { TO_ALL_PLAYERS = [0, -2] select isDedicated; private _allNegativeHCs = allPlayers apply { getPlayerID _x } select { _x != "-1" } // all valid playerIDs apply { getUserInfo _x } select { _x select 7 } // filter by HC apply { -(_x select 1) }; // get negative network ID if (_allNegativeHCs isNotEqualTo []) then { TO_ALL_PLAYERS = [TO_ALL_PLAYERS] + _allNegativeHCs; }; publicVariable "TO_ALL_PLAYERS"; addMissionEventHandler ["OnUserConnected", { params ["_networkId"]; private _userInfo = getUserInfo _networkId; if !(_userInfo select 7) exitWith {}; // not a HC if (TO_ALL_PLAYERS isEqualType 0) then // number to array conversion { if (TO_ALL_PLAYERS == 0) then // player-hosted { TO_ALL_PLAYERS = [-(_userInfo select 1)]; } else // -2, dedicated server { TO_ALL_PLAYERS = [TO_ALL_PLAYERS, -(_userInfo select 1)]; }; } else // already an array { TO_ALL_PLAYERS pushBackUnique -(_userInfo select 1); }; publicVariable "TO_ALL_PLAYERS"; }]; };// client or server will always target the good machines ["Yay!"] remoteExec ["hint", TO_ALL_PLAYERS];
Additional Information
- See also:
- Multiplayer Scripting remoteExecCall remoteExecutedOwner isRemoteExecuted isRemoteExecutedJIP Arma 3: Remote Execution canSuspend BIS_fnc_MP remoteExecutedJIPID
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
- Posted on Dec 29, 2015 - 20:28 (UTC)
-
remoteExec and remoteExecCall are currently filtered by BattlEye's remoteexec.txt, the string analyzed by BE is formatted the same way as the following example's output:
If CfgRemoteExec class Functions is set to mode = 1;, the following remoteexec.txt exclusion can be used to safely allow all whitelisted *_fnc_* functions taking an array as parameter to go through:
Any attempt to exploit this exclusion using other RE methods like createUnit will run into "Error Missing ;" without any malicious code being executed. Mod makers should refrain from remote-executing raw commands from clients, as they require individual exclusions, and instead use *_fnc_* functions taking an array as parameter, which are covered by the above exclusion.!="\w+?_fnc_\w+? \[[\S\s]*\]"
- Posted on Jan 30, 2017 - 18:35 (UTC)
-
will fail, as you can't use JIP and remoteExec on server only[someArgs] remoteExec ['someCommand', 2]; // works
- Posted on Mar 05, 2021 - 00:48 (UTC)
-
The remoteExec'ed function only has to exist on the target machine. For example:
Will display a hint for every client. This is especially useful for when the server is running a mod that is not required by clients.// executed on a DEDICATED server remoteExec ["TAG_fnc_testRemote", -2];
- Posted on Sep 19, 2024 - 08:33 (UTC)
-
It is not possible to use two negative owners to exclude two clients, you'll end up REing all clients:
args remoteExec ["func", [-2, -3]]; // Doesn't work, gonna execute on every client