Advertisement
Guest User

server_mon sqf

a guest
Mar 3rd, 2014
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.57 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. if (isNil "server_initCount") then {
  15. server_initCount = 1;
  16. } else {
  17. server_initCount = server_initCount + 1;
  18. };
  19. diag_log format["server_monitor.sqf execution count = %1", server_initCount];
  20.  
  21. // Custom Configs
  22. if(isnil "MaxVehicleLimit") then {
  23. MaxVehicleLimit = 50;
  24. };
  25.  
  26. if(isnil "MaxDynamicDebris") then {
  27. MaxDynamicDebris = 100;
  28. };
  29. if(isnil "MaxAmmoBoxes") then {
  30. MaxAmmoBoxes = 3;
  31. };
  32. if(isnil "MaxMineVeins") then {
  33. MaxMineVeins = 50;
  34. };
  35. // Custon Configs End
  36.  
  37. if (isServer and isNil "sm_done") then {
  38.  
  39. serverVehicleCounter = [];
  40. _hiveResponse = [];
  41.  
  42. for "_i" from 1 to 5 do {
  43. diag_log "HIVE: trying to get objects";
  44. _key = format["CHILD:302:%1:", dayZ_instance];
  45. _hiveResponse = _key call server_hiveReadWrite;
  46. if ((((isnil "_hiveResponse") || {(typeName _hiveResponse != "ARRAY")}) || {((typeName (_hiveResponse select 1)) != "SCALAR")})) then {
  47. if ((_hiveResponse select 1) == "Instance already initialized") then {
  48. _superkey = profileNamespace getVariable "SUPERKEY";
  49. _shutdown = format["CHILD:400:%1:", _superkey];
  50. _res = _shutdown call server_hiveReadWrite;
  51. diag_log ("HIVE: attempt to kill.. HiveExt response:"+str(_res));
  52. } else {
  53. diag_log ("HIVE: connection problem... HiveExt response:"+str(_hiveResponse));
  54.  
  55. };
  56. _hiveResponse = ["",0];
  57. }
  58. else {
  59. diag_log ("HIVE: found "+str(_hiveResponse select 1)+" objects" );
  60. _i = 99; // break
  61. };
  62. };
  63.  
  64. _BuildingQueue = [];
  65. _objectQueue = [];
  66.  
  67. if ((_hiveResponse select 0) == "ObjectStreamStart") then {
  68.  
  69. // save superkey
  70. profileNamespace setVariable ["SUPERKEY",(_hiveResponse select 2)];
  71. saveProfileNamespace;
  72.  
  73. _hiveLoaded = true;
  74.  
  75. diag_log ("HIVE: Commence Object Streaming...");
  76. _key = format["CHILD:302:%1:", dayZ_instance];
  77. _objectCount = _hiveResponse select 1;
  78. _bQty = 0;
  79. _vQty = 0;
  80. for "_i" from 1 to _objectCount do {
  81. _hiveResponse = _key call server_hiveReadWriteLarge;
  82. //diag_log (format["HIVE dbg %1 %2", typeName _hiveResponse, _hiveResponse]);
  83. if ((_hiveResponse select 2) isKindOf "ModularItems") then {
  84. _BuildingQueue set [_bQty,_hiveResponse];
  85. _bQty = _bQty + 1;
  86. } else {
  87. _objectQueue set [_vQty,_hiveResponse];
  88. _vQty = _vQty + 1;
  89. };
  90. };
  91. diag_log ("HIVE: got " + str(_bQty) + " Epoch Objects and " + str(_vQty) + " Vehicles");
  92. };
  93.  
  94. // # NOW SPAWN OBJECTS #
  95. _totalvehicles = 0;
  96. {
  97. _idKey = _x select 1;
  98. _type = _x select 2;
  99. _ownerID = _x select 3;
  100.  
  101. _worldspace = _x select 4;
  102. _intentory = _x select 5;
  103. _hitPoints = _x select 6;
  104. _fuel = _x select 7;
  105. _damage = _x select 8;
  106.  
  107. _dir = 0;
  108. _pos = [0,0,0];
  109. _wsDone = false;
  110. if (count _worldspace >= 2) then
  111. {
  112. _dir = _worldspace select 0;
  113. if (count (_worldspace select 1) == 3) then {
  114. _pos = _worldspace select 1;
  115. _wsDone = true;
  116. }
  117. };
  118.  
  119. if (!_wsDone) then {
  120. if (count _worldspace >= 1) then { _dir = _worldspace select 0; };
  121. _pos = [getMarkerPos "center",0,4000,10,0,2000,0] call BIS_fnc_findSafePos;
  122. if (count _pos < 3) then { _pos = [_pos select 0,_pos select 1,0]; };
  123. diag_log ("MOVED OBJ: " + str(_idKey) + " of class " + _type + " to pos: " + str(_pos));
  124. };
  125.  
  126.  
  127. if (_damage < 1) then {
  128. //diag_log format["OBJ: %1 - %2", _idKey,_type];
  129.  
  130. //Create it
  131. _object = createVehicle [_type, _pos, [], 0, "CAN_COLLIDE"];
  132. _object setVariable ["lastUpdate",time];
  133. _object setVariable ["ObjectID", _idKey, true];
  134.  
  135. _lockable = 0;
  136. if(isNumber (configFile >> "CfgVehicles" >> _type >> "lockable")) then {
  137. _lockable = getNumber(configFile >> "CfgVehicles" >> _type >> "lockable");
  138. };
  139.  
  140. // fix for leading zero issues on safe codes after restart
  141. if (_lockable == 4) then {
  142. _codeCount = (count (toArray _ownerID));
  143. if(_codeCount == 3) then {
  144. _ownerID = format["0%1", _ownerID];
  145. };
  146. if(_codeCount == 2) then {
  147. _ownerID = format["00%1", _ownerID];
  148. };
  149. if(_codeCount == 1) then {
  150. _ownerID = format["000%1", _ownerID];
  151. };
  152. };
  153.  
  154. if (_lockable == 3) then {
  155. _codeCount = (count (toArray _ownerID));
  156. if(_codeCount == 2) then {
  157. _ownerID = format["0%1", _ownerID];
  158. };
  159. if(_codeCount == 1) then {
  160. _ownerID = format["00%1", _ownerID];
  161. };
  162. };
  163.  
  164. _object setVariable ["CharacterID", _ownerID, true];
  165.  
  166. clearWeaponCargoGlobal _object;
  167. clearMagazineCargoGlobal _object;
  168. // _object setVehicleAmmo DZE_vehicleAmmo;
  169.  
  170. _object setdir _dir;
  171. _object setposATL _pos;
  172. _object setDamage _damage;
  173.  
  174. if ((typeOf _object) in dayz_allowedObjects) then {
  175. if (DZE_GodModeBase) then {
  176. _object addEventHandler ["HandleDamage", {false}];
  177. } else {
  178. _object addMPEventHandler ["MPKilled",{_this call object_handleServerKilled;}];
  179. };
  180. // Test disabling simulation server side on buildables only.
  181. _object enableSimulation false;
  182. // used for inplace upgrades and lock/unlock of safe
  183. _object setVariable ["OEMPos", _pos, true];
  184.  
  185. };
  186.  
  187. if (count _intentory > 0) then {
  188. if (_type in DZE_LockedStorage) then {
  189. // Fill variables with loot
  190. _object setVariable ["WeaponCargo", (_intentory select 0)];
  191. _object setVariable ["MagazineCargo", (_intentory select 1)];
  192. _object setVariable ["BackpackCargo", (_intentory select 2)];
  193. } else {
  194.  
  195. //Add weapons
  196. _objWpnTypes = (_intentory select 0) select 0;
  197. _objWpnQty = (_intentory select 0) select 1;
  198. _countr = 0;
  199. {
  200. if(_x in (DZE_REPLACE_WEAPONS select 0)) then {
  201. _x = (DZE_REPLACE_WEAPONS select 1) select ((DZE_REPLACE_WEAPONS select 0) find _x);
  202. };
  203. _isOK = isClass(configFile >> "CfgWeapons" >> _x);
  204. if (_isOK) then {
  205. _object addWeaponCargoGlobal [_x,(_objWpnQty select _countr)];
  206. };
  207. _countr = _countr + 1;
  208. } forEach _objWpnTypes;
  209.  
  210. //Add Magazines
  211. _objWpnTypes = (_intentory select 1) select 0;
  212. _objWpnQty = (_intentory select 1) select 1;
  213. _countr = 0;
  214. {
  215. if (_x == "BoltSteel") then { _x = "WoodenArrow" }; // Convert BoltSteel to WoodenArrow
  216. if (_x == "ItemTent") then { _x = "ItemTentOld" };
  217. _isOK = isClass(configFile >> "CfgMagazines" >> _x);
  218. if (_isOK) then {
  219. _object addMagazineCargoGlobal [_x,(_objWpnQty select _countr)];
  220. };
  221. _countr = _countr + 1;
  222. } forEach _objWpnTypes;
  223.  
  224. //Add Backpacks
  225. _objWpnTypes = (_intentory select 2) select 0;
  226. _objWpnQty = (_intentory select 2) select 1;
  227. _countr = 0;
  228. {
  229. _isOK = isClass(configFile >> "CfgVehicles" >> _x);
  230. if (_isOK) then {
  231. _object addBackpackCargoGlobal [_x,(_objWpnQty select _countr)];
  232. };
  233. _countr = _countr + 1;
  234. } forEach _objWpnTypes;
  235. };
  236. };
  237.  
  238. if (_object isKindOf "AllVehicles") then {
  239. {
  240. _selection = _x select 0;
  241. _dam = _x select 1;
  242. if (_selection in dayZ_explosiveParts and _dam > 0.8) then {_dam = 0.8};
  243. [_object,_selection,_dam] call object_setFixServer;
  244. } forEach _hitpoints;
  245.  
  246. _object setFuel _fuel;
  247.  
  248. if (!((typeOf _object) in dayz_allowedObjects)) then {
  249.  
  250. //_object setvelocity [0,0,1];
  251. _object call fnc_veh_ResetEH;
  252.  
  253. if(_ownerID != "0" and !(_object isKindOf "Bicycle")) then {
  254. _object setvehiclelock "locked";
  255. _object setVariable ["R3F_LOG_disabled",true,true];
  256. };
  257.  
  258. _totalvehicles = _totalvehicles + 1;
  259.  
  260. // total each vehicle
  261. serverVehicleCounter set [count serverVehicleCounter,_type];
  262. };
  263. };
  264.  
  265. //Monitor the object
  266. PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_object];
  267. };
  268. } forEach (_BuildingQueue + _objectQueue);
  269. // # END SPAWN OBJECTS #
  270.  
  271. // preload server traders menu data into cache
  272. if !(DZE_ConfigTrader) then {
  273. {
  274. // get tids
  275. _traderData = call compile format["menu_%1;",_x];
  276. if(!isNil "_traderData") then {
  277. {
  278. _traderid = _x select 1;
  279.  
  280. _retrader = [];
  281.  
  282. _key = format["CHILD:399:%1:",_traderid];
  283. _data = "HiveEXT" callExtension _key;
  284.  
  285. //diag_log "HIVE: Request sent";
  286.  
  287. //Process result
  288. _result = call compile format ["%1",_data];
  289. _status = _result select 0;
  290.  
  291. if (_status == "ObjectStreamStart") then {
  292. _val = _result select 1;
  293. //Stream Objects
  294. //diag_log ("HIVE: Commence Menu Streaming...");
  295. call compile format["ServerTcache_%1 = [];",_traderid];
  296. for "_i" from 1 to _val do {
  297. _data = "HiveEXT" callExtension _key;
  298. _result = call compile format ["%1",_data];
  299. call compile format["ServerTcache_%1 set [count ServerTcache_%1,%2]",_traderid,_result];
  300. _retrader set [count _retrader,_result];
  301. };
  302. //diag_log ("HIVE: Streamed " + str(_val) + " objects");
  303. };
  304.  
  305. } forEach (_traderData select 0);
  306. };
  307. } forEach serverTraders;
  308. };
  309.  
  310. if (_hiveLoaded) then {
  311. // spawn_vehicles
  312. _vehLimit = MaxVehicleLimit - _totalvehicles;
  313. if(_vehLimit > 0) then {
  314. diag_log ("HIVE: Spawning # of Vehicles: " + str(_vehLimit));
  315. for "_x" from 1 to _vehLimit do {
  316. [] spawn spawn_vehicles;
  317. };
  318. } else {
  319. diag_log "HIVE: Vehicle Spawn limit reached!";
  320. };
  321. };
  322.  
  323. // spawn_roadblocks
  324. diag_log ("HIVE: Spawning # of Debris: " + str(MaxDynamicDebris));
  325. for "_x" from 1 to MaxDynamicDebris do {
  326. [] spawn spawn_roadblocks;
  327. };
  328. // spawn_ammosupply at server start 1% of roadblocks
  329. diag_log ("HIVE: Spawning # of Ammo Boxes: " + str(MaxAmmoBoxes));
  330. for "_x" from 1 to MaxAmmoBoxes do {
  331. [] spawn spawn_ammosupply;
  332. };
  333. // call spawning mining veins
  334. diag_log ("HIVE: Spawning # of Veins: " + str(MaxMineVeins));
  335. for "_x" from 1 to MaxMineVeins do {
  336. [] spawn spawn_mineveins;
  337. };
  338.  
  339. if(isnil "dayz_MapArea") then {
  340. dayz_MapArea = 10000;
  341. };
  342. if(isnil "HeliCrashArea") then {
  343. HeliCrashArea = dayz_MapArea / 2;
  344. };
  345. if(isnil "OldHeliCrash") then {
  346. OldHeliCrash = false;
  347. };
  348.  
  349. // [_guaranteedLoot, _randomizedLoot, _frequency, _variance, _spawnChance, _spawnMarker, _spawnRadius, _spawnFire, _fadeFire]
  350. if(OldHeliCrash) then {
  351. _nul = [3, 4, (50 * 60), (15 * 60), 0.75, 'center', HeliCrashArea, true, false] spawn server_spawnCrashSite;
  352. };
  353. if (isDedicated) then {
  354. // Epoch Events
  355. _id = [] spawn server_spawnEvents;
  356. // server cleanup
  357. [] spawn {
  358. private ["_id"];
  359. sleep 200; //Sleep Lootcleanup, don't need directly cleanup on startup + fix some performance issues on serverstart
  360. waitUntil {!isNil "server_spawnCleanAnimals"};
  361. _id = [] execFSM "\z\addons\dayz_server\system\server_cleanup.fsm";
  362. };
  363.  
  364. // spawn debug box
  365. _debugMarkerPosition = getMarkerPos "respawn_west";
  366. _debugMarkerPosition = [(_debugMarkerPosition select 0),(_debugMarkerPosition select 1),1];
  367. _vehicle_0 = createVehicle ["DebugBox_DZ", _debugMarkerPosition, [], 0, "CAN_COLLIDE"];
  368. _vehicle_0 setPos _debugMarkerPosition;
  369. _vehicle_0 setVariable ["ObjectID","1",true];
  370.  
  371. // max number of spawn markers
  372. if(isnil "spawnMarkerCount") then {
  373. spawnMarkerCount = 10;
  374. };
  375. actualSpawnMarkerCount = 0;
  376. // count valid spawn marker positions
  377. for "_i" from 0 to spawnMarkerCount do {
  378. if (!([(getMarkerPos format["spawn%1", _i]), [0,0,0]] call BIS_fnc_areEqual)) then {
  379. actualSpawnMarkerCount = actualSpawnMarkerCount + 1;
  380. } else {
  381. // exit since we did not find any further markers
  382. _i = spawnMarkerCount + 99;
  383. };
  384.  
  385. };
  386. diag_log format["Total Number of spawn locations %1", actualSpawnMarkerCount];
  387.  
  388. endLoadingScreen;
  389. };
  390. [] ExecVM "\z\addons\dayz_server\DZMS\DZMSInit.sqf";
  391. allowConnection = true;
  392. sm_done = true;
  393. publicVariable "sm_done";
  394. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement