Advertisement
Guest User

Untitled

a guest
May 26th, 2015
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.69 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. waitUntil{!isNil "BIS_MPF_InitDone"};
  6. waitUntil{initialized}; //means all the functions are now defined
  7. if (!isNil "sm_done") exitWith {}; // prevent server_monitor be called twice (bug during login of the first player)
  8. sm_done = false;
  9.  
  10. dayz_serverIDMonitor = [];
  11.  
  12. dayz_versionNo = getText(configFile >> "CfgMods" >> "DayZ" >> "version");
  13. dayz_hiveVersionNo = getNumber(configFile >> "CfgMods" >> "DayZ" >> "hiveVersion");
  14.  
  15.  
  16. diag_log "HIVE: Starting";
  17.  
  18. //Set the Time
  19. _key = "CHILD:307:";
  20. _result = _key call server_hiveReadWrite;
  21. _outcome = _result select 0;
  22. if(_outcome == "PASS") then {
  23. _date = _result select 1;
  24.  
  25. //date setup
  26. _year = _date select 0;
  27. _month = _date select 1;
  28. _day = _date select 2;
  29. _hour = _date select 3;
  30. _minute = _date select 4;
  31.  
  32. if(dayz_ForcefullmoonNights) then {
  33. _date = [2012,8,2,_hour,_minute];
  34. };
  35. diag_log [ "TIME SYNC: Local Time set to:", _date, "Fullmoon:",dayz_ForcefullmoonNights, "Date given by HiveExt.dll:", _result select 1];
  36. setDate _date;
  37. dayzSetDate = _date;
  38. publicVariable "dayzSetDate";
  39. };
  40.  
  41. //Stream in objects
  42. /* STREAM OBJECTS */
  43. //Send the key
  44. _key = format["CHILD:302:%1:",dayZ_instance];
  45. _result = _key call server_hiveReadWrite;
  46.  
  47. diag_log "HIVE: Request sent";
  48.  
  49. //Process result
  50. _status = _result select 0;
  51.  
  52. _myArray = [];
  53. if (_status == "ObjectStreamStart") then {
  54. _val = _result select 1;
  55. //Stream Objects
  56. diag_log ("HIVE: Commence Object Streaming...");
  57. for "_i" from 1 to _val do {
  58. _result = _key call server_hiveReadWrite;
  59.  
  60. _status = _result select 0;
  61. _myArray set [count _myArray,_result];
  62. //diag_log ("HIVE: Loop ");
  63. };
  64. diag_log ("HIVE: Streamed " + str(_val) + " objects");
  65. };
  66.  
  67. _countr = 0;
  68. {
  69.  
  70. //Parse Array
  71. _countr = _countr + 1;
  72.  
  73. _action = _x select 0;
  74. _idKey = _x select 1;
  75. _type = if ((typeName (_x select 2)) == "STRING") then { _x select 2 };
  76. _ownerID = _x select 3;
  77. _worldspace = if ((typeName (_x select 4)) == "ARRAY") then { _x select 4 } else { [] };
  78. _inventory = if ((typeName (_x select 5)) == "ARRAY") then { _x select 5 } else { [] };
  79. _hitPoints = if ((typeName (_x select 6)) == "ARRAY") then { _x select 6 } else { [] };
  80. _fuel = if ((typeName (_x select 7)) == "SCALAR") then { _x select 7 } else { 0 };
  81. _damage = if ((typeName (_x select 8)) == "SCALAR") then { _x select 8 } else { 0.9 };
  82.  
  83. _dir = floor(random(360));
  84. _pos = getMarkerpos "respawn_west";
  85. _wsDone = false;
  86.  
  87. if (count _worldspace >= 1 && {(typeName (_worldspace select 0)) == "SCALAR"}) then {
  88. _dir = _worldspace select 0;
  89. };
  90. if (count _worldspace == 2 && {(typeName (_worldspace select 1)) == "ARRAY"}) then {
  91. _i = _worldspace select 1;
  92. if (count _i == 3 &&
  93. {(typeName (_i select 0)) == "SCALAR"} &&
  94. {(typeName (_i select 1)) == "SCALAR"} &&
  95. {(typeName (_i select 2)) == "SCALAR"}) then {
  96. _pos = _i;
  97. _wsDone = true;
  98. };
  99. };
  100. if (!_wsDone) then {
  101. //_pos = [,0,30,10,0,2000,0] call BIS_fnc_findSafePos;
  102. if (count _pos < 3) then { _pos = [_worldspace select 0,_worldspace select 1,0]; };
  103. diag_log ("MOVED OBJ: " + str(_idKey) + " of class " + _type + " to pos: " + str(_pos));
  104. };
  105.  
  106. if (_damage < 1) then {
  107. //diag_log format["OBJ: %1 - %2,%3,%4,%5,%6,%7,%8", _idKey,_type,_ownerID,_worldspace,_inventory,_hitPoints,_fuel,_damage];
  108.  
  109. DayZ_nonCollide = ["TentStorage","TentStorage","TentStorage0","TentStorage1","TentStorage2","TentStorage3","TentStorage4","StashSmall","StashSmall1","StashSmall2","StashSmall3","StashSmall4","StashMedium","StashMedium1","StashMedium2","StashMedium3", "StashMedium4", "DomeTentStorage", "DomeTentStorage0", "DomeTentStorage1", "DomeTentStorage2", "DomeTentStorag3", "DomeTentStorage4", "CamoNet_DZ"];
  110.  
  111.  
  112. //Create it
  113. _object = createVehicle [_type, _pos, [], 0, if (_type in DayZ_nonCollide) then {"NONE"} else {"CAN_COLLIDE"}];
  114. _object setVariable ["lastUpdate",time];
  115. _object setVariable ["ObjectID", _idKey, true];
  116. dayz_serverIDMonitor set [count dayz_serverIDMonitor,_idKey];
  117. _object setVariable ["CharacterID", _ownerID, true];
  118.  
  119. _object setdir _dir;
  120. _object setDamage _damage;
  121.  
  122. if (!_wsDone) then {
  123. [_object,"position",true] call server_updateObject;
  124. };
  125.  
  126. //Dont add inventory for traps.
  127. if (!(_object isKindOf "TrapItems") And !(_object iskindof "DZ_buildables")) then {
  128. _cargo = _inventory;
  129. clearWeaponCargoGlobal _object;
  130. clearMagazineCargoGlobal _object;
  131. clearBackpackCargoGlobal _object;
  132. _config = ["CfgWeapons", "CfgMagazines", "CfgVehicles" ];
  133. {
  134. _magItemTypes = _x select 0;
  135. _magItemQtys = _x select 1;
  136. _i = _forEachIndex;
  137. {
  138. /*
  139. if (_x == "Crossbow") then { _x = "Crossbow_DZ" }; // Convert Crossbow to Crossbow_DZ
  140. if (_x == "BoltSteel") then { _x = "WoodenArrow" }; // Convert BoltSteel to WoodenArrow
  141. if (_x == "ItemBloodbag") then { _x = "bloodBagONEG" }; // Convert ItemBloodbag into universal blood type/rh bag
  142. // Convert to DayZ Weapons
  143. if (_x == "DMR") then { _x = "DMR_DZ" };
  144. //if (_x == "M14_EP1") then { _x = "M14_DZ" };
  145. if (_x == "SVD") then { _x = "SVD_DZ" };
  146. if (_x == "SVD_CAMO") then { _x = "SVD_CAMO_DZ" };
  147. */
  148. if ((isClass(configFile >> (_config select _i) >> _x)) &&
  149. {(getNumber(configFile >> (_config select _i) >> _x >> "stopThis") != 1)}) then {
  150. if (_forEachIndex < count _magItemQtys) then {
  151. switch (_i) do {
  152. case 0: { _object addWeaponCargoGlobal [_x,(_magItemQtys select _forEachIndex)]; };
  153. case 1: { _object addMagazineCargoGlobal [_x,(_magItemQtys select _forEachIndex)]; };
  154. case 2: { _object addBackpackCargoGlobal [_x,(_magItemQtys select _forEachIndex)]; };
  155. };
  156. };
  157. };
  158. } forEach _magItemTypes;
  159. } forEach _cargo;
  160. };
  161.  
  162. if (_object isKindOf "AllVehicles") then {
  163. {
  164. _selection = _x select 0;
  165. _dam = _x select 1;
  166. if ((_selection in dayZ_explosiveParts and _dam > 0.8) && (!(_object isKindOf "Air"))) then {_dam = 0.8};
  167.  
  168. [_object,_selection,_dam] call fnc_veh_setFixServer;
  169. } forEach _hitpoints;
  170.  
  171. _object setvelocity [0,0,1];
  172. _object setFuel _fuel;
  173. _object call fnc_veh_ResetEH;
  174. } else {
  175. if (_type in DayZ_nonCollide) then {
  176. _pos set [2,0];
  177. _object addMPEventHandler ["MPKilled",{_this call vehicle_handleServerKilled;}];
  178. };
  179. if (_pos select 2 == 0 or 0 == getNumber (configFile >> "CfgVehicles" >> _type >> "canbevertical")) then {
  180. _object setVectorUp surfaceNormal _pos;
  181. } else {
  182. _object setVectorUp [0,0,1];
  183. };
  184. _object setPosATL _pos;
  185. if (_object iskindof "DZ_buildables") then {
  186. _object addMPEventHandler ["MPKilled",{_this call vehicle_handleServerKilled;}];
  187. };
  188. if (_object isKindOf "TrapItems" or _object isKindOf "DZ_buildables") then {
  189. //Use inventory for owner/clan info & traps armed state
  190. {
  191. if (typeName _x != "ARRAY") then {
  192. // old method
  193. if (typeName _x == "STRING") then { _object setVariable ["ownerArray", [_x], true]; };
  194. if (typeName _x == "BOOLEAN") then { _object setVariable ["armed", _x, true]; };
  195. } else { // new method: array of variables to set
  196. switch (_x select 0) do {
  197. case "ownerArray" : { _object setVariable ["ownerArray", _x select 1, true]; };
  198. case "clanArray" : { _object setVariable ["clanArray", _x select 1, true]; };
  199. case "armed" : { _object setVariable ["armed", _x select 1, true]; };
  200. };
  201. };
  202. } forEach _inventory;
  203. //Use hitpoints for Maintenance system.
  204. {
  205. if (_x == "Maintenance") then { _object setVariable ["Maintenance", true, true]; };
  206. } foreach _hitPoints;
  207. };
  208. };
  209.  
  210. //Monitor the object
  211. //_object enableSimulation false;
  212. dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,_object];
  213. };
  214. } forEach _myArray;
  215.  
  216. // # END OF STREAMING #
  217.  
  218. // Draw the pseudo random seeds
  219. call server_plantSpawner;
  220.  
  221. // launch the legacy task scheduler
  222. [] execFSM "\z\addons\dayz_server\system\server_cleanup.fsm";
  223.  
  224. // launch the new task scheduler
  225. [] execVM "\z\addons\dayz_server\system\scheduler\sched_init.sqf";
  226.  
  227. // remove annoying benches
  228. if (toLower(worldName) == "chernarus") then {
  229. ([4654,9595,0] nearestObject 145259) setDamage 1;
  230. ([4654,9595,0] nearestObject 145260) setDamage 1;
  231. };
  232.  
  233. createCenter civilian;
  234. if (isDedicated) then {
  235. endLoadingScreen;
  236. };
  237. allowConnection = true;
  238. sm_done = true;
  239. publicVariable "sm_done";
  240.  
  241. // Trap loop
  242. [] spawn {
  243. private ["_array","_array2","_array3","_script","_armed"];
  244. _array = str dayz_traps;
  245. _array2 = str dayz_traps_active;
  246. _array3 = str dayz_traps_trigger;
  247.  
  248. while {1 == 1} do {
  249. if ((str dayz_traps != _array) || (str dayz_traps_active != _array2) || (str dayz_traps_trigger != _array3)) then {
  250. _array = str dayz_traps;
  251. _array2 = str dayz_traps_active;
  252. _array3 = str dayz_traps_trigger;
  253.  
  254. //diag_log "DEBUG: traps";
  255. //diag_log format["dayz_traps (%2) -> %1", dayz_traps, count dayz_traps];
  256. //diag_log format["dayz_traps_active (%2) -> %1", dayz_traps_active, count dayz_traps_active];
  257. //diag_log format["dayz_traps_trigger (%2) -> %1", dayz_traps_trigger, count dayz_traps_trigger];
  258. //diag_log "DEBUG: end traps";
  259. };
  260.  
  261. {
  262. if (isNull _x) then {
  263. dayz_traps = dayz_traps - [_x];
  264. };
  265.  
  266. _script = call compile getText (configFile >> "CfgVehicles" >> typeOf _x >> "script");
  267. _armed = _x getVariable ["armed", false];
  268.  
  269. if (_armed) then {
  270. if !(_x in dayz_traps_active) then {
  271. ["arm", _x] call _script;
  272. };
  273. } else {
  274. if (_x in dayz_traps_active) then {
  275. ["disarm", _x] call _script;
  276. };
  277. };
  278.  
  279. sleep 0.01;
  280. } forEach dayz_traps;
  281. sleep 1;
  282. };
  283. };
  284.  
  285.  
  286. //Spawn camps and carepak once
  287. [] spawn {
  288. if(isNil "dayz_spawnInfectedSite_clutterCutter") then {
  289. dayz_spawnInfectedSite_clutterCutter = 0;
  290. };
  291.  
  292. // quantity, marker, radius, min distance between 2 camps
  293. Server_InfectedCamps = [3, "center", 4500, 300] call fn_bases;
  294. //dayzInfectedCamps = Server_InfectedCamps;
  295. //publicVariable "dayzInfectedCamps";
  296.  
  297. if(isNil "dayz_spawncarepkgs_clutterCutter") then {
  298. dayz_spawncarepkgs_clutterCutter = 0;
  299. };
  300.  
  301. //Packages
  302. [6,["Misc_cargo_cont_net1","Misc_cargo_cont_net2","Misc_cargo_cont_net3"],["Industrial","Supermarket","Hospital","CarePackages"]] call spawn_carePackages;
  303. };
  304.  
  305. //Spawn helicopter crashes periodically
  306. [] spawn {
  307. if(isNil "dayz_spawnCrashSite_clutterCutter") then {
  308. dayz_spawnCrashSite_clutterCutter = 0;
  309. };
  310.  
  311. // [_guaranteedLoot, _randomizedLoot, spawnOnStart, _frequency, _variance, _spawnChance, _spawnMarker, _spawnRadius, _spawnFire, _fadeFire]
  312. [3, 4, 3, (40 * 60), (15 * 60), 0.75, 'center', 4000, true, false] call server_spawnCrashSite;
  313. };
  314.  
  315. [] execVM "\z\addons\dayz_server\system\lit_fireplaces.sqf";
  316.  
  317. /*
  318. if (isDedicated) then {
  319. //Wild Zeds Ownership isnt working as expected yet
  320. execFSM "\z\addons\dayz_server\system\zombie_wildagent.fsm";
  321. };
  322. */
  323.  
  324. /*
  325. if (dayz_serversideloot) then {
  326. //looot
  327. _i = 0;
  328. {
  329. _radius = 1500;
  330. //_nearByPlayer = (count (_x nearEntities ["CAManBase",_radius])) > 0;
  331. //if (_nearByPlayer) then {
  332. dayz_i = [_x,_radius,_i,1800] call server_lootSpawner;
  333. _i = _i + 1;
  334. //};
  335. } foreach dayz_grid;
  336. };
  337. */
  338.  
  339. "PVDZ_sec_atp" addPublicVariableEventHandler {
  340. _x = _this select 1;
  341. switch (1==1) do {
  342. case (typeName _x == "STRING") : { // just some logs from the client
  343. diag_log _x;
  344. };
  345. case (count _x == 2) : { // wrong side
  346. diag_log Format [ "P1ayer %1 reports possible 'side' hack... Server may be comprised!", (_x select 1) call fa_plr2Str ];
  347. };
  348. default { // player hit
  349. _unit = _x select 0;
  350. _source = _x select 1;
  351. if (((!(isNil {_source})) AND {(!(isNull _source))}) AND {((_source isKindOf "CAManBase") AND {(owner _unit != owner _source)})}) then {
  352. diag_log format ["P1ayer %1 hit by %2 %3 from %4 meters",
  353. _unit call fa_plr2Str, _source call fa_plr2Str, _x select 2, _x select 3];
  354. if (_unit getVariable["processedDeath", 0] == 0) then {
  355. _unit setVariable [ "attacker", name _source ];
  356. _unit setVariable [ "noatlf4", diag_ticktime ]; // server-side "not in combat" test, if player is not already dead
  357. };
  358. };
  359. };
  360. };
  361. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement