Advertisement
Guest User

Lockvault/Server_monitor

a guest
Nov 23rd, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.93 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. // Time sync
  15. if (isDedicated) then {
  16. _result = ["PASS",[2012,6,6,10,10]];
  17. _res = preprocessFile "\cache\set_time.sqf";
  18. if ((_res != "") and !(isNil "_res")) then {
  19. _result = call compile _res;
  20. };
  21. _outcome = _result select 0;
  22.  
  23. if (_outcome == "PASS") then {
  24. _date = _result select 1;
  25. setDate _date;
  26. PVDZE_plr_SetDate = _date;
  27. publicVariable "PVDZE_plr_SetDate";
  28. diag_log ("HIVE: Local Time set to " + str(_date));
  29. };
  30. };
  31.  
  32. // Custom Configs
  33. if(isnil "MaxVehicleLimit") then {
  34. MaxVehicleLimit = 50;
  35. };
  36.  
  37. if(isnil "MaxDynamicDebris") then {
  38. MaxDynamicDebris = 100;
  39. };
  40. if(isnil "MaxAmmoBoxes") then {
  41. MaxAmmoBoxes = 3;
  42. };
  43. if(isnil "MaxMineVeins") then {
  44. MaxMineVeins = 50;
  45. };
  46. // Custon Configs End
  47.  
  48. if (isServer && isNil "sm_done") then {
  49. serverVehicleCounter = [];
  50. diag_log ("LOAD OBJECTS");
  51.  
  52. _objectArray = [];
  53.  
  54. _res = preprocessFile "\cache\objects.sqf";
  55. if ((_res == "") or (isNil "_res")) then {
  56. diag_log ("OBJECTS NOT FOUND!");
  57. } else {
  58. _objectArray = call compile _res;
  59. };
  60. _res = nil;
  61. diag_log format["FOUND %1 OBJECTS", str(count _objectArray)];
  62.  
  63. _BuildingQueue = [];
  64. _objectQueue = [];
  65. _originsQueue = [];
  66. //Define arrays
  67. owner_B1 = [];
  68. owner_B2 = [];
  69. owner_B3 = [];
  70. owner_H1 = [];
  71. owner_H2 = [];
  72. owner_H3 = [];
  73. owner_SG = [];
  74. owner_LG = [];
  75. owner_KING = [];
  76. owner_SH = [];
  77. if ((_hiveResponse select 0) == "ObjectStreamStart") then {
  78.  
  79. // save superkey
  80. profileNamespace setVariable ["SUPERKEY",(_hiveResponse select 2)];
  81.  
  82. _hiveLoaded = true;
  83.  
  84. diag_log ("HIVE: Commence Object Streaming...");
  85. _key = format["CHILD:302:%1:", dayZ_instance];
  86. _objectCount = _hiveResponse select 1;
  87. _bQty = 0;
  88. _vQty = 0;
  89. _oQty = 0;
  90.  
  91. for "_i" from 1 to _objectCount do {
  92. _isOrigins = false;
  93. _hiveResponse = _key call server_hiveReadWriteLarge;
  94. //diag_log (format["HIVE dbg %1 %2", typeName _hiveResponse, _hiveResponse]);
  95. {
  96. if((_hiveResponse select 2) isKindOf _x) exitWith {
  97. _originsQueue set [_oQty,_hiveResponse];
  98. _oQty = _oQty + 1;
  99. _isOrigins = true;
  100. };
  101. } forEach DZE_Origins_Buildings;
  102. if(!_isOrigins) then {
  103. if ((_hiveResponse select 2) isKindOf "ModularItems") then {
  104. _BuildingQueue set [_bQty,_hiveResponse];
  105. _bQty = _bQty + 1;
  106. } else {
  107. _objectQueue set [_vQty,_hiveResponse];
  108. _vQty = _vQty + 1;
  109. };
  110. };
  111. };
  112. diag_log ("HIVE: got " + str(_bQty) + " Epoch Objects, " + str(_oQty) + " Origins Objects and " + str(_vQty) + " Vehicles");
  113. };
  114. // # NOW SPAWN OBJECTS #
  115. _totalvehicles = 0;
  116. PVDZE_EvacChopperFields = [];
  117. {
  118. _idKey = _x select 1;
  119. _type = _x select 2;
  120. _ownerID = _x select 3;
  121.  
  122. _worldspace = _x select 4;
  123. _intentory = _x select 5;
  124. _hitPoints = _x select 6;
  125. _fuel = _x select 7;
  126. _damage = _x select 8;
  127.  
  128. _dir = 0;
  129.  
  130.  
  131. _pos = [0,0,0];
  132. _wsDone = false;
  133. if (count _worldspace >= 2) then
  134. {
  135. if ((typeName (_worldspace select 0)) == "STRING") then {
  136. _worldspace set [0, call compile (_worldspace select 0)];
  137. _worldspace set [1, call compile (_worldspace select 1)];
  138. };
  139. _dir = _worldspace select 0;
  140. if (count (_worldspace select 1) == 3) then {
  141. _pos = _worldspace select 1;
  142. _wsDone = true;
  143. }
  144. };
  145.  
  146. if (!_wsDone) then {
  147. if (count _worldspace >= 1) then { _dir = _worldspace select 0; };
  148. _pos = [getMarkerPos "center",0,4000,10,0,2000,0] call BIS_fnc_findSafePos;
  149. if (count _pos < 3) then { _pos = [_pos select 0,_pos select 1,0]; };
  150. diag_log ("MOVED OBJ: " + str(_idKey) + " of class " + _type + " to pos: " + str(_pos));
  151. };
  152.  
  153. _vector = [[0,0,0],[0,0,0]];
  154. _vecExists = false;
  155. _ownerPUID = "0";
  156. if (count _worldspace >= 3) then{
  157. if(count _worldspace == 3) then{
  158. if(typename (_worldspace select 2) == "STRING")then{
  159. _ownerPUID = _worldspace select 2;
  160. }else{
  161. if(typename (_worldspace select 2) == "ARRAY")then{
  162. _vector = _worldspace select 2;
  163. if(count _vector == 2)then{
  164. if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  165. _vecExists = true;
  166. };
  167. };
  168. };
  169. };
  170.  
  171. }else{
  172. //Was not 3 elements, so check if 4 or more
  173. if(count _worldspace == 4) then{
  174. if(typename (_worldspace select 3) == "STRING")then{
  175. _ownerPUID = _worldspace select 3;
  176. }else{
  177. if(typename (_worldspace select 2) == "STRING")then{
  178. _ownerPUID = _worldspace select 2;
  179. };
  180. };
  181.  
  182.  
  183. if(typename (_worldspace select 2) == "ARRAY")then{
  184. _vector = _worldspace select 2;
  185. if(count _vector == 2)then{
  186. if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  187. _vecExists = true;
  188. };
  189. };
  190. }else{
  191. if(typename (_worldspace select 3) == "ARRAY")then{
  192. _vector = _worldspace select 3;
  193. if(count _vector == 2)then{
  194. if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  195. _vecExists = true;
  196. };
  197. };
  198. };
  199. };
  200.  
  201. }else{
  202. //More than 3 or 4 elements found
  203. //Might add a search for the vector, ownerPUID will equal 0
  204. };
  205. };
  206. };
  207.  
  208. // diag_log format["Server_monitor: [ObjectID = %1] [ClassID = %2] [_ownerPUID = %3]", _idKey, _type, _ownerPUID];
  209.  
  210. if (_damage < 1) then {
  211. //diag_log format["OBJ: %1 - %2", _idKey,_type];
  212.  
  213. //Create it
  214. _object = createVehicle [_type, _pos, [], 0, "CAN_COLLIDE"];
  215. _object setVariable ["lastUpdate",time];
  216. _object setVariable ["ObjectID", _idKey, true];
  217. _object setVariable ["OwnerPUID", _ownerPUID, true];
  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.  
  256. if(_vecExists)then{
  257. _object setVectorDirAndUp _vector;
  258. };
  259.  
  260. _object setposATL _pos;
  261. _object setDamage _damage;
  262.  
  263. if ((typeOf _object) == "HeliHRescue") then {
  264. PVDZE_EvacChopperFields set [count PVDZE_EvacChopperFields, _object];
  265. };
  266.  
  267. if ((typeOf _object) in dayz_allowedObjects) then {
  268. if (DZE_GodModeBase) then {
  269. _object addEventHandler ["HandleDamage", {false}];
  270. } else {
  271. _object addMPEventHandler ["MPKilled",{_this call object_handleServerKilled;}];
  272. };
  273. // Test disabling simulation server side on buildables only.
  274. _object enableSimulation false;
  275. // used for inplace upgrades && lock/unlock of safe
  276. _object setVariable ["OEMPos", _pos, true];
  277.  
  278. };
  279.  
  280. if (count _intentory > 0) then {
  281. if (_type in DZE_LockedStorage || _type in DZE_Origins_Buildings) then {
  282. // Fill variables with loot
  283. _object setVariable ["WeaponCargo", (_intentory select 0),true];
  284. _object setVariable ["MagazineCargo", (_intentory select 1),true];
  285. _object setVariable ["BackpackCargo", (_intentory select 2),true];
  286. } else {
  287.  
  288. //Add weapons
  289. _objWpnTypes = (_intentory select 0) select 0;
  290. _objWpnQty = (_intentory select 0) select 1;
  291. _countr = 0;
  292. {
  293. if(_x in (DZE_REPLACE_WEAPONS select 0)) then {
  294. _x = (DZE_REPLACE_WEAPONS select 1) select ((DZE_REPLACE_WEAPONS select 0) find _x);
  295. };
  296. _isOK = isClass(configFile >> "CfgWeapons" >> _x);
  297. if (_isOK) then {
  298. _object addWeaponCargoGlobal [_x,(_objWpnQty select _countr)];
  299. };
  300. _countr = _countr + 1;
  301. } count _objWpnTypes;
  302.  
  303. //Add Magazines
  304. _objWpnTypes = (_intentory select 1) select 0;
  305. _objWpnQty = (_intentory select 1) select 1;
  306. _countr = 0;
  307. {
  308. if (_x == "BoltSteel") then { _x = "WoodenArrow" }; // Convert BoltSteel to WoodenArrow
  309. if (_x == "ItemTent") then { _x = "ItemTentOld" };
  310. _isOK = isClass(configFile >> "CfgMagazines" >> _x);
  311. if (_isOK) then {
  312. _object addMagazineCargoGlobal [_x,(_objWpnQty select _countr)];
  313. };
  314. _countr = _countr + 1;
  315. } count _objWpnTypes;
  316.  
  317. //Add Backpacks
  318. _objWpnTypes = (_intentory select 2) select 0;
  319. _objWpnQty = (_intentory select 2) select 1;
  320. _countr = 0;
  321. {
  322. _isOK = isClass(configFile >> "CfgVehicles" >> _x);
  323. if (_isOK) then {
  324. _object addBackpackCargoGlobal [_x,(_objWpnQty select _countr)];
  325. };
  326. _countr = _countr + 1;
  327. } count _objWpnTypes;
  328. };
  329. };
  330.  
  331. if (_object isKindOf "AllVehicles") then {
  332. private ["_colour","_colour2","_clrinit","_clrinit2"];
  333. {
  334. _selection = _x select 0;
  335. _dam = _x select 1;
  336. if (_selection in dayZ_explosiveParts && _dam > 0.8) then {_dam = 0.8};
  337. [_object,_selection,_dam] call object_setFixServer;
  338. } count _hitpoints;
  339. if(count _worldspace >= 4) then{
  340. if (((typeName(_worldspace select 2)) == "STRING") and ((typeName(_worldspace select 3)) == "STRING")) then {
  341. _colour = _worldspace select 2;
  342. _colour2 = _worldspace select 3;
  343.  
  344. if (_colour != "0") then {
  345. _object setVariable ["Colour",_colour,true];
  346. _clrinit = format ["#(argb,8,8,3)color(%1)",_colour];
  347. _object setVehicleInit "this setObjectTexture [0,"+str _clrinit+"];";
  348. };
  349. if (_colour2 != "0") then {
  350. _object setVariable ["Colour2",_colour2,true];
  351. _clrinit2 = format ["#(argb,8,8,3)color(%1)",_colour2];
  352. _object setVehicleInit "this setObjectTexture [1,"+str _clrinit2+"];";
  353. };
  354. };
  355. };
  356.  
  357. _object setFuel _fuel;
  358.  
  359. if (!((typeOf _object) in dayz_allowedObjects)) then {
  360.  
  361. //_object setvelocity [0,0,1];
  362. _object call fnc_veh_ResetEH;
  363.  
  364. if(_ownerID != "0" && !(_object isKindOf "Bicycle")) then {
  365. _object setvehiclelock "locked";
  366. _object setVariable ["R3F_LOG_disabled",true,true];
  367. };
  368.  
  369. _totalvehicles = _totalvehicles + 1;
  370.  
  371. // total each vehicle
  372. serverVehicleCounter set [count serverVehicleCounter,_type];
  373. };
  374. };
  375. //Origins
  376. if(_type in DZE_Origins_Buildings) then {
  377. //diag_log format["Origins Object: %1 - %2", _type,_ownerID];
  378. _object setVariable ["CanBeUpdated",false, true];
  379. {
  380. _object setVariable ["OwnerUID",(_x select 0), true];
  381. _object setVariable ["OwnerName",(_x select 1), true];
  382. } count _hitPoints;
  383. _ownerUID = _object getVariable ["OwnerUID","0"];
  384. switch(_type) do {
  385. case "Uroven1DrevenaBudka" : { owner_B1 set [count owner_B1, _ownerUID];};
  386. case "Uroven2KladaDomek" : { owner_B2 set [count owner_B2, _ownerUID];};
  387. case "Uroven3DrevenyDomek" : { owner_B3 set [count owner_B3, _ownerUID];};
  388. case "Uroven1VelkaBudka" : { owner_H1 set [count owner_H1, _ownerUID];};
  389. case "Uroven2MalyDomek" : { owner_H2 set [count owner_H2, _ownerUID];};
  390. case "Uroven3VelkyDomek" : { owner_H3 set [count owner_H3, _ownerUID];};
  391. case "malaGaraz" : { owner_SG set [count owner_SG, _ownerUID];};
  392. case "velkaGaraz" : { owner_LG set [count owner_LG, _ownerUID];};
  393. case "kingramida" : { owner_KING set [count owner_KING, _ownerUID];};
  394. case "krepost" : { owner_SH set [count owner_SH, _ownerUID];};
  395. };
  396. if((_pos select 2) < 0.25) then {
  397. _object setVectorUp surfaceNormal position _object;
  398. };
  399. _object setVectorUp surfaceNormal position _object;
  400. };
  401. //Monitor the object
  402. PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_object];
  403. };
  404. } count (_BuildingQueue + _objectArray);
  405. // # END SPAWN OBJECTS #
  406.  
  407. // preload server traders menu data into cache
  408. if !(DZE_ConfigTrader) then {
  409. {
  410. // get tids
  411. _traderData = call compile format["menu_%1;",_x];
  412. if (!isNil "_traderData") then {
  413. {
  414. _traderid = _x select 1;
  415. //_key = format["CHILD:399:%1:",_traderid];
  416. _key = format["\cache\traders\%1.sqf", _traderid];
  417. diag_log ("LOAD TRADER: "+_key);
  418. _res = preprocessFile _key;
  419.  
  420. if ((_res == "") or (isNil "_res")) then {
  421. diag_log ("TRADER NOT FOUND");
  422. } else {
  423. call compile format["ServerTcache_%1 = [];", _traderid];
  424.  
  425. _retrader = call compile _res;
  426. diag_log format["Count: %1", str(count _retrader)];
  427.  
  428. {
  429. call compile format["ServerTcache_%1 set [count ServerTcache_%1,%2]", _traderid, _x];
  430. } forEach _retrader;
  431.  
  432. _retrader = nil;
  433. };
  434. _res = nil;
  435.  
  436. } forEach (_traderData select 0);
  437. };
  438. } forEach serverTraders;
  439. };
  440.  
  441. // spawn_vehicles
  442. _vehLimit = MaxVehicleLimit - _totalvehicles;
  443. if (_vehLimit > 0) then {
  444. diag_log ("HIVE: Spawning # of Vehicles: " + str(_vehLimit));
  445. for "_x" from 1 to _vehLimit do {
  446. [] spawn spawn_vehicles;
  447. };
  448. } else {
  449. diag_log "HIVE: Vehicle Spawn limit reached!";
  450. };
  451.  
  452. // spawn_roadblocks
  453. diag_log ("HIVE: Spawning # of Debris: " + str(MaxDynamicDebris));
  454. for "_x" from 1 to MaxDynamicDebris do {
  455. [] spawn spawn_roadblocks;
  456. };
  457. // spawn_ammosupply at server start 1% of roadblocks
  458. diag_log ("HIVE: Spawning # of Ammo Boxes: " + str(MaxAmmoBoxes));
  459. for "_x" from 1 to MaxAmmoBoxes do {
  460. [] spawn spawn_ammosupply;
  461. };
  462. // call spawning mining veins
  463. diag_log ("HIVE: Spawning # of Veins: " + str(MaxMineVeins));
  464. for "_x" from 1 to MaxMineVeins do {
  465. [] spawn spawn_mineveins;
  466. };
  467.  
  468. if(isnil "dayz_MapArea") then {
  469. dayz_MapArea = 10000;
  470. };
  471. if(isnil "HeliCrashArea") then {
  472. HeliCrashArea = dayz_MapArea / 2;
  473. };
  474. if(isnil "OldHeliCrash") then {
  475. OldHeliCrash = false;
  476. };
  477. [] ExecVM "\z\addons\dayz_server\custom\box.sqf";
  478. // [_guaranteedLoot, _randomizedLoot, _frequency, _variance, _spawnChance, _spawnMarker, _spawnRadius, _spawnFire, _fadeFire]
  479. if(OldHeliCrash) then {
  480. _nul = [3, 4, (50 * 60), (15 * 60), 0.75, 'center', HeliCrashArea, true, false] spawn server_spawnCrashSite;
  481. };
  482.  
  483. if (isDedicated) then {
  484. // Epoch Events
  485. _id = [] spawn server_spawnEvents;
  486. // server cleanup
  487. [] spawn {
  488. private ["_id"];
  489. sleep 200; //Sleep Lootcleanup, don't need directly cleanup on startup + fix some performance issues on serverstart
  490. waitUntil {!isNil "server_spawnCleanAnimals"};
  491. _id = [] execFSM "\z\addons\dayz_server\system\server_cleanup.fsm";
  492. };
  493.  
  494. // spawn debug box
  495. _debugMarkerPosition = getMarkerPos "respawn_west";
  496. _debugMarkerPosition = [(_debugMarkerPosition select 0),(_debugMarkerPosition select 1),1];
  497. _vehicle_0 = createVehicle ["DebugBox_DZ", _debugMarkerPosition, [], 0, "CAN_COLLIDE"];
  498. _vehicle_0 setPos _debugMarkerPosition;
  499. _vehicle_0 setVariable ["ObjectID","1",true];
  500.  
  501. // max number of spawn markers
  502. if(isnil "spawnMarkerCount") then {
  503. spawnMarkerCount = 10;
  504. };
  505. actualSpawnMarkerCount = 0;
  506. // count valid spawn marker positions
  507. for "_i" from 0 to spawnMarkerCount do {
  508. if (!([(getMarkerPos format["spawn%1", _i]), [0,0,0]] call BIS_fnc_areEqual)) then {
  509. actualSpawnMarkerCount = actualSpawnMarkerCount + 1;
  510. } else {
  511. // exit since we did not find any further markers
  512. _i = spawnMarkerCount + 99;
  513. };
  514.  
  515. };
  516. diag_log format["Total Number of spawn locations %1", actualSpawnMarkerCount];
  517.  
  518. endLoadingScreen;
  519. if (!isDedicated) then {
  520. //Conduct map operations
  521. 0 fadeSound 0;
  522. waitUntil {!isNil "dayz_loadScreenMsg"};
  523. dayz_loadScreenMsg = (localize "STR_AUTHENTICATING");
  524.  
  525. //Run the player monitor
  526. _id = player addEventHandler ["Respawn", {_id = [] spawn player_death;}];
  527. _playerMonitor = [] execVM "player_monitor.sqf";
  528.  
  529. //anti Hack
  530. [] execVM "\z\addons\dayz_code\system\antihack.sqf";
  531.  
  532. //Lights
  533. //[false,12] execVM "\z\addons\dayz_code\compile\local_lights_init.sqf";
  534.  
  535. };
  536. };
  537. [] ExecVM "\z\addons\dayz_server\origins\variables.sqf";
  538. ExecVM "\z\addons\dayz_server\WAI\init.sqf";
  539. allowConnection = true;
  540. sm_done = true;
  541. publicVariable "sm_done";
  542. };
  543. if (isServer && (isNil "EvacServerPreload")) then {
  544. publicVariable "PVDZE_EvacChopperFields";
  545.  
  546. ON_fnc_evacChopperFieldsUpdate = {
  547. private ["_action","_targetField"];
  548. _action = _this select 0;
  549. _targetField = _this select 1;
  550.  
  551. if (_action == "add") then {
  552. PVDZE_EvacChopperFields = PVDZE_EvacChopperFields + [_targetField];
  553. };
  554.  
  555. if (_action == "rem") then {
  556. PVDZE_EvacChopperFields = PVDZE_EvacChopperFields - [_targetField];
  557. };
  558.  
  559. publicVariable "PVDZE_EvacChopperFields";
  560. };
  561.  
  562. "PVDZE_EvacChopperFieldsUpdate" addPublicVariableEventHandler {(_this select 1) spawn ON_fnc_evacChopperFieldsUpdate};
  563.  
  564. EvacServerPreload = true;
  565. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement