Advertisement
Guest User

server_monitor

a guest
May 23rd, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.53 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. []execVM "\z\addons\dayz_server\system\instaaction.sqf";
  4. #include "\z\addons\dayz_server\compile\server_toggle_debug.hpp"
  5.  
  6. dayz_versionNo = getText(configFile >> "CfgMods" >> "DayZ" >> "version");
  7. dayz_hiveVersionNo = getNumber(configFile >> "CfgMods" >> "DayZ" >> "hiveVersion");
  8.  
  9. waitUntil{initialized}; //means all the functions are now defined
  10.  
  11. //####----####----####---- Base Building 1.3 Start ----####----####----####
  12. call build_baseBuilding_arrays; // build BB 1.2 arrays
  13. //####----####----####---- Base Building 1.3 End ----####----####----####
  14.  
  15. diag_log "HIVE: Starting";
  16.  
  17. //Set the Time
  18. //Send request
  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. //Force full moon nights
  33. _date1 = [2014,5,31,_hour,_minute];
  34.  
  35. if(isDedicated) then {
  36. //["dayzSetDate",_date] call broadcastRpcCallAll;
  37. setDate _date1;
  38. dayzSetDate = _date1;
  39. dayz_storeTimeDate = _date1;
  40. publicVariable "dayzSetDate";
  41. };
  42. diag_log ("HIVE: Local Time set to " + str(_date1));
  43. };
  44.  
  45. waituntil{isNil "sm_done"}; // prevent server_monitor be called twice (bug during login of the first player)
  46.  
  47. if (isServer and isNil "sm_done") then {
  48. 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"];
  49.  
  50. //Send the key
  51. _key = format["CHILD:999:select payload, loop_interval, start_delay from message where instance_id = ?:[%1]:", dayZ_instance];
  52. _data = "HiveEXT" callExtension _key;
  53.  
  54. diag_log("SERVER: Fetching messages...");
  55.  
  56. //Process result
  57. _result = call compile format ["%1", _data];
  58. _status = _result select 0;
  59.  
  60. msgList = [];
  61. _msgCount = 0;
  62. if (_status == "CustomStreamStart") then {
  63. _val = _result select 1;
  64. for "_i" from 1 to _val do {
  65. _data = "HiveEXT" callExtension _key;
  66. _result = call compile format ["%1",_data];
  67.  
  68. _status = _result select 0;
  69. msgList set [count msgList, _result];
  70. _msgCount = _msgCount + 1;
  71. };
  72. diag_log ("SERVER: Added " + str(_msgCount) + " messages!");
  73. };
  74.  
  75. //Send the key
  76. _key = format["CHILD:999:select b.class_name, ib.worldspace from instance_building ib join building b on ib.building_id = b.id where ib.instance_id = ?:[%1]:", dayZ_instance];
  77. _data = "HiveEXT" callExtension _key;
  78.  
  79. diag_log("SERVER: Fetching buildings for instance " + str(dayZ_instance));
  80.  
  81. //Process result
  82. _result = call compile format ["%1", _data];
  83. _status = _result select 0;
  84.  
  85. _bldList = [];
  86. _bldCount = 0;
  87. if (_status == "CustomStreamStart") then {
  88. _val = _result select 1;
  89. for "_i" from 1 to _val do {
  90. _data = "HiveEXT" callExtension _key;
  91. _result = call compile format ["%1",_data];
  92.  
  93. _pos = call compile (_result select 1);
  94. _dir = _pos select 0;
  95. _pos = _pos select 1;
  96.  
  97. _building = createVehicle [_result select 0, _pos, [], 0, "CAN_COLLIDE"];
  98. _building setDir _dir;
  99. _bldCount = _bldCount + 1;
  100. };
  101. diag_log ("SERVER: Spawned " + str(_bldCount) + " buildings!");
  102. };
  103.  
  104. //Stream in objects
  105. /* STREAM OBJECTS */
  106. //Send the key
  107. _key = format["CHILD:302:%1:",dayZ_instance];
  108. _result = _key call server_hiveReadWrite;
  109.  
  110. diag_log "HIVE: Request sent";
  111.  
  112. //Process result
  113. _status = _result select 0;
  114.  
  115. _myArray = [];
  116. if (_status == "ObjectStreamStart") then {
  117. _val = _result select 1;
  118. //Stream Objects
  119. diag_log ("HIVE: Commence Object Streaming...");
  120. for "_i" from 1 to _val do {
  121. _result = _key call server_hiveReadWrite;
  122.  
  123. _status = _result select 0;
  124. _myArray set [count _myArray,_result];
  125. //diag_log ("HIVE: Loop ");
  126. };
  127. diag_log ("HIVE: Streamed " + str(_val) + " objects");
  128. };
  129.  
  130. _countr = 0;
  131. {
  132.  
  133. //Parse Array
  134. _countr = _countr + 1;
  135.  
  136. _idKey = _x select 1;
  137. _type = _x select 2;
  138. _ownerID = _x select 3;
  139. _worldspace = _x select 4;
  140. _inventory = _x select 5;
  141. _hitPoints= _x select 6;
  142. _fuel = _x select 7;
  143. _damage = _x select 8;
  144.  
  145. _dir = 0;
  146. _pos = [0,0,0];
  147. _wsDone = false;
  148. if (count _worldspace >= 2) then
  149. {
  150. _dir = _worldspace select 0;
  151. if (count (_worldspace select 1) == 3) then {
  152. _pos = _worldspace select 1;
  153. _wsDone = true;
  154. }
  155. };
  156. if (!_wsDone) then {
  157. if (count _worldspace >= 1) then { _dir = _worldspace select 0; };
  158. _pos = [getMarkerPos "center",0,50,10,0,2000,0] call BIS_fnc_findSafePos;
  159. if (count _pos < 3) then { _pos = [_pos select 0,_pos select 1,0]; };
  160. diag_log ("MOVED OBJ: " + str(_idKey) + " of class " + _type + " to pos: " + str(_pos));
  161. };
  162.  
  163. if (_damage < 1) then {
  164. diag_log format["OBJ: %1 - %2,%3,%4,%5,%6,%7,%8", _idKey,_type,_ownerID,_worldspace,_inventory,_hitPoints,_fuel,_damage];
  165.  
  166. //Create it
  167. _object = createVehicle [_type, _pos, [], 0,
  168. if (_type=="TentStorage") then {"NONE"} else {"CAN_COLLIDE"}
  169. ];
  170. _object setVariable ["lastUpdate",time];
  171. if (_object isKindOf "TentStorage" || _object isKindOf "CamoNet_DZ" || _object isKindOf "Land_A_tent") then {
  172. _object setVariable ["ObjectUID", _idKey, true]
  173. } else {;
  174. _object setVariable ["ObjectID", _idKey, true];
  175. };
  176. _object setVariable ["CharacterID", _ownerID, true];
  177.  
  178. if (_object isKindOf "TentStorage" || _object isKindOf "CamoNet_DZ" || _object isKindOf "Land_A_tent") then {
  179. _pos set [2,0];
  180. _object setpos _pos;
  181. _object addMPEventHandler ["MPKilled",{_this call vehicle_handleServerKilled;}];
  182. };
  183.  
  184. _object setdir _dir;
  185. _object setDamage _damage;
  186.  
  187. //####----####----####---- Base Building 1.3 Start ----####----####----####
  188. //Check to make sure all current flags match the set flag type, if not then change them
  189. if ((typeOf(_object) in BBAllFlagTypes) && (typeOf(_object) != BBTypeOfFlag)) then {
  190. deleteVehicle _object;
  191. _object = createVehicle [BBTypeOfFlag, _pos, [], 0, "CAN_COLLIDE"];
  192. _object setVariable ["CharacterID", _ownerID, true];
  193. };
  194.  
  195. //Check to make sure all current shield generators match the set shield generator type, if not then change them
  196. if ((typeOf(_object) in BBAllZShieldTypes) && (typeOf(_object) != BBTypeOfZShield)) then {
  197. deleteVehicle _object;
  198. _object = createVehicle [BBTypeOfZShield, _pos, [], 0, "CAN_COLLIDE"];
  199. _object setVariable ["CharacterID", _ownerID, true];
  200. };
  201.  
  202. // Give objects all custom UID
  203. if (typeOf(_object) in allbuildables_class) then {
  204. _object setVariable ["AuthorizedUID", _inventory, true]; //Sets the AuthorizedUID for build objects
  205. _object setVariable ["ObjectUID", ((_inventory select 0) select 0), true]; //Sets Object UID using array value
  206. };
  207.  
  208. //Handle Traps (Graves)
  209. if (typeOf(_object) == "Grave") then {
  210. _object setVariable ["isBomb", 1, true];//this will be known as a bomb instead of checking with classnames in player_bomb
  211. _object setpos [(getposATL _object select 0),(getposATL _object select 1), -0.12];
  212. _object addEventHandler ["HandleDamage", {false}];
  213. };
  214.  
  215. //Restore extendable objects to whatever their position is supposed to be
  216. if (typeOf(_object) in allExtendables && typeOf(_object) != "Grave") then {
  217. _object setposATL [(getposATL _object select 0),(getposATL _object select 1), (getposATL _object select 2)];
  218. };
  219.  
  220. //Restore non extendable objects and make sure they follow the land contours
  221. if (!(typeOf(_object) in allExtendables) && (_object isKindOf "Static") && !(_object isKindOf "TentStorage") && typeOf(_object) != "Grave") then {
  222. _object setpos [(getposATL _object select 0),(getposATL _object select 1), 0];
  223. };
  224. //Set Variable
  225. _codePanels = ["Infostand_2_EP1", "Fence_corrugated_plate", BBTypeOfFlag];
  226. if (typeOf(_object) in _codePanels && (typeOf(_object) != "Infostand_1_EP1")) then {
  227. _object addEventHandler ["HandleDamage", {false}];
  228. };
  229.  
  230. /*******************************************This Section Handles Objects Which Move Excessively During the Build Process***********************************************/
  231. /*******************************If added build objects move excessively, you can add a condition for them here and adjust as needed!***********************************/
  232. if (typeOf(_object) == "Land_sara_hasic_zbroj") then {
  233. _object setPosATL [((getPosATL _object select 0)+5.5),((getPosATL _object select 1)-1),(getPosATL _object select 2)];
  234. };
  235. if (typeOf(_object) == "Fence_Ind_long") then {
  236. _object setPosATL [((getPosATL _object select 0)-3.5),((getPosATL _object select 1)-0),(getPosATL _object select 2)];
  237. };
  238. if (typeOf(_object) == "Fort_RazorWire" || typeOf(_object) == "Land_Shed_wooden") then {
  239. _object setPosATL [((getPosATL _object select 0)-1.5),((getPosATL _object select 1)-0.5),(getPosATL _object select 2)];
  240. };
  241. if (typeOf(_object) == "Land_vez") then {
  242. _object setPosATL [((getPosATL _object select 0)-3.5),((getPosATL _object select 1)+1.5),(getPosATL _object select 2)];
  243. };
  244. if (typeOf(_object) == "Land_Misc_Scaffolding") then {
  245. _object setPosATL [((getPosATL _object select 0)-0.5),((getPosATL _object select 1)+3),(getPosATL _object select 2)];
  246. };
  247. /**************************************************************End of Excessive Movement Section***********************************************************************/
  248.  
  249. // Set whether or not buildable is destructable
  250. if (typeOf(_object) in allbuildables_class) then {
  251. diag_log ("SERVER: in allbuildables_class:" + typeOf(_object) + "!");
  252. for "_i" from 0 to ((count allbuildables) - 1) do
  253. {
  254. _classname = (allbuildables select _i) select _i - _i + 1;
  255. _result = [_classname,typeOf(_object)] call BIS_fnc_areEqual;
  256. if (_result) exitWith {
  257. _requirements = (allbuildables select _i) select _i - _i + 2;
  258. _isDestructable = _requirements select 13;
  259. diag_log ("SERVER: " + typeOf(_object) + " _isDestructable = " + str(_isDestructable));
  260. if (!_isDestructable) then {
  261. diag_log("Spawned: " + typeOf(_object) + " Handle Damage False");
  262. _object addEventHandler ["HandleDamage", {false}];
  263. };
  264. };
  265. };
  266. };
  267. //####----####----####---- Base Building 1.3 End ----####----####----####
  268.  
  269. //Dont add inventory for traps.
  270. if (!(_object isKindOf "TrapItems") && !(typeOf(_object) in allbuildables_class) && !(typeOf(_object) in BBAllFlagTypes) && !(typeOf(_object) in BBAllZShieldTypes)) then {
  271. _cargo = _inventory;
  272. clearWeaponCargoGlobal _object;
  273. clearMagazineCargoGlobal _object;
  274. clearBackpackCargoGlobal _object;
  275. _config = ["CfgWeapons", "CfgMagazines", "CfgVehicles" ];
  276. {
  277. _magItemTypes = _x select 0;
  278. _magItemQtys = _x select 1;
  279. _i = _forEachIndex;
  280. {
  281. if (_x == "Crossbow") then { _x = "Crossbow_DZ" }; // Convert Crossbow to Crossbow_DZ
  282. if (_x == "BoltSteel") then { _x = "WoodenArrow" }; // Convert BoltSteel to WoodenArrow
  283. // Convert to DayZ Weapons
  284. if (_x == "DMR") then { _x = "DMR_DZ" };
  285. //if (_x == "M14_EP1") then { _x = "M14_DZ" };
  286. if (_x == "SVD") then { _x = "SVD_DZ" };
  287. if (_x == "SVD_CAMO") then { _x = "SVD_CAMO_DZ" };
  288. if (isClass(configFile >> (_config select _i) >> _x) &&
  289. getNumber(configFile >> (_config select _i) >> _x >> "stopThis") != 1) then {
  290. if (_forEachIndex < count _magItemQtys) then {
  291. switch (_i) do {
  292. case 0: { _object addWeaponCargoGlobal [_x,(_magItemQtys select _forEachIndex)]; };
  293. case 1: { _object addMagazineCargoGlobal [_x,(_magItemQtys select _forEachIndex)]; };
  294. case 2: { _object addBackpackCargoGlobal [_x,(_magItemQtys select _forEachIndex)]; };
  295. };
  296. };
  297. };
  298. } forEach _magItemTypes;
  299. } forEach _cargo;
  300. };
  301.  
  302. if (_object isKindOf "AllVehicles") then {
  303. {
  304. _selection = _x select 0;
  305. _dam = _x select 1;
  306. if (_selection in dayZ_explosiveParts and _dam > 0.8) then {_dam = 0.8};
  307.  
  308. [_object,_selection,_dam] call fnc_veh_setFixServer;
  309. } forEach _hitpoints;
  310. _object setvelocity [0,0,1];
  311. _object setFuel _fuel;
  312. _object call fnc_veh_ResetEH;
  313. if (_object isKindOf "AN2_DZ") then {
  314. _object addWeapon "M240_veh";
  315. _object addMagazine "100Rnd_762x51_M240";
  316. _object addMagazine "100Rnd_762x51_M240";
  317. _object addMagazine "100Rnd_762x51_M240";
  318. };
  319. if (_object isKindOf "AH6X_DZ") then {
  320. _object addWeapon "M240_veh";
  321. _object addMagazine "100Rnd_762x51_M240";
  322. _object addMagazine "100Rnd_762x51_M240";
  323. _object addMagazine "100Rnd_762x51_M240";
  324. };
  325. } else {
  326. if (!(_type in SafeObjects )) then {
  327. _damage = 1;
  328. diag_log format["OBJ: %1 - %2 REMOVED", _object,_damage];
  329. };
  330. };
  331.  
  332. if (_object isKindOf "TrapItems") then {
  333. _object setVariable ["armed", _inventory select 0, false];
  334. };
  335.  
  336. //Monitor the object
  337. //_object enableSimulation false;
  338. dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,_object];
  339. };
  340. } forEach _myArray;
  341.  
  342. // # END OF STREAMING #
  343.  
  344. createCenter civilian;
  345. if (isDedicated) then {
  346. endLoadingScreen;
  347. };
  348.  
  349. if (isDedicated) then {
  350. _id = [] execFSM "\z\addons\dayz_server\system\server_cleanup.fsm";
  351. };
  352.  
  353. call compile preprocessFileLineNumbers "\z\addons\dayz_server\DZAI\init\dzai_initserver.sqf";
  354. [] ExecVM "\z\addons\dayz_server\DZMS\DZMSInit.sqf";
  355. allowConnection = true;
  356.  
  357. // antiwallhack
  358. call compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fa_antiwallhack.sqf";
  359.  
  360. sm_done = true;
  361. publicVariable "sm_done";
  362.  
  363. dayz_Crashspawner = [] spawn {
  364. // [_guaranteedLoot, _randomizedLoot, spawnOnStart, _frequency, _variance, _spawnChance, _spawnMarker, _spawnRadius, _spawnFire, _fadeFire]
  365. [3, 4, 3, (30 * 60), (5 * 60), 0.75, 'center', 4000, true, false] call server_spawnCrashSite;
  366. };
  367.  
  368. //Spawn camps
  369. dayz_Campspawner = [] spawn {
  370. // quantity, marker, radius, min distance between 2 camps
  371. Server_InfectedCamps = [3, "center", 4500, 2000] call fn_bases;
  372. dayzInfectedCamps = Server_InfectedCamps;
  373. publicVariable "dayzInfectedCamps";
  374. };
  375.  
  376. dayz_Plantspawner = [] spawn {
  377. [300] call server_plantSpawner;
  378. };
  379.  
  380. //if (isDedicated) then {
  381. //Wild Zeds Ownership isnt working as expected yet
  382. // execFSM "\z\addons\dayz_server\system\zombie_wildagent.fsm";
  383. //};
  384.  
  385. // Trap loop
  386. [] call {
  387. private ["_array","_array2","_array3","_script","_armed"];
  388. _array = str dayz_traps;
  389. _array2 = str dayz_traps_active;
  390. _array3 = str dayz_traps_trigger;
  391.  
  392. while { true } do {
  393. if ((str dayz_traps != _array) || (str dayz_traps_active != _array2) || (str dayz_traps_trigger != _array3)) then {
  394. _array = str dayz_traps;
  395. _array2 = str dayz_traps_active;
  396. _array3 = str dayz_traps_trigger;
  397.  
  398. diag_log "DEBUG: traps";
  399. diag_log format["dayz_traps (%2) -> %1", dayz_traps, count dayz_traps];
  400. diag_log format["dayz_traps_active (%2) -> %1", dayz_traps_active, count dayz_traps_active];
  401. diag_log format["dayz_traps_trigger (%2) -> %1", dayz_traps_trigger, count dayz_traps_trigger];
  402. diag_log "DEBUG: end traps";
  403. };
  404.  
  405. {
  406. if (isNull _x) then {
  407. dayz_traps = dayz_traps - [_x];
  408. };
  409.  
  410. _script = call compile getText (configFile >> "CfgVehicles" >> typeOf _x >> "script");
  411. _armed = _x getVariable ["armed", false];
  412.  
  413. if (_armed) then {
  414. if !(_x in dayz_traps_active) then {
  415. ["arm", _x] call _script;
  416. };
  417. } else {
  418. if (_x in dayz_traps_active) then {
  419. ["disarm", _x] call _script;
  420. };
  421. };
  422.  
  423. //sleep 0.01;
  424. } forEach dayz_traps;
  425. };
  426. };
  427. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement