isoju

server_monitor2

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