Advertisement
ShadowStalker

server_monitor.sqf

Oct 1st, 2014
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.10 KB | None | 0 0
  1. private ["_nul","_result","_pos","_wsDone","_dir","_isOK","_countr","_objWpnTypes","_objWpnQty","_dam","_selection","_totalvehicles","_object","_idKey","_type","_ownerID","_worldspace","_intentory","_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"];
  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.  
  60. if ((_hiveResponse select 0) == "ObjectStreamStart") then {
  61.  
  62. // save superkey
  63. profileNamespace setVariable ["SUPERKEY",(_hiveResponse select 2)];
  64.  
  65. _hiveLoaded = true;
  66.  
  67. diag_log ("HIVE: Commence Object Streaming...");
  68. _key = format["CHILD:302:%1:", dayZ_instance];
  69. _objectCount = _hiveResponse select 1;
  70. _bQty = 0;
  71. _vQty = 0;
  72. for "_i" from 1 to _objectCount do {
  73. _hiveResponse = _key call server_hiveReadWriteLarge;
  74. //diag_log (format["HIVE dbg %1 %2", typeName _hiveResponse, _hiveResponse]);
  75. if ((_hiveResponse select 2) isKindOf "ModularItems") then {
  76. _BuildingQueue set [_bQty,_hiveResponse];
  77. _bQty = _bQty + 1;
  78. } else {
  79. _objectQueue set [_vQty,_hiveResponse];
  80. _vQty = _vQty + 1;
  81. };
  82. };
  83. diag_log ("HIVE: got " + str(_bQty) + " Epoch Objects and " + str(_vQty) + " Vehicles");
  84. };
  85.  
  86. // # NOW SPAWN OBJECTS #
  87. _totalvehicles = 0;
  88. {
  89. _idKey = _x select 1;
  90. _type = _x select 2;
  91. _ownerID = _x select 3;
  92.  
  93. _worldspace = _x select 4;
  94. _intentory = _x select 5;
  95. _hitPoints = _x select 6;
  96. _fuel = _x select 7;
  97. _damage = _x select 8;
  98.  
  99. _dir = 0;
  100.  
  101.  
  102. _pos = [0,0,0];
  103. _wsDone = false;
  104. if (count _worldspace >= 2) then
  105. {
  106. if ((typeName (_worldspace select 0)) == "STRING") then {
  107. _worldspace set [0, call compile (_worldspace select 0)];
  108. _worldspace set [1, call compile (_worldspace select 1)];
  109. };
  110. _dir = _worldspace select 0;
  111. if (count (_worldspace select 1) == 3) then {
  112. _pos = _worldspace select 1;
  113. _wsDone = true;
  114. }
  115. };
  116.  
  117. if (!_wsDone) then {
  118. if (count _worldspace >= 1) then { _dir = _worldspace select 0; };
  119. _pos = [getMarkerPos "center",0,4000,10,0,2000,0] call BIS_fnc_findSafePos;
  120. if (count _pos < 3) then { _pos = [_pos select 0,_pos select 1,0]; };
  121. diag_log ("MOVED OBJ: " + str(_idKey) + " of class " + _type + " to pos: " + str(_pos));
  122. };
  123.  
  124. _vector = [[0,0,0],[0,0,0]];
  125. _vecExists = false;
  126. _ownerPUID = "0";
  127. if (count _worldspace >= 3) then{
  128. if(count _worldspace == 3) then{
  129. if(typename (_worldspace select 2) == "STRING")then{
  130. _ownerPUID = _worldspace select 2;
  131. }else{
  132. if(typename (_worldspace select 2) == "ARRAY")then{
  133. _vector = _worldspace select 2;
  134. if(count _vector == 2)then{
  135. if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  136. _vecExists = true;
  137. };
  138. };
  139. };
  140. };
  141.  
  142. }else{
  143. //Was not 3 elements, so check if 4 or more
  144. if(count _worldspace == 4) then{
  145. if(typename (_worldspace select 3) == "STRING")then{
  146. _ownerPUID = _worldspace select 3;
  147. }else{
  148. if(typename (_worldspace select 2) == "STRING")then{
  149. _ownerPUID = _worldspace select 2;
  150. };
  151. };
  152.  
  153.  
  154. if(typename (_worldspace select 2) == "ARRAY")then{
  155. _vector = _worldspace select 2;
  156. if(count _vector == 2)then{
  157. if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  158. _vecExists = true;
  159. };
  160. };
  161. }else{
  162. if(typename (_worldspace select 3) == "ARRAY")then{
  163. _vector = _worldspace select 3;
  164. if(count _vector == 2)then{
  165. if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  166. _vecExists = true;
  167. };
  168. };
  169. };
  170. };
  171.  
  172. }else{
  173. //More than 3 or 4 elements found
  174. //Might add a search for the vector, ownerPUID will equal 0
  175. };
  176. };
  177. };
  178.  
  179. // diag_log format["Server_monitor: [ObjectID = %1] [ClassID = %2] [_ownerPUID = %3]", _idKey, _type, _ownerPUID];
  180.  
  181. if (_damage < 1) then {
  182. //diag_log format["OBJ: %1 - %2", _idKey,_type];
  183.  
  184. //Create it
  185. _object = createVehicle [_type, _pos, [], 0, "CAN_COLLIDE"];
  186. _object setVariable ["lastUpdate",time];
  187. _object setVariable ["ObjectID", _idKey, true];
  188. _object setVariable ["OwnerPUID", _ownerPUID, true];
  189.  
  190. _lockable = 0;
  191. if(isNumber (configFile >> "CfgVehicles" >> _type >> "lockable")) then {
  192. _lockable = getNumber(configFile >> "CfgVehicles" >> _type >> "lockable");
  193. };
  194.  
  195. // fix for leading zero issues on safe codes after restart
  196. if (_lockable == 4) then {
  197. _codeCount = (count (toArray _ownerID));
  198. if(_codeCount == 3) then {
  199. _ownerID = format["0%1", _ownerID];
  200. };
  201. if(_codeCount == 2) then {
  202. _ownerID = format["00%1", _ownerID];
  203. };
  204. if(_codeCount == 1) then {
  205. _ownerID = format["000%1", _ownerID];
  206. };
  207. };
  208.  
  209. if (_lockable == 3) then {
  210. _codeCount = (count (toArray _ownerID));
  211. if(_codeCount == 2) then {
  212. _ownerID = format["0%1", _ownerID];
  213. };
  214. if(_codeCount == 1) then {
  215. _ownerID = format["00%1", _ownerID];
  216. };
  217. };
  218.  
  219. _object setVariable ["CharacterID", _ownerID, true];
  220.  
  221. clearWeaponCargoGlobal _object;
  222. clearMagazineCargoGlobal _object;
  223. // _object setVehicleAmmo DZE_vehicleAmmo;
  224.  
  225. _object setdir _dir;
  226.  
  227. if(_vecExists)then{
  228. _object setVectorDirAndUp _vector;
  229. };
  230.  
  231. _object setposATL _pos;
  232. _object setDamage _damage;
  233.  
  234. if ((typeOf _object) in dayz_allowedObjects) then {
  235. if (DZE_GodModeBase) then {
  236. _object addEventHandler ["HandleDamage", {false}];
  237. } else {
  238. _object addMPEventHandler ["MPKilled",{_this call object_handleServerKilled;}];
  239. };
  240. // Test disabling simulation server side on buildables only.
  241. _object enableSimulation false;
  242. // used for inplace upgrades && lock/unlock of safe
  243. _object setVariable ["OEMPos", _pos, true];
  244.  
  245. };
  246.  
  247. if (count _intentory > 0) then {
  248. if (_type in DZE_LockedStorage) then {
  249. // Fill variables with loot
  250. _object setVariable ["WeaponCargo", (_intentory select 0),true];
  251. _object setVariable ["MagazineCargo", (_intentory select 1),true];
  252. _object setVariable ["BackpackCargo", (_intentory select 2),true];
  253. } else {
  254.  
  255. //Add weapons
  256. _objWpnTypes = (_intentory select 0) select 0;
  257. _objWpnQty = (_intentory select 0) select 1;
  258. _countr = 0;
  259. {
  260. if(_x in (DZE_REPLACE_WEAPONS select 0)) then {
  261. _x = (DZE_REPLACE_WEAPONS select 1) select ((DZE_REPLACE_WEAPONS select 0) find _x);
  262. };
  263. _isOK = isClass(configFile >> "CfgWeapons" >> _x);
  264. if (_isOK) then {
  265. _object addWeaponCargoGlobal [_x,(_objWpnQty select _countr)];
  266. };
  267. _countr = _countr + 1;
  268. } count _objWpnTypes;
  269.  
  270. //Add Magazines
  271. _objWpnTypes = (_intentory select 1) select 0;
  272. _objWpnQty = (_intentory select 1) select 1;
  273. _countr = 0;
  274. {
  275. if (_x == "BoltSteel") then { _x = "WoodenArrow" }; // Convert BoltSteel to WoodenArrow
  276. if (_x == "ItemTent") then { _x = "ItemTentOld" };
  277. _isOK = isClass(configFile >> "CfgMagazines" >> _x);
  278. if (_isOK) then {
  279. _object addMagazineCargoGlobal [_x,(_objWpnQty select _countr)];
  280. };
  281. _countr = _countr + 1;
  282. } count _objWpnTypes;
  283.  
  284. //Add Backpacks
  285. _objWpnTypes = (_intentory select 2) select 0;
  286. _objWpnQty = (_intentory select 2) select 1;
  287. _countr = 0;
  288. {
  289. _isOK = isClass(configFile >> "CfgVehicles" >> _x);
  290. if (_isOK) then {
  291. _object addBackpackCargoGlobal [_x,(_objWpnQty select _countr)];
  292. };
  293. _countr = _countr + 1;
  294. } count _objWpnTypes;
  295. };
  296. };
  297.  
  298. if (_object isKindOf "AllVehicles") then {
  299. private ["_colour","_colour2","_clrinit","_clrinit2"];
  300. {
  301. _selection = _x select 0;
  302. _dam = _x select 1;
  303. if (_selection in dayZ_explosiveParts && _dam > 0.8) then {_dam = 0.8};
  304. [_object,_selection,_dam] call object_setFixServer;
  305. } count _hitpoints;
  306.  
  307. if(count _worldspace >= 4) then{
  308. if (((typeName(_worldspace select 2)) == "STRING") and ((typeName(_worldspace select 3)) == "STRING")) then {
  309. _colour = _worldspace select 2;
  310. _colour2 = _worldspace select 3;
  311.  
  312. if (_colour != "0") then {
  313. _object setVariable ["Colour",_colour,true];
  314. _clrinit = format ["#(argb,8,8,3)color(%1)",_colour];
  315. _object setVehicleInit "this setObjectTexture [0,"+str _clrinit+"];";
  316. };
  317. if (_colour2 != "0") then {
  318. _object setVariable ["Colour2",_colour2,true];
  319. _clrinit2 = format ["#(argb,8,8,3)color(%1)",_colour2];
  320. _object setVehicleInit "this setObjectTexture [1,"+str _clrinit2+"];";
  321. };
  322. };
  323. };
  324.  
  325. _object setFuel _fuel;
  326.  
  327. if (!((typeOf _object) in dayz_allowedObjects)) then {
  328.  
  329. //_object setvelocity [0,0,1];
  330. _object call fnc_veh_ResetEH;
  331.  
  332. if(_ownerID != "0" && !(_object isKindOf "Bicycle")) then {
  333. _object setvehiclelock "locked";
  334. };
  335.  
  336. _totalvehicles = _totalvehicles + 1;
  337.  
  338. // total each vehicle
  339. serverVehicleCounter set [count serverVehicleCounter,_type];
  340. };
  341. };
  342.  
  343. //Monitor the object
  344. PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_object];
  345. };
  346. } count (_BuildingQueue + _objectQueue);
  347. // # END SPAWN OBJECTS #
  348.  
  349. // preload server traders menu data into cache
  350. if !(DZE_ConfigTrader) then {
  351. {
  352. // get tids
  353. _traderData = call compile format["menu_%1;",_x];
  354. if(!isNil "_traderData") then {
  355. {
  356. _traderid = _x select 1;
  357.  
  358. _retrader = [];
  359.  
  360. _key = format["CHILD:399:%1:",_traderid];
  361. _data = "HiveEXT" callExtension _key;
  362.  
  363. //diag_log "HIVE: Request sent";
  364.  
  365. //Process result
  366. _result = call compile format ["%1",_data];
  367. _status = _result select 0;
  368.  
  369. if (_status == "ObjectStreamStart") then {
  370. _val = _result select 1;
  371. //Stream Objects
  372. //diag_log ("HIVE: Commence Menu Streaming...");
  373. call compile format["ServerTcache_%1 = [];",_traderid];
  374. for "_i" from 1 to _val do {
  375. _data = "HiveEXT" callExtension _key;
  376. _result = call compile format ["%1",_data];
  377. call compile format["ServerTcache_%1 set [count ServerTcache_%1,%2]",_traderid,_result];
  378. _retrader set [count _retrader,_result];
  379. };
  380. //diag_log ("HIVE: Streamed " + str(_val) + " objects");
  381. };
  382.  
  383. } forEach (_traderData select 0);
  384. };
  385. } forEach serverTraders;
  386. };
  387.  
  388. if (_hiveLoaded) then {
  389. // spawn_vehicles
  390. _vehLimit = MaxVehicleLimit - _totalvehicles;
  391. if(_vehLimit > 0) then {
  392. diag_log ("HIVE: Spawning # of Vehicles: " + str(_vehLimit));
  393. for "_x" from 1 to _vehLimit do {
  394. [] spawn spawn_vehicles;
  395. };
  396. } else {
  397. diag_log "HIVE: Vehicle Spawn limit reached!";
  398. };
  399. };
  400.  
  401. // spawn_roadblocks
  402. diag_log ("HIVE: Spawning # of Debris: " + str(MaxDynamicDebris));
  403. for "_x" from 1 to MaxDynamicDebris do {
  404. [] spawn spawn_roadblocks;
  405. };
  406. // spawn_ammosupply at server start 1% of roadblocks
  407. diag_log ("HIVE: Spawning # of Ammo Boxes: " + str(MaxAmmoBoxes));
  408. for "_x" from 1 to MaxAmmoBoxes do {
  409. [] spawn spawn_ammosupply;
  410. };
  411. // call spawning mining veins
  412. diag_log ("HIVE: Spawning # of Veins: " + str(MaxMineVeins));
  413. for "_x" from 1 to MaxMineVeins do {
  414. [] spawn spawn_mineveins;
  415. };
  416.  
  417. if(isnil "dayz_MapArea") then {
  418. dayz_MapArea = 10000;
  419. };
  420. if(isnil "HeliCrashArea") then {
  421. HeliCrashArea = dayz_MapArea / 2;
  422. };
  423. if(isnil "OldHeliCrash") then {
  424. OldHeliCrash = false;
  425. };
  426.  
  427. // [_guaranteedLoot, _randomizedLoot, _frequency, _variance, _spawnChance, _spawnMarker, _spawnRadius, _spawnFire, _fadeFire]
  428. if(OldHeliCrash) then {
  429. _nul = [3, 4, (50 * 60), (15 * 60), 0.75, 'center', HeliCrashArea, true, false] spawn server_spawnCrashSite;
  430. };
  431. if (isDedicated) then {
  432. // Epoch Events
  433. _id = [] spawn server_spawnEvents;
  434. // server cleanup
  435. [] spawn {
  436. private ["_id"];
  437. sleep 200; //Sleep Lootcleanup, don't need directly cleanup on startup + fix some performance issues on serverstart
  438. waitUntil {!isNil "server_spawnCleanAnimals"};
  439. _id = [] execFSM "\z\addons\dayz_server\system\server_cleanup.fsm";
  440. };
  441.  
  442. // spawn debug box
  443. _debugMarkerPosition = getMarkerPos "respawn_west";
  444. _debugMarkerPosition = [(_debugMarkerPosition select 0),(_debugMarkerPosition select 1),1];
  445. _vehicle_0 = createVehicle ["DebugBox_DZ", _debugMarkerPosition, [], 0, "CAN_COLLIDE"];
  446. _vehicle_0 setPos _debugMarkerPosition;
  447. _vehicle_0 setVariable ["ObjectID","1",true];
  448.  
  449. // max number of spawn markers
  450. if(isnil "spawnMarkerCount") then {
  451. spawnMarkerCount = 10;
  452. };
  453. actualSpawnMarkerCount = 0;
  454. // count valid spawn marker positions
  455. for "_i" from 0 to spawnMarkerCount do {
  456. if (!([(getMarkerPos format["spawn%1", _i]), [0,0,0]] call BIS_fnc_areEqual)) then {
  457. actualSpawnMarkerCount = actualSpawnMarkerCount + 1;
  458. } else {
  459. // exit since we did not find any further markers
  460. _i = spawnMarkerCount + 99;
  461. };
  462.  
  463. };
  464. diag_log format["Total Number of spawn locations %1", actualSpawnMarkerCount];
  465.  
  466. endLoadingScreen;
  467. };
  468.  
  469. ExecVM "\z\addons\dayz_server\WAI\init.sqf";
  470. allowConnection = true;
  471. sm_done = true;
  472. publicVariable "sm_done";
  473. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement