Advertisement
Guest User

Untitled

a guest
Aug 24th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.38 KB | None | 0 0
  1. // DayZ Server Controlcenter Server Project
  2.  
  3. // Incude DayZCC specific funtions ---------------------------------------------------------------------------------------
  4. #include "\@dayzcc\addons\dayz_server_config.hpp"
  5.  
  6. // Initialize funtions --------------------------------------------------------------------------------------------------
  7.  
  8. #include "\z\addons\dayz_server\compile\server_toggle_debug.hpp"
  9. dayz_versionNo = getText(configFile >> "CfgMods" >> "DayZ" >> "version");
  10. dayz_hiveVersionNo = getNumber(configFile >> "CfgMods" >> "DayZ" >> "hiveVersion");
  11. dayz_serverVersionNo = "5.9.2.3";
  12. _script = getText(missionConfigFile >> "onPauseScript");
  13.  
  14. if ((count playableUnits == 0) and !isDedicated) then {
  15. isSinglePlayer = true;
  16. };
  17.  
  18. waitUntil{initialized};
  19.  
  20. //All functions are now defind so let's start the server ---------------------------------------------------------------
  21.  
  22. diag_log format ["SERVER STARTING: VERSION: CC %1", dayz_serverVersionNo];
  23. diag_log ("SERVER: WORLD: " + str(worldName));
  24. diag_log ("SERVER: INSTANCE: " + str(dayz_instance));
  25. diag_log ("HIVE: Starting ...");
  26.  
  27. // Set the time --------------------------------------------------------------------------------------------------------
  28.  
  29. _key = "CHILD:307:";
  30. _result = _key call server_hiveReadWrite;
  31. _outcome = _result select 0;
  32. if(_outcome == "PASS") then {
  33. _date = _result select 1;
  34. if(isDedicated) then {
  35. setDate _date;
  36. dayzSetDate = _date;
  37. publicVariable "dayzSetDate";
  38. };
  39. diag_log ("HIVE: Local Time set to " + str(_date));
  40. };
  41.  
  42. // Fetch and spawn buildings ------------------------------------------------------------------------------------------
  43.  
  44. _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];
  45. _data = "HiveEXT" callExtension _key;
  46.  
  47. diag_log("SERVER: Fetching buildings...");
  48. _result = call compile format ["%1", _data];
  49. _status = _result select 0;
  50.  
  51. _bldList = [];
  52. _bldCount = 0;
  53. if (_status == "CustomStreamStart") then {
  54. _val = _result select 1;
  55. for "_i" from 1 to _val do {
  56. _data = "HiveEXT" callExtension _key;
  57. _result = call compile format ["%1",_data];
  58.  
  59. _pos = call compile (_result select 1);
  60. _dir = _pos select 0;
  61. _pos = _pos select 1;
  62.  
  63. _building = createVehicle [_result select 0, _pos, [], 0, "CAN_COLLIDE"];
  64. _building setDir _dir;
  65. _bldCount = _bldCount + 1;
  66. };
  67. diag_log ("SERVER: Spawned " + str(_bldCount) + " buildings!");
  68. };
  69.  
  70. // Hive Maintenance ---------------------------------------------------------------------------------------------------
  71. waituntil{isNil "sm_done"};
  72.  
  73. #include "\z\addons\dayz_server\compile\fa_hiveMaintenance.hpp"
  74.  
  75. if (isServer and isNil "sm_done") then {
  76. private["_i","_hiveResponse","_key","_objectArray","_objectCount"];
  77.  
  78. for "_i" from 1 to 5 do {
  79. diag_log "HIVE: trying to get objects";
  80. _key = format["CHILD:302:%1:", dayZ_instance];
  81. _hiveResponse = _key call server_hiveReadWrite;
  82. if ((((isnil "_hiveResponse") || {(typeName _hiveResponse != "ARRAY")}) || {((typeName (_hiveResponse select 1)) != "SCALAR")}) || {(_hiveResponse select 1 > 2000)}) then {
  83. diag_log ("HIVE: connection problem... HiveExt response:"+str(_hiveResponse));
  84. _hiveResponse = ["",0];
  85. }
  86. else {
  87. diag_log ("HIVE: found "+str(_hiveResponse select 1)+" objects" );
  88. _i = 99;
  89. };
  90. };
  91.  
  92. _objectArray = [];
  93. if ((_hiveResponse select 0) == "ObjectStreamStart") then {
  94. _objectCount = _hiveResponse select 1;
  95. diag_log ("HIVE: Commence Object Streaming...");
  96. for "_i" from 1 to _objectCount do {
  97. _hiveResponse = _key call server_hiveReadWrite;
  98. _objectArray set [_i - 1, _hiveResponse];
  99. };
  100. diag_log ("HIVE: got " + str(count _objectArray) + " objects");
  101. #ifdef EMPTY_TENTS_CHECK
  102. [_objectArray, EMPTY_TENTS_GLOBAL_LIMIT, EMPTY_TENTS_USER_LIMIT] call fa_removeExtraTents;
  103. #endif
  104. [_objectArray] call fa_checkVehicles;
  105. };
  106.  
  107. {
  108. private["_action","_ObjectID","_class","_CharacterID","_worldspace","_inventory", "_hitpoints","_fuel","_damage","_entity","_dir","_point","_res", "_rawData","_class","_worldspace","_uid", "_selection", "_dam", "_booleans", "_point", "_wantExplosiveParts"];
  109.  
  110. _action = _x select 0;
  111. _ObjectID = _x select 1;
  112. _class = if ((typeName (_x select 2)) == "STRING") then { _x select 2 } else { "Old_bike_TK_CIV_EP1" };
  113. _CharacterID = _x select 3;
  114. _worldspace = if ((typeName (_x select 4)) == "ARRAY") then { _x select 4 } else { [] };
  115. _inventory= if ((typeName (_x select 5)) == "ARRAY") then { _x select 5 } else { [] };
  116. _hitpoints= if ((typeName (_x select 6)) == "ARRAY") then { _x select 6 } else { [] };
  117. _fuel = if ((typeName (_x select 7)) == "SCALAR") then { _x select 7 } else { 0 };
  118. _damage = if ((typeName (_x select 8)) == "SCALAR") then { _x select 8 } else { 0.9 };
  119. _entity = nil;
  120.  
  121. _dir = floor(random(360));
  122. _point = getMarkerpos "respawn_west";
  123. if (count _worldspace >= 1 && {(typeName (_worldspace select 0)) == "SCALAR"}) then {
  124. _dir = _worldspace select 0;
  125. };
  126. if (count _worldspace == 2 && {(typeName (_worldspace select 1)) == "ARRAY"}) then {
  127. _i = _worldspace select 1;
  128. if (count _i == 3 &&
  129. {(typeName (_i select 0)) == "SCALAR"} &&
  130. {(typeName (_i select 1)) == "SCALAR"} &&
  131. {(typeName (_i select 2)) == "SCALAR"}) then {
  132. _point = _i;
  133. };
  134. };
  135.  
  136. if ((_class isKindOf "AllVehicles") && ((_CharacterID == "0") OR (_CharacterID == "1")) && (_damage < 1)) then {
  137. _point set [2, 0];
  138. #ifdef VEH_MAINTENANCE_ROTTEN_AT_STARTUP
  139. if ((random(VEH_MAINTENANCE_ROTTEN_AT_STARTUP) < 1) AND {(_action == "OBJ")}) then {
  140. _damage = VEH_MAINTENANCE_ROTTEN_LOGIC; _action = "DAMAGED";
  141. };
  142. #endif
  143. #ifdef VEH_MAINTENANCE_ADD_MISSING
  144.  
  145. // ask to create a new vehicle if damage is too high
  146. if (_damage > 0.85 AND (_action != "CREATED")) then { _action = "SPAWNED"; };
  147. #endif
  148. // check for no collision with world. Find a suitable place (depending of defined parameters)
  149. _worldspace = [_class, _dir, _point, _action] call fa_smartlocation;
  150. if (count _worldspace < 2) then { // safe position NOT found
  151. _action = "FAILED"; // don't worry, maybe we will find a nice spot next time :)
  152. }
  153. else { // found a spot for respawn
  154. if ((([_worldspace select 1, _point] call BIS_fnc_distance2D) > 1)
  155. AND (_action == "OBJ")) then { _action = "MOVED"; };
  156. _dir = _worldspace select 0;
  157. _point = _worldspace select 1;
  158. _entity = createVehicle [_class, _point, [], 0,
  159. if ((_class isKindOf "Air") OR {(_action != "OBJ")}) then {"NONE"} else {"CAN_COLLIDE"}
  160. ];
  161. _entity setVariable ["ObjectID", _ObjectID, true]; // this variable must be set very early
  162. _entity setVariable ["CharacterID", _CharacterID, true];
  163. _entity setVariable ["lastUpdate",time]; // prevent immediate hive write when vehicle parts are set up
  164. // setPos will be done again just after setDir, see below....
  165. #ifdef VEH_MAINTENANCE_ADD_MISSING
  166. if (_damage > 0.85) then {
  167. _fuel = VEH_MAINTENANCE_SPAWN_FUEL_LOGIC;
  168. _hitpoints = [];
  169. _damage = _hitpoints call fa_setDamagedParts;
  170.  
  171. _inventory = [];
  172. };
  173. #endif
  174. _entity setDamage _damage;
  175. {
  176. _wantExplosiveParts = _x;
  177. {
  178. _selection = _x select 0;
  179. _dam = _x select 1;
  180. if (_selection in dayZ_explosiveParts) then {
  181. if (_wantExplosiveParts) then {
  182. if (_dam > 0.8) then { _dam = 0.8; };
  183. [_entity, _selection, _dam] call fnc_veh_handleDam;
  184. };
  185. }
  186. else {
  187. if (!_wantExplosiveParts) then {
  188. [_entity, _selection, _dam] call fnc_veh_handleDam;
  189. };
  190. };
  191. } forEach _hitpoints;
  192. } forEach [false, true];
  193. _entity setvelocity [0,0,1];
  194. _entity setFuel _fuel;
  195. _entity call fnc_veh_ResetEH;
  196. };
  197. if (_entity isKindOf "AN2_DZ") then {
  198. _entity addWeapon "M240_veh";
  199. _entity addMagazine "100Rnd_762x51_M240";
  200. _entity addMagazine "100Rnd_762x51_M240";
  201. };
  202.  
  203. #ifdef OBJECT_DEBUG
  204. diag_log (format["VEHICLE %1 %2 at %3, original damage=%4, effective damage=%6, fuel=%5",
  205. _action, _entity call fa_veh2str, (getPosASL _entity) call fa_coor2str, _damage, _fuel, damage _entity]);
  206. #endif
  207. }
  208. else {
  209. if (!(_class in SafeObjects )) then {
  210. _damage = 1;
  211. };
  212. if (_damage < 1) then {
  213. _booleans=[];
  214. _worldspace = [_class, _point, _booleans] call fn_niceSpot;
  215. if (_booleans select 3) then {
  216. if ((_class != "TentStorage") OR {(_inventory call fa_tentEmpty)}) then {
  217. _action = "FAILED";
  218. _damage = 5;
  219. #ifdef OBJECT_DEBUG
  220. 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]);
  221. #endif
  222. };
  223. };
  224. };
  225. if (_damage < 1) then {
  226. #ifdef OBJECTS_FIX_OUTOFMAP
  227. _worldspace = [_dir, _point] call fa_staywithus;
  228. _dir = _worldspace select 0;
  229. _point = _worldspace select 1;
  230. #endif
  231. _entity = createVehicle [_class, _point, [], 0,
  232. if (_class=="TentStorage") then {"NONE"} else {"CAN_COLLIDE"}
  233. ];
  234. _entity setVariable ["ObjectID", _ObjectID, true];
  235. _entity setVariable ["CharacterID", _CharacterID, true];
  236. _entity setVariable ["lastUpdate",time];
  237. _entity setDamage _damage;
  238.  
  239. if (_class == "TentStorage") then {
  240. _entity addMPEventHandler ["MPKilled",{_this call vehicle_handleServerKilled;}];
  241. };
  242. }
  243. else {
  244. #ifdef OBJECT_DEBUG
  245. diag_log (format["IGNORED %1 oid#%2 cid:%3 ",
  246. _class, _ObjectID, _CharacterID ]);
  247. #endif
  248. };
  249. };
  250. if (_damage < 1 AND !(isNil ("_entity"))) then {
  251. _entity setdir _dir;
  252. _entity setPos _point;
  253. [_entity, _inventory] call fa_populateCargo;
  254.  
  255. dayz_serverObjectMonitor set [count dayz_serverObjectMonitor, _entity];
  256. if (_action == "CREATED") then {
  257. _key = format["CHILD:308:%1:%2:%3:%4:%5:%6:%7:%8:%9:", dayZ_instance,
  258. _class, _damage , 1,
  259. [_dir, _point],
  260. [getWeaponCargo _entity, getMagazineCargo _entity ,getBackpackCargo _entity],
  261. _hitpoints, _fuel, _ObjectID
  262. ];
  263. _rawData = "HiveEXT" callExtension _key;
  264. };
  265. if (_action == "SPAWNED" || _action == "DAMAGED") then {
  266. };
  267. if (_action == "SPAWNED") then {
  268. _key = format["CHILD:309:%1:%2:", _ObjectID,
  269. [getWeaponCargo _entity, getMagazineCargo _entity, getBackpackCargo _entity]];
  270. _rawData = "HiveEXT" callExtension _key;
  271. };
  272. if (_action == "MOVED" || _action == "SPAWNED") then {
  273. [_entity, "position"] call server_updateObject;
  274. };
  275. };
  276. sleep 0.01;
  277. } forEach _objectArray;
  278.  
  279. // Finish initialization ----------------------------------------------------------------------------------------------
  280.  
  281. createCenter civilian;
  282. if (isDedicated) then {
  283. endLoadingScreen;
  284. };
  285.  
  286. if (isDedicated) then {
  287. _id = [] execFSM "\z\addons\dayz_server\system\server_cleanup.fsm";
  288. };
  289.  
  290. allowConnection = true;
  291.  
  292. // Heli Crashes --------------------------------------------------------------------------------------------------------
  293.  
  294. // [_guaranteedLoot, _randomizedLoot, spawnOnStart, _frequency, _variance, _spawnChance, _spawnMarker, _spawnRadius, _spawnFire, _fadeFire]
  295. [3, 4, 3, (40 * 60), (15 * 60), 0.75, 'center', 4000, true, false] spawn server_spawnCrashSite;
  296.  
  297. // Spawn Camps --------------------------------------------------------------------------------------------------------
  298.  
  299. // quantity, marker, radius, min distance between 2 camps
  300. Server_InfectedCamps = [3, "center", 4500, 2000] call fn_bases;
  301. dayzInfectedCamps = Server_InfectedCamps;
  302. publicVariable "dayzInfectedCamps";
  303.  
  304. // Care packages ------------------------------------------------------------------------------------------------------
  305.  
  306. if (SpawnCare) then {
  307. for "_x" from 1 to SpawnCareCount do {
  308. _id = [] spawn spawn_care;
  309. };
  310. };
  311.  
  312. // Wrecks (Not Heli Crashes!) -----------------------------------------------------------------------------------------
  313.  
  314. if (SpawnWrecks) then {
  315. for "_x" from 1 to SpawnWrecksCount do {
  316. _id = [] spawn spawn_wreck;
  317. };
  318. };
  319.  
  320. // Anti Wallhack ------------------------------------------------------------------------------------------------------
  321.  
  322. call compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fa_antiwallhack.sqf";
  323.  
  324. sm_done = true;
  325. publicVariable "sm_done";
  326. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement