Advertisement
Guest User

server_monitor.sqf

a guest
May 17th, 2018
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.69 KB | None | 0 0
  1. private ["_oriarray","_nul","_result","_pos","_wsDone","_dir","_isOK","_countr","_objWpnTypes","_objWpnQty","_dam","_selection","_totalvehicles","_object","_idKey","_type","_ownerID","_worldspace","_inventory","_hitPoints","_fuel","_damage","_key","_vehLimit","_hiveResponse","_objectCount","_codeCount","_data","_status","_val","_traderid","_retrader","_traderData","_id","_lockable","_debugMarkerPosition","_vehicle_0","_bQty","_vQty","_BuildingQueue","_objectQueue","_superkey","_shutdown","_res","_hiveLoaded","_ownerUID","_oQty","_originsQueue","_isOrigins"];
  2.  
  3. dayz_versionNo = getText(configFile >> "CfgMods" >> "DayZ" >> "version");
  4. dayz_hiveVersionNo = getNumber(configFile >> "CfgMods" >> "DayZ" >> "hiveVersion");
  5.  
  6. _hiveLoaded = false;
  7.  
  8. waitUntil{initialized}; //means all the functions are now defined
  9.  
  10. diag_log "HIVE: Starting";
  11.  
  12. waituntil{isNil "sm_done"}; // prevent server_monitor be called twice (bug during login of the first player)
  13.  
  14. // Custom Configs
  15. if(isnil "MaxVehicleLimit") then {
  16. MaxVehicleLimit = 50;
  17. };
  18.  
  19. if(isnil "MaxDynamicDebris") then {
  20. MaxDynamicDebris = 100;
  21. };
  22. if(isnil "MaxAmmoBoxes") then {
  23. MaxAmmoBoxes = 3;
  24. };
  25. if(isnil "MaxMineVeins") then {
  26. MaxMineVeins = 50;
  27. };
  28. // Custon Configs End
  29.  
  30. if (isServer && isNil "sm_done") then {
  31.  
  32. serverVehicleCounter = [];
  33. _hiveResponse = [];
  34.  
  35. for "_i" from 1 to 5 do {
  36. diag_log "HIVE: trying to get objects";
  37. _key = format["CHILD:302:%1:", dayZ_instance];
  38. _hiveResponse = _key call server_hiveReadWrite;
  39. if ((((isnil "_hiveResponse") || {(typeName _hiveResponse != "ARRAY")}) || {((typeName (_hiveResponse select 1)) != "SCALAR")})) then {
  40. if ((_hiveResponse select 1) == "Instance already initialized") then {
  41. _superkey = profileNamespace getVariable "SUPERKEY";
  42. _shutdown = format["CHILD:400:%1:", _superkey];
  43. _res = _shutdown call server_hiveReadWrite;
  44. diag_log ("HIVE: attempt to kill.. HiveExt response:"+str(_res));
  45. } else {
  46. diag_log ("HIVE: connection problem... HiveExt response:"+str(_hiveResponse));
  47.  
  48. };
  49. _hiveResponse = ["",0];
  50. }
  51. else {
  52. diag_log ("HIVE: found "+str(_hiveResponse select 1)+" objects" );
  53. _i = 99; // break
  54. };
  55. };
  56.  
  57. _BuildingQueue = [];
  58. _objectQueue = [];
  59. _originsQueue = [];
  60. //Define arrays
  61. owner_B1 = [];
  62. owner_B2 = [];
  63. owner_B3 = [];
  64. owner_H1 = [];
  65. owner_H2 = [];
  66. owner_H3 = [];
  67. owner_SG = [];
  68. owner_LG = [];
  69. owner_KING = [];
  70. owner_SH = [];
  71.  
  72. if ((_hiveResponse select 0) == "ObjectStreamStart") then {
  73.  
  74. // save superkey
  75. profileNamespace setVariable ["SUPERKEY",(_hiveResponse select 2)];
  76.  
  77. _hiveLoaded = true;
  78.  
  79. diag_log ("HIVE: Commence Object Streaming...");
  80. _key = format["CHILD:302:%1:", dayZ_instance];
  81. _objectCount = _hiveResponse select 1;
  82. _bQty = 0;
  83. _vQty = 0;
  84. _oQty = 0;
  85.  
  86. for "_i" from 1 to _objectCount do {
  87. _isOrigins = false;
  88. _hiveResponse = _key call server_hiveReadWriteLarge;
  89. //diag_log (format["HIVE dbg %1 %2", typeName _hiveResponse, _hiveResponse]);
  90. {
  91. if((_hiveResponse select 2) isKindOf _x) exitWith {
  92. _originsQueue set [_oQty,_hiveResponse];
  93. _oQty = _oQty + 1;
  94. _isOrigins = true;
  95. };
  96. } forEach DZE_Origins_Buildings;
  97. if(!_isOrigins) then {
  98. if ((_hiveResponse select 2) isKindOf "ModularItems") then {
  99. _BuildingQueue set [_bQty,_hiveResponse];
  100. _bQty = _bQty + 1;
  101. } else {
  102. _objectQueue set [_vQty,_hiveResponse];
  103. _vQty = _vQty + 1;
  104. };
  105. };
  106. };
  107. diag_log ("HIVE: got " + str(_bQty) + " Epoch Objects and " + str(_vQty) + " Vehicles");
  108. };
  109.  
  110. // # NOW SPAWN OBJECTS #
  111. _totalvehicles = 0;
  112. {
  113. _idKey = _x select 1;
  114. _type = _x select 2;
  115. _ownerID = _x select 3;
  116.  
  117. _worldspace = _x select 4;
  118. _inventory = _x select 5;
  119. _hitPoints = _x select 6;
  120. _fuel = _x select 7;
  121. _damage = _x select 8;
  122.  
  123. _dir = 0;
  124. _pos = [0,0,0];
  125. _wsDone = false;
  126. if (count _worldspace >= 2) then
  127. {
  128. if ((typeName (_worldspace select 0)) == "STRING") then {
  129. _worldspace set [0, call compile (_worldspace select 0)];
  130. _worldspace set [1, call compile (_worldspace select 1)];
  131. };
  132.  
  133. _dir = _worldspace select 0;
  134. if (count (_worldspace select 1) == 3) then {
  135. _pos = _worldspace select 1;
  136. _wsDone = true;
  137. }
  138. };
  139.  
  140. if (!_wsDone) then {
  141. if (count _worldspace >= 1) then { _dir = _worldspace select 0; };
  142. _pos = [getMarkerPos "center",0,4000,10,0,2000,0] call BIS_fnc_findSafePos;
  143. if (count _pos < 3) then { _pos = [_pos select 0,_pos select 1,0]; };
  144. diag_log ("MOVED OBJ: " + str(_idKey) + " of class " + _type + " to pos: " + str(_pos));
  145. };
  146.  
  147. _vector = [[0,0,0],[0,0,0]];
  148. _vecExists = false;
  149. _ownerPUID = "0";
  150. if (count _worldspace >= 3) then{
  151. if(count _worldspace == 3) then{
  152. if(typename (_worldspace select 2) == "STRING")then{
  153. _ownerPUID = _worldspace select 2;
  154. }else{
  155. if(typename (_worldspace select 2) == "ARRAY")then{
  156. _vector = _worldspace select 2;
  157. if(count _vector == 2)then{
  158. if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  159. _vecExists = true;
  160. };
  161. };
  162. };
  163. };
  164.  
  165. }else{
  166. //Was not 3 elements, so check if 4 or more
  167. if(count _worldspace == 4) then{
  168. if(typename (_worldspace select 3) == "STRING")then{
  169. _ownerPUID = _worldspace select 3;
  170. }else{
  171. if(typename (_worldspace select 2) == "STRING")then{
  172. _ownerPUID = _worldspace select 2;
  173. };
  174. };
  175.  
  176.  
  177. if(typename (_worldspace select 2) == "ARRAY")then{
  178. _vector = _worldspace select 2;
  179. if(count _vector == 2)then{
  180. if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  181. _vecExists = true;
  182. };
  183. };
  184. }else{
  185. if(typename (_worldspace select 3) == "ARRAY")then{
  186. _vector = _worldspace select 3;
  187. if(count _vector == 2)then{
  188. if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  189. _vecExists = true;
  190. };
  191. };
  192. };
  193. };
  194.  
  195. }else{
  196. //More than 3 or 4 elements found
  197. //Might add a search for the vector, ownerPUID will equal 0
  198. };
  199. };
  200. };
  201.  
  202.  
  203. if (_damage < 1) then {
  204. //diag_log format["OBJ: %1 - %2", _idKey,_type];
  205.  
  206. //Create it
  207. _object = createVehicle [_type, _pos, [], 0, "CAN_COLLIDE"];
  208. _object setVariable ["lastUpdate",time];
  209. _object setVariable ["ObjectID", _idKey, true];
  210. if (typeOf (_object) == "Plastic_Pole_EP1_DZ") then {
  211. _object setVariable ["plotfriends", _inventory, true];
  212. };
  213. _oriarray =["ori_ZAZ968M","ori_taviander","ori_buchanka","ori_m3","ori_maniac","ori_KaTransp","ori_ScrapRaft"];
  214. if (typeOF _object in _oriarray) then {
  215. _object animate ["tropa",1];
  216. if (typeOF _object == "ori_ScrapRaft") then {_object animate ["OriModOhrana",1];};
  217. };
  218.  
  219. _lockable = 0;
  220. if(isNumber (configFile >> "CfgVehicles" >> _type >> "lockable")) then {
  221. _lockable = getNumber(configFile >> "CfgVehicles" >> _type >> "lockable");
  222. };
  223.  
  224. // fix for leading zero issues on safe codes after restart
  225. if (_lockable == 4) then {
  226. _codeCount = (count (toArray _ownerID));
  227. if(_codeCount == 3) then {
  228. _ownerID = format["0%1", _ownerID];
  229. };
  230. if(_codeCount == 2) then {
  231. _ownerID = format["00%1", _ownerID];
  232. };
  233. if(_codeCount == 1) then {
  234. _ownerID = format["000%1", _ownerID];
  235. };
  236. };
  237.  
  238. if (_lockable == 3) then {
  239. _codeCount = (count (toArray _ownerID));
  240. if(_codeCount == 2) then {
  241. _ownerID = format["0%1", _ownerID];
  242. };
  243. if(_codeCount == 1) then {
  244. _ownerID = format["00%1", _ownerID];
  245. };
  246. };
  247.  
  248. _object setVariable ["CharacterID", _ownerID, true];
  249.  
  250. clearWeaponCargoGlobal _object;
  251. clearMagazineCargoGlobal _object;
  252. // _object setVehicleAmmo DZE_vehicleAmmo;
  253.  
  254. _object setdir _dir;
  255. if(_vecExists)then{
  256. _object setVectorDirAndUp _vector;
  257. };
  258. _object setposATL _pos;
  259. _object setDamage _damage;
  260.  
  261. if ((typeOf _object) in dayz_allowedObjects) then {
  262. _object setVariable["memDir",_dir,true];
  263. if (DZE_GodModeBase) then {
  264. _object addEventHandler ["HandleDamage", {false}];
  265. } else {
  266. _object addMPEventHandler ["MPKilled",{_this call object_handleServerKilled;}];
  267. };
  268. // Test disabling simulation server side on buildables only.
  269. _object enableSimulation false;
  270. // used for inplace upgrades && lock/unlock of safe
  271. _object setVariable ["OEMPos", _pos, true];
  272.  
  273. };
  274.  
  275. if ((count _inventory > 0) && !(typeOf( _object) == "Plastic_Pole_EP1_DZ")) then {
  276. /*ZSC*/
  277. if( count (_inventory) > 3)then{
  278. _object setVariable ["bankMoney", _inventory select 3, true];
  279. }else{
  280. _object setVariable ["bankMoney", 0, true];
  281. };
  282. /*ZSC*/
  283. if (_type in DZE_LockedStorage || _type in DZE_Origins_Buildings) then {
  284. // Fill variables with loot
  285. _object setVariable ["WeaponCargo", (_inventory select 0),true];
  286. _object setVariable ["MagazineCargo", (_inventory select 1),true];
  287. _object setVariable ["BackpackCargo", (_inventory select 2),true];
  288. } else {
  289.  
  290. //Add weapons
  291. _objWpnTypes = (_inventory select 0) select 0;
  292. _objWpnQty = (_inventory select 0) select 1;
  293. _countr = 0;
  294. {
  295. if(_x in (DZE_REPLACE_WEAPONS select 0)) then {
  296. _x = (DZE_REPLACE_WEAPONS select 1) select ((DZE_REPLACE_WEAPONS select 0) find _x);
  297. };
  298. _isOK = isClass(configFile >> "CfgWeapons" >> _x);
  299. if (_isOK) then {
  300. _object addWeaponCargoGlobal [_x,(_objWpnQty select _countr)];
  301. };
  302. _countr = _countr + 1;
  303. } count _objWpnTypes;
  304.  
  305. //Add Magazines
  306. _objWpnTypes = (_inventory select 1) select 0;
  307. _objWpnQty = (_inventory select 1) select 1;
  308. _countr = 0;
  309. {
  310. if (_x == "BoltSteel") then { _x = "WoodenArrow" }; // Convert BoltSteel to WoodenArrow
  311. if (_x == "ItemTent") then { _x = "ItemTentOld" };
  312. _isOK = isClass(configFile >> "CfgMagazines" >> _x);
  313. if (_isOK) then {
  314. _object addMagazineCargoGlobal [_x,(_objWpnQty select _countr)];
  315. };
  316. _countr = _countr + 1;
  317. } count _objWpnTypes;
  318.  
  319. //Add Backpacks
  320. _objWpnTypes = (_inventory select 2) select 0;
  321. _objWpnQty = (_inventory select 2) select 1;
  322. _countr = 0;
  323. {
  324. _isOK = isClass(configFile >> "CfgVehicles" >> _x);
  325. if (_isOK) then {
  326. _object addBackpackCargoGlobal [_x,(_objWpnQty select _countr)];
  327. };
  328. _countr = _countr + 1;
  329. } count _objWpnTypes;
  330. };
  331. };
  332.  
  333. if (_object isKindOf "AllVehicles") then {
  334. {
  335. _selection = _x select 0;
  336. _dam = _x select 1;
  337. if (_selection in dayZ_explosiveParts && _dam > 0.8) then {_dam = 0.8};
  338. [_object,_selection,_dam] call object_setFixServer;
  339. } count _hitpoints;
  340.  
  341. _object setFuel _fuel;
  342.  
  343. if (!((typeOf _object) in dayz_allowedObjects)) then {
  344.  
  345. //_object setvelocity [0,0,1];
  346. _object call fnc_veh_ResetEH;
  347.  
  348. if(_ownerID != "0" && !(_object isKindOf "Bicycle")) then {
  349. _object setvehiclelock "locked";
  350. _object setVariable ["R3F_LOG_disabled",true,true];
  351. };
  352.  
  353. _totalvehicles = _totalvehicles + 1;
  354.  
  355. // total each vehicle
  356. serverVehicleCounter set [count serverVehicleCounter,_type];
  357. };
  358. [_object] execVM "\z\addons\dayz_server\compile\Server_DeleteObjInsafezone.sqf";
  359. };
  360.  
  361. //Monitor the object
  362. if(_type in DZE_Origins_Buildings) then {
  363. //diag_log format["Origins Object: %1 - %2", _type,_ownerID];
  364. _object setVariable ["CanBeUpdated",false, true];
  365.  
  366. {
  367. _object setVariable ["OwnerUID",(_x select 0), true];
  368. _object setVariable ["OwnerName",(_x select 1), true];
  369. } count _hitPoints;
  370. _ownerUID = _object getVariable ["OwnerUID","0"];
  371. switch(_type) do {
  372. case "Uroven1DrevenaBudka" : { owner_B1 set [count owner_B1, _ownerUID];};
  373. case "Uroven2KladaDomek" : { owner_B2 set [count owner_B2, _ownerUID];};
  374. case "Uroven3DrevenyDomek" : { owner_B3 set [count owner_B3, _ownerUID];};
  375. case "Uroven1VelkaBudka" : { owner_H1 set [count owner_H1, _ownerUID];};
  376. case "Uroven2MalyDomek" : { owner_H2 set [count owner_H2, _ownerUID];};
  377. case "Uroven3VelkyDomek" : { owner_H3 set [count owner_H3, _ownerUID];};
  378. case "malaGaraz" : { owner_SG set [count owner_SG, _ownerUID];};
  379. case "velkaGaraz" : { owner_LG set [count owner_LG, _ownerUID];};
  380. case "kingramida" : { owner_KING set [count owner_KING, _ownerUID];};
  381. case "krepost" : { owner_SH set [count owner_SH, _ownerUID];};
  382. };
  383. if((_pos select 2) < 0.25) then {
  384. _object setVectorUp surfaceNormal position _object;
  385. };
  386. _object setVectorUp surfaceNormal position _object;
  387. };
  388. PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_object];
  389. };
  390. } count (_BuildingQueue + _originsQueue + _objectQueue);
  391. // # END SPAWN OBJECTS #
  392.  
  393. // preload server traders menu data into cache
  394. if !(DZE_ConfigTrader) then {
  395. {
  396. // get tids
  397. _traderData = call compile format["menu_%1;",_x];
  398. if(!isNil "_traderData") then {
  399. {
  400. _traderid = _x select 1;
  401.  
  402. _retrader = [];
  403.  
  404. _key = format["CHILD:399:%1:",_traderid];
  405. _data = "HiveEXT" callExtension _key;
  406.  
  407. //diag_log "HIVE: Request sent";
  408.  
  409. //Process result
  410. _result = call compile format ["%1",_data];
  411. _status = _result select 0;
  412.  
  413. if (_status == "ObjectStreamStart") then {
  414. _val = _result select 1;
  415. //Stream Objects
  416. //diag_log ("HIVE: Commence Menu Streaming...");
  417. call compile format["ServerTcache_%1 = [];",_traderid];
  418. for "_i" from 1 to _val do {
  419. _data = "HiveEXT" callExtension _key;
  420. _result = call compile format ["%1",_data];
  421. call compile format["ServerTcache_%1 set [count ServerTcache_%1,%2]",_traderid,_result];
  422. _retrader set [count _retrader,_result];
  423. };
  424. //diag_log ("HIVE: Streamed " + str(_val) + " objects");
  425. };
  426.  
  427. } forEach (_traderData select 0);
  428. };
  429. } forEach serverTraders;
  430. };
  431.  
  432. if (_hiveLoaded) then {
  433. // spawn_vehicles
  434. _vehLimit = MaxVehicleLimit - _totalvehicles;
  435. if(_vehLimit > 0) then {
  436. diag_log ("HIVE: Spawning # of Vehicles: " + str(_vehLimit));
  437. for "_x" from 1 to _vehLimit do {
  438. [] spawn spawn_vehicles;
  439. };
  440. } else {
  441. diag_log "HIVE: Vehicle Spawn limit reached!";
  442. };
  443. };
  444.  
  445. // spawn_roadblocks
  446. diag_log ("HIVE: Spawning # of Debris: " + str(MaxDynamicDebris));
  447. for "_x" from 1 to MaxDynamicDebris do {
  448. [] spawn spawn_roadblocks;
  449. };
  450. // spawn_ammosupply at server start 1% of roadblocks
  451. diag_log ("HIVE: Spawning # of Ammo Boxes: " + str(MaxAmmoBoxes));
  452. for "_x" from 1 to MaxAmmoBoxes do {
  453. [] spawn spawn_ammosupply;
  454. };
  455. // call spawning mining veins
  456. diag_log ("HIVE: Spawning # of Veins: " + str(MaxMineVeins));
  457. for "_x" from 1 to MaxMineVeins do {
  458. [] spawn spawn_mineveins;
  459. };
  460.  
  461. if(isnil "dayz_MapArea") then {
  462. dayz_MapArea = 10000;
  463. };
  464. if(isnil "HeliCrashArea") then {
  465. HeliCrashArea = dayz_MapArea / 2;
  466. };
  467. if(isnil "OldHeliCrash") then {
  468. OldHeliCrash = false;
  469. };
  470.  
  471. [] ExecVM "\z\addons\dayz_server\custom\box.sqf";
  472.  
  473. // [_guaranteedLoot, _randomizedLoot, _frequency, _variance, _spawnChance, _spawnMarker, _spawnRadius, _spawnFire, _fadeFire]
  474. if(OldHeliCrash) then {
  475. _nul = [3, 4, (50 * 60), (15 * 60), 0.75, 'center', HeliCrashArea, true, false] spawn server_spawnCrashSite;
  476. };
  477. if (isDedicated) then {
  478. // Epoch Events
  479. _id = [] spawn server_spawnEvents;
  480. // server cleanup
  481. [] spawn {
  482. private ["_id"];
  483. sleep 200; //Sleep Lootcleanup, don't need directly cleanup on startup + fix some performance issues on serverstart
  484. waitUntil {!isNil "server_spawnCleanAnimals"};
  485. _id = [] execFSM "\z\addons\dayz_server\system\server_cleanup.fsm";
  486. };
  487.  
  488. // spawn debug box
  489. _debugMarkerPosition = getMarkerPos "respawn_west";
  490. _debugMarkerPosition = [(_debugMarkerPosition select 0),(_debugMarkerPosition select 1),1];
  491. _vehicle_0 = createVehicle ["DebugBox_DZ", _debugMarkerPosition, [], 0, "CAN_COLLIDE"];
  492. _vehicle_0 setPos _debugMarkerPosition;
  493. _vehicle_0 setVariable ["ObjectID","1",true];
  494.  
  495. // max number of spawn markers
  496. if(isnil "spawnMarkerCount") then {
  497. spawnMarkerCount = 10;
  498. };
  499. actualSpawnMarkerCount = 0;
  500. // count valid spawn marker positions
  501. for "_i" from 0 to spawnMarkerCount do {
  502. if (!([(getMarkerPos format["spawn%1", _i]), [0,0,0]] call BIS_fnc_areEqual)) then {
  503. actualSpawnMarkerCount = actualSpawnMarkerCount + 1;
  504. } else {
  505. // exit since we did not find any further markers
  506. _i = spawnMarkerCount + 99;
  507. };
  508.  
  509. };
  510. diag_log format["Total Number of spawn locations %1", actualSpawnMarkerCount];
  511.  
  512. endLoadingScreen;
  513. };
  514.  
  515. [] ExecVM "\z\addons\dayz_server\WAI\init.sqf";
  516. [] ExecVM "\z\addons\dayz_server\DZMS\DZMSInit.sqf";
  517. [] ExecVM "\z\addons\dayz_server\origins\variables.sqf";
  518. allowConnection = true;
  519. sm_done = true;
  520. publicVariable "sm_done";
  521. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement