add call and spawn support

also added append usage to inject events into the scheduler
This commit is contained in:
vbawol 2017-10-24 11:18:39 -05:00
parent 10530e04e2
commit 67b8d6711f
2 changed files with 158 additions and 34 deletions

View File

@ -31,7 +31,7 @@ link15[] = {8,2};
link16[] = {9,2};
link17[] = {10,2};
globals[] = {0.000000,0,0,0,0,640,480,1,3,6316128,1,275.180084,1161.319580,208.497711,-659.879456,898,884,1};
window[] = {2,-1,-1,-1,-1,968,208,1500,208,3,916};
window[] = {2,-1,-1,-1,-1,838,78,1370,78,3,916};
*//*%FSM</HEAD>*/
class FSM
{
@ -353,43 +353,67 @@ class FSM
condition=/*%FSM<CONDITION""">*/"((diag_tickTime - _pvehTime) > 20)"/*%FSM</CONDITION""">*/;
action=/*%FSM<ACTION""">*/"// Epoch Events" \n
"_pvehTime = diag_tickTime;" \n
"_events append _injectedEvents;" \n
"_injectedEvents = [];" \n
"_newEvents = [];" \n
"{" \n
" _x params [""_time"", ""_scriptName"", [""_runAtStart"",0], [""_usePrePostfix"",1], [""_runNumTimes"",-1], [""_input"",[]], [""_disallowedWorlds"",[]] ];" \n
" _eventKey = format[""EPOCH_EVENT_%1"", _forEachIndex];" \n
" _eventCounter = format[""EPOCH_EVENT_COUNTER_%1"", _forEachIndex];" \n
" _lastTime = missionNamespace getVariable _eventKey;" \n
" _counter = missionNamespace getVariable [_eventCounter,0];" \n
" if (isNil ""_lastTime"") then {" \n
" _startTime = diag_tickTime;" \n
" if (_runAtStart isEqualTo 1) then {" \n
" _startTime = diag_tickTime - _time;" \n
" };" \n
" missionNamespace setVariable[_eventKey, _startTime];" \n
" _lastTime = _startTime;" \n
" };" \n
" if ((_counter >= _runNumTimes && _runNumTimes != -1) || worldName in _disallowedWorlds) then {" \n
" _x params [""_time"", ""_scriptName"", [""_runAtStart"",0], [""_usePrePostfix"",1], [""_runNumTimes"",-1], [""_input"",[]], [""_disallowedWorlds"",[]] ];" \n
" _scriptParams = [];" \n
" _scriptcmdMode = ""execVM"";" \n
" if (_scriptName isEqualType []) then {" \n
" _scriptParams = _scriptName param [0,[]];" \n
" _scriptcmdMode = _scriptName param [1,""call""];" \n
" _scriptName = _scriptName param [2,""""];" \n
" };" \n
" _eventKey = format[""EPOCH_EVENT_%1"", _scriptName];" \n
" _eventCounter = format[""EPOCH_EVENT_COUNTER_%1"", _scriptName];" \n
" _lastTime = missionNamespace getVariable _eventKey;" \n
" _counter = missionNamespace getVariable [_eventCounter,0];" \n
" if (isNil ""_lastTime"") then {" \n
" _startTime = diag_tickTime;" \n
" if (_runAtStart isEqualTo 1) then {" \n
" _startTime = diag_tickTime - _time;" \n
" };" \n
" missionNamespace setVariable[_eventKey, _startTime];" \n
" _lastTime = _startTime;" \n
" };" \n
" if ((_counter >= _runNumTimes && _runNumTimes != -1) || worldName in _disallowedWorlds) then {" \n
" diag_log format[""DEBUG: server event removed %1"", _scriptName];" \n
" } else {" \n
" missionNamespace setVariable[_eventKey, nil];" \n
" missionNamespace setVariable[_eventCounter, nil];" \n
" } else {" \n
" _newEvents pushBack _x;" \n
" if ((diag_tickTime - _lastTime) >= _time) then {" \n
" missionNamespace setVariable[_eventKey, diag_tickTime];" \n
" _preFix = """";" \n
" _postFix = """";" \n
" if (_usePrePostfix == 1) then {" \n
" _preFix = ""\epoch_server_settings\EpochEvents\"";" \n
" _postFix = "".sqf"";" \n
" };" \n
" if (_usePrePostfix == 2) then {" \n
" _preFix = ""\epoch_server_events\EpochEvents\"";" \n
" _postFix = "".sqf"";" \n
" };" \n
" _handle = _input execVM format[""%1%2%3"",_preFix,_scriptName,_postFix];" \n
" _counter = _counter + 1;" \n
" missionNamespace setVariable[_eventCounter, _counter];" \n
" diag_log format[""DEBUG: server event %1"", _scriptName];" \n
" };" \n
" };" \n
" if ((diag_tickTime - _lastTime) >= _time) then {" \n
" missionNamespace setVariable[_eventKey, diag_tickTime];" \n
" _preFix = """";" \n
" _postFix = """";" \n
" if (_usePrePostfix == 1) then {" \n
" _preFix = ""\epoch_server_settings\EpochEvents\"";" \n
" _postFix = "".sqf"";" \n
" };" \n
" if (_usePrePostfix == 2) then {" \n
" _preFix = ""\epoch_server_events\EpochEvents\"";" \n
" _postFix = "".sqf"";" \n
" };" \n
" switch (_scriptcmdMode) do {" \n
" case (""call""): {" \n
" // call" \n
" _scriptParams call (missionNamespace getVariable [_scriptName, {}]);" \n
" };" \n
" case (""spawn""): {" \n
" // spawn" \n
" _scriptParams spawn (missionNamespace getVariable [_scriptName, {}]);" \n
" };" \n
" default {" \n
" // execVM" \n
" _handle = _input execVM format[""%1%2%3"",_preFix,_scriptName,_postFix];" \n
" };" \n
" };" \n
" _counter = _counter + 1;" \n
" missionNamespace setVariable[_eventCounter, _counter];" \n
" diag_log format[""DEBUG: server event %1"", _scriptName];" \n
" };" \n
" };" \n
"} forEach _events;" \n
"// remove expired events" \n
"_events = _newEvents;" \n

100
Tools/SQF/scratch.sqf Normal file
View File

@ -0,0 +1,100 @@
// Epoch Events
_pvehTime = diag_tickTime;
_newEvents = [];
{
_x params ["_time", "_scriptName", ["_runAtStart",0], ["_usePrePostfix",1], ["_runNumTimes",-1], ["_input",[]], ["_disallowedWorlds",[]] ];
_scriptParams = [];
if (_scriptName isEqualType []) then {
_scriptParams = _scriptName param [0,[]];
_scriptcmdMode = _scriptName param [1,"call"];
_scriptName = _scriptName param [2,""];
};
_eventKey = format["EPOCH_EVENT_%1", _scriptName];
_eventCounter = format["EPOCH_EVENT_COUNTER_%1", _scriptName];
_lastTime = missionNamespace getVariable _eventKey;
_counter = missionNamespace getVariable [_eventCounter,0];
if (isNil "_lastTime") then {
_startTime = diag_tickTime;
if (_runAtStart isEqualTo 1) then {
_startTime = diag_tickTime - _time;
};
missionNamespace setVariable[_eventKey, _startTime];
_lastTime = _startTime;
};
if ((_counter >= _runNumTimes && _runNumTimes != -1) || worldName in _disallowedWorlds) then {
diag_log format["DEBUG: server event removed %1", _scriptName];
missionNamespace setVariable[_eventKey, nil];
missionNamespace setVariable[_eventCounter, nil];
} else {
_newEvents pushBack _x;
if ((diag_tickTime - _lastTime) >= _time) then {
missionNamespace setVariable[_eventKey, diag_tickTime];
_preFix = "";
_postFix = "";
if (_usePrePostfix == 1) then {
_preFix = "\epoch_server_settings\EpochEvents\";
_postFix = ".sqf";
};
if (_usePrePostfix == 2) then {
_preFix = "\epoch_server_events\EpochEvents\";
_postFix = ".sqf";
};
switch (_scriptcmdMode) do {
case ("call"): {
// call
_handle = _scriptParams call (missionNamespace getVariable [_scriptName, {}]);
};
case ("spawn"): {
// spawn
_handle = _scriptParams spawn (missionNamespace getVariable [_scriptName, {}]);
};
default {
// execVM
_handle = _input execVM format["%1%2%3",_preFix,_scriptName,_postFix];
};
};
_counter = _counter + 1;
missionNamespace setVariable[_eventCounter, _counter];
diag_log format["DEBUG: server event %1", _scriptName];
};
};
} forEach _events;
// remove expired events
_events = _newEvents;
// restart script
if (_scriptBasedRestart) then {
if (diag_tickTime >= _forceRestartTimeWarning) then {
if (!_serverLocked) then {
diag_log "server shutdown: locked";
_serverLocked = true;
["lock"] call EPOCH_serverCommand;
} else {
if (allPlayers isEqualTo []) then {
["shutdown"] call EPOCH_serverCommand;
diag_log "server shutdown: now";
};
};
_restartIn = round((_forceRestartTime-diag_tickTime)/60);
if (_prevRestartIn != _restartIn) then {
_prevRestartIn = _restartIn;
if (_restartIn > 1) then {
["message", format["Server restart in %1 minutes",_restartIn]] call EPOCH_serverCommand;
} else {
["message", format["Server restart in %1 minute",1]] call EPOCH_serverCommand;
};
};
};
// kick all remaining players before shutdown to force player save
if (diag_tickTime >= _forceRestartTime) then {
if (_serverRestarting) then {
["shutdown"] call EPOCH_serverCommand;
diag_log "server shutdown: now";
} else {
{
["kick", _x , "Server Restarting"] call EPOCH_serverCommand;
} forEach allPlayers;
_serverRestarting = true;
};
};
};