Advertisement
Guest User

server_monitor.sqf

a guest
Sep 9th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.99 KB | None | 0 0
  1. []execVM "\z\addons\dayz_server\system\s_fps.sqf"; //server monitor FPS (writes each ~181s diag_fps+181s diag_fpsmin*)
  2. #include "\z\addons\dayz_server\compile\server_toggle_debug.hpp"
  3.  
  4. dayz_versionNo = getText(configFile >> "CfgMods" >> "DayZ" >> "version");
  5. dayz_hiveVersionNo = getNumber(configFile >> "CfgMods" >> "DayZ" >> "hiveVersion");
  6. _script = getText(missionConfigFile >> "onPauseScript");
  7.  
  8. if ((count playableUnits == 0) and !isDedicated) then {
  9. isSinglePlayer = true;
  10. };
  11.  
  12. waitUntil{initialized}; //means all the functions are now defined
  13. call build_baseBuilding_arrays;
  14. diag_log "HIVE: Starting";
  15.  
  16. //Set the Time
  17. //Send request
  18. _key = "CHILD:307:";
  19. _result = _key call server_hiveReadWrite;
  20. _outcome = _result select 0;
  21. if(_outcome == "PASS") then {
  22. _date = _result select 1;
  23.  
  24. //date setup
  25. _year = _date select 0;
  26. _month = _date select 1;
  27. _day = _date select 2;
  28. _hour = _date select 3;
  29. _minute = _date select 4;
  30.  
  31. //Force full moon nights
  32. _date = [2012,6,6,_hour,_minute];
  33.  
  34. if(isDedicated) then {
  35. //["dayzSetDate",_date] call broadcastRpcCallAll;
  36. setDate _date;
  37. dayzSetDate = _date;
  38. publicVariable "dayzSetDate";
  39. };
  40. diag_log ("HIVE: Local Time set to " + str(_date));
  41. };
  42.  
  43. //Send the key
  44. _key = format["CHILD:999:select payload, loop_interval, start_delay from message where instance_id = ?:[%1]:", dayZ_instance];
  45. _data = "HiveEXT" callExtension _key;
  46.  
  47. diag_log("SERVER: Fetching messages...");
  48.  
  49. //Process result
  50. _result = call compile format ["%1", _data];
  51. _status = _result select 0;
  52.  
  53. msgList = [];
  54. _msgCount = 0;
  55. if (_status == "CustomStreamStart") then {
  56. _val = _result select 1;
  57. for "_i" from 1 to _val do {
  58. _data = "HiveEXT" callExtension _key;
  59. _result = call compile format ["%1",_data];
  60.  
  61. _status = _result select 0;
  62. msgList set [count msgList, _result];
  63. _msgCount = _msgCount + 1;
  64. };
  65. diag_log ("SERVER: Added " + str(_msgCount) + " messages!");
  66. };
  67.  
  68. //Stream in objects
  69. /* STREAM OBJECTS
  70. //Send the key
  71. _key = format["CHILD:302:%1:",dayZ_instance];
  72. _result = _key call server_hiveReadWrite;
  73.  
  74. diag_log "HIVE: Request sent";
  75.  
  76. //Process result
  77. _status = _result select 0;
  78.  
  79. _myArray = [];
  80. if (_status == "ObjectStreamStart") then {
  81. _val = _result select 1;
  82. //Stream Objects
  83. diag_log ("HIVE: Commence Object Streaming...");
  84. for "_i" from 1 to _val do {
  85. _result = _key call server_hiveReadWrite;
  86.  
  87. _status = _result select 0;
  88. _myArray set [count _myArray,_result];
  89. //diag_log ("HIVE: Loop ");
  90. };
  91. //diag_log ("HIVE: Streamed " + str(_val) + " objects");
  92. };
  93.  
  94. _countr = 0;
  95. {
  96.  
  97. //Parse Array
  98. _countr = _countr + 1;
  99.  
  100. _idKey = _x select 1;
  101. _type = _x select 2;
  102. _ownerID = _x select 3;
  103. _worldspace = _x select 4;
  104. _inventory= _x select 5;
  105. _hitPoints= _x select 6;
  106. _fuel = _x select 7;
  107. _damage = _x select 8;
  108.  
  109. _dir = 0;
  110. _pos = [0,0,0];
  111. _wsDone = false;
  112. if (count _worldspace >= 2) then
  113. {
  114. _dir = _worldspace select 0;
  115. if (count (_worldspace select 1) == 3) then {
  116. _pos = _worldspace select 1;
  117. _wsDone = true;
  118. }
  119. };
  120.  
  121. if (!_wsDone) then {
  122. if (count _worldspace >= 1) then { _dir = _worldspace select 0; };
  123. _objectPos = [_worldspace select 1 select 0,_worldspace select 1 select 1,0];
  124. _pos = [(_objectPos),0,15,1,0,2000,0,[],[_objectPos,[]]] call BIS_fnc_findSafePos;
  125. if (count _pos < 3) then { _pos = [_pos select 0,_pos select 1,0]; };
  126. diag_log ("MOVED OBJ: " + str(_idKey) + " of class " + _type + " to pos: " + str(_pos));
  127. };
  128.  
  129. if (_damage < 1) then {
  130. diag_log format["OBJ: %1 - %2", _idKey,_type];
  131.  
  132. //Create it
  133. _object = createVehicle [_type, _pos, [], 0, "CAN_COLLIDE"];
  134. _object setVariable ["lastUpdate",time];
  135. _object setVariable ["ObjectID", _idKey, true];
  136. _object setVariable ["CharacterID", _ownerID, true];
  137.  
  138. clearWeaponCargoGlobal _object;
  139. clearMagazineCargoGlobal _object;
  140.  
  141. if (_object isKindOf "TentStorage") then {
  142. _pos set [2,0];
  143. _object setpos _pos;
  144. _object addMPEventHandler ["MPKilled",{_this call vehicle_handleServerKilled;}];
  145. };
  146. _object setdir _dir;
  147. _object setDamage _damage;
  148.  
  149. if (count _inventory > 0) then {
  150. //Add weapons
  151. _objWpnTypes = (_inventory select 0) select 0;
  152. _objWpnQty = (_inventory select 0) select 1;
  153. _countr = 0;
  154. {
  155. if (_x == "Crossbow") then { _x = "Crossbow_DZ" }; // Convert Crossbow to Crossbow_DZ
  156. _isOK = isClass(configFile >> "CfgWeapons" >> _x);
  157. if (_isOK) then {
  158. _block = getNumber(configFile >> "CfgWeapons" >> _x >> "stopThis") == 1;
  159. if (!_block) then {
  160. _object addWeaponCargoGlobal [_x,(_objWpnQty select _countr)];
  161. };
  162. };
  163. _countr = _countr + 1;
  164. } forEach _objWpnTypes;
  165.  
  166. //Add Magazines
  167. _objWpnTypes = (_inventory select 1) select 0;
  168. _objWpnQty = (_inventory select 1) select 1;
  169. _countr = 0;
  170. {
  171. if (_x == "BoltSteel") then { _x = "WoodenArrow" }; // Convert BoltSteel to WoodenArrow
  172. _isOK = isClass(configFile >> "CfgMagazines" >> _x);
  173. if (_isOK) then {
  174. _block = getNumber(configFile >> "CfgMagazines" >> _x >> "stopThis") == 1;
  175. if (!_block) then {
  176. _object addMagazineCargoGlobal [_x,(_objWpnQty select _countr)];
  177. };
  178. };
  179. _countr = _countr + 1;
  180. } forEach _objWpnTypes;
  181.  
  182. //Add Backpacks
  183. _objWpnTypes = (_inventory select 2) select 0;
  184. _objWpnQty = (_inventory select 2) select 1;
  185. _countr = 0;
  186. {
  187. _isOK = isClass(configFile >> "CfgVehicles" >> _x);
  188. if (_isOK) then {
  189. _block = getNumber(configFile >> "CfgVehicles" >> _x >> "stopThis") == 1;
  190. if (!_block) then {
  191. _object addBackpackCargoGlobal [_x,(_objWpnQty select _countr)];
  192. };
  193. };
  194. _countr = _countr + 1;
  195. } forEach _objWpnTypes;
  196. };
  197.  
  198. if (_object isKindOf "AllVehicles") then {
  199. {
  200. _selection = _x select 0;
  201. _dam = _x select 1;
  202. if (_selection in dayZ_explosiveParts and _dam > 0.8) then {_dam = 0.8};
  203. [_object,_selection,_dam] call fnc_veh_handleRepair;
  204. } forEach _hitpoints;
  205. _object setvelocity [0,0,1];
  206. _object setFuel _fuel;
  207. _object call fnc_veh_ResetEH;
  208. //Updated object position if moved
  209. if (!_wsDone) then {
  210. [_object, "position"] call server_updateObject;
  211. };
  212. };
  213.  
  214. //Monitor the object
  215. //_object enableSimulation false;
  216. dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,_object];
  217. };
  218. } forEach _myArray;
  219.  
  220. // # END OF STREAMING #
  221. */
  222. waituntil{isNil "sm_done"}; // prevent server_monitor be called twice (bug during login of the first player)
  223.  
  224. #include "\z\addons\dayz_server\compile\fa_hiveMaintenance.hpp"
  225.  
  226. if (isServer and isNil "sm_done") then {
  227. private["_i","_hiveResponse","_key","_objectArray","_objectCount"];
  228.  
  229. for "_i" from 1 to 5 do {
  230. diag_log "HIVE: trying to get objects";
  231. _key = format["CHILD:302:%1:", dayZ_instance];
  232. _hiveResponse = _key call server_hiveReadWrite;
  233. if ((((isnil "_hiveResponse") || {(typeName _hiveResponse != "ARRAY")}) || {((typeName (_hiveResponse select 1)) != "SCALAR")}) || {(_hiveResponse select 1 > 2000)}) then {
  234. diag_log ("HIVE: connection problem... HiveExt response:"+str(_hiveResponse));
  235. _hiveResponse = ["",0];
  236. }
  237. else {
  238. diag_log ("HIVE: found "+str(_hiveResponse select 1)+" objects" );
  239. _i = 99; // break
  240. };
  241. };
  242.  
  243. _objectArray = [];
  244. if ((_hiveResponse select 0) == "ObjectStreamStart") then {
  245. _objectCount = _hiveResponse select 1;
  246. diag_log ("HIVE: Commence Object Streaming...");
  247. for "_i" from 1 to _objectCount do {
  248. _hiveResponse = _key call server_hiveReadWrite;
  249. _objectArray set [_i - 1, _hiveResponse];
  250. //diag_log (format["HIVE dbg %1 %2", typeName _hiveResponse, _hiveResponse]);
  251. };
  252. diag_log ("HIVE: got " + str(count _objectArray) + " objects");
  253. #ifdef EMPTY_TENTS_CHECK
  254. // check empty tents, remove some of them
  255. [_objectArray, EMPTY_TENTS_GLOBAL_LIMIT, EMPTY_TENTS_USER_LIMIT] call fa_removeExtraTents;
  256. #endif
  257. // check vehicles count
  258. [_objectArray] call fa_checkVehicles;
  259. };
  260.  
  261. {
  262. private["_action","_ObjectID","_class","_CharacterID","_worldspace","_inventory", "_hitpoints","_fuel","_damage","_entity","_dir","_point","_res", "_rawData","_class","_worldspace","_uid", "_selection", "_dam", "_booleans", "_point", "_wantExplosiveParts"];
  263.  
  264. _action = _x select 0; // values : "OBJ"=object got from hive "CREATED"=vehicle just created ...
  265. _ObjectID = _x select 1;
  266. _class = if ((typeName (_x select 2)) == "STRING") then { _x select 2 } else { "Old_bike_TK_CIV_EP1" };
  267. _CharacterID = _x select 3;
  268. _worldspace = if ((typeName (_x select 4)) == "ARRAY") then { _x select 4 } else { [] };
  269. _inventory= if ((typeName (_x select 5)) == "ARRAY") then { _x select 5 } else { [] };
  270. _hitpoints= if ((typeName (_x select 6)) == "ARRAY") then { _x select 6 } else { [] };
  271. _fuel = if ((typeName (_x select 7)) == "SCALAR") then { _x select 7 } else { 0 };
  272. _damage = if ((typeName (_x select 8)) == "SCALAR") then { _x select 8 } else { 0.9 };
  273. _entity = nil;
  274.  
  275. _dir = floor(random(360));
  276. _point = getMarkerpos "respawn_west";
  277. if (count _worldspace >= 1 && {(typeName (_worldspace select 0)) == "SCALAR"}) then {
  278. _dir = _worldspace select 0;
  279. };
  280. if (count _worldspace == 2 && {(typeName (_worldspace select 1)) == "ARRAY"}) then {
  281. _i = _worldspace select 1;
  282. if (count _i == 3 &&
  283. {(typeName (_i select 0)) == "SCALAR"} &&
  284. {(typeName (_i select 1)) == "SCALAR"} &&
  285. {(typeName (_i select 2)) == "SCALAR"}) then {
  286. _point = _i;
  287. };
  288. };
  289.  
  290. // if legit vehicle
  291. if ((_class isKindOf "AllVehicles") && ((_CharacterID == "0") OR (_CharacterID == "1")) && (_damage < 1)) then {
  292. //_damage=0.86;//_action="CREATED";
  293. _point set [2, 0]; // here _point is in ATL format
  294. #ifdef VEH_MAINTENANCE_ROTTEN_AT_STARTUP
  295. // rotten randomly the vehicle. Successive damages will lead to a respawn.
  296. if ((random(VEH_MAINTENANCE_ROTTEN_AT_STARTUP) < 1) AND {(_action == "OBJ")}) then {
  297. _damage = VEH_MAINTENANCE_ROTTEN_LOGIC; _action = "DAMAGED";
  298. };
  299. #endif
  300. #ifdef VEH_MAINTENANCE_ADD_MISSING
  301.  
  302. // ask to create a new vehicle if damage is too high
  303. if (_damage > 0.85 AND (_action != "CREATED")) then { _action = "SPAWNED"; };
  304. #endif
  305. // check for no collision with world. Find a suitable place (depending of defined parameters)
  306. _worldspace = [_class, _dir, _point, _action] call fa_smartlocation;
  307. if (count _worldspace < 2) then { // safe position NOT found
  308. _action = "FAILED"; // don't worry, maybe we will find a nice spot next time :)
  309. }
  310. else { // found a spot for respawn
  311. if ((([_worldspace select 1, _point] call BIS_fnc_distance2D) > 1)
  312. AND (_action == "OBJ")) then { _action = "MOVED"; };
  313. _dir = _worldspace select 0;
  314. _point = _worldspace select 1;
  315. _entity = createVehicle [_class, _point, [], 0,
  316. if ((_class isKindOf "Air") OR {(_action != "OBJ")}) then {"NONE"} else {"CAN_COLLIDE"}
  317. ];
  318. _entity setVariable ["ObjectID", _ObjectID, true]; // this variable must be set very early
  319. _entity setVariable ["CharacterID", _CharacterID, true];
  320. _entity setVariable ["lastUpdate",time]; // prevent immediate hive write when vehicle parts are set up
  321. // setPos will be done again just after setDir, see below....
  322. #ifdef VEH_MAINTENANCE_ADD_MISSING
  323. if (_damage > 0.85) then {
  324. _fuel = VEH_MAINTENANCE_SPAWN_FUEL_LOGIC;
  325. _hitpoints = [];
  326. _damage = _hitpoints call fa_setDamagedParts;
  327.  
  328. _inventory = []; // TODO: rewrite this inventory setup.
  329. //diag_log (format["VEH MAINTENANCE Creating vehicle Inventory:%1 and Damaged parts:%2", _inventory, _hitpoints]);
  330. };
  331. #endif
  332. _entity setDamage _damage;
  333. {
  334. _wantExplosiveParts = _x;
  335. {
  336. _selection = _x select 0;
  337. _dam = _x select 1;
  338. if (_selection in dayZ_explosiveParts) then {
  339. if (_wantExplosiveParts) then {
  340. if (_dam > 0.8) then { _dam = 0.8; };
  341. [_entity, _selection, _dam] call fnc_veh_handleDam;
  342. };
  343. }
  344. else {
  345. if (!_wantExplosiveParts) then {
  346. [_entity, _selection, _dam] call fnc_veh_handleDam;
  347. };
  348. };
  349. } forEach _hitpoints;
  350. } forEach [false, true]; // we set non explosive part first, then explosive parts
  351. _entity setvelocity [0,0,1];
  352. _entity setFuel _fuel;
  353. _entity call fnc_veh_ResetEH;
  354. };
  355. #ifdef OBJECT_DEBUG
  356. diag_log (format["VEHICLE %1 %2 at %3, original damage=%4, effective damage=%6, fuel=%5",
  357. _action, _entity call fa_veh2str, (getPosASL _entity) call fa_coor2str, _damage, _fuel, damage _entity]); // , hitpoints:%6, inventory=%7" , _hitpoints, _inventory
  358. #endif
  359. }
  360. else { // else for object or non legit vehicle
  361. if (!(_class in SafeObjects )) then {
  362. _damage = 1;
  363. };
  364. if (_damage < 1) then {
  365. // Rule #1: Tents will be always spawned if non empty.
  366. // Rule #2: Objects are not spawned if inside/close to building.
  367. // Rule #3: Rule #1 is higher priority
  368. _booleans=[];
  369. _worldspace = [_class, _point, _booleans] call fn_niceSpot;
  370. if (_booleans select 3) then { // is in building
  371. if ((_class != "TentStorage") OR {(_inventory call fa_tentEmpty)}) then {
  372. _action = "FAILED";
  373. _damage = 5;
  374. #ifdef OBJECT_DEBUG
  375. 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]);
  376. #endif
  377. };
  378. };
  379. };
  380. if (_damage < 1) then { // create object
  381. #ifdef OBJECTS_FIX_OUTOFMAP
  382. _worldspace = [_dir, _point] call fa_staywithus;
  383. _dir = _worldspace select 0;
  384. _point = _worldspace select 1;
  385. #endif
  386. // for tents: non colliding position
  387. _entity = createVehicle [_class, _point, [], 0,
  388. if (_class=="TentStorage") then {"NONE"} else {"CAN_COLLIDE"}
  389. ];
  390. if (_CharacterID == "0") then {
  391. _entity setVariable ["ObjectID", _ObjectID, true];
  392. } else {
  393. _entity setVariable ["ObjectUID", _ObjectID, true];
  394. };
  395. _entity setVariable ["CharacterID", _CharacterID, true];
  396. _entity setVariable ["lastUpdate",time];
  397. _entity setDamage _damage;
  398.  
  399. if (_class == "TentStorage") then {
  400. _entity addMPEventHandler ["MPKilled",{_this call vehicle_handleServerKilled;}];
  401. };
  402. //diag_log ("DW_DEBUG " + _class + " #" + str(_ObjectID) + " pos=" + (_point call fa_coor2str) + ", damage=" + str(_damage) );
  403. }
  404. else { // delete object -- this has been comented out: object are never really deleted from hive
  405. /* _key = format["CHILD:306:%1:%2:%3:", _ObjectID, [], 1];
  406. _rawData = "HiveEXT" callExtension _key;
  407. _key = format["CHILD:304:%1:",_ObjectID]; // delete by ID (not UID which is handler 310)
  408. _rawData = "HiveEXT" callExtension _key;*/
  409. #ifdef OBJECT_DEBUG
  410. diag_log (format["IGNORED %1 oid#%2 cid:%3 ",
  411. _class, _ObjectID, _CharacterID ]);
  412. #endif
  413. };
  414. };
  415. //diag_log(format["VEH MAINTENANCE DEBUG %1 %2", __FILE__, __LINE__]);
  416.  
  417. // common code (vehicle or not)
  418. if (_damage < 1 AND !(isNil ("_entity"))) then {
  419. _entity setdir _dir;
  420. _entity setPos _point;
  421. [_entity, _inventory] call fa_populateCargo;
  422.  
  423. dayz_serverObjectMonitor set [count dayz_serverObjectMonitor, _entity];
  424.  
  425. // UPDATE MODIFIED OBJECTS TO THE HIVE
  426. if (_action == "CREATED") then {
  427. // insert className damage characterId worldSpace inventory hitPoints fuel uniqueId
  428. _key = format["CHILD:308:%1:%2:%3:%4:%5:%6:%7:%8:%9:", dayZ_instance,
  429. _class, _damage , 1,
  430. [_dir, _point],
  431. [getWeaponCargo _entity, getMagazineCargo _entity ,getBackpackCargo _entity],
  432. _hitpoints, _fuel, _ObjectID
  433. ];
  434. //diag_log (_key);
  435. _rawData = "HiveEXT" callExtension _key;
  436. };
  437. if (_action == "SPAWNED" || _action == "DAMAGED") then {
  438. // update hitpoint,damage -- already done by needupdate
  439. /*_key = format["CHILD:306:%1:%2:%3:", _ObjectID, _hitpoints, _damage];
  440. _rawData = "HiveEXT" callExtension _key;*/
  441. };
  442. if (_action == "SPAWNED") then {
  443. // update inventory
  444. _key = format["CHILD:309:%1:%2:", _ObjectID,
  445. [getWeaponCargo _entity, getMagazineCargo _entity, getBackpackCargo _entity]];
  446. _rawData = "HiveEXT" callExtension _key;
  447. };
  448. if (_action == "MOVED" || _action == "SPAWNED") then {
  449. // update position,fuel in Hive
  450. // already done by server_updateObject?
  451. /*_key = format["CHILD:305:%1:%2:%3:", _ObjectID, [_dir, _point], _fuel];
  452. _rawData = "HiveEXT" callExtension _key;*/
  453. //Updated object position if moved
  454. [_entity, "position"] call server_updateObject;
  455. };
  456. }; // not damaged
  457. sleep 0.01; // yield to connecting players.
  458. } forEach _objectArray;
  459.  
  460. // Spawn Buildings
  461. //Send the key
  462. _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];
  463. _data = "HiveEXT" callExtension _key;
  464. diag_log("SERVER: Fetching buildings...");
  465.  
  466. //Process result
  467. _result = call compile format ["%1", _data];
  468. _status = _result select 0;
  469.  
  470. _bldList = [];
  471. _bldCount = 0;
  472. if (_status == "CustomStreamStart") then {
  473. _val = _result select 1;
  474. for "_i" from 1 to _val do {
  475. _data = "HiveEXT" callExtension _key;
  476. _result = call compile format ["%1",_data];
  477.  
  478. _pos = call compile (_result select 1);
  479. _dir = _pos select 0;
  480. _pos = _pos select 1;
  481.  
  482. _building = createVehicle [_result select 0, _pos, [], 0, "CAN_COLLIDE"];
  483. _building setDir _dir;
  484. _bldCount = _bldCount + 1;
  485. };
  486. diag_log ("SERVER: Spawned " + str(_bldCount) + " buildings!");
  487. };
  488.  
  489. createCenter civilian;
  490. if (isDedicated) then {
  491. endLoadingScreen;
  492. };
  493.  
  494. if (isDedicated) then {
  495. _id = [] execFSM "\z\addons\dayz_server\system\server_cleanup.fsm";
  496. };
  497.  
  498. allowConnection = true;
  499.  
  500. // [_guaranteedLoot, _randomizedLoot, spawnOnStart, _frequency, _variance, _spawnChance, _spawnMarker, _spawnRadius, _spawnFire, _fadeFire]
  501. [3, 4, 3, (40 * 60), (15 * 60), 0.75, 'center', 4000, true, false] spawn server_spawnCrashSite;
  502.  
  503. //Spawn camps
  504. // quantity, marker, radius, min distance between 2 camps
  505. Server_InfectedCamps = [3, "center", 4500, 2000] call fn_bases;
  506. dayzInfectedCamps = Server_InfectedCamps;
  507. publicVariable "dayzInfectedCamps";
  508.  
  509. // antiwallhack
  510. call compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fa_antiwallhack.sqf";
  511.  
  512. sm_done = true;
  513. publicVariable "sm_done";
  514. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement