Guest User

Untitled

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