Advertisement
Ranzen

server_monitor.sqf

Oct 8th, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.82 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. _script = getText(missionConfigFile >> "onPauseScript");
  8.  
  9. if ((count playableUnits == 0) and !isDedicated) then {
  10. isSinglePlayer = true;
  11. };
  12.  
  13. waitUntil{initialized}; //means all the functions are now defined
  14. call build_baseBuilding_arrays;
  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. //Send the key
  55. _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];
  56. _data = "HiveEXT" callExtension _key;
  57.  
  58. diag_log("SERVER: Fetching buildings for instance " + str(dayZ_instance));
  59.  
  60. //Process result
  61. _result = call compile format ["%1", _data];
  62. _status = _result select 0;
  63.  
  64. _bldList = [];
  65. _bldCount = 0;
  66. if (_status == "CustomStreamStart") then {
  67. _val = _result select 1;
  68. for "_i" from 1 to _val do {
  69. _data = "HiveEXT" callExtension _key;
  70. _result = call compile format ["%1",_data];
  71.  
  72. _pos = call compile (_result select 1);
  73. _dir = _pos select 0;
  74. _pos = _pos select 1;
  75.  
  76. _building = createVehicle [_result select 0, _pos, [], 0, "CAN_COLLIDE"];
  77. _building setDir _dir;
  78. _bldCount = _bldCount + 1;
  79. };
  80. diag_log ("SERVER: Spawned " + str(_bldCount) + " buildings!");
  81. };
  82.  
  83.  
  84. for "_i" from 1 to 5 do {
  85. diag_log "HIVE: trying to get objects";
  86. _key = format["CHILD:302:%1:", dayZ_instance];
  87. _hiveResponse = _key call server_hiveReadWrite;
  88. if ((((isnil "_hiveResponse") || {(typeName _hiveResponse != "ARRAY")}) || {((typeName (_hiveResponse select 1)) != "SCALAR")}) || {(_hiveResponse select 1 > 2000)}) then {
  89. if (!isNil "_hiveResponse") then {
  90. diag_log ("HIVE: connection problem... HiveExt response:"+str(_hiveResponse));
  91. } else {
  92. diag_log ("HIVE: connection problem... HiveExt NIL response:");
  93. };
  94. _hiveResponse = ["",0];
  95. } else {
  96. diag_log ("HIVE: found "+str(_hiveResponse select 1)+" objects" );
  97. _i = 99; // break
  98. };
  99. };
  100.  
  101. _objectArray = [];
  102. if ((_hiveResponse select 0) == "ObjectStreamStart") then {
  103. _objectCount = _hiveResponse select 1;
  104. diag_log ("HIVE: Commence Object Streaming...");
  105. for "_i" from 1 to _objectCount do {
  106. _hiveResponse = _key call server_hiveReadWrite;
  107. _objectArray set [_i - 1, _hiveResponse];
  108. //diag_log (format["HIVE dbg %1 %2", typeName _hiveResponse, _hiveResponse]);
  109. };
  110. diag_log ("HIVE: got " + str(count _objectArray) + " objects");
  111. #ifdef EMPTY_TENTS_CHECK
  112. // check empty tents, remove some of them
  113. [_objectArray, EMPTY_TENTS_GLOBAL_LIMIT, EMPTY_TENTS_USER_LIMIT] call fa_removeExtraTents;
  114. #endif
  115. // check vehicles count
  116. [_objectArray] call fa_checkVehicles;
  117. };
  118.  
  119. {
  120.  
  121. _action = _x select 0; // values : "OBJ"=object got from hive "CREATED"=vehicle just created ...
  122. _ObjectID = _x select 1;
  123. _class = if ((typeName (_x select 2)) == "STRING") then { _x select 2 } else { "Old_bike_TK_CIV_EP1" };
  124. _CharacterID = _x select 3;
  125. _worldspace = if ((typeName (_x select 4)) == "ARRAY") then { _x select 4 } else { [] };
  126. _inventory= if ((typeName (_x select 5)) == "ARRAY") then { _x select 5 } else { [] };
  127. _hitpoints= if ((typeName (_x select 6)) == "ARRAY") then { _x select 6 } else { [] };
  128. _fuel = if ((typeName (_x select 7)) == "SCALAR") then { _x select 7 } else { 0 };
  129. _damage = if ((typeName (_x select 8)) == "SCALAR") then { _x select 8 } else { 0.9 };
  130. _entity = nil;
  131.  
  132. _dir = floor(random(360));
  133. _point = getMarkerpos "respawn_west";
  134. if (count _worldspace >= 1 && {(typeName (_worldspace select 0)) == "SCALAR"}) then {
  135. _dir = _worldspace select 0;
  136. };
  137. if (count _worldspace == 2 && {(typeName (_worldspace select 1)) == "ARRAY"}) then {
  138. _i = _worldspace select 1;
  139. if (count _i == 3 &&
  140. {(typeName (_i select 0)) == "SCALAR"} &&
  141. {(typeName (_i select 1)) == "SCALAR"} &&
  142. {(typeName (_i select 2)) == "SCALAR"}) then {
  143. _point = _i;
  144. };
  145. };
  146.  
  147. // if legit vehicle
  148. if ((_class isKindOf "AllVehicles") && ((_CharacterID == "0") OR (_CharacterID == "1")) && (_damage < 1)) then {
  149. //_damage=0.86;//_action="CREATED";
  150. _point set [2, 0]; // here _point is in ATL format
  151. // check for no collision with world. Find a suitable place (depending of defined parameters)
  152. _worldspace = [_class, _dir, _point, _action] call fa_smartlocation;
  153. if (count _worldspace < 2) then { // safe position NOT found
  154. _action = "FAILED"; // don't worry, maybe we will find a nice spot next time :)
  155. }
  156. else { // found a spot for respawn
  157. if ((([_worldspace select 1, _point] call BIS_fnc_distance2D) > 1)
  158. AND (_action == "OBJ")) then { _action = "MOVED"; };
  159. _dir = _worldspace select 0;
  160. _point = _worldspace select 1;
  161. _entity = createVehicle [_class, _point, [], 0,
  162. if ((_class isKindOf "Air") OR {(_action != "OBJ")}) then {"NONE"} else {"CAN_COLLIDE"}
  163. ];
  164. _entity setVariable ["ObjectID", _ObjectID, true]; // this variable must be set very early
  165. _entity setVariable ["CharacterID", _CharacterID, true];
  166. _entity setVariable ["lastUpdate",time]; // prevent immediate hive write when vehicle parts are set up
  167. // setPos will be done again just after setDir, see below....
  168. _entity setDamage _damage;
  169. {
  170. _wantExplosiveParts = _x;
  171. {
  172. _selection = _x select 0;
  173. _dam = _x select 1;
  174. if (_selection in dayZ_explosiveParts) then {
  175. if (_wantExplosiveParts) then {
  176. if (_dam > 0.8) then { _dam = 0.8; };
  177. [_entity, _selection, _dam] call fnc_veh_handleDam;
  178. };
  179. }
  180. else {
  181. if (!_wantExplosiveParts) then {
  182. [_entity, _selection, _dam] call fnc_veh_handleDam;
  183. };
  184. };
  185. } forEach _hitpoints;
  186. } forEach [false, true]; // we set non explosive part first, then explosive parts
  187. _entity setvelocity [0,0,1];
  188. _entity setFuel _fuel;
  189. _entity call fnc_veh_ResetEH;
  190. };
  191. #ifdef OBJECT_DEBUG
  192. diag_log (format["VEHICLE %1 %2 at %3, original damage=%4, effective damage=%6, fuel=%5",
  193. _action, _entity call fa_veh2str, (getPosASL _entity) call fa_coor2str, _damage, _fuel, damage _entity]); // , hitpoints:%6, inventory=%7" , _hitpoints, _inventory
  194. #endif
  195. }
  196. else { // else for object or non legit vehicle
  197. if (!(_class in SafeObjects )) then {
  198. _damage = 1;
  199. };
  200. if (_damage < 1) then {
  201. // Rule #1: Tents will be always spawned if non empty.
  202. // Rule #2: Objects are not spawned if inside/close to building.
  203. // Rule #3: Rule #1 is higher priority
  204. _booleans=[];
  205. _worldspace = [_class, _point, _booleans] call fn_niceSpot;
  206. if (_booleans select 3) then { // is in building
  207. if ((_class != "TentStorage") OR {(_inventory call fa_tentEmpty)}) then {
  208. _action = "FAILED";
  209. _damage = 5;
  210. #ifdef OBJECT_DEBUG
  211. 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]);
  212. #endif
  213. };
  214. };
  215. };
  216. if (_damage < 1) then { // create object
  217. // for tents: non colliding position
  218. _entity = createVehicle [_class, _point, [], 0,
  219. if (_class=="TentStorage") then {"NONE"} else {"CAN_COLLIDE"}
  220. ];
  221. _entity setVariable ["ObjectID", _ObjectID, true];
  222. _entity setVariable ["CharacterID", _CharacterID, true];
  223. _entity setVariable ["lastUpdate",time];
  224. _entity setDamage _damage;
  225.  
  226. if (_class == "TentStorage" || _class == "CamoNet_DZ") then {
  227. _entity addMPEventHandler ["MPKilled",{_this call vehicle_handleServerKilled;}];
  228. };
  229. //diag_log ("DW_DEBUG " + _class + " #" + str(_ObjectID) + " pos=" + (_point call fa_coor2str) + ", damage=" + str(_damage) );
  230. // ##### BASE BUILDING 1.2 Server Side ##### - START
  231. // This sets objects to appear properly once server restarts
  232. //_object setVariable ["ObjectUID", _worldspace call dayz_objectUID2, true]; // Optional (REMOVE // lines before _object) May fix DayZ.ST issues, or issues related to Panel codes not working thanks nullpo
  233. if ((_class == "Static") && !(_class == "TentStorage")) then {
  234. _entity setpos [(getposATL _entity select 0),(getposATL _entity select 1), 0];
  235. };
  236. //Set Variable
  237. if ((_class == "Infostand_2_EP1") && !(_class == "Infostand_1_EP1")) then {
  238. _entity setVariable ["ObjectUID", _ObjectID, true];
  239. };
  240.  
  241.  
  242. // Set whether or not buildable is destructable
  243. if (typeOf(_entity) in allbuildables_class) then {
  244. diag_log ("SERVER: in allbuildables_class:" + typeOf(_entity) + " !");
  245. for "_i" from 0 to ((count allbuildables) - 1) do
  246. {
  247. _classname = (allbuildables select _i) select _i - _i + 1;
  248. _result = [_classname,typeOf(_entity)] call BIS_fnc_areEqual;
  249. if (_result) then {
  250. _requirements = (allbuildables select _i) select _i - _i + 2;
  251.  
  252. _isDestructable = _requirements select 13;
  253. diag_log ("SERVER: " + typeOf(_entity) + " _isDestructable = " + str(_isDestructable));
  254. if (!_isDestructable) then {
  255. diag_log("Spawned: " + typeOf(_entity) + " Handle Damage False");
  256. _entity addEventHandler ["HandleDamage", {false}];
  257. };
  258. };
  259. };
  260. //gateKeypad = _entity addaction ["Defuse", "\z\addons\dayz_server\compile\enterCode.sqf"];
  261. };
  262. // This sets objects to appear properly once server restarts
  263. // ##### BASE BUILDING 1.2 Server Side ##### - END
  264. }
  265. else { // delete object -- this has been comented out: object are never really deleted from hive
  266. /* _key = format["CHILD:306:%1:%2:%3:", _ObjectID, [], 1];
  267. _rawData = "HiveEXT" callExtension _key;
  268. _key = format["CHILD:304:%1:",_ObjectID]; // delete by ID (not UID which is handler 310)
  269. _rawData = "HiveEXT" callExtension _key;*/
  270. #ifdef OBJECT_DEBUG
  271. diag_log (format["IGNORED %1 oid#%2 cid:%3 ",
  272. _class, _ObjectID, _CharacterID ]);
  273. #endif
  274. };
  275. };
  276. //diag_log(format["VEH MAINTENANCE DEBUG %1 %2", __FILE__, __LINE__]);
  277.  
  278. // common code (vehicle or not)
  279. if (_damage < 1 AND !(isNil ("_entity"))) then {
  280. _entity setdir _dir;
  281. _entity setPos _point;
  282.  
  283. if (_entity isKindOf "TrapItems") then {
  284. _entity setVariable ["armed", _inventory select 0, false];
  285. } else {
  286. [_entity, _inventory] call fa_populateCargo;
  287. };
  288.  
  289. dayz_serverObjectMonitor set [count dayz_serverObjectMonitor, _entity];
  290.  
  291. // UPDATE MODIFIED OBJECTS TO THE HIVE
  292. if (_action == "CREATED") then {
  293. // insert className damage characterId worldSpace inventory hitPoints fuel uniqueId
  294. _key = format["CHILD:308:%1:%2:%3:%4:%5:%6:%7:%8:%9:", dayZ_instance,
  295. _class, _damage , 1,
  296. [_dir, _point],
  297. [getWeaponCargo _entity, getMagazineCargo _entity ,getBackpackCargo _entity],
  298. _hitpoints, _fuel, _ObjectID
  299. ];
  300. //diag_log (_key);
  301. _rawData = "HiveEXT" callExtension _key;
  302. };
  303. if (_action == "SPAWNED" || _action == "DAMAGED") then {
  304. // update hitpoint,damage -- already done by needupdate
  305. /*_key = format["CHILD:306:%1:%2:%3:", _ObjectID, _hitpoints, _damage];
  306. _rawData = "HiveEXT" callExtension _key;*/
  307. };
  308. if (_action == "SPAWNED") then {
  309. // update inventory
  310. _key = format["CHILD:309:%1:%2:", _ObjectID,
  311. [getWeaponCargo _entity, getMagazineCargo _entity, getBackpackCargo _entity]];
  312. _rawData = "HiveEXT" callExtension _key;
  313. };
  314. if (_action == "MOVED" || _action == "SPAWNED") then {
  315. // update position,fuel in Hive
  316. // already done by server_updateObject?
  317. /*_key = format["CHILD:305:%1:%2:%3:", _ObjectID, [_dir, _point], _fuel];
  318. _rawData = "HiveEXT" callExtension _key;*/
  319. //Updated object position if moved
  320. [_entity, "position"] call server_updateObject;
  321. };
  322. }; // not damaged
  323. sleep 0.01; // yield to connecting players.
  324. } forEach _objectArray;
  325.  
  326. createCenter civilian;
  327. if (isDedicated) then {
  328. endLoadingScreen;
  329. };
  330.  
  331. if (isDedicated) then {
  332. _id = [] execFSM "\z\addons\dayz_server\system\server_cleanup.fsm";
  333. };
  334.  
  335. allowConnection = true;
  336.  
  337. // [_guaranteedLoot, _randomizedLoot, spawnOnStart, _frequency, _variance, _spawnChance, _spawnMarker, _spawnRadius, _spawnFire, _fadeFire]
  338. [3, 4, 3, (40 * 60), (15 * 60), 0.75, 'center', 4000, true, false] spawn server_spawnCrashSite;
  339.  
  340. // antiwallhack
  341. call compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fa_antiwallhack.sqf";
  342.  
  343. //Spawn camps
  344. // quantity, marker, radius, min distance between 2 camps
  345. Server_InfectedCamps = [3, "center", 4500, 2000] call fn_bases;
  346. dayzInfectedCamps = Server_InfectedCamps;
  347. publicVariable "dayzInfectedCamps";
  348.  
  349. sm_done = true;
  350. publicVariable "sm_done";
  351.  
  352. [300] call server_plantSpawner;
  353.  
  354. //if (isDedicated) then {
  355. //Wild Zeds Ownership isnt working as expected yet
  356. // execFSM "\z\addons\dayz_server\system\zombie_wildagent.fsm";
  357. //};
  358. // Trap loop
  359. [] call {
  360. private ["_array","_array2","_array3","_script","_armed"];
  361. _array = str dayz_traps;
  362. _array2 = str dayz_traps_active;
  363. _array3 = str dayz_traps_trigger;
  364.  
  365. while { true } do {
  366. if ((str dayz_traps != _array) || (str dayz_traps_active != _array2) || (str dayz_traps_trigger != _array3)) then {
  367. _array = str dayz_traps;
  368. _array2 = str dayz_traps_active;
  369. _array3 = str dayz_traps_trigger;
  370.  
  371. diag_log "DEBUG: traps";
  372. diag_log format["dayz_traps (%2) -> %1", dayz_traps, count dayz_traps];
  373. diag_log format["dayz_traps_active (%2) -> %1", dayz_traps_active, count dayz_traps_active];
  374. diag_log format["dayz_traps_trigger (%2) -> %1", dayz_traps_trigger, count dayz_traps_trigger];
  375. diag_log "DEBUG: end traps";
  376. };
  377.  
  378. {
  379. if (isNull _x) then {
  380. dayz_traps = dayz_traps - [_x];
  381. };
  382.  
  383. _script = call compile getText (configFile >> "CfgVehicles" >> typeOf _x >> "script");
  384. _armed = _x getVariable ["armed", false];
  385.  
  386. if (_armed) then {
  387. if !(_x in dayz_traps_active) then {
  388. ["arm", _x] call _script;
  389. };
  390. } else {
  391. if (_x in dayz_traps_active) then {
  392. ["disarm", _x] call _script;
  393. };
  394. };
  395.  
  396. //sleep 0.01;
  397. } forEach dayz_traps;
  398. };
  399. };
  400. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement