Advertisement
Guest User

server_monitor.sqf 1.8.0.3

a guest
Jan 19th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.09 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. diag_log "HIVE: Starting";
  12.  
  13. //Set the Time
  14. //Send request
  15. _key = "CHILD:307:";
  16. _result = _key call server_hiveReadWrite;
  17. _outcome = _result select 0;
  18. if(_outcome == "PASS") then {
  19. _date = _result select 1;
  20.  
  21. //date setup
  22. _year = _date select 0;
  23. _month = _date select 1;
  24. _day = _date select 2;
  25. _hour = _date select 3;
  26. _minute = _date select 4;
  27.  
  28. //Force full moon nights
  29. _date1 = [2013,8,3,_hour,_minute];
  30.  
  31. if(isDedicated) then {
  32. //["dayzSetDate",_date] call broadcastRpcCallAll;
  33. setDate _date1;
  34. dayzSetDate = _date1;
  35. dayz_storeTimeDate = _date1;
  36. publicVariable "dayzSetDate";
  37. };
  38. diag_log ("HIVE: Local Time set to " + str(_date1));
  39. };
  40.  
  41. waituntil{isNil "sm_done"}; // prevent server_monitor be called twice (bug during login of the first player)
  42.  
  43. if (isServer and isNil "sm_done") then {
  44. 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"];
  45.  
  46. //Send the key
  47. _key = format["CHILD:999:select payload, loop_interval, start_delay from message where instance_id = ?:[%1]:", dayZ_instance];
  48. _data = "HiveEXT" callExtension _key;
  49.  
  50. diag_log("SERVER: Fetching messages...");
  51.  
  52. //Process result
  53. _result = call compile format ["%1", _data];
  54. _status = _result select 0;
  55.  
  56. msgList = [];
  57. _msgCount = 0;
  58. if (_status == "CustomStreamStart") then {
  59. _val = _result select 1;
  60. for "_i" from 1 to _val do {
  61. _data = "HiveEXT" callExtension _key;
  62. _result = call compile format ["%1",_data];
  63.  
  64. _status = _result select 0;
  65. msgList set [count msgList, _result];
  66. _msgCount = _msgCount + 1;
  67. };
  68. diag_log ("SERVER: Added " + str(_msgCount) + " messages!");
  69. };
  70.  
  71. //Send the key
  72. _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];
  73. _data = "HiveEXT" callExtension _key;
  74.  
  75. diag_log("SERVER: Fetching buildings for instance " + str(dayZ_instance));
  76.  
  77. //Process result
  78. _result = call compile format ["%1", _data];
  79. _status = _result select 0;
  80.  
  81. _bldList = [];
  82. _bldCount = 0;
  83. if (_status == "CustomStreamStart") then {
  84. _val = _result select 1;
  85. for "_i" from 1 to _val do {
  86. _data = "HiveEXT" callExtension _key;
  87. _result = call compile format ["%1",_data];
  88.  
  89. _pos = call compile (_result select 1);
  90. _dir = _pos select 0;
  91. _pos = _pos select 1;
  92.  
  93. _building = createVehicle [_result select 0, _pos, [], 0, "CAN_COLLIDE"];
  94. _building setDir _dir;
  95. _bldCount = _bldCount + 1;
  96. };
  97. diag_log ("SERVER: Spawned " + str(_bldCount) + " buildings!");
  98. };
  99.  
  100. //Stream in objects
  101. /* STREAM OBJECTS */
  102. //Send the key
  103. _key = format["CHILD:302:%1:",dayZ_instance];
  104. _result = _key call server_hiveReadWrite;
  105.  
  106. diag_log "HIVE: Request sent";
  107.  
  108. //Process result
  109. _status = _result select 0;
  110.  
  111. _myArray = [];
  112. if (_status == "ObjectStreamStart") then {
  113. _val = _result select 1;
  114. //Stream Objects
  115. diag_log ("HIVE: Commence Object Streaming...");
  116. for "_i" from 1 to _val do {
  117. _result = _key call server_hiveReadWrite;
  118.  
  119. _status = _result select 0;
  120. _myArray set [count _myArray,_result];
  121. //diag_log ("HIVE: Loop ");
  122. };
  123. diag_log ("HIVE: Streamed " + str(_val) + " objects");
  124. };
  125.  
  126. _countr = 0;
  127. {
  128.  
  129. //Parse Array
  130. _countr = _countr + 1;
  131.  
  132. _idKey = _x select 1;
  133. _type = _x select 2;
  134. _ownerID = _x select 3;
  135. _worldspace = _x select 4;
  136. _inventory = _x select 5;
  137. _hitPoints= _x select 6;
  138. _fuel = _x select 7;
  139. _damage = _x select 8;
  140.  
  141. _dir = 0;
  142. _pos = [0,0,0];
  143. _wsDone = false;
  144. if (count _worldspace >= 2) then
  145. {
  146. _dir = _worldspace select 0;
  147. if (count (_worldspace select 1) == 3) then {
  148. _pos = _worldspace select 1;
  149. _wsDone = true;
  150. }
  151. };
  152. if (!_wsDone) then {
  153. if (count _worldspace >= 1) then { _dir = _worldspace select 0; };
  154. _pos = [getMarkerPos "center",0,50,10,0,2000,0] call BIS_fnc_findSafePos;
  155. if (count _pos < 3) then { _pos = [_pos select 0,_pos select 1,0]; };
  156. diag_log ("MOVED OBJ: " + str(_idKey) + " of class " + _type + " to pos: " + str(_pos));
  157. };
  158.  
  159. if (_damage < 1) then {
  160. diag_log format["OBJ: %1 - %2,%3,%4,%5,%6,%7,%8", _idKey,_type,_ownerID,_worldspace,_inventory,_hitPoints,_fuel,_damage];
  161.  
  162. //Create it
  163. _object = createVehicle [_type, _pos, [], 0,
  164. if (_type=="TentStorage") then {"NONE"} else {"CAN_COLLIDE"}
  165. ];
  166. _object setVariable ["lastUpdate",time];
  167. if (_object isKindOf "TentStorage" || _object isKindOf "CamoNet_DZ" || _object isKindOf "Land_A_tent") then {
  168. _object setVariable ["ObjectUID", _idKey, true]
  169. } else {;
  170. _object setVariable ["ObjectID", _idKey, true];
  171. };
  172. _object setVariable ["CharacterID", _ownerID, true];
  173.  
  174. if (_object isKindOf "TentStorage" || _object isKindOf "CamoNet_DZ" || _object isKindOf "Land_A_tent") then {
  175. _pos set [2,0];
  176. _object setpos _pos;
  177. _object addMPEventHandler ["MPKilled",{_this call vehicle_handleServerKilled;}];
  178. };
  179.  
  180. _object setdir _dir;
  181. _object setDamage _damage;
  182.  
  183. //Dont add inventory for traps.
  184. if (!(_object isKindOf "TrapItems")) then {
  185. _cargo = _inventory;
  186. clearWeaponCargoGlobal _object;
  187. clearMagazineCargoGlobal _object;
  188. clearBackpackCargoGlobal _object;
  189. _config = ["CfgWeapons", "CfgMagazines", "CfgVehicles" ];
  190. {
  191. _magItemTypes = _x select 0;
  192. _magItemQtys = _x select 1;
  193. _i = _forEachIndex;
  194. {
  195. if (_x == "Crossbow") then { _x = "Crossbow_DZ" }; // Convert Crossbow to Crossbow_DZ
  196. if (_x == "BoltSteel") then { _x = "WoodenArrow" }; // Convert BoltSteel to WoodenArrow
  197. // Convert to DayZ Weapons
  198. if (_x == "DMR") then { _x = "DMR_DZ" };
  199. //if (_x == "M14_EP1") then { _x = "M14_DZ" };
  200. if (_x == "SVD") then { _x = "SVD_DZ" };
  201. if (_x == "SVD_CAMO") then { _x = "SVD_CAMO_DZ" };
  202. if (isClass(configFile >> (_config select _i) >> _x) &&
  203. getNumber(configFile >> (_config select _i) >> _x >> "stopThis") != 1) then {
  204. if (_forEachIndex < count _magItemQtys) then {
  205. switch (_i) do {
  206. case 0: { _object addWeaponCargoGlobal [_x,(_magItemQtys select _forEachIndex)]; };
  207. case 1: { _object addMagazineCargoGlobal [_x,(_magItemQtys select _forEachIndex)]; };
  208. case 2: { _object addBackpackCargoGlobal [_x,(_magItemQtys select _forEachIndex)]; };
  209. };
  210. };
  211. };
  212. } forEach _magItemTypes;
  213. } forEach _cargo;
  214. };
  215.  
  216. if (_object isKindOf "AllVehicles") then {
  217. {
  218. _selection = _x select 0;
  219. _dam = _x select 1;
  220. if (_selection in dayZ_explosiveParts and _dam > 0.8) then {_dam = 0.8};
  221.  
  222. [_object,_selection,_dam] call fnc_veh_setFixServer;
  223. } forEach _hitpoints;
  224. _object setvelocity [0,0,1];
  225. _object setFuel _fuel;
  226. _object call fnc_veh_ResetEH;
  227. } else {
  228. if (!(_type in SafeObjects )) then {
  229. _damage = 1;
  230. diag_log format["OBJ: %1 - %2 REMOVED", _object,_damage];
  231. };
  232. };
  233.  
  234. if (_object isKindOf "TrapItems") then {
  235. _object setVariable ["armed", _inventory select 0, false];
  236. };
  237.  
  238. if (_object isKindOf "AN2_DZ") then {
  239.  
  240. _object addWeapon "M240_veh";
  241. _object addMagazine "100Rnd_762x51_M240";
  242. _object addMagazine "100Rnd_762x51_M240";
  243. };
  244.  
  245. //Monitor the object
  246. //_object enableSimulation false;
  247. dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,_object];
  248. };
  249. } forEach _myArray;
  250.  
  251. // # END OF STREAMING #
  252.  
  253. createCenter civilian;
  254. if (isDedicated) then {
  255. endLoadingScreen;
  256. };
  257.  
  258. if (isDedicated) then {
  259. _id = [] execFSM "\z\addons\dayz_server\system\server_cleanup.fsm";
  260. };
  261.  
  262. allowConnection = true;
  263.  
  264. // antiwallhack
  265. call compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fa_antiwallhack.sqf";
  266.  
  267. sm_done = true;
  268. publicVariable "sm_done";
  269.  
  270. dayz_Crashspawner = [] spawn {
  271. // [_guaranteedLoot, _randomizedLoot, spawnOnStart, _frequency, _variance, _spawnChance, _spawnMarker, _spawnRadius, _spawnFire, _fadeFire]
  272. [3, 4, 3, (40 * 60), (15 * 60), 0.75, 'center', 4000, true, false] call server_spawnCrashSite;
  273. };
  274.  
  275. //Spawn camps
  276. dayz_Campspawner = [] spawn {
  277. // quantity, marker, radius, min distance between 2 camps
  278. Server_InfectedCamps = [3, "center", 4500, 2000] call fn_bases;
  279. dayzInfectedCamps = Server_InfectedCamps;
  280. publicVariable "dayzInfectedCamps";
  281. };
  282.  
  283. dayz_Plantspawner = [] spawn {
  284. [300] call server_plantSpawner;
  285. };
  286.  
  287. //if (isDedicated) then {
  288. //Wild Zeds Ownership isnt working as expected yet
  289. // execFSM "\z\addons\dayz_server\system\zombie_wildagent.fsm";
  290. //};
  291.  
  292. // Trap loop
  293. [] call {
  294. private ["_array","_array2","_array3","_script","_armed"];
  295. _array = str dayz_traps;
  296. _array2 = str dayz_traps_active;
  297. _array3 = str dayz_traps_trigger;
  298.  
  299. while { true } do {
  300. if ((str dayz_traps != _array) || (str dayz_traps_active != _array2) || (str dayz_traps_trigger != _array3)) then {
  301. _array = str dayz_traps;
  302. _array2 = str dayz_traps_active;
  303. _array3 = str dayz_traps_trigger;
  304.  
  305. diag_log "DEBUG: traps";
  306. diag_log format["dayz_traps (%2) -> %1", dayz_traps, count dayz_traps];
  307. diag_log format["dayz_traps_active (%2) -> %1", dayz_traps_active, count dayz_traps_active];
  308. diag_log format["dayz_traps_trigger (%2) -> %1", dayz_traps_trigger, count dayz_traps_trigger];
  309. diag_log "DEBUG: end traps";
  310. };
  311.  
  312. {
  313. if (isNull _x) then {
  314. dayz_traps = dayz_traps - [_x];
  315. };
  316.  
  317. _script = call compile getText (configFile >> "CfgVehicles" >> typeOf _x >> "script");
  318. _armed = _x getVariable ["armed", false];
  319.  
  320. if (_armed) then {
  321. if !(_x in dayz_traps_active) then {
  322. ["arm", _x] call _script;
  323. };
  324. } else {
  325. if (_x in dayz_traps_active) then {
  326. ["disarm", _x] call _script;
  327. };
  328. };
  329.  
  330. //sleep 0.01;
  331. } forEach dayz_traps;
  332. };
  333. };
  334. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement