Advertisement
meanbeandk

server_monitor.sqf

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