Advertisement
Guest User

server_monitor.sqf

a guest
Aug 10th, 2014
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.99 KB | None | 0 0
  1. private ["_date","_year","_month","_day","_hour","_minute","_date1","_hiveResponse","_key","_objectCount","_dir","_point","_i","_action","_dam","_selection","_wantExplosiveParts","_entity","_worldspace","_damage","_booleans","_rawData","_ObjectID","_class","_CharacterID","_inventory","_hitpoints","_fuel","_id","_objectArray","_script","_result","_outcome"];
  2. []execVM "\z\addons\dayz_server\system\s_fps.sqf"; //server monitor FPS (writes each ~181s diag_fps+181s diag_fpsmin*)
  3. #include "\z\addons\dayz_server\compile\server_toggle_debug.hpp"
  4.  
  5. dayz_versionNo = getText(configFile >> "CfgMods" >> "DayZ" >> "version");
  6. dayz_hiveVersionNo = getNumber(configFile >> "CfgMods" >> "DayZ" >> "hiveVersion");
  7. dayzNam_versionNo = getText(configFile >> "CfgMods" >> "nc_dzn" >> "version");
  8. _script = getText(missionConfigFile >> "onPauseScript");
  9.  
  10. if ((count playableUnits == 0) and !isDedicated) then {
  11. isSinglePlayer = true;
  12. };
  13.  
  14. waitUntil{initialized}; //means all the functions are now defined
  15.  
  16. diag_log "HIVE: Starting";
  17.  
  18. //Set the Time
  19. //Send request
  20. _key = "CHILD:307:";
  21. _result = _key call server_hiveReadWrite;
  22. _outcome = _result select 0;
  23. if(_outcome == "PASS") then {
  24. _date = _result select 1;
  25.  
  26. //date setup
  27. _year = _date select 0;
  28. _month = _date select 1;
  29. _day = _date select 2;
  30. _hour = _date select 3;
  31. _minute = _date select 4;
  32.  
  33. //Force full moon nights
  34. _date1 = [2013,8,3,_hour,_minute];
  35.  
  36. if(isDedicated) then {
  37. //["dayzSetDate",_date] call broadcastRpcCallAll;
  38. setDate _date1;
  39. dayzSetDate = _date1;
  40. dayz_storeTimeDate = _date1;
  41. publicVariable "dayzSetDate";
  42. };
  43. diag_log ("HIVE: Local Time set to " + str(_date1));
  44. };
  45.  
  46. waituntil{isNil "sm_done"}; // prevent server_monitor be called twice (bug during login of the first player)
  47.  
  48. #include "\z\addons\dayz_server\compile\fa_hiveMaintenance.hpp"
  49.  
  50. if (isServer and isNil "sm_done") then {
  51. private ["_key","_data","_result","_status","_buildingArray","_bldCount","_val","_countr","_idKey","_type","_ownerID","_worldspace","_dir","_wsDone","_inventory","_hitPoints","_squadID","_combination","_damage","_object","_classname","_i","_requirements","_isDestructable","_objWpnTypes","_objWpnQty","_isOK","_block","_hiveResponse","_objectArray","_objectCount"];
  52.  
  53.  
  54. for "_i" from 1 to 5 do {
  55. diag_log "HIVE: trying to get objects";
  56. _key = format["CHILD:302:%1:", dayZ_instance];
  57. _hiveResponse = _key call server_hiveReadWrite;
  58. if ((((isnil "_hiveResponse") || {(typeName _hiveResponse != "ARRAY")}) || {((typeName (_hiveResponse select 1)) != "SCALAR")}) || {(_hiveResponse select 1 > 2000)}) then {
  59. if (!isNil "_hiveResponse") then {
  60. diag_log ("HIVE: connection problem... HiveExt response:"+str(_hiveResponse));
  61. } else {
  62. diag_log ("HIVE: connection problem... HiveExt NIL response:");
  63. };
  64. _hiveResponse = ["",0];
  65. } else {
  66. diag_log ("HIVE: found "+str(_hiveResponse select 1)+" objects" );
  67. _i = 99; // break
  68. };
  69. };
  70.  
  71. _objectArray = [];
  72. if ((_hiveResponse select 0) == "ObjectStreamStart") then {
  73. _objectCount = _hiveResponse select 1;
  74. diag_log ("HIVE: Commence Object Streaming...");
  75. for "_i" from 1 to _objectCount do {
  76. _hiveResponse = _key call server_hiveReadWrite;
  77. _objectArray set [_i - 1, _hiveResponse];
  78. //diag_log (format["HIVE dbg %1 %2", typeName _hiveResponse, _hiveResponse]);
  79. };
  80. diag_log ("HIVE: got " + str(count _objectArray) + " objects");
  81. #ifdef EMPTY_TENTS_CHECK
  82. // check empty tents, remove some of them
  83. [_objectArray, EMPTY_TENTS_GLOBAL_LIMIT, EMPTY_TENTS_USER_LIMIT] call fa_removeExtraTents;
  84. #endif
  85. // check vehicles count
  86. [_objectArray] call fa_checkVehicles;
  87. };
  88.  
  89. {
  90.  
  91. _action = _x select 0; // values : "OBJ"=object got from hive "CREATED"=vehicle just created ...
  92. _ObjectID = _x select 1;
  93. _class = if ((typeName (_x select 2)) == "STRING") then { _x select 2 } else { "Old_bike_TK_CIV_EP1" };
  94. _CharacterID = _x select 3;
  95. _worldspace = if ((typeName (_x select 4)) == "ARRAY") then { _x select 4 } else { [] };
  96. _inventory= if ((typeName (_x select 5)) == "ARRAY") then { _x select 5 } else { [] };
  97. _hitpoints= if ((typeName (_x select 6)) == "ARRAY") then { _x select 6 } else { [] };
  98. _fuel = if ((typeName (_x select 7)) == "SCALAR") then { _x select 7 } else { 0 };
  99. _damage = if ((typeName (_x select 8)) == "SCALAR") then { _x select 8 } else { 0.9 };
  100. _entity = nil;
  101.  
  102. _dir = floor(random(360));
  103. _point = getMarkerpos "respawn_west";
  104. if (count _worldspace >= 1 && {(typeName (_worldspace select 0)) == "SCALAR"}) then {
  105. _dir = _worldspace select 0;
  106. };
  107. if (count _worldspace == 2 && {(typeName (_worldspace select 1)) == "ARRAY"}) then {
  108. _i = _worldspace select 1;
  109. if (count _i == 3 &&
  110. {(typeName (_i select 0)) == "SCALAR"} &&
  111. {(typeName (_i select 1)) == "SCALAR"} &&
  112. {(typeName (_i select 2)) == "SCALAR"}) then {
  113. _point = _i;
  114. };
  115. };
  116.  
  117. // if legit vehicle
  118. if ((_class isKindOf "AllVehicles") && ((_CharacterID == "0") OR (_CharacterID == "1")) && (_damage < 1)) then {
  119. //_damage=0.86;//_action="CREATED";
  120. _point set [2, 0]; // here _point is in ATL format
  121. // check for no collision with world. Find a suitable place (depending of defined parameters)
  122. _worldspace = [_class, _dir, _point, _action] call fa_smartlocation;
  123. if (count _worldspace < 2) then { // safe position NOT found
  124. _action = "FAILED"; // don't worry, maybe we will find a nice spot next time :)
  125. }
  126. else { // found a spot for respawn
  127. if ((([_worldspace select 1, _point] call BIS_fnc_distance2D) > 1)
  128. AND (_action == "OBJ")) then { _action = "MOVED"; };
  129. _dir = _worldspace select 0;
  130. _point = _worldspace select 1;
  131. _entity = createVehicle [_class, _point, [], 0,
  132. if ((_class isKindOf "Air") OR {(_action != "OBJ")}) then {"NONE"} else {"CAN_COLLIDE"}
  133. ];
  134. _entity setVariable ["ObjectID", _ObjectID, true]; // this variable must be set very early
  135. _entity setVariable ["CharacterID", _CharacterID, true];
  136. _entity setVariable ["lastUpdate",time]; // prevent immediate hive write when vehicle parts are set up
  137. // setPos will be done again just after setDir, see below....
  138. _entity setDamage _damage;
  139. {
  140. _wantExplosiveParts = _x;
  141. {
  142. _selection = _x select 0;
  143. _dam = _x select 1;
  144. if (_selection in dayZ_explosiveParts) then {
  145. if (_wantExplosiveParts) then {
  146. if (_dam > 0.8) then { _dam = 0.8; };
  147. [_entity, _selection, _dam] call fnc_veh_handleDam;
  148. };
  149. }
  150. else {
  151. if (!_wantExplosiveParts) then {
  152. [_entity, _selection, _dam] call fnc_veh_handleDam;
  153. };
  154. };
  155. } forEach _hitpoints;
  156. } forEach [false, true]; // we set non explosive part first, then explosive parts
  157. _entity setvelocity [0,0,1];
  158. _entity setFuel _fuel;
  159. _entity call fnc_veh_ResetEH;
  160. };
  161. //Limit ammo of UH1Y
  162. if (_entity isKindOf "UH1Y_DZ") then {
  163. _entity setVehicleAmmo 1;
  164. };
  165.  
  166. //Limit Ammo of ArmoredSUV_PMC
  167. if (_entity isKindOf "ArmoredSUV_PMC") then {
  168. _entity setVehicleAmmo 1;
  169. };
  170.  
  171. //Limit Ammo of GPK
  172. if (_entity isKindOf "HMMWV_M1151_M2_DES_EP1") then {
  173. _entity setVehicleAmmo 1;
  174. };
  175.  
  176. //Limit Ammo of UH60M_DZ
  177. if (_entity isKindOf "UH60M_DZ") then {
  178. _entity setVehicleAmmo 1;
  179. };
  180.  
  181. //Limit Ammo of Camel_DZ
  182. if (_entity isKindOf "Camel_DZ") then {
  183. _entity setVehicleAmmo 1;
  184. };
  185.  
  186. if (_entity isKindOf "AN2_DZ") then {
  187. _entity addWeapon "DSHKM";
  188. _entity addMagazine "50Rnd_127x107_DSHKM";
  189. _entity addMagazine "50Rnd_127x107_DSHKM";
  190. };
  191.  
  192. if (_entity isKindOf "MH6J_DZ") then {
  193. _entity addWeapon "DSHKM";
  194. _entity addMagazine "50Rnd_127x107_DSHKM";
  195. _entity addMagazine "50Rnd_127x107_DSHKM";
  196. _entity addMagazine "50Rnd_127x107_DSHKM";
  197. _entity addMagazine "50Rnd_127x107_DSHKM";
  198. _entity addMagazine "50Rnd_127x107_DSHKM";
  199. _entity addMagazine "50Rnd_127x107_DSHKM";
  200. };
  201.  
  202. if (_entity isKindOf "AH6X_DZ") then {
  203. _entity addWeapon "DSHKM";
  204. _entity addMagazine "50Rnd_127x107_DSHKM";
  205. _entity addMagazine "50Rnd_127x107_DSHKM";
  206. _entity addMagazine "50Rnd_127x107_DSHKM";
  207. _entity addMagazine "50Rnd_127x107_DSHKM";
  208. _entity addMagazine "50Rnd_127x107_DSHKM";
  209. _entity addMagazine "50Rnd_127x107_DSHKM";
  210. };
  211.  
  212. if (_entity isKindOf "MH6J_EP1") then {
  213. _entity addWeapon "DSHKM";
  214. _entity addMagazine "50Rnd_127x107_DSHKM";
  215. _entity addMagazine "50Rnd_127x107_DSHKM";
  216. _entity addMagazine "50Rnd_127x107_DSHKM";
  217. _entity addMagazine "50Rnd_127x107_DSHKM";
  218. _entity addMagazine "50Rnd_127x107_DSHKM";
  219. _entity addMagazine "50Rnd_127x107_DSHKM";
  220. };
  221.  
  222. if (_entity isKindOf "AH6X_EP1") then {
  223. _entity addWeapon "DSHKM";
  224. _entity addMagazine "50Rnd_127x107_DSHKM";
  225. _entity addMagazine "50Rnd_127x107_DSHKM";
  226. _entity addMagazine "50Rnd_127x107_DSHKM";
  227. _entity addMagazine "50Rnd_127x107_DSHKM";
  228. _entity addMagazine "50Rnd_127x107_DSHKM";
  229. _entity addMagazine "50Rnd_127x107_DSHKM";
  230. };
  231. #ifdef OBJECT_DEBUG
  232. diag_log (format["VEHICLE %1 %2 at %3, original damage=%4, effective damage=%6, fuel=%5",
  233. _action, _entity call fa_veh2str, (getPosASL _entity) call fa_coor2str, _damage, _fuel, damage _entity]); // , hitpoints:%6, inventory=%7" , _hitpoints, _inventory
  234. #endif
  235. }
  236. else { // else for object or non legit vehicle
  237. if (!(_class in SafeObjects )) then {
  238. _damage = 1;
  239. };
  240. if (_damage < 1) then {
  241. // Rule #1: Tents will be always spawned if non empty.
  242. // Rule #2: Objects are not spawned if inside/close to building.
  243. // Rule #3: Rule #1 is higher priority
  244. _booleans=[];
  245. _worldspace = [_class, _point, _booleans] call fn_niceSpot;
  246. if (_booleans select 3) then { // is in building
  247. if ((_class != "TentStorage") OR {(_inventory call fa_tentEmpty)}) then {
  248. _action = "FAILED";
  249. _damage = 5;
  250. #ifdef OBJECT_DEBUG
  251. diag_log(format["Won't spawn object #%1(%4) in/close to a building, _point:%3, inventory: %5 booleans:%2",_ObjectID, _booleans, _point, _class, _inventory]);
  252. #endif
  253. };
  254. };
  255. };
  256. if (_damage < 1) then {
  257. //diag_log format["OBJ: %1 - %2,%3,%4,%5,%6,%7,%8", _idKey,_type,_ownerID,_worldspace,_inventory,_hitPoints,_fuel,_damage];
  258.  
  259. dayz_nonCollide = ["DomeTentStorage","TentStorage","CamoNet_DZ"];
  260.  
  261. //Create it
  262. _object = createVehicle [_type, _pos, [], 0, if (_type in dayz_nonCollide) then {"NONE"} else {"CAN_COLLIDE"}];
  263. _object setVariable ["lastUpdate",time];
  264. // Don't set objects for deployables to ensure proper inventory updates
  265. if (_ownerID == "0") then {
  266. _object setVariable ["ObjectID", str(_idKey), true];
  267. } else {
  268. _object setVariable ["ObjectUID", _worldspace call dayz_objectUID2, true];
  269. };
  270. _object setVariable ["CharacterID", _ownerID, true];
  271.  
  272. _object setdir _dir;
  273. _object setDamage _damage;
  274. //diag_log ("DW_DEBUG " + _class + " #" + str(_ObjectID) + " pos=" + (_point call fa_coor2str) + ", damage=" + str(_damage) );
  275. }
  276. else { // delete object -- this has been comented out: object are never really deleted from hive
  277. /* _key = format["CHILD:306:%1:%2:%3:", _ObjectID, [], 1];
  278. _rawData = "HiveEXT" callExtension _key;
  279. _key = format["CHILD:304:%1:",_ObjectID]; // delete by ID (not UID which is handler 310)
  280. _rawData = "HiveEXT" callExtension _key;*/
  281. #ifdef OBJECT_DEBUG
  282. diag_log (format["IGNORED %1 oid#%2 cid:%3 ",
  283. _class, _ObjectID, _CharacterID ]);
  284. #endif
  285. };
  286. };
  287. //diag_log(format["VEH MAINTENANCE DEBUG %1 %2", __FILE__, __LINE__]);
  288.  
  289. // common code (vehicle or not)
  290. if (_damage < 1 AND !(isNil ("_entity"))) then {
  291. _entity setdir _dir;
  292. _entity setPos _point;
  293.  
  294. if (_entity isKindOf "TrapItems") then {
  295. _entity setVariable ["armed", _inventory select 0, false];
  296. } else {
  297. [_entity, _inventory] call fa_populateCargo;
  298. };
  299.  
  300. dayz_serverObjectMonitor set [count dayz_serverObjectMonitor, _entity];
  301.  
  302. // UPDATE MODIFIED OBJECTS TO THE HIVE
  303. if (_action == "CREATED") then {
  304. // insert className damage characterId worldSpace inventory hitPoints fuel uniqueId
  305. _key = format["CHILD:308:%1:%2:%3:%4:%5:%6:%7:%8:%9:", dayZ_instance,
  306. _class, _damage , 1,
  307. [_dir, _point],
  308. [getWeaponCargo _entity, getMagazineCargo _entity ,getBackpackCargo _entity],
  309. _hitpoints, _fuel, _ObjectID
  310. ];
  311. //diag_log (_key);
  312. _rawData = "HiveEXT" callExtension _key;
  313. };
  314. if (_action == "SPAWNED" || _action == "DAMAGED") then {
  315. // update hitpoint,damage -- already done by needupdate
  316. /*_key = format["CHILD:306:%1:%2:%3:", _ObjectID, _hitpoints, _damage];
  317. _rawData = "HiveEXT" callExtension _key;*/
  318. };
  319. if (_action == "SPAWNED") then {
  320. // update inventory
  321. _key = format["CHILD:309:%1:%2:", _ObjectID,
  322. [getWeaponCargo _entity, getMagazineCargo _entity, getBackpackCargo _entity]];
  323. _rawData = "HiveEXT" callExtension _key;
  324. };
  325. if (_action == "MOVED" || _action == "SPAWNED") then {
  326. // update position,fuel in Hive
  327. // already done by server_updateObject?
  328. /*_key = format["CHILD:305:%1:%2:%3:", _ObjectID, [_dir, _point], _fuel];
  329. _rawData = "HiveEXT" callExtension _key;*/
  330. //Updated object position if moved
  331. [_entity, "position"] call server_updateObject;
  332. };
  333. }; // not damaged
  334. sleep 0.01; // yield to connecting players.
  335. } forEach _objectArray;
  336.  
  337. createCenter civilian;
  338. if (isDedicated) then {
  339. endLoadingScreen;
  340. };
  341.  
  342. //if (isDedicated) then {
  343. //_id = [] execFSM "\z\addons\dayz_server\system\server_cleanup.fsm";
  344. //};
  345.  
  346. [] ExecVM "\z\addons\dayz_server\DZMS\DZMSInit.sqf";
  347. allowConnection = true;
  348.  
  349. // [_guaranteedLoot, _randomizedLoot, spawnOnStart, _frequency, _variance, _spawnChance, _spawnMarker, _spawnRadius, _spawnFire, _fadeFire]
  350. [3, 4, 3, (40 * 60), (15 * 60), 0.75, 'center', 4000, true, false] spawn server_spawnCrashSite;
  351.  
  352. // antiwallhack
  353. call compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fa_antiwallhack.sqf";
  354.  
  355. //Spawn camps
  356. // quantity, marker, radius, min distance between 2 camps
  357. Server_InfectedCamps = [3, "center", 4500, 2000] call fn_bases;
  358. dayzInfectedCamps = Server_InfectedCamps;
  359. publicVariable "dayzInfectedCamps";
  360.  
  361. sm_done = true;
  362. publicVariable "sm_done";
  363.  
  364. [300] call server_plantSpawner;
  365.  
  366. //if (isDedicated) then {
  367. //Wild Zeds Ownership isnt working as expected yet
  368. // execFSM "\z\addons\dayz_server\system\zombie_wildagent.fsm";
  369. //};
  370. // Trap loop
  371. [] call {
  372. private ["_array","_array2","_array3","_script","_armed"];
  373. _array = str dayz_traps;
  374. _array2 = str dayz_traps_active;
  375. _array3 = str dayz_traps_trigger;
  376.  
  377. while { true } do {
  378. if ((str dayz_traps != _array) || (str dayz_traps_active != _array2) || (str dayz_traps_trigger != _array3)) then {
  379. _array = str dayz_traps;
  380. _array2 = str dayz_traps_active;
  381. _array3 = str dayz_traps_trigger;
  382.  
  383. diag_log "DEBUG: traps";
  384. diag_log format["dayz_traps (%2) -> %1", dayz_traps, count dayz_traps];
  385. diag_log format["dayz_traps_active (%2) -> %1", dayz_traps_active, count dayz_traps_active];
  386. diag_log format["dayz_traps_trigger (%2) -> %1", dayz_traps_trigger, count dayz_traps_trigger];
  387. diag_log "DEBUG: end traps";
  388. };
  389.  
  390. {
  391. if (isNull _x) then {
  392. dayz_traps = dayz_traps - [_x];
  393. };
  394.  
  395. _script = call compile getText (configFile >> "CfgVehicles" >> typeOf _x >> "script");
  396. _armed = _x getVariable ["armed", false];
  397.  
  398. if (_armed) then {
  399. if !(_x in dayz_traps_active) then {
  400. ["arm", _x] call _script;
  401. };
  402. } else {
  403. if (_x in dayz_traps_active) then {
  404. ["disarm", _x] call _script;
  405. };
  406. };
  407.  
  408. //sleep 0.01;
  409. } forEach dayz_traps;
  410. };
  411. };
  412. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement